/** MakeChart: @mod: reference to module object @bdata: reference to array of bracket-table data @chartfile: path/name of file to be created or replaced @stylefile optional name of .css file to use instead of logged data @titles optional, mode enum for type of titles to include in boxes: 0 for(printer-ready) no labels in unplayed matches 1 for normal labels in all boxes (default) 2 for including match numbers in 'plan' mode Returns: TRUE on success, or lang-key for error message if: bad no. of teams, css parsing failed */ public function MakeChart(&$mod, &$bdata, $chartfile, $stylefile = FALSE, $titles = 1) { $db = cmsms()->GetDb(); $sql = 'SELECT COUNT(1) AS count FROM ' . cms_db_prefix() . 'module_tmt_teams WHERE bracket_id=? AND flags!=2'; $teamscount = (int) $db->GetOne($sql, array($bdata['bracket_id'])); if ($teamscount == 0) { return 'info_nomatch'; } //if no team, then no match list($minteams, $maxteams) = $mod->GetLimits($bdata['type']); if ($teamscount > $maxteams || $teamscount < $minteams) { return 'err_value'; } $css = new tmtStyler(); if (!$stylefile && $bdata['chartcss']) { $stylefile = $bdata['chartcss']; } if ($stylefile) { $config = cmsms()->GetConfig(); $csspath = cms_join_path($config['uploads_path'], $mod->GetPreference('uploads_dir'), $stylefile); if (file_exists($csspath)) { if (!$css->Parse($csspath)) { return 'err_styles'; } } } $this->mod = $mod; $this->layout = array(); $this->ldata = array(); $this->dashes = array(3, 3); $this->dots = array(0.2, 4); //high-use variables sent downstream in array,for extraction there $params = array(); $params['teamscount'] = $teamscount; //inter-box gaps $lw = $css->pxsize($css->GetWithDefault('.line', 'width', '2px')); //line width $bhm = $css->pxsize($css->GetSide('.box', 'margin', 'right')); //horz margin $gw = $css->pxsize($css->GetWithDefault('.chart', 'gapwidth', '20px')); //gap width $gw = max($lw + 4, $bhm * 2 + $gw); $params['gw'] = $gw; //includes box margins, if any $bvm = $css->pxsize($css->GetSide('.box', 'margin', 'top')); //vert margin $params['gh'] = max(2, $bvm * 2); //includes box margins, if any //chart margins $tp = $css->pxsize($css->GetSide('.chart', 'padding', 'top')); if ($tp < 2) { $tp = 2; } if ($titles == 0 && $tp < 40) { $tp = 40; } $th = $css->pxsize($css->GetWithDefault('.chart', 'font-size', '12pt')); //space for title string $params['tm'] = $tp + $th; //top $p = $css->pxsize($css->GetSide('.chart', 'padding', 'right')); $rm = $bhm + $p >= 5 ? $p : 5; if ($titles == 0 && $rm < 40) { $rm = 40; } $params['rm'] = $rm; //right $p = $css->pxsize($css->GetSide('.chart', 'padding', 'bottom')); $bm = $bvm + $p >= 5 ? $p : 5; if ($titles == 0 && $bm < 40) { $bm = 40; } $params['bm'] = $bm; //bottom $p = $css->pxsize($css->GetSide('.chart', 'padding', 'left')); $lm = $bhm + $p >= 5 ? $p : 5; if ($titles == 0 && $lm < 40) { $lm = 40; } $params['lm'] = $lm; //left //box parameters $bh = $css->pxsize($css->GetWithDefault('.box', 'height', '40px')); $params['bh'] = $bh; //content-height $params['bw'] = $css->pxsize($css->GetWithDefault('.box', 'width', '100px')); //content-width $bp = $css->pxsize($css->GetWithDefault('.box', 'padding', '0')); $params['bp'] = $bp; //all-sides' padding $blw = $css->pxsize($css->GetWithDefault('.box', 'border-width', '1px')); $params['blw'] = $blw; //all sides' border-width $params['bhm'] = $bhm; //l/r margin $params['bvm'] = $bvm; //t/b margin $this->Layout($params, $db, $bdata['bracket_id']); //setup boxes' size, position and chart size $this->Boxes($bdata, $db, $titles); //setup boxes' text and style if ($titles == 0) { //print-chart min size $min = $css->pxsize($css->GetWithDefault('.chart', 'minwidth', '770pt')); if ($this->ldata['width'] < $min) { $this->ldata['width'] = $min; } $min = $css->pxsize($css->GetWithDefault('.chart', 'minheight', '526pt')); if ($this->ldata['height'] < $min) { $this->ldata['height'] = $min; } } $cw = $this->ldata['width']; $ch = $this->ldata['height']; //check for custom .ttf files $config = cmsms()->GetConfig(); $rel = $mod->GetPreference('uploads_dir'); $custom = cms_join_path($config['uploads_path'], $rel); if (is_dir($custom)) { $pat = cms_join_path($custom, '*.ttf'); //tPDF recognises only lower-case filenames if (glob($pat, GLOB_NOSORT)) { define('_SYSTEM_TTFONTS', $ttfpath); } } $enc = $mod->GetPreference('export_encoding', 'UTF-8'); $utf = strcasecmp($enc, 'UTF-8') == 0; $pdf = new tFPDF($cw > $ch ? 'L' : 'P', 'px', array($cw, $ch), $utf); $pdf->SetAutoPageBreak(FALSE); $pdf->AddPage(); if ($titles > 0) { $back = $css->hex2rgb($css->GetWithDefault('.chart', 'background-color', FALSE)); //TODO support image-background if ($back) { $pdf->SetFillColor($back[0], $back[1], $back[2]); $pdf->Rect(0, 0, $cw, $ch, 'F'); //no chart border } } //display title $class = '.chart'; $title = $bdata['name'] ? $bdata['name'] : $mod->MissingName(); $ft = $css->GetWithDefault($class, 'font-family', 'sans'); $style = $css->GetWithDefault($class, 'font-weight', 'normal'); $attr = $style != 'bold' ? '' : 'b'; $style = $css->GetWithDefault($class, 'font-style', 'normal'); if (strpos($style, 'italic') !== FALSE || strpos($style, 'oblique') !== FALSE) { $attr .= 'i'; } $style = $css->GetWithDefault($class, 'text-decoration', 'none'); if (strpos($style, 'underline') !== FALSE) { $attr .= 'u'; } $pdf->AddFont($ft, $attr); $pdf->SetFont($ft, $attr, (int) ($th * 72 / 96 - 0.01) + 1); //tFPDF needs font size as pts if ($titles > 0) { $c = $css->hex2rgb($css->GetWithDefault($class, 'color', '#000')); $pdf->SetTextColor($c[0], $c[1], $c[2]); } $pdf->SetXY($lm, $tp); $pdf->Cell($this->ldata['width'] - $lm - $rm, $th, $title, 0, 0, 'C'); $params = array(); $params['pdf'] =& $pdf; $params['gw'] = $gw; $params['lw'] = $lw; if ($titles > 0) { $lc = $css->hex2rgb($css->GetWithDefault('.line', 'color', '#000')); } else { $lc = FALSE; } $params['lc'] = $lc; $params['ls'] = $css->GetWithDefault('.line', 'style', 'solid'); $params['blw'] = $blw; $params['bp'] = $bp; $params['boxstyles'] = array(); foreach (array('deflt' => '', 'nonf' => ':nonfirm', 'firm' => ':firm', 'done' => ':played', 'final' => ':winner') as $type => $suffix) { $class = '.box' . $suffix; $ft = $css->GetWithDefault($class, 'font-family', 'sans'); $style = $css->GetWithDefault($class, 'font-weight', 'normal'); $attr = $style != 'bold' ? '' : 'b'; $style = $css->GetWithDefault($class, 'font-style', 'normal'); if (strpos($style, 'italic') !== FALSE || strpos($style, 'oblique') !== FALSE) { $attr .= 'i'; } $style = $css->GetWithDefault($class, 'text-decoration', 'none'); if (strpos($style, 'underline') !== FALSE) { $attr .= 'u'; } $pdf->AddFont($ft, $attr); $size = $css->pxsize($css->GetWithDefault($class, 'font-size', $bh / 4)); if ($titles > 0) { $bc = $css->hex2rgb($css->GetWithDefault($class, 'border-color', $lc)); $fc = $css->hex2rgb($css->GetWithDefault($class, 'background-color', $back)); //TODO support image/url $tc = $css->hex2rgb($css->GetWithDefault($class, 'color', $lc)); } else { $bc = FALSE; $fc = FALSE; $tc = FALSE; } $params['boxstyles'][$type] = array('bw' => $css->pxsize($css->GetWithDefault($class, 'border-width', $lw)), 'bc' => $bc, 'bs' => $css->GetWithDefault($class, 'border-style', 'solid'), 'fill' => $fc, 'font' => $ft, 'color' => $tc, 'size' => (int) ($size * 72 / 96 - 0.01) + 1, 'attr' => $attr); } $this->Draw($params); if ($bdata['name']) { $pdf->SetTitle($bdata['name'], TRUE); } $pdf->Output($chartfile, 'F'); return TRUE; }
* CASE generating the pdf of items to rennew */ case "generate_renewal_pdf": //Prepare the PDF file include $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/Pdf/Tfpdf/tfpdf.class.php'; $pdf = new tFPDF(); //Add font for utf-8 $pdf->AddFont('DejaVu', '', 'DejaVuSansCondensed.ttf', true); $pdf->aliasNbPages(); $pdf->addPage(); $pdf->SetFont('DejaVu', '', 16); $pdf->Cell(0, 10, $LANG['renewal_needed_pdf_title'], 0, 1, 'C', false); $pdf->SetFont('DejaVu', '', 12); $pdf->Cell(0, 10, $LANG['pdf_del_date'] . date($_SESSION['settings']['date_format'] . " " . $_SESSION['settings']['time_format'], time()), 0, 1, 'C', false); $pdf->SetFont('DejaVu', '', 10); $pdf->SetFillColor(192, 192, 192); $pdf->cell(70, 6, $LANG['label'], 1, 0, "C", 1); $pdf->cell(25, 6, $LANG['creation_date'], 1, 0, "C", 1); $pdf->cell(25, 6, $LANG['expiration_date'], 1, 0, "C", 1); $pdf->cell(45, 6, $LANG['group'], 1, 0, "C", 1); $pdf->cell(25, 6, $LANG['author'], 1, 1, "C", 1); $pdf->SetFont('DejaVu', '', 9); foreach (explode('@|@', addslashes($_POST['text'])) as $line) { $elem = explode('@;@', $line); if (!empty($elem[0])) { $pdf->cell(70, 6, $elem[0], 1, 0, "L"); $pdf->cell(25, 6, $elem[1], 1, 0, "C"); $pdf->cell(25, 6, $elem[2], 1, 0, "C"); $pdf->cell(45, 6, $elem[3], 1, 0, "C"); $pdf->cell(25, 6, $elem[4], 1, 1, "C"); }
/** * Set fill color * * @param mixed $r Could be string or int. If string, it must be HTML code * @param int $g Green value (optional) * @param int $b Blue value (optional) * @param int $black Black value (optional) * * @return void */ public function setFillColor($r, $g = -1, $b = -1, $black = -1) { if (is_string($r)) { $this->html2rgb($r, $r, $g, $b); } parent::SetFillColor($r, $g, $b); }