function cs_cups_addteam2match($cups_id, $teamid, $prevmatchid, $prevmatchround, $prevmatchlb, $matchid, $is_admin) { $return = true; $match = cs_sql_select(__FILE__, 'cupmatches', '*', 'cups_id = ' . $cups_id . ' AND cupmatches_match = ' . $matchid, 0, 0, 1); if (empty($match['cupmatches_id'])) { cs_error(__FILE__, 'ERROR: unknown match #' . $matchid . ' for cup #' . $cups_id, 1); return false; } /* get the other match which is referencing to this match */ $othermatch = cs_sql_select(__FILE__, 'cupmatches', '*', 'cups_id = ' . $cups_id . ' AND (cupmatches_nextmatch = ' . $matchid . ' OR cupmatches_nextmatchlb = ' . $matchid . ') AND cupmatches_match <> ' . $prevmatchid, 0, 0, 1); if (empty($match['cupmatches_id'])) { cs_error(__FILE__, 'ERROR: unknown other match for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); return false; } /* determine on which position this team has to be put */ if ($match['cupmatches_loserbracket'] == 0) { if ($match['cupmatches_match'] != 0) { /* this match is in the winner bracket, so both previous matches should be from the same round */ if ($prevmatchround != $othermatch['cupmatches_round']) { cs_error(__FILE__, 'ERROR: other match for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid . ' not in the same round', 1); $return = false; } /* place the team according to match number */ if ($prevmatchid < $othermatch['cupmatches_match']) { /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } else { /* grand final or 3rd place match */ if ($prevmatchlb == 1 || $othermatch['cupmatches_loserbracket'] == 1) { /* grand final, since one of them comes from a loserbracket */ if ($prevmatchlb == 0) { /* team coming from wb */ /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB GF: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB GF: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* team coming from lb */ /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB GF: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB GF: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } else { /* 3rd place match */ /* place the team according to match number */ if ($prevmatchid < $othermatch['cupmatches_match']) { /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB 3RD: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB 3RD: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB 3RD: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB 3RD: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } } } else { if ($prevmatchlb == 0 || $othermatch['cupmatches_loserbracket'] == 0) { /* one of them comes from the winner bracket, so it's a half round match */ if ($prevmatchlb == 0) { /* team comes from wb */ if ($othermatch['cupmatches_loserbracket'] == 0) { /* both come from wb (first round LB) */ if ($prevmatchid < $othermatch['cupmatches_match']) { /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB 1RD: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB 1RD: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB 1RD: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB 1RD: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } else { /* this team comes from wb, place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB FWB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB FWB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } } else { /* team comes from lb */ /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB FWB: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB FWB: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } else { /* both of them coming from LB */ /* place the team according to match number */ if ($prevmatchid < $othermatch['cupmatches_match']) { /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNIGN LB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } } /* we have determined the position */ $values = array($teamid); cs_sql_update(__FILE__, 'cupmatches', $cells, $values, $match['cupmatches_id']); if (function_exists('cs_datacache_load')) { cs_datacache_clear('cups'); } /* if there were any admin matchedits, fix tree recursively */ cs_cups_autofix($cups_id); return $return; }
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); } else { $tables = 'cupmatches cm INNER JOIN {pre}_cups cp ON cm.cups_id = cp.cups_id'; $cells = 'cp.cups_system AS cups_system'; $system = cs_sql_select(__FILE__, $tables, $cells, 'cm.cupmatches_id = ' . $cupmatches_id); $tables = 'cupmatches cm '; if ($system['cups_system'] == CS_CUPS_TYPE_TEAMS) { $tables .= 'LEFT JOIN {pre}_squads sq1 ON cm.squad1_id = sq1.squads_id '; $tables .= 'LEFT JOIN {pre}_squads sq2 ON cm.squad2_id = sq2.squads_id '; $tables .= 'LEFT JOIN {pre}_cupsquads cs1 ON cm.squad1_id = cs1.squads_id '; $tables .= 'LEFT JOIN {pre}_cupsquads cs2 ON cm.squad2_id = cs2.squads_id '; $cells = 'cm.squad1_id AS squad1_id, cm.squad2_id AS squad2_id, '; $cells .= 'sq1.squads_name AS squad1_name, sq2.squads_name AS squad2_name, '; } else {