示例#1
0
/**
 * 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);
}
示例#2
0
            $cs_cups['squad1_id'] = isset($match['squad_id1']) ? $match['squad_id1'] : 0;
            $cs_cups['squad2_id'] = isset($match['squad_id2']) ? $match['squad_id2'] : 0;
            $cs_cups['cupmatches_loserbracket'] = $match['loserbracket'];
            $cs_cups['cupmatches_round'] = $match['round'];
            $cs_cups['cupmatches_tree_order'] = $match['tree_order'];
            $cs_cups['cupmatches_match'] = $matchnr;
            $cs_cups['cupmatches_nextmatch'] = $match['nextmatch'];
            $cs_cups['cupmatches_nextmatchlb'] = $match['nextmatchlb'];
            $cs_cups['cupmatches_seed1'] = $match['seed1'];
            $cs_cups['cupmatches_seed2'] = $match['seed2'];
            $cells = array_keys($cs_cups);
            $values = array_values($cs_cups);
            cs_sql_insert(__FILE__, 'cupmatches', $cells, $values);
        }
        /* autoclose the matches */
        cs_cups_autoclose($id);
    }
    cs_redirect($cs_lang['started_successfully'], 'cups', 'manage');
} else {
    $id = (int) $_GET['id'];
    $cupsel = cs_sql_select(__FILE__, 'cups', 'cups_teams, cups_system', 'cups_id = ' . $id);
    if ($cupsel['cups_system'] == CS_CUPS_TYPE_TEAMS) {
        // remove squads automatically which doesn't exist anymore in the database
        $del = cs_sql_select(__FILE__, 'cupsquads cq LEFT JOIN {pre}_squads sq ON cq.squads_id = sq.squads_id', 'cq.squads_id', 'sq.squads_id IS NULL AND cups_id = ' . $id, 0, 0, 0);
        if (!empty($del)) {
            foreach ($del as $del_id) {
                cs_sql_delete(__FILE__, 'cupsquads', $del_id['squads_id'], 'squads_id');
            }
        }
    }
    $squads_count = cs_sql_count(__FILE__, 'cupsquads', 'cupsquads_checkedin = 1 AND cups_id = ' . $id);
示例#3
0
     // 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);
 } 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);
示例#4
0
} elseif (isset($_GET['confirm']) && $teams_id > CS_CUPS_TEAM_BYE) {
    $cs_team = cs_sql_select(__FILE__, 'cupsquads', 'cups_id, squads_id', 'cupsquads_id = ' . $teams_id);
    $cs_cup = cs_sql_select(__FILE__, 'cups', 'cups_system, cups_name', 'cups_id = ' . $cs_team['cups_id']);
    /* get the open match if any */
    $cs_match = cs_sql_select(__FILE__, 'cupmatches', '*', '(squad1_id = ' . $cs_team['squads_id'] . ' OR squad2_id = ' . $cs_team['squads_id'] . ') AND cups_id = ' . $cs_team['cups_id'] . ' AND cupmatches_winner = ' . CS_CUPS_TEAM_UNKNOWN);
    if (!empty($cs_match['cupmatches_id'])) {
        $cells = array('squad1_id', 'squad2_id', 'cupmatches_score1', 'cupmatches_score2', 'cupmatches_accepted1', 'cupmatches_accepted2');
        /* set this team as a bye, let the autoclose code handle the rest */
        if ($cs_match['squad1_id'] == $cs_team['squads_id']) {
            $values = array(CS_CUPS_TEAM_BYE, $cs_match['squad2_id'], 0, 0, 0, 0);
        } else {
            $values = array($cs_match['squad1_id'], CS_CUPS_TEAM_BYE, 0, 0, 0, 0);
        }
        cs_sql_update(__FILE__, 'cupmatches', $cells, $values, $cs_match['cupmatches_id']);
        /* autoclose the match(es) */
        cs_cups_autoclose($cs_team['cups_id']);
    }
    cs_sql_delete(__FILE__, 'cupsquads', $teams_id);
    $messages_cells = array('users_id', 'messages_time', 'messages_subject', 'messages_text', 'users_id_to', 'messages_show_receiver');
    $messages_text = html_entity_decode(sprintf($cs_lang['team_removed_mail'], $cs_cup['cups_name']), ENT_QUOTES, $cs_main['charset']);
    if ($cs_cup['cups_system'] == CS_CUPS_TYPE_USERS) {
        $messages_values = array($account['users_id'], cs_time(), $cs_lang['team_removed'], $messages_text, $cs_team['squads_id'], '1');
        cs_sql_insert(__FILE__, 'messages', $messages_cells, $messages_values);
    } else {
        $cs_members = cs_sql_select(__FILE__, 'members', 'users_id', 'squads_id = ' . $teams_id, 0, 0, 0);
        $count_members = count($cs_members);
        for ($run = 0; $run < $count_members; $run++) {
            $messages_values = array($account['users_id'], cs_time(), $cs_lang['team_removed'], $messages_text, $cs_members[$run]['users_id'], '1');
            cs_sql_insert(__FILE__, 'messages', $messages_cells, $messages_values);
        }
    }