function cmp_did_team_participate_at_all($team1_points_before, $team2_points_before, $team1_points, $team2_points, $team_id1_before, $team_id2_before, $team_id1, $team_id2) { global $connection; global $site; if ($site->debug_sql()) { echo '<hr>' . "\n"; echo '<p>cmp_did_team_participate_at_all</p>' . "\n"; echo '<p>$team1_points_before: ' . htmlentities($team1_points_before) . '</p>' . "\n"; echo '<p>$team2_points_before: ' . htmlentities($team2_points_before) . '</p>' . "\n"; echo '<p>$team1_points: ' . htmlentities($team1_points) . '</p>' . "\n"; echo '<p>$team2_points: ' . htmlentities($team2_points) . '</p>' . "\n"; echo '<p>$team_id1_before: ' . htmlentities($team_id1_before) . '</p>' . "\n"; echo '<p>$team_id2_before: ' . htmlentities($team_id2_before) . '</p>' . "\n"; echo '<p>$team_id1: ' . htmlentities($team_id1) . '</p>' . "\n"; echo '<p>$team_id2: ' . htmlentities($team_id2) . '</p>' . "\n"; echo '<hr>' . "\n"; } // check if old team1 is still active in the new match version if ($team_id1_before !== $team_id1 && $team_id1_before !== $team_id2) { // old team1 did participate in the older match version but not in the new version decrease_total_match_count($team_id1_before, $site, $connection); // update old team1 data if ($team1_points_before > $team2_points_before) { // old team1 won in the older version decrease_won_match_count($team_id1_before, $site, $connection); } else { if ($team1_points_before < $team2_points_before) { // old team1 lost in the older version decrease_lost_match_count($team_id1_before, $site, $connection); } else { // old team1 tied in the older version decrease_draw_match_count($team_id1_before, $site, $connection); } } } }
function delete_match($match_id) { global $site; global $connection; global $tables_locked; global $viewerid; lock_tables(); // who entered/edited the match before? $userid = 0; // find out the appropriate team id list for the edited match (to modify total/win/draw/loose count) $query = 'SELECT `userid`, `timestamp`, `team1_id`, `team2_id`,' . ' `team1_points`, `team2_points`, `team1_new_score`, `team2_new_score`, `duration` FROM `matches`' . ' WHERE `id`=' . sqlSafeStringQuotes($match_id); if (!($result = $site->execute_query('matches', $query, $connection))) { unlock_tables(); $site->dieAndEndPage('Could not find out id for team 1 given match id ' . sqlSafeString($match_id) . ' due to a sql problem!'); } while ($row = mysql_fetch_array($result)) { $userid = intval($row['userid']); $timestamp = $row['timestamp']; $team_id1 = intval($row['team1_id']); $team_id2 = intval($row['team2_id']); $team1_caps = intval($row['team1_points']); $team2_caps = intval($row['team2_points']); $duration = intval($row['duration']); } mysql_free_result($result); // prepare to update win/draw/loose count // create array that keeps track of team score changes $team_stats_changes = array(); // mark the participating teams as potentially having a changed score $team_stats_changes[$team_id1] = ''; $team_stats_changes[$team_id2] = ''; // save old match into edit history table $query = 'INSERT INTO `matches_edit_stats` (`match_id`, `userid`, `timestamp`, `team1_id`,' . ' `team2_id`, `team1_points`, `team2_points`, `duration`) VALUES (' . sqlSafeStringQuotes($match_id) . ', ' . sqlSafeStringQuotes($userid) . ', ' . sqlSafeStringQuotes($timestamp) . ', ' . sqlSafeStringQuotes($team_id1) . ', ' . sqlSafeStringQuotes($team_id2) . ', ' . sqlSafeStringQuotes($team1_caps) . ', ' . sqlSafeStringQuotes($team2_caps) . ', ' . sqlSafeStringQuotes($duration) . ')'; if (!($result = $site->execute_query('matches_edit_stats', $query, $connection))) { unlock_tables(); $site->dieAndEndPage('The match reported by user #' . sqlSafeString($viewerid) . ' could not be entered due to a sql problem!'); } // we saved the old match in the editing stats thus we can now delete the actual match // update match table (perform the actual editing) // use current row id to access the entry // only one row needs to be updated $query = 'DELETE FROM `matches` WHERE `id`=' . sqlSafeStringQuotes($match_id) . ' LIMIT 1'; if (!($result = $site->execute_query('matches', $query, $connection))) { unlock_tables(); $site->dieAndEndPage('The match reported by user #' . sqlSafeString($viewerid) . ' could not be deleted due to a sql problem!'); } // update win/draw/loose count require_once 'team_match_count.php'; // both teams didn't play decrease_total_match_count($team_id1); decrease_total_match_count($team_id2); // team 1 won if ($team1_caps > $team2_caps) { // update team 1 data decrease_won_match_count($team_id1); // update team 2 data decrease_lost_match_count($team_id2); } // team 2 won if ($team1_caps < $team2_caps) { // update team 1 data decrease_lost_match_count($team_id1); // update team 2 data decrease_won_match_count($team_id2); } // the match ended in a draw if ($team1_caps === $team2_caps) { // update team 1 data decrease_draw_match_count($team_id1); // update team 2 data decrease_draw_match_count($team_id2); } // old match data variables no longer needed unset($userid_old); // trigger score updates for newer matches update_later_matches($team_id1, $team_id2, $team1_caps, $team2_caps, $timestamp, $team_stats_changes, $viewerid, $duration); show_score_changes($team_stats_changes, array_keys($team_stats_changes)); // done with deleting that match unlock_tables(); require_once '../CMS/maintenance/index.php'; echo '<p>The match was deleted successfully.</p>' . "\n"; $site->dieAndEndPage(); }