Files
HotLunches/staff-delivery-reports.php
T
2026-10-19 15:22:52 -07:00

214 lines
7.1 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
// Start the template and output buffering
startTemplate();
$headerArgs = "";
$school_name = $school_record['school_name'];
unset($student);
if ($_SESSION['UserInfo']['type'] != 'Staff') {
header("Location: /?error_message=".urlencode(getLanguageText('ERRORMSG-ACCESS-DENIED')));
exit();
}
// Get teacher number
$user_num = intval($_SESSION['UserInfo']['record_num']);
$teacher_num = db_getVal("SELECT record_num FROM people WHERE school_num = $base_school_num AND people_type = 'Staff' AND user_num = $user_num");
if (!$teacher_num || $teacher_num == 0) {
header("Location: /?error_message=".urlencode(getLanguageText('ERRORMSG-ACCESS-DENIED')." - $user_num - $teacher_num"));
exit();
}
// Get set of classes for this teacher
$r = db_query("SELECT * FROM classes WHERE school_num = $base_school_num AND (teacher1 = $teacher_num OR teacher2 = $teacher_num OR teacher3 = $teacher_num)");
if (db_num_rows($r) == 0) {
header("Location: /?error_message=".urlencode(getLanguageText('ERRORMSG-NO-CLASSES-FOUND')));
exit();
}
// Get class info
$classes = array();
while ($row = db_fetch_assoc($r)) {
$class_num = $row['record_num'];
$class_info = getClassInfo($class_num,'internal',0);
$classes[] = array($class_num,$class_info);
}
$templatePageTitle = $_SESSION['UserInfo']['first_name'] . ' ' . $_SESSION['UserInfo']['last_name'] . ' - ' . getLanguageText('TEXT-DELIVERY-REPORT');
$today = date("Y-m-d",time());
$cutoff = date("Y-m-d",time() + 60 * 60 * 24 * 28);
$cutoff2 = date("Y-m-d H:i:00",time() - 60 * 60 * 24 * 28);
$currentSchedules = array();
$query = "SELECT hlm.* FROM hotlunch_menu_dates AS hlm, hotlunch_schedules AS hls " .
"WHERE hlm.school_num = $school_num " .
"AND (" .
"(menu_date BETWEEN '$today' AND '$cutoff' AND hls.schedule_type IN ('Hot Lunch','Date Sensitive')) " .
"OR (hls.schedule_type NOT IN ('Hot Lunch','Date Sensitive') AND hls.end_order_datetime >= '$cutoff2') " .
") " .
"AND hls.school_num = $school_num " .
"AND hlm.schedule_num = hls.record_num " .
"AND hls.status = 'Active' " .
"ORDER BY hlm.sequence";
echo("<!-- $query -->\n\n");
$upcoming_menus = db_query($query);
if (db_num_rows($upcoming_menus)) {
?>
<br>
<table width='550' cellpadding='5' cellspacing='2' border='0' class='content-table'>
<tr>
<td align='left'>
<?php
$psnum = 0;
while ($row = db_fetch_assoc($upcoming_menus)) {
$title = $row['menu_title'];
$mdate = $row['menu_date'];
$mnum = $row['record_num'];
$snum = $row['schedule_num'];
if ($snum != $psnum) {
$currentSchedules[] = $snum;
$stitle = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $snum");
if ($psnum > 0) echo("</ul><br>\n");
echo("<p><b>$stitle</b></p>\n");
echo("<ul>");
$psnum = $snum;
}
echo(" <li><a href='?action=delivery-details-print&rowHeight=Normal&menu_num=$mnum&class_num=$class_num'>$title</a></li>\n");
}
echo(" </ul>\n");
?>
</td>
</tr>
</table>
<?php
}
if (count($currentSchedules) == 0) {
header("Location: /?error_message=".urlencode(getLanguageText('ERRORMSG-NO-CURRENT-SCHEDULES')));
exit();
}
?>
<br>
<form method='post'>
<table width='550' cellpadding='5' cellspacing='2' border='0' class='content-table'>
<tr>
<td align='center'>
<table>
<tr>
<td align='left' ><b><?php displayLanguageText('TEXT-MENU'); ?></b>:<br>
<select name='menu_num' class='select-width400'>
<?php
// Get list of current schedules
$today = date("Y-m-d",time());
$now = date("Y-m-d H:i:s",time());
$cutoff = date("Y-m-d",time() - 60 * 60 * 24 * 10);
$query = "SELECT * FROM hotlunch_schedules " .
"WHERE school_num = $school_num " .
"AND schedule_type != 'Volunteer Only' " .
"AND status = 'Active' " .
"AND start_order_datetime <= '$now' " .
"AND schedule_end_date >= '$cutoff' " .
"order by $scheduleSortOrder";
$selectedSchedules = implode(',',$currentSchedules);
$query = "SELECT * FROM hotlunch_schedules " .
"WHERE school_num = $school_num " .
"AND record_num IN ($selectedSchedules) " .
"order by $scheduleSortOrder";
$results = db_query($query);
$num_schedules = db_num_rows($results);
$count = 0;
while ($row = db_fetch_array($results)) {
$schedule_num = $row['record_num'];
$schedule_name = $row['schedule_name'];
$display_menu_date = $row['display_menu_date'];
if ($count == 0) {
$currmenu = db_getVal("SELECT record_num FROM hotlunch_menu_dates WHERE school_num = $school_num AND menu_date >= '$today' Order BY 1 LIMIT 0,1");
}
$count++;
$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)) {
echo(" <optgroup label='$schedule_name'>\n");
while ($row = db_fetch_assoc($menu_dates)) {
$mnum = $row['record_num'];
$mtitle = $row['menu_title'];
$mdate = date("D M j, Y",strtotime($row['menu_date']) + 60 * 60 * 10);
if ($display_menu_date == 'Y') $mtitle .= " - $mdate";
$selected = "";
if ($row['record_num'] == $currmenu) $selected = " selected='selected'";
echo(" <option value='$mnum'$selected>$mtitle</option>\n");
}
echo(" </optgroup>\n");
}
}
?>
</select>
</td>
</tr>
<?php if (count($classes) > 1) { ?>
<tr>
<td align='left' ><b><?php echo($GlobalText['Class']); ?></b>:<br>
<select name='class_num' class='select-width400'>
<?php
for ($i = 0; $i < count($classes); $i++) {
$class_num = $classes[$i][0];
$class_info = $classes[$i][1];
echo(" <option value='$class_num'>$class_info</option>\n");
}
?>
</select>
</td>
</tr>
<?php } else { ?>
<input type='hidden' name='class_num' value='<?php echo($classes[0][0]) ?>'>
<?php } ?>
<tr>
<td align='left'><b><?php displayLanguageText('TEXT-REPORT-ROW-HEIGHT'); ?></b>:<br>
<?php BuildFileRadio("delivery_report_row_height.txt","rowHeight",$school_record['delivery_report_row_height']) ?></td>
</tr>
<tr>
<td align='center'><input type='submit' name='button' class='btn btn--primary' value="<?php displayLanguageText('TEXT-DELIVERY-REPORT'); ?>"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<input type='hidden' name='action' value='delivery-details-print'>
</form>
<?php
include "get.adobe.php";
endTemplate();
?>