327 lines
10 KiB
PHP
327 lines
10 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
|
|
require_once("include/globals.php");
|
|
|
|
// Start session only if not already active, and avoid changing name mid-session
|
|
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()) {
|
|
$error_message = "Invalid Access";
|
|
header("Location: /?error_message=".urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Volunteer Administrator','Financial Team');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
header("Location: /?error_message=".urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
|
|
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
|
|
if (array_key_exists('schedule_num',$_POST)) $schedule_num = intval($_POST['schedule_num']);
|
|
|
|
if (!isset($schedule_num)) {
|
|
$error_message = "Error: schedule number must be specified";
|
|
header("Location: /?error_message=".urlencode($error_message));
|
|
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) {
|
|
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE');
|
|
header("Location: /?error_message=".urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
$hotlunch_schedule = db_fetch_array($results);
|
|
$schedule_name = $hotlunch_schedule['schedule_name'];
|
|
$schedule_num = $hotlunch_schedule['record_num'];
|
|
|
|
|
|
// Get the menu dates for this schedule
|
|
$today = date("Y-m-d",time());
|
|
$query = "select * from hotlunch_menu_dates " .
|
|
"where school_num = $school_num " .
|
|
"and schedule_num = $schedule_num " .
|
|
"order by sequence,menu_date";
|
|
$menu_dates = db_query($query);
|
|
|
|
if (db_num_rows($menu_dates) == 0) {
|
|
$error_message = "There are no active menu dates defined for this schedule";
|
|
header("Location: /?error_message=".urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
// Setup the PDF
|
|
//
|
|
$document_font = "Helvetica";
|
|
$document_font_weight = "";
|
|
$document_text_color = "#000000";
|
|
$document_font_size = 9;
|
|
|
|
|
|
// Set parameters for this document
|
|
$max_rows = 245;
|
|
|
|
$logo_url = "www.hotlunches.net";
|
|
$logo_image = "images/" . $school_record['logo_image'];
|
|
$logo_row = $max_rows + 10;
|
|
|
|
$title_width = 195;
|
|
$line_width = $title_width;
|
|
$left_col = 10;
|
|
$date_col = 160;
|
|
$date_width = $line_width - $date_col + $left_col;
|
|
|
|
$name_col = $left_col;
|
|
$phone_col = 70;
|
|
$email_col = 100;
|
|
$class_col = 170;
|
|
|
|
$name_width = $phone_col - $name_col;
|
|
$phone_width = $email_col - $phone_col;
|
|
$email_width = $class_col - $email_col;
|
|
$class_width = $line_width - $class_col + $left_col;
|
|
|
|
$start_row = 10;
|
|
$incr = 4.5;
|
|
|
|
$report_title = $school_record['school_name'];
|
|
$report_subtitle = getLanguageText('TEXT-VOLUNTEER-LIST') . ": " . $schedule_name;
|
|
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
global $incr, $left_col, $line_width, $date_col, $date_width, $start_row, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle, $menu_title, $mdate;
|
|
|
|
$curr_row = $start_row;
|
|
|
|
// Print the header
|
|
$this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
$this->SetFont($document_font,"B",$document_font_size + 1);
|
|
$this->SetXY($left_col,$curr_row);
|
|
$this->Cell($title_width,$incr + 1,$report_title,'0',1,'L',true,'',1);
|
|
|
|
$curr_row += $incr + 2;
|
|
|
|
if (isset($report_subtitle) && strlen($report_subtitle) > 0) {
|
|
$this->SetXY($left_col,$curr_row);
|
|
$this->Cell($title_width,$incr + 1,$report_subtitle,'0',1,'L',true,'',1);
|
|
}
|
|
|
|
$this->SetFont($document_font,"B",$document_font_size);
|
|
$this->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
|
|
$curr_row += $incr + 2;
|
|
|
|
// Print the menu title
|
|
$this->SetXY($left_col,$curr_row);
|
|
$this->Cell($line_width,$incr,$menu_title,'0',1,'L',true,'',1);
|
|
|
|
$this->SetXY($date_col,$curr_row);
|
|
$this->Cell($date_width,$incr,$mdate,'0',1,'R',true,'',1);
|
|
}
|
|
|
|
function Footer() {
|
|
|
|
global $logo_row, $document_font, $document_font_size, $siteType, $school_record, $incr;
|
|
$document_name = getLanguageText('TEXT-VOLUNTEER-LIST');
|
|
|
|
// Add logo to page
|
|
$this->Image("images/".$school_record['logo_image'],10,$logo_row + 5,50);
|
|
|
|
$this->SetFont($document_font,"",$document_font_size - 1);
|
|
$this->SetXY(80,$logo_row + 5);
|
|
$date = dateString('datetime');
|
|
$this->Cell(120,$incr - 1,$document_name . ": $date",'0',1,'R',false,'',1);
|
|
|
|
$school_name = $school_record['school_name'];
|
|
$this->SetXY(80,$logo_row + 5 + $incr);
|
|
$this->Cell(120,$incr - 1,"$school_name",'0',1,'R');
|
|
|
|
$this->SetFont($document_font,"",$document_font_size);
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
|
|
$font_red = hexdec("00");
|
|
$font_green = hexdec("00");
|
|
$font_blue = hexdec("00");
|
|
|
|
$pdf->SetTextColor($font_red,$font_green,$font_blue);
|
|
|
|
|
|
|
|
|
|
$curr_row = $max_rows + 5;
|
|
$pageNum = 0;
|
|
|
|
$orderBy = "last_name,first_name";
|
|
if ($school_record['volunteer_sorting'] == 'Manual Sorting') $orderBy = "sequence,$orderBy";
|
|
|
|
while ($row = db_fetch_array($menu_dates)) {
|
|
extract($row);
|
|
$menu_num = $record_num;
|
|
$menu_title .= " ($menu_num)";
|
|
$mdate = date("D M jS, Y",strtotime($menu_date) + 60 * 60 * 12);
|
|
|
|
// Get volunteers for this menu date
|
|
$query = "select first_name,last_name,email,home_phone,user_num " .
|
|
"from hotlunch_volunteers as hlv, users as u " .
|
|
"where hlv.school_num = $school_num " .
|
|
"and u.school_num = $base_school_num " .
|
|
"and schedule_num = $schedule_num " .
|
|
"and menu_num = $menu_num " .
|
|
"and user_num = u.record_num " .
|
|
"and hlv.deleted != 'Y' " .
|
|
"order by $orderBy";
|
|
$volunteers = db_query($query);
|
|
$num_volunteers = db_num_rows($volunteers);
|
|
$num_lines = ($num_volunteers + 2) * $incr;
|
|
if ($school_record['include_volunteer_details'] == 'Y') $num_lines = intval(2.1 * $num_lines);
|
|
|
|
if ($curr_row + $num_lines > $max_rows - 2) {
|
|
$pdf->addPage();
|
|
$pageNum++;
|
|
|
|
$curr_row = $start_row + $incr * 4 + 1;
|
|
}
|
|
else {
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
|
|
// Print the menu title
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($line_width,$incr,$menu_title,'0',1,'L',true,'',1);
|
|
|
|
$pdf->SetXY($date_col,$curr_row);
|
|
$pdf->Cell($date_width,$incr,$mdate,'0',1,'R',true,'',1);
|
|
$curr_row += $incr + 1;
|
|
}
|
|
|
|
|
|
// Print set of volunteers
|
|
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
|
|
$count = 0;
|
|
while ($row = db_fetch_array($volunteers)) {
|
|
$bg = $count % 2;
|
|
$count++;
|
|
|
|
if ($curr_row > $max_rows) {
|
|
$pdf->addPage();
|
|
$pageNum++;
|
|
|
|
$curr_row = $start_row + $incr * 4 + 1;
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$name = $row['first_name'] . ' ' . $row['last_name'];
|
|
$phone = $row['home_phone'];
|
|
$email = $row['email'];
|
|
|
|
$pdf->SetXY($name_col,$curr_row);
|
|
$pdf->Cell($name_width,$incr,$name,'0',1,'L',$bg,'',1);
|
|
|
|
$pdf->SetXY($phone_col,$curr_row);
|
|
$pdf->Cell($phone_width,$incr,$phone,'0',1,'L',$bg,'',1);
|
|
|
|
$pdf->SetXY($email_col,$curr_row);
|
|
$pdf->Cell($email_width,$incr,$email,'0',1,'L',$bg,'',1);
|
|
|
|
// Display student grades
|
|
$user_num = $row['user_num'];
|
|
$query = "SELECT c.* FROM people AS p, classes AS c " .
|
|
"WHERE p.school_num = $base_school_num " .
|
|
"AND p.user_num = $user_num " .
|
|
"AND c.school_num = $base_school_num " .
|
|
"AND p.class_num = c.record_num";
|
|
$classes = db_query($query);
|
|
$cinfo = "";
|
|
while ($class = db_fetch_assoc($classes)) {
|
|
$grade = $class['grade'];
|
|
$division = $class['division'];
|
|
$class_num = $class['record_num'];
|
|
|
|
if (strlen($cinfo)) $cinfo .= " // ";
|
|
$cinfo .= getClassInfo($class_num, 'internal', 0);
|
|
}
|
|
$pdf->SetXY($class_col,$curr_row);
|
|
$pdf->Cell($class_width,$incr,$cinfo,'0',1,'L',$bg,'',1);
|
|
|
|
// Display student names if required
|
|
if ($school_record['include_volunteer_details'] == 'Y') {
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
$user_num = $row['user_num'];
|
|
$students = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND user_num = $user_num");
|
|
while ($student = db_fetch_array($students)) {
|
|
$name = $student['first_name'] . ' ' . $student['last_name'];
|
|
$class = $student['class_num'];
|
|
$class_info = getClassInfo($class,'internal',1);
|
|
|
|
$curr_row += $incr - .5;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($line_width,$incr," " .
|
|
"- $name: $class_info",'0',1,'L',$bg,'',1);
|
|
}
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row += 1;
|
|
}
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
$curr_row += $incr;
|
|
if ($school_record['include_volunteer_details'] == 'Y') $curr_row += $incr;
|
|
}
|
|
|
|
|
|
|
|
// 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=volunteer-list.pdf");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output("volunteer-list.pdf","D");
|
|
return;
|
|
|
|
?>
|