\n"); $error_message = "Invalid Access"; include "form.messages.php"; exit(); } // Check permissions $AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Financial Team'); if (checkPermission($AllowedUserTypes) != 1) { echo("
\n"); $error_message = "Invalid Access"; include "form.messages.php"; return; } // Get parameters to script if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']); if (array_key_exists('menu_num',$_GET)) $menu_num = intval($_GET['menu_num']); if (!isset($schedule_num)) { echo("
\n"); $error_message = "Invalid Access"; include "form.messages.php"; return; } // Verify the schedule_num is a valid and active schedule $today = date("Y-m-d",time()); $query = "select * from hotlunch_schedules " . "where school_num = $school_num " . "and record_num = $schedule_num " . "and status = 'Active'"; $results = db_query($query); if (db_num_rows($results) == 0) { echo("
\n"); $error_message = "Invalid schedule number"; include "form.messages.php"; return; } $schedule = db_fetch_array($results); $schedule_name = $schedule['schedule_name']; $schedule_type = $schedule['schedule_type']; // Check if this is a valid menu $query = "select * from hotlunch_menu_dates " . "where school_num = $school_num " . "and schedule_num = $schedule_num " . "and record_num = $menu_num"; $results = db_query($query); if (db_num_rows($results) == 0) { echo("
\n"); $error_message = "The requested hot lunch menu is invalid"; include "form.messages.php"; return; } $hotlunch_menu_date = db_fetch_array($results); $menu_date = $hotlunch_menu_date['menu_date']; $menu_title = $hotlunch_menu_date['menu_title']; // // 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; $document_name = "Menu Price Summary"; // // Setup PDF document // require("tcpdf/config/lang/eng.php"); require("tcpdf/tcpdf.php"); // Set parameters for this document $max_rows = 180; $max_width = 230; $title_width = 200; $left_col = 20; $price_col = 130; $qty_col = 160; $total_col = 190; $last_col = 220; $start_row = 26; $incr = 5; $logo_url = $school_record['logo_url']; $logo_image = "images/" . $school_record['logo_image']; $logo_row = $max_rows + 5; class PDF extends TCPDF { function Header() { global $start_row, $incr, $left_col, $title_width, $max_rows, $max_width, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row, $school_name, $schedule_name, $schedule_type, $menu_title, $menu_date; $this->SetFont($document_font,"B",$document_font_size + 1); $this->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc")); $curr_row = 10; $this->SetXY($left_col,$curr_row); $this->Cell(100,$incr,$school_name,'0',1,'L'); $curr_row += $incr + 1; $this->SetXY($left_col,$curr_row); $this->Cell($max_width,$incr,$schedule_name,'0',1,'L',true); if ($schedule_type == 'Hot Lunch' || $schedule_type == 'Date Sensitive') $menu_title .= " - $menu_date"; $curr_row += $incr + 1; $this->SetXY($left_col,$curr_row); $this->Cell($max_width,$incr,$menu_title,'0',1,'L',true); $this->SetFont($document_font,"",$document_font_size); $curr_row = $start_row; return; } 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'); $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'); } } // 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); $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']; $school_address = $school_record['address']; $school_city = $school_record['city']; $school_province = $school_record['province']; $school_postal = $school_record['postal']; $school_phone = $school_record['phone']; $pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc")); $pdf->SetFont($document_font,"B",$document_font_size + 2); $pdf->addPage(); // Get set of menu items to print $query = "SELECT hlmi.* " . "FROM hotlunch_menu_items AS hlmi, hotlunch_menu_dates AS hlmd " . "WHERE hlmi.school_num = $school_num " . "AND hlmd.school_num = $school_num " . "AND hlmi.menu_num = hlmd.record_num " . "AND hlmd.record_num = $menu_num " . "AND hlmd.schedule_num = $schedule_num " . "order by sequence"; $items = db_query($query); // Process the items $curr_row = $start_row; $page = 1; $printHeader = true; while ($item = db_fetch_assoc($items)) { extract($item); $menu_item_num = $record_num; // Add new page if required if ($curr_row > $max_rows - $incr * 4) { $pdf->addPage(); $curr_row = $start_row; $printHeader = true; } // Print supplier header and column headers if ($printHeader) { $printHeader = false; $curr_row += $incr - 2; $curr_row += $incr; $pdf->SetXY($left_col,$curr_row); $pdf->Cell(110,$incr,getLanguageText('TEXT-MENU-ITEM'),'1',1,'L',true); $pdf->SetXY($price_col,$curr_row); $pdf->Cell($qty_col - $price_col,$incr,getLanguageText('TEXT-PRICE'),'1',1,'R',true); $pdf->SetXY($qty_col,$curr_row); $pdf->Cell($total_col - $qty_col,$incr,getLanguageText('TEXT-QUANTITY'),'1',1,'C',true); $pdf->SetXY($total_col,$curr_row); $pdf->Cell($last_col - $total_col,$incr,getLanguageText('TEXT-TOTAL'),'1',1,'R',true); $pdf->SetFont($document_font,"",$document_font_size); $curr_row += $incr; } $query = "SELECT menu_item_price, count(*) AS qty FROM hotlunch_order_items WHERE school_num = $school_num AND menu_num = $menu_num AND menu_item_num = $menu_item_num GROUP BY 1"; $ordered = db_query($query); while ($row = db_fetch_assoc($ordered)) { $pdf->SetXY($left_col,$curr_row); $pdf->Cell(110,$incr,$item_title,'1',1,'L'); $pdf->SetXY($price_col,$curr_row); $pdf->Cell($qty_col - $price_col,$incr,$currencySymbol . $row['menu_item_price'],'1',1,'R'); $pdf->SetXY($qty_col,$curr_row); $pdf->Cell($total_col - $qty_col,$incr,$row['qty'],'1',1,'C'); $total = $row['qty'] * $row['menu_item_price']; $pdf->SetXY($total_col,$curr_row); $pdf->Cell($last_col - $total_col,$incr,$currencySymbol . number_format($total,2),'1',1,'R'); $curr_row += $incr; } } // Output the completed 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=menu-price-summary.pdf"); header('Content-Transfer-Encoding: binary'); $pdf->Output("menu-price-summary.pdf","D"); ?>