function cmp_team_participated_change($team1_points_before, $team2_points_before, $team1_points, $team2_points, $team_id1_before, $team_id2_before, $team_id1, $team_id2) { global $connection; global $site; // map old team id to new team id if ($team_id1_before === $team_id1) { if ($site->debug_sql()) { echo '<br><p>teamid ' . htmlentities($team_id1) . ' mapped</p>'; echo '<hr>' . "\n"; echo '<p>Function cmp_team_participated_change called.</p>' . "\n"; echo '<p>$team_id1_before: ' . htmlentities($team_id1_before) . '</p>' . "\n"; echo '<p>$team_id1: ' . htmlentities($team_id1) . '</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 '<hr>' . "\n"; } if ($team1_points_before > $team2_points_before) { // team1 won in the older version if ($team1_points > $team2_points) { // team1 won also in the newer version -> nothing to do for team1 } else { if ($team1_points < $team2_points) { // team1 lost in the newer version but won in the older version decrease_won_match_count($team_id1); increase_lost_match_count($team_id1); } else { // team1 tied in the newer version but won in the older version decrease_won_match_count($team_id1); increase_draw_match_count($team_id1); } } } else { if ($team1_points_before < $team2_points_before) { // team1 lost in the older match version if ($team1_points > $team2_points) { // team1 won in the newer version decrease_lost_match_count($team_id1); increase_won_match_count($team_id1); } else { if ($team1_points < $team2_points) { // team1 lost in the older version and in the newer version } else { // team1 lost in the older version but tied in the newer version decrease_lost_match_count($team_id1); increase_draw_match_count($team_id1); } } } else { // team1 tied in the older match version if ($team1_points > $team2_points) { // team1 won in the newer version decrease_draw_match_count($team_id1); increase_won_match_count($team_id1); } else { if ($team1_points < $team2_points) { // team1 tied in the older version and lost in the newer version decrease_draw_match_count($team_id1); increase_lost_match_count($team_id1); } else { // team1 tied in the older version and also tied in the newer version -> nothing to do } } } } return true; } return false; }
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(); }