0) $source = $_GET['source']; if (array_key_exists('source',$_POST) && strlen($_POST['source']) > 0) $source = $_POST['source']; if (!isset($source) || strlen($source) == 0) $source = "On-Line"; // Process other parameters if (array_key_exists('show_all',$_GET) && strlen($_GET['show_all']) > 0) $show_all = $_GET['show_all']; if (array_key_exists('show_all',$_POST) && strlen($_POST['show_all']) > 0) $show_all = $_POST['show_all']; if (array_key_exists('show_status',$_GET) && strlen($_GET['show_status']) > 0) $show_status = $_GET['show_status']; if (array_key_exists('show_status',$_POST) && strlen($_POST['show_status']) > 0) $show_status = $_POST['show_status']; if (array_key_exists('show_source',$_GET) && strlen($_GET['show_source']) > 0) $show_source = $_GET['show_source']; if (array_key_exists('show_source',$_POST) && strlen($_POST['show_source']) > 0) $show_source = $_POST['show_source']; // Get user num if it is set unset($existing_user_num); if (array_key_exists('existing_user_num',$_POST) && strlen($_POST['existing_user_num']) > 0) $existing_user_num = intval($_POST['existing_user_num']); if (!isset($schedule_num)) { header("Location: /?error_message=".urlencode(getLanguageText('ERRORMSG-INVALID-SCHEDULE-NUM'))); exit(); } $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) { header("Location: /?error_message=".urlencode(getLanguageText('ERRORMSG-INVALID-SCHEDULE-NUM'))); exit(); } $schedule = db_fetch_assoc($results); $schedule_name = $schedule['schedule_name']; // Get current order information if (isset($entered_order_num) && $entered_order_num > 0) { $order_num = $entered_order_num; $query = "select * from hotlunch_order_header " . "where school_num = $school_num " . "and record_num = $entered_order_num"; $results = db_query($query); if (db_num_rows($results) == 0) { $error_message = "Invalid order number"; if (!isset($show_all)) $show_all = ''; if (!isset($show_status)) $show_status = ''; if (!isset($show_source)) $show_source = ''; if (!isset($show_only)) $show_only = ''; header("Location: /?action=orders&schedule_num=$schedule_num&show_all=$show_all&show_status=$show_status&show_source=$show_source" . "&show_only=$show_only&error_message=".urlencode($error_message)); exit(); } $row = db_fetch_array($results); $originalOrder = $row; $ordered_by_num = intval($row['ordered_by_num']); $ordered_by_type = $row['ordered_by_type']; } else { $originalOrder = array(); // Get staff_num if (array_key_exists('staff_num',$_GET)) $staff_num = intval($_GET['staff_num']); if (array_key_exists('staff_num',$_POST)) $staff_num = intval($_POST['staff_num']); // Get student_num if (array_key_exists('student_num',$_GET)) $student_num = intval($_GET['student_num']); if (array_key_exists('student_num',$_POST)) $student_num = intval($_POST['student_num']); // Get ordered_by_num if (array_key_exists('ordered_by_num',$_GET)) $ordered_by_num = intval($_GET['ordered_by_num']); if (array_key_exists('ordered_by_num',$_POST)) $ordered_by_num = intval($_POST['ordered_by_num']); // Get ordered_by_type if (array_key_exists('ordered_by_type',$_GET)) $ordered_by_type = $_GET['ordered_by_type']; if (array_key_exists('ordered_by_type',$_POST)) $ordered_by_type = $_POST['ordered_by_type']; // Get people_type if (array_key_exists('people_type',$_GET)) $people_type = $_GET['people_type']; if (array_key_exists('people_type',$_POST)) $people_type = $_POST['people_type']; // Process the order_by_code value if (array_key_exists('ordered_by_code',$_POST)) { $ordered_by_code = $_POST['ordered_by_code']; if (strpos($ordered_by_code, "Student") === 0) { $ordered_by_num = intval(str_replace("Student.","",$ordered_by_code)); $ordered_by_type = 'Student'; } if (strpos($ordered_by_code, "Staff") === 0) { $ordered_by_num = intval(str_replace("Staff.","",$ordered_by_code)); $ordered_by_type = 'Staff'; } if ($ordered_by_code == 'Concession') { $ordered_by_num = $school_num; $ordered_by_type = 'Concession'; $source = 'Concession'; } } // Set ordered_by_num from staff_num if (isset($staff_num) && !isset($ordered_by_num)) { $ordered_by_num = intval($staff_num); $ordered_by_type = 'Staff'; } // Set ordered_by_num from student_num if (isset($student_num) && !isset($ordered_by_num) && $student_num != 0) { $ordered_by_num = intval($student_num); if (isset($people_type)) $ordered_by_type = $people_type; else $ordered_by_type = db_getVal("SELECT people_type FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num"); unset($new_last_name); unset($new_first_name); } } if (isset($ordered_by_num)) writeLog("ordered_by_num: $ordered_by_num"); // Ensure that ordered_by_num is set $AllowedUserTypes = array('Parent','Staff'); if (!isset($ordered_by_num) && checkPermission($AllowedUserTypes) == 1) { $error_message = getLanguageText('ERRORMSG-ACCESS-DENIED') . " - ordered_by_num"; header("Location: /?error_message=".urlencode($error_message)); exit(); } // Control if the fields in the form are editable $form_edit_mode = "edit"; // Perform student validation for Parents if ($_SESSION['UserInfo']['type'] == 'Parent') { // Verify that this student is connected to this user account $uid = $_SESSION['UserInfo']['record_num']; $ordered_by_num = intval($ordered_by_num); $query = "select * from people " . "where school_num = $base_school_num " . "and user_num = $uid " . "and record_num = $ordered_by_num"; $results = db_query($query); if (db_num_rows($results) == 0) { $error_message = "Invalid ordered by number"; if (!isset($show_all)) $show_all = ''; if (!isset($show_status)) $show_status = ''; if (!isset($show_source)) $show_source = ''; if (!isset($show_only)) $show_only = ''; header("Location: /?action=orders&schedule_num=$schedule_num&show_all=$show_all&show_status=$show_status&show_source=$show_source" . "&show_only=$show_only&error_message=".urlencode($error_message)); exit(); } // Verify that the student is allowed to order from this schedule $class_entries = db_getVal("select count(*) from hotlunch_schedules_classes where school_num = $school_num and schedule_num = $schedule_num"); if (isset($class_num) && $class_entries > 0 && $class_num > 0) { $ordered_by_num = intval($ordered_by_num); $class_num = db_getVal("select class_num from people where record_num = $ordered_by_num"); $schedule_access = db_getVal("select count(*) from hotlunch_schedules_classes where school_num = $school_num and schedule_num = $schedule_num and class_num = $class_num"); if ($schedule_access == 0) { $error_message = "This student can not order from this schedule"; header("Location: /?action=orders&schedule_num=$schedule_num&show_all=$show_all&show_status=$show_status&show_source=$show_source" . "&show_only=$show_only&error_message=".urlencode($error_message)); exit(); } } $source = "On-Line"; } // Perform validation for Staff if ($_SESSION['UserInfo']['type'] == 'Staff') { $ordered_by_num = intval($ordered_by_num); $query = "select * from people " . "where school_num = $base_school_num " . "and record_num = $ordered_by_num"; $results = db_query($query); if (db_num_rows($results) == 0) { $error_message = "Invalid staff number"; header("Location: /?action=orders&schedule_num=$schedule_num&show_all=$show_all&show_status=$show_status&show_source=$show_source" . "&show_only=$show_only&error_message=".urlencode($error_message)); exit(); } $source = "On-Line"; } // Parents and Staff can only review orders after end order date has passed if ($_SESSION['UserInfo']['type'] == 'Parent' || $_SESSION['UserInfo']['type'] == 'Staff') { // Check if there is a schedule number and if it is still open for editing if (isset($schedule_num)) { $today = date("Y-m-d",time()); $query = "select * from hotlunch_schedules " . "where record_num = $schedule_num " . "and school_num = $school_num " . "and status = 'Active' " . "and end_order_datetime >= '$now' "; $results = db_query($query); if (db_num_rows($results) == 0) { $form_edit_mode = "review"; } } } // Ensure that Staff and Parent type users have the lunch schedule set $AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier'); if (checkPermission($AllowedUserTypes) != 1) { if (!isset($schedule_num)) { $error_message = getLanguageText('ERRORMSG-ACCESS-DENIED') . " - schedule_num"; header("Location: /?error_message=".urlencode($error_message)); 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'); header("Location: /?error_message=".urlencode($error_message)); exit(); } $hotlunch_schedule = db_fetch_array($results); } else { if (!isset($schedule_num)) { $error_message = "A hot lunch schedule must be specified"; header("Location: /?error_message=".urlencode($error_message)); exit(); } // Check if this is a valid schedule $swhere = ""; if ($_SESSION['UserInfo']['type'] == 'Supplier') $swhere = " and supplier_num = " . $_SESSION['UserInfo']['supplier_num']; $query = "select * from hotlunch_schedules " . "where record_num = $schedule_num " . "and school_num = $school_num $swhere"; $results = db_query($query); if (db_num_rows($results) == 0) { $error_message = "The requested hot lunch schedule is invalid"; header("Location: /?error_message=".urlencode($error_message)); exit(); } $hotlunch_schedule = db_fetch_array($results); } // 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 = "This lunch schedule has no menus defined"; header("Location: /?action=schedule-reports&schedule_num=$schedule_num&error_message=".urlencode($error_message)); 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_items.active != 'N' " . "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 = "This lunch schedule has no menu items defined"; header("Location: /?action=schedule-reports&schedule_num=$schedule_num&error_message=".urlencode($error_message)); exit(); } $CurrentTable = "hotlunch_order_header"; $DeleteField = ""; $dSeparator = ""; $FormFile = "hotlunch_orders.form.php"; $TitleText = "Order"; $OrderBy = ""; $FormFile = "hotlunch_orders.form.new.php"; writeLog("FormFile: $FormFile"); // // Process all actions to list and edit records // $naction = ""; $templatePageTitle = $hotlunch_schedule['schedule_name'] . ' ' . getLanguageText('TEXT-ORDERS');; if (array_key_exists('naction',$_GET)) $naction = $_GET['naction']; if (array_key_exists('naction',$_POST)) $naction = $_POST['naction']; if (array_key_exists('ordered_by_num', $_GET)) $ordered_by_num = intval($_GET['ordered_by_num']); if (array_key_exists('ordered_by_num', $_POST)) $ordered_by_num = intval($_POST['ordered_by_num']); // if (!isset($ordered_by_num)) $ordered_by_num = $school_num; if (isset($ordered_by_num)) writeLog("ordered_by_num: $ordered_by_num"); // $ordered_by_type = 'Concession'; if (isset($ordered_by_num) && $ordered_by_num > 3) { $query = "SELECT * FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num"; writeLog($query); $results = db_query($query); if (db_num_rows($results)) { $person = db_fetch_assoc($results); $ordered_by_type = $person['people_type']; } } switch (strtolower($naction)) { case "add": $sourceText = getLanguageText('TEXT-'.$source.'-ORDER'); $PageTitle = $sourceText; $ButtonText = getLanguageText('TEXT-PLACE-ORDER'); $next_naction = "insert"; $paction = $naction; if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator')) && in_array($_SESSION['UserInfo']['can_order'],array('No','Balance'))) { $error_message = $school_record['no_ordering_message'] . " - " . $_SESSION['UserInfo']['can_order']; echo("
\n"); include "form.messages.php"; break; } if ($_SESSION['UserInfo']['type'] == "Parent" || $_SESSION['UserInfo']['type'] == "Staff") $source = "On-Line"; include $FormFile; break; case "edit": if ($_SESSION['UserInfo']['type'] == "Parent" || $_SESSION['UserInfo']['type'] == "Staff") $source = "On-Line"; $sourceText = getLanguageText('TEXT-'.$source.'-ORDER'); $PageTitle = $sourceText; $ButtonText = getLanguageText('TEXT-UPDATE-ORDER'); $next_naction = "update"; $paction = $naction; if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator')) && in_array($_SESSION['UserInfo']['can_order'],array('No','Balance'))) { $error_message = $school_record['no_ordering_message']; echo("
\n"); include "form.messages.php"; break; } include $FormFile; break; case "update": case "insert": extract($_POST); $error_message = ""; if (!isset($schedule_num)) { echo("
\n"); $error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE-NUM'); include "form.messages.php"; break; } // // Process each menu and menu item in the 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); $num_items = 0; $qtyError = false; while ($menu_date = db_fetch_array($menu_dates)) { $menu_title = $menu_date['menu_title']; $menu_num = $menu_date['record_num']; $menu_code = $schedule_num . "_" . $menu_num; // 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' " . "AND item_type NOT IN ('Heading') " . "order by sequence"; $menu_items = db_query($query); while ($menu_item = db_fetch_assoc($menu_items)) { $item_title = $menu_item['item_title']; $menu_item_num = $menu_item['record_num']; $options = $menu_item['options']; $qty_available = intval($menu_item['quantity_available']); $max_quantity = intval($menu_item['max_quantity']); $curr_code = $schedule_num . "_" . $menu_num . "_" . $menu_item_num; $qty = 0; if (array_key_exists("qty_$curr_code", $_POST)) $qty = intval($_POST["qty_$curr_code"]); // If some of this item have been ordered note that something has been ordered and check the quantity available if ($qty > 0) { $num_items++; // If this item has order limits then verify that the qty is less than the limit if ((!isset($ordered_by_type) || $ordered_by_type != 'Concession') && $max_quantity > 0 && $qty > $max_quantity) { $error_message = "Error: You can not order more than $max_quantity of $item_title"; $next_naction = $naction; include $FormFile; $qtyError = true; // if ($_SESSION['UserInfo']['type'] == 'SuperUser') { // echo("$menu_title: $item_title - $max_quantity - $qty_available - $qty"); // exit(); // } break; } // If this item has inventory restrictions determine how many have been sold thus far if ((!isset($ordered_by_type) || $ordered_by_type != 'Concession') && $qty_available > 0) { $swhere = ""; if (isset($ordered_by_num) && $ordered_by_num > 0) $swhere = " AND ordered_by_num != $ordered_by_num AND ordered_by_type != 'Concession' "; $qty_sold = db_getVal("SELECT sum(qty) FROM hotlunch_order_items WHERE school_num = $school_num AND menu_item_num = $menu_item_num AND active != 'N' $swhere"); $qty_remaining = intval($qty_available) - intval($qty_sold); // If there are not enough available then display the form again if ($qty_remaining < $qty) { if ($paction == 'add') { $sourceText = getLanguageText('TEXT-'.$source.'-ORDER'); $PageTitle = $sourceText; $ButtonText = getLanguageText('TEXT-PLACE-ORDER'); } else { $sourceText = getLanguageText('TEXT-'.$source.'-ORDER'); $PageTitle = $sourceText; $ButtonText = getLanguageText('TEXT-UPDATE-ORDER'); } $error_message = "Error: not enough '$item_title' available on $menu_title - Quantity Available: $qty_remaining"; $next_naction = $naction; header("Location: /?action=orders&naction=add&schedule_num=$schedule_num&student_num=$ordered_by_num&error_message=" . urlencode($error_message)); // include $FormFile; // $qtyError = true; // break; exit(); } } } } } // // Save the order // if ($qtyError) writeLog("qtyError: true"); writeLog("num_items: $num_items"); if (!$qtyError && $num_items > 0) { if (isset($defaultOrder) && $defaultOrder == 'Y') include "hotlunch_orders.generate.php"; else include "hotlunch_orders.save.php"; } else { writeLog("order_num: $order_num"); writeLog("num_items: $num_items"); if (isset($order_num) && $order_num > 0 && $num_items == 0) { logOrderChange($order_num, "ORDER DELETED - NO ITEMS", "hotlunch_orders.php"); $query = "SELECT * FROM hotlunch_order_items " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND ordered_by_num = $ordered_by_num " . "AND order_num = $order_num"; writeLog($query); $items = db_query($query); writeLog("Num Items: ".db_num_rows($items)); while ($row = db_fetch_assoc($items)) { $rnum = $row['record_num']; db_query("DELETE FROM hotlunch_order_items WHERE school_num = $school_num AND record_num = $rnum"); } db_query("DELETE FROM hotlunch_order_header WHERE school_num = $school_num AND ordered_by_num = $ordered_by_num AND record_num = $order_num"); db_query("DELETE FROM user_account WHERE school_num = $school_num AND order_num = $order_num"); // Calculate multiple order discounts calcMultiOrderDiscounts($user_num,$schedule_num,$school_num); header("Location: /?error_message=".urlencode(getLanguageText('TEXT-ORDER-DELETED'))); exit(); } header("Location: /?error_message=".urlencode(getLanguageText('TEXT-NO-ITEMS-ORDERED'))); } break; case "completed": include "hotlunch_orders.completed.php"; $naction = 'list'; break; case "edit-header": $PageTitle = getLanguageText('TEXT-EDIT-ORDER-HEADER'); $ButtonText = getLanguageText('TEXT-UPDATE-ORDER-HEADER'); $next_naction = "update-header"; include "hotlunch_order_header.form.php"; break; case "update-header": extract($_POST); $order_num = $record_num; // Get user_num for current ordered_by_num $user_num = db_getVal("SELECT user_num FROM people WHERE record_num = $ordered_by_num"); // Handle change of ordered_by_num if ($ordered_by_num != $selected_ordered_by_num) { // Get original person info $student = db_getVal("SELECT * FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num"); $student_name = $student['first_name'].' '.$student['last_name']; $oname = $student['last_name'].', '.$student['first_name']; // Get new person info $results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND record_num = $selected_ordered_by_num"); $new_person = db_fetch_array($results); $new_ordered_by_type = $new_person['people_type']; $new_unum = $new_person['user_num']; $nname = $new_person['first_name'] . ' ' . $new_person['last_name']; // Update the order db_query("UPDATE hotlunch_order_header SET ordered_by_num = $selected_ordered_by_num,ordered_by_type = '$new_ordered_by_type' WHERE school_num = $school_num AND record_num = $order_num"); db_query("UPDATE hotlunch_order_items SET ordered_by_num = $selected_ordered_by_num,ordered_by_type = '$new_ordered_by_type' WHERE school_num = $school_num AND order_num = $order_num"); logOrderChange($order_num, "ORDER REASSIGNED - NEW ORDERED BY", "hotlunch_orders.php"); // Move transaction entry to new user account db_query("UPDATE user_account SET user_num = $new_unum,people_num = $selected_ordered_by_num WHERE school_num = $school_num AND user_num = $user_num AND order_num = $order_num"); // Set ordered_by_num to the new value $ordered_by_num = $selected_ordered_by_num; $user_num = $new_unum; // Make activity log entry $uid = db_escape_string($_SESSION['UserInfo']['userid']); $ip = $_SESSION['LoginIP']; $time = time(); $datetime = date("Y-m-d H:i:s",$time); if (db_tableExists("activity_log")) { db_query("insert into activity_log (school_num,userid,user_ip,activity_time,activity_datetime,activity,information) " . "values ($school_num,'$uid','$ip',$time,'$datetime','ordered-by #$order_num changed $oname -> $nname',NULL)"); } } // Cleanup values for the database $amount_paid = str_replace('$','',$amount_paid); $amount_paid = number_format($amount_paid,2); // Get existing order header record $results = db_query("select * from hotlunch_order_header where school_num = $school_num and record_num = $record_num"); $oh = db_fetch_array($results); $setValues = "status = '$status'"; if ($status != $oh['status']) { if ($status == 'Paid') $setValues .= ", payment_method = 'Manual Posting'"; } $setValues .= ", price_category = '" . db_escape_string($price_category) . "', delivered = '" . db_escape_string($delivered) . "'"; $setValues .= ", ordered_by_type = '$ordered_by_type'"; // Save order header data $query = "update hotlunch_order_header " . "set $setValues, " . "source = '$source' " . "where school_num = $school_num " . "and record_num = $record_num"; db_query($query); // echo("$query\n"); exit(); logOrderChange($record_num, "ORDER HEADER UPDATED", "hotlunch_orders.php"); // Check if order status was changed $ostatus = $oh['status']; // Check the order status if ($status != $ostatus) { // Get user_num $ordered_by_num = $oh['ordered_by_num']; $ordered_by_type = $oh['ordered_by_type']; // Set other fields $order_num = $record_num; $people_num = $ordered_by_num; $transaction_datetime = date("Y-m-d H:i:s",time()); $entered_time = time(); $note = "Order #$order_num: $ostatus -> $status "; $transaction_type = 'TRX Note'; $transaction_amount = 0.00; $entered_by_user_num = intval($_SESSION['UserInfo']['record_num']); // If new status is Complimentary post a credit to the account if ($status == 'Complimentary') { $transaction_amount = -1 * $oh['order_total']; $transaction_amount = floatval($transaction_amount); $transaction_type = "Complimentary Credit"; $deleted = 'N'; $transaction_status = 'Open'; if ($transaction_amount != 0.00) $order_payments = "{" . $record_num . ":" . $transaction_amount . "}"; // Check to make sure the transaction is not posted already $results = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND order_num = $order_num AND transaction_type = '$transaction_type'"); if (db_num_rows($results) == 0) { // Create user_account entry $user_account = new Table("user_account"); $query = $user_account->BuildInsert(); db_query($query); } // Update order header $today = date("Y-m-d",time()); $query = "UPDATE hotlunch_order_header " . "SET amount_paid = 0, " . "paid_date = '$today', " . "payment_method = 'Complimentary' " . "WHERE school_num = $school_num " . "AND record_num = $record_num"; db_query($query); logOrderChange($record_num, "ORDER PAID", "hotlunch_orders.php"); // Update user balance updateUserBalance($user_num); } // If new status is Unpaid and previous status was Complimentary if ($status == 'Unpaid' && $ostatus == 'Complimentary') { // Delete user_account credit entry if (isset($user_num) && $user_num > 0) { db_query("delete from user_account where school_num = $school_num and user_num = $user_num and order_num = $order_num and transaction_type = 'Complimentary Credit'"); $query = "UPDATE user_account " . "SET transaction_status = 'Open' " . "WHERE school_num = $school_num " . "AND order_num = $record_num"; db_query($query); } } // If new status is Unpaid and previous status was Paid if ($status == 'Unpaid' && $ostatus == 'Paid') { $query = "UPDATE hotlunch_order_header " . "SET amount_paid = 0, " . "paid_date = NULL, " . "payment_method = '' " . "WHERE school_num = $school_num " . "AND record_num = $record_num"; db_query($query); logOrderChange($record_num, "ORDER STATUS CHANGED", "hotlunch_orders.php"); if (isset($user_num) && $user_num > 0) { $query = "UPDATE user_account " . "SET transaction_status = 'Open' " . "WHERE school_num = $school_num " . "AND order_num = $record_num"; db_query($query); } } // Make activity log entry $uid = db_escape_string($_SESSION['UserInfo']['userid']); $ip = $_SESSION['LoginIP']; $time = time(); if (db_tableExists("activity_log")) { db_query("insert into activity_log (school_num,userid,user_ip,activity_time,activity,information) values ($school_num,'$uid','$ip',$time,'order-status #$order_num changed $ostatus -> $status',NULL)"); } } $naction = "list"; header("Location: /?action=orders&naction=list&schedule_num=$schedule_num&selected_order_num=$record_num&form_message=".urlencode(getLanguageText('TEXT-ORDER-HEADER-UPDATED'))); exit(); case "set-inactive": $record_num = intval($_GET['order_num']); $query = "UPDATE hotlunch_order_header SET status = 'Inactive' " . "WHERE school_num = $school_num " . "and schedule_num = $schedule_num " . "and record_num = $record_num " . "and status = 'Unpaid'"; db_query($query); logOrderChange($record_num, "ORDER STATUS CHANGED TO INACTIVE", "hotlunch_orders.php"); $form_message = "Order Status Has Been Updated"; $show_status = 'Unpaid'; $naction = "list"; break; case "set-paid": $record_num = intval($_GET['order_num']); $query = "UPDATE hotlunch_order_header SET status = 'Paid' " . "WHERE school_num = $school_num " . "and schedule_num = $schedule_num " . "and record_num = $record_num " . "and status = 'Unpaid'"; db_query($query); logOrderChange($record_num, "ORDER STATUS CHANGED TO PAID", "hotlunch_orders.php"); $form_message = "Order Status Has Been Updated"; $show_status = 'Unpaid'; $naction = "list"; break; case "set-unpaid": $record_num = intval($_GET['order_num']); $query = "UPDATE hotlunch_order_header SET status = 'Unpaid' " . "WHERE school_num = $school_num " . "and schedule_num = $schedule_num " . "and record_num = $record_num " . "and status = 'Inactive'"; db_query($query); logOrderChange($record_num, "ORDER STATUS CHANGED TO UNPAID", "hotlunch_orders.php"); $form_message = "Order Status Has Been Updated"; $show_status = 'Inactive'; $naction = "list"; break; case "flag-delivered": $record_num = intval($_GET['order_num']); $query = "UPDATE hotlunch_order_header SET delivered = 'Y' " . "WHERE school_num = $school_num " . "and schedule_num = $schedule_num " . "and record_num = $record_num"; db_query($query); logOrderChange($record_num, "ORDER DELIVERED", "hotlunch_orders.php"); $form_message = "Order Status Has Been Updated"; $show_all = 'Y'; $naction = "list"; break; case "toggle-inactive-unpaid": $query = "UPDATE hotlunch_order_header SET status = 'Unpaid' " . "WHERE school_num = $school_num " . "and schedule_num = $schedule_num " . "and status = 'Inactive'"; db_query($query); logOrderChange(0, "ORDERS CHANGED FROM INACTIVE TO UNPAID", "hotlunch_orders.php", $schedule_num); $form_message = getLanguageText('MSG-INACTIVE-ORDERS-SET-UNPAID'); $show_status = 'Unpaid'; $naction = "list"; break; case "toggle-unpaid-inactive": $query = "UPDATE hotlunch_order_header SET status = 'Inactive' " . "WHERE school_num = $school_num " . "and schedule_num = $schedule_num " . "and status = 'Unpaid'"; db_query($query); logOrderChange(0, "ORDERS CHANGED FROM UNPAID TO INACTIVE", "hotlunch_orders.php", $schedule_num); $form_message = getLanguageText('MSG-UNPAID-ORDERS-SET-INACTIVE'); $show_status = 'Inactive'; $naction = "list"; break; case "toggle-unpaid-paid": if (array_key_exists('balance_payable',$_GET) && $_GET['balance_payable'] == 'Y') { $query = "SELECT hloh.*,p.user_num FROM hotlunch_order_header AS hloh, people AS p " . "WHERE hloh.school_num = $school_num " . "AND p.school_num = $base_school_num " . "AND p.record_num = hloh.ordered_by_num " . "AND hloh.schedule_num = $schedule_num " . "AND hloh.status = 'Unpaid'"; $results = db_query($query); while ($row = db_fetch_assoc($results)) { $onum = $row['record_num']; $unum = $row['user_num']; $balance = db_getVal("select sum(transaction_amount) as balance from user_account where school_num = $school_num and user_num = $unum AND (deleted != 'Y' OR deleted IS NULL)"); if ($balance <= 0) { db_query("UPDATE hotlunch_order_header SET status = 'Paid' WHERE school_num = $school_num AND record_num = $onum"); logOrderChange($onum, "ORDER CHANGED FROM UNPAID TO PAID", "hotlunch_orders.php"); } } } else { $query = "UPDATE hotlunch_order_header SET status = 'Paid' " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND status = 'Unpaid'"; db_query($query); logOrderChange(0, "ALL ORDERS SET TO UNPAID (PAID)", "hotlunch_orders.php"); } $form_message = getLanguageText('MSG-UNPAID-ORDERS-SET-PAID'); $show_status = 'Paid'; $naction = "list"; break; case "toggle-zerototal-paid": $query = "UPDATE hotlunch_order_header SET status = 'Paid' " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND status = 'Unpaid' " . "AND order_total = 0.00"; db_query($query); logOrderChange(0, "ZERO TOTAL ORDERS SET TO PAID", "hotlunch_orders.php", $schedule_num); $form_message = getLanguageText('MSG-UNPAID-ORDERS-SET-PAID'); $show_status = 'Paid'; $naction = "list"; break; case "delete-unpaid": case "delete-inactive": case "delete-paid": $status = 'Unpaid'; if ($naction == 'delete-inactive') $status = 'Inactive'; if ($naction == 'delete-paid') $status = 'Paid'; // Get schedule title $schedule_name = $hotlunch_schedule['schedule_name']; // Get matching orders $query = "SELECT * FROM hotlunch_order_header " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND status = '$status'"; $orders = db_query($query); // Process each order while ($row = db_fetch_array($orders)) { extract($row); $order_total = $currencySymbol . number_format($row['order_total'],2); $order_num = $record_num; $results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num"); $person = db_fetch_array($results); $user_num = intval($person['user_num']); if (!isset($schedule_name)) $schedule_name = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $schedule_num"); $lognote = $person['first_name'] . ' ' . $person['last_name'] . " - $schedule_name ($order_total)"; // Delete existing user_account entry for order db_query("DELETE FROM user_account " . "WHERE school_num = $school_num " . "AND user_num = $user_num " . "AND schedule_num = $schedule_num " . "AND order_num = $order_num " . "AND transaction_type = 'Order'"); $entered_time = time(); $trx_time = date("Y-m-d H:i:s",$entered_time); $lognote = db_escape_string($lognote); $logmsg = 'Order Deleted'; $query = "INSERT INTO user_account " . "(school_num,user_num,schedule_num,transaction_datetime,transaction_type,note,transaction_amount,transaction_fee,payment_method,payment_reference,order_payments,deleted,entered_time,transaction_status) " . "VALUES ($school_num,$user_num,$schedule_num,'$trx_time','TRX Note','$logmsg - $lognote',0,0,NULL,'',NULL,'N',$entered_time,'Closed')"; db_query($query); logOrderChange($order_num, "ORDER DELETED - ADMIN", "hotlunch_orders.php"); db_query("DELETE FROM hotlunch_order_header WHERE school_num = $school_num AND schedule_num = $schedule_num AND status = '$status' AND record_num = $order_num"); $items = db_query("SELECT * FROM hotlunch_order_items " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND ordered_by_num = $ordered_by_num " . "AND order_num = $order_num"); while ($row = db_fetch_assoc($items)) { $rnum = $row['record_num']; db_query("DELETE FROM hotlunch_order_items WHERE school_num = $school_num AND record_num = $rnum"); } // Calculate multiple order discounts calcMultiOrderDiscounts($user_num,$schedule_num,$school_num); } $form_message = getLanguageText('MSG-ORDERS-DELETED'); $show_status = ''; $naction = "list"; break; case "flag-paid": case "flag-unpaid": case "flag-inactive": $status = 'Unpaid'; if ($naction == 'flag-inactive') $status = 'Inactive'; if ($naction == 'flag-paid') $status = 'Paid'; // Get matching orders $query = "SELECT * FROM hotlunch_order_header " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND status = '$status'"; $orders = db_query($query); // Process each order while ($row = db_fetch_array($orders)) { extract($row); $results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num"); $row = db_fetch_array($results); $user_num = $row['user_num']; db_query("UPDATE users SET email_flag = 'Y' WHERE school_num = $base_school_num AND record_num = $user_num"); } $num_entries = db_getVal("SELECT count(*) FROM users WHERE school_num = $base_school_num AND email_flag = 'Y'"); $form_message = getLanguageText('TEXT-FLAGGED'). ": $num_entries"; $naction = "list"; $show_status = $status; break; case "set-complimentary": $record_num = $_GET['order_num']; // Get existing order header record $results = db_query("select * from hotlunch_order_header where school_num = $school_num and record_num = $record_num"); $oh = db_fetch_array($results); // Get user_num $ordered_by_num = $oh['ordered_by_num']; $ordered_by_type = $oh['ordered_by_type']; $user_num = db_getVal("SELECT user_num FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num"); // Set other fields $order_num = $record_num; $people_num = $ordered_by_num; $transaction_datetime = date("Y-m-d H:i:s",time()); $entered_time = time(); $note = "Order #$order_num: $show_status -> Complimentary "; $transaction_amount = -1 * $oh['order_total']; $transaction_amount = floatval($transaction_amount); $transaction_type = "Complimentary Credit"; $deleted = 'N'; if ($transaction_amount != 0.00) $order_payments = "{" . $record_num . ":" . $transaction_amount . "}"; // Create user_account entry $user_account = new Table("user_account"); $query = $user_account->BuildInsert(); db_query($query); // Update user balance updateUserBalance($user_num); // Update status $query = "UPDATE hotlunch_order_header " . "SET status = 'Complimentary', " . "amount_paid = 0, " . "payment_method = 'Complimentary' " . "WHERE school_num = $school_num " . "and schedule_num = $schedule_num " . "and record_num = $record_num " . "and status = '$show_status'"; db_query($query); logOrderChange($record_num, "ORDER SET COMPLIMENTARY", "hotlunch_orders.php"); $form_message = "Order Status Has Been Updated"; $naction = "list"; break; case "delete-confirmed": extract($_GET); $query = "select * from hotlunch_order_header " . "where school_num = $school_num " . "and schedule_num = $schedule_num " . "and record_num = $order_num"; $results = db_query($query); $row = db_fetch_array($results); $order_total = $row['order_total']; $order_status = $row['status']; $ordered_by_num = $row['ordered_by_num']; $ordered_by_type = $row['ordered_by_type']; $order_num = $row['record_num']; if ($order_status == 'Paid') { $error_message = getLanguageText('ERRORMSG-UNABLE-TO-DELETE-PAID-ORDERS'); $naction = 'list'; header("Location: /?action=orders&schedule_num=$schedule_num&show_all=$show_all&show_status=$show_status&show_source=$show_source" . "&show_only=$show_only&error_message=".urlencode($error_message)); exit(); } // Get student info $results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num"); if (db_num_rows($results)) { $row = db_fetch_array($results); if (array_key_exists('user_num', $row)) $user_num = intval($row['user_num']); else $user_num = 0; $order_total = $currencySymbol . number_format($order_total,2); $lognote = $row['first_name'] . ' ' . $row['last_name'] . " - $schedule_name ($order_total)"; $entered_time = time(); $trx_time = date("Y-m-d H:i:s",$entered_time); $lognote = db_escape_string($lognote); $logmsg = 'Order Deleted'; $query = "INSERT INTO user_account " . "(school_num,user_num,schedule_num,transaction_datetime,transaction_type,note,transaction_amount,transaction_fee,payment_method," . "payment_reference,order_payments,deleted,entered_time,transaction_status) " . "VALUES ($school_num,$user_num,$schedule_num,'$trx_time','TRX Note','$logmsg - $lognote',0,0,NULL,'',NULL,'N',$entered_time,'Closed')"; db_query($query); } // Delete order header logOrderChange($order_num, "ORDER DELETED", "hotlunch_orders.php"); $query = "delete from hotlunch_order_header " . "where school_num = $school_num " . "and schedule_num = $schedule_num " . "and record_num = $order_num"; db_query($query); // Delete order line items $query = "select * from hotlunch_order_items " . "where school_num = $school_num " . "and schedule_num = $schedule_num " . "and ordered_by_num = $ordered_by_num " . "and order_num = $order_num"; $items = db_query($query); while ($row = db_fetch_assoc($items)) { $rnum = $row['record_num']; db_query("DELETE FROM hotlunch_order_items WHERE school_num = $school_num AND record_num = $rnum"); } // Delete account transaction entry $user_num = db_getVal("select user_num from people where school_num = $base_school_num and record_num = $ordered_by_num"); if (isset($user_num) && $user_num > 0) { $query = "delete from user_account " . "where school_num = $school_num " . "and schedule_num = $schedule_num " . "and user_num = $user_num " . "and order_num = $order_num"; db_query($query); // Update user balance updateUserBalance($user_num); // Calculate multiple order discounts calcMultiOrderDiscounts($user_num,$schedule_num,$school_num); } $form_message = getLanguageText('RECORD-DELETED-MSG'); $naction = 'list'; break; case "select": case "list": default: $naction = 'list'; break; } // Update the Concession order to be paid in full db_query("update hotlunch_order_header set amount_paid = order_total where school_num = $school_num and schedule_num = $schedule_num and ordered_by_type = 'Concession'"); // List current orders for this schedule if user type is allowed $AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier'); if ($naction == 'list' && checkPermission($AllowedUserTypes) == 1) { $message_width = $default_data_width; include "form.messages.php"; echo("
\n"); include "hotlunch_reports.menu.php"; include "hotlunch_orders.options.php"; $display_records = 'N'; $show_where = ""; $show_having = ""; $TitleText = getLanguageText('TEXT-ALL-ORDERS'); if (isset($show_all) && $show_all == 'Y') { $display_records = 'Y'; } $pdfButton = ""; $csvButton = ""; if (isset($show_status) && strlen($show_status)) { $pdfButton = "?action=orders-print-list-all&schedule_num=$schedule_num"; $csvButton = "?action=orders-list-status-csv&schedule_num=$schedule_num"; switch ($show_status) { case 'Balance Owing': $show_having = "having sum(ua.transaction_amount) > 0.00 "; $pdfButton = ""; $csvButton = ""; break; case 'Balance Payable': $show_having = "having sum(ua.transaction_amount) < 0.00 "; $pdfButton = ""; $csvButton = ""; break; default: $show_where .= "and hlh.status = '$show_status' "; $pdfButton .= "&show_status=$show_status"; $csvButton .= "&show_status=$show_status"; break; } $TitleText = getLanguageText("TEXT-STATUS-$show_status"); $display_records = 'Y'; } if (array_key_exists('selected_date',$_POST) && strlen($_POST['selected_date'])) { $sdate = db_escape_string($_POST['selected_date']); $edate = db_escape_string($_POST['selected_end_date']); if ($edate < $sdate) { $t = $sdate; $sdate = $edate; $edate = $t; } $show_where .= "and hlh.added_date BETWEEN '$sdate' AND '$edate' "; $display_records = 'Y'; $show_only = ''; $show_source = ''; $TitleText = getLanguageText('TEXT-ORDERS-BY-DATE').": $sdate - $edate"; } if (isset($show_only) && strlen($show_only)) { $show_where .= "and hlh.ordered_by_type = '$show_only' "; $TitleText = getLanguageText("TEXT-SHOW-$show_only"); $display_records = 'Y'; } if (isset($show_source) && strlen($show_source)) { $show_where .= "and hlh.source = '$show_source' "; $TitleText = getLanguageText("TEXT-SOURCE-$show_source"); $display_records = 'Y'; } unset($delivered); if (array_key_exists('delivered',$_GET) && strlen($_GET['delivered'])) $delivered = $_GET['delivered']; if (array_key_exists('delivered',$_POST) && strlen($_POST['delivered'])) $delivered = $_POST['delivered']; $dwhere = ""; if (isset($delivered)) { $dwhere = "AND delivered = '$delivered' "; $display_records = 'Y'; } unset($ordered_by_view); if (array_key_exists('ordered_by_view',$_GET) && strlen($_GET['ordered_by_view']) > 0) $ordered_by_view = $_GET['ordered_by_view']; if (array_key_exists('ordered_by_view',$_POST) && strlen($_POST['ordered_by_view']) > 0) $ordered_by_view = $_POST['ordered_by_view']; if (isset($ordered_by_view)) { if (strpos($ordered_by_view, "Student") === 0) { $ordered_by_num = str_replace("Student.","",$ordered_by_view); $ordered_by_type = 'Student'; } if (strpos($ordered_by_view, "Staff") === 0) { $ordered_by_num = str_replace("Staff.","",$ordered_by_view); $ordered_by_type = 'Staff'; } if (strpos($ordered_by_view, "Customer") === 0) { $ordered_by_num = str_replace("Customer.","",$ordered_by_view); $ordered_by_type = 'Guest'; } if ($ordered_by_view == 'Concession') { $ordered_by_num = $school_num; $ordered_by_type = 'Concession'; } $ordered_by_num = intval($ordered_by_num); $show_where = "and hlh.ordered_by_num = $ordered_by_num "; $display_records = 'Y'; } if (array_key_exists('selected_order_num',$_GET)) { $owhere = "and hlh.record_num = " . intval($_GET['selected_order_num']) . " "; $display_records = 'Y'; } $orderby = "p.last_name,p.first_name"; if (array_key_exists('orderby', $_GET)) { $orderby = db_escape_string($_GET['orderby']); } // Create the SQL query if ($display_records == 'Y') { // Get student records to display $columnHeaders = array(getLanguageText('TEXT-NAME'), getLanguageText('TEXT-SOURCE'), getLanguageText('TEXT-ORDER-TOTAL'), getLanguageText('TEXT-STATUS'), getLanguageText('TEXT-CATEGORY'), getLanguageText('TEXT-PAYMENT-METHOD'), getLanguageText('TEXT-ITEMS'), getLanguageText('TEXT-ACCOUNT'), getLanguageText('TEXT-BALANCE')); $columnHeaders[] = getLanguageText('TEXT-DELIVERED'); $columnAlign = array('left','center','right','center','center','center','center','center','right','center'); if (!isset($ordered_by_type) || $ordered_by_type != 'Concession') { if (isset($ordered_by_num)) $ordered_by_num = intval($ordered_by_num); if (!isset($owhere)) $owhere = ""; $query = "SELECT p.last_name,p.first_name,people_type,hlh.source,hlh.order_total,hlh.amount_paid,hlh.status,p.user_num,hlh.record_num,userid," . "sum(ua.transaction_amount) as balance,delivered,ordered_by_num,hlh.added_date,hlh.added_time,hlh.updated_date,entered_by,hlh.payment_method,price_category " . "FROM people AS p, hotlunch_order_header AS hlh, " . "users AS u LEFT JOIN user_account AS ua ON ua.school_num = $school_num AND ua.user_num = u.record_num AND (ua.deleted != 'Y' OR ua.deleted IS NULL) " . "WHERE p.school_num = $base_school_num " . "AND hlh.school_num = $school_num " . "AND p.record_num = hlh.ordered_by_num " . "AND hlh.schedule_num = $schedule_num " . "AND p.user_num = u.record_num " . $show_where . $dwhere . $owhere . "GROUP BY 1,2,3,4,5,6,7,8,9,10,12,13,14,15,16 " . $show_having . "ORDER BY $orderby"; } else { $ordered_by_num = intval($ordered_by_num); $query = "SELECT '','Concession','Concession' as people_type,hlh.source,hlh.order_total,hlh.amount_paid,hlh.status,$school_num,hlh.record_num,'',0.00 as balance," . "added_date,added_time,updated_date,entered_by,'Concession' " . "FROM hotlunch_order_header AS hlh " . "WHERE hlh.school_num = $school_num " . "AND hlh.schedule_num = $schedule_num " . "AND hlh.ordered_by_type = 'Concession' " . "AND hlh.ordered_by_num = $ordered_by_num " . $show_where . "ORDER BY 1,2"; } $orders = db_query($query); $otipSpanIDs = array(); $otipSpans = ""; $data = array(); $count = 0; $zeroBalance = false; $zeroTotal = false; while ($row = db_fetch_array($orders)) { extract($row); $pname = ''; if (isset($first_name) && isset($last_name)) $pname = "$first_name $last_name"; $order_num = $record_num; // Reformat the data if ($people_type == 'Concession') { $name = 'Concession'; // Get related values $nitems = db_getVal("SELECT count(*) FROM hotlunch_order_items WHERE school_num = $school_num AND order_num = $record_num AND active != 'N'"); $balance = $currencySymbol . "0.00"; $acct = ""; } else { // Get info about person placing order $presults = db_query("SELECT * FROM people WHERE record_num = $ordered_by_num"); $person = db_fetch_array($presults); $class = $person['class_num']; $class_info = getLanguageText('TEXT-CLASS-UNDEFINED'); if ($class > 0) $class_info = getClassInfo($class,'internal',1,true); $student_name = $person['first_name'].' '.$person['last_name']; $student_num = $ordered_by_num; $span_id = "person_$ordered_by_num"; if (!in_array($span_id,$otipSpanIDs) && $people_type == 'Student') { $otipSpans .= "" . $otipTABLE . sprintf($otipROW2,getLanguageText('TEXT-NAME').": ",$person['first_name'] . ' ' . $person['last_name']) . sprintf($otipROW2,getLanguageText('TEXT-TYPE').": ",$person['people_type']) . sprintf($otipROW2,getLanguageText('TEXT-STATUS').": ",$person['status']) . sprintf($otipROW2,getLanguageText('TEXT-CATEGORY').": ",$person['menu_price_category']) . sprintf($otipROW2,$GlobalText['Class'].": ",$class_info) . sprintf($otipROW2,getLanguageText('TEXT-DATE-ADDED').": ",date("Y-m-d H:i:s",$added_time)) . sprintf($otipROW2,getLanguageText('TEXT-DATE-MODIFIED').": ",$updated_date) . "\n"; $otipSpanIDs[] = $span_id; } $links = "onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\""; // Create link to access info about person placing order if ($school_num == $base_school_num) { if ($people_type == 'Student') $name = "$last_name, $first_name"; else $name = "$last_name, $first_name --"; } else { if ($people_type == 'Student') $name = "$last_name, $first_name"; else $name = "$last_name, $first_name ($people_type)"; } // Check for duplicates // $ocount = db_getVal("SELECT count(*) FROM hotlunch_order_header WHERE school_num = $school_num AND schedule_num = $schedule_num AND ordered_by_num = $ordered_by_num"); // if ($ocount > 1) $name = "$name"; // Get related values $nitems = db_getVal("SELECT count(*) FROM hotlunch_order_items WHERE school_num = $school_num AND order_num = $record_num AND active != 'N'"); $acct = "$userid"; $balance = db_getVal("select sum(transaction_amount) as balance from user_account where school_num = $school_num and user_num = $user_num AND (deleted != 'Y' OR deleted IS NULL)"); $bal_amt = $balance; $sign = ""; $balance = floatval($balance); if ($balance < 0) $sign = "-"; $balance = $sign . $currencySymbol . number_format(abs($balance),2); } // Order info span $ospan_id = "order_$record_num"; $otipSpans .= "" . $otipTABLE . sprintf($otipROW2,"Order Number: ",$record_num) . sprintf($otipROW2,"Status: ",$status) . sprintf($otipROW2,getLanguageText('TEXT-ADDED-DATE').": ",date("Y-m-d H:i:s",$added_time)) . sprintf($otipROW2,"Last Updated: ",$updated_date) . sprintf($otipROW2,"Total: ",$order_total) . sprintf($otipROW2,"Amount Paid :",$amount_paid); if ($entered_by > 0) $otipSpans .= sprintf($otipROW2,"Entered By: " ,db_getVal("SELECT userid FROM users WHERE school_num = $base_school_num AND record_num = $entered_by")); $otipSpans .= "\n"; if ($order_total == 0.00) $zeroTotal = true; // Account info span if (isset($user_num) && intval($user_num) > 0) { $span_id = "acct_$user_num"; // Get information for tool tip text $user = db_query("SELECT * FROM users WHERE school_num = $base_school_num AND record_num = $user_num"); if (db_num_rows($user) == 1) { $urow = db_fetch_array($user); if (!in_array($span_id,$otipSpanIDs)) { $user_balance = db_getVal("select sum(transaction_amount) as balance from user_account where school_num = $school_num and user_num = $user_num AND (deleted != 'Y' OR deleted IS NULL)"); $user_balance = floatval($user_balance); if ($user_balance == 0.00) $zeroBalance = true; $otipSpans .= "" . $otipTABLE . sprintf($otipROW2,"User ID: ",$urow['userid']) . sprintf($otipROW2,"User Type: ",$urow['type']) . sprintf($otipROW2,"Name: ",$urow['first_name'] . ' ' . $urow['last_name']) . sprintf($otipROW2,"Email: ",$urow['email']) . sprintf($otipROW2,"Phone: ",$urow['home_phone']) . sprintf($otipROW2,'' . getLanguageText('TEXT-CURRENT-BALANCE') . ': ',$currencySymbol . number_format($user_balance,2)); if ($urow['type'] == 'Staff') { $snum = db_getVal("SELECT record_num FROM people WHERE school_num = $base_school_num AND user_num = $user_num"); if ($snum) { $classes = db_query("SELECT * FROM classes WHERE school_num = $base_school_num AND (teacher1 = $snum OR teacher2 = $snum OR teacher3 = $snum)"); while ($row = db_fetch_array($classes)) { $cnum = $row['record_num']; $cinfo = getClassInfo($cnum); $otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-CLASS'),$cinfo); } } else { $otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-CLASS'),"Unknown"); } } $otipSpans .= "\n"; $otipSpanIDs[] = $span_id; } $userID = $userid; $userid = htmlspecialchars_decode($userid,ENT_QUOTES); if (strlen($userid) > 20) $userID = substr($userid,0,20) . "..."; $acct = "$userID"; } else { $acct = "    error    "; } } if ($_SESSION['UserInfo']['type'] == 'SuperUser') { $query = "SELECT * FROM user_account WHERE school_num = $school_num AND order_num = $record_num"; $results = db_query($query); if (db_num_rows($results) == 0) { $source = "" . $source . ""; } } $price_category_text = ''; if (isset($price_category) && strlen($price_category)) { $pcat = strtolower(str_replace(' ','',$price_category)); $pclass = ''; $price_category_text = getLanguageText('TEXT-'.$price_category); if ($price_category != 'Regular') { // $pclass = 'warning'; switch ($price_category) { case 'Special 1': if (strlen($school_record['special1_text'])) $price_category_text = $school_record['special1_text']; break; case 'Special 2': if (strlen($school_record['special2_text'])) $price_category_text = $school_record['special2_text']; break; case 'Special 3': if (strlen($school_record['special3_text'])) $price_category_text = $school_record['special3_text']; break; } } $ScheduleName = db_escape_string(str_replace("'","'",$schedule_name)); $student_name = db_escape_string(str_replace("'","'",$student_name)); $span_id = "price-category-$order_num"; $price_category = "" . $price_category_text . ""; } $sText = getLanguageText('TEXT-'.strtoupper($status)); if ($status == 'Paid' && $order_total != $amount_paid) $status = "$status"; if (!isset($payment_method)) $payment_method = ''; if (!isset($delivered)) $delivered = ''; if (!isset($price_category)) $price_category = ''; $entry = array(); $entry[] = "$name"; $entry[] = "$source"; $entry[] = "$currencySymbol" . $order_total . ""; $entry[] = "$sText"; $entry[] = $price_category; $entry[] = $payment_method; $entry[] = $nitems; $entry[] = $acct; $entry[] = $balance; $entry[] = "$delivered"; $entry['record_num'] = $record_num; $data[] = $entry; } $status_icon = "Edit Order Status"; $delete_icon = "Delete Order"; $order_icon = "Edit Order"; $print_icon = "Print Order"; $account_icon = "View Account Details"; $toggle_icon = "Set Order Status Unpaid"; $inactive_icon = "Set Order Status to Inactive"; $order_paid_icon = "Set Order Status to Paid"; $complimentary_icon = "Set Order Status to Complimentary"; $delivered_icon = "Flag as Delivered"; if (!isset($show_status)) $show_status = ""; if (!isset($show_source)) $show_source = ""; if (!isset($show_only)) $show_only = ""; if (!isset($show_all)) $show_all = ""; $action = "$action&schedule_num=$schedule_num&show_status=$show_status&show_source=$show_source&show_only=$show_only&show_all=$show_all"; $confirmStatusChange = getLanguageText('TEXT-CONFIRM-STATUS-CHANGE'); if ($hotlunch_schedule['schedule_type'] == 'Hot Lunch') { if (!in_array($_SESSION['UserInfo']['type'],array('Application Volunteer','Schedule Volunteer'))) { $commands = array( "$delete_icon", "$order_icon", "$print_icon", "$account_icon" ); } else { $commands = array( "$order_icon", "$print_icon" ); } } else { if (!in_array($_SESSION['UserInfo']['type'],array('Application Volunteer','Schedule Volunteer'))) { $commands = array( "$delete_icon", "$order_icon", "$print_icon", "$print_icon", "$account_icon" ); } else { $commands = array( "$order_icon", "$print_icon", "$print_icon" ); } } $commands[] = "$delivered_icon"; if ($_SESSION['UserInfo']['type'] == 'SuperUser') { $edit_header = "$status_icon"; array_unshift($commands, $edit_header); } // Confirmation message $msg = getLanguageText('TEXT-CONFIRM-STATUS-CHANGE'); // Add toggle status icon and set complimentary icon if required if (!isset($show_status)) $show_status = ''; if (array_key_exists('show_status', $_GET)) $show_status = db_escape_string($_GET['show_status']); if ($show_status == 'Unpaid') { $commands[] = "$inactive_icon"; $commands[] = "$order_paid_icon"; $commands[] = "$complimentary_icon"; } // Add toggle status icon and set complimentary icon if required if ((array_key_exists('show_status', $_GET) && $_GET['show_status'] == 'Inactive') || $show_status == 'Inactive') { $commands[] = "$toggle_icon"; $commands[] = "$complimentary_icon"; } // if ($_SESSION['UserInfo']['type'] == 'SuperUser') { // $commands[] = "S"; // } echo("
\n"); if (strlen($csvButton)) { echo("" . getLanguageText('TEXT-PDF') . ""); echo(" "); echo("" . getLanguageText('TEXT-CSV') . ""); echo("

"); } if (strlen($TitleText)) echo("

$TitleText

\n"); listDataCustom($data,$columnHeaders,$action,$commands,'N',$columnAlign); } echo("
\n"); include "hotlunch_orders.select.php"; $msg = getLanguageText('TEXT-CONFIRM-STATUS-CHANGE'); ?>
\n"); } // For Parent users display the list of available orders $AllowedUserTypes = array('Parent','Administration Team','Staff','Guest'); if ($naction == 'list' && checkPermission($AllowedUserTypes) == 1) { $message_width = "500"; include "form.messages.php"; switch ($_SESSION['UserInfo']['type']) { case 'Parent': case 'Administration Team': include "hotlunch_order_list.parent.php"; break; case 'Staff': include "hotlunch_order_list.staff.php"; break; case 'Guest': include "hotlunch_order_list.guest.php"; break; } } ?>