0) { $selected_classes_string = implode(',',$selected_classes); // Handle the Concession Order if (strpos($selected_classes_string, "Concession") !== false) { $selected_classes_string = str_replace(",Concession","",$selected_classes_string); $selected_classes_string = str_replace("Concession,","",$selected_classes_string); $selected_classes_string = str_replace("Concession","",$selected_classes_string); $cquery = "select 'Concession' as name,'Concession' as first_name,'Concession' as last_name,-1,0,0 as division,'' as description,0,'' as label_note," . "hloi.menu_item_num,hloi.qty,hloi.options_ordered,hloi.options2_ordered,hloi.options3_ordered,hlmi.item_title,hlmi.label_title as label_title," . "hlmi.sequence,999 as class_sequence,'' as lastname,'' as firstname,'Concession','' as order_notes,options_title,options2_title,options3_title " . "from hotlunch_order_items as hloi, hotlunch_menu_items as hlmi " . "where hloi.school_num = $school_num " . "and hlmi.school_num = $school_num " . "and hloi.ordered_by_type = 'Concession' " . "and hloi.menu_item_num in ($items) " . "and hloi.menu_item_num = hlmi.record_num " . "AND hloi.active != 'N' "; } $selectedClasses = "and p.$classNumField in (1) "; if (isset($selected_classes_string) && strlen($selected_classes_string)) $selectedClasses = "and p.$classNumField in ($selected_classes_string,1) "; } // // Create label query // $query = ""; if (isset($selected_classes_string) || !isset($selected_classes)) { $query = "select concat(p.first_name,' ',p.last_name) as name,p.first_name,p.last_name,p.$classNumField AS class_num,p.record_num AS people_num,c.division,c.description,c.grade,label_note," . "hloi.menu_item_num,hloi.qty,hloi.options_ordered,hloi.options2_ordered,hloi.options3_ordered,hlmi.item_title,hlmi.label_title as label_title," . "hlmi.sequence,c.sequence as class_sequence,p.last_name as lastname,p.first_name as firstname,people_type,order_notes,options_title,options2_title,options3_title " . "from hotlunch_order_items as hloi, hotlunch_order_header as hloh, hotlunch_menu_items as hlmi, people as p left join classes as c on p.$classNumField = c.record_num " . "where hloi.school_num = $school_num " . "and hlmi.school_num = $school_num " . "and hloi.ordered_by_num = p.record_num " . "and hloi.order_num = hloh.record_num " . "and hloh.school_num = $school_num " . "and hloh.status not in ('Inactive','Deleted') " . "and p.school_num = $base_school_num " . "and hloi.menu_item_num in ($items) " . "and hloi.menu_item_num = hlmi.record_num " . "AND hloi.active != 'N' " . $selectedClasses; writeLog($query); } if (strlen($query) && strlen($cquery)) $query .= "UNION "; $query .= $cquery; writeLog($query); // Ensure that there are some labels to be selected if (strlen($query) == 0) { header("Location: /?action=item-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOLABELS"); exit(); } $query .= "order by $order_by"; writeLog("---"); writeLog($query); $labels = db_query($query); writeLog("Labels count: ".db_num_rows($labels)); // // Setup the label parameters // writeLog("labelFormat:: $labelFormat"); switch ($labelFormat) { case 'mailinglabels': default: // 12 per sheet $startColumn = 8; $columnWidth = 70; $labelWidth = $columnWidth - 20; $labelColumns = array(); $labelColumns[] = $startColumn; $labelColumns[] = $startColumn + $columnWidth; $labelColumns[] = $startColumn + $columnWidth * 2; $startRow = 15.5; $rowHeight = 25.8; $labelRows = array(); for ($i = 0; $i < 10; $i++) { $labelRows[] = $startRow + $rowHeight * $i; } $numLabels = count($labelColumns) * count($labelRows); $fontSize = 9; if (isset($font_size) && $font_size != 'default') $fontSize = $font_size; $incr = 3.5; $labelSize = 'small'; break; case 'mailinglabels-o1': // 12 per sheet $startColumn = 12; $columnWidth = 72; $labelWidth = $columnWidth - 20; $labelColumns = array(); $labelColumns[] = $startColumn; $labelColumns[] = $startColumn + $columnWidth; $labelColumns[] = $startColumn + $columnWidth * 2; $startRow = 15.5; $rowHeight = 25.8; $labelRows = array(); for ($i = 0; $i < 10; $i++) { $labelRows[] = $startRow + $rowHeight * $i; } $numLabels = count($labelColumns) * count($labelRows); $fontSize = 9; if (isset($font_size) && $font_size != 'default') $fontSize = $font_size; $incr = 3.5; $labelSize = 'small'; break; case 'returnaddresslabels': // 80 per sheet $startColumn = 10; $columnWidth = 52; $labelWidth = $columnWidth - 5; $labelColumns = array(); $labelColumns[] = $startColumn; $labelColumns[] = $startColumn + $columnWidth; $labelColumns[] = $startColumn + $columnWidth * 2; $labelColumns[] = $startColumn + $columnWidth * 3; $startRow = 15.5; $rowHeight = 12.69; $labelRows = array(); for ($i = 0; $i < 20; $i++) { $labelRows[] = $startRow + $rowHeight * $i; } $numLabels = count($labelColumns) * count($labelRows); $fontSize = 8; if (isset($font_size) && $font_size != 'default') $fontSize = $font_size; $incr = 2.7; $labelSize = 'verysmall'; $print_date = 'N'; // echo($numLabels); // echo("
\n"); // echo($labelRows[19]); // exit(); break; case 'mailinglabels-large': // 10 per sheet $startColumn = 8; $columnWidth = 105; $labelWidth = $columnWidth - 20; $labelColumns = array(); $labelColumns[] = $startColumn; $labelColumns[] = $startColumn + $columnWidth; $startRow = 15.5; $rowHeight = 52.0; $labelRows = array(); for ($i = 0; $i < 5; $i++) { $labelRows[] = $startRow + $rowHeight * $i; } $numLabels = count($labelColumns) * count($labelRows); $fontSize = 12; if (isset($font_size) && $font_size != 'default') $fontSize = $font_size; $incr = 5; $labelSize = 'small'; break; case 'shippinglabels6': // 6 per sheet $startColumn = 8; $columnWidth = 105; $labelWidth = $columnWidth - 20; $labelColumns = array(); $labelColumns[] = $startColumn; $labelColumns[] = $startColumn + $columnWidth; $startRow = 15.5; $rowHeight = 84.0; $labelRows = array(); for ($i = 0; $i < 3; $i++) { $labelRows[] = $startRow + $rowHeight * $i; } $numLabels = count($labelColumns) * count($labelRows); $fontSize = 12; if (isset($font_size) && $font_size != 'default') $fontSize = $font_size; $incr = 5; $labelSize = 'large'; break; case 'shippinglabels': // 4 per sheet $startColumn = 8; $columnWidth = 105; $labelWidth = $columnWidth - 20; $labelColumns = array(); $labelColumns[] = $startColumn; $labelColumns[] = $startColumn + $columnWidth; $startRow = 15.5; $rowHeight = 120.0; $labelRows = array(); for ($i = 0; $i < 2; $i++) { $labelRows[] = $startRow + $rowHeight * $i; } $numLabels = count($labelColumns) * count($labelRows); $fontSize = 12; if (isset($font_size) && $font_size != 'default') $fontSize = $font_size; $incr = 5; $labelSize = 'large'; break; } // Initialize the PDF document $document_font = $school_record['document_font']; if (strlen($document_font) == 0) $document_font = "Helvetica"; $document_font_weight = ""; $document_text_color = "#000000"; $document_font_size = $fontSize; // // Setup PDF document // require("tcpdf/config/lang/eng.php"); require("tcpdf/tcpdf.php"); class PDF extends TCPDF { function Header() { return; } function Footer() { return; } } // 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); // 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"); // Default font style parameter for TCPDF SetFont (e.g. '', 'B', 'I', 'BI') $font_parm = ""; $pdf->SetTextColor($font_red,$font_green,$font_blue); $pdf->SetFont($document_font,"",$document_font_size); $pdf->addPage(); $pdf->SetAutoPageBreak(false); $default_offset = 10; $labelColumn = 1; $labelRow = 1; $labelNumber = 1; $prev_div = -1; // Process each record while ($entry = db_fetch_array($labels)) { extract($entry); $name = trim($name); // Get class information $class_info = ""; if (!isset($division_num)) $division_num = ''; if (isset($display_options) && is_array($display_options) && in_array('Class',$display_options)) { writeLog("CLASS NUM: $class_num"); if ($class_num > 0) { if (is_numeric($class_num)) { $label_description = db_getVal("SELECT label_description FROM classes WHERE school_num = $school_num AND record_num = $class_num"); writeLog("label_description: $label_description"); $class_info = getClassInfo($class_num,'label'); writeLog(print_r($class_info, true)); } else { $label_description = ""; $class_info = $class_num; } $division_num = db_getVal("SELECT division FROM classes WHERE school_num = $school_num AND record_num = $class_num"); if ($class_info == "Customer") { $phone = db_getVal("SELECT home_phone FROM users AS u, people AS p ". "WHERE u.school_num = $base_school_num " . "AND p.user_num = u.record_num " . "AND p.record_num = $people_num"); $class_info .= " $phone"; } } else { $division_num = ""; $class_info = $GlobalText['Teacher']; if (isset($class_num) && $class_num === 0) { $class_info = getLanguageText('TEXT-STAFF'); } if (isset($class_num) && $class_num === 1) { $class_info = getLanguageText('TEXT-CUSTOMERS'); } } // writeLog($class_info); } // Handle division breaks if required // writeLog("$div_breaks / $division_num / $prev_div"); if ($div_breaks == 'Y' && $division_num != $prev_div && $prev_div != -1) { $lnum = $labelNumber % count($labelColumns); writeLog("labelNumber: $labelNumber"); writeLog("lnum: $lnum"); switch ($lnum) { case 0: $labelNumber += 1; break; case 1: $labelColumn = 1; break; case 2: $labelNumber += count($labelColumns) - $lnum + 1; break; } } $prev_div = $division_num; $nLabels = $qty; $mItem = $menuItems[$menu_item_num]; if (array_key_exists('number_of_labels', $mItem) && intval($mItem['number_of_labels']) > 0) { $nLabels = $qty * intval($mItem['number_of_labels']); } // Print one label for each item ordered based on quantity ordered for ($i = 0; $i < $nLabels; $i++) { // Add a new page if required if ($labelNumber > $numLabels) { $labelNumber = 1; $pdf->addPage(); } // Generate the label for this record $labelColumn = ($labelNumber - 1) % count($labelColumns); $labelRow = intval(($labelNumber + count($labelColumns) - 1) / count($labelColumns)) - 1; $column = $labelColumns[$labelColumn]; $row = $labelRows[$labelRow]; if ($name == 'Concession') { unset($division); unset($grade); } // Set text offset $offset = 0; if (($school_record['i_display_division'] == 'Y' && isset($division_num) && strlen($division_num) > 0) || ($school_record['i_display_grade'] == 'Y' && isset($grade) && strlen($grade) > 0)) $offset = $default_offset; if ($school_record['staff_meals_to_classroom'] == 'N' && $people_type == 'Staff') { $division_num = ""; $grade = ""; $offset = 0; } // Print division number $grade_printed = false; $grade_offset = 8; if ($school_record['i_display_division'] == 'Y' && isset($division) && strlen($division) > 0) { $pdf->SetFont($document_font,$font_parm,$document_font_size + 3); if (strlen($division) > 4) $pdf->SetFont($document_font,$font_parm,$document_font_size + 2); $pdf->SetXY($column,$row); $pdf->Cell(9,$incr + 3,$division,'0',1,'L',false,'',1); $grade_printed = true; } // Print grade if available elseif ($school_record['i_display_grade'] == 'Y' && isset($grade) && strlen($grade) > 0) { $pdf->SetFont($document_font,$font_parm,$document_font_size + 3); if (strlen($grade) > 4) $pdf->SetFont($document_font,$font_parm,$document_font_size + 2); $pdf->SetXY($column,$row); $pdf->Cell(9,$incr + 3,$grade,'0',1,'L',false,'',1); $grade_printed = true; } // Add school name if required if ($print_school_name == 'Y') { $pdf->SetFont($document_font,"",$document_font_size); $pdf->SetXY($column + $offset,$row); if ($grade_printed) $pdf->SetXY($column + $offset + $grade_offset,$row); $pdf->Cell($labelWidth - $offset,$incr,$school_record['school_name'],'0',1,'L',false,'',1); $row += $incr; } // Add student name to label if ($print_student_info != 'N') { $printName = $name; if ($print_student_info == 'F') $printName = trim($first_name); if ($print_student_info == 'L') $printName = trim($last_name); if ($print_student_info == 'I') $printName = substr($first_name,0,1).'. '.trim($last_name); if ($print_student_info == 'FI') $printName = trim($first_name).' '.substr($last_name,0,1); $pdf->SetFont($document_font,"B",$document_font_size); $pdf->SetXY($column + $offset,$row); if ($grade_printed) $pdf->SetXY($column + $offset + $grade_offset,$row); $pdf->Cell($labelWidth - $offset,$incr + 1,$printName,'0',1,'L',false,'',1); $row += $incr; if (strlen($label_note) && $labelSize != 'verysmall') { $row -= .25; $pdf->SetFont($document_font,"",$document_font_size - 3); $pdf->SetXY($column + $offset,$row); $pdf->Cell($labelWidth - $offset,$incr - 1,$label_note,'0',1,'L',false,'',1); $row += $incr - .8; } } else { $row += $incr - .8; } // Add label description if required if (isset($display_options) && is_array($display_options) && in_array('Label',$display_options)) { // Add description to label $class_num = intval($class_num); $label_description = db_getVal("SELECT label_description FROM classes WHERE school_num = $school_num AND record_num = $class_num"); writeLog("$label_description - $name - $labelSize"); if ($name != 'Concession' && $labelSize != 'verysmall') { if (!isset($label_description)) $label_description = ''; $pdf->SetFont($document_font,"B",$document_font_size - 2); $pdf->SetXY($column + $offset,$row); $pdf->Cell($labelWidth - $offset,$incr,$label_description,'0',1,'L',false,'',1); $row += $incr; } } else $row += $incr - 1.5; // Add class info if required if (isset($display_options) && is_array($display_options) && in_array('Class',$display_options)) { // Add class info to label if ($name != 'Concession' && $labelSize != 'verysmall') { $pdf->SetFont($document_font,"B",$document_font_size - 2); $pdf->SetXY($column + $offset,$row); $pdf->Cell($labelWidth - $offset,$incr,$class_info,'0',1,'L',false,'',1); $row += $incr; } } else $row += $incr - 1.5; // Print item title $pdf->SetFont($document_font,"B",$document_font_size - 1); if ($labelSize == 'verysmall') $pdf->SetFont($document_font,"B",$document_font_size - 2); $label_title = htmlspecialchars_decode($label_title,ENT_QUOTES); if (strlen($label_title) == 0) $label_title = $item_title; if (strlen($label_title) > 31) $label_title = substr($label_title,0,29) . "..."; $pdf->SetXY($column,$row); $pdf->Cell($labelWidth,$incr,$label_title,'0',1,'L',false,'',1); $row += $incr - 1.0; // Display remainder of label if ((strlen($options_ordered) || strlen($options2_ordered) || strlen($options3_ordered)) && isset($display_options) && is_array($display_options) && in_array('Options',$display_options) && $labelSize != 'verysmall') { // Add options info to label $pdf->SetFont($document_font,"",$document_font_size - 2); $pdf->SetXY($column,$row); if ($labelSize == 'small' && $school_record['label_separate_options'] == 'N') { $options = str_replace("\n",", ",trim(trim($options_ordered)."\n".trim($options2_ordered)."\n".trim($options3_ordered))); $options = str_replace(", ",",",trim($options)); } else { $options = ""; if ($school_record['label_separate_options'] == 'Y') { if (strlen(trim($options_ordered))) { if (strlen($options_title)) $options .= $options_title.':'.str_replace("\n",", ",trim($options_ordered))."\n"; else $options .= $options_title.'-'.str_replace("\n",", ",trim($options_ordered))."\n"; } if (strlen(trim($options2_ordered))) { if (strlen($options2_title)) $options .= $options2_title.':'.str_replace("\n", ",",trim($options2_ordered))."\n"; else $options .= str_replace("\n",", ",trim($options2_ordered))."\n"; } if (strlen(trim($options3_ordered))) { if (strlen($options3_title)) $options .= $options3_title.':'.str_replace("\n", ",",trim($options3_ordered))."\n"; else $options .= str_replace("\n",", ",trim($options3_ordered))."\n"; } } else { if (strlen(trim($options_ordered))) $options .= str_replace("\n",", ",trim($options_ordered))."\n"; if (strlen(trim($options2_ordered))) $options .= str_replace("\n",", ",trim($options2_ordered))."\n"; if (strlen(trim($options3_ordered))) $options .= str_replace("\n",", ",trim($options3_ordered))."\n"; } // $options = trim($options_ordered)."\n".trim($options2_ordered)."\n".trim($options3_ordered); $options = trim($options); } $pdf->MultiCell($labelWidth,$incr - 2.0,$options,'0','L',false); $row = $pdf->GetY(); } // Add order note if there is one if (strlen($order_notes)) { $note = $order_notes; if (strlen($note) > 100) $note = substr($order_notes,0,100) . "..."; $pdf->SetFont($document_font,"",$document_font_size - 2); $pdf->SetXY($column,$row); $pdf->Cell($labelWidth,$incr,$note,'0',1,'L',false,'',1); } else { // Add menu date if ($print_date == 'Y') { $pdf->SetFont($document_font,"",$document_font_size - 3); $pdf->SetXY($column,$row); $pdf->Cell($labelWidth,$incr,$menu_date,'0',1,'L',false,'',1); } } $row += $incr; $labelNumber++; } } $filename = "item_labels.$mdate.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"); ?>