$Sql .= $RuleCnt == 1 ? " " : $RuleCnt . " ON C1=C" . $RuleCnt . " "; } $Rs = safe_r_sql($Sql); $tmpQuanti = safe_num_rows($Rs); $pdf->SetFont($pdf->FontStd, '', 8); $pdf->Cell(15, 5, $MyRowEv->EvCode, 1, 0, 'C', 1); $pdf->Cell($DivSize * 4 / 3, 5, $MyRowEv->EventName, 1, 0, 'L', 0); if ($MyRowEv->EvMultiTeam != 0) { $tmpQuanti = 0; while ($tmpRow = safe_fetch($Rs)) { $tmpQuanti += intval($tmpRow->QuantiMulti / $MyRowEv->EvMaxTeamPerson); } } $pdf->Cell($DivSize * 2 / 3, 5, $tmpQuanti, 1, 0, 'R', 0); $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; $pdf->Cell($DivSize, 5, $MyRowEv->FirstPhase == 0 ? "" : get_text(namePhase($MyRowEv->FirstPhase, $MyRowEv->FirstPhase) . '_Phase'), 1, 0, 'R', $tmpMatch <= 0 ? 1 : 0); $pdf->Cell($DivSize / 2, 5, $MyRowEv->FirstPhase == 0 ? "" : $tmpMatch, 'TBL', 0, 'R', $tmpMatch <= 0 ? 1 : 0); $pdf->Cell($DivSize / 2, 5, $MyRowEv->FirstPhase == 0 || $tmpMatch < 0 ? "" : '(' . $tmpBye . ($tmpSaved != 0 ? '+' . $tmpSaved : '') . ')', 'TBR', 0, 'R', $tmpMatch <= 0 ? 1 : 0); $pdf->Cell($DivSize / 2, 5, $MyRowEv->FirstPhase == 0 ? "" : ($tmpQuanti < $tmpQuantiIn ? $tmpQuanti : $tmpQuantiIn), 'TBL', 0, 'R', $tmpMatch <= 0 ? 1 : 0); $pdf->Cell($DivSize / 2, 5, $MyRowEv->FirstPhase == 0 ? "" : ($tmpQuantiOut > 0 ? '(' . $tmpQuantiOut . ')' : '---'), 'TBR', 0, 'R', $tmpMatch <= 0 ? 1 : 0); $pdf->Cell($DivSize, 5, get_text($MyRowEv->EvMixedTeam ? 'Yes' : 'No'), 1, 1, 'C', 0); } } } if (!isset($isCompleteResultBook)) { $pdf->Output(); }
function SetTargetDb($Key, $Value) { $ret = ''; $Errore = 0; $Target = ''; $Phase = ''; $firstPhase = ''; $realPhase = ''; $Event = ''; $Which = $Key; $Campo = ''; $ee = ''; $mm = ''; // matchno estratto $ath = ''; // ath per bersaglio (0 --> 1; 1 --> 2) list(, $Campo, $ee, $mm, $ath) = explode('_', $Key); $Event = $ee; // cerco la fase del matchno $Select = "SELECT GrPhase FROM Grids WHERE GrMatchNo=" . StrSafe_DB($mm) . " "; $Rs = safe_r_sql($Select); if (safe_num_rows($Rs) == 1) { $MyRow = safe_fetch($Rs); $Phase = $MyRow->GrPhase; $realPhase = $Phase; $firstPhase = getFirstPhase($Event, 0); if (valueFirstPhase($firstPhase) != $firstPhase && $Phase > 16) { $realPhase = $Phase == 32 ? 24 : ($Phase == 64 ? 48 : $Phase); } } // if target is followed by a "+" sign fills up the phase from this point up to the last with increments of 1 if (substr($Value, -1) == '+') { $Value = intval($Value); $val = $Value; foreach (range($mm, $Phase * 4 - 1, $ath + 1) as $n) { $ret .= SetTargetDb('d_' . $Campo . '_' . $ee . '_' . $n . '_' . $ath, $val++); } return $ret; } elseif (substr($Value, -1) == '*') { $Value = intval($Value); $mm = 2 * floor($mm / 2); $val = $Value; $z = 1; foreach (range($mm, $Phase * 4 - 1, $ath + 1) as $n) { $ret .= SetTargetDb('d_' . $Campo . '_' . $ee . '_' . $n . '_' . $ath, $val++); $z = 1 - $z; if ($z) { $val++; } } return $ret; } elseif (substr($Value, -1) == '-') { // recupera gli scontri senza bye... // lo scontro parte da un numero pari $mm = 2 * floor($mm / 2); $Value = intval($Value); $val = $Value; // cerca i byes, quindi va a prendere la differenza tra il numero di atleti della fase e gli atleti presenti in quell'evento $MyQuery = "SELECT COUNT(EnId) as Quanti, EvFinalFirstPhase as FirstPhase\r\n\t\t\tFROM Events\r\n\t\t\tINNER JOIN EventClass ON EvCode=EcCode AND EvTeamEvent=EcTeamEvent AND EvTournament=EcTournament\r\n\t\t\tINNER JOIN Individuals ON EvCode=IndEvent AND EvTournament=IndTournament\r\n\t\t\tINNER JOIN Entries ON EnId=IndId AND EnTournament=IndTournament AND EcClass=EnClass AND EcDivision=EnDivision\r\n\t\t\tWHERE EvTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND EcCode=" . StrSafe_DB($ee) . " AND EvTeamEvent=0 AND ((EnIndFEvent=1 AND EnStatus<=1) OR EnId IS NULL)"; $q = safe_r_sql($MyQuery); $r = safe_fetch($q); //debug_svela($MyQuery, true); $tmpQuanti = $r->Quanti; $tmpSaved = $Phase <= 16 ? 0 : (valueFirstPhase($r->FirstPhase) == $r->FirstPhase ? 0 : 8); $tmpQuantiIn = maxPhaseRank($realPhase); $tmpQuantiOut = $tmpQuanti - $tmpQuantiIn; $tmpBye = ($tmpQuantiOut < 0 ? abs($tmpQuantiOut) : 0) + $tmpSaved; //echo $Phase . ",". $tmpQuanti . "," . $tmpSaved . "," . $tmpQuantiIn . "," . $tmpQuantiOut . "," . $tmpBye; exit; // if($tmpBye<=0 && $tmpSaved<=0) { // NON ci sono byes, quindi fa il responso normale... //debug_svela(array($Key, $Value)); // return SetTargetDb($Key, $Value.'+'); // } // ci sono byes, quindi va a riempire solo i matchno dei match pieni cioè con una rank superiore all'ultimo bye! // esempio: 1/8, 13 presenti, sono 3 byes, quindi si parte dal 4° in ranking... // $MyQuery = 'SELECT distinct ' . ' GrMatchNo, ' . ($firstPhase == 48 || $firstPhase == 24 ? 'GrPosition2' : 'GrPosition') . ' as Position' . ' FROM Grids' . ' WHERE ' . " GrPhase = '{$Phase}' " . " AND GrMatchNo>= {$mm} " . ' ORDER BY GrMatchNo ASC'; $q = safe_r_sql($MyQuery); while ($r = safe_fetch($q)) { $butt = $r->Position <= $tmpBye || $r->Position > $tmpQuanti ? '' : $val; if (!$ath or !($r->GrMatchNo % 2)) { if ($r->Position > $tmpBye) { $ret .= SetTargetDb('d_' . $Campo . '_' . $ee . '_' . $r->GrMatchNo . '_' . $ath, $butt); if ($butt) { $val++; } } else { $ret .= SetTargetDb('d_' . $Campo . '_' . $ee . '_' . $r->GrMatchNo . '_' . $ath, ''); $ret .= '<field>'; $ret .= '<error>0</error>' . "\n"; $ret .= '<org>d_' . $Campo . '_' . $ee . '_' . $r->GrMatchNo . '_' . $ath . ' - </org>' . "\n"; $ret .= '<which><![CDATA[d_' . $Campo . '_' . $ee . '_' . $r->GrMatchNo . '_' . $ath . ']]></which>' . "\n"; $ret .= '<target><![CDATA[]]></target>' . "\n"; $ret .= '<phase><![CDATA[' . $Phase . ']]></phase>' . "\n"; $ret .= '<event><![CDATA[' . $Event . ']]></event>' . "\n"; $ret .= '</field>'; } } } return $ret; } // verifico che il target sia un numero vero if (preg_match('/^[0-9]{1,' . TargetNoPadding . '}$/i', $Value) || strlen(trim($Value)) == 0) { if (strlen(trim($Value)) > 0) { $Target = str_pad($Value, TargetNoPadding, '0', STR_PAD_LEFT); } // scrivo il target $Insert = "INSERT INTO FinSchedule (FSEvent,FSTeamEvent,FSMatchNo,FSTournament,FSTarget, FSLetter) " . "VALUES(" . StrSafe_DB($ee) . "," . StrSafe_DB('0') . "," . StrSafe_DB($mm) . "," . StrSafe_DB($_SESSION['TourId']) . "," . StrSafe_DB($Target) . "," . StrSafe_DB($Target ? $Target : '') . "" . ") " . "ON DUPLICATE KEY UPDATE " . "FSTarget=" . StrSafe_DB($Target) . "," . "FSGroup=FSGroup," . "FSLetter=" . StrSafe_DB($Target ? $Target : '') . ", " . "FSScheduledTime=FSScheduledTime "; $Rs = safe_w_sql($Insert); if (debug) { print $Insert . '<br>'; } if (!$Rs) { $Errore = 1; } else { if ($ath == 1) { $Insert = "INSERT INTO FinSchedule (FSEvent,FSTeamEvent,FSMatchNo,FSTournament,FSTarget, FSLetter) " . "VALUES(" . StrSafe_DB($ee) . "," . StrSafe_DB('0') . "," . StrSafe_DB($mm + 1) . "," . StrSafe_DB($_SESSION['TourId']) . "," . StrSafe_DB($Target) . "," . StrSafe_DB($Target ? $Target . 'B' : '') . "" . ") " . "ON DUPLICATE KEY UPDATE " . "FSTarget=" . StrSafe_DB($Target) . "," . "FSGroup=FSGroup," . "FSLetter=" . StrSafe_DB($Target ? $Target . 'B' : '') . ", " . "FSScheduledTime=FSScheduledTime "; $Rs = safe_w_sql($Insert); if (!$Rs) { $Errore = 1; } $Update = "update FinSchedule " . " SET " . " FSLetter=" . StrSafe_DB($Target ? $Target . 'A' : '') . " " . "WHERE" . " FSEvent= " . StrSafe_DB($ee) . " AND FSTeamEvent= " . StrSafe_DB('0') . " AND FSMatchNo= " . StrSafe_DB($mm) . " AND FSTournament= " . StrSafe_DB($_SESSION['TourId']); $Rs = safe_w_sql($Update); if (!$Rs) { $Errore = 1; } } } } else { $Errore = 1; } $ret .= '<field>'; $ret .= '<error>' . $Errore . '</error>' . "\n"; $ret .= '<org>' . $Key . ' - ' . $Value . '</org>' . "\n"; $ret .= '<which><![CDATA[' . $Which . ']]></which>' . "\n"; $ret .= '<target><![CDATA[' . $Target . ']]></target>' . "\n"; $ret .= '<phase><![CDATA[' . $Phase . ']]></phase>' . "\n"; $ret .= '<event><![CDATA[' . $Event . ']]></event>' . "\n"; $ret .= '</field>'; return $ret; }
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; }