408 lines
14 KiB
PHP
408 lines
14 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
header("Location: /?action=$action&error_code=NOACCESS");
|
|
exit();
|
|
}
|
|
|
|
|
|
// Check permissions
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Administration Team');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
header("Location: /?action=$action&error_code=NOACCESS");
|
|
return;
|
|
}
|
|
|
|
|
|
// Get parameters to script
|
|
unset($selected_schedule_num);
|
|
if (array_key_exists('schedule_num',$_GET)) $selected_schedule_num = intval($_GET['schedule_num']);
|
|
if (array_key_exists('schedule_num',$_POST)) $selected_schedule_num = intval($_POST['schedule_num']);
|
|
|
|
$mode = "menu";
|
|
if (array_key_exists('mode',$_GET)) $mode = $_GET['mode'];
|
|
if (array_key_exists('mode',$_POST)) $mode = $_POST['mode'];
|
|
|
|
|
|
|
|
//
|
|
// Setup the PDF
|
|
//
|
|
$document_font = $school_record['document_font'];
|
|
if (strlen($document_font) == 0) $document_font = "Helvetica";
|
|
|
|
$document_font_weight = "";
|
|
$document_text_color = "#000000";
|
|
$document_font_size = 9;
|
|
|
|
|
|
// Set parameters for this document
|
|
$max_rows = 185;
|
|
$max_width = 255;
|
|
$left_col = 10;
|
|
$last_col = 265;
|
|
|
|
$start_row = 10;
|
|
$incr = 4.5;
|
|
|
|
$logo_url = $school_record['logo_url'];
|
|
$logo_image = "images/" . $school_record['logo_image'];
|
|
$logo_row = $max_rows + 5;
|
|
|
|
$report_title = getLanguageText('TEXT-MENU-DETAILS-REPORT');
|
|
$report_subtitle = $school_record['school_name'];
|
|
$document_name = $report_title;
|
|
|
|
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle;
|
|
|
|
return;
|
|
|
|
$this->SetFont($document_font,"B",$document_font_size + 1);
|
|
$this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
// Report title
|
|
$this->SetXY($left_col,$start_row);
|
|
$this->Cell($title_width,$incr,$report_title,'0',1,'L',true,'',1);
|
|
}
|
|
|
|
function Footer() {
|
|
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row, $school_name;
|
|
|
|
// Print the date
|
|
$this->SetFont($document_font,"",$document_font_size - 1);
|
|
$this->SetXY($left_col,$logo_row);
|
|
$date = dateString('datetime');
|
|
$this->Cell($title_width,$incr - 1,"$document_name: $date",'0',1,'R',false,'',1);
|
|
|
|
$this->SetXY($left_col,$logo_row + $incr);
|
|
$this->Cell($title_width,$incr - 1,"$school_name",'0',1,'R','',1);
|
|
|
|
$this->Image($logo_image,10,$logo_row, 50);
|
|
|
|
$this->SetXY(20,$logo_row + 9);
|
|
$this->SetFont($document_font,"B",$document_font_size);
|
|
$this->Cell($title_width,$incr,$logo_url,'0',1,'L',false,'',1);
|
|
}
|
|
}
|
|
|
|
// Force exact physical size for Letter: 8.5 x 11 inches => 279.4mm x 215.9mm (landscape)
|
|
$pageFormat = array(279.4, 215.9);
|
|
|
|
$pdf= new PDF('L', 'mm', $pageFormat, true, 'UTF-8', false);
|
|
|
|
// set default monospaced font
|
|
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
|
|
|
|
//set margins
|
|
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
|
|
|
|
//set auto page breaks
|
|
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
|
|
|
|
//set image scale factor
|
|
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
|
|
|
$font_red = hexdec("00");
|
|
$font_green = hexdec("00");
|
|
$font_blue = hexdec("00");
|
|
|
|
$pdf->SetTextColor($font_red,$font_green,$font_blue);
|
|
|
|
$school_name = $school_record['school_name'];
|
|
|
|
|
|
// Get selected schedule
|
|
$results = db_query("SELECT * FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $selected_schedule_num");
|
|
$row = db_fetch_array($results);
|
|
extract($row);
|
|
|
|
|
|
// Set parameters for this document
|
|
$max_rows = 180;
|
|
$max_width = 255;
|
|
$last_col = 265;
|
|
|
|
|
|
if ($schedule_type == 'Hot Lunch' || $schedule_type == 'Date Sensitive') {
|
|
$columns = array(10,160,$last_col);
|
|
$fields = array('menu_title','menu_date');
|
|
$alignment = array('L','R');
|
|
$headings = array("MENU","MENU DATE");
|
|
}
|
|
else {
|
|
$columns = array(10,$last_col);
|
|
$fields = array('menu_title');
|
|
$alignment = array('L');
|
|
$headings = array("MENU");
|
|
}
|
|
|
|
|
|
if ($school_record['special_item_prices'] != 'Y') {
|
|
$columns2 = array(15,185,210,225,245,15,$last_col);
|
|
$fields2 = array('item_title','max_quantity','prods','online_price','offline_price','item_description');
|
|
$prefixes2 = array('','','',$currencySymbol,$currencySymbol,'');
|
|
$alignment2 = array('L','C','C','R','R','L');
|
|
$headings2 = array("ITEM","MAX","PRODS","ONLINE","OFFLINE","");
|
|
|
|
$columns3 = array(15,25,90,170,190,220,$last_col);
|
|
$fields3 = array('','supplier_name','product_name','package_cost','calc.1','');
|
|
$prefixes3 = array('','','',"$currencySymbol",'','');
|
|
$alignment3 = array('L','L','L','R','R','R','C');
|
|
$headings3 = array('',"SUPPLIER","PRODUCT","COST","","");
|
|
}
|
|
else {
|
|
$columns2 = array(15,135,180,190,205,220,235,250,15,$last_col);
|
|
$fields2 = array('item_title','max_quantity','prods','online_price','offline_price','special_price1','special_price2','special_price3','item_description');
|
|
// Ensure prefixes array matches length of $fields2 to avoid undefined index warnings
|
|
$prefixes2 = array('','','',$currencySymbol,$currencySymbol,$currencySymbol,$currencySymbol,$currencySymbol,'');
|
|
$alignment2 = array('L','C','C','R','R','R','R','R','L');
|
|
$headings2 = array("ITEM","MAX","PRODS","ONLINE","OFFLINE","SPECIAL1","SPECIAL2","SPECIAL3");
|
|
|
|
$columns3 = array(15,25,90,170,190,220,$last_col);
|
|
$fields3 = array('','supplier_name','product_name','package_cost','calc.1','');
|
|
$prefixes3 = array('','','',"$currencySymbol",'','');
|
|
$alignment3 = array('L','L','L','R','R','R','C');
|
|
$headings3 = array('',"SUPPLIER","PRODUCT","COST","","");
|
|
}
|
|
|
|
$start_row = 10;
|
|
$incr = 3.5;
|
|
|
|
$curr_row = $start_row;
|
|
|
|
|
|
|
|
// Get menu_dates
|
|
$menu_dates = db_query("SELECT * FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $selected_schedule_num ORDER BY sequence,menu_date");
|
|
$numDates = db_num_rows($menu_dates);
|
|
$num_dates = getLanguageText('TEXT-MENUS') . ": $numDates";
|
|
|
|
$curr_row = $max_rows + 10;
|
|
while ($row = db_fetch_array($menu_dates)) {
|
|
if ($numDates == 1) $mdate = $row['menu_date'];
|
|
|
|
if ($curr_row > $max_rows) {
|
|
$pdf->addPage();
|
|
$curr_row = $start_row;
|
|
|
|
// Display titles
|
|
$pdf->SetFont($document_font,"B",12);
|
|
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
$pdf->SetXY($columns[0],$curr_row);
|
|
$pdf->Cell($max_width,$incr + 1,$schedule_name,'0',1,'L',true,'',1);
|
|
|
|
$pdf->SetXY($last_col - 50,$curr_row);
|
|
$pdf->Cell(50,$incr + 1,$num_dates,'0',1,'R',true,'',1);
|
|
$curr_row += $incr;
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
|
|
// Print menu heading
|
|
for ($i = 0; $i < count($fields); $i++) {
|
|
$col = $columns[$i];
|
|
$align = $alignment[$i];
|
|
if (isset($columns[$i + 1]) && $columns[$i + 1] > $columns[$i]) $width = $columns[$i + 1] - $columns[$i];
|
|
else $width = $last_col - $columns[$i];
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
if (strlen($fields[$i])) $pdf->Cell($width,$incr,$row[$fields[$i]],'0',1,$align,true,'',1);
|
|
else $pdf->Cell($width,$incr,'','0',1,$align,true,'',1);
|
|
|
|
if (isset($columns[$i + 1]) && $columns[$i + 1] < $columns[$i]) $curr_row += $incr;
|
|
}
|
|
|
|
$curr_row += $incr * 2;
|
|
|
|
// Print menu items headings
|
|
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
for ($i = 0; $i < count($headings2); $i++) {
|
|
$col = $columns2[$i];
|
|
$align = $alignment2[$i];
|
|
if (isset($columns2[$i + 1]) && $columns2[$i + 1] > $columns2[$i]) $width = $columns2[$i + 1] - $columns2[$i];
|
|
else $width = $last_col - $columns2[$i];
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
if (strlen($headings2[$i])) $pdf->Cell($width,$incr,$headings2[$i],'0',1,$align,true,'',1);
|
|
else $pdf->Cell($width,$incr,'','0',1,$align,true,'',1);
|
|
}
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$curr_row += $incr;
|
|
|
|
// Get menu items
|
|
$menu_num = $row['record_num'];
|
|
$menu_items = db_query("SELECT * FROM hotlunch_menu_items WHERE school_num = $school_num AND menu_num = $menu_num AND item_type = 'Item' ORDER BY sequence");
|
|
|
|
$count = 0;
|
|
while ($row = db_fetch_array($menu_items)) {
|
|
$bg = false;
|
|
if ($count % 2) $bg = true;
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$menu_item_num = $row['record_num'];
|
|
$prods = db_getVal("SELECT count(*) FROM hotlunch_menu_products WHERE school_num = $school_num AND menu_item_num = $menu_item_num");
|
|
$row['prods'] = $prods;
|
|
|
|
$rows_needed = $incr;
|
|
if ($mode == 'products') $rows_needed += $incr * $prods * 2;
|
|
|
|
// Start a new page if there is not enough room for this menu item
|
|
if (($curr_row + $rows_needed) > $max_rows) {
|
|
$pdf->addPage();
|
|
$curr_row = $start_row;
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
}
|
|
|
|
// Print menu items
|
|
for ($i = 0; $i < count($fields2); $i++) {
|
|
$col = $columns2[$i];
|
|
$align = $alignment2[$i];
|
|
$prefix = isset($prefixes2[$i]) ? $prefixes2[$i] : '';
|
|
if (isset($columns2[$i + 1]) && $columns2[$i + 1] > $columns2[$i]) $width = $columns2[$i + 1] - $columns2[$i];
|
|
else $width = $last_col - $columns2[$i];
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
if (strlen($row[$fields2[$i]]) && strlen($fields2[$i])) $pdf->Cell($width,$incr,$prefix . $row[$fields2[$i]],'0',1,$align,$bg,'',1);
|
|
// else $pdf->Cell($width,$incr,'','0',1,$align,$bg,'',1);
|
|
|
|
if (isset($columns2[$i + 1]) && $columns2[$i + 1] < $columns2[$i] && strlen($row['item_description']) > 0) {
|
|
$curr_row += $incr;
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
}
|
|
}
|
|
$curr_row += $incr;
|
|
|
|
// Print menu item products if required
|
|
if ($mode == 'products') {
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
$menu_products = db_query("SELECT * FROM hotlunch_menu_products WHERE school_num = $school_num AND menu_item_num = $menu_item_num ORDER BY product_sequence");
|
|
$numProducts = db_num_rows($menu_products);
|
|
$productsTotal = 0;
|
|
while ($row = db_fetch_array($menu_products)) {
|
|
$supplier_product_num = $row['supplier_product_num'];
|
|
$supplier_product_qty = $row['supplier_product_qty'];
|
|
$results = db_query("SELECT * FROM supplier_products WHERE school_num = $supplier_school_num AND record_num = $supplier_product_num");
|
|
$row = array();
|
|
if (db_num_rows($results)) {
|
|
$row = db_fetch_array($results);
|
|
$supplier_num = $row['supplier_num'];
|
|
if ($supplier_num > 0) $row['supplier_name'] = db_getVal("SELECT supplier_name FROM suppliers WHERE school_num = $supplier_school_num AND record_num = $supplier_num");
|
|
else $row['supplier_name'] = "none";
|
|
}
|
|
|
|
// Print menu items
|
|
for ($i = 0; $i < count($fields3); $i++) {
|
|
$col = $columns3[$i];
|
|
$align = $alignment3[$i];
|
|
$prefix = $prefixes3[$i];
|
|
|
|
if (isset($columns3[$i + 1]) && $columns3[$i + 1] > $columns3[$i]) $width = $columns3[$i + 1] - $columns3[$i];
|
|
else $width = $last_col - $columns3[$i];
|
|
|
|
$value = '';
|
|
|
|
switch ($fields3[$i]) {
|
|
case 'package_cost':
|
|
$pattern = "%0." . $school_record['supplier_costs_decimals'] . "f pkg";
|
|
$value = '';
|
|
if (array_key_exists($fields3[$i], $row)) $value = sprintf($pattern,$row[$fields3[$i]]);
|
|
break;
|
|
|
|
case 'calc.1':
|
|
$pattern = "%0." . $school_record['supplier_costs_decimals'] . "f ea";
|
|
$pqty = 1;
|
|
if (array_key_exists('package_qty', $row)) $pqty = $row['package_qty'];
|
|
if ($pqty == 0) $pqty = 1;
|
|
$value = '';
|
|
if (array_key_exists('package_cost', $row)) {
|
|
$value = sprintf($pattern,$row['package_cost'] / $pqty);
|
|
$value .= " ( x $supplier_product_qty )";
|
|
$productsTotal += $row['package_cost'] / $pqty;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
if (array_key_exists($fields3[$i], $row)) $value = $row[$fields3[$i]];
|
|
break;
|
|
}
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
if (strlen($fields3[$i])) $pdf->Cell($width,$incr,$prefix . $value,'0',1,$align,$bg,'',1);
|
|
else $pdf->Cell($width,$incr,'','0',1,$align,$bg,'',1);
|
|
|
|
if (isset($columns3[$i + 1]) && $columns3[$i + 1] < $columns3[$i]) {
|
|
$curr_row += $incr;
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
}
|
|
}
|
|
$curr_row += $incr;
|
|
}
|
|
if ($numProducts > 1) {
|
|
$pattern = "%0." . $school_record['supplier_costs_decimals'] . "f ea";
|
|
$value = sprintf($pattern,$productsTotal);
|
|
|
|
$col = $columns3[0];
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell(250,$incr,' ','0',1,$align,$bg,'',1);
|
|
|
|
$col = $columns3[4];
|
|
$width = $columns3[5] - $col;
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->SetFont($document_font,"B",$document_font_size - 1);
|
|
$pdf->Cell($width,$incr,getLanguageText('TEXT-TOTAL') . ' ' . $currencySymbol . $value,'0',1,'R',$bg,'',1);
|
|
$curr_row += $incr;
|
|
}
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
}
|
|
|
|
$curr_row += 1;
|
|
$count++;
|
|
}
|
|
|
|
$curr_row = $max_rows + 1;
|
|
$count++;
|
|
}
|
|
|
|
|
|
// Output the completed PDF
|
|
$ext = "";
|
|
if (isset($mdate)) $ext = ".$mdate";
|
|
|
|
if ($mode == 'products') $filename = genFileName("menu-products$ext.pdf");
|
|
else $filename = genFileName("menu-details$ext.pdf");
|
|
|
|
header('Pragma: public');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
header('Cache-Control: private',false);
|
|
header('Content-type: application/pdf');
|
|
header("Content-Disposition: attachment; filename=$filename");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output($filename,"D");
|
|
return;
|
|
|
|
?>
|