function handle_edit_match() { $defaults = array('id' => 0, 'game_id' => 0, 'title' => '', 'description' => '', 'external_url' => '', 'date' => Utils::current_time_fixed('timestamp', 0), 'team1' => 0, 'team2' => 0, 'new_team_title' => '', 'new_team_country' => '', 'match_status' => 0, 'scores' => array(), 'gallery' => array()); extract(Utils::extract_args(stripslashes_deep($_POST), $defaults)); $date = Utils::date_array2time_helper($date); if (!empty($new_team_title) && !empty($new_team_country)) { $pickteam = $this->quick_pick_team($new_team_title, $new_team_country); if ($pickteam > 0) { $team2 = $pickteam; } } $model = array('title' => $title, 'date' => date('Y-m-d H:i:s', $date), 'team1' => $team1, 'team2' => $team2, 'game_id' => $game_id, 'match_status' => $match_status, 'description' => $description, 'external_url' => $external_url); \WP_Clanwars\Matches::update_match($id, $model); $rounds_not_in = array(); foreach ($scores as $round_group => $r) { $num_rounds = sizeof($r['team1']); for ($i = 0; $i < $num_rounds; $i++) { $round_id = $r['round_id'][$i]; $model = array('match_id' => $id, 'group_n' => abs($round_group), 'map_id' => $r['map_id'], 'tickets1' => $r['team1'][$i], 'tickets2' => $r['team2'][$i]); if ($round_id > 0) { \WP_Clanwars\Rounds::update_round($round_id, $model); $rounds_not_in[] = $round_id; } else { $new_round = \WP_Clanwars\Rounds::add_round($model); if ($new_round !== false) { $rounds_not_in[] = $new_round; } } } } \WP_Clanwars\Rounds::delete_rounds_not_in($id, $rounds_not_in); \WP_Clanwars\Matches::update_match_post($id, $gallery); Flash::success(__('Updated a match.', WP_CLANWARS_TEXTDOMAIN)); wp_redirect(admin_url('admin.php?page=wp-clanwars-matches&act=edit&id=' . $id)); exit; }