Example #1
0
function eventList($series = "", $season = "")
{
    $db = Database::getConnection();
    $player = Player::getSessionPlayer();
    $playerSeries = $player->stewardsSeries();
    $seriesEscaped = array();
    foreach ($playerSeries as $oneSeries) {
        $seriesEscaped[] = $db->escape_string($oneSeries);
    }
    $seriesString = '"' . implode('","', $seriesEscaped) . '"';
    $query = "SELECT e.name AS name, e.format AS format,\n    COUNT(DISTINCT n.player) AS players, e.host AS host, e.start AS start,\n    e.finalized, e.cohost, e.series\n    FROM events e\n    LEFT OUTER JOIN entries AS n ON n.event = e.name\n    WHERE (e.host = \"{$db->escape_string($player->name)}\"\n           OR e.cohost = \"{$db->escape_string($player->name)}\"\n           OR e.series IN (" . $seriesString . "))";
    if (isset($_GET['format']) && strcmp($_GET['format'], "") != 0) {
        $query = $query . " AND e.format=\"{$db->escape_string($_GET['format'])}\" ";
    }
    if (isset($_GET['series']) && strcmp($_GET['series'], "") != 0) {
        $query = $query . " AND e.series=\"{$db->escape_string($_GET['series'])}\" ";
    }
    if (isset($_GET['season']) && strcmp($_GET['season'], "") != 0) {
        $query = $query . " AND e.season=\"{$db->escape_string($_GET['season'])}\" ";
    }
    $query = $query . " GROUP BY e.name ORDER BY e.start DESC LIMIT 100";
    $result = $db->query($query);
    $seriesShown = array();
    $results = array();
    while ($thisEvent = $result->fetch_assoc()) {
        $results[] = $thisEvent;
        $seriesShown[] = $thisEvent['series'];
    }
    if (isset($_GET['series']) && $_GET['series'] != "") {
        $seriesShown = $playerSeries;
    } else {
        $seriesShown = array_unique($seriesShown);
    }
    echo "<form action=\"event.php\" method=\"get\">";
    echo "<table class=\"form\" style=\"border-width: 0px\" align=\"center\">";
    echo "<tr><td colspan=\"2\" align=\"center\"><b>Filters</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><th>Format</th><td>";
    if (!isset($_GET['format'])) {
        $_GET['format'] = '';
    }
    formatDropMenu($_GET['format'], 1);
    echo "</td></tr>";
    echo "<tr><th>Series</th><td>";
    Series::dropMenu($_GET['series'], 1, $seriesShown);
    echo "</td></tr>";
    echo "<tr><th>Season</th><td>";
    seasonDropMenu($_GET['season'], 1);
    echo "</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><td colspan=\"2\" class=\"buttons\">";
    if (count($playerSeries) > 0) {
        echo "<input type=\"submit\" name=\"mode\" value=\"Create New Event\" />\n";
    }
    echo "<input type=\"submit\" name=\"mode\" value=\"Filter Events\" />\n";
    echo "</td></tr></table>";
    echo "<table style=\"border-width: 0px\" align=\"center\" cellpadding=\"3\">";
    echo "<tr><td colspan=\"5\">&nbsp;</td></tr>";
    echo "<tr><td><b>Event</td><td><b>Format</td>";
    echo "<td align=\"center\"><b>Players</td>";
    echo "<td><b>Host(s)</td>";
    echo "<td align=\"center\"><b>Finalized</td></tr>";
    foreach ($results as $thisEvent) {
        $event = new Event($thisEvent['name']);
        $dateStr = $thisEvent['start'];
        $dateArr = explode(" ", $dateStr);
        $date = $dateArr[0];
        echo "<tr><td>";
        echo $event->linkTo();
        echo "</td>";
        echo "<td>{$thisEvent['format']}</td>";
        echo "<td align=\"center\">{$thisEvent['players']}</td>";
        echo "<td>{$thisEvent['host']}";
        $ch = $thisEvent['cohost'];
        if (!is_null($ch) && strcmp($ch, "") != 0) {
            echo "/{$ch}";
        }
        echo "</td>";
        #echo "<td>$date</td>";
        echo "<td align=\"center\">";
        if ($thisEvent['finalized'] == 1) {
            echo "&#x2714;";
        }
        echo "</td>";
        echo "</tr>";
    }
    if ($result->num_rows == 100) {
        echo "<tr><td colspan=\"5\" width=\"500\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"5\" align=\"center\">";
        echo "<i>This list only shows the 100 most recent results. ";
        echo "Please use the filters at the top of this page to find older ";
        echo "results.</i></td></tr>";
    }
    $result->close();
    echo "<tr><td colspan=\"5\" width=\"500\">&nbsp;</td></tr>";
    echo "</table></form>";
}