300 lines
9.4 KiB
PHP
300 lines
9.4 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
// Guarded session handling to avoid warnings and align with other modules
|
|
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=order-details&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');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
header("Location: /?action=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOACCESS");
|
|
exit();
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Get and validate the parameters
|
|
//
|
|
unset($schedule_num);
|
|
unset($menu_num);
|
|
unset($selected_groups);
|
|
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('selected_groups',$_POST)) $selected_groups = $_POST['selected_groups'];
|
|
|
|
if (!isset($schedule_num)) {
|
|
header("Location: /?action=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOSCHED");
|
|
exit();
|
|
}
|
|
|
|
if (!isset($menu_num)) {
|
|
header("Location: /?action=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOMENU");
|
|
exit();
|
|
}
|
|
|
|
if (!isset($selected_groups)) {
|
|
header("Location: /?action=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOGROUPS");
|
|
exit();
|
|
}
|
|
|
|
$groups = implode(', ',$selected_groups);
|
|
|
|
|
|
// 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&menu_num=$menu_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 = $_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&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=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=INVALIDMENU");
|
|
exit();
|
|
}
|
|
|
|
$hotlunch_menu_date = db_fetch_array($results);
|
|
$menu_title = $hotlunch_menu_date['menu_title'];
|
|
$menu_date = date("D M j Y",strtotime($hotlunch_menu_date['menu_date']));
|
|
|
|
|
|
$school_name = $school_record['school_name'];
|
|
|
|
|
|
|
|
//
|
|
// Get set of people to process
|
|
//
|
|
$people = db_query("SELECT * FROM people WHERE school_num = $base_school_num ORDER BY last_name,first_name");
|
|
|
|
|
|
|
|
// Initialize the PDF document
|
|
$document_font = "Arial";
|
|
$document_font_weight = "";
|
|
$document_text_color = "#000000";
|
|
$document_font_size = 9;
|
|
$incr = 8;
|
|
|
|
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
define('FPDF_FONTPATH',"font/");
|
|
require("include/fpdi.php");
|
|
|
|
$pdf= new fpdi('P','pt','Letter');
|
|
|
|
$pdf->addPage();
|
|
$pdf->SetAutoPageBreak(true,10);
|
|
|
|
$font_parm = $document_font_weight;
|
|
$font_red = hexdec(substr(str_replace("#","",$document_text_color),0,2));
|
|
$font_green = hexdec(substr(str_replace("#","",$document_text_color),2,2));
|
|
$font_blue = hexdec(substr(str_replace("#","",$document_text_color),4,2));
|
|
|
|
$pdf->SetTextColor($font_red,$font_green,$font_blue);
|
|
|
|
// Set parameters for this document
|
|
$start_row = 15;
|
|
$max_rows = 750;
|
|
$curr_row = $start_row;
|
|
$new_page = true;
|
|
|
|
$left_col = 15;
|
|
$title_col = 200;
|
|
$group_col = 50;
|
|
$qty_col = 75;
|
|
$item_col = 100;
|
|
|
|
$max_line_length = 5;
|
|
|
|
|
|
$pdf->SetFont("Arial",$font_parm,$document_font_size);
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
|
|
|
|
$prev_class_num = -1;
|
|
|
|
// Process each record
|
|
$page = 0;
|
|
$pCount = 0;
|
|
while ($person = db_fetch_array($people)) {
|
|
extract($person);
|
|
$person_num = $record_num;
|
|
|
|
if ($curr_row >= $max_rows - $incr * 5) {
|
|
// Add date to page
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
$pdf->SetXY(200,$max_rows + 5);
|
|
$date = date("F j, Y",time());
|
|
$pdf->Cell(350,$incr - 1,getLanguageText('TEXT-MENU-GROUPS-REPORT').": $date",'0',1,'R');
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$pdf->addPage();
|
|
$curr_row = $start_row;
|
|
$new_page = true;
|
|
}
|
|
|
|
// Display titles in report format on each page
|
|
if ($new_page) {
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$pdf->SetFont("Arial",'B',$document_font_size + 1);
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(580,$incr + 2,$school_name,'0',1,'L',true);
|
|
|
|
$pdf->SetFont("Arial",'B',$document_font_size);
|
|
$pdf->SetXY($title_col + 100,$curr_row);
|
|
$pdf->Cell(280,$incr + 2,"$menu_date - $menu_title",'0',1,'R',true);
|
|
|
|
$curr_row += $incr + 2;
|
|
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(580,$incr + 2,getLanguageText('TEXT-MENU-GROUPS-REPORT')." - $groups",'0',1,'L',true);
|
|
|
|
$new_page = false;
|
|
$curr_row += $incr + 10;
|
|
}
|
|
|
|
// Determine if this person has an Active or Unpaid order for this schedule
|
|
$oCount = db_getVal("SELECT count(*) FROM hotlunch_order_header WHERE school_num = $school_num AND ordered_by_num = $person_num AND schedule_num = $schedule_num AND status NOT IN ('Inactive','Deleted')");
|
|
if ($oCount == 0) continue;
|
|
|
|
// Determine if this person has ordered items in selected group(s)
|
|
$gCount = 0;
|
|
for ($i = 0; $i < count($selected_groups); $i++) {
|
|
$gCode = db_escape_string($selected_groups[$i]);
|
|
$query = "SELECT count(*) FROM hotlunch_menu_items AS hlmi, hotlunch_order_items AS hloi " .
|
|
"WHERE hlmi.school_num = $school_num " .
|
|
"AND hlmi.menu_num = $menu_num " .
|
|
"AND hlmi.menu_group = '$gCode' " .
|
|
"AND hloi.school_num = $school_num " .
|
|
"AND hloi.schedule_num = $schedule_num " .
|
|
"AND hloi.menu_num = $menu_num " .
|
|
"AND hloi.menu_item_num = hlmi.record_num " .
|
|
"AND hloi.active != 'N' " .
|
|
"AND hloi.ordered_by_num = $person_num";
|
|
$itemCount = db_getVal($query);
|
|
if ($itemCount > 0) $gCount++;
|
|
}
|
|
|
|
if ($gCount < count($selected_groups)) continue;
|
|
$pCount++;
|
|
|
|
// Display name
|
|
$pdf->SetFont("Arial",$font_parm,$document_font_size);
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
|
|
$name = trim($first_name . ' ' . $last_name);
|
|
if (isset($ordered_by_type) && $ordered_by_type == 'Staff') $name .= " (Staff)";
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(580,$incr,$name,'0',1,'L',true);
|
|
$curr_row += $incr;
|
|
|
|
// List items ordered
|
|
for ($i = 0; $i < count($selected_groups); $i++) {
|
|
$gCode = db_escape_string($selected_groups[$i]);
|
|
$query = "SELECT * FROM hotlunch_menu_items AS hlmi, hotlunch_order_items AS hloi " .
|
|
"WHERE hlmi.school_num = $school_num " .
|
|
"AND hlmi.menu_num = $menu_num " .
|
|
"AND hlmi.menu_group = '$gCode' " .
|
|
"AND hloi.school_num = $school_num " .
|
|
"AND hloi.schedule_num = $schedule_num " .
|
|
"AND hloi.menu_num = $menu_num " .
|
|
"AND hloi.menu_item_num = hlmi.record_num " .
|
|
"AND hloi.active != 'N' " .
|
|
"AND hloi.ordered_by_num = $person_num";
|
|
$results = db_query($query);
|
|
|
|
// Print the quantity and item on the report
|
|
if (db_num_rows($results) > 0) {
|
|
while ($row = db_fetch_array($results)) {
|
|
$pdf->SetXY($group_col,$curr_row);
|
|
$pdf->Cell(20,$incr,$gCode,'0',1,'L',false);
|
|
|
|
$pdf->SetXY($qty_col,$curr_row);
|
|
$pdf->Cell(20,$incr,$row['qty'],'0',1,'L',false);
|
|
|
|
$pdf->SetXY($item_col,$curr_row);
|
|
$pdf->Cell(450,$incr,$row['item_title'],'0',1,'L',false);
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
}
|
|
}
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
|
|
// Print total number of people
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($qty_col,$curr_row);
|
|
$pdf->Cell(450,$incr,getLanguageText('TEXT-ORDERS').": $pCount",'0',1,'L',false);
|
|
|
|
// Add date to page
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
$pdf->SetXY(200,$max_rows + 5);
|
|
$date = date("F j, Y",time());
|
|
$pdf->Cell(350,$incr - 1,getLanguageText('TEXT-MENU-GROUPS-REPORT').": $date",'0',1,'R');
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
|
|
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=menu-groups.pdf");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output("menu-groups.pdf","D");
|
|
|
|
?>
|