/** * @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; }