Files
HotLunches/student-allergies.csv.php
2026-10-19 15:22:52 -07:00

101 lines
2.9 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();
}
// Initialize the spreadsheet document type
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/octet-stream; charset=utf-8");
header("Content-Disposition: attachment; filename=student-allergies.csv");
header('Content-Transfer-Encoding: text');
echo("\xEF\xBB\xBF");
$school_name = $school_record['school_name'];
echo("$school_name\n");
// Process each defined allergy
$prev_class = 0;
while ($row = db_fetch_array($allergens)) {
extract($row);
// 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) {
echo("-- $allergen --\n");
echo(getLanguageText('TEXT-NAME').",".getLanguageText('TEXT-CLASS').",".getLanguageText('TEXT-ACCOUNT')."\n");
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);
echo("\"$name\",\"$class_info\",\"".$contact_info[0]."\",\"".$contact_info[1]."\",\"".$contact_info[2]."\"\n");
}
echo("----------\n");
}
}
$query = "SELECT * FROM people WHERE school_num = $base_school_num AND diet_requests != '' ORDER BY last_name,first_name";
$people = db_query($query);
echo("-- ".getLanguageText('TEXT-SPECIAL-DIET-REQUESTS')." --\n");
echo(getLanguageText('TEXT-NAME').",".getLanguageText('TEXT-CLASS')."\n");
while ($row = db_fetch_assoc($people)) {
extract($row);
$name = "$first_name $last_name";
$class_info = getClassInfo($class_num,'internal',1);
echo("\"$name\",\"$class_info\",\"".$diet_requests."\"\n");
}
?>