0 " . "order by sequence"; $menu_items = db_query($query); $selected_items = array(); while ($row = db_fetch_array($menu_items)) { extract($row); $selected_items[] = array("title" => $item_title, "item_num" => $record_num); } // Initialize the PDF document $document_font = "Helvetica"; $document_font_weight = ""; $document_text_color = "#000000"; $document_font_size = 8; $incr = 4; // Set parameters for this document $start_row = 10; $max_rows = 250; $curr_row = $start_row; $new_page = true; $width = 200; $option_width = 200; $left_col = 10; $option_col = 10; $qty_col = 190; $document_name = getLanguageText('TEXT-OPTION-DETAILS-REPORT'); // // Setup PDF document // require("tcpdf/config/lang/eng.php"); require("tcpdf/tcpdf.php"); $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 $curr_row, $start_row, $document_font, $document_font_size, $font_parm, $left_col, $incr, $width; global $school_name, $class_info, $rpt_title; $curr_row = $start_row; // Print report titles $this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb")); $this->SetFont($document_font,'B',$document_font_size + 1); $this->SetXY($left_col,$curr_row); $this->Cell($width,$incr + 2,$school_name,'0',1,'L',true); $this->SetXY($left_col + 100,$curr_row); $this->Cell($width - 100,$incr + 2,$rpt_title,'0',1,'R',true); $curr_row += $incr * 2; $this->SetXY($left_col,$curr_row); $this->Cell($width,$incr + 2,$class_info,'0',1,'L',true); $curr_row += $incr * 2; // $this->SetXY($left_col,$curr_row); // $this->Cell($width,$incr + 2,$class_info,'0',1,'L',true); $this->SetFont($document_font,$font_parm,$document_font_size); $this->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc")); $curr_row = $start_row + $incr * 5; } 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 => 215.9mm x 279.4mm (portrait) $pageFormat = array(215.9, 279.4); $pdf= new PDF('P', 'mm', $pageFormat, true, 'UTF-8', false); $pdf->SetAutoPageBreak(false,0); $font_parm = $document_font_weight; $font_red = hexdec(substr(str_replace("#","",$document_text_color),0,2)); $font_green = hexdec(substr(str_replace("#","",$document_text_color),2,2)); $font_blue = hexdec(substr(str_replace("#","",$document_text_color),4,2)); $pdf->SetTextColor($font_red,$font_green,$font_blue); $pdf->SetFont($document_font,$font_parm,$document_font_size); $pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc")); // // Get count of each selected option // $selected_classes = array(); if ($mode == 'Class') { $classes = db_query("SELECT hlsc.class_num FROM hotlunch_schedules_classes AS hlsc,classes as c " . "WHERE hlsc.school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND hlsc.class_num = c.record_num " . "ORDER BY c.sequence"); if (db_num_rows($classes) == 0) $classes = db_query("SELECT record_num AS class_num FROM classes WHERE school_num = $school_num ORDER BY sequence"); $selected_classes[] = 0; while ($class = db_fetch_array($classes)) { $selected_classes[] = $class['class_num']; } } $selected_classes[] = -1; // // Process the selected classes // $pageNum = 0; for ($cnum = 0; $cnum < count($selected_classes); $cnum++) { $class_num = $selected_classes[$cnum]; if ($class_num > 1) $class_info = getClassInfo($class_num); else { if ($class_num == 0) $class_info = $GlobalText['Staff']; if ($class_num == 1) $class_info = getLanguageText('TEXT-CUSTOMER'); if ($class_num == -1) $class_info = getLanguageText('TEXT-TOTALS'); } $pdf->addPage(); $pageNum++; $curr_row = $start_row + $incr * 5; // Process each menu item for ($i = 0; $i < count($selected_items); $i++) { $item_title = $selected_items[$i]['title']; $item_num = $selected_items[$i]['item_num']; $pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb")); $pdf->SetFont($document_font,"B",$document_font_size); $pdf->SetXY($option_col,$curr_row); $pdf->Cell($option_width,$incr,$item_title,'0',1,'L',true); $pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd")); $pdf->SetFont($document_font,"",$document_font_size); $curr_row += $incr; if ($curr_row > $max_rows) { $pdf->addPage(); $pageNum++; $curr_row = $start_row + $incr * 5; } if ($class_num >= 0) { if ($school_record['staff_meals_to_classroom'] == 'N') { if ($class_num == 0) { $query = "SELECT options_ordered,options2_ordered,options3_ordered,sum(qty) AS quantity FROM hotlunch_order_items as hloi, hotlunch_order_header AS hloh, people as p " . "WHERE hloi.school_num = $school_num " . "AND hloh.school_num = $school_num " . "AND p.school_num = $school_num " . "AND hloi.order_num = hloh.record_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "AND hloi.menu_num = $menu_num " . "AND hloi.menu_item_num = $item_num " . "AND hloi.ordered_by_num = p.record_num " . "AND hloi.ordered_by_type = 'Staff' " . "AND hloi.active != 'N' " . "GROUP BY 1,2,3"; } else { $query = "SELECT options_ordered,options2_ordered,options3_ordered,sum(qty) AS quantity FROM hotlunch_order_items as hloi, hotlunch_order_header AS hloh, people as p " . "WHERE hloi.school_num = $school_num " . "AND hloh.school_num = $school_num " . "AND p.school_num = $school_num " . "AND hloi.order_num = hloh.record_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "AND hloi.menu_num = $menu_num " . "AND hloi.menu_item_num = $item_num " . "AND hloi.ordered_by_num = p.record_num " . "AND hloi.ordered_by_type IN ('Student','Customer') " . "AND hloi.active != 'N' " . "AND p.class_num = $class_num " . "GROUP BY 1,2,3"; } } else { $query = "SELECT options_ordered,options2_ordered,options3_ordered,sum(qty) AS quantity FROM hotlunch_order_items as hloi, hotlunch_order_header AS hloh, people as p " . "WHERE hloi.school_num = $school_num " . "AND hloh.school_num = $school_num " . "AND p.school_num = $school_num " . "AND hloi.order_num = hloh.record_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "AND hloi.menu_num = $menu_num " . "AND hloi.menu_item_num = $item_num " . "AND hloi.ordered_by_num = p.record_num " . "AND hloi.active != 'N' " . "AND p.class_num = $class_num " . "GROUP BY 1,2,3"; } } else { $query = "SELECT options_ordered,options2_ordered,options3_ordered,sum(qty) AS quantity FROM hotlunch_order_items AS hloi, hotlunch_order_header AS hloh " . "WHERE hloi.school_num = $school_num " . "AND hloh.school_num = $school_num " . "AND hloi.order_num = hloh.record_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "AND hloi.menu_num = $menu_num " . "AND hloi.menu_item_num = $item_num " . "AND hloi.active != 'N' " . "GROUP BY 1,2,3"; } // Get the data $results = db_query($query); // Print results if (db_num_rows($results) > 0) { $count = 0; while ($row = db_fetch_array($results)) { extract($row); $pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd")); if ($count % 2) $pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee")); $options_ordered = trim($options_ordered); $options2_ordered = trim($options2_ordered); $options3_ordered = trim($options3_ordered); if (strlen($options2_ordered)) { if (strlen($options_ordered)) $options_ordered .= "\n$options2_ordered"; else $options_ordered = $options2_ordered; } if (strlen($options3_ordered)) { if (strlen($options_ordered)) $options_ordered .= "\n$options3_ordered"; else $options_ordered = $options3_ordered; } if (strlen($options_ordered) == 0) $options_ordered = getLanguageText('TEXT-NO-OPTIONS-SELECTED'); else $options_ordered = preg_replace("/\n/",", ",trim($options_ordered)); $pdf->SetXY($option_col,$curr_row); $pdf->Cell($option_width,$incr,$options_ordered,'0',1,'L',true); $pdf->SetXY($qty_col,$curr_row); $pdf->Cell(15,$incr,$quantity,'0',1,'R',true); $curr_row += $incr; if ($curr_row > $max_rows) { $pdf->addPage(); $pageNum++; $curr_row = $start_row + $incr * 5; } $count++; } } else { $pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd")); $options_ordered = getLanguageText('TEXT-NO-ITEMS-ORDERED'); $pdf->SetXY($option_col,$curr_row); $pdf->Cell($option_width,$incr,$options_ordered,'0',1,'L',true); $curr_row += $incr; } $curr_row += $incr; } } 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=option-details.pdf"); header('Content-Transfer-Encoding: binary'); $pdf->Output("option-details.pdf","D"); ?>