More security/sanitizing fixes
[busui.git] / stop.pdf.php
blob:a/stop.pdf.php -> blob:b/stop.pdf.php
<?php <?php
include('common.inc.php'); include('common.inc.php');
$url = $APIurl."/json/stop?stop_id=".$_REQUEST['stopid']; $stopid = filter_var($_REQUEST['stopid'],FILTER_SANITIZE_NUMBER_INT);
  $url = $APIurl."/json/stop?stop_id=".$stopid;
$stop = json_decode(getPage($url)); $stop = json_decode(getPage($url));
   
$html .= '<div data-role="content" class="ui-content" role="main"><p>'.staticmap(Array(0 => Array($stop[2],$stop[3])), 0,"iconb", false).'</p>'; $html .= '<div data-role="content" class="ui-content" role="main"><p>'.staticmap(Array(0 => Array($stop[2],$stop[3])), 0,"iconb", false).'</p>';
$html .= ' <ul data-role="listview" data-inset="true">'; $html .= ' <ul data-role="listview" data-inset="true">';
$url = $APIurl."/json/stoptrips?stop=".$_REQUEST['stopid']."&time=".midnight_seconds()."&service_period=".service_period(); $url = $APIurl."/json/stoptrips?stop=".$stopid."&time=".midnight_seconds()."&service_period=".service_period();
$trips = json_decode(getPage($url)); $trips = json_decode(getPage($url));
debug(print_r($trips,true)); debug(print_r($trips,true));
foreach ($trips as $row) foreach ($trips as $row)
{ {
$html .= '<li>'; $html .= '<li>';
$html .= '<h3><a href="trip.php?stopid='.$_REQUEST['stopid'].'&tripid='.$row[1][0].'">'.$row[1][1]; $html .= '<h3><a href="trip.php?stopid='.$stopid.'&tripid='.$row[1][0].'">'.$row[1][1];
if (isFastDevice()) { if (isFastDevice()) {
$viaPoints = viaPointNames($row[1][0],$_REQUEST['stopid']); $viaPoints = viaPointNames($row[1][0],$stopid);
if ($viaPoints != "") $html .= '<br><small>Via: '.$viaPoints.'</small> </a></h3>'; if ($viaPoints != "") $html .= '<br><small>Via: '.$viaPoints.'</small> </a></h3>';
} }
$html .= '<p class="ui-li-aside"><strong>'.midnight_seconds_to_time($row[0]).'</strong></p>'; $html .= '<p class="ui-li-aside"><strong>'.midnight_seconds_to_time($row[0]).'</strong></p>';
$html .= '</li>'; $html .= '</li>';
} }
if (sizeof($trips) == 0) $html .= "<li> <center>No trips in the near future.</center> </li>"; if (sizeof($trips) == 0) $html .= "<li> <center>No trips in the near future.</center> </li>";
$html .= '</ul></div>'; $html .= '</ul></div>';
require_once('tcpdf/config/lang/eng.php'); require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php'); require_once('tcpdf/tcpdf.php');
   
