801 lines
26 KiB
PHP
801 lines
26 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
// Session already started in index.php - don't start again
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_name($sessionName);
|
|
session_start();
|
|
}
|
|
|
|
$school_name = $school_record['school_name'];
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOACCESS");
|
|
exit();
|
|
}
|
|
|
|
|
|
// Check permissions
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier','Financial Team','Schedule Reporting');
|
|
if (!in_array($_SESSION['UserInfo']['type'],$AllowedUserTypes)) {
|
|
header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOACCESS");
|
|
exit();
|
|
}
|
|
|
|
|
|
$moduleName = "hotlunch.meal.labels.generate.php";
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog($moduleName);
|
|
|
|
|
|
if (array_key_exists('reseller_school',$_GET)) $reseller_school = intval($_GET['reseller_school']);
|
|
if (array_key_exists('reseller_menu_num',$_GET)) $reseller_menu_num = intval($_GET['reseller_menu_num']);
|
|
|
|
if (isset($reseller_school) && isset($reseller_menu_num)) {
|
|
$school_num = $reseller_school;
|
|
$base_school_num = $reseller_school;
|
|
$menu_num = $reseller_menu_num;
|
|
|
|
$query = "SELECT * FROM schools WHERE record_num = $school_num";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
$school_record = db_fetch_assoc($results);
|
|
|
|
$schedule_num = db_getVal("SELECT schedule_num FROM hotlunch_menu_dates WHERE school_num = $reseller_school AND record_num = $menu_num");
|
|
|
|
writeLog("school_num: $school_num");
|
|
writeLog("menu_num: $menu_num");
|
|
writeLog("schedule_num: $schedule_num");
|
|
writeLog("school: ".$school_record['school_name']);
|
|
writeLog("logo: ".$school_record['logo_image']);
|
|
|
|
$schedule_num = db_getVal("SELECT schedule_num FROM hotlunch_menu_dates WHERE school_num = $reseller_school AND record_num = $reseller_menu_num");
|
|
|
|
$query = "SELECT * FROM form_defaults WHERE school_num = $school_num AND action = 'meal-labels'";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
while ($row = db_fetch_array($results)) {
|
|
$fname = $row['field'];
|
|
$$fname = $row['default_value'];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
// Get and validate the parameters
|
|
//
|
|
$display_class_info = 'N';
|
|
$display_school_name = $school_record['label_print_school_name'];
|
|
|
|
if (array_key_exists('schedule_num',$_POST)) $schedule_num = intval($_POST['schedule_num']);
|
|
if (array_key_exists('menu_num',$_POST)) $menu_num = intval($_POST['menu_num']);
|
|
if (array_key_exists('sort_by',$_POST)) $sort_by = $_POST['sort_by'];
|
|
if (array_key_exists('display_school_name',$_POST) && $_POST['display_school_name'] == 'Y') $display_school_name = $_POST['display_school_name'];
|
|
if (array_key_exists('display_class_info',$_POST) && $_POST['display_class_info'] == 'Y') $display_class_info = $_POST['display_class_info'];
|
|
if (isset($_POST['labelFormat'])) $labelFormat = $_POST['labelFormat'];
|
|
if (array_key_exists('print_student_info',$_POST)) $print_student_info = $_POST['print_student_info'];
|
|
if (array_key_exists('choose_items',$_POST)) $choose_items = $_POST['choose_items'];
|
|
if (array_key_exists('print_date',$_POST)) $print_date = $_POST['print_date'];
|
|
if (array_key_exists('print_meal',$_POST)) $print_meal = $_POST['print_meal'];
|
|
if (array_key_exists('font_size',$_POST)) $font_size = $_POST['font_size'];
|
|
if (array_key_exists('suppliers',$_POST)) $suppliers = $_POST['suppliers'];
|
|
|
|
if (!isset($schedule_num)) {
|
|
header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOSCHED");
|
|
exit();
|
|
}
|
|
|
|
if (!isset($menu_num)) {
|
|
header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOMENU");
|
|
exit();
|
|
}
|
|
|
|
if (!isset($choose_items)) $choose_items = 'All';
|
|
if (!isset($display_class_info)) $display_class_info = 'Y';
|
|
if (!isset($selected_include)) $selected_include = 'All';
|
|
if (!isset($print_date)) $print_date = 'N';
|
|
if (!isset($print_meal)) $print_meal = 'Y';
|
|
if (!isset($sort_by)) $sort_by = 'class_num';
|
|
if (!isset($labelFormat)) $labelFormat = 'mailinglabels';
|
|
if (!isset($font_size)) $font_size = '9';
|
|
|
|
|
|
|
|
// Check if this is a valid schedule
|
|
$query = "select * from hotlunch_schedules " .
|
|
"where school_num = $school_num " .
|
|
"and record_num = $schedule_num";
|
|
$results = db_query($query);
|
|
|
|
if (db_num_rows($results) == 0) {
|
|
header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=INVALIDSCHED");
|
|
exit();
|
|
}
|
|
|
|
$hotlunch_schedule = db_fetch_array($results);
|
|
|
|
|
|
// If this is a ScheduleTeam user check if they have permission to access this schedule
|
|
if (in_array($_SESSION['UserInfo']['type'],array('Schedule Team','Schedule Volunteer'))) {
|
|
$userNum = $_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) {
|
|
header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOACCESS");
|
|
exit();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=INVALIDMENU");
|
|
exit();
|
|
}
|
|
|
|
$hotlunch_menu_date = db_fetch_array($results);
|
|
$menu_date = date($school_record['date_format'],strtotime($hotlunch_menu_date['menu_date']));
|
|
$mdate = date("Y-m-d",strtotime($hotlunch_menu_date['menu_date']));
|
|
|
|
$iwhere = "";
|
|
if (isset($choose_items) && $choose_items != 'All') {
|
|
$iwhere = "AND sp.hot_cold_food = '$choose_items' ";
|
|
$iwhere2 = "AND hot_cold_food = '$choose_items' ";
|
|
}
|
|
|
|
|
|
// Process only selected suppliers
|
|
// if (!is_array($suppliers) || count($suppliers) == 0) {
|
|
// header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOSUPPLIER");
|
|
// exit();
|
|
// }
|
|
|
|
$swhere = "";
|
|
if (isset($suppliers) && count($suppliers)) $swhere = "AND supplier_num IN (".implode(",",$suppliers).") ";
|
|
|
|
|
|
// Determine which items have been selected
|
|
writeLog("swhere: $swhere");
|
|
writeLog("iwhere: $iwhere");
|
|
$selected_items = array();
|
|
if (strlen($swhere)) {
|
|
$query = "SELECT hlmi.* " .
|
|
"FROM suppliers as s, supplier_products as sp, hotlunch_menu_products as hlmp, hotlunch_menu_items as hlmi " .
|
|
"WHERE s.school_num = $supplier_school_num " .
|
|
"AND s.school_num = sp.school_num " .
|
|
"AND hlmp.school_num = $school_num " .
|
|
"AND hlmi.school_num = $school_num " .
|
|
"AND s.status = 'Active' " .
|
|
"AND s.record_num = sp.supplier_num " .
|
|
"AND sp.record_num = hlmp.supplier_product_num " .
|
|
"AND hlmp.menu_item_num = hlmi.record_num " .
|
|
"AND hlmi.menu_num = $menu_num " .
|
|
"AND item_type != 'Heading' " .
|
|
$swhere .
|
|
$iwhere .
|
|
"ORDER BY hlmi.sequence";
|
|
}
|
|
else {
|
|
if (!isset($iwhere2)) $iwhere2 = "";
|
|
$query = "SELECT hlmi.* " .
|
|
"FROM hotlunch_menu_items as hlmi " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND menu_num = $menu_num " .
|
|
"AND item_type != 'Heading' " .
|
|
$iwhere2 .
|
|
"ORDER BY sequence";
|
|
}
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
$num_items = db_num_rows($results);
|
|
writeLog("Items: $num_items");
|
|
|
|
while ($row = db_fetch_array($results)) {
|
|
$record_num = $row['record_num'];
|
|
writeLog("item record_num: $record_num");
|
|
// if (!isset($reseller_school)) $selected_items[] = $record_num;
|
|
$selected_items[] = $record_num;
|
|
}
|
|
|
|
writeLog("Num selected_items: ".count($selected_items));
|
|
if (count($selected_items) == 0) {
|
|
header("Location: /?action=meal-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOITEMS");
|
|
exit();
|
|
}
|
|
|
|
$classNumField = "class_num";
|
|
if ($school_record['implement_meal_locations'] == 'Y') {
|
|
$classNumField = "meal_location";
|
|
$query = "UPDATE people SET meal_location = class_num WHERE school_num = $school_num AND meal_location IS NULL";
|
|
db_query($query);
|
|
}
|
|
$class_breaks = 'N';
|
|
|
|
|
|
// Set order by for label sorting
|
|
writeLog("SORT BY: $sort_by");
|
|
$div_breaks = 'N';
|
|
switch ($sort_by) {
|
|
case 'item_class_num':
|
|
case 'item_division':
|
|
$order_by = "item_sequence,options_ordered,class_sequence,last_name,first_name";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'item_class_num_breaks':
|
|
case 'item_division_breaks':
|
|
$order_by = "item_sequence,options_ordered,class_sequence,last_name,first_name";
|
|
$div_breaks = 'Y';
|
|
break;
|
|
|
|
case 'class_num':
|
|
$order_by = "class_sequence,last_name,first_name";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'class_num_breaks':
|
|
$order_by = "class_sequence,last_name,first_name";
|
|
$class_breaks = 'Y';
|
|
break;
|
|
|
|
case 'class_num_item':
|
|
case 'division_item':
|
|
$order_by = "class_sequence,item_sequence,options_ordered,last_name,first_name";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'item_student_name':
|
|
case 'item_student':
|
|
$order_by = "item_sequence,options_ordered,last_name,first_name";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'student_name':
|
|
$order_by = "last_name,first_name,item_sequence,options_ordered";
|
|
$div_breaks = 'N';
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
// Handle selected people types
|
|
$people_where = "";
|
|
switch ($selected_include) {
|
|
case 'All':
|
|
$people_where = "";
|
|
if (is_array($selected_classes) && count($selected_classes) > 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");
|
|
|
|
?>
|