Exemple #1
0
    // only show 200 messages, not 201
    // NOTE: array_pop would not work on a resource (e.g. $result)
    array_pop($matchid_list);
}
// walk through the array values
foreach ($matchid_list as $match_entry) {
    echo '<tr class="matches_overview">' . "\n";
    echo '<td>';
    echo $match_entry['timestamp'] . ' [' . $match_entry['duration'] . ']';
    echo '</td>' . "\n" . '<td>';
    // get name of first team
    team_name_from_id($match_entry['team1_id'], $match_entry['team1_name']);
    // seperator showing that opponent team will be named soon
    echo ' - ';
    // get name of second team
    team_name_from_id($match_entry['team2_id'], $match_entry['team2_name']);
    // done with the table field, go to next field
    echo '</td>' . "\n" . '<td>';
    echo htmlentities($match_entry['team1_points']);
    echo ' - ';
    echo htmlentities($match_entry['team2_points']);
    echo '</td>' . "\n";
    echo '<td>';
    // get name of first team
    player_name_from_id($match_entry['userid'], $match_entry['playername']);
    echo '</td>' . "\n";
    // show allowed actions based on permissions
    if ($allow_edit_match || $allow_delete_match) {
        echo '<td>';
        if ($allow_edit_match) {
            echo '<a class="button" href="./?edit=' . htmlspecialchars($match_entry['id']) . '">Edit match result</a>';
Exemple #2
0
function similarMatchEntered($newerMatches = true)
{
    global $site;
    global $connection;
    // equal case should never happen
    $comparisonOperator = '>';
    if (!$newerMatches) {
        $comparisonOperator = '<=';
    }
    // similar match entered already?
    // strategy: ask for one match before the entered one and one after the one to be entered and do not let the database engine do the comparison
    $query = 'SELECT `id`,`timestamp`,`team1_id`,`team2_id`,`team1_points`,`team2_points`, `duration` FROM `matches`';
    $query .= ' WHERE (`timestamp`' . sqlSafeString($comparisonOperator) . sqlSafeStringQuotes($_POST['match_day'] . $_POST['match_time']);
    // sorting needed
    $query .= ') ORDER BY `timestamp` DESC';
    // only comparing nearest match in time
    $query .= ' LIMIT 0,1';
    if (!($result = @$site->execute_query('matches', $query, $connection))) {
        $site->dieAndEndPage('Unfortunately there seems to be a database problem and thus comparing timestamps (using operator ' . sqlSafeString($comparisonOperator) . ') of matches failed.');
    }
    // initialise values
    // casting the values to 0 is important
    // (a post variable having no value means it has to be set to 0 to successfully compare values here)
    $timestamp = '';
    $duration = (int) $_POST['duration'];
    $team_id1 = (int) $_POST['team_id1'];
    $team_id2 = (int) $_POST['team_id2'];
    $team_id1_matches = false;
    $team_id2_matches = false;
    $team1_points = (int) $_POST['team1_points'];
    $team2_points = (int) $_POST['team2_points'];
    $team1_points_matches = false;
    $team2_points_matches = false;
    while ($row = mysql_fetch_array($result)) {
        // we can save comparisons using a helper variable
        $team_ids_swapped = false;
        $timestamp = $row['timestamp'];
        $duration_matches = intval($row['duration']) === $duration;
        $team_id1_matches = intval($row['team1_id']) === $team_id1;
        if (!$team_id1_matches) {
            $team_ids_swapped = true;
            $team_id1_matches = intval($row['team1_id']) === $team_id2;
        }
        if ($team_ids_swapped) {
            $team_id2_matches = intval($row['team2_id']) === $team_id1;
        } else {
            $team_id2_matches = intval($row['team2_id']) === $team_id2;
        }
        // use helper variable to save some comparisons of points
        if ($team_ids_swapped) {
            $team1_points_matches = intval($row['team1_points']) === $team2_points;
            $team2_points_matches = intval($row['team2_points']) === $team1_points;
        } else {
            $team1_points_matches = intval($row['team1_points']) === $team1_points;
            $team2_points_matches = intval($row['team2_points']) === $team2_points;
        }
    }
    mysql_free_result($result);
    // if similar match was found warn the user
    if ($team_id1_matches && $team_id2_matches && $team1_points_matches && $team2_points_matches && $duration_matches) {
        echo '<p>The nearest ';
        if ($newerMatches) {
            echo 'newer ';
        } else {
            echo 'older ';
        }
        echo ' match in the database is quite similar:</p>';
        // use the post data as much as possible instead of looking up the same data in the database
        echo '<p><strong>' . $timestamp . ' [' . $duration . ']  </strong> ';
        $query = 'SELECT `name` FROM `teams` WHERE `id`=' . sqlSafeStringQuotes($team_id1) . ' LIMIT 1';
        if (!($result = @$site->execute_query('teams', $query, $connection))) {
            $site->dieAndEndPage('Could not find out name of team #' . sqlSafeString($team_id1) . '.');
        }
        while ($row = mysql_fetch_array($result)) {
            team_name_from_id($team_id1, htmlent($row['name']));
        }
        mysql_free_result($result);
        echo ' - ';
        $query = 'SELECT `name` FROM `teams` WHERE `id`=' . sqlSafeStringQuotes($team_id2) . ' LIMIT 1';
        if (!($result = @$site->execute_query('teams', $query, $connection))) {
            $site->dieAndEndPage('Could not find out name of team #' . sqlSafeString($team_id2) . '.');
        }
        while ($row = mysql_fetch_array($result)) {
            team_name_from_id($team_id2, htmlent($row['name']));
        }
        mysql_free_result($result);
        echo ' with result <strong>' . $team1_points . ' - ' . $team2_points . '</strong>.</p>';
        echo "\n";
        return true;
    }
    return false;
}