\n"); $error_message = "Invalid Access"; include "form.messages.php"; exit(); } // Get parameters to script if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']); if (array_key_exists('schedule_num',$_POST)) $schedule_num = intval($_POST['schedule_num']); if (array_key_exists('selected_menu_nums',$_POST)) $selected_menu_nums = $_POST['selected_menu_nums']; if (array_key_exists('sort_by',$_POST)) $sort_by = $_POST['sort_by']; // Verify the schedule_num is valid $today = date("Y-m-d",time()); $query = "select * from hotlunch_schedules " . "where school_num = $school_num " . "and record_num = $schedule_num " . "and status != 'Deleted'"; $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); // If this is a ScheduleTeam user check if they have permission to access this schedule if ($_SESSION['UserInfo']['type'] == 'ScheduleTeam') { $userNum = intval($_SESSION['UserInfo']['record_num']); $access = db_getVal("SELECT count(*) FROM hotlunch_schedules_people WHERE school_num = $school_num AND schedule_num = $schedule_num AND user_num = $userNum"); if (!$access || $access == 0) { echo("
\n"); $error_message = "You are not allowed access to the requested hot lunch schedule"; include "form.messages.php"; return; } } // // Setup the PDF // require("tcpdf/config/lang/eng.php"); require("tcpdf/tcpdf.php"); $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; $incr = 4; $left_col = 10; $middle_col = 100; $start_row = 10; $max_rows = 270; $print_rows = $max_rows - $start_row; $header_height = $incr * 2 + 2; // Set columns $columnWidth = 39; $columns = array(); $columns[0] = $left_col; for ($i = 1; $i < 6; $i++) { $columns[$i] = $columns[$i - 1] + $columnWidth; } // Set rows $rows = array(); if ($school_record['meal_ticket_headers'] == 'Once per Page') { $rowHeight = ($print_rows - $header_height) / 5; } else { $rowHeight = $print_rows / 5; } $rows[0] = $start_row + $header_height; for ($i = 1; $i < 6; $i++) { $rows[$i] = $rows[$i - 1] + $rowHeight; } $title_width = 195; $logo_url = $school_record['logo_url']; $logo_image = "images/" . $school_record['logo_image']; $logo_row = $max_rows + 5; $report_title = $school_record['school_name'] . ' - ' . $schedule['schedule_name']; $document_name = getLanguageText('TEXT-ORDER-DETAILS'); class PDF extends TCPDF { function Header() { global $incr, $left_col, $start_row, $header_height, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle, $columns, $rows, $max_rows, $school_record; if ($school_record['meal_ticket_headers'] == 'Once per Page') { $header_row = $start_row; // Print the header $this->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd")); $this->SetFont($document_font,"B",$document_font_size + 2); $this->SetXY($left_col,$header_row); $this->Cell($title_width,$incr + 1," $report_title",'0',1,'L',true,'',1); // The subheader $this->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee")); $this->SetFont($document_font,"B",$document_font_size); $this->SetXY($left_col,$header_row + $incr + 1); $this->Cell($title_width,$incr + 1," $report_subtitle ",'0',1,'L',true,'',1); // Draw vertical lines $top_row = $header_row + $header_height; $last_row = $max_rows; for ($i = 0; $i < count($columns); $i++) { $this->Line($columns[$i],$top_row,$columns[$i],$last_row); $last_col = $columns[$i]; } // Draw horizontal lines for ($r = 0; $r < count($rows); $r++) { $row = $rows[$r]; $this->Line($left_col,$row,$last_col,$row); } } else { for ($r = 0; $r < count($rows) - 1; $r++) { $header_row = $rows[$r] - $header_height; // Print the header $this->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd")); $this->SetFont($document_font,"B",$document_font_size + 2); $this->SetXY($left_col,$header_row); $this->Cell($title_width,$incr + 1," $report_title",'0',1,'L',true,'',1); // The subheader $this->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee")); $this->SetFont($document_font,"B",$document_font_size); $this->SetXY($left_col,$header_row + $incr + 1); // $this->Cell($title_width,$incr + 1," $report_subtitle ",'0',1,'L',true,'',1); $this->Cell($title_width,$incr + 1," ",'0',1,'L',true,'',1); // Draw vertical lines $top_row = $rows[$r]; $last_row = $rows[$r + 1] - $header_height - 0.5; for ($i = 0; $i < count($columns); $i++) { $this->Line($columns[$i],$top_row,$columns[$i],$last_row); $last_col = $columns[$i]; } // Draw horizontal lines $this->Line($left_col,$top_row,$last_col,$top_row); $this->Line($left_col,$last_row,$last_col,$last_row); } } } 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; return; // 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); } } // // Setup PDF document // // Force exact physical size for Letter: 8.5 x 11 inches => 215.9mm x 279.4mm (portrait) $pageFormat = array(215.9, 279.4); $pdf= new PDF('P', '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); $pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee")); $pdf->SetFont($document_font,"",$document_font_size); $mwhere = ""; if (isset($selected_menu_nums) && is_array($selected_menu_nums)) { $mnums = implode(",",$selected_menu_nums); $mwhere = "AND record_num IN ($mnums) "; } // Get set of menu dates for this schedule $query = "SELECT * FROM hotlunch_menu_dates " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . $mwhere . "ORDER BY sequence"; $results = db_query($query); $menu_dates = array(); while ($row = db_fetch_assoc($results)) { $menu_dates[] = $row; } $first_menu_date = $menu_dates[0]['menu_date']; $first_menu_week = date("W",strtotime($first_menu_date)); $first_menu_year = date("Y",strtotime($first_menu_date)); $first_dow = date("w",strtotime($first_menu_date)); $last_menu_date = $menu_dates[count($menu_dates) - 1]['menu_date']; $last_menu_week = date("W",strtotime($last_menu_date)); $last_menu_year = date("Y",strtotime($last_menu_date)); $last_dow = date("w",strtotime($last_menu_date)); $orderby = "last_name,first_name"; if (isset($sort_by) && $sort_by == 'class') $orderby = "sequence,class_num"; // Get set of orders for this schedule $query = "SELECT hloh.*,p.first_name,p.last_name,p.class_num,c.sequence FROM hotlunch_order_header AS hloh, people AS p LEFT JOIN classes AS c ON c.school_num = $base_school_num AND p.class_num = c.record_num " . "WHERE hloh.school_num = $school_num " . "AND hloh.schedule_num = $schedule_num " . "AND hloh.ordered_by_num = p.record_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "AND p.school_num = $base_school_num " . "ORDER BY $orderby"; $orders = db_query($query); $pageStudent = 0; $weekCount = 0; while ($row = db_fetch_assoc($orders)) { extract($row); // Format header if ($class_num == 0) $class_info = getLanguageText('TEXT-CUSTOMER'); if ($class_num == 1) $class_info = getLanguageText('TEXT-STAFF'); if ($class_num > 1) $class_info = getClassInfo($class_num); $report_subtitle = $first_name . ' ' . $last_name . ' - ' . $class_info; if ($first_menu_week != $last_menu_week) $pdf->addPage(); else { $pageStudent = $weekCount % 5; if ($pageStudent == 0) $pdf->addPage(); $weekCount++; } // Process each menu date $currPage = 0; $maxWeek = $first_menu_week; for ($i = 0; $i < count($menu_dates); $i++) { $menu_date = $menu_dates[$i]; $menu_num = $menu_date['record_num']; $menuTime = strtotime($menu_date['menu_date']); $menuTitle = $menu_date['menu_title']; $dow = date("w",$menuTime); $week = date("W",$menuTime); $year = date("Y",$menuTime); if ($week >= $maxWeek) $maxWeek = $week; else $week += $maxWeek; $week_offset = $week - $first_menu_week + $pageStudent; $page = intval($week_offset / 5); if ($page > $currPage) $pdf->addPage(); $currPage = $page; $col_index = $dow - 1; $row_index = $week_offset % 5; $col = $columns[$col_index] + .5; $row = $rows[$row_index] + .5; $heading_col = $columns[0]; $heading_row = $row - $incr - 1; $pdf->SetFont($document_font,"B",$document_font_size); if (($col_index == 0 || ($i ==0 && $first_dow != 1)) && $school_record['meal_ticket_headers'] != 'Once per Page') { $pdf->setXY($heading_col,$heading_row); $pdf->Cell($title_width - 5,$incr," $report_subtitle ",'0',1,'L',true,'',1); } $pdf->setXY($col,$row); $pdf->Cell($columnWidth - 1,$incr,dateString('shortdate',$menuTime),'0',1,'L',true,'',1); $row += $incr; $pdf->setXY($col,$row); $pdf->Cell($columnWidth - 1,$incr,$menuTitle,'0',1,'L',false,'',1); $row += $incr; $pdf->SetFont($document_font,"",$document_font_size); // Get items ordered $query = "SELECT label_title,item_title,qty,sequence,hloi.options_ordered,hloi.options2_ordered,hloi.options3_ordered " . "FROM hotlunch_menu_items as hlmi, hotlunch_order_items as hloi " . "WHERE hlmi.school_num = $school_num " . "AND hlmi.menu_num = $menu_num " . "AND hlmi.record_num = hloi.menu_item_num " . "AND hloi.school_num = $school_num " . "AND hloi.ordered_by_num = $ordered_by_num " . "AND hloi.active != 'N' " . "ORDER BY hlmi.sequence"; $items_ordered = db_query($query); if (db_num_rows($items_ordered)) { while ($item = db_fetch_assoc($items_ordered)) { $title = $item['item_title']; $pdf->setXY($col,$row); $pdf->Cell($columnWidth - 1,$incr," $title",'0',1,'L',false,'',1); $row += $incr; } } } } // Output the completed PDF $filename = "ticket.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"); ?>