Files
HotLunches/student-list.print.php
T
2026-10-19 15:22:52 -07:00

315 lines
10 KiB
PHP

<?php
$ValidAccess = 2010;
require_once("include/globals.php");
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
echo("<br>\n");
$error_message = "Invalid Access";
include "form.messages.php";
exit();
}
// Ensure that only valid user types have access to this module
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Communications Administrator','Administration Team','Schedule Team','Financial','Financial Team');
if (checkPermission($AllowedUserTypes) != 1) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
include "form.messages.php";
return;
}
// Determine how many schedules to report on
$today = date("Y-m-d",time() + 60 * 60 * 24 * 90);
$now = date("Y-m-d H:i:s",time() + 60 * 60 * 24 * 90);
$numSchedules = db_getVal("select count(*) from hotlunch_schedules " .
"where school_num = $school_num " .
"and status not in ('Pending','Completed','Closed','Deleted') " .
"and start_order_datetime <= '$now' " .
"order by schedule_start_date ASC");
if ($numSchedules <= 7) {
$limit = "0,7";
}
else {
$start = $numSchedules - 7;
$limit = "$start,7";
}
$schedules = db_query("SELECT * FROM hotlunch_schedules " .
"WHERE school_num = $school_num " .
"AND status not in ('Pending','Completed','Closed','Deleted') " .
"AND start_order_datetime <= '$now' " .
"ORDER BY schedule_start_date ASC " .
"LIMIT $limit");
$schedule_dates = array();
$n = 0;
while ($row = db_fetch_array($schedules)) {
$schedule_dates[$n]['date'] = $row['schedule_start_date'];
$schedule_dates[$n]['title'] = $row['schedule_name'];
$schedule_dates[$n]['num'] = $row['record_num'];
$n++;
}
$query = "SELECT p.first_name,p.last_name,people_type,class_num,sequence,p.record_num AS people_num,p.user_num,userid,u.email " .
"FROM classes,users AS u,people AS p " .
"WHERE p.school_num = $base_school_num " .
"AND p.class_num = classes.record_num " .
"AND p.user_num = u.record_num " .
"AND p.people_type = 'Student' " .
"AND u.school_num = $base_school_num " .
"AND classes.school_num = $base_school_num " .
"UNION " .
"SELECT p.first_name,p.last_name,people_type,0,999,p.record_num AS people_num,p.user_num,userid,u.email " .
"FROM users AS u,people AS p " .
"WHERE p.school_num = $base_school_num " .
"AND p.user_num = u.record_num " .
"AND p.people_type = 'Staff' " .
"AND u.school_num = $base_school_num " .
"ORDER BY sequence,last_name,first_name";
$people = db_query($query);
//
// Setup the PDF
//
$document_font = $school_record['document_font'];
if (strlen($document_font) == 0) $document_font = "Helvetica";
$document_font_weight = "";
$document_text_color = "#000000";
$document_font_size = 9;
// Set parameters for this document
$max_rows = 180;
$left_col = 15;
$name_col = 15;
$account_col = 55;
$email_col = 115;
$balance_col = 100;
$sched_col = 119;
$title_width = 250;
$name_width = $account_col - $name_col - 1;
$account_width = $balance_col - $account_col - 1;
$email_width = 64;
$balance_width = 18;
$sched_width = 100;
if ($numSchedules > 0) $sched_width = intval(100 / $numSchedules);
if ($sched_width < 20) $sched_width = 20;
$start_row = 25;
$incr = 4.5;
//
// 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() {
return;
}
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;
// 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 => 279.4mm x 215.9mm (landscape)
$pageFormat = array(279.4, 215.9);
$pdf= new PDF('L', '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();
$school_name = $school_record['school_name'];
$document_name = getLanguageText('TEXT-ORDERS');
// Process student records
$page_count = 0;
$prev_class = 0;
$curr_row = $start_row;
$student_count = 0;
while ($row = db_fetch_array($people)) {
extract($row);
if ($people_type == 'Staff') $class_num = 0;
if ($class_num != $prev_class || $curr_row > $max_rows - 5) {
if ($page_count > 0) {
// $curr_row += $incr;
$summary = getLanguageText('TEXT-ENTRIES') . ": $student_count";
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
$pdf->SetXY($name_col,$curr_row);
$pdf->Cell($title_width,$incr,$summary,'0',1,'L',true);
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$pdf->addPage();
}
$page_count++;
$class_info = getClassInfo($class_num);
$prev_class = $class_num;
$curr_row = $start_row;
// Display page titles
$pdf->SetFont($document_font,"B",12);
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$pdf->SetXY($name_col,10);
$pdf->Cell($title_width,$incr + 1,$school_name,'0',1,'L',true);
$pdf->SetXY($name_col,16);
$ctext = "Class List: ";
$pdf->Cell($title_width,$incr + 1,$class_info,'0',1,'L',true);
$pdf->SetFont($document_font,"",10);
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
// Create headers
$pdf->SetFont($document_font,"B",10);
$pdf->SetXY($name_col,$curr_row);
$pdf->MultiCell($name_width,$incr * 2,getLanguageText('TEXT-NAME'),0,'L',true,0,'','',true,1,false,true,$incr * 2);
$pdf->SetXY($account_col,$curr_row);
$pdf->MultiCell($account_width,$incr * 2,getLanguageText('TEXT-ACCOUNT'),0,'L',true,0,'','',true,1,false,true,$incr * 2);
// $pdf->SetXY($email_col,$curr_row);
// $pdf->Cell($email_width,$incr,getLanguageText('TEXT-EMAIL'),'0',1,'L',true);
$pdf->SetFont($document_font,"",8);
$pdf->SetXY($balance_col,$curr_row);
$pdf->MultiCell($balance_width,$incr * 2,getLanguageText('TEXT-BALANCE'),0,'R',true,0,'','',true,1,false,true,$incr * 2);
$pdf->SetFont($document_font,"",7);
for ($i = 0; $i < count($schedule_dates); $i++) {
$col = $sched_col + $i * $sched_width + $i;
$pdf->SetXY($col,$curr_row);
$pdf->MultiCell($sched_width,$incr * 2,$schedule_dates[$i]['date'] . "\n" . $schedule_dates[$i]['title'],0,'C',true,0,'','',true,0,false,true,$incr * 2);
}
$pdf->SetFont($document_font,"",10);
$pdf->SetFont($document_font,"",9);
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$curr_row += $incr * 2;
$student_count = 0;
$email_count = 0;
}
$fill = false;
if ($student_count % 2) $fill = true;
$student_count++;
// if (strlen($email) > 0) $email_count++;
$name = $first_name . " " . $last_name;
$pdf->SetXY($name_col,$curr_row);
$pdf->Cell($name_width,$incr,$name,'0',1,'L',$fill,'',1);
$pdf->SetXY($account_col,$curr_row);
$pdf->Cell($account_width,$incr,$userid,'0',1,'L',$fill,'',1);
// $pdf->SetXY($email_col,$curr_row);
// $pdf->Cell($email_width,$incr,$email,'0',1,'L',$fill);
$balance = "";
$balance = db_getVal("SELECT sum(transaction_amount) FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND (deleted != 'Y' OR deleted IS NULL)");
$balance = floatval($balance);
if ($balance != 0.00) {
$sign = "";
if ($balance < 0) $sign = "-";
$balance = $sign . $currencySymbol . number_format(abs($balance),2);
}
$pdf->SetFont($document_font,"",8);
$pdf->SetXY($balance_col,$curr_row);
$pdf->Cell($balance_width,$incr,$balance,'0',1,'R',$fill,'',1);
for ($i = 0; $i < count($schedule_dates); $i++) {
$col = $sched_col + $i * $sched_width + $i;
$snum = $schedule_dates[$i]['num'];
$source = db_getVal("SELECT source FROM hotlunch_order_header WHERE school_num = $school_num AND schedule_num = $snum AND ordered_by_num = $people_num");
$pdf->SetXY($col,$curr_row);
$pdf->Cell($sched_width,$incr,$source,'0',1,'C',$fill,'',1);
}
$pdf->SetFont($document_font,"",$document_font_size);
$curr_row += $incr;
}
// Print summary for last class
$curr_row += $incr * 2;
$summary = getLanguageText('TEXT-ENTRIES') . ": $student_count";
$pdf->SetXY($name_col,$curr_row);
$pdf->Cell(250,$incr,$summary,'0',1,'L',true);
// Output the completed 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=student-list.pdf");
header('Content-Transfer-Encoding: binary');
$pdf->Output("student-list.pdf","D");
return;
?>