0) { $selected_classes[] = 0; $selected_classes[] = 1; } break; case 'Students': $people_where = "and p.people_type = 'Student' "; break; case 'Students_Teachers': $people_where = "and p.people_type in ('Student','Staff') "; break; case 'Staff': $people_where = "and p.people_type = 'Staff' "; unset($selected_classes); break; } // Handle selected classes $class_where = ""; if ($selected_classes && is_array($selected_classes) && count($selected_classes) > 0) { $class_where = "and p.$classNumField in (" . implode(',',$selected_classes) . ") "; } // // Get set of labels to print // $items = implode(',',$selected_items); writeLog("Items: $items"); $query = "SELECT hloh.* FROM hotlunch_order_header AS hloh, hotlunch_order_items AS hloi " . "WHERE hloh.school_num = $school_num " . "AND hloh.status NOT IN ('Inactive','Deleted') " . "AND hloh.ordered_by_type != 'Concession' " . "AND hloh.schedule_num = $schedule_num " . "AND hloi.order_num = hloh.record_num " . "AND hloi.school_num = $school_num " . "AND hloi.schedule_num = $schedule_num " . "AND hloi.menu_item_num in ($items)"; writeLog($query); $results = db_query($query); $num = db_num_rows($results); writeLog("Orders: $num"); if ($num == 0) { header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOORDERS"); exit(); } $Orders = array(); while ($row = db_fetch_assoc($results)) { $Orders[] = $row['record_num']; } $owhere = "AND hloi.order_num IN (".implode(',',$Orders).") "; writeLog($owhere); $query = "select p.first_name,p.last_name,p.label_note,p.$classNumField AS class_num,division,c.sequence as class_sequence,hlmi.sequence as item_sequence," . "hloi.options_ordered,hloi.options2_ordered,hloi.options3_ordered,p.people_type,p.record_num as person " . "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 left join people as p1 on c.teacher1 = p1.record_num " . "where hloi.school_num = $school_num " . "and hloh.school_num = $school_num " . "and hloh.status not in ('Inactive','Deleted') " . "and hloi.order_num = hloh.record_num " . "and hloi.ordered_by_num = p.record_num " . "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' " . $class_where . $people_where . "order by $order_by"; $query = "select p.first_name,p.last_name,p.label_note,p.$classNumField AS class_num,division,c.sequence as class_sequence,hlmi.sequence as item_sequence," . "hloi.options_ordered,hloi.options2_ordered,hloi.options3_ordered,p.people_type,p.record_num as person " . "from hotlunch_order_items as hloi, hotlunch_menu_items as hlmi, " . "people as p left join classes as c on p.$classNumField = c.record_num left join people as p1 on c.teacher1 = p1.record_num " . "where hloi.school_num = $school_num " . $owhere . "and hloi.ordered_by_num = p.record_num " . "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' " . $class_where . $people_where . "order by $order_by"; writeLog($query); $labels = db_query($query); $num = db_num_rows($labels); writeLog("Labels: $num"); // // Setup the label parameters // switch ($labelFormat) { default: case 'mailinglabels': $startColumn = 6; $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)) $fontSize = $font_size; $incr = 3.5; $display_class_details = false; break; case 'mailinglabels-large': $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 = 14; if (isset($font_size)) $fontSize = $font_size; $display_class_details = true; break; case 'shippinglabels6': $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 = 14; if (isset($font_size)) $fontSize = $font_size; $display_class_details = true; break; case 'shippinglabels': $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 = 14; if (isset($font_size)) $fontSize = $font_size; $display_class_details = true; break; case '2perpage': $startColumn = 8; $columnWidth = 210; $labelWidth = $columnWidth - 20; $labelColumns = array(); $labelColumns[] = $startColumn; // One label per row - delete second column // $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 = 14; if (isset($font_size)) $fontSize = $font_size; $display_class_details = true; break; } // Set line increment switch ($fontSize) { case '9': $incr = 3.5; break; case '12': $incr = 4.4; break; case '14': $incr = 5.2; break; case '16': $incr = 6.0; 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"); $logo_url = $school_record['logo_url']; $logo_image = "images/" . $school_record['logo_image']; $max_rows = 0; // Initialize variable $logo_row = $max_rows + 5; class PDF extends TCPDF { function Header() { return; } function Footer() { global $incr, $document_font_size, $document_font, $school_name; return; $this->SetFont($document_font,"",$document_font_size - 2); $this->setXY(10,270); $date = dateString('datetime'); $this->Cell(182,$incr - 1,getLanguageText('TEXT-PRINTED') . ": $date",'0',1,'R'); $this->setXY(10,270 + $incr); $this->Cell(182,$incr - 1,"$school_name",'0',1,'R','',1); 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"); $pdf->SetTextColor($font_red,$font_green,$font_blue); $pdf->SetFont($document_font,"",$document_font_size); $pdf->addPage(); $pdf->SetAutoPageBreak(false); $offset = 10; if ($school_record['i_display_division'] == 'N') $offset = 0; $labelColumn = 1; $labelRow = 1; $labelNumber = 1; $prev_div = -1; $prev_class = -1; $processed_people = array(); // Process each record while ($entry = db_fetch_array($labels)) { extract($entry); if (!isset($print_student_info)) $print_student_info = ''; switch ($print_student_info) { case 'F': $name = trim($first_name); break; case 'L': $name = trim($last_name); break; case 'N': $name = ""; break; case 'I': $name = substr($first_name,0,1) . '. ' . trim($last_name); break; case 'FI': $name = trim($first_name).' '.substr($last_name,0,1); break; default: $name = trim($first_name) . ' ' . trim($last_name); break; } if (in_array($person,$processed_people)) continue; $processed_people[] = $person; // Get class information if ($class_num > 0) { $division_num = db_getVal("SELECT division FROM classes WHERE school_num = $base_school_num AND record_num = $class_num"); $grade = db_getVal("SELECT grade FROM classes WHERE school_num = $base_school_num AND record_num = $class_num"); $class_info = getClassInfo($class_num,'label'); if ($class_breaks == 'Y' && $class_num != $prev_class && $prev_class != -1) $labelNumber = $numLabels + 1; $prev_class = $class_num; } else { $division_num = ""; $grade = ""; if ($class_num == 0) $class_info = getLanguageText('TEXT-STAFF'); if ($class_num == 1) $class_info = getLanguageText('TEXT-CUSTOMERS'); } // Handle division breaks if required if ($div_breaks == 'Y' && $division_num != $prev_div && $prev_div != -1) { $lnum = $labelNumber % count($labelColumns); switch ($lnum) { case 0: $labelNumber += 1; break; case 1: $labelColumn = 1; break; case 2: case 3: $labelNumber += count($labelColumns) - $lnum + 1; break; } } $prev_div = $division_num; // if ($class_breaks == 'Y') $labelNumber = $numLabels + 1; // Add a new page if required if ($labelNumber > $numLabels) { $labelNumber = 1; $pdf->addPage(); } // Generate the label for this student $labelColumn = ($labelNumber - 1) % count($labelColumns); $labelRow = intval(($labelNumber + count($labelColumns) - 1) / count($labelColumns)) - 1; $column = $labelColumns[$labelColumn]; $curr_row = $labelRows[$labelRow]; // Use grade if division_num not set if (!isset($division_num) || strlen($division_num) == 0) $division_num = $grade; // Print division number if ($school_record['i_display_division'] == 'Y') { $pdf->SetFont($document_font,"B",$document_font_size + 2); $pdf->SetXY($column,$curr_row); $pdf->Cell($offset,$incr + 1,$division_num,'0',1,'L',false,'',1); $pdf->SetFont($document_font,"",$document_font_size); } // Add school name to label if ($display_school_name == 'Y') { $pdf->SetXY($column + $offset,$curr_row); $pdf->Cell($labelWidth,$incr,$school_name,'0',1,'L',false,'',1); $curr_row += $incr; } // Append class info to name for smaller labels if ($display_school_name == 'Y' && $display_class_info == 'Y' && $display_class_details == false) { if (strlen($name)) $name .= " - "; $name .= $class_info; } // Add student name to label if (strlen($name)) { $pdf->SetFont($document_font,"B",$document_font_size); $pdf->SetXY($column + $offset,$curr_row); $pdf->Cell($labelWidth,$incr,$name,'0',1,'L',false,'',1); $pdf->SetFont($document_font,"",$document_font_size); $curr_row += $incr; } if ($display_school_name != 'Y' && $display_class_info == 'Y' && $display_class_details == false) { // Add class info to a separate line $pdf->SetFont($document_font,"B",$document_font_size - 2); $pdf->SetXY($column + $offset,$curr_row); $pdf->Cell($labelWidth,$incr,$class_info,'0',1,'L',false,'',1); $pdf->SetFont($document_font,"",$document_font_size); $curr_row += $incr - 1; } if (strlen($label_note)) { $curr_row -= .25; $pdf->SetFont($document_font,"",$document_font_size - 3); $pdf->SetXY($column + $offset,$curr_row); $pdf->Cell($labelWidth,$incr - 1,$label_note,'0',1,'L',false,'',1); $curr_row += $incr - .8; $pdf->SetFont($document_font,"",$document_font_size); } // Add class info if required if ($display_class_info == 'Y' && $display_class_details) { $pdf->SetFont($document_font,"B",$document_font_size - 2); $pdf->SetXY($column + $offset,$curr_row); $pdf->Cell($labelWidth,$incr,"- $class_info",'0',1,'L',false,'',1); $pdf->SetFont($document_font,"",$document_font_size); $curr_row += $incr; } if ($print_meal == 'Y') { // Get the items ordered by this person $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.record_num = hloi.menu_item_num " . "AND hloi.school_num = $school_num " . "AND hloi.ordered_by_num = $person " . "AND hloi.active != 'N' " . "AND hlmi.record_num IN ($items) " . "ORDER BY hlmi.sequence"; $items_ordered = db_query($query); $pdf->SetFont($document_font,"",$document_font_size - 2); while ($item = db_fetch_array($items_ordered)) { $label_title = $item['label_title']; if (strlen($label_title) == 0) $label_title = $item['item_title']; if ($item['qty'] > 1) $label_title = $item['qty'] . " x " . $label_title; $options = ""; if (strlen($item['options_ordered']) || strlen($item['options2_ordered']) || strlen(trim($item['options3_ordered']))) { $options = str_replace("\n",", ",trim(trim($item['options_ordered'])."\n".trim($item['options2_ordered']))."\n".trim($item['options3_ordered'])); $options = str_replace(", ",",",trim($options)); if (strlen($options)) $label_title .= " ($options)"; } $pdf->SetXY($column + $offset,$curr_row); $pdf->SetXY($column,$curr_row); $pdf->MultiCell($labelWidth,$incr - 1,$label_title,'0','L',false); $curr_row = $pdf->GetY(); } } if ($print_date == 'Y') { $pdf->SetFont($document_font,"",$document_font_size - 2); $pdf->SetXY($column + $offset,$curr_row); $pdf->Cell($labelWidth,$incr,$menu_date,'0',1,'L',false,'',1); } $pdf->SetFont($document_font,"",$document_font_size); $labelNumber++; } $filename = "order_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"); ?>