First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,322 @@
|
||||
<?php
|
||||
$ValidAccess = 2010;
|
||||
require_once("include/globals.php");
|
||||
|
||||
// Use existing session if already active (index.php usually 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=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);
|
||||
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 (!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();
|
||||
}
|
||||
|
||||
// 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 = dateString('default',strtotime($hotlunch_menu_date['menu_date']));
|
||||
|
||||
|
||||
// Get set of group codes in use in this menu
|
||||
$groups = array();
|
||||
$results = db_query("SELECT DISTINCT menu_group FROM hotlunch_menu_items WHERE school_num = $school_num AND menu_num = $menu_num");
|
||||
while ($row = db_fetch_array($results)) {
|
||||
if (strlen($row['menu_group']) > 0) $groups[] = $row['menu_group'];
|
||||
}
|
||||
|
||||
|
||||
$school_name = $school_record['school_name'];
|
||||
|
||||
|
||||
// Initialize the PDF document
|
||||
$document_font = "FreeSans";
|
||||
$document_font_weight = "";
|
||||
$document_text_color = "#000000";
|
||||
$document_font_size = 9;
|
||||
$incr = 4;
|
||||
|
||||
// Default font style parameter for TCPDF SetFont
|
||||
$font_parm = "";
|
||||
|
||||
|
||||
// Set parameters for this document
|
||||
$start_row = 10;
|
||||
$max_rows = 250;
|
||||
|
||||
$left_col = 10;
|
||||
$title_col = 60;
|
||||
$group_col = 15;
|
||||
$qty_col = 25;
|
||||
$item_col = 30;
|
||||
|
||||
$title_width = 190;
|
||||
|
||||
$report_title = "$school_name - $menu_title - $menu_date";
|
||||
$document_name = getLanguageText('TEXT-MENU-GROUPS-CHECK-REPORT');
|
||||
|
||||
|
||||
//
|
||||
// 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'];
|
||||
$logo_row = $max_rows + 5;
|
||||
|
||||
class PDF extends TCPDF {
|
||||
function Header() {
|
||||
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title;
|
||||
|
||||
// Print the header
|
||||
$this->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
||||
$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);
|
||||
}
|
||||
|
||||
function Footer() {
|
||||
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row, $school_name;
|
||||
|
||||
$curr_row = $max_rows;
|
||||
|
||||
// Print the date
|
||||
$this->SetFont($document_font,"",$document_font_size - 1);
|
||||
$this->SetXY($left_col,$curr_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,$max_rows, 50);
|
||||
|
||||
$this->SetXY(20,$curr_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->SetTextColor($font_red,$font_green,$font_blue);
|
||||
$pdf->SetFont($document_font,"",$document_font_size);
|
||||
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
||||
|
||||
$pdf->SetAutoPageBreak(true,10);
|
||||
$curr_row = $max_rows + 10;
|
||||
|
||||
|
||||
//
|
||||
// Get set of people to process
|
||||
//
|
||||
$people = db_query("SELECT * FROM people WHERE school_num = $base_school_num ORDER BY last_name,first_name");
|
||||
|
||||
|
||||
// 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) {
|
||||
$pdf->addPage();
|
||||
$curr_row = $start_row + 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 group A
|
||||
$query = "SELECT sum(qty) 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 = 'A' " .
|
||||
"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";
|
||||
$groupACount = db_getVal($query);
|
||||
if ($groupACount == 0) continue;
|
||||
|
||||
// Display name
|
||||
$pdf->SetFont($document_font,$font_parm,$document_font_size);
|
||||
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
||||
|
||||
$name = trim($first_name . ' ' . $last_name);
|
||||
if (isset($people_type) && $people_type == 'Staff') $name .= " (Staff)";
|
||||
$pdf->SetXY($left_col,$curr_row);
|
||||
$pdf->Cell($title_width,$incr,$name,'0',1,'L',true);
|
||||
$curr_row += $incr;
|
||||
|
||||
// List items ordered
|
||||
for ($i = 0; $i < count($groups); $i++) {
|
||||
$gCode = $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) {
|
||||
$sum = 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(150,$incr,$row['item_title'],'0',1,'L',false);
|
||||
|
||||
$sum += $row['qty'];
|
||||
$curr_row += $incr;
|
||||
}
|
||||
|
||||
if ($sum < $groupACount) {
|
||||
$pdf->SetXY($item_col + 100,$curr_row - $incr);
|
||||
$pdf->Cell(50,$incr,getLanguageText('TEXT-ERROR'),'0',1,'L',false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$pdf->SetFont($document_font,"B",$document_font_size);
|
||||
$pdf->SetXY($group_col,$curr_row);
|
||||
$pdf->Cell(20,$incr,$gCode,'0',1,'L',false);
|
||||
|
||||
$pdf->SetXY($qty_col,$curr_row);
|
||||
$pdf->Cell(80,$incr,getLanguageText('TEXT-NO-ITEMS-ORDERED'),'0',1,'L',true);
|
||||
$pdf->SetFont($document_font,"",$document_font_size);
|
||||
|
||||
$curr_row += $incr;
|
||||
}
|
||||
}
|
||||
|
||||
$curr_row += $incr;
|
||||
$pCount++;
|
||||
}
|
||||
|
||||
|
||||
// Print total number of people
|
||||
$curr_row += $incr;
|
||||
$pdf->SetXY($qty_col,$curr_row);
|
||||
$pdf->Cell($title_width,$incr,getLanguageText('TEXT-ORDERS').": $pCount",'0',1,'L',false);
|
||||
|
||||
|
||||
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-check.pdf");
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
|
||||
$pdf->Output("menu-groups-check.pdf","D");
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user