function DefineForcePrintouts($TourId)
{
    $q = safe_r_SQL("select ToPrintLang from Tournament where ToId={$TourId}");
    $r = safe_fetch($q);
    @define('PRINTLANG', $r->ToPrintLang);
}
function UpdatePreOpen($TournamentID)
{
    // checks if the structure of the database is consistent
    //	CheckDbStructure();
    $DbVersion = GetParameter('DBUpdate');
    $rs = safe_r_SQL("SELECT ToDbVersion, ToType, ToNumSession FROM Tournament WHERE ToId='{$TournamentID}'");
    $row = safe_fetch($rs);
    $version = $row->ToDbVersion;
    if ($version < '2010-11-26 15:50:00') {
        updateEnTimeStamp_20101126($TournamentID);
        to_save_version($TournamentID, '2010-11-26 15:50:00');
    }
    if ($version < '2010-12-11 20:30:00') {
        recalculateIndividuals_20101211($TournamentID);
        to_save_version($TournamentID, '2010-12-11 20:30:00');
    }
    if ($version < '2011-02-16 15:42:00') {
        // metto a posto il numero max di persone nei team
        calcMaxTeamPerson_20110216($TournamentID);
        // ricalcolo le rank a squadra
        recalculateTeamRanking_20110216($TournamentID);
        to_save_version($TournamentID, '2011-02-16 15:42:00');
    }
    if ($version < '2011-03-09 14:38:00') {
        initTourGoldsXNineChars_20110309($TournamentID);
        to_save_version($TournamentID, '2011-03-09 14:38:00');
    }
    if ($version < '2011-04-15 15:55:00') {
        RecalcFinRank_20110415($TournamentID);
        to_save_version($TournamentID, '2011-04-15 15:55:00');
    }
    if ($version < '2012-01-11 10:20:00') {
        Update3DIta_20120111($TournamentID);
        to_save_version($TournamentID, '2012-01-11 10:20:00');
    }
    if ($version < '2012-01-24 15:16:00') {
        $q = insertIntoGridForF2F_21($TournamentID);
        $rs2 = safe_w_sql($q, false, array(1062));
        to_save_version($TournamentID, '2012-01-24 15:16:00');
    }
    if ($version < '2012-05-18 07:10:00') {
        safe_w_sql("update Divisions set DivWaDivision=DivId, DivRecDivision=DivId where DivWaDivision='' or DivRecDivision=''");
        safe_w_sql("update Classes set ClWaClass=ClId, ClRecClass=ClId where ClWaClass='' or ClRecClass=''");
        safe_w_sql("update Events set EvWaCategory=EvCode, EvRecCategory=EvCode where EvWaCategory='' or EvRecCategory=''");
        to_save_version($TournamentID, '2012-05-18 07:10:00');
    }
    if ($version < '2013-12-19 12:30:00') {
        // Updating DistanceInformation
        require_once 'Modules/Sets/lib.php';
        require_once 'Tournament/Fun_ManSessions.inc.php';
        $Distances = getDistanceArrays($row->ToType);
        $q = safe_r_sql("select SesAth4Target, SesOrder from Session where SesTournament={$TournamentID}");
        while ($r = safe_fetch($q)) {
            CreateDistanceInformation($TournamentID, $Distances, 0, $r->SesAth4Target, $r->SesOrder);
        }
        to_save_version($TournamentID, '2013-12-19 12:30:00');
    }
    if ($version < '2014-03-22 14:00:00') {
        UpdateWinLose_20140322($TournamentID);
        to_save_version($TournamentID, '2014-03-22 14:00:00');
    }
    if ($version < '2014-04-01 00:00:00') {
        UpdateItaRules_20140401($TournamentID);
        to_save_version($TournamentID, '2014-04-01 00:00:00');
    }
    if ($version < '2014-05-23 16:00:00') {
        safe_w_sql("update Scheduler\n\t\t\tleft join Session on SchTournament=SesTournament and SchSesOrder=SesOrder and SchSesType=SesType\n\t\t\tset SchDay=date(SchDateStart), SchStart=time(SchDateStart), SchDuration=TIMESTAMPDIFF(MINUTE, SchDateStart, SchDateEnd), SchText=SchDescr, SchTitle=SesName\n\t\t\twhere SchTournament={$TournamentID}");
        $q = safe_r_sql("select * from Scheduler where SchTournament={$TournamentID} and SchDay>0 and SchStart>0 order by SchDay, SchStart, SchOrder desc");
        $oldKeys = array();
        while ($r = safe_fetch($q)) {
            $good = true;
            $key = $r->SchDay . '|' . $r->SchStart;
            while (in_array($key, $oldKeys)) {
                $key++;
                $good = false;
            }
            $oldKeys[] = $key;
            if (!$good) {
                $SQL = "update Scheduler set SchStart='" . substr($key, -8) . "' where SchDay='{$r->SchDay}' and SchStart='{$r->SchStart}' and SchDuration='{$r->SchDuration}' and SchSesOrder={$r->SchSesOrder} and SchOrder={$r->SchOrder} and SchSesType='{$r->SchSesType}' limit 1";
                safe_w_sql($SQL);
            }
        }
        to_save_version($TournamentID, '2014-04-01 00:00:00');
    }
    to_save_version($TournamentID, $DbVersion);
}
Exemple #3
0
function InsertSchedComment($Request, $Type = 'Q')
{
    foreach ($Request as $Session => $Distances) {
        foreach ($Distances as $Dist => $Value) {
            safe_w_sql("insert into DistanceInformation set\n\t\t\t\t\tDiTournament={$_SESSION['TourId']},\n\t\t\t\t\tDiDistance={$Dist},\n\t\t\t\t\tDiSession={$Session},\n\t\t\t\t\tDiType='{$Type}',\n\t\t\t\t\tDiOptions=" . StrSafe_DB($Value) . "\n\t\t\t\ton duplicate key update\n\t\t\t\t\tDiOptions=" . StrSafe_DB($Value) . "\n\t\t\t\t\t");
            $q = safe_r_SQL("select DiDay, DiStart, DiDuration, DiWarmStart, DiWarmDuration, DiOptions, DiShift\n\t\t\t\tfrom DistanceInformation\n\t\t\t\twhere DiTournament={$_SESSION['TourId']} and DiDistance={$Dist} and DiSession={$Session} and DiType='{$Type}'");
            return DistanceInfoData(safe_fetch($q));
        }
    }
    return array('error' => 1);
}
Exemple #4
0
$Width = $pdf->getPageWidth() - 65;
$CellHeight = $Height[1] - 10;
// 5 top and bottom
$fontname = $pdf->addTTFfont($CFG->DOCUMENT_PATH . 'Common/tcpdf/fonts/ariblk.ttf');
$pdf->SetFont($fontname);
$Filter = '';
if (!empty($_REQUEST['x_Session'])) {
    $Filter .= " and QuSession={$_REQUEST['x_Session']}";
}
if (!empty($_REQUEST['x_From'])) {
    $Filter .= " and substr(QuTargetNo,2)>='" . str_pad($_REQUEST['x_From'], 3, '0', STR_PAD_LEFT) . "'";
}
if (!empty($_REQUEST['x_To'])) {
    $Filter .= " and substr(QuTargetNo,2)<='" . str_pad($_REQUEST['x_To'], 3, '0', STR_PAD_LEFT) . "'";
}
$Rs = safe_r_SQL("select EnName, EnFirstName, QuTargetNo\n\tfrom Entries\n\tinner join Qualifications on EnId=QuId {$Filter} where EnTournament={$_SESSION['TourId']}\n\torder by QuTargetNo");
error_reporting(E_ALL);
$n = 0;
while ($MyRow = safe_fetch($Rs)) {
    if ($n == 0) {
        $pdf->AddPage();
        $pdf->Line(5, $Height[1], 15, $Height[1]);
        $pdf->Line($pdf->getPageWidth() - 15, $Height[1], $pdf->getPageWidth() - 5, $Height[1]);
        $pdf->Line(5, $Height[2], 15, $Height[2]);
        $pdf->Line($pdf->getPageWidth() - 15, $Height[2], $pdf->getPageWidth() - 5, $Height[2]);
    }
    $pdf->SetXY(10, $Height[$n] + 5);
    $pdf->setColor('text', 0);
    $pdf->SetFont('', '', 136);
    $pdf->Cell($Width, $CellHeight, $MyRow->EnFirstName, 0, 0, 'L');
    $pdf->setx($pdf->GetX() + 5);
    // aggiungo la colonna x salvare se quella rank ha dei pari oppure no.
    $MySql = "ALTER TABLE `Eliminations` ADD `ElSO` TINYINT( 3 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `ElRank`; ";
    safe_w_SQL($MySql, false, array(1060));
    db_save_version('2010-11-29 11:03:00');
}
if ($version < '2010-12-03 16:40:00') {
    // aggiungo la colonna x le frecce di spareggio delle eliminatorie
    $MySql = "ALTER TABLE `Eliminations` ADD `ElTiebreak` VARCHAR( 8 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `ElArrowString` ; ";
    safe_w_SQL($MySql, false, array(1060));
    db_save_version('2010-12-03 16:40:00');
}
if ($version < '2010-12-11 20:30:00') {
    $MySql = "ALTER TABLE `Individuals` CHANGE `IndSO` `IndSO` SMALLINT NOT NULL DEFAULT '0'";
    safe_w_SQL($MySql);
    $MySql = "ALTER TABLE `Eliminations` CHANGE `ElSO` `ElSO` SMALLINT NOT NULL DEFAULT '0'";
    safe_w_SQL($MySql);
    $MySql = "ALTER TABLE `HhtData` ADD `HdRealTargetNo` VARCHAR( 3 ) NOT NULL ,\n\t\tADD `HdLetter` VARCHAR( 1 ) NOT NULL";
    safe_w_SQL($MySql, false, array(1060));
    $MySql = "SELECT ToId From Tournament";
    $rs = safe_r_SQL($MySql);
    while ($myRow = safe_fetch($rs)) {
        recalculateIndividuals_20101211($myRow->ToId);
    }
    //Riporto i QuRank e le freccie di Shootoff dalla tabella qualifications
    $MySql = "UPDATE Entries\n\t\tINNER JOIN Qualifications On QuId=EnId\n\t\tINNER JOIN EventClass ON EcTeamEvent=0 AND EcTournament=EnTournament AND EcClass=EnClass AND EcDivision=EnDivision\n\t\tINNER JOIN Individuals ON IndId=EnId AND IndEvent=EcCode AND IndTournament=EnTournament\n\t\tSET IndRank=QuRank, IndTieBreak=QuTieBreak\n\t\tWHERE QuRank!=0 AND (QuRank!=IndRank OR QutieBreak!=IndTieBreak)";
    safe_w_SQL($MySql);
    //riporto la posizione dalla tabella finali... mi serve solo per partecipazioni ad eventi multi pli sennò bastava query sopra
    $MySql = "UPDATE Individuals\n\t\tINNER JOIN Finals ON IndId=FinAthlete AND IndEvent=FinEvent AND IndTournament=FinTournament\n\t\tINNER JOIN Events ON EvCode=FinEvent AND EvTeamEvent=0 AND EvTournament=FinTournament\n\t\tINNER JOIN Grids ON GrMatchNo=FinMatchNo AND GrPhase=IF(EvFinalFirstPhase=24,32,EvFinalFirstPhase)\n\t\tSET IndRank=GrPosition\n\t\tWHERE FinAthlete!=0 AND (EvElim1=0 AND EvElim2=0)";
    safe_w_SQL($MySql);
    db_save_version('2010-12-11 20:30:00');
}
Exemple #6
0
					<td>missing mail</td>
					<td>' . $tmp[0] . '</td>
					<td></td>
					</tr>';
                continue;
            }
            if (!preg_match('/^[a-z0-9._#-]+@[a-z0-9._-]+$/sim', $tmp[1])) {
                $ImportResult['Refused'][] = '<tr>
					<td>invalid mail</td>
					<td>' . $tmp[0] . '</td>
					<td>' . $tmp[1] . '</td>
					</tr>';
                continue;
            }
            // gets the EnIds of the archer with that EnCode
            $q = safe_r_SQL("select EnId from Entries where EnCode=" . StrSafe_DB($tmp[0]) . " and EnTournament={$_SESSION['TourId']}");
            if (safe_num_rows($q)) {
                while ($r = safe_fetch($q)) {
                    safe_w_sql("insert into ExtraData set EdId={$r->EnId}, EdType='E', EdEmail=" . StrSafe_DB($tmp[1]) . " on duplicate key update EdEmail=" . StrSafe_DB($tmp[1]) . "");
                    $ImportResult['Inserted'][] = '<tr>
						<td>Inserted/updated</td>
						<td>' . $tmp[0] . '</td>
						<td>' . $tmp[1] . '</td>
						</tr>';
                    $ImportResult['Imported']++;
                }
            } else {
                $ImportResult['Refused'][] = '<tr>
					<td>Wrong Entry code</td>
					<td>' . $tmp[0] . '</td>
					<td>' . $tmp[1] . '</td>
		<td class="Center" colspan="4"><input name="UploadedFile" type="file" size="20"></td>
	</tr>
	<tr>
	<td colspan="4" class="Center"><input type="submit" value="<?php 
    echo get_text('MsgSyncronize', 'Tournament');
    ?>
"></td>
	</tr>
	<tr><th colspan="4"><?php 
    echo '<input type="checkbox" name="PrevPhoto"' . (empty($_REQUEST['PrevPhoto']) ? '' : ' checked="checked"') . ' onclick="window.location.href=\'' . basename(__FILE__) . (empty($_REQUEST['PrevPhoto']) ? '?PrevPhoto=on' : '') . '\'">' . get_text('PreviousPhotos', 'Tournament');
    ?>
</th></tr>
	<?php 
    // check if there are some photos in this tournament...
    if (!empty($_REQUEST['PrevPhoto'])) {
        $q = safe_r_SQL("select * from Entries\r\n\t\t\tinner join (select PhEnId OtPhEnId, EnCode OtEnCode, EnIocCode OtEnIocCode, EnTournament OtEnTournament, ToCode OtToCode, ToName OtToName\r\n\t\t\t\tfrom Entries\r\n\t\t\t\tinner join Photos on PhEnId=EnId\r\n\t\t\t\tinner join Tournament on EnTournament=ToId) Ot on EnCode=OtEnCode and EnIocCode=OtEnIocCode\r\n\t\t\twhere EnId not in (select PhEnId from Photos inner join Entries on PhEnId=EnId and EnTournament={$_SESSION['TourId']})\r\n\t\t    and EnTournament={$_SESSION['TourId']}\r\n\t\t\torder by EnCode, OtPhEnId desc");
        while ($r = safe_fetch($q)) {
            echo '<tr>';
            echo '<td><a href="' . go_get(array('EnId' => $r->EnId, 'PhEnId' => $r->OtPhEnId)) . '">' . $r->EnFirstName . ' ' . $r->EnName . '</a></td>';
            echo '<td><img src="../Partecipants-exp/common/photo.php?id=' . $r->OtPhEnId . '&mode=y&val=50"></td>';
            echo '<td>' . $r->OtToCode . '</td>';
            echo '<td>' . $r->OtToName . '</td>';
            echo '</tr>';
        }
    }
    ?>
	</table>
	</form>
<?php 
} else {
    //ini_set('memory_limit', '512M');
function GetTargetInfo($TrgId, $size = 0)
{
    global $LetterPoint;
    $q = safe_r_SQL("select Targets.* from Targets where TarId={$TrgId}");
    if (!($MyRow = safe_fetch($q))) {
        return false;
    }
    $ret = array();
    foreach (range('Z', 'B') as $key) {
        if ($MyRow->{$key . '_size'}) {
            $ret[] = array("value" => $LetterPoint[$key]['N'], "display" => $LetterPoint[$key]['P'], "color" => $MyRow->{$key . '_color'}, "radius" => strval($MyRow->{$key . '_size'} * $size / 20));
        }
    }
    $ret[] = array("value" => $LetterPoint['A']['N'], "display" => $LetterPoint['A']['P'], "color" => "FFFFFF", "radius" => 0);
    return $ret;
}
         $vv = 0;
     } elseif (!safe_num_rows($Rs) && !$vv) {
         $vv = '';
     }
 }
 if (strlen(trim($vv)) > 0) {
     $badDate = false;
     if ($cc == 'FSScheduledDate') {
         $vv = ConvertDate($Value);
         $badDate = !($vv >= date('Y-m-d', $_SESSION['ToWhenFromUTS']) && $vv <= date('Y-m-d', $_SESSION['ToWhenToUTS']));
         if (!$badDate) {
             // check if there is still a warmup for that event at the original time...
             $q = safe_r_SQL("select count(*) as Counted, FsScheduledDate, FsScheduledTime from FinSchedule\n\t\t\t\t\t\t\t\twhere FsEvent=" . StrSafe_DB($ee) . "\n\t\t\t\t\t\t\t\tAND FsTeamEvent=0\n\t\t\t\t\t\t\t\tAND FsTournament={$_SESSION['TourId']}\n\t\t\t\t\t\t\t\tAND (FsScheduledDate, FsScheduledTime)=(select FsScheduledDate,FsScheduledTime from FinSchedule\n\t\t\t\t\t\t\t\t\twhere FsEvent=" . StrSafe_DB($ee) . "\n\t\t\t\t\t\t\t\t\tAND FsTeamEvent=0\n\t\t\t\t\t\t\t\t\tAND FsMatchNo=" . StrSafe_DB($mm) . "\n\t\t\t\t\t\t\t\t\tAND FsTournament={$_SESSION['TourId']})");
             if ($r = safe_fetch($q) and $r->Counted == 1) {
                 // change the associated warmup if any
                 $q = safe_r_SQL("select * from FinWarmup\n\t\t\t\t\t\t\t\t\twhere FwTournament={$_SESSION['TourId']}\n\t\t\t\t\t\t\t\t\tand FwTeamEvent=0\n\t\t\t\t\t\t\t\t\tand FwDay='{$vv}'\n\t\t\t\t\t\t\t\t\tand FwMatchTime='{$r->FsScheduledTime}'\n\t\t\t\t\t\t\t\t\tand FwEvent=" . StrSafe_DB($ee));
                 if ($dest = safe_fetch($q)) {
                     // destination date and time already exists for that event...
                     // get the source data
                     // deletes the associated warmup that failed with previous query
                     safe_w_sql("delete from FinWarmup\n\t\t\t\t\t\t\t\t\t\twhere FwTournament={$_SESSION['TourId']}\n\t\t\t\t\t\t\t\t\t\tand FwTeamEvent=0\n\t\t\t\t\t\t\t\t\t\tand FwDay='{$r->FsScheduledDate}'\n\t\t\t\t\t\t\t\t\t\tand FwMatchTime='{$r->FsScheduledTime}'\n\t\t\t\t\t\t\t\t\t\tand FwEvent=" . StrSafe_DB($ee));
                 } else {
                     safe_w_sql("update ignore FinWarmup set FwDay='{$vv}'\n\t\t\t\t\t\t\t\t\t\twhere FwTournament={$_SESSION['TourId']}\n\t\t\t\t\t\t\t\t\t\tand FwTeamEvent=0\n\t\t\t\t\t\t\t\t\t\tand FwDay='{$r->FsScheduledDate}'\n\t\t\t\t\t\t\t\t\t\tand FwMatchTime='{$r->FsScheduledTime}'\n\t\t\t\t\t\t\t\t\t\tand FwEvent=" . StrSafe_DB($ee));
                 }
             }
         }
     } elseif ($cc == 'FSScheduledTime') {
         $vv = Convert24Time($vv);
     }
     if ($vv > 0 && !$badDate || $vv == 0 && $cc == 'FSScheduledLen') {
         // Scrivo per $mm
Exemple #10
0
                if ($f == 'IceTournament') {
                    continue;
                }
                $SQL[] = $f . '=' . StrSafe_DB($v);
            }
            safe_w_sql("insert ignore into IdCardElements set " . implode(',', $SQL));
            CheckPictures();
        }
    }
}
if (!empty($_REQUEST['ExportLayout'])) {
    $Layout = array();
    $q = safe_r_SQL("select * from IdCards where IcTournament={$_SESSION['TourId']}");
    if ($r = safe_fetch_assoc($q)) {
        $Layout['IdCards'] = $r;
        $q = safe_r_SQL("select * from IdCardElements where IceTournament={$_SESSION['TourId']}");
        while ($r = safe_fetch_assoc($q)) {
            $Layout['IdCardElements'][] = $r;
        }
        // We'll be outputting a gzipped TExt File in UTF-8 pretending it's binary
        header('Content-type: application/octet-stream');
        // It will be called ToCode-IdCard.ianseo
        header("Content-Disposition: attachment; filename=\"{$_SESSION['TourCode']}-IdCard.ianseo\"");
        ini_set('memory_limit', sprintf('%sM', 512));
        echo gzcompress(serialize($Layout), 9);
        die;
    }
}
if (!empty($_REQUEST['DoPrint'])) {
    $FIELDS = "EnId";
    $SORT = 'EnId';
Exemple #11
0
 /**
  * @param string $pdf
  * If empty creates and returns a pdf, otherwise adds page to an existant pdf
  * @return tcpdf object
  *
  *
  */
 function getSchedulePDF(&$pdf = '')
 {
     if (empty($pdf)) {
         require_once 'Common/pdf/IanseoPdf.php';
         $pdf = new IanseoPdf('Scheduler');
         $pdf->startPageGroup();
         $pdf->AddPage();
     } else {
         $pdf->AddPage();
     }
     $Start = true;
     $StartX = $pdf->getX();
     $FontAdjust = 1;
     $TimingWidth = 20;
     $DelayWidth = 10;
     $descrSize = $pdf->getPageWidth() - 40;
     $CellHeight = 5;
     if ($this->DayByDay) {
         $FontAdjust = 2;
         $TimingWidth = 30;
         $StartX += 10;
         $CellHeight = 8;
     } else {
         $StartX += 20;
     }
     foreach ($this->GetSchedule() as $Date => $Times) {
         if (!$Start and ($this->DayByDay or !$pdf->SamePage(55))) {
             $pdf->AddPage();
         } elseif (!$Start) {
             $pdf->dy(2 * $FontAdjust);
         }
         $Start = false;
         // DAY
         $pdf->SetFont($pdf->FontStd, 'B', 8 * $FontAdjust);
         $pdf->Cell(0, $CellHeight, formatTextDate($Date), 0, 1, 'L', 1);
         $OldTitle = '';
         $OldSubTitle = '';
         $OldType = '';
         $OldStart = '';
         $OldEnd = '';
         $IsTitle = false;
         $OldComment = '';
         ksort($Times);
         //			debug_svela($Times);
         foreach ($Times as $Time => $Sessions) {
             foreach ($Sessions as $Session => $Distances) {
                 foreach ($Distances as $Distance => $Items) {
                     foreach ($Items as $k => $Item) {
                         if (!$pdf->SamePage(15)) {
                             $pdf->AddPage();
                             // Day...
                             $pdf->SetFont($pdf->FontStd, 'B', 8 * $FontAdjust);
                             $pdf->Cell(0, $CellHeight, formatTextDate($Date) . '    (' . get_text('Continue') . ')', 0, 1, 'L', 1);
                             // maybe the session title?
                             if ($Item->Type != 'Z' and $OldTitle == $Item->Title and $OldTitle) {
                                 $pdf->SetFont($pdf->FontStd, 'B', 8 * $FontAdjust);
                                 $pdf->SetX($StartX + $TimingWidth);
                                 $pdf->Cell($descrSize, $CellHeight, $Item->Title . '    (' . get_text('Continue') . ')', 0, 1, 'L', 0);
                             }
                             $pdf->SetFont($pdf->FontStd, '', 8 * $FontAdjust);
                         }
                         $timingDelayed = '';
                         $timing = '';
                         if ($Item->Type == 'Z') {
                             // free text
                             $timing = $Item->Start . ($Item->Duration ? '-' . addMinutes($Item->Start, $Item->Duration) : '');
                             if ($Item->Shift) {
                                 $timingDelayed = '+' . $Item->Shift;
                             }
                             if ($OldTitle != $Item->Title and $Item->Title) {
                                 if (!$IsTitle) {
                                     $pdf->SetX($StartX);
                                     // prints timing only if alone
                                     if (!$Item->SubTitle and !$Item->Text) {
                                         if ($Item->Shift and $timing) {
                                             $pdf->SetX($StartX - $DelayWidth);
                                             $pdf->Cell($DelayWidth, $CellHeight, $timingDelayed, 0, 0);
                                             $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                         } else {
                                             $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                         }
                                         $timing = '';
                                     } else {
                                         $pdf->Cell($TimingWidth, $CellHeight, ' ', 0, 0);
                                     }
                                     $pdf->SetFont($pdf->FontStd, 'B', 8 * $FontAdjust);
                                     $pdf->Cell($descrSize, $CellHeight, $Item->Title, 0, 1, 'L', 0);
                                     $pdf->SetFont($pdf->FontStd, '', 8 * $FontAdjust);
                                 }
                                 $OldTitle = $Item->Title;
                                 $OldSubTitle = '';
                                 $IsTitle = true;
                             }
                             if ($OldSubTitle != $Item->SubTitle and $Item->SubTitle) {
                                 $pdf->SetX($StartX);
                                 if (!$Item->Text) {
                                     if ($Item->Shift and $timing) {
                                         $pdf->SetX($StartX - $DelayWidth);
                                         $pdf->Cell($DelayWidth, $CellHeight, $timingDelayed, 0, 0);
                                         $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                     } else {
                                         $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                     }
                                     $timing = '';
                                 } else {
                                     $pdf->Cell($TimingWidth, $CellHeight, ' ', 0, 0);
                                 }
                                 $pdf->SetFont($pdf->FontStd, 'BI', 8 * $FontAdjust);
                                 $pdf->Cell($descrSize, $CellHeight, $Item->SubTitle, 0, 1, 'L', 0);
                                 $pdf->SetFont($pdf->FontStd, '', 8 * $FontAdjust);
                                 $OldSubTitle = $Item->SubTitle;
                                 $IsTitle = false;
                             }
                             if ($Item->Text) {
                                 $pdf->SetX($StartX);
                                 if ($Item->Shift and $timing) {
                                     $pdf->SetX($StartX - $DelayWidth);
                                     $pdf->Cell($DelayWidth, $CellHeight, $timingDelayed, 0, 0);
                                     $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                     $pdf->Line($StartX, $y = $pdf->GetY() + $CellHeight / 2, $StartX + $TimingWidth - $FontAdjust, $y);
                                 } else {
                                     $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                 }
                                 $pdf->SetFont($pdf->FontStd, '', 8 * $FontAdjust);
                                 $pdf->Cell($descrSize, $CellHeight, $Item->Text, 0, 1, 'L', 0);
                                 $pdf->SetFont($pdf->FontStd, '', 8 * $FontAdjust);
                                 $timing = '';
                                 $IsTitle = false;
                             }
                             $OldStart = $Item->Start;
                             $OldEnd = $Item->Duration;
                             $OldComment = '';
                         } else {
                             // all other kind of texts have a title and the items
                             if ($OldTitle != $Item->Title) {
                                 // Title
                                 if (!$IsTitle) {
                                     $pdf->SetX($StartX);
                                     $pdf->Cell($TimingWidth, $CellHeight, ' ', 0, 0);
                                     $pdf->SetFont($pdf->FontStd, 'B', 8 * $FontAdjust);
                                     $pdf->Cell($descrSize, $CellHeight, $Item->Title, 0, 1, 'L', 0);
                                     $pdf->SetFont($pdf->FontStd, '', 8 * $FontAdjust);
                                 }
                                 $OldTitle = $Item->Title;
                                 $OldSubTitle = '';
                                 $IsTitle = true;
                             }
                             if ($OldSubTitle != $Item->SubTitle) {
                                 // SubTitle
                                 $pdf->SetX($StartX);
                                 $pdf->Cell($TimingWidth, $CellHeight, ' ', 0, 0);
                                 $pdf->SetFont($pdf->FontStd, 'BI', 8 * $FontAdjust);
                                 $pdf->Cell($descrSize, $CellHeight, $Item->SubTitle, 0, 1, 'L', 0);
                                 $pdf->SetFont($pdf->FontStd, '', 8 * $FontAdjust);
                                 $OldSubTitle = $Item->SubTitle;
                                 $IsTitle = false;
                             }
                             $timing = '';
                             if ($OldStart != $Item->Start or $OldEnd != $Item->Duration) {
                                 $timing = $Item->Start . ($Item->Duration ? '-' . addMinutes($Item->Start, $Item->Duration) : '');
                                 $OldStart = $Item->Start;
                                 $OldEnd = $Item->Duration;
                                 if ($Item->Shift) {
                                     $timingDelayed = '+' . $Item->Shift;
                                 }
                             }
                             $lnk = $Item->Text;
                             if (!$Item->Warmup) {
                                 // not warmup!
                                 $OldComment = '';
                                 switch ($Item->Type) {
                                     case 'Q':
                                     case 'E':
                                         $t = safe_r_SQL("select distinct EcCode, EcTeamEvent from Entries\n\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN Qualifications on QuId=EnId and QuSession={$Item->Session}\n\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN EventClass ON EcClass=EnClass AND EcDivision=EnDivision AND EcTournament=EnTournament\n\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN Events on EvCode=EcCode AND EvTeamEvent=IF(EcTeamEvent!=0, 1,0) AND EvTournament=EcTournament\n\t\t\t\t\t\t\t\t\t\t\t\twhere EnTournament={$this->TourId}\n\t\t\t\t\t\t\t\t\t\t\t\torder by EvTeamEvent, EvProgr");
                                         $Link = array();
                                         $lnk = '';
                                         if ($Item->Comments) {
                                             $pdf->SetX($StartX);
                                             if ($Item->Shift and $timing) {
                                                 $pdf->SetX($StartX - $DelayWidth);
                                                 $pdf->Cell($DelayWidth, $CellHeight, $timingDelayed, 0, 0);
                                                 $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                             } else {
                                                 $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                             }
                                             $pdf->SetFont($pdf->FontStd, 'I', 8 * $FontAdjust);
                                             $pdf->Cell($descrSize, $CellHeight, $Item->Comments, 0, 1, 'L', 0);
                                             $pdf->SetFont($pdf->FontStd, '', 8 * $FontAdjust);
                                             $timing = '';
                                         }
                                         if (count($this->Groups[$Item->Type][$Session]) == 1) {
                                             $txt = $Item->Text . $lnk;
                                         } elseif ($Item == @end(end(end(end($this->Groups[$Item->Type][$Session]))))) {
                                             $txt = get_text('Distance', 'Tournament') . ' ' . $Distance . $lnk;
                                         } else {
                                             $txt = get_text('Distance', 'Tournament') . ' ' . $Distance;
                                             // more distances defined so format is different...
                                         }
                                         $pdf->SetX($StartX);
                                         if ($Item->Shift and $timing) {
                                             $pdf->SetX($StartX - $DelayWidth);
                                             $pdf->Cell($DelayWidth, $CellHeight, $timingDelayed, 0, 0);
                                             $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                         } else {
                                             $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                         }
                                         $pdf->Cell($descrSize, $CellHeight, $txt, 0, 1, 'L', 0);
                                         $IsTitle = false;
                                         break;
                                     case 'I':
                                     case 'T':
                                         $lnk = $Item->Text . ': ' . $Item->Events;
                                         $pdf->SetX($StartX);
                                         if ($Item->Shift and $timing) {
                                             $pdf->SetX($StartX - $DelayWidth);
                                             $pdf->Cell($DelayWidth, $CellHeight, $timingDelayed, 0, 0);
                                             $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                         } else {
                                             $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                         }
                                         $pdf->Cell($descrSize, $CellHeight, $lnk, 0, 1, 'L', 0);
                                         $IsTitle = false;
                                         if ($this->Finalists && $Item->Session <= 1) {
                                             // Bronze or Gold Finals
                                             if ($Item->Type == 'I') {
                                                 $SQL = "select concat(upper(e1.EnFirstname), ' ', e1.EnName, ' (', c1.CoCode, ')') LeftSide,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tconcat('(', c2.CoCode, ') ', upper(e2.EnFirstname), ' ', e2.EnName) RightSide\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfrom Finals tf1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Finals tf2 on tf1.FinEvent=tf2.FinEvent and tf1.FinTournament=tf2.FinTournament and tf2.FinMatchNo=tf1.FinMatchNo+1 and tf2.FinMatchNo%2=1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Entries e1 on e1.EnId=tf1.FinAthlete and tf1.FinEvent IN ('{$Item->Event}')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Entries e2 on e2.EnId=tf2.FinAthlete and tf2.FinEvent IN ('{$Item->Event}')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Countries c1 on e1.EnCountry=c1.CoId and c1.CoTournament={$this->TourId}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Countries c2 on e2.EnCountry=c2.CoId and c2.CoTournament={$this->TourId}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Grids on tf1.FinMatchNo=GrMatchNo and GrPhase={$Item->Session}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere tf1.FinTournament={$this->TourId}";
                                             } else {
                                                 $SQL = "select concat(c1.CoName, ' (', c1.CoCode, ')') LeftSide,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tconcat('(', c2.CoCode, ') ', c2.CoName) RightSide\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfrom TeamFinals tf1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join TeamFinals tf2 on tf1.TfEvent=tf2.TfEvent and tf1.TfTournament=tf2.TfTournament and tf2.TfMatchNo=tf1.TfMatchNo+1 and tf2.TfMatchNo%2=1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Countries c1 on c1.CoId=tf1.TfTeam and tf1.TfEvent IN ('{$Item->Event}')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Countries c2 on c2.CoId=tf2.TfTeam and tf2.TfEvent IN ('{$Item->Event}')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Grids on tf1.TfMatchNo=GrMatchNo and GrPhase={$Item->Session}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere tf1.TfTournament={$this->TourId}";
                                             }
                                             // 												debug_svela($SQL);
                                             $q = safe_r_SQL($SQL);
                                             if ($r = safe_fetch($q) and trim($r->LeftSide) and trim($r->RightSide)) {
                                                 $pdf->SetXY($StartX + $TimingWidth, $pdf->getY() - 1.5);
                                                 $pdf->Cell($descrSize, $CellHeight, $r->LeftSide . ' - ' . $r->RightSide, 0, 1, 'L', 0);
                                             }
                                         }
                                         break;
                                     case 'R':
                                         $lnk = $Item->Text . ': ' . $Item->Events;
                                         $pdf->SetX($StartX);
                                         if ($Item->Shift and $timing) {
                                             $pdf->SetX($StartX - $DelayWidth);
                                             $pdf->Cell($DelayWidth, $CellHeight, $timingDelayed, 0, 0);
                                             $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                         } else {
                                             $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                         }
                                         $pdf->Cell($descrSize, $CellHeight, $lnk, 0, 1, 'L', 0);
                                         $IsTitle = false;
                                         if ($this->Finalists) {
                                             list($Phase, $Round, $Group) = explode('-', $Item->Session);
                                             $SQL = "select concat(upper(e1.EnFirstname), ' ', e1.EnName, ' (', c1.CoCode, ')') LeftSide,\n\t\t\t\t\t\t\t\t\t\t\t\t\tconcat('(', c2.CoCode, ') ', upper(e2.EnFirstname), ' ', e2.EnName) RightSide\n\t\t\t\t\t\t\t\t\t\t\t\t\tfrom F2FGrid g\n\t\t\t\t\t\t\t\t\t\t\t\t\tinner join F2FFinal tf1 on g.F2FTournament=tf1.F2FTournament and g.F2FPhase=tf1.F2FPhase and g.F2FRound=tf1.F2FRound and g.F2FGroup=tf1.F2FGroup and g.F2FMatchNo1=tf1.F2FMatchNo\n\t\t\t\t\t\t\t\t\t\t\t\t\tinner join F2FFinal tf2 on g.F2FTournament=tf2.F2FTournament and g.F2FPhase=tf2.F2FPhase and g.F2FRound=tf2.F2FRound and g.F2FGroup=tf2.F2FGroup and g.F2FMatchNo2=tf2.F2FMatchNo and tf1.F2FEvent=tf2.F2FEvent\n\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Entries e1 on e1.EnId=tf1.F2FEnId and tf1.F2FEvent IN ('{$Item->Event}')\n\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Entries e2 on e2.EnId=tf2.F2FEnId and tf2.F2FEvent IN ('{$Item->Event}')\n\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Countries c1 on e1.EnCountry=c1.CoId and c1.CoTournament={$this->TourId}\n\t\t\t\t\t\t\t\t\t\t\t\t\tinner join Countries c2 on e2.EnCountry=c2.CoId and c2.CoTournament={$this->TourId}\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere g.F2FTournament={$this->TourId} and tf1.F2FSchedule='{$Date} {$Time}'";
                                             $q = safe_r_SQL($SQL);
                                             while ($r = safe_fetch($q) and trim($r->LeftSide) and trim($r->RightSide)) {
                                                 $pdf->SetXY($StartX + $TimingWidth, $pdf->getY() - 1.5);
                                                 $pdf->Cell($descrSize, $CellHeight, $r->LeftSide . ' - ' . $r->RightSide, 0, 1, 'L', 0);
                                             }
                                         }
                                         break;
                                     default:
                                         debug_svela($Item);
                                 }
                             } else {
                                 if ($Item->Comments) {
                                     $lnk = $Item->Comments;
                                 } else {
                                     switch ($Item->Type) {
                                         case 'I':
                                         case 'T':
                                             $lnk = $Item->Text . ': ' . $Item->Events . ' ' . 'warmup';
                                             break;
                                         default:
                                             $lnk .= ' Warmup';
                                     }
                                 }
                                 if ($OldComment == $lnk) {
                                     continue;
                                 }
                                 $OldComment = $lnk;
                                 $pdf->SetX($StartX);
                                 if ($Item->Shift and $timing) {
                                     $pdf->SetX($StartX - $DelayWidth);
                                     $pdf->Cell($DelayWidth, $CellHeight, $timingDelayed, 0, 0);
                                     $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                 } else {
                                     $pdf->Cell($TimingWidth, $CellHeight, $timing, 0, 0);
                                 }
                                 $pdf->SetFont($pdf->FontStd, 'I', 8 * $FontAdjust);
                                 $pdf->Cell($descrSize, $CellHeight, $lnk, 0, 1, 'L', 0);
                                 $pdf->SetFont($pdf->FontStd, '', 8 * $FontAdjust);
                                 $IsTitle = false;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $pdf;
 }
function getDistFields()
{
    $ret = array();
    $q = safe_r_SQL("select distinct EnDivision, EnClass from Entries where EnTournament={$_SESSION['TourId']}");
    while ($r = safe_fetch($q)) {
        $cat = trim($r->EnDivision) . trim($r->EnClass);
        $MySql = "select" . " concat_ws('#', Td1, Td2, Td3, Td4, Td5, Td6, Td7, Td8) QryFields " . "from" . " TournamentDistances " . "WHERE" . " TdType={$_SESSION['TourType']} " . " AND TdTournament = {$_SESSION['TourId']} " . " AND '{$cat}' LIKE TdClasses " . "order by" . " TdTournament=0" . ", '{$cat}' = TdClasses desc" . ", left(TdClasses,1)!='_' and left(TdClasses,1)!='%' desc" . ", left(TdClasses,1)='_' desc" . ", TdClasses desc" . ", TdClasses='%' " . "LIMIT 1";
        $t = safe_r_sql($MySql);
        if ($u = safe_fetch($t)) {
            $ret[$cat] = str_replace(array('-', '#'), array('', '-'), $u->QryFields);
        }
    }
    return $ret;
}
 /**
  * Viene chiamata per fare i passaggi di fase delle finali
  *
  * @param array int $keys: vettore delle chiavi per il passaggio di fase
  * @param array int $team: 0 individuali 1 squadre
  * @param boolean &$error: true se il post processo genera un errore
  */
 private function nextPhase($keys, $team, &$error)
 {
     /*
      * Se non ci sono $keys buone non ho passaggi di fase e il post-processing fallisce
      */
     if (count($keys) == 0) {
         $error = true;
         return;
     }
     foreach ($keys as $key => $value) {
         $events = implode(',', array_keys($value));
         $query = "";
         if ($team == 0) {
             $query = "SELECT GrPhase AS Phase,GrPosition AS Position,\t/* Grids*/ " . "FinMatchNo AS MatchNo,FinEvent AS Event, FinAthlete AS Id, FinScore AS Score,FinTie AS Tie, " . "IF(GrPhase>2, FLOOR(FinMatchNo/2),FLOOR(FinMatchNo/2)-2) AS NextMatchNo " . "FROM Finals INNER JOIN Grids ON FinMatchNo=GrMatchNo AND GrPhase=" . StrSafe_DB($key) . " " . "LEFT JOIN Entries ON FinAthlete=EnId AND FinEvent IN(" . $events . ') ' . "WHERE FinTournament=" . $this->getTourId() . " " . "ORDER BY FinEvent, NextMatchNo ASC, FinScore DESC, FinTie DESC ";
         } else {
             $query = "SELECT GrPhase AS Phase,GrPosition AS Position,\t/* Grids*/ " . "TfTeam AS Id,TfMatchNo AS MatchNo,TfEvent AS Event, TfScore AS Score,TfTie AS Tie, " . "IF(GrPhase>2, FLOOR(TfMatchNo/2),FLOOR(TfMatchNo/2)-2) AS NextMatchNo " . "FROM TeamFinals INNER JOIN Grids ON TfMatchNo=GrMatchNo AND GrPhase=" . StrSafe_DB($key) . " " . "WHERE TfTournament=" . $this->getTourId() . " AND TfEvent IN (" . $events . ") " . "ORDER BY TfEvent, NextMatchNo ASC, TfScore DESC, TfTie DESC ";
         }
         //print $query . '<br>';exit;
         $rs = safe_r_SQL($query);
         $myNextMatchNo = 'xx';
         $row = array();
         if (safe_num_rows($rs) > 0) {
             while ($row0 = safe_fetch($rs)) {
                 $row1 = safe_fetch($rs);
                 $athProp = 0;
                 $myUpQuery = "";
                 if ($row0->Phase >= 2) {
                     if (($row0->Score > 0 || $row0->Tie > 0) && ($row0->Score != $row1->Score || $row0->Tie != $row1->Tie)) {
                         if ($team == 0) {
                             $myUpQuery = "UPDATE Finals SET ";
                             $myUpQuery .= "FinAthlete =" . StrSafe_DB($row0->Id) . ", ";
                             $myUpQuery .= "FinDateTime=" . StrSafe_DB(date('Y-m-d H:i:s')) . " ";
                             $myUpQuery .= "WHERE FinEvent=" . StrSafe_DB($row0->Event) . " AND FinMatchNo=" . StrSafe_DB($row0->NextMatchNo) . " AND FinTournament=" . $this->getTourId() . " ";
                         } else {
                             $myUpQuery = "UPDATE TeamFinals SET ";
                             $myUpQuery .= "TfTeam =" . StrSafe_DB($row0->Id) . ", ";
                             $myUpQuery .= "TfDateTime=" . StrSafe_DB(date('Y-m-d H:i:s')) . " ";
                             $myUpQuery .= "WHERE TfEvent=" . StrSafe_DB($row0->Event) . " AND TfMatchNo=" . StrSafe_DB($row0->NextMatchNo) . " AND TfTournament=" . $this->getTourId() . " ";
                         }
                         //print $myUpQuery . '<br><br>';
                         $rsUp = safe_w_sql($myUpQuery);
                         $athProp = $row0->Id;
                     } else {
                         if ($team == 0) {
                             $myUpQuery = "UPDATE Finals SET ";
                             $myUpQuery .= "FinAthlete ='0', ";
                             $myUpQuery .= "FinDateTime=" . StrSafe_DB(date('Y-m-d H:i:s')) . " ";
                             $myUpQuery .= "WHERE FinEvent=" . StrSafe_DB($row0->Event) . " AND FinMatchNo=" . StrSafe_DB($row0->NextMatchNo) . " AND FinTournament=" . $this->getTourId() . " ";
                         } else {
                             $myUpQuery = "UPDATE TeamFinals SET ";
                             $myUpQuery .= "TfTeam ='0', ";
                             $myUpQuery .= "TfDateTime=" . StrSafe_DB(date('Y-m-d H:i:s')) . " ";
                             $myUpQuery .= "WHERE TfEvent=" . StrSafe_DB($row0->Event) . " AND TfMatchNo=" . StrSafe_DB($row0->NextMatchNo) . " AND TfTournament=" . $this->getTourId() . " ";
                         }
                         $rsUp = safe_w_sql($myUpQuery);
                     }
                 }
                 if ($row1->Phase == 2) {
                     if (($row1->Score > 0 || $row1->Tie > 0) && ($row0->Score != $row1->Score || $row0->Tie != $row1->Tie)) {
                         if ($team == 0) {
                             $myUpQuery = "UPDATE Finals SET ";
                             $myUpQuery .= "FinAthlete =" . StrSafe_DB($row1->Id) . ", ";
                             $myUpQuery .= "FinDateTime=" . StrSafe_DB(date('Y-m-d H:i:s')) . " ";
                             $myUpQuery .= "WHERE FinEvent=" . StrSafe_DB($row1->Event) . " AND FinMatchNo=" . StrSafe_DB($row1->NextMatchNo + 2) . " AND FinTournament=" . $this->getTourId() . " ";
                         } else {
                             $myUpQuery = "UPDATE TeamFinals SET ";
                             $myUpQuery .= "TfTeam =" . StrSafe_DB($row1->Id) . ", ";
                             $myUpQuery .= "TfDateTime=" . StrSafe_DB(date('Y-m-d H:i:s')) . " ";
                             $myUpQuery .= "WHERE TfEvent=" . StrSafe_DB($row1->Event) . " AND TfMatchNo=" . StrSafe_DB($row1->NextMatchNo + 2) . " AND TfTournament=" . $this->getTourId() . " ";
                         }
                         $rsUp = safe_w_sql($myUpQuery);
                         $athProp = $Row1->FinAthlete;
                     } else {
                         if ($team == 0) {
                             $myUpQuery = "UPDATE Finals SET ";
                             $myUpQuery .= "FinAthlete =" . StrSafe_DB($row1->Id) . ", ";
                             // 0
                             $myUpQuery .= "FinDateTime=" . StrSafe_DB(date('Y-m-d H:i:s')) . " ";
                             $myUpQuery .= "WHERE FinEvent=" . StrSafe_DB($row1->Event) . " AND FinMatchNo=" . StrSafe_DB($row1->NextMatchNo + 2) . " AND FinTournament=" . $this->getTourId() . " ";
                         } else {
                             $myUpQuery = "UPDATE TeamFinals SET ";
                             $myUpQuery .= "TfTeam =" . StrSafe_DB($row1->Id) . ", ";
                             // 0
                             $myUpQuery .= "TfDateTime=" . StrSafe_DB(date('Y-m-d H:i:s')) . " ";
                             $myUpQuery .= "WHERE TfEvent=" . StrSafe_DB($row1->Event) . " AND TfMatchNo=" . StrSafe_DB($row1->NextMatchNo + 2) . " AND TfTournament=" . $this->getTourId() . " ";
                         }
                         $rsUp = safe_w_sql($myUpQuery);
                     }
                     // Devo fare la propagazione del nome se il matchno>7 (fase>2)
                     $oldId = $athProp != 0 ? StrSafe_DB($row1->Id) : StrSafe_DB($row0->Id) . ',' . StrSafe_DB($row1->Id);
                     $update = "";
                     if ($team == 0) {
                         $update = "UPDATE Finals SET " . "FinAthlete=" . StrSafe_DB($athProp) . " " . "WHERE FinAthlete IN (" . $oldId . ") AND FinTournament=" . $this->getTourId() . " AND FinEvent=" . StrSafe_DB($row0->Event) . " AND FinMatchNo<" . StrSafe_DB($row0->NextMatchNo) . " AND (FinScore<>0 OR FinTie<>0) ";
                     } else {
                         $update = "UPDATE TeamFinals SET " . "TfTeam=" . StrSafe_DB($athProp) . " " . "WHERE TfTeam IN (" . $oldId . ") AND TfTournament=" . $this->getTourId() . " AND TfEvent=" . StrSafe_DB($row0->Event) . " AND TfMatchNo<" . StrSafe_DB($row0->NextMatchNo) . " AND (TfScore<>0 OR TfTie<>0) ";
                     }
                     //print $update . '<br><br>';
                     $rsProp = safe_w_sql($update);
                     if (safe_w_affected_rows() > 0) {
                         $error = false;
                     }
                 }
             }
         }
     }
 }
Exemple #14
0
                $Team[$tmp[2] . $tmp[3]] = $MyRow->BsExtra;
            } elseif ($tmp[1] == 'Abs') {
                $AbsInd[$tmp[2]] = $MyRow->BsExtra;
            } elseif ($tmp[1] == 'AbsTeam') {
                $AbsTeam[$tmp[2]] = $MyRow->BsExtra;
            } elseif ($tmp[1] == 'Lst') {
                if (($Ses = substr($MyRow->BsType, -2, 1)) == 'Q') {
                    $Lst[$MyRow->BsExtra[0]] = sprintf($LstTemplate, substr($MyRow->BsType, -1));
                }
            }
            break;
    }
}
if ($Lst) {
    foreach ($Lst as $k => $SQL) {
        $q = safe_r_SQL($SQL);
        $txt = array();
        while ($r = safe_fetch($q)) {
            // 			debug_svela($r);
            $txt[] = sprintf("%s %s %s", ltrim($r->Target, '0'), $r->EnName, $r->EnFirstName);
        }
        $FeedItems['Lst-' . $k]['title'] = get_text('StartList', 'Tournament');
        $FeedItems['Lst-' . $k]['text'] = implode(' - ', $txt);
    }
}
if ($Ind) {
    require_once 'Common/Lib/Obj_RankFactory.php';
    //Genero la query che mi ritorna tutti al max 10 righe dei podi qualificati
    $options = array('dist' => 0);
    $options['cutRank'] = max(array_values($Ind));
    $family = 'DivClass';
$age = isset($_REQUEST['age']) ? $_REQUEST['age'] : '';
if (!CheckTourSession() || is_null($sex)) {
    print get_text('CrackError');
    exit;
}
if (!empty($age)) {
    preg_match('/(?P<age>[0-9]{4})/', $age, $tmp);
    if (!empty($tmp['age'])) {
        $age = $tmp['age'];
        $age = substr($_SESSION['TourRealWhenTo'], 0, 4) - $age;
    }
}
$error = 0;
$isAthlete = 0;
$query = "SELECT distinct ClId, DivAthlete FROM Divisions" . " inner join Classes on DivTournament=ClTournament and DivAthlete=ClAthlete" . " where DivTournament={$_SESSION['TourId']}" . " AND (ClDivisionsAllowed='' or find_in_set(DivId, ClDivisionsAllowed))" . " AND ClSex in (-1, {$sex})" . " AND DivId='{$div}'" . ($age ? " AND (ClAthlete!='1' or (ClAgeFrom<={$age} AND ClAgeTo>={$age} ))" : '') . " ORDER BY ClViewOrder";
$rs = safe_r_SQL($query);
//debug_svela($query);
$classes = array();
if (!$rs) {
    $error = 1;
} else {
    while ($myRow = safe_fetch($rs)) {
        $classes[] = $myRow->ClId;
        $isAthlete = $myRow->DivAthlete;
    }
}
$xmlDoc = new DOMDocument('1.0', PageEncode);
$xmlRoot = $xmlDoc->createElement('response');
$xmlDoc->appendChild($xmlRoot);
// Header
$xmlHeader = $xmlDoc->createElement('header');
Exemple #16
0
    echo '</td></tr>';
}
//Individual Cl/div
$Sql = "SELECT CONCAT(DivId,ClId) as Event\r\n\t\tFROM Divisions INNER JOIN Classes ON DivTournament=ClTournament\r\n\t\tLEFT JOIN Awards ON DivTournament=AwTournament AND CONCAT(DivId,ClId)=AwEvent AND AwFinEvent=0 AND AwTeam=0\r\n\t\tWHERE DivTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND ClAthlete=1 AND DivAthlete=1 AND AwEvent IS NULL";
$Rs = safe_r_SQL($Sql);
if (safe_num_rows($Rs)) {
    $needSubmit = true;
    echo '<tr><th style="width: 15%">' . get_text('ResultIndClass', 'Tournament') . '</th><td>';
    while ($row = safe_fetch($Rs)) {
        echo '<input type="checkbox" name="addField[]" value="' . $row->Event . '|0|0">' . $row->Event . "&nbsp;&nbsp;&nbsp;";
    }
    echo '</td></tr>';
}
//Team Cl/div
$Sql = "SELECT CONCAT(DivId,ClId) as Event\r\n\t\tFROM Divisions INNER JOIN Classes ON DivTournament=ClTournament\r\n\t\tLEFT JOIN Awards ON DivTournament=AwTournament AND CONCAT(DivId,ClId)=AwEvent AND AwFinEvent=0 AND AwTeam=1\r\n\t\tWHERE DivTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND ClAthlete=1 AND DivAthlete=1 AND AwEvent IS NULL";
$Rs = safe_r_SQL($Sql);
if (safe_num_rows($Rs)) {
    $needSubmit = true;
    echo '<tr><th style="width: 15%">' . get_text('ResultSqClass', 'Tournament') . '</th><td>';
    while ($row = safe_fetch($Rs)) {
        echo '<input type="checkbox" name="addField[]" value="' . $row->Event . '|0|1">' . $row->Event . "&nbsp;&nbsp;&nbsp;";
    }
    echo '</td></tr>';
}
if ($needSubmit) {
    echo '<tr><td colspan="2" class="Center"><input type="hidden" name="Command" value="ADD"><input type="submit" name="' . get_text('CmdAdd', 'Tournament') . '"></td></th>';
}
echo '</table></td></tr>';
?>
</table>
<?php 
Exemple #17
0
function GetExistingTournamentTypes()
{
    global $CFG;
    $SetType = array();
    $q = safe_r_SQL("select * from TourTypes order by TtOrderBy");
    $TourTypes = array();
    while ($r = safe_fetch($q)) {
        $TourTypes["{$r->TtId}"] = get_text($r->TtType, 'Tournament') . ($r->TtDistance ? " - {$r->TtDistance} " . get_text('Distances', 'Tournament') : '');
    }
    // search in the local rules
    $glob = glob($CFG->DOCUMENT_PATH . 'Modules/Sets/*/sets.php');
    foreach ($glob as $val) {
        include $val;
    }
    return $SetType;
}
function recalculateTeamRanking_20110216($TournamentID)
{
    // per tutte le squadre del torneo ricalcolo le 3 rank
    $rank = Obj_RankFactory::create('DivClassTeam', array('tournament' => $TournamentID));
    if ($rank) {
        $rank->calculate();
    }
    $rank = Obj_RankFactory::create('AbsTeam', array('tournament' => $TournamentID));
    if ($rank) {
        $rank->calculate();
    }
    $MySql = "SELECT EvCode, EvFinalFirstPhase FROM Events WHERE EvTournament=" . StrSafe_DB($TournamentID) . " AND EvTeamEvent=1";
    $rs = safe_r_SQL($MySql);
    $eventsC = array();
    while ($MyRow = safe_fetch($rs)) {
        $eventsC[] = $MyRow->EvCode . "@-3";
        $eventsC[] = $MyRow->EvCode . "@" . $MyRow->EvFinalFirstPhase;
    }
    $rank = Obj_RankFactory::create('FinalTeam', array('eventsC' => $eventsC, 'tournament' => $TournamentID));
    if ($rank) {
        $rank->calculate();
    }
}
 public function read()
 {
     $filter = $this->safeFilter();
     error_reporting(E_ALL);
     /*
      *  prima passata per costruire la struttura del vettore.
      *  Tiro fuori i nomi delle squadre
      */
     $MyQueryNames = "SELECT TfcId, TfcEvent, TfcCoId, TfcSubTeam, TfcOrder, ucase(EnFirstName) EnUpperName, EnFirstName, EnName, concat(ucase(EnFirstName), ' ', EnName) Athlete, CONCAT(TeRank,CHAR(64+TfcOrder)) AS BackNo  ";
     $MyQueryNames .= "FROM TeamFinComponent ";
     $MyQueryNames .= "INNER JOIN Events ON TfcEvent=EvCode AND TfcTournament=EvTournament AND EvTeamEvent=1 AND EvFinalFirstPhase!=0 ";
     $MyQueryNames .= "INNER JOIN Entries ON TfcId=EnId AND TfcTournament=EnTournament ";
     $MyQueryNames .= "INNER JOIN Teams ON TfcCoId=TeCoId AND TfcSubTeam=TeSubTeam AND TfcEvent=TeEvent AND TfcTournament=TeTournament AND TeFinEvent=1 ";
     $MyQueryNames .= "WHERE TfcTournament = " . $this->tournament . " ";
     if (!empty($this->opts['events'])) {
         $MyQueryNames .= CleanEvents($this->opts['events'], 'TfcEvent');
     }
     $MyQueryNames .= " ORDER BY EvProgr, TfcEvent, TfcCoId, TfcSubTeam, TfcOrder ";
     $this->data['sections'] = array();
     $q = safe_r_SQL($MyQueryNames);
     while ($r = safe_fetch($q)) {
         $this->data['sections'][$r->TfcEvent]['athletes'][$r->TfcCoId][$r->TfcSubTeam][] = array('athlete' => $r->Athlete, 'backNo' => $r->BackNo, 'id' => $r->TfcId, 'familyName' => $r->EnFirstName, 'familyUpperName' => $r->EnUpperName, 'givenName' => $r->EnName);
         if (!empty($this->opts['enid']) and $r->TfcId == $this->opts['enid']) {
             $this->EnIdFound[] = $r->TfcEvent;
             $this->TeamFound = $r->TfcCoId;
         }
     }
     if (!empty($this->opts['enid'])) {
         if (!$this->EnIdFound) {
             return;
         }
         foreach ($this->data['sections'] as $ev => $data) {
             if (!in_array($ev, $this->EnIdFound)) {
                 unset($this->data['sections'][$ev]);
             }
         }
     }
     $q = "SELECT * from (" . "select" . " EvCode Event," . " EvEventName EventDescr," . " EvFinalFirstPhase," . " EvMaxTeamPerson," . " EvFinalPrintHead," . " EvMatchMode," . " EvProgr," . " EvShootOff," . " GrPhase Phase," . " IF(EvFinalFirstPhase=48 || EvFinalFirstPhase=24,GrPosition2, GrPosition) Position," . " TfTournament Tournament," . " TfTeam Team," . " TfSubTeam SubTeam," . " TfMatchNo MatchNo," . " TeRank QualRank," . " TeRankFinal FinRank," . " TeScore QualScore, " . " TfWinLose Winner, " . " TfDateTime LastUpdated, " . " CONCAT(CoName, IF(TfSubTeam>'1',CONCAT(' (',TfSubTeam,')'),'')) as CountryName," . " CoCode as CountryCode," . " TfScore AS Score," . " TfSetScore as SetScore," . " TfTie Tie," . " TfTieBreak TieBreak," . " TfStatus Status, " . " TfSetPoints SetPoints, " . " TfArrowstring arrowstring, TfLive LiveFlag," . " FSTarget Target," . " TarId, TarDescr, EvDistance as Distance, EvTargetSize as TargetSize, " . "\tEvFinEnds, EvFinArrows, EvFinSO, EvElimEnds, EvElimArrows, EvElimSO, " . " DATE_FORMAT(FSScheduledDate,'" . get_text('DateFmtDB') . "') as ScheduledDate," . " DATE_FORMAT(FSScheduledTime,'" . get_text('TimeFmt') . "') AS ScheduledTime " . " FROM TeamFinals " . " INNER JOIN Events ON TfEvent=EvCode AND TfTournament=EvTournament AND EvTeamEvent=1 AND EvFinalFirstPhase!=0 " . " INNER JOIN Grids ON TfMatchNo=GrMatchNo " . " INNER JOIN Targets ON EvFinalTargetType=TarId " . " LEFT JOIN Teams ON TfTeam=TeCoId AND TfSubTeam=TeSubTeam AND TfEvent=TeEvent AND TfTournament=TeTournament AND TeFinEvent=1 " . " LEFT JOIN Countries ON TfTeam=CoId AND TfTournament=CoTournament " . " LEFT JOIN FinSchedule ON TfEvent=FSEvent AND TfMatchNo=FSMatchNo AND TfTournament=FSTournament AND FSTeamEvent='1' " . " WHERE TfMatchNo%2=0 AND TfTournament = " . $this->tournament . " " . $filter . ") f1 inner join (" . "select" . " EvCode OppEvent," . " IF(EvFinalFirstPhase=48 || EvFinalFirstPhase=24,GrPosition2, GrPosition) OppPosition," . " TfTournament OppTournament," . " TfTeam OppTeam," . " TfSubTeam OppSubTeam," . " TfMatchNo OppMatchNo," . " TeRank OppQualRank," . " TeRankFinal OppFinRank," . " TeScore OppQualScore, " . " TfWinLose OppWinner, " . " TfDateTime OppLastUpdated, " . " CONCAT(CoName, IF(TfSubTeam>'1',CONCAT(' (',TfSubTeam,')'),'')) as OppCountryName," . " CoCode as OppCountryCode," . " TfScore AS OppScore," . " TfSetScore as OppSetScore," . " TfTie OppTie," . " TfTieBreak OppTieBreak," . " TfStatus OppStatus, " . " TfSetPoints OppSetPoints, " . " TfArrowstring oppArrowstring, " . " FSTarget OppTarget " . " FROM TeamFinals " . " INNER JOIN Events ON TfEvent=EvCode AND TfTournament=EvTournament AND EvTeamEvent=1 AND EvFinalFirstPhase!=0 " . " INNER JOIN Grids ON TfMatchNo=GrMatchNo " . " LEFT JOIN Teams ON TfTeam=TeCoId AND TfSubTeam=TeSubTeam AND TfEvent=TeEvent AND TfTournament=TeTournament AND TeFinEvent=1 " . " LEFT JOIN Countries ON TfTeam=CoId AND TfTournament=CoTournament " . " LEFT JOIN FinSchedule ON TfEvent=FSEvent AND TfMatchNo=FSMatchNo AND TfTournament=FSTournament AND FSTeamEvent='1' " . " WHERE TfMatchNo%2=1 AND TfTournament = " . $this->tournament . " " . $filter . ") f2 on Tournament=OppTournament and Event=OppEvent and MatchNo=OppMatchNo-1 " . ($this->EnIdFound ? ' where Event in ("' . implode('","', $this->EnIdFound) . '") AND (Team=' . StrSafe_DB($this->TeamFound) . ' or oppTeam=' . StrSafe_DB($this->TeamFound) . ')' : '') . (empty($this->opts['coid']) ? '' : " where (Team=" . intval($this->opts['coid']) . " or OppTeam=" . intval($this->opts['coid']) . ") ") . (isset($this->opts['matchno']) ? " where MatchNo=" . intval($this->opts['matchno']) . ' ' : '') . (isset($this->opts['liveFlag']) ? " where LiveFlag=1 " : '') . " ORDER BY EvProgr ASC, event, Phase DESC, MatchNo ASC ";
     $r = safe_r_sql($q);
     $this->data['meta']['title'] = get_text('BracketsSq');
     $this->data['meta']['lastUpdate'] = '0000-00-00 00:00:00';
     $this->data['meta']['fields'] = array('scheduledDate' => get_text('Date', 'Tournament'), 'scheduledTime' => get_text('Time', 'Tournament'), 'winner' => get_text('Winner'), 'matchNo' => get_text('MatchNo'), 'bib' => get_text('Code', 'Tournament'), 'target' => get_text('Target'), 'athlete' => get_text('Athlete'), 'familyname' => get_text('FamilyName', 'Tournament'), 'givenname' => get_text('Name', 'Tournament'), 'countryCode' => '', 'countryName' => get_text('Country'), 'countryIocCode' => '', 'qualRank' => get_text('RankScoreShort'), 'finRank' => get_text('FinalRank', 'Tournament'), 'qualscore' => get_text('TotalShort', 'Tournament'), 'score' => get_text('TotalShort', 'Tournament'), 'setScore' => get_text('SetTotal', 'Tournament'), 'setPoints' => get_text('SetPoints', 'Tournament'), 'tie' => 'S.O.', 'arrowstring' => get_text('Arrows', 'Tournament'), 'tiebreak' => get_text('TieArrows'), 'status' => get_text('Status', 'Tournament'), 'oppMatchNo' => get_text('MatchNo'), 'oppBib' => get_text('Code', 'Tournament'), 'oppTarget' => get_text('Target'), 'oppAthlete' => get_text('Athlete'), 'oppFamilyname' => get_text('FamilyName', 'Tournament'), 'oppGivenname' => get_text('Name', 'Tournament'), 'oppCountryCode' => '', 'oppCountryName' => get_text('Country'), 'oppCountryIocCode' => '', 'oppQualRank' => get_text('RankScoreShort'), 'oppFinRank' => get_text('FinalRank', 'Tournament'), 'oppQualScore' => get_text('TotalShort', 'Tournament'), 'oppScore' => get_text('TotalShort', 'Tournament'), 'oppSetScore' => get_text('SetTotal', 'Tournament'), 'oppSetPoints' => get_text('SetPoints', 'Tournament'), 'oppTie' => 'S.O.', 'oppArrowstring' => get_text('Arrows', 'Tournament'), 'oppTiebreak' => get_text('TieArrows'), 'oppStatus' => get_text('Status', 'Tournament'));
     while ($myRow = safe_fetch($r)) {
         if ($myRow->LastUpdated > $this->data['meta']['lastUpdate']) {
             $this->data['meta']['lastUpdate'] = $myRow->LastUpdated;
         }
         if ($myRow->OppLastUpdated > $this->data['meta']['lastUpdate']) {
             $this->data['meta']['lastUpdate'] = $myRow->OppLastUpdated;
         }
         if (!isset($this->data['sections'][$myRow->Event]['meta'])) {
             $this->data['sections'][$myRow->Event]['meta'] = array('phase' => get_text('Phase'), 'eventName' => get_text($myRow->EventDescr, '', '', true), 'firstPhase' => $myRow->EvFinalFirstPhase, 'printHead' => get_text($myRow->EvFinalPrintHead, '', '', true), 'maxTeamPerson' => $myRow->EvMaxTeamPerson, 'matchMode' => $myRow->EvMatchMode, 'order' => $myRow->EvProgr, 'shootOffSolved' => $myRow->EvShootOff, 'finEnds' => $myRow->EvFinEnds, 'finArrows' => $myRow->EvFinArrows, 'finSO' => $myRow->EvFinSO, 'elimEnds' => $myRow->EvElimEnds, 'elimArrows' => $myRow->EvElimArrows, 'elimSO' => $myRow->EvElimSO, 'targetType' => $myRow->TarDescr, 'targetTypeId' => $myRow->TarId, 'targetSize' => $myRow->TargetSize, 'distance' => $myRow->Distance);
             $this->data['sections'][$myRow->Event]['phases'] = array();
         }
         if (!isset($this->data['sections'][$myRow->Event]['phases'][$myRow->Phase])) {
             $this->data['sections'][$myRow->Event]['phases'][$myRow->Phase]['meta'] = array('phaseName' => get_text($myRow->Phase . "_Phase"));
             $this->data['sections'][$myRow->Event]['phases'][$myRow->Phase]['items'] = array();
         }
         $tmpArr = array();
         $oppArr = array();
         if ($myRow->TieBreak) {
             for ($countArr = 0; $countArr < strlen(trim($myRow->TieBreak)); $countArr += $myRow->EvMaxTeamPerson) {
                 $tmp = ValutaArrowString(substr(trim($myRow->TieBreak), $countArr, $myRow->EvMaxTeamPerson));
                 if (!ctype_upper(trim($myRow->TieBreak))) {
                     $tmp .= "*";
                 }
                 $tmpArr[] = $tmp;
             }
             //debug_svela($myRow);
         }
         if ($myRow->OppTieBreak) {
             for ($countArr = 0; $countArr < strlen(trim($myRow->OppTieBreak)); $countArr += $myRow->EvMaxTeamPerson) {
                 $tmp = ValutaArrowString(substr(trim($myRow->OppTieBreak), $countArr, $myRow->EvMaxTeamPerson));
                 if (!ctype_upper(trim($myRow->OppTieBreak))) {
                     $tmp .= "*";
                 }
                 $oppArr[] = $tmp;
             }
         }
         $this->data['sections'][$myRow->Event]['phases'][$myRow->Phase]['items'][] = array('liveFlag' => $myRow->LiveFlag, 'scheduledDate' => $myRow->ScheduledDate, 'scheduledTime' => $myRow->ScheduledTime, 'matchNo' => $myRow->MatchNo, 'target' => $myRow->Target, 'countryCode' => $myRow->CountryCode, 'countryName' => $myRow->CountryName, 'qualRank' => $myRow->QualRank, 'finRank' => $myRow->FinRank, 'qualScore' => $myRow->QualScore, 'winner' => $myRow->Winner, 'score' => $myRow->Score, 'setScore' => $myRow->SetScore, 'setPoints' => $myRow->SetPoints, 'arrowstring' => $myRow->arrowstring, 'tie' => $myRow->Tie, 'tiebreak' => $myRow->TieBreak, 'tiebreakDecoded' => implode(',', $tmpArr), 'status' => $myRow->Status, 'position' => $myRow->QualRank ? $myRow->QualRank : $myRow->Position, 'teamId' => $myRow->Team, 'subTeam' => $myRow->SubTeam, 'oppMatchNo' => $myRow->OppMatchNo, 'oppTarget' => $myRow->OppTarget, 'oppCountryCode' => $myRow->OppCountryCode, 'oppCountryName' => $myRow->OppCountryName, 'oppQualRank' => $myRow->OppQualRank, 'oppFinRank' => $myRow->OppFinRank, 'oppQualScore' => $myRow->OppQualScore, 'oppWinner' => $myRow->OppWinner, 'oppScore' => $myRow->OppScore, 'oppSetScore' => $myRow->OppSetScore, 'oppSetPoints' => $myRow->OppSetPoints, 'oppArrowstring' => $myRow->oppArrowstring, 'oppTie' => $myRow->OppTie, 'oppTiebreak' => $myRow->OppTieBreak, 'oppTiebreakDecoded' => implode(',', $oppArr), 'oppStatus' => $myRow->OppStatus, 'oppPosition' => $myRow->OppQualRank ? $myRow->OppQualRank : $myRow->OppPosition, 'oppTeamId' => $myRow->OppTeam, 'oppSubTeam' => $myRow->OppSubTeam);
     }
 }