<html>
    <head>
        <title>Open Mic Night Signups</title>
        <link rel="stylesheet" type="text/css" href="signups.css">
    </head>
    <body>
        <div class="imgheader">
            <img src="header.png">
        </div>
        <div id="currentList">
            <div class="header">Current Signup List</div>
            <?php
                $current = fopen("data-list.txt", "r");
                if ($current) {
                    $line = "";
                    while (($buffer = fgets($current)) !== false) {
                        $line = $line . "<li>" . $buffer . "</li>";
                    }
                    fclose($current);

                    if (strlen($line) == 0) {
                        echo "<div style=\"text-align: center;\">No one is currently signed up.</div>";
                    }
                    else {
                        echo "<ol>" . $line . "</ol>";
                    }
                }
            ?>
        </div>
        <div id="historyList">
            <div class="header">Past Participants</div>
            <?php
                $history = fopen("data-hist.txt", "r");
                if ($history) {
                    $line = "";
                    while (($buffer = fgets($history)) !== false) {
                        $parsed = json_decode($buffer);
                        $line = $line . "<li>" . $parsed->{"nick"} . " has had " . count($parsed->{"turns"});
                        if (count($parsed->{"turns"}) == 1) {
                            $line = $line . " turn: ";
                        }
                        else {
                            $line = $line . " turns: ";
                        }
                        $first = true;
                        foreach ($parsed->{"turns"} as $turn) {
                            if ($first) {
                                $first = false;
                            }
                            else {
                                $line = $line . ", ";
                            }
                            if (strlen($turn->{"url"}) == 0) {
                                $line = $line . $turn->{"date"};
                            }
                            else {
                                $line = $line . "<a href=\"" . $turn->{"url"} . "\" target=\"_blank\">" . $turn->{"date"} . "</a>";
                            }
                        }
                        $line = $line . "</li>";
                    }
                    fclose($history);
                    
                    if (strlen($line) == 0) {
                        echo "<div style=\"text-align: center;\">No one has had a turn yet.</div>";
                    }
                    else {
                        echo "<ul>" . $line . "</ul>";
                    }
                }
            ?>
        </div>
        <div class="clear"></div>
        <div class="imgheader">
            <img src="footer.png">
        </div>
    </body>
</html>
