/** * Recursively close all matches with byes in a cup and update the matches accordingly */ function cs_cups_autoclose($cups_id, $level = 1) { $where = 'cups_id = ' . (int) $cups_id . ' AND ' . '(squad1_id = ' . CS_CUPS_TEAM_BYE . ' AND cupmatches_accepted1 = 0) OR ' . '(squad2_id = ' . CS_CUPS_TEAM_BYE . ' AND cupmatches_accepted2 = 0)'; $order = 'cupmatches_loserbracket ASC, cupmatches_round ASC, cupmatches_match ASC'; $select = cs_sql_select(__FILE__, 'cupmatches', '*', $where, $order, 0, 0); if (empty($select)) { /* no more matches, return the number of recursive loops */ return $level; } $changed = 0; foreach ($select as $match) { if ($match['squad2_id'] == CS_CUPS_TEAM_BYE) { if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { $changed++; /* always let first team win if both team are a bye */ $cells = array('cupmatches_accepted1', 'cupmatches_accepted2', 'cupmatches_winner', 'cupmatches_score1', 'cupmatches_score2'); $values = array(1, 1, $match['squad1_id'], 1, 0); cs_sql_update(__FILE__, 'cupmatches', $cells, $values, $match['cupmatches_id']); if ($match['cupmatches_nextmatch'] != CS_CUPS_NO_NEXTMATCH) { /* add winner team (coming from match in lb/wb) to the next wb/lb match */ cs_cups_addteam2match($cups_id, $match['squad1_id'], $match['cupmatches_match'], $match['cupmatches_round'], $match['cupmatches_loserbracket'], $match['cupmatches_nextmatch'], true); } if ($match['cupmatches_nextmatchlb'] != CS_CUPS_NO_NEXTMATCH) { /* add loser team to the next lb match */ cs_cups_addteam2match($cups_id, $match['squad2_id'], $match['cupmatches_match'], $match['cupmatches_round'], $match['cupmatches_loserbracket'], $match['cupmatches_nextmatchlb'], true); } } } else { if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { $changed++; $cells = array('cupmatches_accepted1', 'cupmatches_accepted2', 'cupmatches_winner', 'cupmatches_score1', 'cupmatches_score2'); $values = array(1, 1, $match['squad2_id'], 0, 1); cs_sql_update(__FILE__, 'cupmatches', $cells, $values, $match['cupmatches_id']); if ($match['cupmatches_nextmatch'] != CS_CUPS_NO_NEXTMATCH) { /* add winner team (coming from match in lb/wb) to the next wb/lb match */ cs_cups_addteam2match($cups_id, $match['squad2_id'], $match['cupmatches_match'], $match['cupmatches_round'], $match['cupmatches_loserbracket'], $match['cupmatches_nextmatch'], true); } if ($match['cupmatches_nextmatchlb'] != CS_CUPS_NO_NEXTMATCH) { /* add loser team to the next lb match */ cs_cups_addteam2match($cups_id, $match['squad1_id'], $match['cupmatches_match'], $match['cupmatches_round'], $match['cupmatches_loserbracket'], $match['cupmatches_nextmatchlb'], true); } } } } if ($changed == 0) { if (function_exists('cs_datacache_load')) { cs_datacache_clear('cups'); } return $level; } return cs_cups_autoclose($cups_id, $level + 1); }
$cs_match['cupmatches_accepted2'] = empty($_POST['cupmatches_accepted2']) ? 0 : 1; $cells = array_keys($cs_match); $values = array_values($cs_match); cs_sql_update(__FILE__, 'cupmatches', $cells, $values, $cupmatches_id); // Check for new round if (!empty($cs_match['cupmatches_accepted1']) && !empty($cs_match['cupmatches_accepted2'])) { $cs_match = cs_sql_select(__FILE__, 'cupmatches', '*', 'cupmatches_id = ' . $cupmatches_id, 0, 0, 1); $loser = $cs_match['cupmatches_winner'] == $cup_match['squad1_id'] ? $cup_match['squad2_id'] : $cup_match['squad1_id']; if ($cs_match['cupmatches_nextmatch'] != CS_CUPS_NO_NEXTMATCH) { /* add winner team to next match */ cs_cups_addteam2match($cs_match['cups_id'], $cs_match['cupmatches_winner'], $cs_match['cupmatches_match'], $cs_match['cupmatches_round'], $cs_match['cupmatches_loserbracket'], $cs_match['cupmatches_nextmatch'], true); $msg = $cs_lang['new_match']; } if ($cs_match['cupmatches_nextmatchlb'] != CS_CUPS_NO_NEXTMATCH) { /* add loser team to next match in LB */ cs_cups_addteam2match($cs_match['cups_id'], $loser, $cs_match['cupmatches_match'], $cs_match['cupmatches_round'], $cs_match['cupmatches_loserbracket'], $cs_match['cupmatches_nextmatchlb'], true); $msg = $cs_lang['new_match']; } /* close all defwin matches */ cs_cups_autoclose($cs_match['cups_id']); } echo $cs_lang['changes_done'] . '. '; $message = $cs_lang['changes_done'] . '. '; if (!empty($msg)) { $message .= ' ' . $msg; } // clear datacache if (function_exists('cs_datacache_load')) { cs_datacache_clear('cups'); } cs_redirect($message, 'cups', 'match', 'id=' . $cupmatches_id);