362 lines
12 KiB
PHP
362 lines
12 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
// Session is already started in index.php, so don't start it again
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_name($sessionName);
|
|
session_start();
|
|
}
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
header("Location: /?action=order-details&schedule_num=$schedule_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');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
header("Location: /?action=order-details&schedule_num=$schedule_num&error_code=NOACCESS");
|
|
exit();
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Get and validate the parameters
|
|
//
|
|
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
|
|
|
|
$document_format = 'list';
|
|
$report_sort = 'byStudent';
|
|
$orderStatus = 'Active';
|
|
|
|
|
|
if (!isset($schedule_num)) {
|
|
header("Location: /?action=order-details&schedule_num=$schedule_num&error_code=NOSCHED");
|
|
exit();
|
|
}
|
|
|
|
|
|
|
|
// 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=order-details&schedule_num=$schedule_num&error_code=INVALIDSCHED");
|
|
exit();
|
|
}
|
|
|
|
$hotlunch_schedule = db_fetch_array($results);
|
|
$schedule_name = $hotlunch_schedule['schedule_name'];
|
|
|
|
|
|
// 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 = intval($_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=order-details&schedule_num=$schedule_num&error_code=NOACCESS");
|
|
exit();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$school_name = $school_record['school_name'];
|
|
|
|
|
|
|
|
//
|
|
// Orders to print
|
|
//
|
|
$order_by = "last_name,first_name";
|
|
$groupByClass = false;
|
|
|
|
|
|
// Setup order status where clause
|
|
$oswhere = "and hloh.status not in ('Inactive','Deleted') ";
|
|
if ($orderStatus == 'Any') $oswhere = "and hloh.status != 'Deleted' ";
|
|
|
|
|
|
// Get all orders for this schedule with notes
|
|
$query = "select distinct p.people_type,hloh.ordered_by_num,p.first_name,p.last_name,p.class_num,p.user_num,hloh.status,hloh.order_notes,hloh.order_notes2 " .
|
|
"from hotlunch_order_header as hloh, people as p " .
|
|
"where hloh.school_num = $school_num " .
|
|
"and hloh.schedule_num = $schedule_num " .
|
|
$oswhere .
|
|
"and hloh.ordered_by_num = p.record_num " .
|
|
"and p.school_num = $base_school_num " .
|
|
"and p.status != 'Inactive' " .
|
|
"and (length(order_notes) > 0 OR length(order_notes2) > 0) " .
|
|
"order by $order_by";
|
|
$orders = db_query($query);
|
|
|
|
|
|
// Initialize the PDF document
|
|
$document_font = "Helvetica";
|
|
$document_font_weight = "";
|
|
$document_text_color = "#000000";
|
|
$document_font_size = 9;
|
|
$incr = 2.8;
|
|
|
|
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
|
|
// Set parameters for this document
|
|
$start_row = 8;
|
|
$title_width = 190;
|
|
$status_width = $title_width - 30;
|
|
$item_width = $title_width - 100;
|
|
$max_rows = 230;
|
|
$curr_row = $start_row;
|
|
|
|
$left_col = 12;
|
|
$qty_col = 20;
|
|
$item_col = 25;
|
|
$items_col = 25;
|
|
$notes_col = $left_col;
|
|
|
|
$max_line_length = 5;
|
|
$notes_width = $title_width;
|
|
|
|
$logo_url = $school_record['logo_url'];
|
|
$logo_image = "images/" . $school_record['logo_image'];
|
|
$logo_row = 250;
|
|
$document_name = getLanguageText('TEXT-ORDER-NOTES');
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle, $document_format, $groupByClass, $class_info;
|
|
|
|
if ($document_format != 'report' && $document_format != 'list') return;
|
|
|
|
// Print the header
|
|
$this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
$this->SetFont($document_font,"B",$document_font_size + 1);
|
|
$this->SetXY($left_col,$start_row);
|
|
$this->Cell($title_width,$incr + 1," $report_title",'0',1,'L',true,'',1);
|
|
|
|
if (isset($report_subtitle) && strlen($report_subtitle) > 0) {
|
|
$offset = 100;
|
|
$this->SetXY($left_col + $offset,$start_row);
|
|
$this->Cell($title_width - $offset,$incr + 1,"$report_subtitle ",'0',1,'R',true,'',1);
|
|
}
|
|
}
|
|
|
|
function Footer() {
|
|
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row, $document_format, $school_name;
|
|
|
|
if ($document_format == 'receipt') return;
|
|
|
|
// 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);
|
|
|
|
// 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->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$pdf->SetTextColor($font_red,$font_green,$font_blue);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
|
|
$fill = true;
|
|
if ($document_format == 'report') $fill = false;
|
|
|
|
|
|
$prev_class_num = -1;
|
|
$new_page = true;
|
|
$curr_row = $max_rows + 10;
|
|
|
|
$report_title = $school_name . " - " . $schedule_name;
|
|
$report_subtitle = $document_name . ": " . db_num_rows($orders);
|
|
|
|
// Process each record
|
|
$page = 0;
|
|
$count = 0;
|
|
while ($entry = db_fetch_array($orders)) {
|
|
extract($entry);
|
|
|
|
// Start new page if required
|
|
if (isset($selected_items) && is_array($selected_items) && $curr_row > ($max_rows - count($selected_items) * $incr)) {
|
|
$pdf->addPage();
|
|
$curr_row = $start_row + 10;
|
|
$new_page = true;
|
|
}
|
|
|
|
// Display ordered by name
|
|
$pdf->SetFont($document_font,$font_parm,$document_font_size);
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$fill = true;
|
|
if (count($selected_items) == 1) {
|
|
$fill = true;
|
|
$count++;
|
|
}
|
|
|
|
// Get parent contact info if required
|
|
$info = getContactInfo($user_num);
|
|
$user_record = $info[3];
|
|
|
|
$name = trim($first_name . ' ' . $last_name);
|
|
if ($people_type == 'Staff') $name .= " (Staff)";
|
|
if ($orderStatus == 'Any') $name .= " - " . $status;
|
|
|
|
$linked_to_student = db_getVal("SELECT linked_to_student FROM users WHERE school_num = $base_school_num AND record_num = $user_num");
|
|
if (strlen($linked_to_student)) $name .= " ($linked_to_student)";
|
|
|
|
|
|
// Include quantity if required
|
|
if (count($selected_items) == 1) {
|
|
$qty = db_getVal("SELECT qty FROM hotlunch_order_items WHERE school_num = $school_num AND ordered_by_num = $ordered_by_num AND schedule_num = $schedule_num AND menu_item_num = $items");
|
|
if ($qty > 1) $name .= " (x$qty)";
|
|
}
|
|
|
|
// Print name
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr,$name,'0',1,'L',$fill);
|
|
|
|
// Print additional info if required
|
|
$additional_info = "";
|
|
$results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num");
|
|
$ainfo = db_fetch_array($results);
|
|
|
|
// Include class info if only one item has been selected
|
|
if (count($selected_items) == 1 || $groupByClass == false) {
|
|
$additional_info .= getClassInfo($class_num);
|
|
}
|
|
|
|
// Student number
|
|
if ($school_record['collect_student_number'] == 'Y' && strlen($ainfo['student_number']) > 0) {
|
|
if (strlen($additional_info) > 0) $additional_info .= " / ";
|
|
$additional_info .= getLanguageText('TEXT-STUDENT-NUMBER') . ": " . $ainfo['student_number'];
|
|
}
|
|
|
|
// Student birthdate
|
|
if ($school_record['collect_student_birthdate'] == 'Y' && strlen($ainfo['birthdate']) > 0) {
|
|
if (strlen($additional_info) > 0) $additional_info .= " / ";
|
|
$additional_info .= getLanguageText('TEXT-BIRTH-DATE') . ": " . date($school_record['date_format'],strtotime($ainfo['birthdate']));
|
|
}
|
|
|
|
// Student sex
|
|
if ($school_record['collect_student_sex'] == 'Y' && strlen($ainfo['sex']) > 0) {
|
|
if (strlen($additional_info) > 0) $additional_info .= " / ";
|
|
$additional_info .= $ainfo['sex'];
|
|
}
|
|
|
|
// Student age
|
|
if ($school_record['collect_student_age'] == 'Y' && strlen($ainfo['age']) > 0) {
|
|
if (strlen($additional_info) > 0) $additional_info .= " / ";
|
|
$additional_info .= getLanguageText('TEXT-AGE') . ": " . $ainfo['age'];
|
|
}
|
|
|
|
// Student grade
|
|
if ($school_record['collect_student_grade'] == 'Y' && strlen($ainfo['school_grade']) > 0) {
|
|
if (strlen($additional_info) > 0) $additional_info .= " / ";
|
|
$additional_info .= getLanguageText('TEXT-GRADE') . ": " . $ainfo['school_grade'];
|
|
}
|
|
|
|
// Student permission
|
|
if (($school_record['collect_permission'] == 'Y' || $school_record['collect_permission'] == 'W') && strlen($ainfo['additional_permission']) > 0) {
|
|
if (strlen($additional_info) > 0) $additional_info .= " / ";
|
|
$additional_info .= $school_record['permission_prompt'] . ": " . $ainfo['additional_permission'];
|
|
if (strlen($ainfo['additional_permission_note'])) $additional_info .= " - " . $ainfo['additional_permission_note'];
|
|
}
|
|
|
|
// User Defined Data
|
|
if ($school_record['user_defined_values'] == 'Y' && strlen($school_record['user_defined_title']) > 0 && strlen($ainfo['user_defined_value'])) {
|
|
if (strlen($additional_info) > 0) $additional_info .= " / ";
|
|
$additional_info .= $school_record['user_defined_title'] . ": " . $ainfo['user_defined_value'];
|
|
}
|
|
|
|
if (strlen($additional_info)) {
|
|
$width = 50;
|
|
$info_col = $left_col + $title_width - $width;
|
|
// $curr_row += $incr;
|
|
$pdf->SetXY($info_col,$curr_row);
|
|
$pdf->SetFont($document_font,"",$document_font_size - 2);
|
|
$pdf->Cell($width,$incr,$additional_info,'0',1,'R',false,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
}
|
|
|
|
$curr_row += $incr + 1.5;
|
|
|
|
if (strlen($order_notes)) {
|
|
$pdf->SetXY($notes_col,$curr_row);
|
|
$pdf->SetFont($document_font,"",$document_font_size - 2);
|
|
$pdf->MultiCell($notes_width,$incr,$order_notes,'1','L',false);
|
|
$curr_row = $pdf->GetY();
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
if (strlen($order_notes2)) {
|
|
$pdf->SetXY($notes_col,$curr_row);
|
|
$pdf->SetFont($document_font,"",$document_font_size - 2);
|
|
$pdf->MultiCell($notes_width,$incr,$order_notes2,'1','L',false);
|
|
$curr_row = $pdf->GetY();
|
|
}
|
|
|
|
$curr_row += $incr - .5;
|
|
}
|
|
|
|
$filename = "order-notes.pdf";
|
|
if ($siteType == 'registration') $filename = "registration-notes.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");
|
|
|
|
?>
|