107 lines
3.1 KiB
PHP
107 lines
3.1 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
logExit("Session is not active",$moduleName);
|
|
exit();
|
|
}
|
|
|
|
// Set userType
|
|
$userType = "Parent";
|
|
if (array_key_exists('type', $_SESSION['UserInfo']) && in_array($_SESSION['UserInfo']['type'],$AllAdminUserTypes)) $userType = "Admin";
|
|
if ($userType != 'Admin') return;
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
if ($userType != 'Admin') {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
logExit($error_message);
|
|
exit;
|
|
}
|
|
|
|
|
|
// CSRF token validation
|
|
include "include/ajax.csrfToken.php";
|
|
|
|
|
|
// Set default timezone
|
|
date_default_timezone_set("Canada/Pacific");
|
|
$now = date("Y-m-d H:i:s",time());
|
|
|
|
$return_data = array();
|
|
$sequence_flag = 'N';
|
|
|
|
$moduleName = "ajax.OrderRecalculate.php";
|
|
// startLog($moduleName);
|
|
|
|
|
|
// Get parameters
|
|
if (array_key_exists('order_num', $_GET)) $order_num = intval($_GET['order_num']);
|
|
if (array_key_exists('schedule_num', $_GET)) $schedule_num = intval($_GET['schedule_num']);
|
|
if (array_key_exists('schedule_name', $_GET)) $schedule_name = db_escape_string($_GET['schedule_name']);
|
|
if (array_key_exists('student_name', $_GET)) $student_name = db_escape_string($_GET['student_name']);
|
|
if (array_key_exists('new_category', $_GET)) $new_category = db_escape_string($_GET['new_category']);
|
|
|
|
|
|
// Validate parameters
|
|
if (!isset($order_num)) {
|
|
logExit("Order Num is not set");
|
|
}
|
|
|
|
if (!isset($schedule_num)) {
|
|
logExit("Schedule Num is not set");
|
|
}
|
|
|
|
if (!isset($new_category)) {
|
|
logExit("New Category is not set");
|
|
}
|
|
|
|
writeLog("order_num: $order_num");
|
|
writeLog("new_category: $new_category");
|
|
|
|
|
|
$school_num = $school_record['record_num'];
|
|
|
|
|
|
// Error logging
|
|
$validCategories = array('Regular', 'Special 1', 'Special 2', 'Special 3');
|
|
if (!in_array($new_category, $validCategories)) {
|
|
logExit("New Category is invalid: $new_category");
|
|
}
|
|
|
|
// Update order header
|
|
$query = "UPDATE hotlunch_order_header SET price_category = '$new_category' WHERE school_num = $school_num AND record_num = $order_num";
|
|
writeLog($query);
|
|
db_query($query);
|
|
|
|
// Recalculate order total
|
|
$results = calcOrderTotal($order_num, $schedule_num, 'Y');
|
|
writeLog("Subtotal: ".$results['order_subtotal']);
|
|
|
|
$order_total = '$'.number_format($results['order_total'],2);
|
|
|
|
|
|
// Set return values
|
|
$new_category_text = getLanguageText('TEXT-'.strtoupper(str_replace(' ','',$new_category)));
|
|
switch ($new_category) {
|
|
case 'Special 1': $new_category_text = $Special1_Title; break;
|
|
case 'Special 2': $new_category_text = $Special2_Title; break;
|
|
case 'Special 3': $new_category_text = $Special3_Title; break;
|
|
}
|
|
|
|
$return_data['ajax_return_code'] = 0;
|
|
$return_data['ajax_return_message'] = getLanguageText('TEXT-ORDER-UPDATED')."\n".
|
|
"-- $student_name --\n" .
|
|
"-- $schedule_name --\n" .
|
|
"\n" .
|
|
getLanguageText('TEXT-ORDER-TOTAL').": $order_total";
|
|
$return_data['new_category'] = $new_category_text;
|
|
$return_data['order_total'] = $order_total;
|
|
|
|
writeLog("complete\n");
|
|
echo(json_encode($return_data));
|
|
|
|
?>
|