Skip to content
Snippets Groups Projects
index.php 16.8 KiB
Newer Older
Tim Repke's avatar
Tim Repke committed
<?php
session_start();
Tim Repke's avatar
Tim Repke committed

require 'frameworks/environment.php';
require 'view/signups/index.php';
Tim Repke's avatar
Tim Repke committed

require 'view/default_index.php';

// =====================================================================================================================
// HEADERS
Tim Repke's avatar
Tim Repke committed

function echo_headers() {
    echo index_get_css_includes();
    echo index_get_js_includes();
    echo index_get_additional_headers();
}
Tim Repke's avatar
Tim Repke committed

function index_get_css_includes() {
    $basefolder = 'view/';
Tim Repke's avatar
Tim Repke committed

    $base_styles = ['style.css'];
Tim Repke's avatar
Tim Repke committed
    $additional_styles = index_get_dependencies_helper('getCSSDependencies');

    $styles = array_merge($base_styles, $additional_styles);

    $ret = '';
    foreach ($styles as $style) {
        $ret .= "<link rel=\"stylesheet\" href=\"" . $basefolder . $style . "\" />\n";
    }
    return $ret;
Tim Repke's avatar
Tim Repke committed
}

function index_get_js_includes() {
    $basefolder = 'view/';
Tim Repke's avatar
Tim Repke committed

    $base_js = [
        'js/jquery-1.11.1.min.js',
        'js/jquery-ui.min.js',
        'js/angular.min.js',
Tim Repke's avatar
Tim Repke committed
        'js/elevator.js',
        'js/hurrdurr.js',
Tim Repke's avatar
Tim Repke committed
        'js/api.js'
    ];
    $additional_js = index_get_dependencies_helper('getJSDependencies');

    $scripts = array_merge($base_js, $additional_js);

    $ret = '';
Tim Repke's avatar
Tim Repke committed
    $currPathLength = strlen(realpath(".")) + 1;
    $uniq = array();
Tim Repke's avatar
Tim Repke committed
    foreach ($scripts as $script) {
Tim Repke's avatar
Tim Repke committed
        $script = substr(realpath($basefolder . $script), $currPathLength);
        if (isset($uniq[$script])) continue;
        $uniq[$script] = true;
        $ret .= "<script type=\"text/javascript\" src=\"" . $script . "\"></script>\n";
Tim Repke's avatar
Tim Repke committed
    }
    return $ret;
}

