Files
HotLunches/hotlunch_orders.form.new.php
T
2026-10-19 15:22:52 -07:00

4050 lines
176 KiB
PHP

<?php
require_once("include/globals.php");
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog("hotlunch_orders.form.new.php");
// if ($school_num == 3) startLog("hotlunch_orders.form.new.php");
// writeLog("School Num: $school_num");
// writeLog(print_r($_GET, true));
// writeLog(print_r($_POST, true));
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier');
if (checkPermission($AllowedUserTypes) == 1) {
include "hotlunch_reports.menu.php";
echo("<br>\n");
}
$userType = "Parent";
if (array_key_exists('type', $_SESSION['UserInfo']) && in_array($_SESSION['UserInfo']['type'],$AllAdminUserTypes)) $userType = "Admin";
//
// Setup defaults for the form
//
$form_width = '98%';
$source = "On-Line";
if (array_key_exists('source',$_GET) && strlen($_GET['source']) > 0) $source = $_GET['source'];
unset($defaultOrder);
if (array_key_exists('defaultOrder', $_GET) && strlen($_GET['defaultOrder']) > 0) $defaultOrder = $_GET['defaultOrder'];
// Get schedule information
$swhere = "";
if ($_SESSION['UserInfo']['type'] == 'Supplier') $swhere = " and supplier_num = " . $_SESSION['UserInfo']['supplier_num'];
$query = "select * from hotlunch_schedules " .
"where school_num = $school_num " .
"and record_num = $schedule_num $swhere";
$results = db_query($query);
if (db_num_rows($results) == 0) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE-NUM');
include "form.messages.php";
return;
}
$schedule_record = db_fetch_array($results);
$schedule_name = $schedule_record['schedule_name'];
$schedule_type = $schedule_record['schedule_type'];
$allow_multiple_orders = $schedule_record['allow_multiple_orders'];
$discount_offered = $schedule_record['discount_offered'];
$discount_type = $schedule_record['discount_type'];
$discount_order_minimum = $schedule_record['discount_order_minimum'];
$discount_expiry_date = $schedule_record['discount_expiry_date'];
$display_menu_date = $schedule_record['display_menu_date'];
$late_charge = $schedule_record['late_charge'];
$late_charge_date = $schedule_record['late_charge_date'];
$last_link_update = $schedule_record['last_link_update'];
$check_for_missed_menus = $schedule_record['check_for_missed_menus'];
$implement_order_notes = $schedule_record['implement_order_notes'];
$order_notes_message = $schedule_record['order_notes_message'];
$implement_order_notes2 = $schedule_record['implement_order_notes2'];
$order_notes_message2 = $schedule_record['order_notes_message2'];
$hide_unavailable_dates = $schedule_record['hide_unavailable_dates'];
$menu_display_mode = $schedule_record['menu_display_mode'];
$calendar_month_breaks = $schedule_record['calendar_month_breaks'];
$display_title_or_label = $schedule_record['display_title_or_label'];
$schedule_prices = $schedule_record['schedule_prices'];
if ($schedule_type == 'Date Sensitive') $display_menu_date = 'Y';
// Determine if there are any discounts defined for this schedule
$today = date("Y-m-d",time());
$numDiscounts = db_getVal("SELECT count(*) FROM hotlunch_schedules_discounts " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND (expiry_date IS NULL OR expiry_date >= '$today') " .
"ORDER BY menu_group,order_quantity");
$discountGroups = array();
if ($numDiscounts > 0) {
$results = db_query("SELECT distinct menu_group " .
"FROM hotlunch_schedules_discounts " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND (expiry_date IS NULL OR expiry_date >= '$today') " .
"ORDER BY menu_group");
while ($row = db_fetch_array($results)) {
$discountGroups[$row['menu_group']] = TRUE;
}
}
// Check if order has already been paid for
$form_edit_mode = "edit";
$form_edit_message = "";
if (array_key_exists('ordered_by_num',$_GET)) $ordered_by_num = intval($_GET['ordered_by_num']);
if (array_key_exists('order_num',$_GET) && $_GET['order_num'] > 0) $order_num = intval($_GET['order_num']);
if (!isset($order_num) && array_key_exists('entered_order_num',$_GET) && $_GET['entered_order_num'] > 0) $order_num = intval($_GET['entered_order_num']);
if (array_key_exists('user_num',$_GET)) {
$user_num = intval($_GET['user_num']);
$userNum = intval($_GET['user_num']);
}
// Setup for parent/student orders
if ($_SESSION['UserInfo']['type'] == 'Parent') {
$user_num = intval($_SESSION['UserInfo']['record_num']);
if (!array_key_exists('student_num', $_GET)) {
startLog("hotlunch_orders.form.new.php");
writeLog("Student Number not set: ".$school_record['school_name']);
writeLog("Student Number not set: $user_num");
$error_message = getLanguageText('ERRORMSG-STUDENT-INFORMATION-MISSING');
header("Location: /?action=students-list&error_message=".urlencode($error_message));
exit();
}
$ordered_by_num = intval($_GET['student_num']);
$ordered_by_type = "Student";
}
// Setup for staff orders
if ($_SESSION['UserInfo']['type'] == 'Staff') {
$user_num = intval($_SESSION['UserInfo']['record_num']);
$ordered_by_type = "Staff";
}
// Setup for Guest orders
if ($_SESSION['UserInfo']['type'] == 'Guest') {
$user_num = intval($_SESSION['UserInfo']['record_num']);
$ordered_by_num = intval($_GET['user_num']);
$ordered_by_type = "Customer";
}
// Get name of person ordering
$menu_price_category = 'Regular';
$access_to_multiple_item_prices = 'N';
if (isset($ordered_by_num) && $ordered_by_num > 3) {
$results = db_query("SELECT * FROM people WHERE record_num = $ordered_by_num");
if (db_num_rows($results)) {
$person = db_fetch_assoc($results);
$name = db_getVal("SELECT concat(first_name,' ',last_name) FROM people WHERE record_num = $ordered_by_num");
$people_type = $person['people_type'];
$access_to_multiple_item_prices = $person['access_to_multiple_item_prices'];
$menu_price_category = db_getVal("SELECT menu_price_category FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num");
if (!isset($menu_price_category) || (isset($menu_price_category) && strlen($menu_price_category) == 0)) $menu_price_category = 'Regular';
if ($ordered_by_type != $people_type) $ordered_by_type = $people_type;
}
else {
$name = '';
$people_type = 'Concession';
$access_to_multiple_item_prices = 'N';
$menu_price_category = 'Regular';
}
}
else {
$name = '';
$people_type = 'Concession';
$access_to_multiple_item_prices = 'N';
$menu_price_category = 'Regular';
}
writeLog("access_to_multiple_item_prices: $access_to_multiple_item_prices");
$category_title = getLanguageText('TEXT-'.strtoupper(str_replace(' ','-',$menu_price_category)));
if (isset($menu_price_category) && $menu_price_category != 'Regular') {
$PageTitle = "$category_title " . getLanguageText('TEXT-ORDER');
$access_to_multiple_item_prices = 'N';
}
// if ($access_to_multiple_item_prices == 'Y') $PageTitle = "$category_title " . getLanguageText('TEXT-FLEX-PRICING');
if ($school_record['special_item_prices'] == 'N') {
$menu_price_category = 'Regular';
}
if ($school_record['implement_multiple_item_prices'] == 'N') {
$access_to_multiple_item_prices = 'N';
}
// Get current user's class_num
$ccnum = 0;
if (isset($ordered_by_num) && $ordered_by_num > 3) $ccnum = db_getVal("SELECT class_num FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num");
unset($query);
$newOrder = 'Y';
$owhere = "";
// If order_num is set then get existing order
if (isset($order_num) && $order_num > 0) {
$owhere = "and order_num = $order_num ";
$query = "select * from hotlunch_order_header " .
"where school_num = $school_num " .
"and record_num = $order_num";
$item_query = "UPDATE hotlunch_order_items SET order_num = $order_num " .
"WHERE school_num = $school_num " .
"AND ordered_by_num = $ordered_by_num " .
"AND schedule_num = $schedule_num " .
"AND order_num = 0";
db_query($item_query);
}
else {
// Otherwise check for an existing order if multiples are not allowed
if ($allow_multiple_orders != 'Y' || $naction != 'add') {
if (isset($ordered_by_num) && $ordered_by_num > 0) {
$order_num = db_getVal("SELECT record_num FROM hotlunch_order_header WHERE school_num = $school_num AND ordered_by_num = $ordered_by_num AND schedule_num = $schedule_num AND status != 'Deleted'");
if (! $order_num) {
$query = "select * from hotlunch_order_header " .
"where school_num = $school_num " .
"and ordered_by_num = $ordered_by_num " .
"and schedule_num = $schedule_num " .
"and status != 'Deleted'";
}
else {
$owhere = "and order_num = $order_num ";
$query = "select * from hotlunch_order_header " .
"where school_num = $school_num " .
"and record_num = $order_num";
}
}
}
}
if (isset($query)) {
$results = db_query($query);
if (db_num_rows($results) > 0) {
$newOrder = 'N';
$header = db_fetch_array($results);
$source = $header['source'];
$status = $header['status'];
$order_num = $header['record_num'];
$ordered_by_num = $header['ordered_by_num'];
$ordered_by_type = $header['ordered_by_type'];
$order_notes = $header['order_notes'];
$order_notes2 = $header['order_notes2'];
$discount_amount = $header['discount_amount'];
$price_category = $header['price_category'];
if ($_SESSION['UserInfo']['type'] == 'System Administrator' || $_SESSION['UserInfo']['type'] == 'SuperUser') echo("<p>Order Number: $order_num</p>\n");
// Get the user_num associated with this person
$user_num = db_getVal("SELECT user_num FROM people WHERE record_num = $ordered_by_num");
// Do not allow editing of Paid orders by default
if ($status == 'Paid' && $school_record['allow_edit_of_paid_orders'] == 'N' && ($schedule_record['edit_paid_orders'] == 'D' || $schedule_record['edit_paid_orders'] == 'N')) {
$form_edit_mode = "review";
$form_edit_message = getLanguageText('MSG-ORDER-PAID');
if (strlen($PageTitle)) $PageTitle .= " - ";
$PageTitle .= getLanguageText('TEXT-REVIEW-ORDER');
}
// Do not allow editing of complimentary orders
if ($status == 'Complimentary' && $school_record['allow_edit_of_complimentary_orders'] != 'Y' && ($schedule_record['edit_complimentary_orders'] == 'D' || $schedule_record['edit_complimentary_orders'] == 'N')) {
$form_edit_mode = "review";
$form_edit_message = getLanguageText('MSG-ORDER-NO-EDIT');
if (strlen($PageTitle)) $PageTitle .= " - ";
$PageTitle .= getLanguageText('TEXT-REVIEW-ORDER');
}
}
}
// If we are past the last date for ordering
$today = date("Y-m-d",time());
$query = "SELECT min(menu_date) FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_type = 'Regular'";
$first_menu_date = db_getVal($query);
$days_prior = $schedule_record['days_prior_to_order_date'];
if ($days_prior == 0 && date("H",time()) >= $schedule_record['order_until_hour']) $days_prior = 1;
$menu_date_cutoff = date("Y-m-d",time() + $days_prior * 60 * 60 * 24 - 60);
// writeLog("days_prior: $days_prior menu_date_cutoff: $menu_date_cutoff");
if ($schedule_record['end_order_datetime'] < $first_menu_date) $menu_date_cutoff = $today;
// writeLog("days_prior: $days_prior menu_date_cutoff: $menu_date_cutoff");
if (strlen($schedule_record['menu_cutoff_date']) && $schedule_record['menu_cutoff_date'] > $today) $menu_date_cutoff = $schedule_record['menu_cutoff_date'];
// writeLog("days_prior: $days_prior menu_date_cutoff: $menu_date_cutoff");
// writeLog("schedule_record['menu_cutoff_date']: ".$schedule_record['menu_cutoff_date']);
$customDateWhere = "";
$dateNow = date("Y-m-d H:i:00",time());
if ($schedule_record['custom_menu_end_dates'] == 'Y') {
$customDateWhere = "AND menu_end_order_datetime > '$dateNow' ";
}
// Ordering ended prior to today
if ($form_edit_mode == "edit" && $schedule_record['end_order_datetime'] < $today) {
$form_edit_mode = "review";
$form_edit_message = "$schedule_name - " . getLanguageText('MSG-ORDER-CUTOFF-DATE') . ' ' . date("l F jS, Y",strtotime($schedule_record['end_order_datetime'])) . ".";
}
$now = date("Y-m-d H:i:s",time());
if ($form_edit_mode == "edit" && $schedule_record['end_order_datetime'] < $now) {
$form_edit_mode = "review";
$form_edit_message = "$schedule_name - " . getLanguageText('MSG-ORDER-CUTOFF-DATE') . ' ' . date("l F jS, Y",strtotime($schedule_record['end_order_datetime'])) . ".";
}
// Unless we are logged in as Admin or HotLunchTeam user
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier');
if (checkPermission($AllowedUserTypes) == 1) {
$form_edit_mode = "edit";
$form_edit_message = "";
}
else {
if ($form_edit_mode == "edit") {
$form_edit_message = "$schedule_name - " . getLanguageText('MSG-ORDER-DATES') . "<br>\n" .
date("l F jS, Y",strtotime($schedule_record['start_order_datetime'])) . " &amp; " .
date("l F jS, Y",strtotime($schedule_record['end_order_datetime'])) . ".";
}
}
db_query("UPDATE hotlunch_menu_dates SET current_menu_link = menu_link WHERE school_num = $school_num AND schedule_num = $schedule_num");
//
// Determine if there are any linked menu dates for this order source
//
$menu_link_code = "('None')";
$linked_items = 'N';
if ($source == 'Paper') {
$num = db_getVal("select count(*) from hotlunch_menu_dates where school_num = $school_num and schedule_num = $schedule_num and menu_link in ('Paper','All') and active != 'N'");
if ($num > 0) {
$linked_items = 'Y';
$menu_link_code = "('Paper','All')";
}
}
if ($source == 'On-Line') {
$num = db_getVal("select count(*) from hotlunch_menu_dates where school_num = $school_num and schedule_num = $schedule_num and menu_link = 'All' and active != 'N'");
if ($num > 0) {
$linked_items = 'Y';
$menu_link_code = "('All')";
}
}
//
// Get volunteer message if required
//
$school_volunteer_signup = $school_record['enable_volunteer_signup'];
$schedule_volunteer_signup = $schedule_record['volunteer_signup'];
// Setup readonly for text fields based on current user type
$readonly_flag = " readonly";
$disabled_flag = " disabled";
if ($linked_items == 'Y') {
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator');
if (checkPermission($AllowedUserTypes) == 1) {
$readonly_flag = "";
$disabled_flag = "";
}
// Update the hotlunch_menu_items table
if ($today > $last_link_update) {
$query = "SELECT menu_date,source_menu,record_num " .
"FROM hotlunch_menu_dates " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"ORDER BY sequence,menu_date";
$menu_dates = db_query($query);
while ($row = db_fetch_array($menu_dates)) {
$mnum = $row['record_num'];
db_query("UPDATE hotlunch_menu_items SET current_source_item = source_item WHERE school_num = $school_num AND menu_num = $mnum");
db_query("UPDATE hotlunch_menu_dates SET current_menu_link = menu_link WHERE school_num = $school_num AND record_num = $mnum");
}
// Now get the set of source menu dates that are prior to the cut off date
$query = "SELECT menu_date,source_menu,record_num " .
"FROM hotlunch_menu_dates " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND (source_menu = 0 OR source_menu IS NULL) " .
"AND menu_date < '$menu_date_cutoff' " .
$customDateWhere .
"ORDER BY sequence,menu_date";
$menu_dates = db_query($query);
if (db_num_rows($menu_dates) > 0) {
while ($row = db_fetch_array($menu_dates)) {
$mnum = $row['record_num'];
$mdate = $row['menu_date'];
$query = "SELECT * FROM hotlunch_menu_dates " .
"WHERE school_num = $school_num " .
"AND source_menu = $mnum " .
"AND menu_date >= '$menu_date_cutoff' " .
$customDateWhere .
"ORDER BY sequence,menu_date";
// writeLog($query);
$results = db_query($query);
$num_menus = db_num_rows($results);
if ($num_menus == 0) continue;
$new_source_menu = db_fetch_array($results);
$new_mnum = $new_source_menu['record_num'];
db_query("UPDATE hotlunch_menu_dates SET current_menu_link = 'No' WHERE school_num = $school_num AND record_num = $new_mnum");
// Get other linked menus if there are any
$other_menus = "";
if ($num_menus > 1) {
while ($row = db_fetch_array($results)) {
if (strlen($other_menus)) $other_menus .= ",";
$other_menus .= $row['record_num'];
}
}
// Get all the menu items for this menu date
$results = db_query("SELECT * FROM hotlunch_menu_items WHERE school_num = $school_num AND menu_num = $new_mnum ORDER BY sequence");
while ($row = db_fetch_array($results)) {
$inum = $row['record_num'];
$snum = $row['source_item'];
// Update other linked menus
if (strlen($other_menus) > 0) {
db_query("UPDATE hotlunch_menu_items SET current_source_item = $inum WHERE school_num = $school_num AND source_item = $snum");
}
// Update the items to be the new source items
db_query("UPDATE hotlunch_menu_items SET current_source_item = 0 WHERE school_num = $school_num AND record_num = $inum");
}
}
}
}
}
// Create a message about the discount
$discount_msg = "";
if (isset($discount_offered) && $discount_offered != 0 && $discount_expiry_date >= $today) {
// $order_total = 0;
// if (isset($ordertotal)) $order_total = $ordertotal;
$discount_msg = getLanguageText('MSG-DISCOUNT-AMOUNT') . ' ';
if ($discount_type == 'Amount') {
$discount_msg .= $currencySymbol . number_format($discount_offered,2);
}
else {
$discount_msg .= number_format($discount_offered,1) . "%";
}
$discount_msg .= " " . getLanguageText('MSG-DISCOUNT-DATE') . ' ' . date("F jS, Y",strtotime($discount_expiry_date));
if (isset($discount_order_minimum) && $discount_order_minimum > 0) {
$discount_msg .= ' ' . getLanguageText('TEXT-OVER') . " $currencySymbol" . number_format($discount_order_minimum,2);
}
}
// Create message about late charges
if (isset($late_charge) && $late_charge > 0) {
if (strlen($discount_msg) > 0) $discount_msg .= "<br>\n";
$discount_msg .= getLanguageText('MSG-LATE-CHARGE') . " $currencySymbol" . number_format($late_charge,2) . " " . getLanguageText('MSG-LATE-CHARGE-DATE') . " " .
date("F jS, Y",strtotime($late_charge_date)) . ".";
$apply_late_charge = 'N';
if ($late_charge_date <= $today) $apply_late_charge = 'Y';
}
// Set flag for concession orders
$concessionOrder = 'N';
if (isset($ordered_by_type) && $ordered_by_type == 'Concession') {
$concessionOrder = 'Y';
}
$viewOptions = "<span id='view-all-options-link'>[".getLanguageText('TEXT-VIEW-ALL-OPTIONS')."]</span>";
$hideOptions = "<span id='hide-all-options-link'>[".getLanguageText('TEXT-HIDE-ALL-OPTIONS')."]</span>";
?>
<script language="JavaScript">
// Function to update the form for checkboxes
function updateCheckboxLine(code, mcode, gcheck, qtest) {
var cbcode = 'cb_'+code+'';
var qtycode = 'qty_' +code+'';
if (document.getElementById(cbcode).checked == true) document.getElementById(qtycode).value = 1;
else document.getElementById(qtycode).value = 0;
updateLine(code, mcode, gcheck, qtest);
}
// Function to update the form totals
function updateLine(code, mcode, gcheck, qtest) {
var qtycode = 'qty_' +code+'';
var qtyfield = 'document.orderform.qty_'+code+'';
var cbfield = 'cb_'+code+'';
var pricefield = 'document.orderform.price_'+code+'';
var altpricefield = 'document.orderform.alt_prices_'+code+'';
var altpricefield_id = '#alt_prices_'+code+'';
var altpricefield_hidden_id = 'alt_prices_hidden_'+code+'';
var minqtyfield = 'document.orderform.minqty_'+code+'';
var warnqtyfield = 'document.orderform.warnqty_'+code+'';
var maxqtyfield = 'document.orderform.maxqty_'+code+'';
var maxqtybyfield = 'document.orderform.maxqty_by_'+code+'';
var familyqtyfield = 'document.orderform.family_qty_'+code+'';
var linetotal = 'document.orderform.ltotal_'+code+'';
var linecount = 'document.orderform.lcount_'+code+'';
var menutotal = 'document.orderform.mtotal_'+mcode+'';
var menucount = 'document.orderform.mcount_'+mcode+'';
var lcodeid = 'ltotal_'+code+'';
var mcodeid = 'mtotal_'+mcode+'';
var lcountid = 'lcount_'+code+'';
var mcountid = 'mcount_'+mcode+'';
var stotal = document.orderform.ordersubtotal.value;
var ototal = document.orderform.ordertotal.value;
var ordered_by_type = document.getElementById('curr_ordered_by_type').value;
const name_field = document.querySelector('input[name="new_first_name"]');
if (name_field != null) {
var new_first_name = document.getElementById('new_first_name').value;
// if (qtest != 'L' && new_first_name.length == 0) {
// alert("<?php displayLanguageText('ERRORMSG-STUDENT-INFORMATION-MISSING'); ?> fn:"+qtest);
// return false;
// }
var new_last_name = document.getElementById('new_last_name').value;
// if (qtest != 'L' && new_last_name.length == 0) {
// alert("<?php displayLanguageText('ERRORMSG-STUDENT-INFORMATION-MISSING'); ?> ln:"+qtest);
// return false;
// }
var parent_first_name = document.getElementById('new_parent_first_name').value;
var parent_last_name = document.getElementById('new_parent_last_name').value;
// if (qtest != 'L' && (parent_last_name.length == 0 || parent_first_name.length == 0)) {
// alert("<?php displayLanguageText('ERRORMSG-PARENT-NAMES-MISSING'); ?>");
// return false;
// }
}
else {
// if (qtest != 'L' && ordered_by_type.length == 0) {
// alert("<?php displayLanguageText('ERRORMSG-STUDENT-INFORMATION-MISSING'); ?>");
// return false;
// }
}
if (document.orderform.discount_amount) var discount = document.orderform.discount_amount.value;
var linespan = 'span_' +code+'';
var menuspan = 'span_' +mcode+'';
ltotal = eval(''+linetotal+'.value');
lcount = eval(''+linecount+'.value');
mtotal = eval(''+menutotal+'.value');
mcount = eval(''+menucount+'.value');
qty = eval(''+qtyfield+'.value');
if (qty.length > 0 && !isInteger(qty)) {
document.getElementById(qtycode).value = '';
alert("<?php displayLanguageText('JAVA-INTEGERS-ONLY'); ?>");
return false;
}
if (gcheck == 'Y') {
groupCheck(code, mcode);
}
qty = eval(''+qtyfield+'.value');
var atest = 'N';
<?php
if ($concessionOrder == 'N') {
?>
maxqty = eval(''+maxqtyfield+'.value');
if (Math.abs(maxqty) > 0 && Math.abs(qty) > Math.abs(maxqty)) {
document.getElementById(qtycode).value = '';
qty = maxqty;
document.getElementById(qtycode).value = qty;
alert("<?php displayLanguageText('JAVA-ORDER-LIMIT') ?> "+maxqty);
}
maxqtyby = eval(''+maxqtybyfield+'.value');
if (Math.abs(maxqty) > 0 && maxqtyby == 'Family') {
familyqty = eval(''+familyqtyfield+'.value');
totalqty = Math.abs(familyqty) + Math.abs(qty);
if (Math.abs(totalqty) > Math.abs(maxqty)) {
document.getElementById(qtycode).value = '';
qty = 0;
document.getElementById(qtycode).value = qty;
alert("++<?php displayLanguageText('JAVA-ORDER-LIMIT') ?> "+maxqty);
}
}
minqty = eval(''+minqtyfield+'.value');
if (Math.abs(minqty) > 0 && Math.abs(qty) < Math.abs(minqty)) {
document.getElementById(qtycode).value = '';
qty = minqty;
document.getElementById(qtycode).value = minqty;
qtyfield.value = minqty;
if (document.getElementById(cbfield)) document.getElementById(cbfield).checked = true;
alert("<?php displayLanguageText('JAVA-MIN-ORDER-LIMIT') ?> "+minqty);
return false;
}
<?php
if ($schedule_record['qty_absolute_limit'] > 0) {
$alimit = $schedule_record['qty_absolute_limit'];
?>
var schedule_limit = <?php echo($alimit) ?>;
var qty_max = schedule_limit;
if (Math.abs(maxqty) > 0) qty_max = maxqty;
if (qtest == 'Y' && Math.abs(qty) > Math.abs(qty_max)) {
document.getElementById(qtycode).value = '';
qty = <?php echo($alimit) ?>;
document.getElementById(qtycode).value = qty;
atest = 'Y';
alert("<?php displayLanguageText('JAVA-ORDER-LIMIT') ?> <?php echo($alimit) ?>");
}
<?php
}
if ($schedule_record['qty_warning_limit'] > 0) {
$wlimit = $schedule_record['qty_warning_limit'];
?>
var schedule_warning_limit = <?php echo($wlimit) ?>;
var qty_warn = schedule_warning_limit;
var item_warning_limit = eval(''+warnqtyfield+'.value');
if (Math.abs(item_warning_limit) > 0) qty_warn = item_warning_limit;
if (qtest == 'Y' && atest == 'N' && Math.abs(qty) >= Math.abs(qty_warn)) {
r = confirm("<?php displayLanguageText('JAVA-ORDER-CONFIRMATION') ?> "+qty+'');
if (r != true) {
document.getElementById(qtycode).value = '';
qty = 0;
}
}
<?php
}
}
?>
price = eval(''+pricefield+'.value');
if (document.querySelector(altpricefield_id) !== null) {
price = eval(''+altpricefield+'.value');
}
if (document.querySelector('#'+altpricefield_hidden_id) != null) {
document.getElementById(altpricefield_hidden_id).value = price;
}
linetotal = qty * price;
if (mtotal > 0) {
menutotal = Math.abs(mtotal - ltotal + linetotal);
}
else {
menutotal = Math.abs(linetotal);
}
menucount = mcount - lcount + qty;
if (stotal > 0) {
ordersubtotal = stotal - mtotal + menutotal;
ordertotal = ototal - mtotal + menutotal;
}
else {
ordersubtotal = menutotal;
ordertotal = menutotal;
}
if (document.getElementById(linespan)) {
document.getElementById(linespan).innerHTML = '';
if (linetotal > 0 || qty > 0) {
document.getElementById(linespan).innerHTML = formatCurrency(linetotal);
}
}
<?php if ($numDiscounts > 0) { ?>
// Calculate the discount amount
calculateDiscount(ordersubtotal);
if (document.getElementById('discount_amount').value) ordertotal = ordersubtotal - document.getElementById('discount_amount').value;
<?php } ?>
if (document.getElementById(menuspan)) document.getElementById(menuspan).innerHTML = formatCurrency(menutotal);
document.getElementById(lcodeid).value = linetotal.toString().replace(/\$|\,/g,'');
document.getElementById(mcodeid).value = menutotal.toString().replace(/\$|\,/g,'');
document.getElementById('orderspan').innerHTML = formatCurrency(ordertotal);
ordersubtotal = formatDecimal(ordersubtotal);
document.getElementById('ordersubtotal').value = ordersubtotal.toString().replace(/\$|\,/g,'');
ordertotal = formatDecimal(ordertotal);
document.getElementById('ordertotal').value = ordertotal.toString().replace(/\$|\,/g,'');
document.getElementById(lcountid).value = qty;
document.getElementById(mcountid).value = menucount;
<?php
//
// Menu items are linked and updated based on source and menu definitions
// - See above for the setting of this value
//
if ($linked_items == 'Y') {
?>
updateLinkedItems(code);
<?php
}
?>
return;
}
//Define function to format a value as currency:
function formatCurrency(num)
{
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '<?php echo($currencySymbol) ?>' + num + '.' + cents);
}
//Define function to format a value as decimal
function formatDecimal(num)
{
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}
// Function to check if a value is an integer
function isInteger(n) {
return (n.toString().search(/^-?[0-9]+$/) == 0);
}
function infoWindow(item) {
var infowin=dhtmlwindow.open("infobox","iframe","info.view.php?item="+item+"","<?php displayLanguageText('TEXT-ADDITIONAL-INFORMATION'); ?>","width=400px,height=300px,resize=1,scrolling=1,center=1");
}
</script>
<noscript>
<p style='background-color: red; color: white;'><br>
<b><?php displayLanguageText('TEXT-JAVASCRIPT-NOT-ENABLED'); ?></b><br>
</p>
<br>
</noscript>
<form method='post' action='/' name='orderform' id='orderform' onSubmit="return checkForm()">
<?php
// Display form_edit_message if there is one
if (strlen($form_edit_message)) {
?>
<table width='<?php echo($form_width) ?>' cellpadding='1' cellspacing='1' border='0' class='big-content-table'>
<tr>
<td align='center' class='warning-span' style='padding: 10px 0;'><b><?php echo($form_edit_message) ?></b></td>
</tr>
</table>
<br>
<?php
}
// If there is a desription for this schedule the display it
if (strlen(trim($schedule_record['description'])) > 0 || $schedule_record['display_instructions'] == 'Y') {
?>
<table width='<?php echo($form_width) ?>' cellpadding='1' cellspacing='1' border='0' class='content-table'>
<tr>
<td align='center'>
<table>
<tr>
<td bgcolor='#ffffff'>
<?php
if (strlen(trim($schedule_record['description'])) > 0) {
if (strip_tags($schedule_record['description']) == $schedule_record['description']) {
echo("<p>" . htmlspecialchars_decode($schedule_record['description']) . "</p>\n");
// echo(htmlspecialchars_decode($row['content'],ENT_QUOTES));
}
else {
echo(nl2br($schedule_record['description']));
}
}
if ($schedule_record['display_instructions'] == 'Y') echo("<p>" . getLanguageText('TEXT-ORDER-INSTRUCTIONS') . "</p>\n");
?>
</tr>
</table>
</td>
</tr>
</table>
<br>
<?php
}
if (isset($defaultOrder) && $defaultOrder == 'Y') $PageTitle .= " (" . getLanguageText('TEXT-GENERATE-ORDERS') . ")";
if ($linked_items == 'Y' && $_SESSION['UserInfo']['type'] == 'SuperUser') {
echo("<span class='yellow'><b>[<a href='#' onclick='updateAllLinkedItems(); document.getElementById(\"orderform\").submit();'>Update Linked and Submit</a>]</b></span><br><br>");
}
if ($_SESSION['UserInfo']['type'] == 'SuperUser') {
echo("<span class='yellow'><b>[<a href='#' onclick='document.getElementById(\"orderform\").submit();'>Submit and Update</a>]</b></span><br><br>");
}
$message_width = $form_width;
include "form.messages.php";
?>
<table width='<?php echo($form_width) ?>' class='content-table'>
<tr>
<td align='center' class='heading'>
<?php echo($PageTitle) ?><br><?php echo($schedule_name) ?>
<?php if ($userType == 'Admin' && $_SESSION['UserInfo']['type'] == 'SuperUser') echo("<br>$viewOptions$hideOptions"); ?>
</td>
</tr>
<tr>
<td align='center'>
<?php
// If there is a discount offered for this schedule then display it
if (isset($discount_msg) && strlen($discount_msg) > 0) echo("<p><b>$discount_msg</b></p>\n");
$tabindex = 1;
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier');
if (checkPermission($AllowedUserTypes) == 1) {
?>
<center>
<table width='60%'cellpadding='1' cellspacing='1' border='0' align='center'>
<?php
if (!isset($ordered_by_num) && (!isset($defaultOrder) || $defaultOrder != 'Y')) {
?>
<tr>
<td align='left'><b><?php displayLanguageText('TEXT-ORDER-FORM'); ?></b></td>
</tr>
<tr>
<td align='left'><?php echo(getLanguageText('TEXT-LAST-NAME')) ?>:<br>
<input type='text' name='new_last_name' id='new_last_name' tabindex=1 value="<?php if (isset($new_last_name)) echo($new_last_name) ?>" size='40'></td>
</tr>
<tr>
<td align='left'>
<div id=studentResultsRow>
<div style="width: 525px; border: 1px solid #000; border-bottom: none; background:#eee;">
<table id=studentResultsHead border=0 cellspacing=0 cellpadding=2>
<tr>
<th align=left><?php echo(getLanguageText('TEXT-NAME')) ?></th>
<th align=left><?php echo(getLanguageText('TEXT-PARENT')) ?></th>
<th align=left><?php echo(getLanguageText('TEXT-PHONE')) ?></th>
<th align=center><?php echo(getLanguageText('TEXT-ORDERED')) ?>?</th>
</tr>
</table>
</div>
<div id=studentResultsScroll style="height:100px; width:525px; overflow:auto; border: 1px solid #000; border-top: none; background:#fff;">
<table id=studentResultsTable border=0 cellspacing=0 cellpadding=2><tr><td></td></tr></table>
</div>
</div>
</td>
</tr>
<tr>
<td align='left'><?php echo(getLanguageText('TEXT-FIRST-NAME')) ?>:<br>
<input type='text' name='new_first_name' id='new_first_name' tabindex=2 value="<?php if (isset($new_first_name)) echo($new_first_name) ?>" size='40'></td>
</tr>
<?php if ($school_record['collect_student_birthdate'] == 'Y') { ?>
<tr>
<td align='left' valign='top'><?php displayLanguageText('TEXT-BIRTH-DATE'); ?>: <br>
<select name='birth_year'>
<?php
$birth_year = date("Y",time()) - 15;
$yr = date("Y",time());
for ($i = 0; $i < 100; $i++) {
$selected = "";
if ($yr == $birth_year) $selected = " selected='selected'";
echo(" <option value='$yr'$selected>$yr</option>\n");
$yr--;
}
?>
</select>
<select name='birth_month'>
<?php
if (isset($birthdate)) $birth_month = substr($birthdate,5,2);
$months = array(getLanguageText('MONTH-JANUARY'),
getLanguageText('MONTH-FEBRUARY'),
getLanguageText('MONTH-MARCH'),
getLanguageText('MONTH-APRIL'),
getLanguageText('MONTH-MAY'),
getLanguageText('MONTH-JUNE'),
getLanguageText('MONTH-JULY'),
getLanguageText('MONTH-AUGUST'),
getLanguageText('MONTH-SEPTEMBER'),
getLanguageText('MONTH-OCTOBER'),
getLanguageText('MONTH-NOVEMBER'),
getLanguageText('MONTH-DECEMBER'));
for ($i = 0; $i < count($months); $i++) {
$num = sprintf("%02d",$i + 1);
$month = $months[$i];
$selected = "";
if (isset($birth_month) && $num == $birth_month) $selected = " selected='selected'";
echo(" <option value='$num'$selected>$month</option>\n");
}
?>
</select>
<select name='birth_day'>
<?php
if (isset($birthdate)) $birth_day = substr($birthdate,8,2);
for ($i = 1; $i <= 31; $i++) {
$selected = "";
if (isset($birth_day) && $i == $birth_day) $selected = " selected='selected'";
echo(" <option value='$i'$selected>$i</option>\n");
}
?>
</select>
</td>
</tr>
<?php } ?>
<?php
if ($school_record['participant_grouping'] != 'None') {
$numClasses = db_getVal("SELECT count(*) FROM classes WHERE school_num = $base_school_num");
if ($numClasses > 0 || $school_record['orders_for'] != 'Registrant') {
?>
<tr>
<td align='left' valign='top'><?php echo($school_record['student_class_text']) ?>:<br>
<select name='new_class_num' id='new_class_num' tabindex=3 class='select-width300'>
<?php
// Get class and teacher information
if ($school_record['i_display_program'] == 'Y') {
$query = "select c.*,program_name,cp.sequence " .
"from classes as c left join class_programs as cp on cp.record_num = class_program " .
"where c.school_num = $base_school_num " .
"order by cp.sequence,c.sequence";
$cresults = db_query($query);
}
else {
$query = "select * from classes " .
"where school_num = $base_school_num " .
"order by sequence";
$cresults = db_query($query);
}
if (db_num_rows($cresults)) {
$prev_program = "none";
while ($crow = db_fetch_array($cresults)) {
if (array_key_exists('program_name', $crow) && strlen($crow['program_name']) > 0 && $prev_program != $crow['program_name']) {
if ($prev_program != "none") echo(" </optgroup>\n");
$title = '';
if (array_key_exists('program_name', $crow)) $title = $crow['program_name'];
$prev_program = $title;
echo(" <optgroup label='$title'>\n");
}
$cnum = $crow['record_num'];
$class_info = getClassInfo($cnum);
$selected = "";
if (isset($class_num) && $cnum == $class_num) $selected = " selected='selected'";
echo(" <option value='$cnum'$selected>$class_info</option>\n");
}
}
// Handle staff people
if ($school_record['registrations_permitted'] == 'Parent' || $school_record['registrations_permitted'] == 'Both') {
$selected = "";
if (isset($class_num) && $class_num == 0) $selected = " selected='selected'";
echo(" <option value='0'$selected>" . $GlobalText['Staff'] . "</option>\n");
}
// Handle customers
if ($school_record['registrations_permitted'] == 'Both') {
$selected = "";
if (isset($class_num) && $class_num == 1) $selected = " selected='selected'";
echo(" <option value='1'$selected>" . getLanguageText('TEXT-CUSTOMER') . "</option>\n");
}
?>
</select>
</td>
</tr>
<?php
}
}
if (!isset($additional_permission_note)) $additional_permission_note = '';
?>
<?php if ($school_record['collect_student_number'] == 'Y') { ?>
<tr>
<td align='left' valign='top'><?php displayLanguageText('TEXT-STUDENT-NUMBER'); ?>: <br>
<input type='text' name='student_number' id='grade' value="<?php if (isset($student_number)) echo($student_number) ?>" size='15'></td>
</tr>
<?php } ?>
<?php if ($school_record['collect_student_birthdate'] == 'Y') { ?>
<tr>
<td align='left' valign='top'><?php displayLanguageText('TEXT-BIRTH-DATE'); ?>: <br>
<input type='text' name='birthdate' id='birthdate' value='<?php if (isset($birthdate)) echo($birthdate) ?>' size='20'></td>
</tr>
<?php } ?>
<?php if ($school_record['collect_student_age'] == 'Y') { ?>
<tr>
<td align='left' valign='top'><?php displayLanguageText('TEXT-AGE'); ?>: <br>
<td align='left' valign='top'><input type='text' name='age' id='age' value='<?php if (isset($age)) echo($age) ?>' size='5'></td>
</tr>
<?php } ?>
<?php
if ($school_record['collect_student_sex'] == 'Y') {
if (!isset($sex)) $sex = '';
?>
<tr>
<td align='left' valign='top'><?php displayLanguageText('TEXT-SEX'); ?>: <br>
<select name='sex' id='sex'>
<?php BuildFileList("sex.txt",$sex); ?>
</select>
</td>
</tr>
<?php } ?>
<?php if ($school_record['collect_student_grade'] == 'Y') { ?>
<tr>
<td align='left' valign='top'><?php displayLanguageText('TEXT-GRADE'); ?>: <br>
<input type='text' name='school_grade' id='grade' value="<?php if (isset($school_grade)) echo($school_grade); ?>" size='5'></td>
</tr>
<?php } ?>
<?php if ($school_record['collect_permission'] == 'Y' || $school_record['collect_permission'] == 'W') { ?>
<tr>
<td align='left' valign='top'><br>
<?php echo($school_record['permission_prompt']); ?>: <br>
<?php BuildFileRadio("yn.txt","additional_permission",'N') ?><br>
<?php if ($school_record['collect_permission'] == 'W') { ?>
<input type='text' name='additional_permission_note' value="<?php echo($additional_permission_note) ?>" size='30'><br>
<?php } ?>
<?php if (strlen(trim($school_record['permission_description']))) echo("<span class='small'>" . nl2br(trim($school_record['permission_description'])) . "</span>") ?>
<br>
</td>
</tr>
<?php } ?>
<?php if ($school_record['user_defined_values'] == 'Y' && strlen($school_record['user_defined_title']) > 0) { ?>
<tr>
<td align='left' valign='top'><?php echo($school_record['user_defined_title']); ?>: <br>
<input type='text' name='user_defined_value' id='user_defined_value' value="<?php if (isset($user_defined_value)) echo($user_defined_value) ?>" size='20'></td>
</tr>
<?php } ?>
<tr>
<td align='left'><?php displayLanguageText('TEXT-PARENT-NAME'); ?>:<br>
<input type='text' name='new_parent_last_name' id='new_parent_last_name' tabindex=4 value="<?php if (isset($new_parent_last_name)) echo($new_parent_last_name) ?>" size='40'></td>
</tr>
<tr>
<td align='left'>
<div id=parentResultsRow>
<div style="width: 525px; border: 1px solid #000; border-bottom: none; background:#eee;">
<table id=parentResultsHead border=0 cellspacing=0 cellpadding=2>
<tr>
<th align=left><?php displayLanguageText('TEXT-ACCOUNT'); ?></th>
<th align=left><?php displayLanguageText('TEXT-NAME'); ?></th>
<th align=left><?php displayLanguageText('TEXT-EMAIL'); ?></th>
</tr>
</table>
</div>
<div id=parentResultsScroll style="height:100px; width:525px; overflow:auto; border: 1px solid #000; border-top: none; background:#fff;">
<table id=parentResultsTable border=0 cellspacing=0 cellpadding=2><tr><td></td></tr></table>
</div>
</div>
</td>
</tr>
<tr>
<td align='left'><?php displayLanguageText('TEXT-PARENT-FIRST-NAME'); ?>:<br>
<input type='text' name='new_parent_first_name' id='new_parent_first_name' tabindex=5 value="<?php if (isset($new_parent_first_name)) echo($new_parent_first_name) ?>" size='40'></td>
</tr>
<tr>
<td align='left' valign='top'><?php displayLanguageText('TEXT-EMAIL'); ?>:<br>
<input type='text' name='new_email' id='new_email' tabindex=6 value="<?php if (isset($new_email)) echo($new_email) ?>" size='50'><br>
<span class='small'><?php displayLanguageText('MSG-LEAVE-EMAIL-BLANK'); ?></span>
</td>
</tr>
<tr>
<td align='left'><?php displayLanguageText('TEXT-HOME-PHONE'); ?>:<br>
<input type='text' name='new_phone' id='new_phone' tabindex=7 value='<?php if (isset($new_phone)) echo($new_phone) ?>' size='15'></td>
</tr>
<tr id=contactInfoRow>
<td align='left'><?php displayLanguageText('TEXT-CONTACT-INFORMATION'); ?>:<br>
<input type='radio' name='display_contact_info' tabindex=8 value='Y' checked='checked'> <?php displayLanguageText('TEXT-YES'); ?>
<input type='radio' name='display_contact_info' tabindex=9 value='N'> <?php displayLanguageText('TEXT-NO'); ?>
</td>
</tr>
<?php
}
?>
</table>
</center>
<br>
<?php
$tabindex = 10;
}
if (isset($name) && strlen($name) > 0) echo("<p><b>$name</b></p>\n");
// Set name title for Concession Order
$display_current_totals = 'N';
$concessionOrder = 'N';
if (isset($ordered_by_type) && $ordered_by_type == 'Concession') {
echo("<p><b>".getLanguageText('TEXT-CONCESSION-ORDER')."</b></p>\n");
$display_current_totals = 'Y';
$concessionOrder = 'Y';
}
//
// Menu Dates Array
//
$MenuDates = array();
$CurrentDates = array();
// Get menu dates for this schedule
$query = "select * from hotlunch_menu_dates " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and active != 'N' " .
"order by sequence,menu_date";
// writeLog($query);
$menu_dates = db_query($query);
$ordertotal = '0';
$global_code = "";
$menu_items_code = "";
$all_menu_items_code = "";
$menu_options_code = "";
$group_check_code = "";
$group_complete_code = "";
$form_check_code = "";
$discount_code = "";
$groupQtyFields = array();
$groupCodes = array('A','B','C','D','E','F','G','H','I','J','K','L','M');
$otipSpans = "";
$nutrition_spans = "";
$image_spans = "";
// writeLog("SELECT min(menu_date) FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $schedule_num AND active != 'N' AND menu_type = 'Regular'");
$firstMenuDate = db_getVal("SELECT min(menu_date) FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $schedule_num AND active != 'N' AND menu_type = 'Regular' AND menu_date IS NOT NULL");
// writeLog("firstMenuDate: $firstMenuDate");
// writeLog("SELECT max(menu_date) FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $schedule_num AND active != 'N' AND menu_type = 'Regular'");
$lastMenuDate = db_getVal("SELECT max(menu_date) FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $schedule_num AND active != 'N' AND menu_type = 'Regular'");
// writeLog("lastMenuDate: $lastMenuDate");
while ($mdate = db_fetch_array($menu_dates)) {
$menu_num = $mdate['record_num'];
$menu_code = $schedule_num . "_" . $menu_num;
$menu_title = $mdate['menu_title'];
$menu_link = $mdate['menu_link'];
$menu_link = $mdate['current_menu_link'];
$menu_date = $mdate['menu_date'];
$menu_type = $mdate['menu_type'];
$menu_instructions = $mdate['menu_instructions'];
$volunteer_msg = $mdate['volunteer_msg'];
$menu_available = $mdate['available'];
// writeLog("menu_num: $menu_num\n");
// writeLog("menu_date: $menu_date\n");
// Check if this student can order in this menu
if ($ccnum > 0 && isset($ordered_by_type) && $ordered_by_type == 'Student' && isset($ordered_by_num) && $ordered_by_num > 3) {
$query = "SELECT count(*) FROM hotlunch_menu_dates_classes WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_num = $menu_num";
$sclasses = db_getVal($query);
if ($sclasses > 0) {
$query = "SELECT count(*) FROM hotlunch_menu_dates_classes WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_num = $menu_num AND class_num = $ccnum";
$access = db_getVal($query);
if (($_SESSION['UserInfo']['type'] == 'Parent' || $_SESSION['UserInfo']['type'] == 'Staff') && $access == 0) continue;
}
}
// if ($menu_type != 'Footer') {
// if ($firstMenuDate == 0) $firstMenuDate = $menu_date;
// $lastMenuDate = $menu_date;
// }
// else {
// $menu_date = $lastMenuDate;
// }
if (isset($menu_type) && $menu_type == 'Footer') $menu_date = $lastMenuDate;
$menuDateActive = 'Y';
$rowStyle = "";
$volunteer_signup = 'N';
if ($school_volunteer_signup == 'Y') {
$maxVolunteers = $school_record['max_volunteers'];
$volunteerMessage = $school_record['default_volunteer_message'];
if (strlen($schedule_record['schedule_volunteer_message']) > 0) $volunteerMessage = $schedule_record['schedule_volunteer_message'];
$volunteer_signup = 'Y';
}
if ($schedule_volunteer_signup == 'Y') {
$maxVolunteers = $schedule_record['max_volunteers'];
$volunteer_signup = 'Y';
}
if (strlen($schedule_record['schedule_volunteer_message']) > 0) $volunteerMessage = $schedule_record['schedule_volunteer_message'];
if ($schedule_volunteer_signup == 'N') {
$volunteer_signup = 'N';
}
if ($mdate['num_volunteer_override'] == 'Y') {
$maxVolunteers = $mdate['max_volunteers'];
$volunteer_signup = 'Y';
}
if (strlen($mdate['volunteer_msg']) > 0) $volunteerMessage = $mdate['volunteer_msg'];
if ($mdate['num_volunteer_override'] == 'N') {
$volunteer_signup = 'N';
}
// Handle linked child items if the field needs to be readonly based on the menu_link
$readonly = "";
$disabled = "";
$linkedMenu = false;
if (($menu_link == 'Paper' && $source == 'Paper') || $menu_link == 'All') {
if ($schedule_record['edit_linked_menus'] == 'N') {
$readonly = $readonly_flag;
$disabled = $disabled_flag;
$linkedMenu = true;
writeLog("disabled_flag: $disabled_flag - linked Menu");
}
}
// Set class for menu header
$tclass = 'menudate-header';
// Get menu items for this menu date
$active_menu_items = array();
$currentMenuItems = array();
$query = "select * from hotlunch_menu_items " .
"where school_num = $school_num " .
"and menu_num = $menu_num " .
"AND active != 'N' " .
"order by sequence";
$menu_items = db_query($query);
while ($menu_item = db_fetch_array($menu_items)) {
extract($menu_item);
// Check if this student can order in this menu item
if ($ccnum > 0 && $ordered_by_type == 'Student' && isset($ordered_by_num) && $ordered_by_num > 3) {
$sclasses = db_getVal("SELECT count(*) FROM hotlunch_menu_items_classes WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_num = $menu_num AND menu_item_num = $record_num");
if ($sclasses > 0) {
$access = db_getVal("SELECT count(*) FROM hotlunch_menu_items_classes WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_num = $menu_num AND menu_item_num = $record_num AND class_num = $ccnum");
if (($_SESSION['UserInfo']['type'] == 'Parent' || $_SESSION['UserInfo']['type'] == 'Staff') && $access == 0) continue;
}
}
$active_menu_items[] = $record_num;
$currentMenuItems[] = $menu_item;
}
$iwhere = "";
if (count($active_menu_items)) {
$activeMenuItems = implode(",",$active_menu_items);
$iwhere = "AND record_num IN ($activeMenuItems) ";
}
$numItems = count($active_menu_items);
if ($numItems == 0) $tclass = 'menudate-noitems';
// Adjust title if date is in the past
if ($schedule_type == 'Hot Lunch' || $schedule_type == 'Date Sensitive') {
if ($form_edit_mode == 'edit') {
// writeLog("menu_date: $menu_date menu_date_cutoff: $menu_date_cutoff");
// writeLog("menuDateActive: $menuDateActive");
if ($menu_date < $menu_date_cutoff) $menuDateActive = 'N';
// writeLog("menuDateActive: $menuDateActive");
// writeLog("schedule_record['custom_menu_end_dates']: ".$schedule_record['custom_menu_end_dates']);
// writeLog("mdate['menu_end_order_datetime'] :".$mdate['menu_end_order_datetime']);
// writeLog("dateNow: $dateNow");
if ($schedule_record['custom_menu_end_dates'] == 'Y' && $mdate['menu_end_order_datetime'] < $dateNow) $menuDateActive = 'N';
// writeLog("menuDateActive: $menuDateActive");
if ($menuDateActive == 'N' || $menu_available == 'N') {
$tclass = 'menudate-past';
if ($_SESSION['UserInfo']['type'] == 'Parent' || $_SESSION['UserInfo']['type'] == 'Staff' || $_SESSION['UserInfo']['type'] == 'Guest') {
$menu_title .= " - " . getLanguageText('TEXT-NOT-AVAILABLE-AT-THIS-TIME');
if ($hide_unavailable_dates == 'Y') $rowStyle = " style='display: none;'";
}
}
}
}
//
// Save menu date information
//
if (in_array($siteType,array('hotlunch','fundraising'))) $menuDate = $mdate['menu_date'];
else $menuDate = $mdate['menu_date'] . "." . $menu_num;
// writeLog(print_r($mdate, true));
$MenuDates[$menu_num]['menu_date'] = $mdate['menu_date'];
$MenuDates[$menu_num]['menu_type'] = $mdate['menu_type'];
$MenuDates[$menu_num]['rowStyle'] = $rowStyle;
$MenuDates[$menu_num]['tclass'] = $tclass;
$MenuDates[$menu_num]['menu_title'] = $menu_title;
$MenuDates[$menu_num]['display_menu_date'] = $display_menu_date;
$MenuDates[$menu_num]['menu_instructions'] = $menu_instructions;
$MenuDates[$menu_num]['menu_active'] = $menuDateActive;
// Get menu items for this menu date
$query = "select * from hotlunch_menu_items " .
"where school_num = $school_num " .
"and menu_num = $menu_num " .
"AND active != 'N' " .
$iwhere .
"order by sequence";
$menu_items = db_query($query);
// Determine if groups are in use in this menu
$groupCount = db_getVal("SELECT count(*) FROM hotlunch_menu_items " .
"WHERE school_num = $school_num " .
"AND menu_num = $menu_num " .
"AND active != 'N' " .
"AND menu_group IN ('A','B','C','D','E','F','G','H','I','J','K','L','M')");
$group_items = array();
$groupLimits = array();
$menu_total = '0';
$menu_count = 0;
$item_count = 0;
unset($MenuItems);
$MenuItems = array();
$MenuItemCount = 0;
$LastHeadingClass = '';
while ($menu_item = db_fetch_array($menu_items)) {
extract($menu_item);
$menuItemFormat = 'Checkbox';
if ((($mdate['order_format'] != 'Checkbox' || $menu_item_format == 'Q') && $menu_item_format != 'C') || $concessionOrder == 'Y') $menuItemFormat = 'Quantity';
$readonly = "";
if ($item_type == 'Heading') {
$LastHeadingClass = "header-$record_num";
if ($heading_visibility == 'hidden') $LastHeadingClass .= " hidden-item";
$heading_class = "";
}
else {
$heading_class = $LastHeadingClass;
}
$curr_item_num = $record_num;
$curr_code = $schedule_num . "_" . $menu_num . "_" . $curr_item_num;
$qtyfield = "qty_$curr_code";
$qtyfielda = "qtya_$curr_code";
$cbfield = "cb_$curr_code";
$titlefield = "title_$curr_code";
$pricefield = "price_$curr_code";
$linespan = "span_$curr_code";
$linetotal = "ltotal_$curr_code";
$linecount = "lcount_$curr_code";
$minqty = "minqty_$curr_code";
$warnqty = "warnqty_$curr_code";
$maxqty = "maxqty_$curr_code";
$maxqty_by = "maxqty_by_$curr_code";
$family_qty = "family_qty_$curr_code";
// Save qty field to groupQtyFields array for later processing
if ($item_type != 'Heading' && array_key_exists('Any',$discountGroups)) $groupQtyFields['Any'] .= " $qtyfield";
for ($i = 0; $i < count($groupCodes); $i++) {
$gCode = $groupCodes[$i];
if ($item_type != 'Heading' && array_key_exists($gCode,$discountGroups)) $groupQtyFields[$gCode] .= " $qtyfield";
}
if (strlen(trim($label_title)) == 0) $label_title = $item_title;
if ($display_title_or_label == 'Title') $label_title = $item_title;
$MenuItems[$MenuItemCount]['item_type'] = $item_type;
if ($item_type != 'Heading') {
// Format tips for "Form" display mode
if ($menu_display_mode == 'Form') {
// Display nutritional information icon if data exists
$nutrition_image = "";
if (strlen(trim($nutritional_info)) > 0) {
$span_id = "nut_span$curr_item_num";
$nutrition_icon = "<img src='images/icons/infoabout16.png' alt='" . getLanguageText('TEXT-ADDITIONAL-INFORMATION') . "' title='" . getLanguageText('TEXT-ADDITIONAL-INFORMATION') . "' hspace='0' border='0'>";
$otipSpans .= "<span id='$span_id'>" . sprintf($otipNUTRITION,nl2br($nutritional_info)) . "</span>\n";
$nutrition_image = "&nbsp;&nbsp;<a href=\"javascript:TagToTip('$span_id',BGCOLOR,'#FFFFFF')\" onmouseover=\"TagToTip('$span_id',BGCOLOR,'#FFFFFF')\" onmouseout=\"UnTip()\">$nutrition_icon</a> ";
}
// Process the BC Food Guidelines icons
$rating_image = "";
$rating_icon = "<img src='images/icons/accept16.png' alt='Choose $bc_guideline_rating' title='Choose $bc_guideline_rating' hspace='0'>";
if ($school_record['display_bc_food_guidelines'] == 'Y') {
if ($bc_guideline_rating == 'Sometimes') $rating_image = " $rating_icon ";
if ($bc_guideline_rating == 'Most') $rating_image = " <nobr>" . $rating_icon . $rating_icon . "</nobr>";
}
// Handle item image
$image_link = "";
if (strlen($image) > 0 && is_file("$imagedir/$image")) {
$image_icon = "<img src='images/icons/pictures16.png' alt='Item Image' title='Item Image' hspace='5' border='0' align='right'>";
$ic = explode('.',$image);
$iname = "";
$ext = $ic[count($ic) - 1];
for ($i = 0; $i < count($ic) - 1; $i++) {
if (strlen($iname)) $iname .= ".";
$iname .= $ic[$i];
}
$image_size = GetImageSize("$imagedir/$image");
$image_width = $image_size[0];
$image_height = $image_size[1];
$thumbnail = $iname."-tn.".$ext;
if ($schedule_record['display_product_thumbnail'] == 'Y') {
if (!is_file("$imagedir/$thumbnail")) {
$img = createThumbnail($image, $imagedir);
}
$image_size = GetImageSize("$imagedir/$thumbnail");
$image_width = $image_size[0];
$image_height = $image_size[1];
$image_icon = "<img src='$imageurl/$thumbnail' alt='Item Image' title='Item Image' hspace='5' border='0' width='$image_width' height='$image_height' align='right'>";
}
if ($image_width >= $image_height) {
if ($image_width > $maxImageDimension) {
$image_height = intval($image_height * $maxImageDimension / $image_width);
$image_width = $maxImageDimension;
}
}
else {
if ($image_height > $maxImageDimension) {
$image_width = intval($image_width * $maxImageDimension / $image_height);
$image_height = $maxImageDimension;
}
}
$span_id = "img_span$curr_item_num";
$otipSpans .= "<span id='$span_id'>" . sprintf($otipIMG,"$imageurl/$image",$image_height,$image_width,$item_title) . "</span>\n";
$image_link = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$image_icon</a>";
}
}
// Setup prices
$item_price = $offline_price;
if ($source == 'On-Line') $item_price = $online_price;
// Use Special Prices if required
if ($school_record['special_item_prices'] == 'Y') {
if ($menu_price_category == 'Special 1') $item_price = $special_price1;
if ($menu_price_category == 'Special 2') $item_price = $special_price2;
if ($menu_price_category == 'Special 3') $item_price = $special_price3;
}
if (strlen($item_price) == 0) $item_price = "0.00";
$selected_item_price = $item_price;
// Format tips for "Calendar" display mode
if ($menu_display_mode == 'Calendar' || $menu_display_mode == 'Calendar No Weekends') {
$iTitle = "<b>&nbsp;-&nbsp;$item_title</b>";
if ($display_price != 'N') $iTitle .= " - <span class='price-tip'>&nbsp;&nbsp;$currencySymbol$item_price&nbsp;&nbsp;</span>";
$iTitle .= "<br>\n";
if (strlen($item_description)) $iTitle .= " -- $item_description<br>\n";
if ($taxable_item == 'Y') $iTitle .= " -- " . getLanguageText('TEXT-TAXABLE') . "<br>\n";
// Format nutritional info
if (strlen(trim($nutritional_info))) $nutritional_info = "<br>\n" . nl2br(trim($nutritional_info));
// Include image if there is one
$iImage = "<br><br>";
if (strlen($image) > 0 && is_file("$imagedir/$image")) {
$image_size = GetImageSize("$imagedir/$image");
$image_width = $image_size[0];
$image_height = $image_size[1];
if ($image_width >= $image_height) {
if ($image_width > $maxImageDimension) {
$image_height = intval($image_height * $maxImageDimension / $image_width);
$image_width = $maxImageDimension;
}
}
else {
if ($image_height > $maxImageDimension) {
$image_width = intval($image_width * $maxImageDimension / $image_height);
$image_height = $maxImageDimension;
}
}
$image = urlencode($image);
$iImage = "<br>\n<center>" . sprintf($otipIMG,"$imageurl/$image",$image_height,$image_width,$item_title) . "</center>";
}
$mtitle = "";
if (strlen($menu_title)) $mtitle = "<span class='title-tip'>&nbsp;&nbsp;&nbsp;$menu_title&nbsp;&nbsp;&nbsp;&nbsp;</span><br>\n";
// Process the BC Food Guidelines icons
$rating_image = "";
$rating_icon = "<img src='images/icons/accept16.png' alt='Choose $bc_guideline_rating' title='Choose $bc_guideline_rating' hspace='0'>";
if ($school_record['display_bc_food_guidelines'] == 'Y') {
if ($bc_guideline_rating == 'Sometimes') $rating_image = " $rating_icon ";
if ($bc_guideline_rating == 'Most') $rating_image = " <nobr>" . $rating_icon . $rating_icon . "</nobr>";
}
$span_id = "info_span$curr_item_num";
if ($menu_available != 'N') {
$otipSpans .= "<span id='$span_id' class='info-span'>" .
sprintf($otipNUTRITION,$mtitle . $iTitle . $nutritional_info) .
$iImage .
"</span>\n";
}
else {
$msg = "<span class='error'>" . getLanguageText('TEXT-NOT-AVAILABLE') . "</span><br>";
$otipSpans .= "<span id='$span_id'>" .
sprintf($otipNUTRITION,$msg . $mtitle . $iTitle . $nutritional_info) .
$iImage .
"</span>\n";
}
$label_title = "<a href=\"javascript:TagToTip('$span_id',BGCOLOR,'#FFFFFF')\" onmouseover=\"TagToTip('$span_id',BGCOLOR,'#FFFFFF')\" onmouseout=\"UnTip()\" " .
"class='menu-item-title' menu-num='$menu_num' item-num='$curr_item_num'>$label_title</a>";
}
$qtyvalue = '';
$line_total = '0';
$item_options_ordered = array();
$item_options2_ordered = array();
$item_options3_ordered = array();
$actual_price = $item_price;
$selected_item_price = $item_price;
$options_ordered = '';
$options2_ordered = '';
$options3_ordered = '';
// Check if there is an order for this item for this person
if (isset($ordered_by_num) && $newOrder != 'Y') {
$query = "select * from hotlunch_order_items " .
"where school_num = $school_num " .
"and ordered_by_num = $ordered_by_num " .
"and schedule_num = $schedule_num " .
$owhere .
"and menu_num = $menu_num " .
"and menu_item_num = $curr_item_num " .
"and active != 'N'";
$orders = db_query($query);
if (db_num_rows($orders) > 0) {
$order = db_fetch_array($orders);
$qtyvalue = $order['qty'];
$options_ordered = $order['options_ordered'];
$options2_ordered = $order['options2_ordered'];
$options3_ordered = $order['options3_ordered'];
if (strlen($options_ordered) > 0) $item_options_ordered = explode("\n",trim($options_ordered));
if (strlen($options2_ordered) > 0) $item_options2_ordered = explode("\n",trim($options2_ordered));
if (strlen($options3_ordered) > 0) $item_options3_ordered = explode("\n",trim($options3_ordered));
// $item_price = $order['menu_item_price'];
$selected_item_price = $order['menu_item_price'];
writeLog("selected_item_price: $selected_item_price");
writeLog("item_price: $item_price");
writeLog("number_of_alternate_prices: $number_of_alternate_prices");
if ($_SESSION['UserInfo']['type'] == 'SuperUser' && $number_of_alternate_prices == 0 && $selected_item_price != $item_price) {
$selected_item_price = floatval($item_price);
$rnum = $order['record_num'];
$query = "UPDATE hotlunch_order_items SET menu_item_price = $selected_item_price WHERE school_num = $school_num AND record_num = $rnum";
writeLog($query);
db_query($query);
}
$ltotal = $qtyvalue * $selected_item_price;
$line_total = number_format($ltotal,2);
$menu_total += $ltotal;
$menu_count += $qtyvalue;
$ordertotal += $ltotal;
}
}
else {
if (isset($_POST["qty_$curr_code"])) $qtyvalue = $_POST["qty_$curr_code"];
if ($min_quantity > 0 && $qtyvalue == 0) $qtyvalue = $min_quantity;
$ltotal = intval($qtyvalue) * floatval($item_price);
$line_total = number_format($ltotal,2);
$menu_total += $ltotal;
$menu_count += intval($qtyvalue);
$ordertotal += $ltotal;
}
// Handle dates that have passed for parents
if ($_SESSION['UserInfo']['type'] == 'Parent' || $_SESSION['UserInfo']['type'] == 'Staff') {
if ($form_edit_mode == 'edit' && $menuDateActive == 'N') {
$readonly = $readonly_flag;
$disabled = $disabled_flag;
writeLog("disabled_flag: $disabled_flag - Menu Inactive");
}
}
// Handle item options
$options_count_code = "";
$options_code = "";
$optionsArray = array();
$hasOptions = 'N';
$hasOptionsOrdered = 'N';
if (strlen(trim($options)) > 0) $hasOptions = 'Y';
if (strlen(trim($options2)) > 0) $hasOptions = 'Y';
if (strlen(trim($options3)) > 0) $hasOptions = 'Y';
if (strlen($options_ordered) > 0) $hasOptionsOrdered = 'Y';
if (strlen($options2_ordered) > 0) $hasOptionsOrdered = 'Y';
if (strlen($options3_ordered) > 0) $hasOptionsOrdered = 'Y';
echo("<!-- $options_ordered :: $options2_ordered :: $options2_ordered -->\n");
echo("<input type='hidden' id='has-options-$curr_item_num' value='$hasOptions'>\n");
echo("<input type='hidden' id='has-options-ordered-$curr_item_num' value='$hasOptionsOrdered'>\n");
for ($set = 0; $set <= 2; $set++) {
switch ($set) {
case 0:
$optionsTitle = $options_title;
$itemOptions = $options;
if (strlen($itemOptions)) {
$defaultOptions = $default_options;
$orderedOptions = $item_options_ordered;
$minOptions = $min_options;
$maxOptions = $max_options;
$ext = "";
$options_code .= "<input type='hidden' id='set-$curr_item_num-$set' value='0'>\n";
$options_code .= "<input type='hidden' id='title-$curr_item_num-$set' value='$options_title'>\n";
}
break;
case 1:
$optionsTitle = $options2_title;
$itemOptions = $options2;
if (strlen($itemOptions)) {
$defaultOptions = $default_options2;
$orderedOptions = $item_options2_ordered;
$minOptions = $min_options2;
$maxOptions = $max_options2;
$ext = "2";
$options_code .= "<input type='hidden' id='set-$curr_item_num-$set' value='0'>\n";
$options_code .= "<input type='hidden' id='title-$curr_item_num-$set' value='$options2_title'>\n";
}
break;
case 2:
$optionsTitle = $options3_title;
$itemOptions = $options3;
if (strlen($itemOptions)) {
$defaultOptions = $default_options3;
$orderedOptions = $item_options3_ordered;
$minOptions = $min_options3;
$maxOptions = $max_options3;
$ext = "3";
$options_code .= "<input type='hidden' id='set-$curr_item_num-$set' value='0'>\n";
$options_code .= "<input type='hidden' id='title-$curr_item_num-$set' value='$options3_title'>\n";
}
break;
}
$itemOptions = trim($itemOptions);
$slen = strlen($itemOptions);
writeLog("itemOptions: $itemOptions $slen ++++");
if (strlen($itemOptions) > 0) {
$item_options = explode("\n",$itemOptions);
$default_options_array = array();
if (strlen(trim($defaultOptions))) $default_options_array = explode("\n",trim($defaultOptions));
for ($o = 0; $o < count($default_options_array); $o++) { $default_options_array[$o] = trim($default_options_array[$o]); }
if ($menu_display_mode == 'Form' || $set > 0) $options_code .= "<br>\n";
if (strlen($optionsTitle)) $options_code .= "<span class='options$ext'><b>$optionsTitle</b>:</span><br>";
// $optionsText = "$optionsTitle: ";
if ($form_edit_mode != 'review') {
// Build menu options code string
$menu_options_code .= " if (code == '$curr_code') {\n";
$menu_options_code .= " var qtyfield = 'qty_'+code+'';\n";
$menu_options_code .= " var cbfield = 'cb_'+code+'';\n";
if ($menuDateActive == 'Y') {
$menu_options_code .= " if (document.getElementById(sname).checked && ! document.getElementById(qtyfield).value) {\n";
$menu_options_code .= " document.getElementById(qtyfield).value = 1;\n";
$menu_options_code .= " if (document.getElementById(cbfield)) document.getElementById(cbfield).checked = true;\n";
$menu_options_code .= " }\n\n";
}
// Handle limits on the number of options selected
if ($maxOptions > 0 || $minOptions > 0) {
$numOptions = count($orderedOptions);
$global_code .= " var ocount$ext" . "_$curr_code = $numOptions;\n";
$menu_options_code .= " ocount$ext" . "_$curr_code = 0;\n";
$options_count_code .= " ocount$ext" . "_$curr_code = 0;\n";
}
$num_options = count($item_options);
for ($i = 0; $i < count($item_options); $i++) {
$option = trim($item_options[$i]);
$optionsArray[] = array($option,$ext);
if (strlen($option) > 0) $checked = "";
if (in_array($option,$orderedOptions)) $checked = " checked='checked'";
if ($newOrder == 'Y' && in_array($option,$default_options_array)) $checked = " checked='checked'";
$option_f = str_replace(" ","_",substr($option,0,30));
$option_f = str_replace("&","and",$option_f);
$option_f = preg_replace("/[^a-zA-Z0-9_]/","",$option_f);
$sname = "option{$ext}_$curr_code" . "_$option_f";
// $options_code .= "<br>";
writeLog("disabled: $disabled");
if ($disabled != $disabled_flag || strlen($disabled_flag) == 0) {
$optClass = "option-$curr_item_num-$set";
$options_code .= "<span class='menu-item-option options$ext' item_num='$curr_item_num' cbid='$sname' opt_set='$set' set_max='$maxOptions' set_min='$minOptions'>" .
"<input type='checkbox' name='$sname' id='$sname' inum='$curr_item_num' optionf='$option_f' class='item-option $current_source_item $option_f $optClass' value='Y' " .
"opt_set='$set' set_max='$maxOptions' curr-code='$curr_code' menu-code='$menu_code' " .
"onChange=\"checkOptions('$curr_code','$menu_code','$sname');\"$checked>&nbsp;";
if ($menu_display_mode == 'Calendar' || $menu_display_mode == 'Calendar No Weekends') {
$options_code .= "<span class='item-option-calendar-span' inum='$curr_item_num' cbid='$sname' opt_set='$set' set_max='$maxOptions'>$option</span></span> \n";
}
else {
$options_code .= "<span class='item-option-span' inum='$curr_item_num' cbid='$sname' opt_set='$set' set_max='$maxOptions'>$option</span></span> \n";
}
}
else {
// $fname = $sname . "_visible";
$options_code .= "<span class='menu-item-option options$ext'><input type='checkbox' name='$sname' id='$sname' class='item-option $current_source_item $option_f' value='Y' " .
"$checked$disabled>&nbsp;" .
"$option</span> \n";
if (strlen($checked)) $options_code .= "<input type='hidden' name='$sname' id='$sname' value='Y'>";
}
// $optionsText .= "$option ";
// writeLog("optionsText: $optionsText");
// if ($menu_display_mode == 'Form' && strlen($optionsText) > 70 && $i < ($num_options - 1)) {
// $optionsText = "";
$options_code .= "<br>\n";
// }
if ($maxOptions > 0 || $minOptions > 0) {
$menu_options_code .= " if (document.orderform.$sname.checked) ocount$ext" . "_$curr_code" . "++;\n";
$options_count_code .= " if (document.orderform.$sname.checked) ocount$ext" . "_$curr_code" . "++;\n";
}
}
// Ensure that too many options are not selected
// if ($menuDateActive == 'Y' && $maxOptions > 0) {
// $menu_options_code .= " if (ocount$ext" . "_$curr_code > $maxOptions) {\n";
// $menu_options_code .= " document.getElementById(sname).checked = false;\n";
// $menu_options_code .= " alert(\"" . getLanguageText('TEXT-YOU-MAY-NOT-SELECT-MORE-THAN') . " $maxOptions $optionsTitle\");\n";
// $menu_options_code .= " return false;\n";
// $menu_options_code .= " }\n";
// }
$menu_options_code .= " }\n\n";
// Ensure that the minimum number of options have been selected
writeLog("menuDateActive: $menuDateActive - minOptions: $minOptions");
if ($menuDateActive == 'Y' && $minOptions > 0) {
$ititle = str_replace("'","&quot;",$item_title);
if ($display_menu_date == 'Y') $ititle .= " - " . dateString('date',strtotime($mdate['menu_date']));
if ($linkedMenu != true) {
$form_check_code .= $options_count_code;
$form_check_code .= " if (document.getElementById('qty_$curr_code').value > 0 && ocount$ext" . "_$curr_code < $minOptions) {\n";
$form_check_code .= " checkFormMissedOptionsMessage += '" . getLanguageText('TEXT-YOU-MUST-SELECT-AT-LEAST') . " $minOptions $optionsTitle: $ititle\\n';\n";
$form_check_code .= " }\n";
}
}
}
else {
$noptions = 0;
for ($i = 0; $i < count($item_options); $i++) {
$option = trim($item_options[$i]);
if (strlen($option) > 0) {
if (in_array($option,$orderedOptions)) {
if ($noptions == 0) $options_code .= " - ";
if ($noptions > 0) $options_code .= ", ";
$options_code .= $option;
$noptions++;
}
}
}
}
}
}
// Complete the span
// Display the options
// if ($menu_display_mode != 'Form' && strlen($options_code)) {
$optclass = '';
if ($hasOptionsOrdered == 'Y') $optclass = ' item-options-ordered-span';
if (strlen($options_code)) $options_code = "\n<div id='$curr_code' class='modal options-code item-options-span$optclass' style='text-align: left'>$options_code<br><br></div>\n";
$view_icon_small = "<img src='images/icons/find16.png' alt='Edit Options' menu-num='$menu_num' item-num='$curr_item_num' border='0'>";
// $label_title .= "&nbsp;" . $view_icon_small;
// }
// Get total items ordered if required
$total_ordered = "";
if ($display_current_totals == 'Y') {
$query = "select sum(qty) from hotlunch_order_items AS hloi, hotlunch_order_header AS hloh, people AS p " .
"where hloi.school_num = $school_num " .
"and hloh.school_num = $school_num " .
"and p.school_num = $base_school_num " .
"and hloh.record_num = hloi.order_num " .
"and hloh.status NOT IN ('Inactive','Deleted') " .
"and hloi.ordered_by_type != 'Concession' " .
"and hloi.ordered_by_num = p.record_num " .
"and hloh.schedule_num = $schedule_num " .
"and hloi.schedule_num = $schedule_num " .
"and hloi.menu_num = $menu_num " .
"and hloi.menu_item_num = $curr_item_num " .
"and hloi.active != 'N'";
$total_ordered = floatval(db_getVal($query));
$total_ordered = number_format($total_ordered,0) . "&nbsp;&nbsp;";
}
// Set the border color of the quantity field
$borderColor = "808080";
$groupText = "";
$group_available = 0;
if (isset($menu_group) && strlen($menu_group) == 1) {
$mgcode = strtolower("group_$menu_group" . "_color");
$borderColor = $school_record[$mgcode];
$groupText = "($menu_group)&nbsp;";
$group_available = $mdate['group_' . strtolower($menu_group) . '_available'];
$groupLimits[$menu_group] = $group_available;
$group_sold = 0;
if ($group_available > 0) {
$query = "SELECT sum(qty) FROM hotlunch_order_items AS hloi, hotlunch_menu_items AS hlmi " .
"WHERE hloi.school_num = $school_num " .
"AND hlmi.school_num = $school_num " .
"AND hloi.schedule_num = $schedule_num " .
"AND hloi.menu_num = $menu_num " .
"AND hlmi.menu_num = $menu_num " .
"AND hloi.menu_item_num = hlmi.record_num " .
"AND hlmi.menu_group = '$menu_group' " .
"AND hloi.active != 'N' " .
"AND hlmi.active != 'N'";
$group_sold = db_getVal($query);
$group_qty_available = $group_available - intval($group_sold);
$groupLimits[$menu_group] = $group_qty_available;
}
}
// Clear the group color if the school profile specifies to
if (array_key_exists('display_group_colors', $school_record)) $display_group_colors = $school_record['display_group_colors'];
if (!isset($display_group_colors)) $display_group_colors = 'N';
if ($school_record['display_group_colors'] == 'N' && $display_group_colors != 'Y') $borderColor = "808080";
if (!isset($display_group_colors) || $display_group_colors == 'N') $borderColor = "808080";
// Clear the group text if this is a concession order or if the school profile specifies to
if ($concessionOrder == 'Y') $groupText = "";
if ($school_record['display_group_letters'] == 'N' || !isset($display_group_letters) || $display_group_letters == 'N') $groupText = "";
if (!isset($display_group_letters) || $display_group_letters == 'N') $groupText = "";
// If group processing is required save this item number to the correct group
if ($groupCount > 0 && $concessionOrder == 'N') $group_items[$menu_group][] = $curr_item_num;
$item_count++;
$item_price_d = "$currencySymbol$item_price";
// Multiple Item Prices
if ($access_to_multiple_item_prices == 'Y' && $display_price == 'Y' && $school_record['implement_multiple_item_prices'] == 'Y') {
if ($number_of_alternate_prices > 0 && $source == 'On-Line') {
$multiple = true;
if ($school_record['special_item_prices'] == 'Y') {
if ($menu_price_category == 'Special 1') $multiple = false;
if ($menu_price_category == 'Special 2') $multiple = false;
if ($menu_price_category == 'Special 3') $multiple = false;
}
if ($multiple) {
$item_price_d = "<select name='alt_prices_$curr_code' id='alt_prices_$curr_code' curr_code='$curr_code' mcode='$menu_code' item-format='$menuItemFormat' class='alternate-prices' $disabled>";
$item_price_d .= "<option value='$item_price'>$currencySymbol$item_price</option>";
for ($n = 1; $n <= $number_of_alternate_prices; $n++) {
$fname = "alternate_price$n";
$alt_price = $$fname;
$selected = "";
if (isset($selected_item_price) && $selected_item_price == $alt_price) $selected = " selected='selected'";
$item_price_d .= "<option value='$alt_price'$selected>$currencySymbol$alt_price</option>";
}
$item_price_d .= "</select>";
if (strlen($disabled)) {
$item_price_d .= "<input type='hidden' name='alt_prices_hidden_$curr_code' id='alt_prices_hidden_$curr_code'>";
}
}
}
}
else {
$selected_item_price = $item_price;
}
if ($display_price == 'N') $item_price_d = "";
// Handle limited quantity items
$item_availability = "";
$qty_remaining = 9999;
$quantity_available = intval($quantity_available);
if ($quantity_available > 0) {
$qty_sold = db_getVal("SELECT sum(qty) FROM hotlunch_order_items " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND menu_num = $menu_num " .
"AND menu_item_num = $curr_item_num " .
"AND active != 'N'");
$qty_sold = intval($qty_sold);
$qty_remaining = $quantity_available - $qty_sold;
$availablityText = getLanguageText('TEXT-AVAILABLE');
}
if ($group_available > 0) {
if ($group_qty_available < $qty_remaining) {
$qty_remaining = $group_qty_available;
$availablityText = getLanguageText('TEXT-AVAILABLE-IN-GROUP') . " $menu_group";
}
}
if ($quantity_available > 0 || $group_available > 0) {
$item_availability = " ";
if ($menu_display_mode != 'Form') $item_availability = "<br>";
$item_availability .= "($qty_remaining " . $availablityText . ")";
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') $item_availability .= " $group_sold / $group_available";
}
// Setup the order form field
if ((($mdate['order_format'] != 'Checkbox' || $menu_item_format == 'Q') && $menu_item_format != 'C') || $concessionOrder == 'Y') {
$rstyle = "";
$onclick = "";
$menuItemFormat = 'Quantity';
if ($linkedMenu) {
$rstyle = " background: #E0C0C0";
$onclick = " onclick='alert(\"" . getLanguageText('MSG-LINKED-MENU') . "\")'";
$readonly = " readonly";
writeLog("readonly: $readonly - Linked Menu");
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier');
if (checkPermission($AllowedUserTypes) == 1) $onclick = "";
}
if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team'))) {
if ($menu_available == 'N' || $menuDateActive == 'N') {
$readonly = " readonly onClick='alert(\"" . getLanguageText('TEXT-NOT-AVAILABLE') . "\");'";
writeLog("readonly: $readonly - Menu Not Available");
$onclick = "";
}
}
if (strlen($readonly) == 0) {
if ($qty_remaining <= 0) {
$readonly = " readonly onClick='alert(\"" . getLanguageText('TEXT-NOT-AVAILABLE') . "\");'";
writeLog("readonly: $readonly - Qty Not Available");
$onclick = "";
}
}
$itemTitle = "";
if (strlen(trim($item_message))) $itemTitle = "title=\"$item_message\" ";
if ($min_quantity > 0) {
if (intval($qtyvalue) == 0) {
$qtyvalue = $min_quantity;
$line_total = number_format($qtyvalue * $item_price, 2);
}
}
$today = date("Y-m-d",time());
if (isset($active_until_date) && strlen($active_until_date) && $active_until_date != '' && $active_until_date != '0000-00-00' && $active_until_date < $today) {
$readonly = " readonly";
writeLog("readonly: $readonly - active_until_date: $active_until_date");
}
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator');
if (checkPermission($AllowedUserTypes) == 1) {
$readonly = "";
}
$rstyle = "";
if (strlen($readonly)) {
$rstyle = " style='color: #ff0000; background-color: #cccccc;'";
}
$qfield = "<nobr>$groupText$total_ordered<input type='text' name='$qtyfield' id='$qtyfield' size='2' value='$qtyvalue' tabindex=$tabindex " .
"menu-num='$menu_num' item-num='$curr_item_num' class='qty-field' $rstyle curr-code='$curr_code' menu-code='$menu_code' field-type='qty' " .
$itemTitle .
"style='width: 20px; text-align: center; border: 1px solid #$borderColor;$rstyle'$onclick " .
"onChange=\"updateLine('$curr_code','$menu_code','Y','Y');\"$readonly></nobr>";
if (strlen($readonly) == 0) {
if (!isset($readonlyflag)) $readonlyflag = '';
$qfield = "<nobr>$groupText$total_ordered" .
"<span class='item-title' rflag='$readonlyflag' code='$curr_code' mcode='$menu_code' menu-num='$menu_num' item-num='$curr_item_num'><img src='images/icons/add24.png' hspace='5' width='18' height='18' style='mix-blend-mode: multiply'></span>" .
"<input type='text' name='$qtyfield' id='$qtyfield' size='2' value='$qtyvalue' tabindex=$tabindex " .
"menu-num='$menu_num' item-num='$curr_item_num' class='qty-field' $rstyle curr-code='$curr_code' menu-code='$menu_code' field-type='qty' " .
$itemTitle .
"style='width: 20px; text-align: center; border: 1px solid #$borderColor;$rstyle'$onclick " .
"onChange=\"updateLine('$curr_code','$menu_code','Y','Y');\"$readonly>" .
"<span class='item-qty-down' rflag='$readonlyflag' code='$curr_code' mcode='$menu_code' menu-num='$menu_num' item-num='$curr_item_num'><img src='images/icons/subtract24.png' hspace='5' width='18' height='18' style='mix-blend-mode: multiply'></span>" .
"</nobr>";
}
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') $qfield .= " $qtyvalue - $min_quantity";
if (1 == 2 && strlen($readonly) == 0) {
$qfield = "<nobr>$groupText$total_ordered<select name='$qtyfield' id='$qtyfield' onChange=\"updateLine('$curr_code','$menu_code','Y','Y');\">";
$qfield .= "<option value=''></option>";
for ($i = 1; $i <= 100; $i++) {
$selected = "";
if (strlen($qtyvalue) && $qtyvalue == $i) $selected = " selected='selected'";
$qfield .= "<option value='$i'$selected>$i</option>";
}
$qfield .= "</select></nobr>";
}
// if ($_SESSION['UserInfo']['type'] == 'SuperUser' && isset($min_quantity)) $qfield .= " ($min_quantity)";
if ($form_edit_mode == "review") {
$qfield = $qtyvalue . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
}
else {
$rstyle = "";
if ($qtyvalue == 0 && $quantity_available > 0 && $qty_remaining <= 0) {
$qfield = "";
$item_price_d = "";
}
else {
$checked = "";
$qtyvalue = intval($qtyvalue);
if ($qtyvalue == 1) $checked = " checked='checked'";
if ($min_quantity > 0) {
$checked = " checked='checked'";
if ($qtyvalue == 0) $qtyvalue = 1;
}
// $line_total = number_format($qtyvalue * $item_price,2);
// $menu_total += $ltotal;
// $menu_count += intval($qtyvalue);
// $ordertotal += $ltotal;
writeLog("qtyvalue: $qtyvalue $checked line_total: $line_total item_price: $item_price");
if ($form_edit_mode == "review") {
$disabled = $disabled_flag;
writeLog("disabled: $disabled form_edit_mode == review");
}
if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team'))) {
if ($menu_available == 'N' || $menuDateActive == 'N') {
$disabled = " disabled onClick='alert(\"" . getLanguageText('TEXT-NOT-AVAILABLE') . "\");'";
$onclick = "";
$rstyle = " style='background-color: #FF8080'";
}
}
$itemTitle = "";
if (strlen(trim($item_message))) $itemTitle = "title=\"$item_message\" ";
$qfield = "<nobr>$groupText$total_ordered<input type='hidden' name='$qtyfield' id='$qtyfield' value='$qtyvalue' class='qty-field' curr-code='$curr_code' menu-code='$menu_code' field-type='cb'>" .
"<input type='checkbox' name='$cbfield' id='$cbfield'$rstyle qtyfield='$qtyfield' " .
"menu-num='$menu_num' item-num='$curr_item_num' class='qty-checkbox' tabindex=$tabindex " .
"curr_code='$curr_code' menu_code='$menu_code' gcheck='Y' qtest='N' " .
$itemTitle .
"onClick=\"updateCheckboxLine('$curr_code','$menu_code','Y','N');\"$checked$disabled>&nbsp;</nobr>";
}
}
$tabindex++;
//
// Handle item links based on the $menu_link_code value set previously
// - $menu_link_code is set when evaluating order source and linking
//
if ($menuDateActive == 'Y') {
$query = "select hlmi.* " .
"from hotlunch_menu_items as hlmi, hotlunch_menu_dates as hlmd " .
"where hlmi.school_num = $school_num " .
"AND hlmi.active != 'N' " .
"and hlmi.current_source_item = $curr_item_num " .
"and hlmi.menu_num = hlmd.record_num " .
"and menu_link in $menu_link_code " .
"and hlmd.school_num = $school_num " .
"and hlmd.schedule_num = $schedule_num " .
"and hlmd.menu_date >= '$menu_date_cutoff'";
$results = db_query($query);
$nrows = db_num_rows($results);
if (db_num_rows($results) > 0) {
$menu_items_code .= " if (code == '$curr_code') {\n";
$all_menu_items_code .= " updateLinkedItems('$curr_code');\n";
while ($row = db_fetch_array($results)) {
$linked_menu_code = $schedule_num . "_" . $row['menu_num'];
$linked_code = $linked_menu_code . "_" . $row['record_num'];
$linked_qty_field = "qty_$linked_code";
$linked_cb_field = "cb_$linked_code";
$menu_items_code .= " document.orderform.$linked_qty_field.value = document.orderform.qty_$curr_code.value;\n";
writeLog("$item_title :: $linked_menu_code :: ".$row['number_of_alternate_prices']);
if ($access_to_multiple_item_prices == 'Y' && $row['number_of_alternate_prices'] > 0) {
$linked_price_field = "alt_prices_$linked_code";
$menu_items_code .= " document.orderform.$linked_price_field.value = document.orderform.price_$curr_code.value;\n";
}
// Set checkboxes if required
if ($mdate['order_format'] == 'Checkbox' || $row['menu_item_format'] == 'C') {
$menu_items_code .= " if (document.orderform.$linked_cb_field) document.orderform.$linked_cb_field.checked = document.orderform.cb_$curr_code.checked;\n";
}
$menu_items_code .= " updateLine('$linked_code','$linked_menu_code','Y','N');\n";
}
$menu_items_code .= " }\n\n";
}
}
// Handle item description text
$item_description = trim($item_description);
if (strlen($item_description)) $item_description = "<br>\n<span class='small'> - $item_description</span>";
// Handle supplier product code
if ($mdate['display_supplier_code'] == 'Y') {
$product_num = db_getVal("SELECT supplier_product_num FROM hotlunch_menu_products WHERE school_num = $school_num AND menu_item_num = $curr_item_num AND product_sequence = 1");
$supplier_code = "";
if ($product_num > 0) {
$supplier_code = db_getVal("SELECT supplier_code FROM supplier_products WHERE school_num = $supplier_school_num AND record_num = $product_num");
}
if (strlen($supplier_code) > 1) $item_title = "$supplier_code: $item_title";
}
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') $item_title = "$curr_item_num: $item_title";
if (strlen($qtyvalue) == 0) $qtyvalue = '0';
$itemStyle = "";
if (strlen($rowStyle)) $itemStyle = $rowStyle;
if ($active == 'N') {
$itemStyle = " style='display: none;'";
$heading_class = "";
}
if (!isset($current_source_num)) $current_source_num = 0;
if (!isset($nutrition_image)) $nutrition_image = '';
if (!isset($image_link)) $image_link = '';
// Save menu item data
$MenuItems[$MenuItemCount]['itemStyle'] = $itemStyle;
$MenuItems[$MenuItemCount]['item_title'] = $item_title;
$MenuItems[$MenuItemCount]['label_title'] = $label_title;
$MenuItems[$MenuItemCount]['item_availability'] = $item_availability;
$MenuItems[$MenuItemCount]['rating_image'] = $rating_image;
$MenuItems[$MenuItemCount]['nutrition_image'] = $nutrition_image;
$MenuItems[$MenuItemCount]['image_link'] = $image_link;
$MenuItems[$MenuItemCount]['item_description'] = $item_description;
$MenuItems[$MenuItemCount]['options_code'] = $options_code;
$MenuItems[$MenuItemCount]['qfield'] = $qfield;
$MenuItems[$MenuItemCount]['item_price_d'] = $item_price_d;
$MenuItems[$MenuItemCount]['linespan'] = $linespan;
$MenuItems[$MenuItemCount]['line_total'] = $line_total;
$MenuItems[$MenuItemCount]['titlefield'] = $titlefield;
$MenuItems[$MenuItemCount]['pricefield'] = $pricefield;
$MenuItems[$MenuItemCount]['item_price'] = $item_price;
$MenuItems[$MenuItemCount]['selected_item_price'] = $selected_item_price;
$MenuItems[$MenuItemCount]['number_of_alternate_prices'] = $number_of_alternate_prices;
$MenuItems[$MenuItemCount]['alternate_price1'] = $alternate_price1;
$MenuItems[$MenuItemCount]['alternate_price2'] = $alternate_price2;
$MenuItems[$MenuItemCount]['alternate_price3'] = $alternate_price3;
$MenuItems[$MenuItemCount]['alternate_price4'] = $alternate_price4;
$MenuItems[$MenuItemCount]['alternate_price5'] = $alternate_price5;
$MenuItems[$MenuItemCount]['alternate_price6'] = $alternate_price6;
$MenuItems[$MenuItemCount]['alternate_price7'] = $alternate_price7;
$MenuItems[$MenuItemCount]['alternate_price8'] = $alternate_price8;
$MenuItems[$MenuItemCount]['alternate_price9'] = $alternate_price9;
$MenuItems[$MenuItemCount]['alternate_price10'] = $alternate_price10;
$MenuItems[$MenuItemCount]['linetotal'] = $linetotal;
$MenuItems[$MenuItemCount]['line_total'] = $line_total;
$MenuItems[$MenuItemCount]['linecount'] = $linecount;
$MenuItems[$MenuItemCount]['qtyvalue'] = $qtyvalue;
$MenuItems[$MenuItemCount]['min_quantity'] = $min_quantity;
$MenuItems[$MenuItemCount]['warn_quantity'] = $warn_quantity;
$MenuItems[$MenuItemCount]['max_quantity'] = $max_quantity;
$MenuItems[$MenuItemCount]['max_quantity_by'] = $max_quantity_by;
$MenuItems[$MenuItemCount]['minqty'] = $minqty;
$MenuItems[$MenuItemCount]['warnqty'] = $warnqty;
$MenuItems[$MenuItemCount]['maxqty'] = $maxqty;
$MenuItems[$MenuItemCount]['maxqty_by'] = $maxqty_by;
$MenuItems[$MenuItemCount]['family_qty'] = $family_qty;
$MenuItems[$MenuItemCount]['item_format'] = $menu_item_format;
$MenuItems[$MenuItemCount]['item_num'] = $curr_item_num;
$MenuItems[$MenuItemCount]['source_item_num'] = $current_source_num;
$MenuItems[$MenuItemCount]['heading_class'] = $heading_class;
$MenuItems[$MenuItemCount]['curr_code'] = $curr_code;
$MenuItems[$MenuItemCount]['menu_code'] = $menu_code;
$MenuItems[$MenuItemCount]['readonly'] = $readonly;
$MenuItems[$MenuItemCount]['schedule_num'] = $schedule_num;
$MenuItems[$MenuItemCount]['menu_num'] = $menu_num;
$MenuItems[$MenuItemCount]['curr_item_num'] = $curr_item_num;
if (isset($ordered_by_num) && $ordered_by_num > 3) $user_num = db_getVal("SELECT user_num FROM people WHERE record_num = $ordered_by_num");
if (isset($user_num) && $user_num > 0) {
$query = "SELECT sum(qty) FROM hotlunch_order_items AS hloi, people AS p " .
"WHERE p.school_num = $base_school_num " .
"AND hloi.school_num = $school_num " .
"AND p.user_num = $user_num " .
"AND p.record_num = hloi.ordered_by_num " .
"AND hloi.menu_item_num = $curr_item_num";
$fqty = intval(db_getVal($query));
$MenuItems[$MenuItemCount]['family_quantity'] = $fqty - intval($qtyvalue);
}
else {
$MenuItems[$MenuItemCount]['family_quantity'] = 0;
}
$MenuItems[$MenuItemCount]['display_price'] = $display_price;
$MenuItemCount++;
}
else {
$description = $item_description;
if (strlen($item_description) > 0) $item_description = "<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='small'>$item_description</span>";
$MenuItems[$MenuItemCount]['rowStyle'] = $rowStyle;
$MenuItems[$MenuItemCount]['item_title'] = $item_title;
$MenuItems[$MenuItemCount]['item_description'] = $item_description;
$MenuItems[$MenuItemCount]['description'] = $description;
$MenuItems[$MenuItemCount]['item_num'] = $curr_item_num;
$MenuItems[$MenuItemCount]['heading_visibility'] = $heading_visibility;
$MenuItemCount++;
}
}
$MenuDates[$menu_num]['MenuItems'] = $MenuItems;
$MenuDates[$menu_num]['item_count'] = $item_count;
unset($MenuTotals);
$MenuTotals = array();
// Show a totals box if there are menu items
if ($item_count > 0) {
$menuspan = "span_$menu_code";
$menutotal = "mtotal_$menu_code";
$menucount = "mcount_$menu_code";
$menu_total = number_format($menu_total,2);
if ($menuDateActive == 'Y' && ($schedule_type == 'Hot Lunch' || $schedule_type == 'Date Sensitive') && $check_for_missed_menus == 'Y') {
$mtitle = str_replace('"',"&quot;",$menu_title);
if ($display_menu_date == 'Y') $mtitle .= " - " . dateString('date',strtotime($mdate['menu_date']));
$form_check_code .= " if (document.orderform.$menucount.value == 0) {\n";
$form_check_code .= " missedMenuCount++;\n";
$form_check_code .= " if (missedMenuCount <= maxMenuCount) {\n";
$form_check_code .= " checkFormMissedDatesMessage += \" - $mtitle\\n\";\n";
$form_check_code .= " }\n";
$form_check_code .= " }\n";
}
$MenuTotals['rowStyle'] = $rowStyle;
$MenuTotals['menuspan'] = $menuspan;
$MenuTotals['menu_total'] = $menu_total;
$MenuTotals['menutotal'] = $menutotal;
$MenuTotals['menucount'] = $menucount;
$MenuTotals['menu_count'] = $menu_count;
}
$MenuDates[$menu_num]['MenuTotals'] = $MenuTotals;
unset($MenuVolunteers);
$MenuVolunteers = array();
$MenuDates[$menu_num]['MenuVolunteers'] = $MenuVolunteers;
if ($concessionOrder == 'N') {
if ($volunteer_signup == 'Y') {
$vBox = "volunteer_$menu_code";
$vChecked = "";
$vnum = 0;
if (isset($user_num) && $user_num > 0) {
$vnum = db_getVal("SELECT count(*) FROM hotlunch_volunteers WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_num = $menu_num AND user_num = $user_num AND deleted != 'Y'");
if ($vnum == 1) $vChecked = " checked='checked'";
}
// Determine the number of volunteers currently registered
$numRegistered = db_getVal("SELECT count(*) FROM hotlunch_volunteers WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_num = $menu_num AND deleted != 'Y'");
if ($form_edit_mode == 'review' || $menuDateActive == 'N' || $numRegistered >= $maxVolunteers) {
$vField = 'N';
if ($vnum == 1) $vField = 'Y';
$vField .= "<input type='hidden' name='$vBox' value='$vField'>";
}
else {
$vField = "<input type='checkbox' name='$vBox' value='Y'$vChecked tabindex=$tabindex>";
$tabindex++;
}
if (!isset($volunteerMessage)) $volunteerMessage = getLanguageText('TEXT-DEFAULT-VOLUNTEER-MESSAGE');
$MenuVolunteers['rowStyle'] = $rowStyle;
$MenuVolunteers['volunteerMessage'] = $volunteerMessage;
$MenuVolunteers['volunteer_msg'] = $volunteer_msg;
$MenuVolunteers['numRegistered'] = $numRegistered;
$MenuVolunteers['maxVolunteers'] = $maxVolunteers;
$MenuVolunteers['vnum'] = $vnum;
$MenuVolunteers['vField'] = $vField;
$MenuDates[$menu_num]['MenuVolunteers'] = $MenuVolunteers;
}
}
// Generate the group processing code if required
if ($groupCount > 0 && $concessionOrder == 'N') {
$group_check_code .= " if (mcode == '$menu_code') {\n";
$group_check_code .= " var Atotal = Number(0);\n";
$group_menu_code = "";
// Process each group
for ($i = 0; $i < count($groupCodes); $i++) {
$gCode = $groupCodes[$i];
if (array_key_exists($gCode, $group_items)) {
$groupItems = $group_items[$gCode];
$groupTotal = $gCode . "total";
$groupSum = "var $groupTotal = ";
$currGroup = "group_" . strtolower($gCode);
$groupLimit = $mdate[$currGroup];
$Lword = "item";
if ($groupLimit > 1) $Lword = "items";
if (isset($groupLimits[$gCode]) && $groupLimits[$gCode] > 0 && $groupLimits[$gCode] < $groupLimit) $groupLimit = $groupLimits[$gCode];
// If this is group B - E check if A required
if ($i > 0) {
$aRequiredField = $currGroup . "_a_required";
$aCustomMessage = $currGroup . "_message";
}
if (isset($groupItems) && is_array($groupItems) && count($groupItems) > 0) {
for ($j = 0; $j < count($groupItems); $j++) {
$item = $groupItems[$j];
$curr_code = $schedule_num . "_" . $menu_num . "_" . $item;
// Code to check the quantities of menu groups
$group_check_code .= " var $gCode$j = 0;\n";
$group_check_code .= " if (document.orderform.qty_$curr_code) $gCode$j = Number(document.orderform.qty_$curr_code.value);\n";
$group_complete_code .= " var $gCode$j = 0;\n";
$group_complete_code .= " if (document.orderform.qty_$curr_code) $gCode$j = Number(document.orderform.qty_$curr_code.value);\n";
if ($j > 0) $groupSum .= " + ";
$groupSum .= "$gCode$j";
$group_menu_code .= " if (code == '$curr_code') {\n";
if ($gCode == 'A') {
$group_menu_code .= " if (Atotal == 0) {\n";
for ($m = 1; $m < count($groupCodes); $m++) {
$codeTemp = $groupCodes[$m];
if (array_key_exists($codeTemp, $group_items)) {
$groupTemp = $group_items[$codeTemp];
$requiredTemp = "group_" . strtolower($codeTemp) . "_a_required";
if ($mdate[$requiredTemp] == 'Y' && count($groupTemp) > 0) {
for ($n = 0; $n < count($groupTemp); $n++) {
$item_temp = $groupTemp[$n];
$temp_code = $schedule_num . "_" . $menu_num . "_" . $item_temp;
$group_menu_code .= " document.orderform.qty_$temp_code.value = 0;\n";
// $group_menu_code .= " document.orderform.ltotal_$temp_code.value = 0;\n";
// $group_menu_code .= " document.orderform.lcount_$temp_code.value = 0;\n";
$group_menu_code .= " updateLine('$temp_code','$menu_code','N','Y');\n";
}
}
}
}
$group_menu_code .= " updateLine('$curr_code','$menu_code','N','Y');\n";
$group_menu_code .= " }\n\n";
}
// Code to prevent someone from ordering unless at least one group A has been ordered
if (isset($aRequiredField) && array_key_exists($aRequiredField, $mdate) && $mdate[$aRequiredField] == 'Y') {
$g_message = getLanguageText('TEXT-GROUP-A-FIRST') . " $gCode";
if (array_key_exists($aCustomMessage, $mdate) && strlen($mdate[$aCustomMessage])) $g_message = $mdate[$aCustomMessage];
$group_menu_code .= " if (Atotal == 0 && document.orderform.qty_$curr_code.value > 0) {\n";
$group_menu_code .= " document.orderform.qty_$curr_code.value = '';\n";
if ($mdate['order_format'] == 'Checkbox') {
$group_menu_code .= " document.orderform.cb_$curr_code.checked = false;\n";
}
$g_message = str_replace('"','\"',$g_message);
$group_menu_code .= " alert(\"$g_message\");\n";
$group_menu_code .= " return;\n";
$group_menu_code .= " }\n\n";
}
// Ensure that group B,C,D... items are not more than group A items
for ($n = 0; $n < count($groupCodes); $n++) {
$gCode2 = $groupCodes[$n];
if ($gCode2 == 'A') continue;
$groupArrayCode = "group_" . strtolower($gCode2);
$aRequiredField2 = $groupArrayCode . "_a_required";
$numGroupItems = db_getVal("SELECT count(*) FROM hotlunch_menu_items WHERE school_num = $school_num AND menu_num = $menu_num AND active != 'N' AND menu_group = '$gCode2'");
if ($numGroupItems > 0 && $mdate[$aRequiredField2] == 'Y' && $mdate[$groupArrayCode] == 0) {
$g_quantity = sprintf(getLanguageText('TEXT-GROUP-QTY-ERROR'),$gCode2);
$group_menu_code .= " if (Atotal > 0 && " . $gCode2 . "total > Atotal) {\n";
$group_menu_code .= " document.orderform.qty_$curr_code.value = '';\n";
$group_menu_code .= " if (document.orderform.cb_$curr_code.checked) {\n";
$group_menu_code .= " document.orderform.cb_$curr_code.checked = false;\n";
$group_menu_code .= " }\n";
$group_menu_code .= " alert(\"$g_quantity\");\n";
$group_menu_code .= " return;\n";
$group_menu_code .= " }\n\n";
}
}
// Code to manage group quantity limits
if ($groupLimit > 0) {
$g_limit = sprintf(getLanguageText('TEXT-GROUP-LIMIT'),$groupLimit) . " $gCode";
$customMsgField = "group_" . strtolower($gCode) . "_max_message";
if (array_key_exists($customMsgField, $mdate) && strlen($mdate[$customMsgField])) $g_limit = $mdate[$customMsgField];
$group_menu_code .= " if ($groupTotal > $groupLimit) {\n";
$group_menu_code .= " document.orderform.qty_$curr_code.value = '';\n";
if ($mdate['order_format'] == 'Checkbox') {
$group_menu_code .= " document.orderform.cb_$curr_code.checked = false;\n";
}
$group_menu_code .= " alert(\"$g_limit\");\n";
$group_menu_code .= " }\n";
}
$group_menu_code .= " }\n";
}
$group_check_code .= " $groupSum;\n";
$group_complete_code .= " $groupSum;\n";
if ($gCode == 'A') {
if ($mdate['group_a_min'] > 0) {
$min = $mdate['group_a_min'];
$msg = getLanguageText('ERRORMSG-NO-ITEMS-SELECTED') . "\\n-- " . $mdate['menu_title'] . " --";
$group_complete_code .= " if ($groupTotal < $min) {\n";
$group_complete_code .= " alert(\"$msg\");\n";
$group_complete_code .= " return(false);\n";
$group_complete_code .= " }\n";
}
}
}
}
}
$group_check_code .= "\n$group_menu_code";
$group_check_code .= " }\n\n";
// Setup code to check if the mandatory groups have been entered
$groupMandatory = false;
// Process each group
for ($i = 1; $i < count($groupCodes); $i++) {
$mandatoryCode = "group_" . strtolower($groupCodes[$i]) . "_mandatory";
if ($mdate[$mandatoryCode] == 'Y') $groupMandatory = true;
}
// If there is a mandatory group in this menu
if ($groupMandatory == true) {
$mtitle = str_replace("'","\'",$menu_title);
if ($display_menu_date == 'Y') $mtitle .= " - " . dateString('date',strtotime($mdate['menu_date']));
$group_complete_code .= " if (Atotal > 0) {\n";
for ($i = 1; $i < count($groupCodes); $i++) {
$mandatoryCode = "group_" . strtolower($groupCodes[$i]) . "_mandatory";
$groupLimit = $mdate["group_" . strtolower($groupCodes[$i])];
if ($mdate[$mandatoryCode] == 'Y') {
// if ($groupLimit == 0) $group_complete_code .= " if (" . $groupCodes[$i] . "total < Atotal) {\n";
// else $group_complete_code .= " if (" . $groupCodes[$i] . "total < $groupLimit) {\n";
if ($groupLimit == 0) {
$group_complete_code .= " if (" . $groupCodes[$i] . "total < Atotal) {\n";
$group_complete_code .= " msg = '" . getLanguageText('MESSAGE-INCOMPLETE-ORDER-GROUPS') . "'+'\\n - '+'$mtitle';\n";
$group_complete_code .= " alert(msg);\n";
$group_complete_code .= " return false;\n";
$group_complete_code .= " }\n";
}
else {
$group_complete_code .= " if (" . $groupCodes[$i] . "total < 1) {\n";
$group_complete_code .= " msg = '" . getLanguageText('MESSAGE-INCOMPLETE-ORDER-GROUPS') . "'+'\\n - '+'$mtitle';\n";
$group_complete_code .= " alert(msg);\n";
$group_complete_code .= " return false;\n";
$group_complete_code .= " }\n";
}
}
}
$group_complete_code .= " }\n";
}
}
}
//
// Display calendar form menus
//
if ($menu_display_mode == 'Calendar' || $menu_display_mode == 'Calendar No Weekends') {
$dayNames = array(
getLanguageText('TEXT-SUNDAY'),
getLanguageText('TEXT-MONDAY'),
getLanguageText('TEXT-TUESDAY'),
getLanguageText('TEXT-WEDNESDAY'),
getLanguageText('TEXT-THURSDAY'),
getLanguageText('TEXT-FRIDAY'),
getLanguageText('TEXT-SATURDAY')
);
// writeLog("firstMenuDate: $firstMenuDate");
// writeLog("lastMenuDate: $lastMenuDate");
$firstDateTime = strtotime($firstMenuDate);
$lastDateTime = strtotime($lastMenuDate);
$firstCalendarMonth = date("n",$firstDateTime);
$lastCalendarMonth = date("n",$lastDateTime);
$currYear = date("Y",$firstDateTime);
$currMonth = $firstCalendarMonth;
$currMonthDate = date("Y-m-01",$firstDateTime);
$currDateTime = $firstDateTime;
$currMonthYear = date("Y-m",$firstDateTime);
$lastMonthYear = date("Y-m",$lastDateTime);
$monthBreak = true;
if ($calendar_month_breaks != 'Y') $monthBreak = false;
if ($school_num == 18493 || $school_num == 18494) $monthBreak = false;
$monthNum = 1;
$monthSpanned = false;
$EventCount = 0;
$query = "select count(*) " .
"from event_calendar " .
"where school_num = $school_num " .
"and status = 'Approved' " .
"and display = 'Active' " .
"and start_date <= '$firstMenuDate' and '$lastMenuDate' <= end_date";
$EventCount = db_getVal($query);
$RegularMenus = array();
$query = "SELECT menu_date,record_num FROM hotlunch_menu_dates " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND menu_type = 'Regular' " .
"ORDER BY sequence,menu_date";
while ($row = db_fetch_assoc($results)) {
$RegularMenus[$row['menu_date']][] = $row['record_num'];
}
while ($currMonthYear <= $lastMonthYear) {
$currMonthTime = strtotime("$currMonthYear-01");
$currMenuDate = date("Y-m-d",$currMonthTime);
$futureMenuDates = db_getVal("SELECT count(*) FROM hotlunch_menu_dates " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND menu_date >= '$currMenuDate' " .
"AND menu_type = 'Regular'");
if ($futureMenuDates == 0 && $monthBreak == false) break;
$monthTitle = date("F Y",$currMonthTime);
$cols = 7;
$colwidth = '14%';
if ($menu_display_mode == 'Calendar No Weekends') {
$cols = 5;
$colwidth = '20%';
}
if ($monthBreak == false) $monthTitle = $schedule_name;
if ($monthBreak || $monthNum == 1) {
?>
<table width='100%' cellpadding='1' cellspacing='1' border='0' class='content-table calendar-table calendar-<?php echo($cols) ?>'>
<tr>
<td colspan='<?php echo($cols) ?>' align='center' class='menudate-header'><?php echo($monthTitle) ?></td>
</tr>
<?php
// Display day of week heading
// echo(" <tr>\n");
for ($dow = 0; $dow < 7; $dow++) {
$dayOfWeek = $dayNames[$dow];
if ($menu_display_mode == 'Calendar No Weekends' && ($dow == 0 || $dow == 6)) continue;
?>
<!--
<td width='<?php echo($colwidth) ?>' align='center' class='menudate-header'><?php echo($dayOfWeek) ?></td>
<td align='center' class='menudate-header'><?php echo($dayOfWeek) ?></td>
-->
<?php
}
// echo(" </tr>\n");
}
$monthNum++;
// Display calendar dates
$startDOW = date("w",$currMonthTime);
$currCalendarDateTime = $currMonthTime - $startDOW * 60 * 60 * 24 + 60 * 60 * 2;
$startWeek = 0;
if ($monthSpanned) {
$startWeek = 1;
$currCalendarDateTime += 60 * 60 * 24 * 7;
if (date("d",$currCalendarDateTime) > '07') $currCalendarDateTime = $currMonthTime - 7 * 60 * 60 * 24 + 60 * 60 * 2;
}
$monthSpanned = false;
for ($Week = $startWeek; $Week <= 6; $Week++) {
if ($currCalendarDateTime >= $lastDateTime) {
$Week = 7;
$currMonthYear = intval($lastMonthYear) + 1;
$currMonthTime = $lastDateTime;
break;
}
// Check if there are any menus this week
if ($menu_display_mode == 'Calendar No Weekends') {
$menusThisWeek = false;
$wtime = $currCalendarDateTime;
for ($dow = 0; $dow < 7; $dow++) {
$menu_date = date("Y-m-d",$wtime);
if (date("n",$wtime) != date("n",$currMonthTime)) {
$wtime = strtotime(date("Y-m-d",$wtime + 60 * 60 * 25));
continue;
}
$query = "SELECT * FROM hotlunch_menu_dates " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND menu_date = '$menu_date' " .
"AND menu_type = 'Regular' " .
"ORDER BY sequence,menu_date LIMIT 0,1";
$cResults = db_query($query);
if (db_num_rows($cResults)) {
$cMenu = db_fetch_assoc($cResults);
if (is_array($cMenu)) {
$menu_num = $cMenu['record_num'];
// writeLog("menu_num: $menu_num");
// writeLog("MenuDates[$menu_num]['menu_date']: " .$MenuDates[$menu_num]['menu_date']);
if (array_key_exists($menu_num, $MenuDates) && $MenuDates[$menu_num]['menu_date'] == $menu_date) $menusThisWeek = true;
}
}
$wtime = strtotime(date("Y-m-d",$wtime + 60 * 60 * 25));
}
if (!$menusThisWeek) {
$currCalendarDateTime = $wtime;
if (date("n",$currCalendarDateTime) > date("n",$currMonthTime)) break;
if (date("Y",$currCalendarDateTime) > date("Y",$currMonthTime)) break;
continue;
}
}
echo(" <tr height='100'>\n");
for ($dow = 0; $dow < 7; $dow++) {
if ($menu_display_mode == 'Calendar No Weekends' && ($dow == 0 || $dow == 6)) {
$currCalendarDateTime = strtotime(date("Y-m-d",$currCalendarDateTime + 60 * 60 * 25));
continue;
}
$currCalendarDate = dateString('date-cal',$currCalendarDateTime);
$menu_date = date("Y-m-d",$currCalendarDateTime);
$tdclass = "calendar-date";
$dtclass = "caldate";
$currMonthFlag = true;
if (date("n",$currCalendarDateTime) != date("n",$currMonthTime)) {
if ($monthBreak) {
$tdclass = "non-current-date";
$dtclass = "noncaldate";
$currMonthFlag = false;
}
else {
$monthSpanned = true;
if ($menu_display_mode == 'Calendar') $Week = 0;
}
}
else {
if (date("Y-m-d",$currCalendarDateTime) < date("Y-m-d",time())) {
$tdclass .= " calendar-date-past";
}
}
// Display calendar cell
echo(" <td align='left' valign='top' class='$tdclass'><span class='$dtclass'>$currCalendarDate</span><br>\n");
// Check event calendar for events on this date
if ($school_record['system_configuration'] == 'Full' && $EventCount > 0) {
$query = "select ec.* " .
"from event_calendar as ec, event_types as et " .
"where ec.school_num = $school_num " .
"and et.school_num = $school_num " .
"and ec.event_type = et.event_type_title " .
"and et.display_on_order_form = 'Y' " .
"and ec.status = 'Approved' " .
"and ec.display = 'Active' " .
"and start_date <= '$menu_date' and '$menu_date' <= end_date " .
"order by start_date,end_date,title";
$events = db_query($query);
if (db_num_rows($events)) {
while ($row = db_fetch_array($events)) {
// Handle event type colors
$sspan = "";
$espan = "";
$event_type = $row['event_type'];
$results = db_query("SELECT * FROM event_types WHERE school_num = $school_num AND event_type_title = '" . db_escape_string($event_type) . "'");
if (db_num_rows($results) > 0) {
$erow = db_fetch_array($results);
$sspan = "<span style='color: #" . $erow['text_color'] . "; background-color: #" . $erow['bg_color'] . ";'>";
$espan = "</span>";
}
echo("<span class='calitem'>$sspan" . $row['title'] . "$espan</span><br>");
}
}
}
$menuDate = $menu_date;
$query = "SELECT record_num,menu_link,current_menu_link FROM hotlunch_menu_dates " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND menu_date = '$menu_date' " .
"AND menu_type = 'Regular' " .
"ORDER BY sequence,menu_date";
// writeLog($query);
$menu_dates = db_query($query);
while ($row = db_fetch_assoc($menu_dates)) {
$menu_num = $row['record_num'];
$mLink = $row['menu_link'];
$mLink = $row['current_menu_link'];
if ($currMonthFlag && array_key_exists($menu_num, $MenuDates) && $MenuDates[$menu_num]['menu_date'] == $menu_date) {
extract($MenuDates[$menu_num]);
// Display menu items for current date
if (count($MenuItems)) {
$qclass = "";
$tclass = "";
if ($menu_active == 'N') {
$qclass = " calitem-past";
$tclass = 'menudate-past';
}
$ext = "";
if (($mLink == 'Paper' && $source == 'Paper') || $mLink == 'All') $tclass = 'menudate-linked';
if (strlen($menu_title) && $schedule_record['display_menu_title'] == 'Y') echo("<span class='caltext menu-title $tclass'><b>$menu_title</b> $ext</span>\n");
if (strlen($menu_instructions) > 0) {
echo("<span class='caltext menu-instructions warning'>" . nl2br($menu_instructions) . "</span>\n");
}
echo(" <table width='100%' cellpadding='0' cellspacing='1'>\n");
for ($i = 0; $i < count($MenuItems); $i++) {
extract($MenuItems[$i]);
if ($item_type != 'Heading') {
$item_price_info = "";
if ($schedule_record['display_item_price'] == 'Y' && $display_price != 'N') $item_price_info = "<br> -- <span class='cal-item-price'>$currencySymbol".number_format($item_price,2)."</span>";
$display_title = "<span class='menu-item-title'>$label_title</span>";
$ItemTitle = str_replace('"',"&quot;",$item_title);
$curr_price = $item_price;
if (isset($selected_item_price)) $curr_price = $selected_item_price;
$ftitle = db_escape_string($display_title);
$item_price_info = '';
?>
<tr<?php echo($itemStyle) ?> class='<?php echo($heading_class) ?>' style='display: flex; flex-direction: column'>
<td align='left' valign='top' class='oitem calitem<?php echo($qclass) ?>'><?php echo("$display_title$item_availability$item_price_info") ?></td>
<td align='right' valign='top' class='oitem calitem<?php echo($qclass) ?>'><?php echo($qfield) ?>
<input type='hidden' name='<?php echo($pricefield) ?>' id='<?php echo($pricefield) ?>' value='<?php echo($curr_price) ?>'>
<input type='hidden' name='<?php echo($linetotal) ?>' id='<?php echo($linetotal) ?>' value='<?php echo($line_total) ?>'>
<input type='hidden' name='<?php echo($linecount) ?>' id='<?php echo($linecount) ?>' value='<?php echo($qtyvalue) ?>'>
<input type='hidden' name='<?php echo($minqty) ?>' id='<?php echo($minqty) ?>' class='minimum-qty' value='<?php echo($min_quantity) ?>'>
<input type='hidden' name='<?php echo($warnqty) ?>' id='<?php echo($warnqty) ?>' value='<?php echo($warn_quantity) ?>'>
<input type='hidden' name='<?php echo($maxqty) ?>' id='<?php echo($maxqty) ?>' value='<?php echo($max_quantity) ?>'>
<input type='hidden' name='<?php echo($maxqty_by) ?>' id='<?php echo($maxqty_by) ?>' value='<?php echo($max_quantity_by) ?>'>
<input type='hidden' name='<?php echo($family_qty) ?>' id='<?php echo($family_qty) ?>' value='<?php echo($family_quantity) ?>'>
<input type='hidden' name='item_title_<?php echo($item_num) ?>' id='item_title_<?php echo($item_num) ?>' value="<?php echo($ItemTitle) ?>">
<input type='hidden' name='<?php echo($titlefield) ?>' id='<?php echo($titlefield) ?>' value="<?php echo($ItemTitle) ?>">
<?php echo($options_code) ?>
</td>
</tr>
<?php
}
else {
if ($schedule_record['display_menu_headings'] == 'Y') {
$control = " -- <span hnum='$item_num' mode='visible' id='header-$item_num' class='header-controls'>[".getLanguageText('TEXT-HIDE-LOWERCASE')."]</span>";
if ($heading_visibility == 'hidden') {
$control = " -- <span hnum='$item_num' mode='hidden' id='header-$item_num' class='header-controls'>[".getLanguageText('TEXT-SHOW-LOWERCASE')."]</span>";
}
?>
<tr<?php echo($itemStyle) ?>>
<td colspan='2' align='left' valign='middle' class='menudate-subheader caltext'>
<?php
if (strlen($item_title)) {
echo("$item_title$control");
if (strlen($description)) echo("<br>\n");
}
?>
<?php if (strlen($description)) echo("<span class='item-description'>$description</span>"); ?>
</td>
</tr>
<?php
}
}
}
if (count($MenuVolunteers) > 0) {
extract($MenuVolunteers);
if (strlen($volunteerMessage) > 0) {
if ($numRegistered < $maxVolunteers || $vnum > 0) {
$vfont = $school_record['volunteer_msg_font'];
$vcolor = $school_record['volunteer_msg_color'];
if (strlen($vfont)) $vfont = " style='font: $vfont;'";
if (strlen($vcolor)) $vcolor = " style='background: #$vcolor;'";
?>
<tr<?php echo($rowStyle) ?> style='display: flex; flex-direction: column'>
<td align='left' valign='top' class='signup'<?php echo($vcolor) ?>>
<span class='signup-text caltext'<?php echo($vfont) ?>><b><?php echo(nl2br($volunteerMessage)) ?></b></span>
</td>
<td align='right' valign='top' class='signup'<?php echo($vcolor) ?>><?php echo($vField) ?></td>
</tr>
<?php
}
}
}
if ($item_count > 0) {
extract($MenuTotals);
?>
<tr>
<td align='right' colspan='2' class='oitem calitem'><b><?php displayLanguageText('TEXT-SUBTOTAL'); ?>:&nbsp;</b> <b>&nbsp;<span id='<?php echo($menuspan) ?>'><?php echo($school_record['currency_symbol'] . $menu_total) ?></span></b>
<input type='hidden' name='<?php echo($menutotal) ?>' id='<?php echo($menutotal) ?>' value='<?php echo(trimNumber($menu_total)) ?>'>
<input type='hidden' name='<?php echo($menucount) ?>' id='<?php echo($menucount) ?>' value='<?php echo(trimNumber($menu_count)) ?>'>
</td>
</tr>
<?php
}
echo(" </table>\n");
}
else {
echo(" <table width='100%' cellpadding='0' cellspacing='1'>\n");
echo(" <tr><td class='caltext menudate-noitems'>$menu_title</td></tr>\n");
echo(" </table>\n");
// echo("<span class='caltext menudate-noitems'><b>$menu_title</b></span><br>\n");
}
}
}
echo(" </td>\n");
$currCalendarDateTime = strtotime(date("Y-m-d",$currCalendarDateTime + 60 * 60 * 25));
}
echo(" </tr>\n");
if (date("n",$currCalendarDateTime) > date("n",$currMonthTime)) {
if ($monthBreak) break;
else $monthSpanned = true;
}
if (date("Y",$currCalendarDateTime) > date("Y",$currMonthTime)) break;
}
if ($monthBreak) {
?>
</table>
<br>
<?php
}
$prevMonthYear = $currMonthYear;
$currMonthTime += 32 * 24 * 60 * 60;
$currMonthYear = date("Y-m",$currMonthTime);
$currMonthTime = strtotime("$currMonthYear-01");
}
if (!$monthBreak) {
?>
</table>
<br>
<?php
}
}
// Check for Footer menu dates
$FooterMenus = db_query("SELECT * FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_type != 'Regular' ORDER BY sequence");
$displayFooterMenus = false;
if (db_num_rows($FooterMenus) > 0) {
$displayFooterMenus = true;
}
//
// Display menu form
//
if ($menu_display_mode == 'Form' || $displayFooterMenus) {
?>
<table width='90%' cellpadding='1' cellspacing='1' border='0'>
<?php
foreach ($MenuDates as $menu_num => $val) {
extract($MenuDates[$menu_num]);
// If displaying Footer menus do not display regular menus
if ($menu_display_mode != 'Form' && $displayFooterMenus && $menu_type == 'Regular') continue;
?>
<tr<?php echo($rowStyle) ?>>
<td align='center' colspan='4' class='<?php echo($tclass) ?>'>
<table width='100%' cellspacing='0' cellpadding='0' border='0'>
<tr>
<td align='left' class='<?php echo($tclass) ?> menu-heading'><?php echo(str_replace('\\','',$menu_title)) ?></td>
<?php if ($display_menu_date == 'Y' && $menu_type != 'Footer') { ?>
<td align='right' class='<?php echo($tclass) ?> menu-heading'><nobr><?php echo(dateString('date',strtotime($menu_date))) ?></nobr></td>
<?php } ?>
</tr>
</table>
<?php if (strlen($menu_instructions) > 0) { ?>
<table width='100%' cellspacing='0' cellpadding='3' border='0'>
<tr>
<td align='center' class='instructions'><span class='instructions-text'><?php echo(nl2br($menu_instructions)) ?></span></td>
</tr>
</table>
<?php } ?>
</td>
</tr>
<?php
//
// Display menu items for current date
//
$priceVal = false;
for ($i = 0; $i < count($MenuItems); $i++) {
extract($MenuItems[$i]);
if ($item_type != 'Heading') {
$item_title = "<b>$item_title</b>";
if ($item_price != 0.00) $priceVal = true;
$priceSpan = "<span>";
$qcolSpan = 1;
if ($schedule_prices == 'N') {
$priceSpan = "<span style='visibility: hidden'>";
$qcolSpan = 3;
}
$readonlyflag = "";
if (strlen($readonly)) $readonlyflag = "readonly";
?>
<tr<?php echo($itemStyle) ?> class='<?php echo($heading_class) ?>'>
<td width='80%' align='left' valign='top' class='oitem'><?php echo("<span class='item-title-title' rflag='$readonlyflag' code='$curr_code' mcode='$menu_code' menu-num='$menu_num' item-num='$curr_item_num'>$item_title</span>$item_availability$rating_image") ?><?php echo($nutrition_image) ?><?php echo("$image_link$item_description$options_code") ?></td>
<td width='4%' colspan='<?php echo($qcolSpan) ?>' align='right' valign='top' class='oitem'><?php echo($qfield) ?></td>
<?php if ($schedule_prices != 'N') { ?>
<td width='8%' align='right' valign='top' class='oitem'><nobr><span class='item-price' <?php echo("rflag='$readonlyflag' code='$curr_code' mcode='$menu_code'"); ?>><?php echo($priceSpan) ?><?php echo($item_price_d) ?></span></span></nobr></td>
<td width='12%' align='right' valign='top' class='oitem'><?php echo($priceSpan) ?><span id='<?php echo($linespan) ?>'>
<?php
if ($line_total != '0') {
echo($school_record['currency_symbol'] . $line_total);
}
else {
echo("<img src='images/spacer.gif' width='35' height='1'>");
}
?></span></span>
<?php } else { ?>
<span style='visibility: hidden' id='<?php echo($linespan) ?>'></span>
<?php } ?>
<?php
$curr_price = $item_price;
if (isset($selected_item_price)) $curr_price = $selected_item_price;
$display_title = str_replace("'","&apos;",strip_tags($item_title));
$ItemTitle = str_replace('"',"&quot;",$item_title);
?>
<input type='hidden' name='<?php echo($pricefield) ?>' id='<?php echo($pricefield) ?>' value='<?php echo($curr_price) ?>'>
<input type='hidden' name='<?php echo($linetotal) ?>' id='<?php echo($linetotal) ?>' value='<?php echo($line_total) ?>'>
<input type='hidden' name='<?php echo($linecount) ?>' id='<?php echo($linecount) ?>' value='<?php echo($qtyvalue) ?>'>
<input type='hidden' name='<?php echo($minqty) ?>' id='<?php echo($minqty) ?>' mcode='<?php echo($curr_code) ?>' class='minimum-qty' value='<?php echo($min_quantity) ?>'>
<input type='hidden' name='<?php echo($warnqty) ?>' id='<?php echo($warnqty) ?>' value='<?php echo($warn_quantity) ?>'>
<input type='hidden' name='<?php echo($maxqty) ?>' id='<?php echo($maxqty) ?>' value='<?php echo($max_quantity) ?>'>
<input type='hidden' name='<?php echo($maxqty_by) ?>' id='<?php echo($maxqty_by) ?>' value='<?php echo($max_quantity_by) ?>'>
<input type='hidden' name='<?php echo($family_qty) ?>' id='<?php echo($family_qty) ?>' value='<?php echo($family_quantity) ?>'>
<input type='hidden' name='item_title_<?php echo($item_num) ?>' id='item_title_<?php echo($item_num) ?>' value="<?php echo($ItemTitle) ?>">
<input type='hidden' name='<?php echo($titlefield) ?>' id='<?php echo($titlefield) ?>' value="<?php echo($display_title) ?>">
</td>
</tr>
<?php
}
else {
$control = "<span hnum='$item_num' mode='visible' id='header-$item_num' class='header-controls'>[".getLanguageText('TEXT-HIDE-LOWERCASE')."]</span>";
if ($heading_visibility == 'hidden') {
$control = "<span hnum='$item_num' mode='hidden' id='header-$item_num' class='header-controls'>[".getLanguageText('TEXT-SHOW-LOWERCASE')."]</span>";
}
?>
<tr height='25'<?php echo($rowStyle) ?> class='menu-subheading'>
<td colspan='4' width='100%' align='left' valign='middle' class='menudate-subheader'>
&nbsp;&nbsp;&nbsp;&nbsp; <?php
if (strlen($item_title)) echo("-- $item_title -- $control");
echo($item_description);
?>
</td>
</tr>
<?php
}
}
if ($item_count > 0) {
extract($MenuTotals);
$currRowStyle = $rowStyle;
if ($priceVal == false) $currRowStyle = " class='invisible'";
?>
<tr<?php echo($currRowStyle) ?>>
<td colspan='3'>&nbsp;</td>
<td align='right' class='oitem'><span id='<?php echo($menuspan) ?>'><?php if ($menu_total > 0.00) echo($school_record['currency_symbol'] . $menu_total) ?></span>
<input type='hidden' name='<?php echo($menutotal) ?>' id='<?php echo($menutotal) ?>' value='<?php echo(trimNumber($menu_total)) ?>'>
<input type='hidden' name='<?php echo($menucount) ?>' id='<?php echo($menucount) ?>' value='<?php echo(trimNumber($menu_count)) ?>'>
</td>
</tr>
<?php
}
if (count($MenuVolunteers) > 0) {
extract($MenuVolunteers);
if (strlen($volunteerMessage) > 0) {
if ($numRegistered < $maxVolunteers || $vnum > 0) {
$vfont = $school_record['volunteer_msg_font'];
$vcolor = $school_record['volunteer_msg_color'];
if (strlen($vfont)) $vfont = " style='font: $vfont;'";
if (strlen($vcolor)) $vcolor = " style='background: #$vcolor;'";
?>
<tr<?php echo($rowStyle) ?>>
<td align='center' colspan='4'>
<table width='100%' cellspacing='0' cellpadding='3' border='0'>
<tr>
<td align='left' valign='top' class='signup'<?php echo($vcolor) ?>>
<span class='signup-text'<?php echo($vfont) ?>><b><?php echo(nl2br($volunteerMessage)) ?></b></span>
</td>
<td align='center' valign='top' class='signup'<?php echo($vcolor) ?>><?php echo($vField) ?></td>
</tr>
</table>
</td>
</tr>
<?php
}
}
}
?>
<tr<?php echo($rowStyle) ?>>
<td colspan='4'>&nbsp;</td>
</tr>
<?php
}
?>
</table>
<?php
}
$ordersubtotal = $ordertotal;
if (isset($discount_amount) && $discount_amount > 0) $ordertotal = $ordertotal - $discount_amount;
// Table for footer fields and buttons
?>
<table width='90%' cellpadding='1' cellspacing='1' border='0'>
<?php
if ($implement_order_notes == 'Y') {
?>
<tr>
<td colspan='2' align='left' class='oitem'>
<b><?php echo($order_notes_message) ?>::</b><br>
<?php
if (!isset($order_notes)) $order_notes = '';
if ($form_edit_mode == "edit") {
?>
<textarea name='order_notes' rows='2' cols='100'><?php echo($order_notes) ?></textarea>
<?php
}
else {
echo(nl2br($order_notes));
}
?>
</td>
</tr>
<tr>
<td colspan='2'>&nbsp;</td>
</tr>
<?php
}
if ($implement_order_notes2 == 'Y') {
?>
<tr>
<td colspan='2' align='left' class='oitem'>
<b><?php echo($order_notes_message2) ?>::</b><br>
<?php
if (!isset($order_notes2)) $order_notes2 = '';
if ($form_edit_mode == "edit") {
?>
<textarea name='order_notes2' rows='2' cols='100'><?php echo($order_notes2) ?></textarea>
<?php
}
else {
echo(nl2br($order_notes2));
}
?>
</td>
</tr>
<tr>
<td colspan='2'>&nbsp;</td>
</tr>
<?php
}
?>
<?php if (isset($apply_late_charge) && $apply_late_charge == 'Y' && $_SESSION['UserInfo']['type'] != 'Parent' && $_SESSION['UserInfo']['type'] != 'Staff') { ?>
<tr>
<td align='right' class='oitem'><b><?php displayLanguageText('TEXT-APPLY-LATE-CHARGE'); ?> $<?php echo($late_charge) ?>:: </b></td>
<td align='center' class='oitem'><input type='checkbox' name='apply_late_charge' value='Y' checked='checked'></td>
</tr>
<?php } ?>
<?php if ($numDiscounts > 0) { ?>
<tr>
<td align='right' class='oitem'><b><?php displayLanguageText('TEXT-DISCOUNT'); ?>: </b></td>
<td align='right' class='oitem'><span id='discountspan'><?php if ($discount_amount > 0) echo($school_record['currency_symbol'] . number_format($discount_amount,2)) ?></span></td>
<input type='hidden' name='discount_amount' id='discount_amount' value='<?php echo(trimNumber($discount_amount)) ?>'></td>
</tr>
<?php } ?>
<?php if ($schedule_prices != 'N') { ?>
<tr>
<td width='92%' align='right' class='oitem'><b><?php displayLanguageText('TEXT-ORDER-TOTAL'); ?>: </b></td>
<td width='8%' align='right' class='oitem'><span id='orderspan'><?php if ($ordertotal > 0.00) echo($school_record['currency_symbol'] . number_format($ordertotal,2)) ?></span></td>
</tr>
<?php } ?>
</table>
<span id='orderspan' style='visibility: hidden'></span>
<input type='hidden' name='ordersubtotal' id='ordersubtotal' value='<?php echo(trimNumber($ordersubtotal)) ?>'>
<input type='hidden' name='ordertotal' id='ordertotal' value='<?php echo(trimNumber($ordertotal)) ?>'>
</td>
</tr>
<tr>
<td align='center'>
<br>
<?php
// Display schedule documents
$schedule_docs = db_query("SELECT d.* FROM hotlunch_schedules_documents AS hlsd, documents AS d " .
"WHERE hlsd.school_num = $school_num " .
"AND hlsd.schedule_num = $schedule_num " .
"AND hlsd.document_num = d.record_num " .
"ORDER BY sequence");
if (db_num_rows($schedule_docs)) {
$view_icon = "<img src='images/icons/filesearch24.png' alt='View Document' border='0'>";
$startTable = " <table width='50%' cellpadding='0' cellspacing='1' class='content-table'>\n";
$numDocs = 0;
while ($row = db_fetch_array($schedule_docs)) {
$doc_num = $row['record_num'];
$query = "select * from documents " .
"where school_num = $school_num " .
"and record_num = $doc_num";
$results = db_query($query);
if (db_num_rows($results)) {
$r = db_fetch_array($results);
$fname = $r['file_name'];
$doc_title = "<b>" . $row['title'] . "</b>";
if (strlen($row['description'])) $doc_title .= "<br>\n" . $row['description'];
$link = "<a href='view-doc.php?dnum=$doc_num'>$view_icon</a>";
echo($startTable);
echo(" <tr>\n");
echo(" <td width='90%' class='oitem' align='left' valign='top'>$doc_title</td>\n");
echo(" <td class='oitem' align='center' valign='top'>$link</td>\n");
echo(" </tr>\n");
$startTable = "";
$numDocs++;
}
}
if ($numDocs > 0) {
echo(" </table>\n");
echo(" <br>\n");
}
}
if ($form_edit_mode == "edit") {
if (isset($defaultOrder)) {
$classes = db_query("SELECT * FROM classes WHERE school_num = $base_school_num ORDER BY sequence");
$numRows = db_num_rows($classes);
if ($numRows > 10) $numRows = 10;
?>
<select name='selected_classes[]' multiple size='<?php echo($numRows) ?>'>
<?php
while ($row = db_fetch_assoc($classes)) {
$classInfo = getClassInfo($row['record_num']);
echo("<option value='".$row['record_num']."'>$classInfo</option>\n");
}
?>
</select>
<br>
<br>
<?php
}
?>
<table cellpadding='5' cellspacing='2' border='0'>
<tr>
<td align='center'><input type='submit' id='submit_button' class='btn btn--primary' tabindex=<?php echo($tabindex) ?> value="<?php echo($ButtonText) ?>"></td>
<?php if (isset($ordered_by_num)) { ?>
<td align='center'><a href='/' class='btn btn--primary>'><?php displayLanguageText('TEXT-CANCEL-CHANGES'); ?></a></td>
<?php } else { ?>
<td align='center'><a href='/' class='btn btn--primary>'><?php displayLanguageText('TEXT-CANCEL-ORDER'); ?></a></td>
<?php } ?>
</tr>
</table>
<input type='hidden' name='action' value='<?php echo($action) ?>'>
<input type='hidden' name='naction' value='<?php echo($next_naction) ?>'>
<input type='hidden' name='paction' value='<?php echo($paction) ?>'>
<input type='hidden' name='schedule_num' value='<?php echo($schedule_num) ?>'>
<input type='hidden' name='student_num' id='student_num' value=''>
<input type='hidden' name='people_type' id='people_type' value=''>
<input type='hidden' name='existing_user_num' id='user_num' value=''>
<?php if ($_SESSION['UserInfo']['type'] == 'Parent' || $_SESSION['UserInfo']['type'] == 'Staff') { ?>
<?php if (!isset($apply_late_charge)) $apply_late_charge = 'N'; ?>
<input type='hidden' name='apply_late_charge' id='apply_late_charge' value='<?php echo($apply_late_charge) ?>'>
<?php } ?>
<?php if (isset($source)) { ?>
<input type='hidden' name='source' id='source' value='<?php echo($source) ?>'>
<?php } ?>
<?php if (isset($defaultOrder)) { ?>
<input type='hidden' name='defaultOrder' id='defaultOrder' value='<?php echo($defaultOrder) ?>'>
<?php } ?>
<?php if (isset($ordered_by_num)) { ?>
<?php if (!isset($name)) $name = ''; ?>
<input type='hidden' name='ordered_by_num' id='ordered_by_num' value='<?php echo($ordered_by_num) ?>'>
<input type='hidden' name='ordered_by_name' id='ordered_by_name' value='<?php echo($name) ?>'>
<input type='hidden' name='ordered_by_type' id='ordered_by_type' value='<?php echo($ordered_by_type) ?>'>
<input type='hidden' name='curr_ordered_by_type' id='curr_ordered_by_type' value='<?php echo($ordered_by_type) ?>'>
<input type='hidden' name='order_num' id='order_num' value='<?php echo($order_num) ?>'>
<input type='hidden' name='source' id='source' value='<?php echo($source) ?>'>
<input type='hidden' name='price_category' id='price_category' value='<?php echo($menu_price_category) ?>'>
<?php } else { ?>
<input type='hidden' name='ordered_by_type' id='ordered_by_type' value=''>
<input type='hidden' name='curr_ordered_by_type' id='curr_ordered_by_type' value=''>
<input type='hidden' name='order_num' id='order_num' value='0'>
<?php
}
}
?>
<br>
<br>
</td>
</tr>
</table>
</form>
<?php
// Include search and lookup code
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team');
if (checkPermission($AllowedUserTypes) == 1) include "hotlunch_orders.print_buttons.php";
?>
New
<script language="JavaScript">
<?php echo($global_code) ?>
<?php
if ($linked_items == 'Y') {
?>
// Function to update the linked menu dates
function updateLinkedItems(code) {
<?php echo($menu_items_code) ?>
}
// Function to update all linked items
function updateAllLinkedItems() {
<?php echo($all_menu_items_code) ?>
}
<?php
}
?>
// Function to validate the quantities based on the group rules
function groupCheck(code, mcode) {
<?php echo($group_check_code) ?>
return;
}
// Function to validate the menu options
function checkOptions(code, mcode, sname) {
<?php // if ($_SESSION['UserInfo']['type'] == 'SuperUser' || $user_ip == "23.16.142.243") echo("alert('checkOptions');"); ?>
<?php echo($menu_options_code) ?>
updateLine(code, mcode,'Y','Y');
return true;
}
<?php if ($numDiscounts > 0) { ?>
// Function to calculate form discounts
function calculateDiscount(ordersubtotal) {
var groupQtyTotal = 0;
var discountRate = 0;
var discountAmt = 0;
<?php
foreach ($groupQtyFields as $groupCode => $val) {
echo(" // Calculate the discount amount for group '$groupCode'\n");
echo(" groupQtyTotal = 0;\n");
$fields = explode(" ",trim($val));
for ($i = 0; $i < count($fields); $i++) {
$field = $fields[$i];
echo(" if (document.getElementById('$field').value) groupQtyTotal = groupQtyTotal + parseInt(document.getElementById('$field').value);\n");
}
echo("\n");
$results = db_query("SELECT * FROM hotlunch_schedules_discounts " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND menu_group = '$groupCode' " .
"AND (expiry_date IS NULL OR expiry_date >= '$today') " .
"ORDER BY order_quantity");
while ($row = db_fetch_array($results)) {
extract($row);;
if ($discount_percentage > 0 && $discount_amount == 0) echo(" if (groupQtyTotal >= $order_quantity) discountRate = $discount_percentage;\n");
if ($discount_amount > 0 && $discount_percentage == 0) echo(" if (groupQtyTotal >= $order_quantity) discountAmt = $discount_amount;\n");
}
}
?>
document.getElementById('discount_amount').value = 0;
document.getElementById('discountspan').innerHTML = formatCurrency(0);
if (discountRate > 0) {
discountAmount = ordersubtotal * discountRate / 100;
document.getElementById('discount_amount').value = discountAmount;
document.getElementById('discountspan').innerHTML = formatCurrency(discountAmount);
}
if (discountAmt > 0) {
document.getElementById('discount_amount').value = discountAmt;
document.getElementById('discountspan').innerHTML = formatCurrency(discountAmt);
}
}
<?php } ?>
// Function to validate the form data
function checkForm() {
var checkFormMissedDatesMessage = '';
var checkFormMissedOptionsMessage = '';
var actionMessage = "<?php displayLanguageText('MESSAGE-CONFIRM-ACTION'); ?>";
var noItemsMessage = "<?php displayLanguageText('MESSAGE-NO-ITEMS-SELECTED'); ?>";
var textMenus = "<?php displayLanguageText('TEXT-MENUS'); ?>";
var missedMenuCount = 0;
var maxMenuCount = 5;
const fname_field = document.querySelector('#new_first_name');
const otype_field = document.querySelector('#curr_ordered_by_type');
if (fname_field && otype_field) {
var new_first_name = document.getElementById('new_first_name').value;
var ordered_by_type = document.getElementById('curr_ordered_by_type').value;
if (ordered_by_type.length == 0 && new_first_name.length == 0) {
alert("<?php displayLanguageText('ERRORMSG-STUDENT-INFORMATION-MISSING'); ?>");
return false;
}
}
// Check that any groups have been completed
<?php echo($group_complete_code) ?>
// Check that all menu dates have been entered
<?php echo($form_check_code) ?>
// Check for minimum order quantities
const minimums = document.querySelectorAll('.minimum-qty');
var qtyError = false;
minimums.forEach(min => {
var id = min.getAttribute('id');
var min_qty = min.value;
if (min_qty > 0) {
var curr_code = min.getAttribute('mcode');
const qtyfield = document.getElementById('qty_'+curr_code);
const titlefield = document.getElementById('title_'+curr_code);
var qtyordered = qtyfield.value;
var item_title = titlefield.value;
if (qtyordered < min_qty) {
alert("<?php displayLanguageText('JAVA-MIN-ORDER-LIMIT'); ?> "+min_qty+" - "+item_title);
qtyError = true;
}
}
});
if (qtyError) return false;
if (checkFormMissedDatesMessage.length > 0) {
var additionalMenus = missedMenuCount - maxMenuCount;
checkFormMissedDatesMessage = noItemsMessage+' '+missedMenuCount+' '+textMenus+':\n---------------------------------------------\n'+checkFormMissedDatesMessage;
if (additionalMenus > 0) {
checkFormMissedDatesMessage = checkFormMissedDatesMessage+'------ <?php displayLanguageText('TEXT-AND') ?> '+additionalMenus+' <?php displayLanguageText('TEXT-OTHER-MENUS') ?> ------\n';
}
checkFormMissedDatesMessage = checkFormMissedDatesMessage+'---------------------------------------------\n'+actionMessage;
var r1 = confirm(checkFormMissedDatesMessage);
if (r1 == false) return false;
}
if (checkFormMissedOptionsMessage.length > 0) {
// var r2 = confirm(checkFormMissedOptionsMessage);
// if (r2 == false) return false;
alert(checkFormMissedOptionsMessage);
return false;
}
<?php if ($school_record['order_confirmation_pop_up'] == 'Y') { ?>
var ordertotal = document.getElementById('orderspan').innerHTML;
if (ordertotal == '') ordertotal = "$0.00";
var ans = confirm("<?php displayLanguageText('TEXT-CONFIRM-ORDER'); ?>: "+ordertotal);
if (ans == false) return false;
<?php } ?>
// document.getElementById('submit_button').disabled = true;
return true;
}
</script>
<script type="text/javascript">
// JQuery ready
jQuery(function($) {
calcForm();
$(".item-options-span").each(function() {
$(this).hide();
});
$(".item-options-ordered-span").each(function() {
$(this).show();
});
// Update all checkbox lines
var ordered_by_type = $('#curr_ordered_by_type').val();
$(".qty-checkbox").each(function() {
var code = $(this).attr('curr_code');
var mcode = $(this).attr('menu_code');
var gcheck = $(this).attr('gcheck');
var qtest = $(this).attr('qtest');
qtest = 'L';
updateCheckboxLine(code, mcode, gcheck, qtest);
});
$("#hide-all-options-link").hide();
$("#view-all-options-link").click(function(e) {
e.preventDefault();
$(".item-options-span").each(function() {
$(this).show();
});
$("#view-all-options-link").hide();
$("#hide-all-options-link").show();
});
$("#hide-all-options-link").click(function(e) {
e.preventDefault();
$(".item-options-span").each(function() {
$(this).hide();
});
$("#view-all-options-link").show();
$("#hide-all-options-link").hide();
});
var studentCellWidths = [150, 150, 105, 70];
for (i=0; i<studentCellWidths.length; i++) $('#studentResultsHead th').eq(i).css('width', studentCellWidths[i]);
var parentCellWidths = [110, 150, 215];
for (i=0; i<parentCellWidths.length; i++) $('#parentResultsHead th').eq(i).css('width', parentCellWidths[i]);
// Hide everything by default
var studentSearch = $('#new_last_name');
var studentResultsRow = $('#studentResultsRow').hide();
var studentResultsTable = $('#studentResultsTable');
var studentResultsScroll = $('#studentResultsScroll');
var selectedStudent = null;
var selectedParent = null;
var parentSearch = $('#new_parent_last_name');
var parentResultsRow = $('#parentResultsRow').hide();
var parentResultsTable = $('#parentResultsTable');
var parentResultsScroll = $('#parentResultsScroll');
// Handle typing in the student search box
studentSearch.keyup(function() {
var searchName = $(this).val();
if (searchName.length < 2) {
doStudentClick(null);
return;
}
var d = new Date();
searchName = escape(searchName);
$.getJSON('/ajaxSearchStudents.php', {s:searchName, sn:<?php echo($school_num) ?>, bn:<?php echo($base_school_num) ?>, sch:<?php echo($schedule_num) ?>, d:d.getTime()}, updateStudentResults);
});
function updateStudentResults(data) {
var row;
var radio;
if (data.length == 0) {
doStudentClick(null);
return;
}
// empty the results table, and rebuild it
studentResultsTable.empty();
// add the 'new student' row
row = $('<tr>');
row.append($('<td align=left colspan=4>').html('<b><i> - <?php displayLanguageText('TEXT-ENTER-A-NEW-STUDENT'); ?> - </i></b>')).addClass('newStudent');
studentResultsTable.append(row);
for (var i=0; i<data.length; i++) {
data[i]['name'] = unescape(data[i]['name']);
row = $('<tr>');
row.append($('<td align=left>').css('width', studentCellWidths[0]).html(decodeURIComponent( escape( data[i]['name'] ) )));
row.append($('<td align=left>').css('width', studentCellWidths[1]).html(data[i]['parent']==''?'&nbsp;':unescape(decodeURIComponent( data[i]['parent'] ))));
row.append($('<td align=left>').css('width', studentCellWidths[2]).html(data[i]['phone']==''?'&nbsp;':data[i]['phone']));
row.append($('<td align=center>').css('width', studentCellWidths[3]).html(data[i]['hasOrder']?'Yes':'No'));
if (data[i]['hasOrder']) {
row.addClass('hasOrder');
row.find('td').css('fontStyle','italic');
}
row.data('info', data[i]);
studentResultsTable.append(row);
}
// treat a click anywhere on the row as a click on the radio button
$('#studentResultsTable tr *').css('cursor','pointer').click(function() {
doStudentClick($(this).closest('tr'));
});
// display results, if the height > 150px, setup autoscroll
studentResultsScroll.css('overflow','visible').css('height', 'auto');
studentResultsRow.show();
if (studentResultsScroll.height() > 150) studentResultsScroll.css('overflow','auto').css('height', 150);
updateStudentValues(null, false);
$('#new_first_name').removeAttr('disabled').removeClass('disabled');
}
function doStudentClick(row) {
if (row == null) {
selectedStudent = null;
updateStudentValues(null, false);
doParentClick(null);
if (studentSearch.val() != '') $('#new_first_name').removeAttr('disabled').removeClass('disabled');
}
else if (row == 0 || row.hasClass('newStudent')) {
// entering a new student
selectedStudent = 0;
updateStudentValues(null, true);
$('#new_first_name')[0].focus();
$('#student_num').val(0);
parentSearch.val(studentSearch.val()).keyup();
}
else if (row.hasClass('hasOrder')) {
data = row.data('info');
if (confirm("<?php displayLanguageText('TEXT-EDIT-EXISTING-ORDER'); ?>")) {
location.href= '/?action=orders&naction=edit&schedule_num=<?php echo($schedule_num) ?>&student_num=' + data['record_num'];
exit;
}
}
else {
// clicked on a student
data = row.data('info');
// if (data['price_category'] != 'Regular') location.href= '/?action=orders&naction=edit&schedule_num=<?php echo($schedule_num) ?>&student_num=' + data['record_num'];
location.href= '/?action=orders&naction=edit&schedule_num=<?php echo($schedule_num) ?>&student_num=' + data['record_num'];
selectedStudent = data['record_num'];
// updateStudentValues(data, false);
// $('#student_num').val(data['record_num']);
// $('#user_num').val(data['user']['record_num']);
// $('#people_type').val(data['people_type']);
// $('#new_last_name').val(data==null?'':unescape(decodeURIComponent( data['last_name'] )));
location.href= '/?action=orders&naction=add&schedule_num=<?php echo($schedule_num) ?>&student_num=' + data['record_num'];
exit;
}
studentResultsRow.hide();
studentResultsTable.empty();
}
function updateStudentValues(data, enabled) {
if (data != null) studentSearch.val(data['last_name']);
$('#new_first_name').val(data==null?'':unescape(decodeURIComponent( data['first_name'] )));
$('#new_class_num').val(data==null?'':data['class_num']);
$('#age').val(data==null?'':unescape(data['age']));
$('#grade').val(data==null?'':unescape(data['grade']));
$('#sex').val(data==null?'':unescape(data['sex']));
$('#user_defined_value').val(data==null?'':unescape(data['user_defined_value']));
$('#new_parent_last_name').val(data==null?'':unescape(decodeURIComponent( data['user']['last_name'] )));
$('#new_parent_first_name').val(data==null?'':unescape(decodeURIComponent( data['user']['first_name'] )));
$('#new_email').val(data==null?'':data['user']['email']);
$('#new_phone').val(data==null?'':data['user']['home_phone']);
$('#ordered_by_type').val(data==null?'':data['people_type']);
if (enabled) {
$('#new_first_name').removeAttr('disabled').removeClass('disabled');
$('#new_class_num').removeAttr('disabled').removeClass('disabled');
$('#new_parent_last_name').removeAttr('disabled').removeClass('disabled');
parentSearch.keyup();
}
else {
$('#contactInfoRow').hide();
parentResultsRow.hide();
parentResultsTable.empty();
}
}
$('#new_first_name').focus(function() {
if (selectedStudent == null) doStudentClick(0);
studentResultsRow.hide();
studentResultsTable.empty();
});
doStudentClick(null);
// Handle typing in the student search box
parentSearch.keyup(function() {
var searchName = $(this).val();
if (searchName.length < 2) {
doParentClick(null);
return;
}
var d = new Date();
searchName = escape(searchName);
$.getJSON('/ajaxSearchParents.php', {s:searchName, sn:<?php echo($base_school_num) ?>, sch:<?php echo($schedule_num) ?>, d:d.getTime()}, updateParentResults);
});
function updateParentResults(data) {
var row;
var radio;
if (data.length == 0) {
doParentClick(null);
return;
}
// empty the results table, and rebuild it
parentResultsTable.empty();
// add the 'new user' row
row = $('<tr>');
row.append($('<td align=left colspan=4>').html('<b><i> - Enter A New Parent - </i></b>')).addClass('newParent');
parentResultsTable.append(row);
for (var i=0; i<data.length; i++) {
row = $('<tr>');
row.append($('<td align=left>').css('width', parentCellWidths[0]).html(unescape(data[i]['account'])));
row.append($('<td align=left>').css('width', parentCellWidths[1]).html(data[i]['name']==''?'&nbsp;':unescape(decodeURIComponent( data[i]['name'] ))));
row.append($('<td align=left>').css('width', parentCellWidths[2]).html(data[i]['email']==''?'&nbsp;':data[i]['email']));
row.data('info', data[i]);
parentResultsTable.append(row);
}
// treat a click anywhere on the row as a click on the radio button
$('#parentResultsTable tr *').css('cursor','pointer').click(function() {
doParentClick($(this).closest('tr'));
});
// display results, if the height > 150px, setup autoscroll
parentResultsScroll.css('overflow','visible').css('height', 'auto');
parentResultsRow.show();
if (parentResultsScroll.height() > 150) parentResultsScroll.css('overflow','auto').css('height', 150);
updateParentValues(null, false);
$('#new_parent_first_name').removeAttr('disabled').removeClass('disabled');
}
function doParentClick(row) {
if (row == null) {
selectedParent = null;
updateParentValues(null, false);
if (parentSearch.val() != '') $('#new_parent_first_name').removeAttr('disabled').removeClass('disabled');
}
else if (row == 0 || row.hasClass('newParent')) {
// entering a new parent/user
selectedParent = 0;
updateParentValues(null, true);
$('#new_parent_first_name')[0].focus();
$('#user_num').val(0);
} else {
// clicked on a user
data = row.data('info');
selectedParent = data['record_num'];
updateParentValues(data, false);
$('#user_num').val(data['record_num']);
$('#new_parent_last_name').val(data==null?'':unescape(data['last_name']));
}
parentResultsRow.hide();
parentResultsTable.empty();
}
function updateParentValues(data, enabled) {
if (data != null) parentSearch.val(data['last_name']);
$('#new_parent_first_name').val(data==null?'':unescape(data['first_name']));
$('#new_email').val(data==null?'':data['email']);
$('#new_phone').val(data==null?'':data['home_phone']);
if (enabled) {
$('#new_parent_first_name').removeAttr('disabled').removeClass('disabled');
$('#new_email').removeAttr('disabled').removeClass('disabled');
$('#new_phone').removeAttr('disabled').removeClass('disabled');
$('#contactInfoRow').show();
}
else {
// $('#new_parent_first_name').attr('disabled','disabled').addClass('disabled');
// $('#new_phone').attr('disabled','disabled').addClass('disabled');
// $('#new_email').attr('disabled','disabled').addClass('disabled');
$('#contactInfoRow').hide();
}
}
$('#new_parent_first_name').focus(function() {
if (selectedParent == null) doParentClick(0);
});
$(document).on('click', '.header-controls', function(e) {
e.preventDefault();
var hnum = $(this).attr('hnum');
var mode = $(this).attr('mode');
if (mode == 'visible') {
$(".header-"+hnum).hide();
$(this).attr('mode','hidden');
$(this).html("[<?php displayLanguageText('TEXT-SHOW-LOWERCASE'); ?>]");
}
if (mode == 'hidden') {
// $(".header-"+hnum).show();
$(".header-"+hnum).each(function() {
$(this).show();
$(this).removeClass('hidden-item');
});
$(this).attr('mode','visible');
$(this).html("[<?php displayLanguageText('TEXT-HIDE-LOWERCASE'); ?>]");
}
});
$(document).on('click','.item-title',function(e) {
var code = $(this).attr('code');
var mcode = $(this).attr('mcode');
var rflag = $(this).attr('rflag');
var qty = $("#qty_"+code).val();
var nqty = Math.abs(qty) + 1;
var menu_num = $(this).attr('menu-num');
var item_num = $(this).attr('item-num');
if (rflag == 'readonly') return;
$("#qty_"+code).val(nqty);
if (nqty > 0) showOptions(menu_num, item_num);
else hideOptions(menu_num, item_num);
updateLine(code,mcode,'Y','Y');
});
$(document).on('click','.item-qty-down',function(e) {
var code = $(this).attr('code');
var mcode = $(this).attr('mcode');
var rflag = $(this).attr('rflag');
var qty = $("#qty_"+code).val();
var nqty = Math.abs(qty) - 1;
var menu_num = $(this).attr('menu-num');
var item_num = $(this).attr('item-num');
if (rflag == 'readonly') return;
if (nqty >= 0) {
$("#qty_"+code).val(nqty);
if (updateLine(code,mcode,'Y','Y')) {
if (nqty == 0) {
$("#qty_"+code).val('');
hideOptions(menu_num, item_num);
}
}
}
});
//
// JQuery code to manage forms
//
var schedule_num = <?php echo($schedule_num) ?>;
$(".info-span").hide();
$("#new_last_name").focus();
// Checkbox click
$(document).on("click", ".qty-checkbox", function(e) {
var menu_num = $(this).attr('menu-num');
var item_num = $(this).attr('item-num');
var item_title = $("#item_title_"+item_num).val();
var qtyfield = $(this).attr('qtyfield');
var qty = $("#"+qtyfield).val();
if (qty > 0) showOptions(menu_num, item_num);
else hideOptions(menu_num, item_num);
});
// Quantity field change
$(document).on("change", ".qty-field", function(e) {
var menu_num = $(this).attr('menu-num');
var item_num = $(this).attr('item-num');
var item_title = $("#item_title_"+item_num).val();
var qty = $(this).val();
if (qty > 0) showOptions(menu_num, item_num);
else hideOptions(menu_num, item_num);
});
$(document).on("click", ".menu-item-title", function(e) {
e.preventDefault();
var menu_num = $(this).attr('menu-num');
var item_num = $(this).attr('item-num');
var item_title = $(this).html();
showOptions(menu_num, item_num);
});
function showOptions(menu_num, item_num) {
var options_span = schedule_num+'_'+menu_num+'_'+item_num;
var has_options = $("#has-options-"+item_num).val();
if (has_options == 'N') return;
$("#"+options_span).show();
}
function hideOptions(menu_num, item_num) {
var options_span = schedule_num+'_'+menu_num+'_'+item_num;
var has_options = $("#has-options-"+item_num).val();
if (has_options == 'N') return;
$("#"+options_span).hide();
}
$(document).on("change", ".item-option", function(e) {
var id = $(this).attr('id');
var cbid = $(this).attr('id');
var checked = $("#"+cbid).prop("checked");
var save_id = id.substring(1);
var num_options = $("#options_selected").val();
var inum = $(this).attr('inum');
var opt_set = $(this).attr('opt_set');
var qty = $("#set-"+inum+"-"+opt_set).val();
var max_qty = $(this).attr('set_max');
var opt_title = $("#title-"+inum+"-"+opt_set).val();
var optionf = $(this).attr('optionf');
num_options = qty;
var msg = "** <?php displayLanguageText('TEXT-YOU-MAY-NOT-SELECT-MORE-THAN') ?> "+max_qty+" "+opt_title;
var numChecked = 0;
var oClass = "option-"+inum+"-"+opt_set;
var cID = $(this).attr('id');
var oID;
var opt_max = $(this).attr('set_max');
$("."+oClass).each(function() {
oID = $(this).attr('id');
if ($('#'+oID).is(':checked')) {
numChecked = numChecked + 1;
}
});
if (opt_max > 0 && numChecked > opt_max) {
alert(msg);
$('#'+cID).prop('checked',false);
return(false);
}
});
$(document).on('click', '.item-option-span', function() {
var cbid = $(this).attr('cbid');
var inum = $(this).attr('inum');
var opt_set = $(this).attr('opt_set');
var qty = $("#set-"+inum+"-"+opt_set).val();
var checked = $("#"+cbid).prop("checked");
var max_qty = $(this).attr('set_max');
var opt_title = $("#title-"+inum+"-"+opt_set).val();
var msg = "* <?php displayLanguageText('TEXT-YOU-MAY-NOT-SELECT-MORE-THAN') ?> "+max_qty+" "+opt_title;
if (checked) {
$("#"+cbid).prop("checked", false);
qty = Math.abs(qty) - 1;
$("#set-"+inum+"-"+opt_set).val(qty);
}
else {
qty = Math.abs(qty) + 1;
if (max_qty > 0 && qty > max_qty) {
alert(msg);
}
else {
$("#"+cbid).prop("checked", true);
$("#"+cbid).prop("checked", true);
$("#set-"+inum+"-"+opt_set).val(qty);
}
}
});
$(".qty-field").tooltip({
position: { my: "left+5 top+5", at: "left bottom", collision: "flipfit" },
show: { effect: "fade", delay: 200 },
hide: false,
content: function() { return $(this).prop('title'); }
});
$(".qty-checkbox").tooltip({
position: { my: "left+5 top+5", at: "left bottom", collision: "flipfit" },
show: { effect: "fade", delay: 200 },
hide: false,
content: function() { return $(this).prop('title'); }
});
function calcForm() {
$(".qty-field").each(function() {
var qty = $(this).val();
var currCode = $(this).attr('curr-code');
var menuCode = $(this).attr('menu-code');
var ftype = $(this).attr('field-type');
if (ftype == 'qty') {
updateLine(currCode,menuCode,'Y','Y');
}
});
}
});
// Multiple Item Pricing Code
$(document).on('change', '.alternate-prices', function() {
var field_code = $(this).attr('curr_code');
var qty = $("#qty_"+field_code).val();
var price = $(this).val();
var price_field = "#price_" + field_code;
var cb = "#cb_"+field_code;
var mcode = $(this).attr('mcode');
var item_format = $(this).attr('item-format');
$(price_field).val(price);
if (item_format == 'Checkbox') {
$(cb).prop('checked',true);
updateCheckboxLine(field_code, mcode,'Y','N');
}
else {
if (qty == '' || qty == 0) $("#qty_"+field_code).val('1');
updateLine(field_code, mcode,'Y','Y');
}
});
</script>