Files
HotLunches/schedule_products.php
2026-10-19 15:22:52 -07:00

252 lines
7.9 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
// Start the template and output buffering
startTemplate();
$templatePageTitle = getLanguageText('TEXT-SCHEDULE-PRODUCTS-SUMMARY');
$headerArgs = "";
// Ensure that only valid user types have access to this module
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Supplier');
if (checkPermission($AllowedUserTypes) != 1) {
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
$action = '';
$naction = '';
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
exit();
}
//
// Process all actions to list and edit records
//
$naction = "";
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 = getLanguageText('ERRORMSG-INVALID-SCHEDULE');
$naction = '';
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&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) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE');
include "form.messages.php";
return;
}
$hotlunch_schedule = db_fetch_array($results);
// If this is a ScheduleTeam user check if they have permission to access this schedule
if (in_array($_SESSION['UserInfo']['type'],array('Schedule Team','Schedule Volunteer'))) {
$userNum = intval($_SESSION['UserInfo']['record_num']);
$access = db_getVal("SELECT count(*) FROM hotlunch_schedules_people WHERE school_num = $school_num AND schedule_num = $schedule_num AND user_num = $userNum");
if (!$access || $access == 0) {
echo("<br>\n");
$error_message = "You are not allowed access to the requested hot lunch schedule";
include "form.messages.php";
return;
}
}
$num_menu_dates = db_getVal("SELECT count(*) FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $schedule_num");
$select_size = $num_menu_dates;
if ($select_size > 10) $select_size = 10;
include "hotlunch_reports.menu.php";
echo("<br>\n");
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
$school_num = $school_record['record_num'];
include "form.messages.php";
//
// Display the menu selection
//
?>
<form method='post' action='/'>
<table width='90%' class='content-table'>
<tr class='heading'>
<td colspan='2' align='center'><?php displayLanguageText('TEXT-SCHEDULE-PRODUCTS-SUMMARY'); ?></td>
</tr>
<tr>
<td colspan='2' align='center'>
<br>
<table class='content-table'>
<tr class='heading'>
<td align='center'><?php displayLanguageText('TEXT-SELECTED-MENU-DATES'); ?></td>
</tr>
<tr>
<td align='left'>
<select name='selected_menus[]' multiple size='<?php echo($select_size) ?>'>
<?php
$query = "select * from hotlunch_menu_dates " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"order by sequence,menu_date";
$results = db_query($query);
$selected_date = 'N';
while ($row = db_fetch_array($results)) {
$mtitle = $row['menu_title'];
$mdate = $row['menu_date'];
$record_num = $row['record_num'];
if ($hotlunch_schedule['display_menu_date'] == 'Y') $mtitle .= " - $mdate";
$selected = "";
if (isset($menu_num) && $menu_num == $record_num) {
$selected_date = 'Y';
$selected = " selected='selected'";
}
$selected = " selected='selected'";
echo(" <option value='$record_num'$selected>$mtitle</option>\n");
}
?>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<br>
<table width='600' class='content-table'>
<tr class='heading'>
<td colspan='2' align='center'><?php displayLanguageText('TEXT-SCHEDULE-PRODUCTS'); ?></td>
</tr>
<tr class='data-odd'>
<td align='left'><b>Check/Uncheck All Products</b> :: </td>
<td align='center'><input type='checkbox' name='select_all' id='select_all' value='Y' onClick='toggleProductCheckboxes();'></td>
</tr>
<?php
// Display the schedule products
$query = "SELECT * FROM supplier_products " .
"WHERE school_num = $supplier_school_num " .
"AND record_num IN " .
"(SELECT supplier_product_num FROM hotlunch_menu_products AS hlmp, hotlunch_menu_items AS hlmi, hotlunch_menu_dates AS hlmd " .
"WHERE hlmp.menu_item_num = hlmi.record_num " .
"AND hlmp.school_num = $school_num " .
"AND hlmi.school_num = $school_num " .
"AND hlmd.school_num = $school_num " .
"AND hlmi.menu_num = hlmd.record_num " .
"AND hlmd.schedule_num = $schedule_num) " .
"ORDER BY product_name";
$schedule_products = db_query($query);
$count = 0;
$products = array();
while ($product = db_fetch_array($schedule_products)) {
$product_name = $product['product_name'];
$product_num = $product['record_num'];
$products[] = "product_$product_num";
$class = 'data-even';
if ($count % 2) $class = 'data-odd';
$count++;
?>
<tr class='<?php echo($class) ?>'>
<td align='left'><?php echo($product_name) ?>: </td>
<td align='center'><input type='checkbox' name='selected_products[]' id='product_<?php echo($product_num) ?>' value='<?php echo($product_num) ?>' onClick='clearOnePerBox();'></td>
</tr>
<?php
}
$class = 'data-even';
if ($count % 2) $class = 'data-odd';
$count++;
?>
</table>
<br>
</td>
</tr>
</table>
<br>
<input type='hidden' name='action' value='schedule-products-csv-generate'>
<input type='hidden' name='schedule_num' value='<?php echo($schedule_num) ?>'>
<input type='submit' name='button' class='btn btn--primary' value='Generate CSV'>
</form>
<br>
<?php
?>
<?php include "hotlunch_orders.print_buttons.php"; ?>
<script language='javascript'>
function toggleProductCheckboxes() {
var cb = document.getElementById('select_all').checked;
if (cb == false) {
<?php
for ($i = 0; $i < count($products); $i++) {
$product = $products[$i];
echo(" var cb$i = document.getElementById('$product');\n");
echo(" cb$i.checked = false;\n");
}
?>
}
else {
<?php
for ($i = 0; $i < count($products); $i++) {
$product = $products[$i];
echo(" var cb$i = document.getElementById('$product');\n");
echo(" cb$i.checked = true;\n");
}
?>
}
}
function clearItemCheckboxes() {
var cb = document.getElementById('one_per').checked;
if (cb == false) {
return true;
}
else {
<?php
for ($i = 0; $i < count($products); $i++) {
$product = $products[$i];
echo(" var cb$i = document.getElementById('$product');\n");
echo(" cb$i.checked = false;\n");
}
?>
}
}
function clearOnePerBox() {
var cb = document.getElementById('one_per');
cb.checked = false;
}
</script>
<?php
endTemplate();
?>