コード例 #1
0
function MakeTeamsAbs($Societa, $Div, $Cl)
{
    $Errore = 0;
    if (is_null($Societa)) {
        $Errore = CreateTmpTeamsAndSnap();
        if ($Errore == 1) {
            return 1;
        }
    }
    $events4abs = array();
    /* simo */
    $Delete = "DELETE FROM " . "te, tc " . "USING " . "Teams AS te INNER JOIN TeamComponent AS tc " . "ON te.TeCoId=tc.TcCoId AND te.TeEvent=tc.TcEvent AND te.TeTournament=tc.TcTournament AND te.TeFinEvent=tc.TcFinEvent  " . "INNER JOIN (" . "SELECT EcCode AS sqEcCode, EcTournament AS sqEcTournament " . "FROM EventClass " . "WHERE " . "EcTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND EcTeamEvent<>0 " . (!is_null($Societa) ? " AND EcClass=" . StrSafe_DB($Cl) . " AND EcDivision=" . StrSafe_DB($Div) . " " : "") . ") AS sq ON te.TeEvent=sqEcCode AND te.TeTournament=sqEcTournament " . "WHERE " . "te.TeFinEvent=1 AND te.TeTournament=" . StrSafe_DB($_SESSION['TourId']) . " " . (!is_null($Societa) ? "AND te.TeCoId=" . StrSafe_DB($Societa) . " " : "");
    /* end simo */
    //print $Delete;exit;
    $Rs = safe_w_sql($Delete);
    //
    // Estraggo la lista di eventi per le finali a squadre
    $Select = "SELECT DISTINCT EcCode, EvPartialTeam, EvMultiTeam, EvMixedTeam, EvTeamCreationMode, EvRunning " . "FROM EventClass INNER JOIN Events ON EcCode=EvCode AND EvTeamEvent=1 AND EcTeamEvent!='0' AND EcTournament=EvTournament " . "WHERE EcTournament=" . StrSafe_DB($_SESSION['TourId']);
    if (!is_null($Societa)) {
        $Select .= " AND EcDivision=" . StrSafe_DB($Div) . " AND EcClass=" . StrSafe_DB($Cl) . " ";
    }
    $RsSel = safe_r_sql($Select);
    if (safe_num_rows($RsSel) > 0) {
        while ($RowEv = safe_fetch($RsSel)) {
            $EventCode = $RowEv->EcCode;
            if (!in_array($EventCode, $events4abs)) {
                /*
                 * Da questo array verranno tolti gli eventi ritornati da
                 * SetupTeamRank()
                 */
                $events4abs[] = $EventCode;
            }
            $MyQuery = 'SELECT EcCode, EcTeamEvent, EcNumber, EcDivision, EcClass ' . ' FROM EventClass ' . 'WHERE EcTournament = ' . StrSafe_DB($_SESSION['TourId']) . ' AND EcTeamEvent!=0 and EcCode=' . StrSafe_DB($EventCode) . ' ' . 'ORDER BY EcCode, EcTeamEvent, EcDivision, EcClass';
            $RsDef = safe_r_sql($MyQuery);
            if (!$RsDef) {
                $Errore = 1;
            } else {
                $TeamDef = array();
                $TeamNum = array();
                $TeamComponent = array();
                while ($MyRowDef = safe_fetch($RsDef)) {
                    if (!array_key_exists($MyRowDef->EcTeamEvent, $TeamDef)) {
                        $TeamDef[$MyRowDef->EcTeamEvent] = array();
                    }
                    $TeamDef[$MyRowDef->EcTeamEvent][] = $MyRowDef->EcDivision . "|" . $MyRowDef->EcClass;
                    $TeamPar[$MyRowDef->EcCode] = $RowEv->EvPartialTeam;
                    if (!array_key_exists($MyRowDef->EcTeamEvent, $TeamNum)) {
                        $TeamNum[$MyRowDef->EcTeamEvent] = $MyRowDef->EcNumber;
                    }
                }
                $MyQuery = '';
                foreach ($TeamDef as $key => $value) {
                    $ifc = ifSqlForCountry($RowEv->EvTeamCreationMode);
                    $MyQuery .= "(SELECT {$ifc} AS Country, " . $key . " as CheQuery, EnId, EnSubTeam, " . "QuScore, QuGold, QuXnine, QuHits, " . ($RowEv->EvRunning == 1 ? "(QuScore/QuHits)" : "QuScore") . " As ScoreCalc " . "FROM Entries INNER JOIN Qualifications ON EnId=QuId " . "WHERE EnAthlete=1 AND {$ifc}<>0 " . " AND " . ($RowEv->EvMixedTeam ? "EnTeamMixEvent" : "EnTeamFEvent") . "=1 " . " AND EnStatus <= 1 AND QuScore>0 AND EnTournament = " . StrSafe_DB($_SESSION['TourId']) . " AND " . " CONCAT(EnDivision, '|', EnClass) IN ('" . implode("', '", $value) . "')" . (!is_null($Societa) ? " AND {$ifc}=" . StrSafe_DB($Societa) : '') . ') ';
                    $MyQuery .= "UNION ALL ";
                }
                $MyQuery = substr($MyQuery, 0, -1 * strlen("UNION ALL ")) . "ORDER BY Country, EnSubTeam, CheQuery, ScoreCalc DESC, QuGold DESC, QuXnine DESC,EnId ASC ";
                //print $RowEv->EcCode . ":<br>" . $MyQuery. "<br><br>";//exit;
                $Rs = safe_r_sql($MyQuery);
                if (!$Rs) {
                    $Errore = 1;
                } else {
                    $CurTeam = 0;
                    //Codice team attuale
                    $CurSubTeam = $RowEv->EvMultiTeam ? 1 : 0;
                    //Codice Subteam attuale
                    $MaxSubTeam = 0;
                    $CntCheQuery = 0;
                    $CurSubQuery = 0;
                    //Codice team attuale
                    $TeamCount = array();
                    //contatore degli elementi trovati
                    $CurComponent = array();
                    //Componenti della Squadra
                    $Scores = array();
                    $Golds = array();
                    $XNines = array();
                    $Hits = array();
                    while ($MyRow = safe_fetch($Rs)) {
                        // Change Team
                        if ($CurTeam != $MyRow->Country || $MyRow->EnSubTeam != 0 && $CurSubTeam != $MyRow->EnSubTeam) {
                            if ($RowEv->EvPartialTeam == 1) {
                                foreach ($TeamCount as $k => $value) {
                                    if (array_sum($TeamCount[$k]) > 0) {
                                        //Insert Partial Team if not complete yet
                                        WriteTeamAbs($CurTeam, $k, $CurComponent[$k], $EventCode, $Scores[$k], $Golds[$k], $XNines[$k], $Hits[$k]);
                                    }
                                }
                            }
                            $CurTeam = $MyRow->Country;
                            $CurSubTeam = $MyRow->EnSubTeam != 0 ? $MyRow->EnSubTeam : ($RowEv->EvMultiTeam ? 1 : 0);
                            $MaxSubTeam = 0;
                            $CntCheQuery = 0;
                            $CurSubQuery = $MyRow->CheQuery;
                            $TeamCount = array();
                            $CurComponent = array();
                            $Scores = array();
                            $Golds = array();
                            $XNines = array();
                            $Hits = array();
                            $TeamCount[$CurSubTeam] = $TeamNum;
                            $CurComponent[$CurSubTeam] = array();
                            $Scores[$CurSubTeam] = array();
                            $Golds[$CurSubTeam] = array();
                            $XNines[$CurSubTeam] = array();
                            $Hits[$CurSubTeam] = array();
                        }
                        //Multiteam Management
                        if ($MyRow->EnSubTeam == 0 && $RowEv->EvMultiTeam && ($TeamCount[$CurSubTeam][$MyRow->CheQuery] == 0 || $CurSubQuery != $MyRow->CheQuery)) {
                            if ($CurSubQuery == $MyRow->CheQuery) {
                                $CurSubTeam++;
                            } else {
                                $CurSubTeam = 1;
                            }
                            if (empty($TeamCount[$CurSubTeam])) {
                                $TeamCount[$CurSubTeam] = $TeamNum;
                                $CurComponent[$CurSubTeam] = array();
                                $Scores[$CurSubTeam] = array();
                                $Golds[$CurSubTeam] = array();
                                $XNines[$CurSubTeam] = array();
                                $Hits[$CurSubTeam] = array();
                            }
                            $CurSubQuery = $MyRow->CheQuery;
                            //Manage the subQueryCounter
                        }
                        //Looking for team components
                        if (array_sum($TeamCount[$CurSubTeam]) > 0) {
                            if ($TeamCount[$CurSubTeam][$MyRow->CheQuery] > 0) {
                                $CurComponent[$CurSubTeam][] = $MyRow->EnId;
                                $Scores[$CurSubTeam][] = $MyRow->QuScore;
                                $Golds[$CurSubTeam][] = $MyRow->QuGold;
                                $XNines[$CurSubTeam][] = $MyRow->QuXnine;
                                $Hits[$CurSubTeam][] = $MyRow->QuHits;
                                $TeamCount[$CurSubTeam][$MyRow->CheQuery]--;
                                //If we have everybody, we save....
                                if (array_sum($TeamCount[$CurSubTeam]) == 0) {
                                    WriteTeamAbs($CurTeam, $CurSubTeam, $CurComponent[$CurSubTeam], $EventCode, $Scores[$CurSubTeam], $Golds[$CurSubTeam], $XNines[$CurSubTeam], $Hits[$CurSubTeam]);
                                }
                            }
                        }
                    }
                    if ($RowEv->EvPartialTeam == 1) {
                        foreach ($TeamCount as $k => $value) {
                            if (array_sum($TeamCount[$k]) > 0) {
                                //Insert Partial Team if not complete yet
                                WriteTeamAbs($CurTeam, $k, $CurComponent[$k], $EventCode, $Scores[$k], $Golds[$k], $XNines[$k], $Hits[$k]);
                            }
                        }
                    }
                }
            }
        }
    }
    Obj_RankFactory::create('AbsTeam', array('events' => $events4abs))->calculate();
    if ($Errore == 0 && is_null($Societa)) {
        $tmp = FindTeamEventsWithNull();
        if ($tmp === false) {
            $Errore = 1;
        } else {
            $Errore = SetupShootoff($tmp);
            if ($Errore == 0) {
                $toRemove = SetupTeamsRank($tmp);
                if ($toRemove !== false) {
                    foreach ($toRemove as $e) {
                        if (($x = array_search($e, $events4abs)) !== false) {
                            unset($events4abs[$x]);
                        }
                    }
                }
            }
        }
        DropTmpTeams();
    }
    return $Errore;
}
コード例 #2
0
ファイル: UploadResults.php プロジェクト: brian-nelson/ianseo
        continue;
    }
    $outputIndFin .= '<input type="checkbox" name="FinalInd[]" value="' . $FinCode . '" id="' . $FinCode . '"' . (empty($_POST['FinalInd']) || !in_array($FinCode, $_POST['FinalInd']) ? '' : 'checked="checked"') . '>' . $MyRow->EvEventName . '<br/>' . "\n";
    $outputIndBra .= '<input type="checkbox" name="BracketsInd[]" value="' . $BraCode . '" id="' . $BraCode . '"' . (empty($_POST['BracketsInd']) || !in_array($BraCode, $_POST['BracketsInd']) ? '' : 'checked="checked"') . '>' . $MyRow->EvEventName . '<br/>' . "\n";
}
// select the ACTUAL Team Events
$Sql = "SELECT EvCode, EvEventName, EvMixedTeam, EvMultiTeam, EvMaxTeamPerson,EvTeamCreationMode,EvFinalFirstPhase FROM Events WHERE EvTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND EvTeamEvent=1 ORDER BY EvProgr";
$RsEv = safe_r_sql($Sql);
while ($MyRowEv = safe_fetch($RsEv)) {
    $Sql = "SELECT DISTINCT EcCode, EcTeamEvent, EcNumber FROM EventClass WHERE EcCode=" . StrSafe_DB($MyRowEv->EvCode) . " AND EcTeamEvent!=0 AND EcTournament=" . StrSafe_DB($_SESSION['TourId']);
    $RsEc = safe_r_sql($Sql);
    if (safe_num_rows($RsEc) > 0) {
        $RuleCnt = 0;
        $Sql = "Select * ";
        while ($MyRowEc = safe_fetch($RsEc)) {
            $ifc = ifSqlForCountry($MyRowEv->EvTeamCreationMode);
            $Sql .= ++$RuleCnt == 1 ? "FROM " : "INNER JOIN ";
            //				$Sql .= "(SELECT IF(EnCountry2=0,EnCountry,EnCountry2) as C" . $RuleCnt . ", SUM(IF(EnSubTeam=0,1,0)) AS QuantiMulti
            //					  FROM Entries
            //					  INNER JOIN EventClass ON EnClass=EcClass AND EnDivision=EcDivision AND EnTournament=EcTournament AND EcTeamEvent=" . $MyRowEc->EcTeamEvent . " AND EcCode=" . StrSafe_DB($MyRowEc->EcCode) . "
            //					  WHERE EnTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND EnTeam" . ($MyRowEv->EvMixedTeam ? 'Mix' : 'F') ."Event=1
            //					  group by IF(EnCountry2=0,EnCountry,EnCountry2), EnSubTeam
            //					  HAVING COUNT(EnId)>=" . $MyRowEc->EcNumber . ") as sqy";
            //				$Sql .= ($RuleCnt == 1 ? " ": $RuleCnt . " ON C1=C". $RuleCnt . " ");
            $Sql .= "(SELECT {$ifc} as C" . $RuleCnt . ", SUM(IF(EnSubTeam=0,1,0)) AS QuantiMulti\n\t\t\t\t\t  FROM Entries\n\t\t\t\t\t  INNER JOIN EventClass ON EnClass=EcClass AND EnDivision=EcDivision AND EnTournament=EcTournament AND EcTeamEvent=" . $MyRowEc->EcTeamEvent . " AND EcCode=" . StrSafe_DB($MyRowEc->EcCode) . "\n\t\t\t\t\t  WHERE {$ifc}<>0 AND EnTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND EnTeam" . ($MyRowEv->EvMixedTeam ? 'Mix' : 'F') . "Event=1\n\t\t\t\t\t  group by {$ifc}, EnSubTeam\n\t\t\t\t\t  HAVING COUNT(EnId)>=" . $MyRowEc->EcNumber . ") as sqy";
            $Sql .= $RuleCnt == 1 ? " " : $RuleCnt . " ON C1=C" . $RuleCnt . " ";
        }
        $Sql .= " limit 1";
        $Rs = safe_r_sql($Sql);
        if (safe_num_rows($Rs)) {
            $QualCode = 'TQ' . $MyRowEv->EvCode;
コード例 #3
0
ファイル: OrisFunctions.php プロジェクト: brian-nelson/ianseo
function getStatEntriesByEvent($ORIS = '')
{
    $Data = new StdClass();
    $Data->Code = 'C30A';
    $Data->Order = '2';
    $Data->Description = 'Number of Entries by Event';
    $Data->Continue = get_text('Continue');
    $Data->Data = array();
    if ($ORIS) {
        // Individuals
        $Data->Header = array("Event", "No. Athletes", "No. Countries", "No. Teams");
        $Data->HeaderWidth = array(60, 40, 40, 40);
        $MyQuery = getStatEntriesByEventQuery('IF');
        $Rs = safe_r_sql($MyQuery);
        while ($Row = safe_fetch($Rs)) {
            $Data->Data[$Row->Code] = array('Name' => $Row->EventName, 'Number' => $Row->Quanti, 'Countries' => $Row->Countries, 'Teams' => 0);
        }
        // Teams
        $Teams = array();
        $MyQuery = getStatEntriesByEventQuery('TF');
        $RsEv = safe_r_sql($MyQuery);
        while ($MyRowEv = safe_fetch($RsEv)) {
            $Sql = "SELECT DISTINCT EcCode, EcTeamEvent, EcNumber FROM EventClass WHERE EcCode=" . StrSafe_DB($MyRowEv->EvCode) . " AND EcTeamEvent!=0 AND EcTournament=" . StrSafe_DB($_SESSION['TourId']);
            $RsEc = safe_r_sql($Sql);
            if (safe_num_rows($RsEc) > 0) {
                $RuleCnt = 0;
                $Sql = "Select * ";
                while ($MyRowEc = safe_fetch($RsEc)) {
                    $ifc = ifSqlForCountry($MyRowEv->EvTeamCreationMode);
                    $Sql .= ++$RuleCnt == 1 ? "FROM " : "INNER JOIN ";
                    $Sql .= "(SELECT {$ifc} as C" . $RuleCnt . ", SUM(IF(EnSubTeam=0,1,0)) AS QuantiMulti\n\t\t\t\t\t  FROM Entries\n\t\t\t\t\t  INNER JOIN EventClass ON EnClass=EcClass AND EnDivision=EcDivision AND EnTournament=EcTournament AND EcTeamEvent=" . $MyRowEc->EcTeamEvent . " AND EcCode=" . StrSafe_DB($MyRowEc->EcCode) . "\n\t\t\t\t\t\t\t  WHERE {$ifc}<>0 AND EnTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND EnTeam" . ($MyRowEv->EvMixedTeam ? 'Mix' : 'F') . "Event=1\n\t\t\t\t\t\t\t  \t\tgroup by {$ifc}, EnSubTeam\n\t\t\t\t\t\t\t  \t\tHAVING COUNT(EnId)>=" . $MyRowEc->EcNumber . ") as sqy";
                    $Sql .= $RuleCnt == 1 ? " " : $RuleCnt . " ON C1=C" . $RuleCnt . " ";
                }
                $Rs = safe_r_sql($Sql);
                $tmpQuanti = safe_num_rows($Rs);
                $Countries = $tmpQuanti;
                if ($MyRowEv->EvMultiTeam != 0) {
                    $tmpQuanti = 0;
                    while ($tmpRow = safe_fetch($Rs)) {
                        $Countries++;
                        $tmpQuanti += intval($tmpRow->QuantiMulti / $MyRowEv->EvMaxTeamPerson);
                    }
                }
                $tmpSaved = valueFirstPhase($MyRowEv->FirstPhase) == $MyRowEv->FirstPhase ? 0 : 8;
                $tmpQuantiIn = maxPhaseRank($MyRowEv->FirstPhase);
                $tmpQuantiOut = $tmpQuanti - $tmpQuantiIn;
                $tmpMatch = min($tmpQuantiIn, $tmpQuanti) - $tmpSaved - $MyRowEv->FirstPhase;
                $tmpBye = $MyRowEv->FirstPhase - $tmpMatch;
                $Teams[$MyRowEv->EvCode] = array('Name' => $MyRowEv->EventName, 'Number' => $tmpQuanti, 'Countries' => $Countries);
            }
        }
        foreach ($Teams as $EvCode => $Items) {
            if (empty($Data->Data[$EvCode])) {
                $Data->Data[$EvCode] = array('Name' => $Items['Name'], 'Number' => 0, 'Countries' => $Items['Countries'], 'Teams' => $Items['Number']);
            } else {
                $Data->Data[$EvCode]['Teams'] = $Items['Number'];
            }
        }
    } else {
        // Start with Qualification Rounds
        $MyQuery = getStatEntriesByEventQuery('QR');
        $QR = array();
        $QR['Title'] = get_text('StatEvents', 'Tournament');
        $QR['SubTitle'] = array(get_text('Individual'), get_text('Team'));
        $QR['Div'] = array();
        $QR['Cls'] = array();
        $QR['Data'] = array();
        $Rs = safe_r_sql($MyQuery);
        while ($Row = safe_fetch($Rs)) {
            if (!in_array($Row->Divisione, $QR['Div'])) {
                $QR['Div'][] = $Row->Divisione;
            }
            if (!in_array($Row->Classe, $QR['Cls'])) {
                $QR['Cls'][] = $Row->Classe;
            }
            $QR['Data'][$Row->Divisione][$Row->Classe] = array($Row->QuantiInd, $Row->QuantiSq);
        }
        $Data->Data['QR'] = $QR;
        // Go with Individual Finals
        $MyQuery = getStatEntriesByEventQuery('IF');
        $QR = array();
        $QR['Title'] = get_text('IndFinal');
        $QR['SubTitle'] = array(get_text('EvName'), get_text('Athletes'), get_text('FirstPhase'), get_text('FirstPhaseMatchesBye', 'Tournament'), get_text('FirstPhaseInOut', 'Tournament'));
        $QR['Data'] = array();
        $Rs = safe_r_sql($MyQuery);
        while ($Row = safe_fetch($Rs)) {
            $tmpSaved = valueFirstPhase($Row->FirstPhase) == $Row->FirstPhase ? 0 : 8;
            $tmpQuantiIn = maxPhaseRank($Row->FirstPhase);
            $tmpQuantiOut = $Row->Quanti - $tmpQuantiIn;
            $tmpMatch = min($tmpQuantiIn, $Row->Quanti) - $tmpSaved - $Row->FirstPhase;
            $tmpBye = $Row->FirstPhase - $tmpMatch;
            $QR['Data'][$Row->Code] = array('Name' => $Row->EventName, 'FirstPhase' => $Row->FirstPhase, 'Number' => $Row->Quanti, 'Invalid' => $tmpMatch <= 0, 'Phase' => $Row->FirstPhase == 0 ? "" : get_text(namePhase($Row->FirstPhase, $Row->FirstPhase) . '_Phase'), 'Matches' => $Row->FirstPhase == 0 ? "" : $tmpMatch, 'Byes' => $Row->FirstPhase == 0 || $tmpMatch < 0 ? "" : ($tmpBye + $tmpSaved == 0 ? '' : '(' . $tmpBye . ($tmpSaved != 0 ? '+' . $tmpSaved : '') . ')'), 'ArchersIn' => $Row->FirstPhase == 0 ? "" : ($Row->Quanti < $tmpQuantiIn ? $Row->Quanti : $tmpQuantiIn), 'ArchersOut' => $Row->FirstPhase == 0 ? "" : ($tmpQuantiOut > 0 ? '(' . $tmpQuantiOut . ')' : '-----'));
        }
        $Data->Data['IF'] = $QR;
        // Go with Team Finals
        $QR = array();
        $QR['Title'] = get_text('TeamFinal');
        $QR['SubTitle'] = array(get_text('EvName'), get_text('MixedTeamEvent'), get_text('Teams'), get_text('FirstPhase'), get_text('FirstPhaseMatchesBye', 'Tournament'), get_text('FirstPhaseInOut', 'Tournament'));
        $QR['Data'] = array();
        $MyQuery = getStatEntriesByEventQuery('TF');
        $RsEv = safe_r_sql($MyQuery);
        while ($MyRowEv = safe_fetch($RsEv)) {
            $Sql = "SELECT DISTINCT EcCode, EcTeamEvent, EcNumber FROM EventClass WHERE EcCode=" . StrSafe_DB($MyRowEv->EvCode) . " AND EcTeamEvent!=0 AND EcTournament=" . StrSafe_DB($_SESSION['TourId']);
            $RsEc = safe_r_sql($Sql);
            if (safe_num_rows($RsEc) > 0) {
                $RuleCnt = 0;
                $Sql = "Select * ";
                while ($MyRowEc = safe_fetch($RsEc)) {
                    $ifc = ifSqlForCountry($MyRowEv->EvTeamCreationMode);
                    $Sql .= ++$RuleCnt == 1 ? "FROM " : "INNER JOIN ";
                    $Sql .= "(SELECT {$ifc} as C" . $RuleCnt . ", SUM(IF(EnSubTeam=0,1,0)) AS QuantiMulti\n\t\t\t\t\t  FROM Entries\n\t\t\t\t\t  INNER JOIN EventClass ON EnClass=EcClass AND EnDivision=EcDivision AND EnTournament=EcTournament AND EcTeamEvent=" . $MyRowEc->EcTeamEvent . " AND EcCode=" . StrSafe_DB($MyRowEc->EcCode) . "\n\t\t\t\t\t\t  WHERE {$ifc}<>0 AND EnTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND EnTeam" . ($MyRowEv->EvMixedTeam ? 'Mix' : 'F') . "Event=1\n\t\t\t\t\t\t  group by {$ifc}, EnSubTeam\n\t\t\t\t\t\t  HAVING COUNT(EnId)>=" . $MyRowEc->EcNumber . ") as sqy";
                    $Sql .= $RuleCnt == 1 ? " " : $RuleCnt . " ON C1=C" . $RuleCnt . " ";
                }
                $Rs = safe_r_sql($Sql);
                $tmpQuanti = safe_num_rows($Rs);
                if ($MyRowEv->EvMultiTeam != 0) {
                    $tmpQuanti = 0;
                    while ($tmpRow = safe_fetch($Rs)) {
                        $tmpQuanti += intval($tmpRow->QuantiMulti / $MyRowEv->EvMaxTeamPerson);
                    }
                }
                $tmpSaved = valueFirstPhase($MyRowEv->FirstPhase) == $MyRowEv->FirstPhase ? 0 : 8;
                $tmpQuantiIn = maxPhaseRank($MyRowEv->FirstPhase);
                $tmpQuantiOut = $tmpQuanti - $tmpQuantiIn;
                $tmpMatch = min($tmpQuantiIn, $tmpQuanti) - $tmpSaved - $MyRowEv->FirstPhase;
                $tmpBye = $MyRowEv->FirstPhase - $tmpMatch;
                $QR['Data'][$MyRowEv->EvCode] = array('Name' => $MyRowEv->EventName, 'Number' => $tmpQuanti, 'Invalid' => $tmpMatch <= 0, 'FirstPhase' => $MyRowEv->FirstPhase == 0 ? "" : get_text(namePhase($MyRowEv->FirstPhase, $MyRowEv->FirstPhase) . '_Phase'), 'Matches' => $MyRowEv->FirstPhase == 0 ? "" : $tmpMatch, 'Byes' => $MyRowEv->FirstPhase == 0 || $tmpMatch < 0 ? "" : '(' . $tmpBye . ($tmpSaved != 0 ? '+' . $tmpSaved : '') . ')', 'ArchersIn' => $MyRowEv->FirstPhase == 0 ? "" : ($tmpQuanti < $tmpQuantiIn ? $tmpQuanti : $tmpQuantiIn), 'ArchersOut' => $MyRowEv->FirstPhase == 0 ? "" : ($tmpQuantiOut > 0 ? '(' . $tmpQuantiOut . ')' : '---'), 'MixedTeam' => get_text($MyRowEv->EvMixedTeam ? 'Yes' : 'No'));
            }
        }
        $Data->Data['TF'] = $QR;
    }
    return $Data;
}