First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
require_once("include/globals.php");
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Start the template and output buffering
|
||||
startTemplate();
|
||||
$templatePageTitle = getLanguageText('TEXT-MENU-PRODUCT-UPDATE');
|
||||
|
||||
|
||||
|
||||
// Ensure that only valid user types have access to this module
|
||||
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team');
|
||||
if (checkPermission($AllowedUserTypes) != 1) {
|
||||
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
||||
include "form.messages.php";
|
||||
endTemplate();
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Get schedule_num
|
||||
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
|
||||
if (array_key_exists('schedule_num',$_POST)) $schedule_num = intval($_POST['schedule_num']);
|
||||
|
||||
|
||||
|
||||
if (!isset($schedule_num)) {
|
||||
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE-NUM');
|
||||
include "form.messages.php";
|
||||
endTemplate();
|
||||
exit();
|
||||
}
|
||||
|
||||
// Check if this is a valid schedule
|
||||
$today = date("Y-m-d",time());
|
||||
$query = "select * from hotlunch_schedules " .
|
||||
"where record_num = $schedule_num " .
|
||||
"and school_num = $school_num";
|
||||
$results = db_query($query);
|
||||
|
||||
if (db_num_rows($results) == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE');
|
||||
include "form.messages.php";
|
||||
return;
|
||||
}
|
||||
|
||||
$hotlunch_schedule = db_fetch_array($results);
|
||||
|
||||
|
||||
// If this is a ScheduleTeam user check if they have permission to access this schedule
|
||||
if (in_array($_SESSION['UserInfo']['type'],array('Schedule Team','Schedule Volunteer'))) {
|
||||
$userNum = $_SESSION['UserInfo']['record_num'];
|
||||
$access = db_getVal("SELECT count(*) FROM hotlunch_schedules_people WHERE school_num = $school_num AND schedule_num = $schedule_num AND user_num = $userNum");
|
||||
|
||||
if (!$access || $access == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-NO-SCHEDULE-ACCESS');
|
||||
include "form.messages.php";
|
||||
endTemplate();
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Check that this schedule date has lunch dates specified
|
||||
$query = "select count(*) num from hotlunch_menu_dates " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num";
|
||||
$results = db_query($query);
|
||||
$row = db_fetch_array($results);
|
||||
if ($row['num'] == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-NO-MENU-DATES');
|
||||
include "form.messages.php";
|
||||
endTemplate();
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Check that this schedule date has lunch items specified
|
||||
$query = "select count(hotlunch_menu_items.record_num) num from hotlunch_menu_items,hotlunch_menu_dates " .
|
||||
"WHERE hotlunch_menu_items.school_num = $school_num " .
|
||||
"AND hotlunch_menu_dates.school_num = $school_num " .
|
||||
"AND hotlunch_menu_dates.record_num = hotlunch_menu_items.menu_num " .
|
||||
"AND hotlunch_menu_dates.schedule_num = $schedule_num";
|
||||
$results = db_query($query);
|
||||
$row = db_fetch_array($results);
|
||||
if ($row['num'] == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-NO-MENU-ITEMS');
|
||||
include "form.messages.php";
|
||||
endTemplate();
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Process all actions to list and edit records
|
||||
//
|
||||
$naction = "";
|
||||
|
||||
|
||||
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
||||
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
||||
|
||||
|
||||
switch (strtolower($naction)) {
|
||||
case "update":
|
||||
|
||||
// Loop through the menu dates and items and update the prices
|
||||
// Get menu dates for this schedule
|
||||
$query = "select * from hotlunch_menu_dates " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"order by sequence,menu_date";
|
||||
$menu_dates = db_query($query);
|
||||
|
||||
while ($menu_date = db_fetch_array($menu_dates)) {
|
||||
$menu_num = $menu_date['record_num'];
|
||||
$menu_link = $menu_date['menu_link'];
|
||||
|
||||
if ($menu_link != 'No') continue;
|
||||
|
||||
// Get menu items for this menu date
|
||||
$query = "select * from hotlunch_menu_items " .
|
||||
"where school_num = $school_num " .
|
||||
"and menu_num = $menu_num " .
|
||||
"order by sequence";
|
||||
$menu_items = db_query($query);
|
||||
|
||||
while ($menu_item = db_fetch_array($menu_items)) {
|
||||
extract($menu_item);
|
||||
|
||||
if ($item_type == 'Heading') continue;
|
||||
$menu_item_num = $record_num;
|
||||
|
||||
// Setup field names
|
||||
$product_field1 = "product1_$menu_item_num";
|
||||
$product_field2 = "product2_$menu_item_num";
|
||||
$product_field3 = "product3_$menu_item_num";
|
||||
|
||||
$qty_field1 = "qty1_$menu_item_num";
|
||||
$qty_field2 = "qty2_$menu_item_num";
|
||||
$qty_field3 = "qty3_$menu_item_num";
|
||||
|
||||
|
||||
$product1 = $_POST[$product_field1];
|
||||
$product2 = $_POST[$product_field2];
|
||||
$product3 = $_POST[$product_field3];
|
||||
|
||||
$qty1 = $_POST[$qty_field1];
|
||||
$qty2 = $_POST[$qty_field2];
|
||||
$qty3 = $_POST[$qty_field3];
|
||||
|
||||
if (strlen($qty1) == 0) $qty1 = 1;
|
||||
if (strlen($qty2) == 0 && strlen($product2)) $qty2 = 1;
|
||||
if (strlen($qty3) == 0 && strlen($product3)) $qty3 = 1;
|
||||
|
||||
// Update item products
|
||||
db_query("DELETE FROM hotlunch_menu_products WHERE school_num = $school_num AND menu_item_num = $menu_item_num");
|
||||
|
||||
if (strlen($product1) && $product1 > 0 && $qty1 > 0) db_query("INSERT INTO hotlunch_menu_products VALUES($school_num,$menu_item_num,1,$product1,$qty1)");
|
||||
if (strlen($product2) && $product2 > 0 && $qty2 > 0) db_query("INSERT INTO hotlunch_menu_products VALUES($school_num,$menu_item_num,2,$product2,$qty2)");
|
||||
if (strlen($product3) && $product3 > 0 && $qty3 > 0) db_query("INSERT INTO hotlunch_menu_products VALUES($school_num,$menu_item_num,3,$product3,$qty3)");
|
||||
|
||||
// Update any linked items
|
||||
$query = "SELECT * FROM hotlunch_menu_items " .
|
||||
"where school_num = $school_num " .
|
||||
"and source_item = $menu_item_num";
|
||||
$results = db_query($query);
|
||||
|
||||
while ($row = db_fetch_array($results)) {
|
||||
$menu_item_num = $row['record_num'];
|
||||
|
||||
// Update item products
|
||||
db_query("DELETE FROM hotlunch_menu_products WHERE school_num = $school_num AND menu_item_num = $menu_item_num");
|
||||
|
||||
if (strlen($product1) && $product1 > 0) db_query("INSERT INTO hotlunch_menu_products VALUES($school_num,$menu_item_num,1,$product1,$qty1)");
|
||||
if (strlen($product2) && $product2 > 0) db_query("INSERT INTO hotlunch_menu_products VALUES($school_num,$menu_item_num,2,$product2,$qty2)");
|
||||
if (strlen($product3) && $product3 > 0) db_query("INSERT INTO hotlunch_menu_products VALUES($school_num,$menu_item_num,3,$product3,$qty3)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form_message = getLanguageText('MSG-MENU-ITEMS-UPDATED');
|
||||
break;
|
||||
}
|
||||
|
||||
// Display the selected menu form
|
||||
include "hotlunch_menu.product_update.form.php";
|
||||
|
||||
endTemplate();
|
||||
?>
|
||||
Reference in new issue
Block a user