<?php
    session_start();
    include 'db_conn.php';
    $stmt = $db->prepare('SELECT Labels.* FROM Labels ORDER BY label ASC');
    $stmt->execute();
    $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>

<div id="sidebar">
    <div id="sidebar-content">
    <?php
        if (!isset($_SESSION['logged_in']))
        {
    ?>
        <h2 class="blue centered pointer mobile-visible" onclick="loginPopup();">Login</h2>
        <h2 class="blue centered pointer mobile-visible" onclick="registerPopup();">Register</h2>
    <?php
        } else {
    ?>
        <h2 class="blue centered pointer mobile-visible" onclick="logout();">Logout</h2>
    <?php
        }
    ?>
        <h2 class="mobile-visible">Date</h2>
        <div class="date mobile-visible"><?php echo date('F Y'); ?></div>
        <div class="weekNumber mobile-visible">Week: <?php echo ltrim(date('W'), '0'); ?></div>
        <h2 id="labelButton" onclick='accordionToggle()'>Labels</h2>
        <div id="labelPanel">
            <?php
                foreach ($results as $row) {
                    echo '<input type="checkbox" class="label-checkbox" onclick="setLabel(\''.$row["label_id"].'\'); updateEvents(true);" id="labelId-'.$row["label_id"].'" name="labelId" value="'.$row['label_id'].'">'.$row['label'].'<br>';
                }
            ?>
            <div class="labelButtonLink" onclick='clearLabels(); updateEvents(true)'><em>Show all labels</em></div>
            <?php if (isset($_SESSION['logged_in'])) { ?>
            <div class="labelButtonLink" onclick='setMyLabels(); showSet();'><em>Set as my labels</em></div>
            <?php } if (isset($_SESSION['logged_in']) && $_SESSION['privilege_id'] != 4) { ?>
                <input id="checkboxShowUnconfirmedEvents" type="checkbox" onclick="toggleUnapproved();">Show unapproved events</label>
            <?php } ?>
                <input id="checkboxShowAllDayEvents" type="checkbox" onclick="toggleAllDay();">Hide all-day events</label>
        </div>
    </div>
</div>
<div id="main-content">
    <div id="days">
        <div class='hour-column'><div class='hour-row'></div></div>
        <?php
            $days = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun");
            $correction = -((date('w') + 6) % 7) ;

            for ($x=0;$x<7;$x++)
            {
                echo "<div class='day-column'>";
                echo "<div class='hour-row day-name'>";
                echo "<div class='day-name-inner'>{$days[$x]}<div class='date-no'></div> ";
                echo "</div>";
                echo "</div>";
                echo "</div>";
            }
        ?>
        <div class="fake-scrollbar"></div>
    </div>
    <div class='all-day'>
        <div class='hour-column'><div class='hour-row'></div></div>
        <div class='all-day-bg'>
            <?php
                        for ($x=0;$x<7;$x++)
                        {
                            echo "<div class='day-column'>";
                            echo "<div class='hour-row' id='-day-{$x}-hour-0'>";
                            echo "</div>";
                            echo "</div>";
                        }
            ?>
            <div class="fake-scrollbar"></div>
        </div>
        <div class='all-day-ev'>
        </div>
    </div>
    <div id="grid">
        <div id="agenda">
            <div id="week">
                <?php
                    echo "<div class='hour-column'>";

                    for ($y=0;$y<24;$y++)
                    {
                        echo "<div class='hour-row'>".$y.":00";
                        echo "</div>";
                    }

                    echo "</div>";
                    setlocale(LC_ALL, "nl_NL");
                    $weekday = date("N") - 1;
                    for($x=0;$x<7;$x++)
                    {
                        echo "<div class='day-column'>";

                        for ($y=0;$y<24;$y++)
                        {
                            echo "<div class='hour-row' id='day-".$x."-hour-".$y."'>";
                            echo "</div>";
                        }
                        echo "</div>";
                    }
                ?>
            </div>
        </div>
    </div>
</div>
