334 lines
9.5 KiB
PHP
334 lines
9.5 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
header("Location: /?error_code=NOACCESS");
|
|
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');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
header("Location: /?error_code=INVALIDACCESS");
|
|
exit();
|
|
}
|
|
|
|
|
|
// Get set of allergens defined
|
|
$allergens = db_query("select * from allergens where school_num = $school_num order by sequence");
|
|
if (db_num_rows($allergens) == 0) {
|
|
header("Location: /?error_code=NOALLERGENS");
|
|
exit();
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// 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;
|
|
|
|
$left_col = 5;
|
|
$middle_col = 100;
|
|
$title_width = 270;
|
|
|
|
|
|
// Set parameters for this document
|
|
$max_rows = 180;
|
|
$columns = array(5,55,150,185,210,275);
|
|
|
|
$start_row = 5;
|
|
$incr = 4.0;
|
|
|
|
|
|
$logo_url = $school_record['logo_url'];
|
|
$logo_image = "images/" . $school_record['logo_image'];
|
|
$logo_row = $max_rows + 5;
|
|
|
|
$report_title = getLanguageText('TEXT-ALLERGIES');
|
|
$document_name = $report_title;
|
|
|
|
$mode = 'Normal';
|
|
|
|
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $columns, $alignment, $headings, $curr_row;
|
|
global $allergen, $columns;
|
|
|
|
$this->SetFont($document_font,"B",$document_font_size + 1);
|
|
$this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
// Report title
|
|
$this->SetXY($left_col,$start_row);
|
|
$this->Cell($title_width,$incr,$report_title,'0',1,'L',true);
|
|
|
|
$row = $start_row + $incr + 1;
|
|
if (isset($headings) && is_array($headings)) {
|
|
for ($i = 0; $i < count($headings); $i++) {
|
|
$col = $columns[$i];
|
|
$width = $columns[$i + 1] - $col;
|
|
$align = $alignment[$i];
|
|
$this->SetXY($col,$row);
|
|
$this->Cell($width,$incr,' '.$headings[$i],'0',1,$align,true);
|
|
}
|
|
}
|
|
|
|
$curr_row = $row;
|
|
$this->subHeader();
|
|
}
|
|
|
|
function subHeader() {
|
|
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $columns, $alignment, $headings, $curr_row;
|
|
global $allergen, $columns, $mode;
|
|
|
|
$row = $curr_row;
|
|
|
|
$this->SetFont($document_font,"B",$document_font_size);
|
|
$this->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$this->SetXY($columns[0],$row);
|
|
$this->Cell(270,$incr,$allergen,'0',1,'L',true);
|
|
$row += $incr + 1;
|
|
|
|
$this->SetFont($document_font,"B",$document_font_size);
|
|
$this->SetXY($columns[0],$row);
|
|
$width = $columns[1] - $columns[0];
|
|
$this->Cell(270,$incr,getLanguageText('TEXT-NAME'),'0',1,'L',true);
|
|
|
|
$this->SetXY($columns[1],$row);
|
|
$width = $columns[2] - $columns[1];
|
|
$this->Cell($width,$incr,getLanguageText('TEXT-CLASS'),'0',1,'L',true);
|
|
|
|
if ($mode == 'Normal') {
|
|
$this->SetXY($columns[2],$row);
|
|
$width = $columns[5] - $columns[2];
|
|
$this->Cell($width,$incr,getLanguageText('TEXT-ACCOUNT'),'0',1,'L',true);
|
|
}
|
|
|
|
$row += $incr;
|
|
|
|
$this->SetFont($document_font,"",$document_font_size);
|
|
$this->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
|
|
$curr_row = $row;
|
|
}
|
|
|
|
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->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$curr_row = $max_rows;
|
|
|
|
$school_name = $school_record['school_name'];
|
|
|
|
|
|
|
|
|
|
// Process each defined allergy
|
|
$prev_class = 0;
|
|
$curr_row = $max_rows;
|
|
while ($allergen = db_fetch_array($allergens)) {
|
|
extract($allergen);
|
|
|
|
// Get list of students with this allergy
|
|
$query = "select p.* from people as p,allergies as a " .
|
|
"where p.school_num = $base_school_num " .
|
|
"and a.school_num = $school_num " .
|
|
"and a.allergen_num = $record_num " .
|
|
"and a.people_num = p.record_num " .
|
|
"order by p.last_name,p.first_name";
|
|
$students = db_query($query);
|
|
|
|
$num_students = db_num_rows($students);
|
|
|
|
if ($num_students > 0) {
|
|
if ((($num_students + 3) * $incr + $curr_row) > $max_rows) {
|
|
$pdf->addPage();
|
|
$curr_row = $start_row + 3 * $incr + 3;
|
|
}
|
|
else {
|
|
$curr_row += $incr;
|
|
$pdf->subHeader();
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$line_count = 0;
|
|
|
|
while ($student = db_fetch_array($students)) {
|
|
extract($student);
|
|
$name = "$first_name $last_name";
|
|
|
|
$class_info = getClassInfo($class_num,'internal',1);
|
|
$contact_info = getContactInfo($user_num);
|
|
|
|
$fill = false;
|
|
if ($line_count % 2) $fill = true;
|
|
$cnum = 0;
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($columns[$cnum],$curr_row);
|
|
$pdf->Cell($width,$incr,$name,'0',1,'L',$fill);
|
|
|
|
$cnum = 1;
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($columns[$cnum],$curr_row);
|
|
$pdf->Cell($width,$incr,$class_info,'0',1,'L',$fill);
|
|
|
|
$cnum = 2;
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($columns[$cnum],$curr_row);
|
|
$pdf->Cell($width,$incr,$contact_info[0],'0',1,'L',$fill);
|
|
|
|
$cnum = 3;
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($columns[$cnum],$curr_row);
|
|
$pdf->Cell($width,$incr,$contact_info[1],'0',1,'L',$fill);
|
|
|
|
$cnum = 4;
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($columns[$cnum],$curr_row);
|
|
$pdf->Cell($width,$incr,$contact_info[2],'0',1,'L',$fill);
|
|
|
|
$line_count++;
|
|
$curr_row += $incr;
|
|
|
|
if ($curr_row >= $max_rows) {
|
|
$pdf->addPage();
|
|
$curr_row = $start_row + 3 * $incr + 3;
|
|
}
|
|
}
|
|
|
|
$curr_row += $incr + 2;
|
|
}
|
|
}
|
|
|
|
|
|
// Get special diet requests
|
|
$query = "SELECT * FROM people WHERE school_num = $base_school_num AND diet_requests != '' ORDER BY last_name,first_name";
|
|
$people = db_query($query);
|
|
$num_students = db_num_rows($people);
|
|
|
|
if ($num_students) {
|
|
$allergen = getLanguageText('TEXT-SPECIAL-DIET-REQUESTS');
|
|
$mode = "Diet";
|
|
|
|
if ((($num_students + 3) * $incr + $curr_row) > $max_rows) {
|
|
$pdf->addPage();
|
|
$curr_row = $start_row + 3 * $incr + 3;
|
|
}
|
|
else {
|
|
$curr_row += $incr;
|
|
$pdf->subHeader();
|
|
}
|
|
|
|
while ($row = db_fetch_assoc($people)) {
|
|
extract($row);
|
|
$name = "$first_name $last_name";
|
|
|
|
$class_info = getClassInfo($class_num,'internal',1);
|
|
$contact_info = getContactInfo($user_num);
|
|
|
|
$fill = false;
|
|
if ($line_count % 2) $fill = true;
|
|
$cnum = 0;
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$width = 270;
|
|
$pdf->SetXY($columns[$cnum],$curr_row);
|
|
$pdf->Cell($width,$incr,$name,'0',1,'L',$fill);
|
|
|
|
$cnum = 1;
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($columns[$cnum],$curr_row);
|
|
$pdf->Cell($width,$incr,$class_info,'0',1,'L',$fill);
|
|
|
|
$cnum = 2;
|
|
$col = 120;
|
|
$width = 275 - $col;
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($width,$incr,$diet_requests,'0',1,'L',$fill,'',1);
|
|
|
|
$line_count++;
|
|
$curr_row += $incr;
|
|
|
|
if ($curr_row >= $max_rows) {
|
|
$pdf->addPage();
|
|
$curr_row = $start_row + 3 * $incr + 3;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 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=allergies.pdf");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output("allergies.pdf","D");
|
|
return;
|
|
|
|
?>
|