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

243 lines
9.4 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
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','Supplier');
if (checkPermission($AllowedUserTypes) != 1) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
include "form.messages.php";
return;
}
$menu_num = intval($_GET['menu_num']);
$scriptName = str_replace("/m/data1/app.hotlunches.net/","",__FILE__);
include "help.docs.php";
?>
<br>
<form method='post' action='/'>
<?php
$message_width = $default_form_width;
include "form.messages.php";
?>
<table width='<?php echo($default_form_width) ?>' class='content-table'>
<tr>
<td colspan='2' align='center' class='heading'><?php displayLanguageText('TEXT-COPY-A-MENU'); ?></td>
</tr>
<tr>
<td colspan='2' align='center'>
<br>
<p style='width: 400px;'><b><?php displayLanguageText('TEXT-COPY-A-MENU-INSTRUCTIONS'); ?></b></p>
</td>
</tr>
<tr>
<td width='30%' align='right' valign='top'><?php displayLanguageText('TEXT-SOURCE-MENU'); ?>: </td>
<td width='70%' align='left' valign='top'>
<select name='source_menu' class='select-width400'>
<?php
$swhere = "";
if ($_SESSION['UserInfo']['type'] == 'Supplier') {
$snum = $_SESSION['UserInfo']['supplier_num'];
$swhere = " and hs.supplier_num = $snum ";
}
if ($school_num == 0) {
$query = "select distinct hlmd.*,hs.schedule_name,hs.schedule_start_date,hs.sequence AS schedule_sequence " .
"from hotlunch_menu_dates as hlmd,hotlunch_schedules as hs " .
"where hlmd.school_num IN (19244,19180) " .
"and hs.school_num IN (19244,19180) " .
"and hs.status NOT IN ('Closed','Deleted') " .
"and hlmd.schedule_num = hs.record_num " .
$swhere .
"order by school_num,schedule_sequence asc,hs.schedule_name,hlmd.sequence,menu_date";
}
else {
$query = "select distinct hlmd.*,hs.schedule_name,hs.schedule_start_date,hs.sequence AS schedule_sequence " .
"from hotlunch_menu_dates as hlmd,hotlunch_schedules as hs " .
"where hlmd.school_num = $school_num " .
"and hs.school_num = $school_num " .
"and hs.status NOT IN ('Closed','Deleted') " .
"and hlmd.schedule_num = hs.record_num " .
$swhere .
"order by school_num,schedule_sequence asc,hs.schedule_name,hlmd.sequence,menu_date";
}
$results = db_query($query);
$prev_school_num = 0;
$prev_schedule = "";
while ($row = db_fetch_array($results)) {
// If this is a child menu to another menu then it can not be copied from
if ($row['source_menu'] > 0 && $row['menu_link'] != 'No') continue;
// Get current menu values
$name = $row['menu_title'];
$date = date("l F jS, Y",strtotime($row['menu_date']));
$rnum = $row['record_num'];
$s_num = $row['school_num'];
if ($hotlunch_schedule['display_menu_date'] == 'Y' || $hotlunch_schedule['schedule_type'] == 'Date Sensitive') $name .= " - $date";
$numItems = db_getVal("SELECT count(*) FROM hotlunch_menu_items WHERE school_num = $s_num AND menu_num = $rnum");
$name .= " - ($numItems)";
$schedule_name = formatText($row['schedule_name']);
if ($schedule_name != $prev_schedule) {
if ($prev_schedule != "") echo(" </optgroup>\n");
echo(" <optgroup label='&nbsp;&nbsp;$schedule_name'>\n");
$prev_schedule = $schedule_name;
}
$selected = "";
if ($rnum == $menu_num) $selected = " selected='selected'";
echo(" <option value='$rnum'$selected>$name</option>\n");
}
echo(" </optgroup>\n");
?>
</select>
</td>
</tr>
<tr>
<td colspan='2' align='center'><br></td>
</tr>
<tr>
<td width='30%' align='right' valign='top'><?php displayLanguageText('TEXT-DESTINATION'); ?>: </td>
<td width='70%' align='left' valign='top'>
<input type='radio' name='destination_type' value='Existing' checked='checked' onclick="hideRow('new');"> <?php displayLanguageText('TEXT-EXISTING-MENU'); ?>
<input type='radio' name='destination_type' value='New' onclick="hideRow('existing');"> <?php displayLanguageText('TEXT-NEW-MENU'); ?>
</td>
</tr>
<tr id='existing'>
<td align='right' valign='top'><?php displayLanguageText('TEXT-COPY-TO-EXISTING-MENU'); ?>: </td>
<td align='left' valign='top'>
<select name='menu_num[]' multiple size='10' class='select-width400'>
<?php
$query = "select distinct hlmd.*,hs.schedule_name,hs.schedule_start_date " .
"from hotlunch_menu_dates as hlmd, hotlunch_schedules as hs " .
"where hlmd.school_num = $school_num " .
"and hs.school_num = $school_num " .
"and hs.status NOT IN ('Closed','Deleted') " .
"and hlmd.schedule_num = hs.record_num " .
"and hlmd.schedule_num = $schedule_num " .
$swhere .
"order by hs.schedule_start_date desc,hs.schedule_name,hlmd.sequence,menu_date";
$results = db_query($query);
$prev_schedule = "";
$count = 0;
while ($row = db_fetch_array($results)) {
$name = $row['menu_title'];
$date = date("l F jS, Y",strtotime($row['menu_date']));
$rnum = $row['record_num'];
if ($hotlunch_schedule['display_menu_date'] == 'Y' || $hotlunch_schedule['schedule_type'] == 'Date Sensitive') $name .= " - $date";
// Check if this date is a source date for other menus
$num_menus = db_getVal("SELECT count(*) FROM hotlunch_menu_dates WHERE school_num = $school_num AND source_menu = $rnum");
if ($num_menus > 0) continue;
// Check if this menu has orders
$disabled = "";
$num_orders = db_getVal("SELECT count(*) FROM hotlunch_order_items WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_num = $rnum");
if ($num_orders > 0) $disabled = " disabled";
$schedule_name = $row['schedule_name'];
if ($schedule_name != $prev_schedule) {
if ($prev_schedule != "") echo(" </optgroup>\n");
echo(" <optgroup label='$schedule_name'>\n");
$prev_schedule = $schedule_name;
}
echo(" <option value='$rnum'$disabled>$name</option>\n");
$count++;
}
if ($count == 0) {
echo(" <option value='0'>" . getLanguageText('TEXT-NO-MENUS-AVAILABLE') . "</option>\n");
}
else {
echo(" </optgroup>\n");
}
?>
</select>
</td>
</tr>
<tr id='copy-title'>
<td align='right' valign='top'><?php displayLanguageText('TEXT-MENU-TITLE'); ?>: </td>
<td align='left' valign='top'><?php BuildFileRadio("yn.txt","copy_menu_title",'Y') ?></td>
</tr>
<tr id='new' class='invisible'>
<td align='right' valign='top'><?php displayLanguageText('TEXT-MENU-DATE'); ?>: </td>
<td align='left' valign='top'><input type='text' name='new_menu_date' id='new_menu_date' value='<?php echo(date("Y-m-d",time())) ?>' size='15' class='date-field'></td>
</tr>
<tr id='title' class='invisible'>
<td align='right' valign='top'><?php displayLanguageText('TEXT-MENU-TITLE'); ?>: </td>
<td align='left' valign='top'><input type='text' name='new_menu_title' size='30'></td>
</tr>
<tr>
<td colspan='2' align='center'>
<br>
<p style='width: 400px;'><span class='small'><?php displayLanguageText('TEXT-MENU-LINKING-MSG'); ?><br>
<b><?php displayLanguageText('TEXT-MENU-LINKING-MSG-NOTE'); ?></b></span></p>
</td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-MENU-LINK'); ?>: </td>
<td align='left' valign='top'>
<?php BuildFileRadio("menu_linking.txt","menu_link","No") ?>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<br>
<input type='submit' class='btn btn--primary' value="<?php displayLanguageText('TEXT-COPY-MENU'); ?>">
<input type='hidden' name='action' value='menu-dates'>
<input type='hidden' name='naction' value='copy-menu'>
<input type='hidden' name='schedule_num' value='<?php echo($schedule_num) ?>'>
<br>
<br>
</td>
</tr>
</table>
</form>
<!--
<p><a href='/?action=staff' class='btn btn--primary>'>Staff List</a></p>
-->
<script type="text/javascript">
function hideRow(row) {
if (row == 'existing') {
var row1 = document.getElementById('existing');
var row2 = document.getElementById('copy-title');
var row3 = document.getElementById('new');
var row4 = document.getElementById('title');
row1.className = 'invisible';
row2.className = 'invisible';
<?php if ($hotlunch_schedule['display_menu_date'] == 'Y' || $hotlunch_schedule['schedule_type'] == 'Date Sensitive') { ?>
row3.className = 'visible';
<?php } ?>
row4.className = 'visible';
}
else {
var row1 = document.getElementById('existing');
var row2 = document.getElementById('copy-title');
var row3 = document.getElementById('new');
var row4 = document.getElementById('title');
row1.className = 'visible';
row2.className = 'visible';
<?php if ($hotlunch_schedule['display_menu_date'] == 'Y' || $hotlunch_schedule['schedule_type'] == 'Date Sensitive') { ?>
row3.className = 'invisible';
<?php } ?>
row4.className = 'invisible';
}
}
</script>