function __construct($TemplateID = 0) { parent::__construct('BackNumber'); $Select = "SELECT BackNumber.*, LENGTH(BnBackground) as ImgSize " . "FROM BackNumber " . "WHERE BnTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND BnFinal in (0," . $TemplateID . ") order by BnFinal desc limit 1"; //print $Select;exit; $Rs = safe_r_sql($Select); if (safe_num_rows($Rs) == 1) { $this->RowBn = safe_fetch($Rs); } else { // fall back if no Backnumber creates from template! include_once 'Tournament/BackNumberEmpty.php'; $this->RowBn = emptyBackNumber(); } $this->Rotation = $this->RowBn->BnOffsetX != 0 || $this->RowBn->BnOffsetY != 0; $this->RotX = $this->RowBn->BnWidth / 2; $this->RotY = $this->RowBn->BnOffsetY / 2; // TargetNo Specs $this->TargetNoFont = ($this->RowBn->BnTargetNo & 4) == 4 ? $this->FontFix : (($this->RowBn->BnTargetNo & 2) == 2 ? 'dejavuserif' : $this->FontStd); $this->TargetNoStyle = ($this->RowBn->BnTargetNo & 8 ? 'B' : '') . ($this->RowBn->BnTargetNo & 16 ? 'I' : ''); $this->TargetNoColor = array(base_convert(substr($this->RowBn->BnTnoColor, 0, 2), 16, 10), base_convert(substr($this->RowBn->BnTnoColor, 2, 2), 16, 10), base_convert(substr($this->RowBn->BnTnoColor, 4, 2), 16, 10)); $this->TargetNoAlign = ($this->RowBn->BnTargetNo & 96) == 64 ? 'L' : (($this->RowBn->BnTargetNo & 96) == 32 ? 'R' : 'C'); // Athlete Specs $this->AthleteFont = ($this->RowBn->BnAthlete & 4) == 4 ? $this->FontFix : (($this->RowBn->BnAthlete & 2) == 2 ? 'dejavuserif' : $this->FontStd); $this->AthleteStyle = ($this->RowBn->BnAthlete & 8 ? 'B' : '') . ($this->RowBn->BnAthlete & 16 ? 'I' : ''); $this->AthleteColor = array(base_convert(substr($this->RowBn->BnAthColor, 0, 2), 16, 10), base_convert(substr($this->RowBn->BnAthColor, 2, 2), 16, 10), base_convert(substr($this->RowBn->BnAthColor, 4, 2), 16, 10)); $this->AthleteAlign = ($this->RowBn->BnAthlete & 96) == 64 ? 'L' : (($this->RowBn->BnAthlete & 96) == 32 ? 'R' : 'C'); if ($this->RowBn->BnCapitalFirstName) { $this->FirstNameAllCaps = true; } // Country Specs $this->CountryFont = ($this->RowBn->BnCountry & 4) == 4 ? $this->FontFix : (($this->RowBn->BnCountry & 2) == 2 ? 'dejavuserif' : $this->FontStd); $this->CountryStyle = ($this->RowBn->BnCountry & 8 ? 'B' : '') . ($this->RowBn->BnCountry & 16 ? 'I' : ''); $this->CountryColor = array(base_convert(substr($this->RowBn->BnCoColor, 0, 2), 16, 10), base_convert(substr($this->RowBn->BnCoColor, 2, 2), 16, 10), base_convert(substr($this->RowBn->BnCoColor, 4, 2), 16, 10)); $this->CountryAlign = ($this->RowBn->BnCountry & 96) == 64 ? 'L' : (($this->RowBn->BnCountry & 96) == 32 ? 'R' : 'C'); // background temp creation if ($this->RowBn->ImgSize) { $this->BackGroundFile = tempnam('/tmp', 'bgf'); $img = imagecreatefromstring($this->RowBn->BnBackground); if (!imagepng($img, $this->BackGroundFile)) { die('could not create image'); } } $Orientation = $this->RowBn->BnWidth > $this->RowBn->BnHeight ? 'L' : 'P'; $this->setPageOrientation($Orientation); $this->setPageFormat(array($this->RowBn->BnWidth, $this->RowBn->BnHeight), $Orientation); $this->SetFont($this->FontStd, '', 10); $this->AliasNbPages(); $this->setPrintHeader(false); $this->setPrintFooter(false); $this->SetMargins(10, 10, 10); $this->SetAutoPageBreak(false, 10); $this->SetAuthor('http://www.ianseo.net'); $this->SetCreator('Software Design by Ianseo'); $this->SetTitle('IANSEO - Integrated Result System (release ' . ProgramVersion . ')'); $this->SetSubject('BackNo'); }
} if ($BackNoFinal > 4) { $BackNoFinal = 0; } if (isset($_REQUEST["deleteLayout"])) { safe_w_sql("DELETE FROM BackNumber WHERE BnTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND BnFinal=" . StrSafe_DB($BackNoFinal)); cd_redirect('BackNumber.php?BackNo=' . $BackNoFinal); } $RowBn = NULL; $Select = "(SELECT BackNumber.*, LENGTH(BnBackground) as ImgSize, 1 as Customized " . "FROM BackNumber " . "WHERE BnTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND BnFinal=" . StrSafe_DB($BackNoFinal) . ")" . "UNION " . "(SELECT BackNumber.*, LENGTH(BnBackground) as ImgSize, 0 as Customized " . "FROM BackNumber " . "WHERE BnTournament=" . StrSafe_DB($_SESSION['TourId']) . " AND BnFinal=0) " . "LIMIT 1"; $Rs = safe_r_sql($Select); if (safe_num_rows($Rs) == 1) { $RowBn = safe_fetch($Rs); } else { include 'Tournament/BackNumberEmpty.php'; $RowBn = emptyBackNumber(); } if (isset($_REQUEST["Submit"])) { $TmpUpdate = ''; foreach ($_REQUEST as $Key => $Value) { if (substr($Key, 0, 2) == 'Bn') { if (is_array($Value)) { $Tmp = 0; foreach ($Value as $SubValue) { $Tmp += $SubValue; } $TmpUpdate .= $Key . " = " . StrSafe_DB($Tmp) . ', '; } else { $TmpUpdate .= $Key . " = " . StrSafe_DB(str_replace('#', '', $Value)) . ', '; } }
function createBackno($TourCodeSafe) { // return; global $CFG; include 'Tournament/BackNumberEmpty.php'; $RowBn = emptyBackNumber(); $W = $RowBn->BnBgW; $H = $RowBn->BnBgH; $img = imagecreatetruecolor($W * 12, $H * 12); $ColWhi = imagecolorallocate($img, 255, 255, 255); // bianco imagefilledrectangle($img, 0, 0, $W * 12, $H * 12, $ColWhi); $ColBlue = imagecolorallocate($img, 0, 83, 166); // azzurro if (file_exists($file = $CFG->DOCUMENT_PATH . 'TV/Photos/' . $TourCodeSafe . '-ToLeft.jpg')) { $fmt = 75 / 65; // max rectangle is 75 w x 65 h $im2 = imagecreatefromjpeg($file); $w2 = imagesx($im2); $h2 = imagesy($im2); if ($w2 / $h2 > $fmt) { // more landscape than available rectangle $newW = 75 * 12; $newH = $newW * $h2 / $w2; } else { // more portrait than available rectangle $newH = 65 * 12; $newW = $newH * $w2 / $h2; } imagecopyresampled($img, $im2, 0, 0, 0, 0, $newW, $newH, $w2, $h2); } if (file_exists($file = $CFG->DOCUMENT_PATH . 'TV/Photos/' . $TourCodeSafe . '-ToRight.jpg')) { $fmt = ($W - 51) / 34; // max rectangle is 75 w x 65 h $im2 = imagecreatefromjpeg($file); $w2 = imagesx($im2); $h2 = imagesy($im2); if ($w2 / $h2 > $fmt) { // more landscape than available rectangle $newW = ($W - 51) * 12; $newH = $newW * $h2 / $w2; } else { // more portrait than available rectangle $newH = 34 * 12; $newW = $newH * $w2 / $h2; } imagecopyresampled($img, $im2, 0, $H * 12 - $newH, 0, 0, $newW, $newH, $w2, $h2); } // text putenv('GDFONTPATH=' . dirname(__FILE__) . '/tcpdf/fonts'); if ($_SESSION['ISORIS']) { define('PRINTLANG', 'en'); } elseif ($_SESSION['TourPrintLang']) { define('PRINTLANG', $_SESSION['TourPrintLang']); } $q = safe_r_sql("select ToWhere, ToName, ToWhenFrom, ToWhenTo from Tournament where ToId={$_SESSION['TourId']}"); $font = 'ariblk.ttf'; $r = safe_fetch($q); $text = ''; $date1 = explode('-', $r->ToWhenFrom); $date2 = explode('-', $r->ToWhenTo); if ($date1[0] != $date2[0]) { // 2 years $text = intval($date1[2]) . ' ' . get_text($date1[1] . '_Short', 'DateTime') . ' ' . $date1[0] . '/' . intval($date2[2]) . ' ' . get_text($date2[1] . '_Short', 'DateTime') . ' ' . $date2[0]; } elseif ($date1[1] != $date2[1]) { // 2 months $text = intval($date1[2]) . ' ' . get_text($date1[1] . '_Short', 'DateTime') . '/' . intval($date2[2]) . ' ' . get_text($date2[1] . '_Short', 'DateTime') . ' ' . $date2[0]; } elseif ($date1[0] != $date2[0]) { // 2 days $text = intval($date1[2]) . '/' . intval($date2[2]) . ' ' . get_text($date2[1] . '_Short', 'DateTime') . ' ' . $date2[0]; } else { $text = intval($date2[2]) . ' ' . get_text($date2[1] . '_Short', 'DateTime') . ' ' . $date2[0]; } $text .= ' - ' . preg_replace("#[\n\r]+#", ' - ', $r->ToWhere) . ' - ' . preg_replace("#[\n\r]+#", ' - ', $r->ToName); $FontSize = 50; $dim = imagettfbbox($FontSize, 0, $font, $text); while ($dim[2] > $W * 12) { $FontSize--; $dim = imagettfbbox($FontSize, 0, $font, $text); } $textX = ($W * 12 - $dim[2]) / 2; $textY = 65 * 12 + 5 - $dim[7]; imagettftext($img, $FontSize, 0, $textX, $textY, $ColBlue, $font, $text); imagesetthickness($img, 10); imageline($img, $textX, $textY + $dim[1] + 8, $textX + $dim[2], $textY + $dim[1] + 8, $ColBlue); imagejpeg($img, $FILE = $CFG->DOCUMENT_PATH . 'TV/Photos/' . $TourCodeSafe . '-BackNo-0.jpg', 90); $TmpUpdate = ''; $RowBn->BnTournament = $_SESSION['TourId']; $RowBn->BnFinal = 0; foreach ($RowBn as $Key => $Value) { if (substr($Key, 0, 2) == 'Bn') { if (is_array($Value)) { $Tmp = 0; foreach ($Value as $SubValue) { $Tmp += $SubValue; } $TmpUpdate .= $Key . " = " . StrSafe_DB($Tmp) . ', '; } else { $TmpUpdate .= $Key . " = " . StrSafe_DB(str_replace('#', '', $Value)) . ', '; } } } $TmpUpdate .= "BnBackground='" . addslashes(file_get_contents($FILE)) . "'"; safe_w_sql("INSERT INTO BackNumber SET {$TmpUpdate} on duplicate key update {$TmpUpdate}"); }