function index_get_dependencies_helper($dependency_function_name) {
    $methods_basefolder = 'signups/';

    $signup_method = SignupMethods::getInstance();

    if ($signup_method->signupMethodExists()) {
Tim Repke's avatar
Tim Repke committed
        $method_folder = $signup_method->getActiveMethodId();

        return array_map(function ($d) use ($methods_basefolder, $method_folder) {
Tim Repke's avatar
Tim Repke committed
            return $methods_basefolder . $method_folder . '/' . $d;
        }, $signup_method->getActiveMethod()->$dependency_function_name());
    }
    return [];
Tim Repke's avatar
Tim Repke committed

function index_get_additional_headers() {
    $signup_method = SignupMethods::getInstance();
    if ($signup_method->signupMethodExists()) {
        return $signup_method->getActiveMethod()->getAdditionalHeader();
    }
    return '';
// =====================================================================================================================
// CONTENT

function show_content() {
    $environment = Environment::getEnv();

    if (!$environment->isSelectedTripIdValid()) {
        index_show_alleFahrten();
Tim Repke's avatar
Tim Repke committed
        index_make_hurrdurr();
Tim Repke's avatar
Tim Repke committed
    } else {
        $fid = $environment->getSelectedTripId();
        try {
            $opentime = $environment->database->select('fahrten', ['opentime'], ['fahrt_id' => $fid])[0]['opentime'];
        } catch (Exception $ex) {
            $opentime = 0;
        }

Tim Repke's avatar
Tim Repke committed
        // --- Fahrtinfos
        index_show_fahrtHeader($fid);
        index_show_fahrtHeader_js($fid);
        if ($opentime < time()) {
            // --- Anmeldebox
            index_show_signup();

            // --- Liste der Anmeldungen
            index_show_signupTable($fid);
Tim Repke's avatar
Tim Repke committed

            index_make_hurrdurr();
        } else index_show_countdown($opentime);
Tim Repke's avatar
Tim Repke committed
    }
// ---------------------------------------------------------------------------------------------------------------------
// SIGNUP AREA

function index_show_signup() {
    $environment = Environment::getEnv();
Tim Repke's avatar
Tim Repke committed
    $signup_method = SignupMethods::getInstance();
    $fid = $environment->getSelectedTripId();
Tim Repke's avatar
Tim Repke committed
    $openstatus = $environment->getRegistrationState($fid);
    $waitlist_confirmed = $environment->isInWaitlistMode();

Tim Repke's avatar
Tim Repke committed

    echo '<div id="signup-container">';
    echo '<h2>Anmeldung</h2>';

Tim Repke's avatar
Tim Repke committed
    // Anmeldung erfolgreich
    if (isset($_REQUEST['success'])) {
        echo '<div style="text-align:center; font-size: 20pt; font-weight: bold">Die Anmeldung war erfolgreich.</div>';
    } // Anmeldung fehlgeschlagen, weil voll oder duplikat
Tim Repke's avatar
Tim Repke committed
    elseif (isset($_REQUEST['full'])) {
        echo '<div style="text-align:center; font-size: 20pt; font-weight: bold">Anmeldung leider fehlgeschlagen.</div>';
        echo '<div style="text-align:center; font-size: 16pt; font-weight: bold">Die Anmeldegrenze wurde leider erreicht oder du bist bereits angemeldet.</div>';
Tim Repke's avatar
Tim Repke committed
        echo '<div style="text-align:center; font-size: 14pt; ">Es besteht die Möglichkeit sich auf der Warteliste einzutragen.<br />
              Wenn du das möchtest, klicke hier: <a class="normallink" href="?fid=' . $fid . '&waitlist">&#8694; Warteliste</a></div>';
    } // Formulardaten empfangen -> auswerten!
    elseif ($environment->formDataReceived()) {
Tim Repke's avatar
Tim Repke committed
        comm_verbose(1, "Formular bekommen");
Tim Repke's avatar
Tim Repke committed

        $sub = $signup_method->validateSubmission();

        if ($sub['valid']) {
            if ($environment->sendBachelorToDB($sub['data']))
                header("Location: ?fid=" . $fid . "&success");
                header("Location: ?fid=" . $fid . "&full");
Tim Repke's avatar
Tim Repke committed
        } else {
Tim Repke's avatar
Tim Repke committed
            if (!isset($_REQUEST['hideErrors'])) index_show_errors($sub['errors']);
            $environment->setDanglingFormData($sub['data']);
            $signup_method->getFallbackMethod()->showInlineHTML();
    } // Anmeldung anzeigen (Form or game)
Tim Repke's avatar
Tim Repke committed
    elseif ($signup_method->signupMethodExists() &&
        ($openstatus == 0 || ($waitlist_confirmed && $openstatus < 2))
    ) {
Tim Repke's avatar
Tim Repke committed

        $signup_method->getActiveMethod()->showInlineHTML();
Tim Repke's avatar
Tim Repke committed

        // future feature: option to show edit view (when $_GET['bid'] isset)
    } // Anmeldeoptionen anzeigen
Tim Repke's avatar
Tim Repke committed
    else {
        if ($openstatus > 0 && !$waitlist_confirmed) {
            echo '<div style="text-align:center; font-size: 20pt; font-weight: bold">Die Anmeldung wurde geschlossen.</div>';
Tim Repke's avatar
Tim Repke committed

            if ($openstatus != 2) {
                echo '
                <div style="text-align:center; font-size: 16pt; font-weight: bold">
                    Ein Auge offen halten, ob Plätze frei werden.
                </div><div style="text-align:center; font-size: 14pt;">
                    Es gibt aber auch eine Warteliste.<br />
                    Wenn du da rauf möchtest, klicke hier:
                    <a class="normallink" href="?fid=' . $fid . '&waitlist">&#8694; Warteliste</a>
                </div>';
Tim Repke's avatar
Tim Repke committed
        } elseif ($openstatus < 2) {
            $methods = $signup_method->getSignupMethodsBaseInfo();
            $link = '?fid=' . $fid . ($waitlist_confirmed ? '&waitlist' : '') . '&method=';

Tim Repke's avatar
Tim Repke committed
            echo '<p>Es stehen verschiedene Methoden zur Anmeldung offen. Wähle eine davon:';

Tim Repke's avatar
Tim Repke committed
            echo '<ul id="method-list">';
            foreach ($methods as $method) {
                echo '<li><a href="' . $link . $method['id'] . '#signup-container">' . $method["name"] . '</a> <br />' . $method['description'] . '</li>';
Tim Repke's avatar
Tim Repke committed
            }
            echo '</ul>';
Tim Repke's avatar
Tim Repke committed
    }
Tim Repke's avatar
Tim Repke committed

    echo '</div>'; // close signup-container
Tim Repke's avatar
Tim Repke committed
}

/**
 * puts out a list of all errors
 * @param $errors
 */
function index_show_errors($errors) {
    echo '<div class="message error"><ul>';
    foreach ($errors as $e) {
        echo '<li>' . $e . '</li>';
    echo '</ul></div>';
Tim Repke's avatar
Tim Repke committed

// ---------------------------------------------------------------------------------------------------------------------
// TRIP LISTING
Tim Repke's avatar
Tim Repke committed


/**
 * show list of all fahrten
 */
function index_show_alleFahrten() {
    $environment = Environment::getEnv();

    comm_verbose(2, "Liste aller Fahrten (Jahr, Ziel, Zeitraum, Anz. Mitfahrer)");
Manuel Herrmann's avatar
Manuel Herrmann committed
    echo '<h2>Anmeldung zur Fachschaftsfahrt</h2>';
    $foos = $environment->database->select("fahrten",
        ['fahrt_id', 'titel', 'ziel', 'von', 'bis', 'beschreibung', 'leiter', 'kontakt', 'max_bachelor'],
        "ORDER BY fahrt_id DESC");
    if (!$foos) {
Tim Repke's avatar
Tim Repke committed
        echo 'Keine Fahrten im System gefunden';
        return;
    }

    foreach ($foos as $foo) {
Tim Repke's avatar
Tim Repke committed
        index_show_fahrtHeader($foo);
Tim Repke's avatar
Tim Repke committed
    }
Tim Repke's avatar
Tim Repke committed
}

/**
 * @param $fahrt wenn array, dann Datenbankrow; wenn zahl, dann wird das selektiert
 */
function index_show_fahrtHeader($fahrt) {
    $environment = Environment::getEnv();
    if (!is_array($fahrt)) {
        $fahrt = $environment->database->select('fahrten',
            ['fahrt_id', 'titel', 'ziel', 'von', 'bis', 'leiter', 'kontakt', 'beschreibung', 'max_bachelor'],
            ['fahrt_id' => $fahrt]);
        if (!$fahrt)
            return; // break here and show nothing!
        else
            $fahrt = $fahrt[0];
    $cnt = $environment->database->count("bachelor", ["AND" =>
            "fahrt_id" => $fahrt['fahrt_id']]]);
Tim Repke's avatar
Tim Repke committed
            <div class="fahrt-left">
            <a  class="fahrthead" href="index.php?fid=' . $fahrt['fahrt_id'] . '">' . $fahrt['titel'] . '</a>';
    echo 'Ziel: <i>' . $fahrt['ziel'] . '</i><br />';
    echo 'Datum: <i>' . comm_from_mysqlDate($fahrt['von']) . " - " . comm_from_mysqlDate($fahrt['bis']) . '</i><br />';
    echo "Ansprechpartner: <i>" . $fahrt['leiter'] . " (" . comm_convert_mail($fahrt['kontakt']) . ")</i><br />";
    echo "Anmeldungen: <i>" . $cnt . " / " . $fahrt['max_bachelor'] . "</i>";
    echo '<p>' . $fahrt['beschreibung'] . '</p></div>
            <div class="map-canvas" id="map-canvas-' . $fahrt['fahrt_id'] . '"></div>
Tim Repke's avatar
Tim Repke committed
            <div style="clear:both"></div>
function index_show_fahrtHeader_js($fahrten) {
    $environment = Environment::getEnv();

    $pins = $environment->database->select("fahrten", ["fahrt_id", "map_pin"], ["fahrt_id" => $fahrten]);
    echo '<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
Tim Repke's avatar
Tim Repke committed
        <script type="text/javascript">
            window.onload = function() {
                $("div.fahrt-left i").click(function(){
                    });

               $("div.fahrt-left i").hover(
                    function(){
                        $(this).html($(this).html().replace(/·/g, "&#128045;"));
                        $(this).html($(this).html().replace("Ø", "&#128053;"));
                    },
                    function(){
                        $(this).html($(this).html().replace(/🐭/g, "&middot;"));
                        $(this).html($(this).html().replace("🐵", "&Oslash;"));
                    }
                );
    foreach ($pins as $p) {
Tim Repke's avatar
Tim Repke committed
        // if not valid GPS pos, fallback to Kheta!
        if (!preg_match("/\\d+\\.\\d+ \\d+\\.\\d+/m", $p["map_pin"]))
Tim Repke's avatar
Tim Repke committed
            $p["map_pin"] = '71.555267 99.690962';

        echo '
            var ziel_' . $p['fahrt_id'] . ' = new google.maps.LatLng(' . str_replace(" ", ", ", $p["map_pin"]) . ');
            var marker_' . $p['fahrt_id'] . ';
            var map_' . $p['fahrt_id'] . ';
    foreach ($pins as $p) {
        echo '
                var mapOptions_' . $p['fahrt_id'] . ' = {
                    center: ziel_' . $p['fahrt_id'] . ',
                    panControl: false,
                    zoomControl: false,
                    scaleControl: true,
                    mapTypeControl: false,
                    streetViewControl: false,
                    overviewMapControl: false
                };

                map_' . $p['fahrt_id'] . ' = new google.maps.Map(document.getElementById(\'map-canvas-' . $p['fahrt_id'] . '\'), mapOptions_' . $p['fahrt_id'] . ');
                marker_' . $p['fahrt_id'] . ' = new google.maps.Marker({
                    map:map_' . $p['fahrt_id'] . ',
                    draggable:true,
                    animation: google.maps.Animation.DROP,
                    position: ziel_' . $p['fahrt_id'] . '
                marker_' . $p['fahrt_id'] . '.setAnimation(google.maps.Animation.BOUNCE);';
            }

            google.maps.event.addDomListener(window, \'load\', initialize);

        </script>';
Tim Repke's avatar
Tim Repke committed
}


// ---------------------------------------------------------------------------------------------------------------------
// PUBLIC REGISTRATIONS LISTING

Tim Repke's avatar
Tim Repke committed
/**
 * show table of public registrations
 */
function index_show_signupTable($fid) {
    $environment = Environment::getEnv();

Tim Repke's avatar
Tim Repke committed
    echo '<h2>Anmeldungen</h2>';
Manuel Herrmann's avatar
Manuel Herrmann committed

    $data = $environment->database->select('bachelor',
        ["pseudo", "antyp", "abtyp", "anday", "abday", "comment", "studityp"],
        ["AND" => [
            'fahrt_id' => (int)$fid,
            'public' => 1,
            'backstepped' => NULL
Tim Repke's avatar
Tim Repke committed

    if (!$data) echo '<div class="signups">Noch keine (sichtbaren) Anmeldungen!</div>';
Tim Repke's avatar
Tim Repke committed
    else {
        echo '
            <table class="signups">
                <thead>
                    <tr>
Tim Repke's avatar
Tim Repke committed
                        <th>Anzeigename</th>
                        <th>Anreisetag</th>
                        <th>Anreiseart</th>
Tim Repke's avatar
Tim Repke committed
                        <th>Abreisetag</th>
                        <th>Abreiseart</th>
Tim Repke's avatar
Tim Repke committed
                        <th>Kommentar</th>
                    </tr>
                </thead>';
        foreach ($data as $d) {
Tim Repke's avatar
Tim Repke committed
            echo '<tr>
                <!--td>' . $d["studityp"] . '</td-->
                <td>' . $d["pseudo"] . '</td>
                <td>' . comm_from_mysqlDate($d["anday"]) . '</td>
                <td>' . index_show_signupTable_destroyTypes($d["antyp"]) . '</td>
                <td>' . comm_from_mysqlDate($d["abday"]) . '</td>
                <td>' . index_show_signupTable_destroyTypes($d["abtyp"]) . '</td>
                <td>' . $d["comment"] . '</td>
Tim Repke's avatar
Tim Repke committed
            </tr>';
        }
        echo '</table>';
    }
}
function index_show_signupTable_destroyTypes($anabtyp) {
    global $config_reisearten, $config_reisearten_destroyed;
    if (array_search($anabtyp, $config_reisearten) >= 2)
        return $config_reisearten_destroyed[array_rand($config_reisearten_destroyed)];
    return $anabtyp;
Tim Repke's avatar
Tim Repke committed
function index_make_hurrdurr() {
    echo "<script>
        $(function () {
            var hurdur = new HurDur();
            new Elevator({
                element: document.getElementById('nyan'),
                mainAudio: 'view/audio/audio.ogg',
                endAudio: 'view/audio/end-audio.ogg',
Tim Repke's avatar
Tim Repke committed
                duration: 5000,
                startCallback: hurdur.start,
                endCallback: hurdur.stop
            });});</script>";
}

function index_show_countdown($opentime) {
    echo '<script type="text/javascript" src="view/js/jquery.qrcode.js"></script>';
    echo "
    <script>
Tim Repke's avatar
Tim Repke committed
        var opentime = " . $opentime . ";
        var b = true;
Tim Repke's avatar
Tim Repke committed

        $(function () {
            var url = window.location.href;
            if(url.indexOf('#showQR')>0) $('#QRcode').qrcode({
                render: 'canvas',
                ecLevel: 'Q',
                size: 150,
                fill: '#000',
                background: null,
                text:  url.replace('#showQR',''),
                radius: 0.5,
                quiet:2,
                mode: 2,
                label: 'FS Fahrt',
                fontname: 'sans',
                fontcolor: '#ff9818'

            });
Tim Repke's avatar
Tim Repke committed
            var hurdur = new HurDur({
            cats: 10,
            loopcb: function() {
		        $('#text, body').stop().animate({color:b?'#ffffff':'#000000'}, 1000);

                var now = (Date.now() + ((new Date()).getTimezoneOffset()*60))/1000;
                var diff = opentime - now;
                var view = '';
                if (diff <= 0) {
                    view = '00:00:00.00';
                } else {
                    view = hurrdurrr(parseInt(diff/60/60/24, 10)) + 'd ' + hurrdurrr(parseInt(diff / 60 / 60 % 24, 10))
                        + 'h:' + hurrdurrr(parseInt(diff / 60 % 60, 10)) + 'm.' + hurrdurrr(parseInt(diff%60, 10)) + 's';
Tim Repke's avatar
Tim Repke committed
                }
                $('#countdown').html(view);
                function hurrdurrr(num) {
                    return ((num < 10) ? '0' : '') + num;
                }
		        b = !b;
            }});
            hurdur.start();
        });
    </script>";

    echo '<div id="text" style="font-weight:bold;text-align:center;font-size:40pt;font-family:Verdana, Geneva, sans-serif">
Tim Repke's avatar
Tim Repke committed
            ANMELDUNG IN KÜRZE<br />
            <span id="countdown"></span>
Tim Repke's avatar
Tim Repke committed
    echo '<div style="width:100%; margin-top: 20px;">
            <div style="margin:0 auto; width:300px">
                <iframe width="300" height="300" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/109529816&amp;auto_play=true&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>
    echo '<canvas id="QRcode" style="position: fixed; bottom: 10px; right: -240px;width:500px;height:250px;"></canvas>';