// create new PDF document // create new PDF document
class Custom_TCPDF extends TCPDF { class Custom_TCPDF extends TCPDF {
var $QRCodeURL; var $QRCodeURL;
function set_QRCodeURL ($url) { function set_QRCodeURL ($url) {
$this->QRCodeURL = $url; $this->QRCodeURL = $url;
} }
   
/** /**
* This method is used to render the page header. * This method is used to render the page header.
* It is automatically called by AddPage() and could be overwritten in your own inherited class. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
* @public * @public
*/ */
public function Header() { public function Header() {
if ($this->header_xobjid < 0) { if ($this->header_xobjid < 0) {
// start a new XObject Template // start a new XObject Template
$this->header_xobjid = $this->startTemplate($this->w, $this->tMargin+10); $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin+10);
$headerfont = $this->getHeaderFont(); $headerfont = $this->getHeaderFont();
$headerdata = $this->getHeaderData(); $headerdata = $this->getHeaderData();
$this->y = $this->header_margin; $this->y = $this->header_margin;
if ($this->rtl) { if ($this->rtl) {
$this->x = $this->w - $this->original_rMargin; $this->x = $this->w - $this->original_rMargin;
} else { } else {
$this->x = $this->original_lMargin-10; $this->x = $this->original_lMargin-10;
} }
if (isset($this->QRCodeURL)) { if (isset($this->QRCodeURL)) {
// QRCODE,H : QR-CODE Best error correction // QRCODE,H : QR-CODE Best error correction
$style = array( $style = array(
'border' => 1, 'border' => 1,
'padding' => 0, 'padding' => 0,
'fgcolor' => array(0,0,0), 'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255) 'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points 'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points 'module_height' => 1 // height of a single module in points
); );
$this->write2DBarcode($this->QRCodeURL, 'QRCODE,H', '', '', 25, 25, $style, 'T'); $this->write2DBarcode($this->QRCodeURL, 'QRCODE,H', '', '', 25, 25, $style, 'T');
$imgy = 50+20; $imgy = 50+20;
} elseif (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) { } elseif (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
$imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']); $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
if (($imgtype == 'eps') OR ($imgtype == 'ai')) { if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
$this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
} elseif ($imgtype == 'svg') { } elseif ($imgtype == 'svg') {
$this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
} else { } else {
$this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']); $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
} }
$imgy = $this->getImageRBY(); $imgy = $this->getImageRBY();
} else { } else {
$imgy = $this->y; $imgy = $this->y;
} }
$cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2); $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2);
// set starting margin for text data cell // set starting margin for text data cell
if ($this->getRTL()) { if ($this->getRTL()) {
$header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1); $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
} else { } else {
$header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1); $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
} }
$cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1); $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
$this->SetTextColor(0, 0, 0); $this->SetTextColor(0, 0, 0);
// header title // header title
$this->SetFont($headerfont[0], 'B', $headerfont[2] + 1); $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
$this->SetX($header_x); $this->SetX($header_x);
$this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0); $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
// header string // header string
$this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]); $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
$this->SetX($header_x); $this->SetX($header_x);
$this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false); $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
// print an ending header line // print an ending header line
//$this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); //$this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
//$this->SetY((2.835 / $this->k) + max($imgy, $this->y)); //$this->SetY((2.835 / $this->k) + max($imgy, $this->y));
if ($this->rtl) { if ($this->rtl) {
$this->SetX($this->original_rMargin); $this->SetX($this->original_rMargin);
} else { } else {
$this->SetX($this->original_lMargin); $this->SetX($this->original_lMargin);
} }
//$this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C'); //$this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
$this->endTemplate(); $this->endTemplate();
} }
// print header template // print header template
$x = 0; $x = 0;
$dx = 0; $dx = 0;
if ($this->booklet AND (($this->page % 2) == 0)) { if ($this->booklet AND (($this->page % 2) == 0)) {
// adjust margins for booklet mode // adjust margins for booklet mode
$dx = ($this->original_lMargin - $this->original_rMargin); $dx = ($this->original_lMargin - $this->original_rMargin);
} }
if ($this->rtl) { if ($this->rtl) {
$x = $this->w + $dx; $x = $this->w + $dx;
} else { } else {
$x = 0 + $dx; $x = 0 + $dx;
} }
$this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false); $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
} }
   
   
} }
$pdf = new Custom_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf = new Custom_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
   
// set document information // set document information
$pdf->SetCreator(PDF_CREATOR); $pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('bus.lambdacomplex.org'); $pdf->SetAuthor('bus.lambdacomplex.org');
$pdf->SetTitle($stop[1]); $pdf->SetTitle($stop[1]);
   
// set default header data // set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $stop[1] . " Timetable", "Some description of customization like Weekdays, 9am-10am"); $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $stop[1] . " Timetable", "Some description of customization like Weekdays, 9am-10am");
$pdf->set_QRCodeURL(curPageURL()."stop.php?stopid=".$_REQUEST['stopid']); $pdf->set_QRCodeURL(curPageURL()."stop.php?stopid=".$_REQUEST['stopid']);
   
// set header and footer fonts // set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
   
// set default monospaced font // set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
   
//set margins //set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
   
//set auto page breaks //set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
   
//set image scale factor //set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
   
//set some language-dependent strings //set some language-dependent strings
$pdf->setLanguageArray($l); $pdf->setLanguageArray($l);
   
// --------------------------------------------------------- // ---------------------------------------------------------
   
// set default font subsetting mode // set default font subsetting mode
$pdf->setFontSubsetting(true); $pdf->setFontSubsetting(true);
   
// Set font // Set font
// dejavusans is a UTF-8 Unicode font, if you only need to // dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like // print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size. // helvetica or times to reduce file size.
$pdf->SetFont('helvetica', '', 14, '', true); $pdf->SetFont('helvetica', '', 14, '', true);
   
// Add a page // Add a page
// This method has several options, check the source code documentation for more information. // This method has several options, check the source code documentation for more information.
$pdf->AddPage(); $pdf->AddPage();
   
   
// Print text using writeHTMLCell() // Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true); $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
   
   
   
// --------------------------------------------------------- // ---------------------------------------------------------
   
// Close and output PDF document // Close and output PDF document
// This method has several options, check the source code documentation for more information. // This method has several options, check the source code documentation for more information.
$pdf->Output('example_001.pdf', 'I'); $pdf->Output('example_001.pdf', 'I');
   
//============================================================+ //============================================================+
// END OF FILE // END OF FILE
//============================================================+ //============================================================+
?> ?>