883 lines
31 KiB
PHP
883 lines
31 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
// Use the existing session if one is already active (index.php starts it)
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
if (!empty($sessionName)) {
|
|
session_name($sessionName);
|
|
}
|
|
session_start();
|
|
}
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
header("Location: /?action=item-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=item-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOACCESS");
|
|
exit();
|
|
}
|
|
|
|
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog("hotlunch.labels.generate.php");
|
|
|
|
$post = print_r($_POST,true);
|
|
writeLog("_POST: $post");
|
|
|
|
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 = 'item-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
|
|
//
|
|
$print_school_name = '';
|
|
$print_student_info = 'N';
|
|
$display_options = '';
|
|
|
|
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 = db_escape_string($_POST['sort_by']);
|
|
if (array_key_exists('selected_classes',$_POST)) $selected_classes = $_POST['selected_classes'];
|
|
if (array_key_exists('labelFormat',$_POST)) $labelFormat = db_escape_string($_POST['labelFormat']);
|
|
if (array_key_exists('print_student_info',$_POST)) $print_student_info = $_POST['print_student_info'];
|
|
if (array_key_exists('font_size',$_POST)) $font_size = $_POST['font_size'];
|
|
if (array_key_exists('display_options',$_POST)) $display_options = $_POST['display_options'];
|
|
if (array_key_exists('print_school_name',$_POST)) $print_school_name = $_POST['print_school_name'];
|
|
|
|
$print_date = 'Y';
|
|
if (array_key_exists('print_date',$_POST)) $print_date = $_POST['print_date'];
|
|
|
|
|
|
if (!isset($schedule_num)) {
|
|
header("Location: /?action=item-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOSCHED");
|
|
exit();
|
|
}
|
|
|
|
if (!isset($menu_num)) {
|
|
header("Location: /?action=item-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOMENU");
|
|
exit();
|
|
}
|
|
|
|
if (!isset($labelFormat)) $labelFormat = 'mailinglabels';
|
|
if (!isset($font_size)) $font_size = 'default';
|
|
|
|
|
|
// 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=item-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=item-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";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
|
|
if (db_num_rows($results) == 0) {
|
|
header("Location: /?action=item-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=INVALIDMENU");
|
|
exit();
|
|
}
|
|
|
|
$hotlunch_menu_date = db_fetch_array($results);
|
|
$menu_date = date("D M j Y",strtotime($hotlunch_menu_date['menu_date']));
|
|
$mdate = date("Y-m-d",strtotime($hotlunch_menu_date['menu_date']));
|
|
|
|
|
|
// Determine which items have been selected
|
|
$selected_items = array();
|
|
$menuItems = array();
|
|
$query = "select * from hotlunch_menu_items " .
|
|
"where school_num = $school_num " .
|
|
"and menu_num = $menu_num " .
|
|
"and item_type != 'Heading' " .
|
|
"order by sequence";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
|
|
if (isset($reseller_school)) writeLog("RESELLER_SCHOOL: $reseller_school");
|
|
|
|
while ($row = db_fetch_array($results)) {
|
|
$record_num = $row['record_num'];
|
|
$menuItems[$record_num] = $row;
|
|
if (array_key_exists("item_$record_num",$_POST) && $_POST["item_$record_num"] == 'Y') {
|
|
if ($_POST["item_$record_num"] == 'Y') {
|
|
$selected_items[] = $record_num;
|
|
}
|
|
}
|
|
else {
|
|
if (isset($reseller_school)) {
|
|
$selected_items[] = $record_num;
|
|
}
|
|
}
|
|
}
|
|
|
|
writeLog("selected_items: ".count($selected_items));
|
|
|
|
if (count($selected_items) == 0) {
|
|
header("Location: /?action=item-labels&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOITEMS");
|
|
exit();
|
|
}
|
|
|
|
if (!isset($sort_by) || $sort_by == '') $sort_by = 'item_class';
|
|
|
|
|
|
// Save form defaults
|
|
$formFields = array('print_student_info',
|
|
'print_school_name',
|
|
'display_options',
|
|
'print_school_name',
|
|
'print_date',
|
|
'sort_by',
|
|
'labelFormat',
|
|
'font_size'
|
|
);
|
|
for ($i = 0; $i < count($formFields); $i++) {
|
|
$fname = $formFields[$i];
|
|
if (array_key_exists($fname, $_POST)) {
|
|
$value = $_POST[$fname];
|
|
if (is_array($value)) $value = implode(',',$value);
|
|
db_query("INSERT INTO form_defaults VALUES ($school_num,'item-labels','$fname','$value') ON DUPLICATE KEY UPDATE default_value = '$value'");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Set order by for label sorting
|
|
switch ($sort_by) {
|
|
case 'item_class':
|
|
$order_by = "label_title,item_title,class_sequence,lastname,firstname";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'item_options_class':
|
|
$order_by = "label_title,item_title,options_ordered,options2_ordered,class_sequence,lastname,firstname";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'item_class_breaks':
|
|
$order_by = "label_title,item_title,class_sequence,lastname,firstname";
|
|
$div_breaks = 'Y';
|
|
break;
|
|
|
|
case 'item_options_class_breaks':
|
|
$order_by = "label_title,item_title,options_ordered,options2_ordered,class_sequence,lastname,firstname";
|
|
$div_breaks = 'Y';
|
|
break;
|
|
|
|
case 'class_item':
|
|
$order_by = "class_sequence,label_title,item_title,options_ordered,lastname,firstname";
|
|
if ($school_record['staff_meals_to_classroom'] == 'N') $order_by = "people_type desc,$order_by";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'class_item_breaks':
|
|
$order_by = "class_sequence,label_title,item_title,options_ordered,lastname,firstname";
|
|
if ($school_record['staff_meals_to_classroom'] == 'N') $order_by = "people_type desc,$order_by";
|
|
$div_breaks = 'Y';
|
|
break;
|
|
|
|
case 'class_student':
|
|
$order_by = "class_sequence,lastname,firstname,label_title,item_title,options_ordered";
|
|
if ($school_record['staff_meals_to_classroom'] == 'N') $order_by = "people_type desc,$order_by";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'class_student_breaks':
|
|
$order_by = "class_sequence,lastname,firstname,label_title,item_title,options_ordered";
|
|
if ($school_record['staff_meals_to_classroom'] == 'N') $order_by = "people_type desc,$order_by";
|
|
$div_breaks = 'Y';
|
|
break;
|
|
|
|
case 'item_student':
|
|
$order_by = "label_title,item_title,lastname,firstname";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'item_options_student':
|
|
$order_by = "label_title,item_title,options_ordered,options2_ordered,lastname,firstname";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'student_item':
|
|
$order_by = "lastname,firstname,label_title,item_title,options_ordered";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'division_item':
|
|
$order_by = "cast(division AS unsigned),label_title,item_title,options_ordered,lastname,firstname";
|
|
if ($school_record['staff_meals_to_classroom'] == 'N') $order_by = "people_type desc,$order_by";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
case 'division_student':
|
|
$order_by = "cast(division AS unsigned),lastname,firstname,label_title,item_title,options_ordered";
|
|
if ($school_record['staff_meals_to_classroom'] == 'N') $order_by = "people_type desc,$order_by";
|
|
$div_breaks = 'N';
|
|
break;
|
|
|
|
}
|
|
|
|
writeLog("div_breaks: $div_breaks");
|
|
|
|
//
|
|
// Get set of labels to print
|
|
//
|
|
$items = implode(',',$selected_items);
|
|
|
|
$classNumField = "class_num";
|
|
if ($school_record['implement_meal_locations'] == 'Y') {
|
|
$query = "UPDATE people SET meal_location = class_num WHERE school_num = $school_num AND meal_location IS NULL";
|
|
writeLog($query);
|
|
db_query($query);
|
|
$classNumField = "meal_location";
|
|
}
|
|
else {
|
|
// Set deliver locations if required
|
|
if ($school_record['staff_meals_to_classroom'] == 'N') {
|
|
$query = "UPDATE people SET delivery_class_num = class_num WHERE school_num = $school_num";
|
|
db_query($query);
|
|
|
|
$query = "UPDATE people SET delivery_class_num = 0 WHERE school_num = $school_num AND people_type = 'Staff'";
|
|
db_query($query);
|
|
$classNumField = "delivery_class_num";
|
|
}
|
|
}
|
|
|
|
|
|
// Handle selected classes
|
|
$selectedClasses = "";
|
|
$cquery = "";
|
|
if (isset($selected_classes) && count($selected_classes) > 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("<br>\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");
|
|
|
|
?>
|