2448 lines
90 KiB
PHP
2448 lines
90 KiB
PHP
<?php
|
|
writeLog("school-functions.php");
|
|
|
|
//
|
|
// Global variables
|
|
//
|
|
if (!isset($LanguageEntries)) $LanguageEntries = array();
|
|
|
|
|
|
|
|
//
|
|
// Calculate the order subtotal, discount and total
|
|
//
|
|
function calcOrderTotal($order_num,$schedule_num,$recalc_tax='Y') {
|
|
|
|
global $school_record;
|
|
global $school_num, $base_school_num;
|
|
|
|
// Save parameters
|
|
$saved_order_num = $order_num;
|
|
$saved_schedule_num = $schedule_num;
|
|
|
|
|
|
$moduleName = "calcOrderTotal";
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog($moduleName);
|
|
writeLog("order_num: $order_num");
|
|
writeLog("schedule_num: $schedule_num");
|
|
|
|
|
|
// Get the order header
|
|
$query = "SELECT * FROM hotlunch_order_header WHERE record_num = $order_num";
|
|
writeLog("query: $query");
|
|
$results = db_query($query);
|
|
$order_header = db_fetch_assoc($results);
|
|
$ordered_by_num = $order_header['ordered_by_num'];
|
|
$price_category = $order_header['price_category'];
|
|
writeLog("price_category: $price_category");
|
|
|
|
$price_field = 'online_price';
|
|
switch ($price_category) {
|
|
case 'Special 1': $price_field = 'special_price1'; break;
|
|
case 'Special 2': $price_field = 'special_price2'; break;
|
|
case 'Special 3': $price_field = 'special_price3'; break;
|
|
}
|
|
|
|
// Get user_num
|
|
$user_num = 0;
|
|
if ($ordered_by_num > 0) {
|
|
$query = "SELECT user_num FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num";
|
|
writeLog("query: $query");
|
|
$user_num = intval(db_getVal($query));
|
|
}
|
|
// writeLog("user_num: $user_num");
|
|
|
|
// Get the schedule info
|
|
$results = db_query("SELECT * FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $schedule_num");
|
|
$schedule = db_fetch_assoc($results);
|
|
|
|
// Adjust ordered item prices and extended_price
|
|
$query = "SELECT hloi.*, hlmi.$price_field AS new_price, hlmi.online_price, hlmi.number_of_alternate_prices 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.order_num = $order_num " .
|
|
"AND hloi.ordered_by_num = $ordered_by_num " .
|
|
"AND hloi.menu_item_num = hlmi.record_num " .
|
|
"AND hloi.active = 'Y'";
|
|
writeLog("query: $query");
|
|
$order_items = db_query($query);
|
|
writeLog("Num Items: ".db_num_rows($order_items));
|
|
|
|
$category_savings = 0;
|
|
while ($row = db_fetch_assoc($order_items)) {
|
|
$ornum = $row['record_num'];
|
|
$qty = $row['qty'];
|
|
if (array_key_exists('new_price', $row)) {
|
|
$number_of_alternate_prices = $row['number_of_alternate_prices'];
|
|
if ($number_of_alternate_prices == 0) {
|
|
$new_price = floatval($row['new_price']);
|
|
$online_price = floatval($row['online_price']);
|
|
$extended_price = $qty * $new_price;
|
|
$full_price = $qty * $online_price;
|
|
$category_savings += $full_price - $extended_price;
|
|
|
|
$query = "UPDATE hotlunch_order_items SET menu_item_price = $new_price, extended_price = $extended_price WHERE school_num = $school_num AND record_num = $ornum";
|
|
db_query($query);
|
|
}
|
|
}
|
|
}
|
|
writeLog("Category Savings: $category_savings");
|
|
|
|
// Get the order total
|
|
$order_subtotal = db_getVal("SELECT sum(extended_price) FROM hotlunch_order_items WHERE school_num = $school_num AND order_num = $order_num AND active = 'Y'");
|
|
$order_total = $order_subtotal;
|
|
|
|
// Handle any schedule record discount offered
|
|
$discount_amount = $order_header['discount_amount'];
|
|
if ($order_header['source'] == 'On-Line' && $schedule['discount_offered'] > 0 && $schedule['discount_expiry_date'] >= $order_header['updated_date']) {
|
|
$discount_offered = $schedule['discount_offered'];
|
|
$discount_type = $schedule['discount_type'];
|
|
$discount_order_minimum = $schedule['discount_order_minimum'];
|
|
|
|
if ($order_total >= $discount_order_minimum) {
|
|
if ($discount_type == 'Amount') $discount_amount = $discount_offered;
|
|
else $discount_amount = $order_total * $discount_offered / 100;
|
|
}
|
|
}
|
|
|
|
// Apply the discount amount
|
|
$order_total = floatval($order_total) - floatval($discount_amount);
|
|
|
|
|
|
// Calculate any taxes
|
|
$tax_charge_amount = 0;
|
|
if ($schedule['tax_rate'] > 0.00) {
|
|
$tax_rate = $schedule['tax_rate'];
|
|
$tax_description = $schedule['tax_description'];
|
|
|
|
$query = "select sum(extended_price) " .
|
|
"from hotlunch_order_items " .
|
|
"where school_num = $school_num " .
|
|
"and ordered_by_num = $ordered_by_num " .
|
|
"and schedule_num = $schedule_num " .
|
|
"and order_num = $order_num " .
|
|
"and active != 'N' " .
|
|
"and taxable_item = 'Y'";
|
|
$taxable_total = db_getVal($query);
|
|
$taxable_total = floatval($taxable_total);
|
|
$tax_charge_amount = round($tax_rate * $taxable_total / 100,2);
|
|
}
|
|
|
|
// Determine if there is already a tax charge for this order
|
|
if ($recalc_tax == 'Y' && $user_num) {
|
|
$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 = 'Tax Charge' AND deleted = 'N'");
|
|
if (!isset($tax_description)) $tax_description = '';
|
|
$tdescription = db_escape_string($tax_description) . ' - Order (#' . $order_num . ')';
|
|
|
|
// Create or update tax charge entry if required
|
|
if ($tax_charge_amount > 0 && db_num_rows($results) == 0) {
|
|
$datetime = date("Y-m-d H:i:s",time());
|
|
$entered_time = time();
|
|
$entered_user_num = $_SESSION['UserInfo']['record_num'];
|
|
$query = "INSERT INTO user_account (school_num,user_num,schedule_num,order_num,people_num,transaction_datetime,transaction_type,note,transaction_amount," .
|
|
"deleted,entered_time,entered_by_user_num) " .
|
|
"VALUES ($school_num,$user_num,$schedule_num,$order_num,$ordered_by_num,'$datetime','Tax Charge','$tdescription',$tax_charge_amount," .
|
|
"'N',$entered_time,$entered_user_num)";
|
|
db_query($query);
|
|
}
|
|
else {
|
|
if ($tax_charge_amount > 0) {
|
|
db_query("UPDATE user_account SET transaction_amount = $tax_charge_amount,note = '$tdescription' " .
|
|
"WHERE school_num = $school_num AND user_num = $user_num AND order_num = $order_num AND transaction_type = 'Tax Charge' AND deleted = 'N'");
|
|
}
|
|
else {
|
|
db_query("DELETE FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND order_num = $order_num AND transaction_type = 'Tax Charge'");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Update database
|
|
$order_subtotal = sprintf("%0.2f",$order_subtotal);
|
|
$discount_amount = sprintf("%0.2f",$discount_amount);
|
|
$tax_amount = sprintf("%0.2f",$tax_charge_amount);
|
|
$order_total = sprintf("%0.2f",$order_total);
|
|
|
|
// writeLog("user_num: $user_num");
|
|
// writeLog("schedule_num: $schedule_num");
|
|
|
|
$multi_order_discount = 0;
|
|
if ($user_num > 0) {
|
|
$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 = 'Order'");
|
|
if (db_num_rows($results)) {
|
|
db_query("UPDATE user_account SET transaction_amount = $order_total WHERE school_num = $school_num AND user_num = $user_num AND order_num = $order_num AND transaction_type = 'Order'");
|
|
}
|
|
else {
|
|
$datetime = date("Y-m-d H:i:s",time());
|
|
$entered_time = time();
|
|
$current_name = db_getVal("SELECT concat_ws(' ',first_name,last_name) FROM people WHERE school_num = $school_num AND record_num = $ordered_by_num");
|
|
$cname = db_escape_string($current_name);
|
|
|
|
$query = "INSERT INTO user_account (school_num,user_num,schedule_num,order_num,people_num,transaction_datetime,transaction_type,note,transaction_amount,deleted,entered_time,transaction_status) " .
|
|
"VALUES ($school_num,$user_num,$schedule_num,$order_num,$ordered_by_num,'$datetime','Order','Order for $cname',$order_total,'N',$entered_time,'Open')";
|
|
db_query($query);
|
|
// writeLog("query: $query");
|
|
}
|
|
|
|
$multi_order_discount = calcMultiOrderDiscounts($user_num,$schedule_num,$school_num);
|
|
}
|
|
|
|
$query = "UPDATE hotlunch_order_header " .
|
|
"SET order_total = $order_total, " .
|
|
"order_subtotal = $order_subtotal, " .
|
|
"discount_amount = $discount_amount, " .
|
|
"category_savings = $category_savings, " .
|
|
"tax_amount = $tax_amount " .
|
|
"WHERE record_num = $order_num";
|
|
writeLog($query);
|
|
db_query($query);
|
|
|
|
$numItems = db_getVal("SELECT count(*) FROM hotlunch_order_items WHERE school_num = $school_num AND order_num = $order_num AND active = 'Y'");
|
|
|
|
// Restore parameters
|
|
$order_num = $saved_order_num;
|
|
$schedule_num = $saved_schedule_num;
|
|
|
|
|
|
// Return array of values
|
|
return(array("order_subtotal" => $order_subtotal,
|
|
"discount_amount" => $discount_amount,
|
|
"tax_amount" => $tax_amount,
|
|
"order_total" => $order_total,
|
|
"category_savings" => $category_savings,
|
|
"multi_order_discount" => $multi_order_discount,
|
|
"num_items" => $numItems));
|
|
}
|
|
|
|
|
|
//
|
|
// calcMultiOrderDiscounts
|
|
//
|
|
// Calculate any discounts for multiple orders based on entries in the hotlunch_schedules_multi_order_discounts table
|
|
//
|
|
function calcMultiOrderDiscounts($user_num,$schedule_num,$school_num) {
|
|
global $school_record;
|
|
if (!isset($school_num) && isset($school_record)) $school_num = $school_record['record_num'];
|
|
|
|
$moduleName = "calcMultiOrderDiscounts";
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog($moduleName);
|
|
// writeLog("user_num: $user_num");
|
|
// writeLog("schedule_num: $schedule_num");
|
|
|
|
|
|
$today = date("Y-m-d",time());
|
|
$query = "SELECT * FROM hotlunch_schedules_multi_order_discounts WHERE school_num = $school_num " .
|
|
"AND (expiry_date >= '$today' OR expiry_date IS NULL) " .
|
|
"AND (schedule_num1 = $schedule_num " .
|
|
"OR schedule_num2 = $schedule_num " .
|
|
"OR schedule_num3 = $schedule_num " .
|
|
"OR schedule_num4 = $schedule_num)";
|
|
// writeLog("query: $query");
|
|
$discount = db_query($query);
|
|
|
|
// If no discount entry exists then delete any discounts for current schedule and return
|
|
if (db_num_rows($discount) == 0) {
|
|
$query = "DELETE FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND transaction_type = 'Multiple Order Discount' " .
|
|
"AND schedule_num = $schedule_num";
|
|
// writeLog("query: $query");
|
|
db_query($query);
|
|
return;
|
|
}
|
|
|
|
$discount_row = db_fetch_assoc($discount);
|
|
extract($discount_row);
|
|
|
|
|
|
// Format set of schedules
|
|
$sset = $schedule_num1 . ',' . $schedule_num2 . ',' . $schedule_num3 . ',' . $schedule_num4;
|
|
|
|
// Delete any existing multi order discounts for schedules
|
|
$query = "DELETE FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND transaction_type = 'Multiple Order Discount' " .
|
|
"AND schedule_num IN ($sset)";
|
|
// writeLog("query: $query");
|
|
db_query($query);
|
|
|
|
|
|
// Get set of people in this account
|
|
$people = db_query("SELECT * FROM people WHERE school_num = $school_num AND user_num = $user_num");
|
|
$numPeople = db_num_rows($people);
|
|
// writeLog("numPeople: $numPeople");
|
|
|
|
// If there is only one person in account then return
|
|
if ($numPeople <= 1) return;
|
|
|
|
// Get set of people numbers in account
|
|
$p = array();
|
|
while ($row = db_fetch_assoc($people)) {
|
|
$p[] = $row['record_num'];
|
|
}
|
|
$pset = implode(',',$p);
|
|
// writeLog("pset: $pset");
|
|
|
|
|
|
// Get date of last order
|
|
$query = "SELECT max(added_time) FROM hotlunch_order_header " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND schedule_num IN ($sset) " .
|
|
"AND ordered_by_num IN ($pset) " .
|
|
"AND status != 'Deleted'";
|
|
// writeLog("query: $query");
|
|
$added_time = db_getVal($query);
|
|
|
|
// Get set of orders
|
|
$query = "SELECT * FROM hotlunch_order_header " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND schedule_num IN ($sset) " .
|
|
"AND ordered_by_num IN ($pset) " .
|
|
"AND status != 'Deleted' " .
|
|
"ORDER BY order_total DESC";
|
|
// writeLog("query: $query");
|
|
$orders = db_query($query);
|
|
$numOrders = db_num_rows($orders);
|
|
// writeLog("numOrders: $numOrders");
|
|
|
|
// If there is no order or only 1 order return
|
|
if ($numOrders <= 1) return;
|
|
|
|
|
|
$user_account = new Table("user_account");
|
|
|
|
$total_discount = 0;
|
|
$count = 0;
|
|
while ($order = db_fetch_assoc($orders)) {
|
|
$count++;
|
|
// writeLog("count: $count");
|
|
|
|
if ($count > 1) {
|
|
$dataSet = array();
|
|
$dataSet['school_num'] = $school_num;
|
|
$dataSet['user_num'] = $user_num;
|
|
|
|
// Get the schedule info
|
|
$schedule_num = $order['schedule_num'];
|
|
$results = db_query("SELECT * FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $schedule_num");
|
|
$schedule = db_fetch_assoc($results);
|
|
|
|
$discount_rate = $discount_row["order$count"."_percentage"];
|
|
|
|
$dataSet['transaction_amount'] = round($order['order_total'] * $discount_rate * -1) / 100;
|
|
$dataSet['transaction_type'] = 'Multiple Order Discount';
|
|
$dataSet['payment_method'] = $transaction_type;
|
|
$dataSet['transaction_status'] = 'Open';
|
|
$dataSet['schedule_num'] = $order['schedule_num'];
|
|
$dataSet['order_num'] = $order['record_num'];
|
|
$dataSet['entered_by_user_num'] = $_SESSION['UserInfo']['record_num'];
|
|
$dataSet['deleted'] = 'N';
|
|
$dataSet['deleted_datetime'] = NULL;
|
|
$dataSet['delete_reason'] = NULL;
|
|
$dataSet['entered_time'] = time();
|
|
$dataSet['posting_date'] = date("Y-m-d",time());
|
|
// $dataSet['transaction_datetime'] = date("Y-m-d H:i:s",time());
|
|
// $dataSet['transaction_datetime'] = date("Y-m-d H:i:s",$order['added_time'] + 1);
|
|
$dataSet['transaction_datetime'] = date("Y-m-d H:i:s",$added_time + 1);
|
|
$dataSet['note'] = getLanguageText('TEXT-ORDER') . " #" . $order['record_num'] . " - " . $schedule['schedule_name'];
|
|
|
|
if ($dataSet['transaction_amount'] < 0.00) {
|
|
$query = $user_account->BuildInsert($dataSet);
|
|
// writeLog("query: $query");
|
|
db_query($query);
|
|
}
|
|
|
|
$total_discount += $dataSet['transaction_amount'];
|
|
}
|
|
}
|
|
|
|
return($total_discount);
|
|
}
|
|
|
|
|
|
//
|
|
// Log change to an order
|
|
//
|
|
function logOrderChange($order_num, $order_action, $module = "", $schedule_num = 0) {
|
|
global $school_record;
|
|
$school_num = $school_record['record_num'];
|
|
|
|
$order_num = intval($order_num);
|
|
$updated_by = 0;
|
|
if (array_key_exists('UserInfo', $_SESSION) && array_key_exists('record_num', $_SESSION['UserInfo'])) $updated_by = $_SESSION['UserInfo']['record_num'];
|
|
$log_time = time();
|
|
$updated_time = date("Y-m-d H:i:s",$log_time);
|
|
|
|
$order = array();
|
|
|
|
$order['school_num'] = $school_num;
|
|
$order['log_time'] = $log_time;
|
|
$order['updated_by'] = $updated_by;
|
|
$order['updated_time'] = $updated_time;
|
|
$order['order_num'] = $order_num;
|
|
$order['order_action'] = $order_action;
|
|
$order['module'] = $module;
|
|
$order['ordered_by_num'] = 0;
|
|
$order['user_num'] = 0;
|
|
$order['schedule_num'] = 0;
|
|
|
|
|
|
$orderLog = new Table("hotlunch_order_change_log");
|
|
|
|
if ($order_num < 0) {
|
|
$order['log_status'] = "ORDER NUMBER ERROR";
|
|
$query = $orderLog->BuildInsert($order);
|
|
db_query($query);
|
|
return;
|
|
}
|
|
|
|
|
|
if ($order_num == 0) {
|
|
$order['log_status'] = "MASS ORDER UPDATE";
|
|
$order['schedule_num'] = intval($schedule_num);
|
|
$query = $orderLog->BuildInsert($order);
|
|
db_query($query);
|
|
return;
|
|
}
|
|
|
|
|
|
$results = db_query("SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $order_num");
|
|
if (db_num_rows($results) == 0) {
|
|
$order['log_status'] = "ORDER NOT FOUND";
|
|
$query = $orderLog->BuildInsert($order);
|
|
db_query($query);
|
|
return;
|
|
}
|
|
|
|
$order = db_fetch_assoc($results);
|
|
|
|
$people_num = $order['ordered_by_num'];
|
|
$order['user_num'] = 0;
|
|
if ($people_num > 0) {
|
|
$results = db_query("SELECT * FROM people WHERE school_num = $school_num AND record_num = $people_num");
|
|
if (db_num_rows($results)) {
|
|
$person = db_fetch_assoc($results);
|
|
$order['user_num'] = intval($person['user_num']);
|
|
}
|
|
}
|
|
|
|
$order['log_time'] = $log_time;
|
|
$order['updated_by'] = $updated_by;
|
|
$order['updated_time'] = $updated_time;
|
|
$order['order_num'] = $order_num;
|
|
$order['order_action'] = $order_action;
|
|
$order['module'] = $module;
|
|
|
|
$order['order_detail'] = getOrderDetailLog($order_num);
|
|
$order['log_status'] = "Order Logged";
|
|
|
|
$query = $orderLog->BuildInsert($order);
|
|
db_query($query);
|
|
}
|
|
|
|
|
|
//
|
|
// Get the details of an order for logging
|
|
//
|
|
function getOrderDetailLog($order_num) {
|
|
global $school_record;
|
|
$school_num = $school_record['record_num'];
|
|
|
|
$order_detail = "";
|
|
$items = db_query("SELECT * FROM hotlunch_order_items WHERE school_num = $school_num AND order_num = $order_num");
|
|
if (db_num_rows($items) == 0) {
|
|
return("No Order Items Found");
|
|
}
|
|
else {
|
|
while ($row = db_fetch_assoc($items)) {
|
|
extract($row);
|
|
|
|
$results = db_query("SELECT * FROM hotlunch_menu_items WHERE school_num = $school_num AND record_num = $menu_item_num");
|
|
if (db_num_rows($results) == 0) {
|
|
$order_detail .= $menu_num . '|' .
|
|
$menu_item_num . '|' .
|
|
'ITEM NOT FOUND';
|
|
continue;
|
|
}
|
|
|
|
$item = db_fetch_assoc($results);
|
|
$item_title = $item['item_title'];
|
|
$item_description = $item['item_description'];
|
|
|
|
if (!isset($options_ordered)) $options_ordered = '';
|
|
if (!isset($options2_ordered)) $options2_ordered = '';
|
|
if (!isset($options3_ordered)) $options3_ordered = '';
|
|
if (!isset($options4_ordered)) $options4_ordered = '';
|
|
if (!isset($options5_ordered)) $options5_ordered = '';
|
|
if (!isset($options6_ordered)) $options6_ordered = '';
|
|
|
|
$options_ordered = str_replace("\n","::",trim($options_ordered));
|
|
$options2_ordered = str_replace("\n","::",trim($options2_ordered));
|
|
$options3_ordered = str_replace("\n","::",trim($options3_ordered));
|
|
$options4_ordered = str_replace("\n","::",trim($options4_ordered));
|
|
$options5_ordered = str_replace("\n","::",trim($options5_ordered));
|
|
$options6_ordered = str_replace("\n","::",trim($options6_ordered));
|
|
|
|
$order_detail .= $menu_num . '|' .
|
|
$menu_item_num . '|' .
|
|
$menu_item_price . '|' .
|
|
$qty . '|' .
|
|
$extended_price . '|' .
|
|
$item_title . '|' .
|
|
$item_description . '|' .
|
|
$options_ordered . '|' .
|
|
$options2_ordered . '|' .
|
|
$options3_ordered . '|' .
|
|
$options4_ordered . '|' .
|
|
$options5_ordered . '|' .
|
|
$options6_ordered . "::\n";
|
|
}
|
|
|
|
return($order_detail);
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
// Delete existing order
|
|
//
|
|
function deleteOrder($order_num) {
|
|
global $school_record;
|
|
$school_num = $school_record['record_num'];
|
|
$deleted_by = $_SESSION['UserInfo']['record_num'];
|
|
$delete_reason = getLanguageText('TEXT-ORDER-DELETED');
|
|
|
|
$deleted_datetime = date("Y-m-d H:i:s",time());
|
|
|
|
$query = "SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $order_num";
|
|
$results = db_query($query);
|
|
|
|
if (db_num_rows($results)) {
|
|
$order = db_fetch_assoc($results);
|
|
$ordered_by_num = $order['ordered_by_num'];
|
|
$schedule_num = $order['schedule_num'];
|
|
|
|
$results = db_query("SELECT * FROM people WHERE school_num = $school_num AND record_num = $ordered_by_num");
|
|
$row = db_fetch_assoc($results);
|
|
$user_num = $row['user_num'];
|
|
|
|
// Update order to deleted status
|
|
db_query("UPDATE hotlunch_order_header SET status = 'Deleted' WHERE school_num = $school_num AND record_num = $order_num");
|
|
db_query("UPDATE hotlunch_order_items SET active = 'N' WHERE school_num = $school_num AND order_num = $order_num");
|
|
|
|
// Update user account to delete line items associated with order
|
|
db_query("UPDATE user_account SET deleted = 'Y', deleted_datetime = '$deleted_datetime', deleted_by_user_num = 0, delete_reason = 'Automatic deletion of Inactive Order' " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND order_num = $order_num");
|
|
|
|
// Update any multi order discounts
|
|
calcMultiOrderDiscounts($user_num,$schedule_num,$school_num);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Post a transaction to user_account
|
|
//
|
|
function postTransaction($transaction_record) {
|
|
global $school_record;
|
|
$school_num = $school_record['record_num'];
|
|
|
|
$moduleName = "postTransaction";
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog($moduleName);
|
|
|
|
extract($transaction_record);
|
|
// writeLog("school_num: $school_num");
|
|
// writeLog("transaction_type: $transaction_type");
|
|
|
|
$transaction_record['deleted'] = 'N';
|
|
$transaction_record['entered_time'] = date("Y-m-d H:i:s",time());
|
|
$transaction_record['transaction_status'] = 'Open';
|
|
|
|
if (!isset($transaction_record['transaction_datetime']) || strlen($transaction_record['transaction_datetime']) == 0) {
|
|
$transaction_record['transaction_datetime'] = $transaction_record['entered_time'];
|
|
}
|
|
|
|
|
|
// Get balance before posting transaction
|
|
if ($transaction_amount > 0) {
|
|
$userBalancePrior = db_getVal("SELECT sum(transaction_amount) FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND (deleted != 'Y' OR deleted IS NULL)");
|
|
// writeLog("userBalancePrior: $userBalancePrior");
|
|
|
|
// If there is a credit on the account
|
|
if ($userBalancePrior < 0) {
|
|
}
|
|
}
|
|
|
|
// Insert user_account entry
|
|
$table = new Table("user_account");
|
|
$query = $table->BuildInsert($transaction_record);
|
|
// writeLog("query: $query");
|
|
db_query($query);
|
|
$trx_num = db_insert_id();
|
|
|
|
return($trx_num);
|
|
}
|
|
|
|
|
|
//
|
|
// Post a credit to a user account
|
|
//
|
|
function postCredit($transaction_record, $selected_transactions=array()) {
|
|
global $school_record;
|
|
$school_num = $school_record['record_num'];
|
|
|
|
$moduleName = "postPayment";
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog($moduleName);
|
|
|
|
extract($transaction_record);
|
|
|
|
// Get user balance before posting
|
|
$userBalancePrior = db_getVal("SELECT sum(transaction_amount) FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND (deleted != 'Y' OR deleted IS NULL)");
|
|
// writeLog("userBalancePrior: $userBalancePrior");
|
|
|
|
$trx_num = postTransaction($transaction_record);
|
|
// writeLog("trx_num: $trx_num");
|
|
|
|
|
|
// Process transactions for this payment
|
|
$today = date("Y-m-d",time());
|
|
$order_payments = "";
|
|
$transaction_payments = "";
|
|
$total_posted = 0;
|
|
$allocated_total = 0;
|
|
|
|
// Get set of transactions to post to
|
|
if (count($selected_transactions) == 0) {
|
|
|
|
// Get set of "Open" transactions
|
|
$query = "SELECT * FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND transaction_status = 'Open' " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL) " .
|
|
"ORDER BY transaction_datetime ASC";
|
|
$trxResults = db_query($query);
|
|
}
|
|
else {
|
|
$transactions = implode(',',$selected_transactions);
|
|
|
|
// Get set of "Selected" transactions
|
|
$query = "SELECT * FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND transaction_status = 'Open' " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL) " .
|
|
"AND record_num IN ($transactions) " .
|
|
"ORDER BY transaction_datetime ASC";
|
|
$trxResults = db_query($query);
|
|
}
|
|
|
|
$trxComplete = false;
|
|
|
|
$order_numbers = array();
|
|
while (!$trxComplete && $row = db_fetch_assoc($trxResults)) {
|
|
$trxnum = $row['record_num'];
|
|
$onum = $row['order_num'];
|
|
$snum = $row['schedule_num'];
|
|
$trxtotal = $row['transaction_amount'];
|
|
$trxpaid = $row['amount_paid'];
|
|
$owing = $trxtotal - $trxpaid;
|
|
|
|
// writeLog("$moduleName: trxtotal: $trxtotal");
|
|
// writeLog("$moduleName: trxpaid: $trxpaid");
|
|
|
|
$amt = $owing;
|
|
// writeLog("$moduleName: amt: $amt");
|
|
// writeLog("$moduleName: allocated_total: $allocated_total");
|
|
// writeLog("$moduleName: owing: $owing");
|
|
// writeLog("$moduleName: transaction_amount: $transaction_amount");
|
|
|
|
if ($allocated_total + $owing > abs($transaction_amount)) {
|
|
$amt = abs($transaction_amount) - $allocated_total;
|
|
}
|
|
// writeLog("$moduleName: amt: $amt");
|
|
$payment_amt = $amt;
|
|
// writeLog("$moduleName: payment_amt: $payment_amt");
|
|
|
|
$total_posted += $payment_amt;
|
|
|
|
if (strlen($transaction_payments) > 0) $transaction_payments .= "|";
|
|
$transaction_payments .= "{" . $trxnum . ":" . $payment_amt . "}";
|
|
$allocated_total += $payment_amt;
|
|
|
|
// Save transaction details
|
|
$now = time();
|
|
$query = "INSERT INTO user_account_detail (school_num,user_num,transaction_num,posted_to_transaction,posted_amount,posted_schedule,entered_time,deleted) " .
|
|
"VALUES ($school_num, $user_num, $trx_num, $trxnum, $payment_amt, $snum, $now, 'N')";
|
|
// writeLog("$moduleName: query: $query");
|
|
db_query($query);
|
|
|
|
if ($onum > 0) {
|
|
if (strlen($order_payments) > 0) $order_payments .= "|";
|
|
$order_payments .= "{" . $onum . ":" . $payment_amt . "}";
|
|
$order_numbers[] = $onum;
|
|
|
|
$query = "UPDATE hotlunch_order_header " .
|
|
"SET amount_paid = amount_paid + $payment_amt, " .
|
|
"paid_date = '$today', " .
|
|
"payment_method = '$payment_method' " .
|
|
"WHERE record_num = $onum";
|
|
// writeLog("$moduleName: query: $query");
|
|
db_query($query);
|
|
|
|
$query = "UPDATE hotlunch_order_header " .
|
|
"SET status = 'Paid' " .
|
|
"WHERE record_num = $onum " .
|
|
"AND amount_paid = order_total";
|
|
// writeLog("$moduleName: query: $query");
|
|
db_query($query);
|
|
}
|
|
|
|
|
|
// Update user account transactions
|
|
$query = "UPDATE user_account " .
|
|
"SET amount_paid = amount_paid + $payment_amt " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND record_num = $trxnum";
|
|
// writeLog("$moduleName: query: $query");
|
|
db_query($query);
|
|
|
|
// Close transactions that are paid in full
|
|
$query = "UPDATE user_account " .
|
|
"SET transaction_status = 'Closed' " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND amount_paid = transaction_amount " .
|
|
"AND record_num = $trxnum";
|
|
// writeLog("$moduleName: query: $query");
|
|
db_query($query);
|
|
}
|
|
|
|
$order_payments = db_escape_string($order_payments);
|
|
$transaction_payments = db_escape_string($transaction_payments);
|
|
$query = "UPDATE user_account SET order_payments = '$order_payments', transaction_payments = '$transaction_payments', amount_paid = $allocated_total WHERE record_num = $trx_num";
|
|
// writeLog("$moduleName: query: $query");
|
|
db_query($query);
|
|
|
|
// writeLog("$moduleName: total_posted: $total_posted");
|
|
// writeLog("$moduleName: transaction_amount: $transaction_amount");
|
|
|
|
// if ($total_posted < abs($transaction_amount)) {
|
|
// // Save transaction balance
|
|
// $amt = (abs($transaction_amount) - $total_posted) * -1;
|
|
// $now = time();
|
|
// $query = "INSERT INTO user_account_detail (school_num,user_num,transaction_num,posted_to_transaction,posted_amount,posted_schedule,entered_time,deleted) " .
|
|
// "VALUES ($school_num, $user_num, $trx_num, 0, $amt, 0, $now, 'N')";
|
|
// writeLog("$moduleName: query: $query");
|
|
// db_query($query);
|
|
// }
|
|
|
|
return($trx_num);
|
|
}
|
|
|
|
|
|
//
|
|
// adjustUserAccountDetails - create user account detail entries for all transactions
|
|
//
|
|
function adjustUserAccountDetails($user_num,$school_num = 0) {
|
|
global $school_record;
|
|
if ($school_num == 0) $school_num = $school_record['record_num'];
|
|
|
|
$moduleName = "adjustUserAccountDetails";
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog($moduleName);
|
|
// startLog($moduleName);
|
|
// writeLog("user_num: $user_num");
|
|
|
|
$uwhere = "";
|
|
if ($user_num > 0) $uwhere = "AND user_num = $user_num ";
|
|
|
|
$currMonth = date("m",time());
|
|
$currYear = date("Y",time());
|
|
switch ($currMonth) {
|
|
case '01':
|
|
$sdate = ($currYear - 1) . "-12-01";
|
|
$tdate = ($currYear - 1) . "-09-01";
|
|
$tdate = ($currYear - 1) . "-11-01";
|
|
break;
|
|
case '02':
|
|
$sdate = $currYear . "-01-01";
|
|
$sdate = ($currYear - 1) . "-12-01";
|
|
$tdate = ($currYear - 1) . "-10-01";
|
|
$tdate = ($currYear - 1) . "-11-01";
|
|
break;
|
|
case '03':
|
|
$sdate = ($currYear - 1) . "-12-01";
|
|
$sdate = $currYear . "-02-01";
|
|
$tdate = ($currYear - 1) . "-11-01";
|
|
$tdate = $currYear . "-01-01";
|
|
break;
|
|
case '04':
|
|
$sdate = $currYear . "-03-01";
|
|
$tdate = $currYear . "-02-01";
|
|
break;
|
|
case '05':
|
|
$sdate = $currYear . "-04-01";
|
|
$tdate = $currYear . "-03-01";
|
|
break;
|
|
case '06':
|
|
$sdate = $currYear . "-05-01";
|
|
$tdate = $currYear . "-04-01";
|
|
break;
|
|
case '07':
|
|
$sdate = $currYear . "-06-01";
|
|
$tdate = $currYear . "-05-01";
|
|
break;
|
|
case '08':
|
|
case '09':
|
|
$sdate = $currYear . "-07-01";
|
|
$tdate = $currYear . "-05-01";
|
|
break;
|
|
case '10':
|
|
$sdate = $currYear . "-08-01";
|
|
$tdate = $currYear . "-06-01";
|
|
break;
|
|
case '11':
|
|
$sdate = $currYear . "-08-01";
|
|
$tdate = $currYear . "-08-01";
|
|
break;
|
|
case '12':
|
|
$sdate = $currYear . "-08-01";
|
|
$tdate = $currYear . "-08-01";
|
|
break;
|
|
}
|
|
|
|
$sdate = date("Y-m-d",time() - 60 * 60 * 24 * 10);
|
|
|
|
$query = "SELECT DISTINCT user_num FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND transaction_datetime >= '$sdate 00:00:00' " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL) " .
|
|
$uwhere;
|
|
// writeLog("query: $query");
|
|
$users = db_query($query);
|
|
$nUsers = db_num_rows($users);
|
|
// writeLog("NumUsers: $nUsers");
|
|
|
|
while ($row = db_fetch_assoc($users)) {
|
|
extract($row);
|
|
|
|
$query = "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)";
|
|
// writeLog("query: $query");
|
|
$balance = db_getVal($query);
|
|
|
|
$userid = db_getVal("SELECT userid FROM users WHERE school_num = $school_num AND record_num = $user_num");
|
|
|
|
// $numDetails = db_getVal("SELECT count(*) FROM user_account_detail WHERE school_num = $school_num AND user_num = $user_num");
|
|
$query = "DELETE FROM user_account_detail WHERE school_num = $school_num AND user_num = $user_num";
|
|
// writeLog("query: $query");
|
|
db_query($query);
|
|
|
|
$query = "SELECT * FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND transaction_status != 'Open' AND (deleted != 'Y' OR deleted IS NULL)";
|
|
$trx = db_query($query);
|
|
while ($row = db_fetch_assoc($trx)) {
|
|
$rnum = $row['record_num'];
|
|
$query = "UPDATE user_account SET transaction_status = 'Open' WHERE school_num = $school_num AND user_num = $user_num AND record_num = $rnum";
|
|
$query = "UPDATE user_account SET transaction_status = 'Open' WHERE record_num = $rnum";
|
|
db_query($query);
|
|
}
|
|
// writeLog("query: $query");
|
|
db_query($query);
|
|
|
|
$trx_amount = 0;
|
|
|
|
// Check for a credit transaction
|
|
$query = "SELECT * FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL) " .
|
|
"AND transaction_amount < 0.00 " .
|
|
"AND transaction_datetime >= '$tdate 00:00:00' " .
|
|
"ORDER BY transaction_datetime";
|
|
// writeLog("query: $query");
|
|
$credits = db_query($query);
|
|
|
|
if (db_num_rows($credits) > 0) {
|
|
|
|
// Get total of all payments
|
|
$query = "SELECT sum(transaction_amount) AS amount, count(*) AS num FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL) " .
|
|
"AND transaction_type = 'Payment'";
|
|
$results = db_query($query);
|
|
$row = db_fetch_assoc($results);
|
|
$pTotal = $row['amount'];
|
|
$pNum = $row['num'];
|
|
|
|
// Get total of all other credits
|
|
$query = "SELECT sum(transaction_amount) AS amount, count(*) AS num FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL) " .
|
|
"AND transaction_amount < 0.00 " .
|
|
"AND transaction_type != 'Payment'";
|
|
$results = db_query($query);
|
|
$row = db_fetch_assoc($results);
|
|
$cTotal = $row['amount'];
|
|
$cNum = $row['num'];
|
|
|
|
// Get total of all charges
|
|
$query = "SELECT sum(transaction_amount) AS amount, count(*) AS num FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL) " .
|
|
"AND transaction_amount > 0.00";
|
|
$results = db_query($query);
|
|
$row = db_fetch_assoc($results);
|
|
$dTotal = $row['amount'];
|
|
$dNum = $row['num'];
|
|
|
|
$net = number_format($dTotal + $cTotal + $pTotal,2);
|
|
|
|
$total_credits = 0;
|
|
$total_debits = 0;
|
|
|
|
|
|
// Process each credit transaction
|
|
while ($row = db_fetch_assoc($credits)) {
|
|
$trx_amount = $row['transaction_amount'];
|
|
$trx_type = $row['transaction_type'];
|
|
$ptrxNum = $row['record_num'];
|
|
$note = $row['note'];
|
|
$oNum = $row['order_num'];
|
|
$trxPayments = $row['transaction_payments'];
|
|
|
|
if ($trx_type == 'Credit') {
|
|
$trx_type = 'Generated Credit';
|
|
db_query("UPDATE user_account SET transaction_type = '$trx_type' WHERE school_num = $school_num AND record_num = $ptrxNum");
|
|
}
|
|
|
|
$receipt_status = 'Open';
|
|
$now = time();
|
|
|
|
$today = date("Y-m-d",time());
|
|
$order_payments = "";
|
|
$transaction_payments = "";
|
|
|
|
$total_credits += $row['transaction_amount'];
|
|
|
|
$trxComplete = false;
|
|
|
|
$allocated_total = 0;
|
|
|
|
$twhere = "";
|
|
if (strlen($trxPayments)) {
|
|
$entries = explode('|',$trxPayments);
|
|
$trxNums = "";
|
|
for ($i = 0; $i < count($entries); $i++) {
|
|
$code = str_replace('{','',str_replace('}','',$entries[$i]));
|
|
if (strlen($code) && strpos($code, ':') > 0) {
|
|
list($trx,$amt) = explode(":",$code);
|
|
if (strlen($trx)) {
|
|
if (strlen($trxNums)) $trxNums .= ",";
|
|
$trxNums .= $trx;
|
|
}
|
|
}
|
|
}
|
|
$twhere = "AND record_num IN ($trxNums) ";
|
|
}
|
|
|
|
|
|
// Get current transactions
|
|
$query = "SELECT * FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL) " .
|
|
"AND transaction_amount > 0.00 " .
|
|
$twhere .
|
|
"ORDER BY transaction_datetime, transaction_amount DESC";
|
|
$results = db_query($query);
|
|
while (!$trxComplete && $row = db_fetch_assoc($results)) {
|
|
extract($row);
|
|
|
|
$dtrxNum = $record_num;
|
|
|
|
$tAmt = $transaction_amount * -1;
|
|
$aAmt = floatval(db_getVal("SELECT sum(posted_amount) FROM user_account_detail WHERE school_num = $school_num AND posted_to_transaction = $dtrxNum"));
|
|
$pAmt = $tAmt - $aAmt;
|
|
$total_debits += $transaction_amount;
|
|
$total_net = $total_debits + $total_credits;
|
|
|
|
$available = $trx_amount - $allocated_total;
|
|
if ($transaction_amount > 0 && abs($pAmt) > abs($available)) {
|
|
$pAmt = $available;
|
|
}
|
|
$allocated_total += $pAmt;
|
|
|
|
$schedule_num = intval($schedule_num);
|
|
$query = "INSERT INTO user_account_detail (school_num,user_num,receipt_number,receipt_status,transaction_num,posted_to_transaction,posted_amount,posted_schedule,entered_time,deleted) " .
|
|
"VALUES ($school_num,$user_num,'none','$receipt_status',$ptrxNum,$dtrxNum,$pAmt,$schedule_num,$now,'N')";
|
|
db_query($query);
|
|
|
|
// Get total allocated to current transaction
|
|
$postedTotal = db_getVal("SELECT sum(posted_amount) FROM user_account_detail WHERE school_num = $school_num AND posted_to_transaction = $dtrxNum");
|
|
db_query("UPDATE user_account SET amount_paid = $postedTotal WHERE school_num = $school_num AND record_num = $dtrxNum");
|
|
|
|
if ($postedTotal + $transaction_amount == 0.00) {
|
|
$query = "UPDATE user_account SET transaction_status = 'Closed' WHERE school_num = $school_num AND record_num = $dtrxNum";
|
|
$query = "UPDATE user_account SET transaction_status = 'Closed' WHERE record_num = $dtrxNum";
|
|
db_query($query);
|
|
}
|
|
|
|
if ($allocated_total == $trx_amount) {
|
|
$trxComplete = true;
|
|
$query = "UPDATE user_account SET transaction_status = 'Closed' WHERE school_num = $school_num AND record_num = $ptrxNum";
|
|
$query = "UPDATE user_account SET transaction_status = 'Closed' WHERE record_num = $ptrxNum";
|
|
db_query($query);
|
|
|
|
if ($trx_type == 'Payment') {
|
|
db_query("UPDATE school_receipt_number SET receipt_number = receipt_number + 1 WHERE school_num = $school_num");
|
|
$rcptNum = db_getVal("SELECT receipt_number FROM school_receipt_number WHERE school_num = $school_num");
|
|
$trxDT = date("ymdhi",strtotime($transaction_datetime));
|
|
$rcptNum = $user_num . "-$trxDT";
|
|
db_query("UPDATE user_account_detail SET receipt_status = 'Closed', receipt_number = '$rcptNum' WHERE school_num = $school_num AND user_num = $user_num AND receipt_status = 'Open'");
|
|
db_query("UPDATE user_account_detail SET receipt_number = '$rcptNum' WHERE school_num = $school_num AND user_num = $user_num AND receipt_number = 'none'");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$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)");
|
|
|
|
if ($user_balance == 0.00) {
|
|
$query = "SELECT * FROM user_account " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND user_num = $user_num " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL)";
|
|
$results = db_query($query);
|
|
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$rnum = $row['record_num'];
|
|
$query = "UPDATE user_account SET transaction_status = 'Closed' WHERE record_num = $rnum";
|
|
db_query($query);
|
|
}
|
|
}
|
|
}
|
|
// writeLog("complete");
|
|
}
|
|
|
|
|
|
|
|
function echoValue($text) {
|
|
$text = str_replace("'","'",$text);
|
|
$text = str_replace('"',""",$text);
|
|
echo($text);
|
|
}
|
|
|
|
|
|
|
|
function getPageContent($school_num,$location) {
|
|
|
|
if (array_key_exists('display_content',$_GET) && $_GET['display_content'] == 'No') return("");
|
|
|
|
// Get the content record if there is one
|
|
$query = "select content " .
|
|
"from formatted_content " .
|
|
"where school_num = $school_num " .
|
|
"and content_id = '$location'";
|
|
$content = db_getVal($query);
|
|
|
|
$content = htmlspecialchars_decode($content,ENT_QUOTES);
|
|
$content = preg_replace("#<script>#","",$content);
|
|
$content = preg_replace("#</script>#","",$content);
|
|
|
|
return($content);
|
|
}
|
|
|
|
|
|
function logActivity($action) {
|
|
global $school_record;
|
|
|
|
$school_num = $school_record['record_num'];
|
|
|
|
if ($_SESSION['UserInfo']['type'] == 'Parent' ||
|
|
$_SESSION['UserInfo']['type'] == 'Guest' ||
|
|
$_SESSION['UserInfo']['type'] == 'Supplier') return;
|
|
|
|
$user_ip = $_SESSION['LoginIP'];
|
|
$login_time = $_SESSION['LoginTime'];
|
|
$username = $_SESSION['UserInfo']['userid'];
|
|
$curr_time = time();
|
|
$today = date("Y-m-d",$curr_time);
|
|
|
|
if (strlen($username) > 0 && strlen($user_ip) > 0 && $login_time > 0) {
|
|
$session_school_num = $school_num;
|
|
$uname = db_escape_string($username);
|
|
// if ($username == 'superuser') $session_school_num = 0;
|
|
|
|
// Update activity time in login_log
|
|
$query = "update login_log set last_activity_date = '$today', last_activity = $curr_time, last_activity_date = '$today' " .
|
|
"where school_num = $session_school_num " .
|
|
"and userid = '$uname' " .
|
|
"and login_time = $login_time " .
|
|
"and user_ip = '$user_ip'";
|
|
db_query("START TRANSACTION");
|
|
db_query($query);
|
|
db_query("COMMIT");
|
|
|
|
// Make an entry to the activity_log
|
|
if (isset($_GET['naction']) && strlen($_GET['naction']) > 0) $na = $_GET['naction'];
|
|
if (isset($_POST['naction']) && strlen($_POST['naction']) > 0) $na = $_POST['naction'];
|
|
$activity = $action;
|
|
if (isset($na) && strlen($na)) $activity .= " - $na";
|
|
|
|
// Save $_GET or $_POST if there is data
|
|
$additional_info = "";
|
|
if (is_array($_GET) && count($_GET) > 0) $additional_info .= parseArray($_GET,"_GET");
|
|
if (is_array($_POST) && count($_POST) > 0) $additional_info .= parseArray($_POST,"_POST");
|
|
|
|
if (strlen($additional_info) > 0) $additional_info = db_escape_string($additional_info);
|
|
|
|
$activity_datetime = date("Y-m-d H:i:s",$curr_time);
|
|
$query = "insert into activity_log (school_num,userid,user_ip,activity_time,activity_datetime,activity,information) " .
|
|
"values($school_num,'$uname','$user_ip',$curr_time,'$activity_datetime','" . db_escape_string($activity) . "','$additional_info')";
|
|
db_query($query);
|
|
}
|
|
}
|
|
|
|
|
|
function getClassInfo($class_num,$mode='internal',$max_teachers=2,$with_breaks=false) {
|
|
|
|
global $school_record;
|
|
global $classArray;
|
|
global $base_school_num;
|
|
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog("getClassInfo");
|
|
|
|
if (!is_numeric($class_num)) return($class_num);
|
|
|
|
if ($class_num == 0 || strlen($class_num) == 0) return(getLanguageText('TEXT-STAFF'));
|
|
if ($class_num == 1) return(getLanguageText('TEXT-CUSTOMER'));
|
|
if ($class_num == 2) return(getLanguageText('TEXT-PARENT'));
|
|
|
|
$school_num = $school_record['record_num'];
|
|
// if ($school_record['status'] == 'Linked') $school_num = $school_record['linked_site'];
|
|
|
|
// Get class record
|
|
$results = db_query("SELECT c.*,cp.program_name FROM classes AS c LEFT JOIN class_programs AS cp ON c.class_program = cp.record_num " .
|
|
"WHERE c.school_num = $base_school_num " .
|
|
"AND c.record_num = $class_num");
|
|
if (db_num_rows($results) == 0) {
|
|
return(getLanguageText('TEXT-STAFF'));
|
|
}
|
|
|
|
$class = db_fetch_assoc($results);
|
|
$classArray = $class;
|
|
|
|
$class_info = "";
|
|
|
|
if ($class['entry_type'] == 'Location') {
|
|
$class_info = $class['description'];
|
|
if ($mode == 'label' && strlen($class['label_description'])) $class_info = $class['label_description'];
|
|
return($class_info);
|
|
}
|
|
|
|
if ($mode == 'label' && strlen($class['label_description'])) {
|
|
$class_info = $class['label_description'];
|
|
return($class_info);
|
|
}
|
|
|
|
$label_description = $class['label_description'];
|
|
|
|
// Get teacher info if required
|
|
if ($mode == 'internal') $tflag = $school_record['i_display_teachers'];
|
|
else $tflag = $school_record['p_display_teachers'];
|
|
|
|
$class_info = "";
|
|
if ($tflag == 'Y') {
|
|
$label_note = "";
|
|
if ($max_teachers > 0 && intval($class['teacher1']) > 0) {
|
|
$results = db_query("SELECT title,first_name,last_name,label_note FROM people WHERE record_num = $class[teacher1]");
|
|
if (db_num_rows($results)) {
|
|
$r = db_fetch_assoc($results);
|
|
if (strlen($r['title'])) $class_info .= $r['title'] . ' ';
|
|
$class_info .= $r['first_name'] . ' ' . $r['last_name'];
|
|
if (strlen($r['label_note'])) $class_info .= ' ('.$r['label_note'].')';
|
|
}
|
|
}
|
|
if ($max_teachers > 1 && intval($class['teacher2']) > 0 && $class['display_teacher2'] == 'Y') {
|
|
$results = db_query("SELECT title,first_name,last_name,label_note FROM people WHERE record_num = $class[teacher2]");
|
|
if (db_num_rows($results)) {
|
|
$r = db_fetch_assoc($results);
|
|
$class_info .= " / ";
|
|
if (strlen($r['title'])) $class_info .= $r['title'] . ' ';
|
|
// $class_info .= $r['first_name'] . ' ' . $r['last_name'];
|
|
$class_info .= $r['first_name'] . ' ' . $r['last_name'];
|
|
if (strlen($r['label_note'])) $class_info .= ' ('.$r['label_note'].')';
|
|
}
|
|
}
|
|
if ($max_teachers > 2 && intval($class['teacher3']) > 0 && $class['display_teacher3'] == 'Y') {
|
|
$results = db_query("SELECT title,first_name,last_name,label_note FROM people WHERE record_num = $class[teacher3]");
|
|
if (db_num_rows($results)) {
|
|
$r = db_fetch_assoc($results);
|
|
$class_info .= " / ";
|
|
if (strlen($r['title'])) $class_info .= $r['title'] . ' ';
|
|
$class_info .= $r['first_name'] . ' ' . $r['last_name'];
|
|
if (strlen($r['label_note'])) $class_info .= ' ('.$r['label_note'].')';
|
|
}
|
|
}
|
|
if ($max_teachers > 3 && intval($class['teacher4']) > 0 && $class['display_teacher4'] == 'Y') {
|
|
$results = db_query("SELECT title,first_name,last_name,label_note FROM people WHERE record_num = $class[teacher4]");
|
|
if (db_num_rows($results)) {
|
|
$r = db_fetch_assoc($results);
|
|
$class_info .= " / ";
|
|
if (strlen($r['title'])) $class_info .= $r['title'] . ' ';
|
|
$class_info .= $r['first_name'] . ' ' . $r['last_name'];
|
|
if (strlen($r['label_note'])) $class_info .= ' ('.$r['label_note'].')';
|
|
}
|
|
}
|
|
if ($max_teachers > 4 && intval($class['teacher5']) > 0 && $class['display_teacher5'] == 'Y') {
|
|
$results = db_query("SELECT title,first_name,last_name,label_note FROM people WHERE record_num = $class[teacher5]");
|
|
if (db_num_rows($results)) {
|
|
$r = db_fetch_assoc($results);
|
|
$class_info .= " / ";
|
|
if (strlen($r['title'])) $class_info .= $r['title'] . ' ';
|
|
$class_info .= $r['first_name'] . ' ' . $r['last_name'];
|
|
if (strlen($r['label_note'])) $class_info .= ' ('.$r['label_note'].')';
|
|
}
|
|
}
|
|
}
|
|
|
|
$grade = $class['grade'];
|
|
$div = $class['division'];
|
|
$desc = $class['description'];
|
|
$prog = $class['program_name'];
|
|
|
|
switch ($mode) {
|
|
case 'internal':
|
|
if ($school_record['i_display_program'] == 'Y' && strlen($prog)) {
|
|
if (strlen($class_info) > 0) {
|
|
if ($with_breaks) $class_info .= "<br>";
|
|
$class_info .= " - ";
|
|
}
|
|
$class_info .= $prog;
|
|
}
|
|
|
|
if ($school_record['i_display_grade'] == 'Y' && isset($grade) && $grade) {
|
|
if (strlen($class_info) > 0) {
|
|
if ($with_breaks) $class_info .= "<br>";
|
|
$class_info .= " - ";
|
|
}
|
|
$class_info .= $grade;
|
|
}
|
|
|
|
if ($school_record['i_display_division'] == 'Y') {
|
|
$div = "$school_record[division_class_num_text]: $div";
|
|
if (strlen($class_info) > 0) {
|
|
if ($with_breaks) $class_info .= "<br>$div";
|
|
else $class_info = $div . " - $class_info";
|
|
}
|
|
else $class_info = $div;
|
|
}
|
|
|
|
if ($school_record['i_display_description'] == 'Y' && strlen($desc) > 0) {
|
|
if (strlen($class_info) > 0) {
|
|
if ($with_breaks) $class_info .= "<br>";
|
|
$class_info .= " - ";
|
|
}
|
|
$class_info .= $desc;
|
|
}
|
|
break;
|
|
|
|
case 'external':
|
|
case 'parent':
|
|
case 'dropdown':
|
|
if ($mode != 'dropdown' && $school_record['p_display_program'] == 'Y' && strlen($prog)) {
|
|
if (strlen($class_info) > 0) {
|
|
if ($with_breaks) $class_info .= "<br>";
|
|
$class_info .= " - ";
|
|
}
|
|
$class_info .= $prog;
|
|
}
|
|
|
|
if ($school_record['p_display_grade'] == 'Y' && isset($grade) && $grade) {
|
|
if (strlen($class_info) > 0) {
|
|
if ($with_breaks) $class_info .= "<br>";
|
|
$class_info .= " - ";
|
|
}
|
|
if ($grade == 'K') $class_info .= getLanguageText('TEXT-KINDERGARTEN');
|
|
else $class_info .= "Gr: $grade";
|
|
}
|
|
|
|
if ($school_record['p_display_division'] == 'Y') {
|
|
if (strlen($class_info) > 0) {
|
|
if ($with_breaks) $class_info .= "<br>";
|
|
$class_info .= " - ";
|
|
}
|
|
$class_info .= "$school_record[division_class_num_text]: $div";
|
|
}
|
|
|
|
if ($school_record['p_display_description'] == 'Y' && strlen($desc) > 0) {
|
|
if (strlen($class_info) > 0) {
|
|
if ($with_breaks) $class_info .= "<br>";
|
|
$class_info .= " - ";
|
|
}
|
|
$class_info .= $desc;
|
|
}
|
|
break;
|
|
|
|
case 'label':
|
|
if ($school_record['p_display_grade'] == 'Y' && isset($grade) && $grade) {
|
|
if (strlen($class_info) > 0) $class_info .= " - ";
|
|
if ($grade == 'K') $class_info .= "Kindergarten";
|
|
else $class_info .= "Gr: $grade";
|
|
}
|
|
|
|
if ($school_record['p_display_division'] == 'Y') {
|
|
if (strlen($class_info) > 0) $class_info .= " - ";
|
|
$class_info .= "$school_record[division_class_num_text]: $div";
|
|
}
|
|
break;
|
|
|
|
case 'teacher':
|
|
break;
|
|
}
|
|
|
|
if (strlen($label_description)) $class_info .= " ($label_description)";
|
|
|
|
return($class_info);
|
|
}
|
|
|
|
|
|
function getContactInfo($user_num) {
|
|
|
|
global $school_record;
|
|
global $school_num;
|
|
global $base_school_num;
|
|
|
|
$info = array();
|
|
|
|
// Get user record
|
|
$results = db_query("select * from users where school_num = $base_school_num and record_num = $user_num");
|
|
if (db_num_rows($results)) {
|
|
$user = db_fetch_assoc($results);
|
|
|
|
$info[0] = $user['first_name'] . " " . $user['last_name'];
|
|
$info[1] = $user['home_phone'];
|
|
$info[2] = $user['email'];
|
|
$info[3] = $user;
|
|
}
|
|
|
|
return($info);
|
|
}
|
|
|
|
|
|
function updateUserAccount($user_num) {
|
|
}
|
|
|
|
|
|
//
|
|
// Load language data
|
|
//
|
|
function loadLanguageText($selected_language = '') {
|
|
|
|
global $school_record;
|
|
global $currLanguage;
|
|
global $LanguageEntries;
|
|
|
|
if (isset($_SERVER) && array_key_exists('REMOTE_ADDR', $_SERVER)) $user_ip = $_SERVER["REMOTE_ADDR"];
|
|
|
|
$language = $currLanguage;
|
|
if (strlen($selected_language)) $language = $selected_language;
|
|
if (strlen($language) == 0) $language = "english";
|
|
|
|
$query = "SELECT * FROM language_text";
|
|
$results = db_query($query);
|
|
while ($row = db_fetch_assoc($results)) {
|
|
extract($row);
|
|
$LanguageEntries[$message_id] = $row;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Get the screen text based on the language parameter
|
|
//
|
|
function getLanguageText($field_id,$selectedLanguage="") {
|
|
|
|
global $school_record;
|
|
global $currLanguage;
|
|
global $LanguageEntries;
|
|
global $_SESSION, $_SERVER;
|
|
|
|
$user_ip = '';
|
|
if (isset($_SERVER) && array_key_exists('REMOTE_ADDR', $_SERVER)) $user_ip = $_SERVER["REMOTE_ADDR"];
|
|
|
|
$language = 'English';
|
|
if (isset($currLanguage)) $language = $currLanguage;
|
|
|
|
// $moduleName = "getLanguageText";
|
|
// startLog($moduleName);
|
|
|
|
if (isset($selectedLanguage) && strlen($selectedLanguage) > 0) $language = $selectedLanguage;
|
|
|
|
if (!isset($LanguageEntries) || count($LanguageEntries) == 0) loadLanguageText($language);
|
|
|
|
if (strlen($language) == 0) $language = "english";
|
|
$fname = strtolower($language);
|
|
// writeLog("language: $language - $fname");
|
|
// writeLog("field_id: $field_id");
|
|
// writeLog("$moduleName: fname: $fname");
|
|
|
|
// Ensure that there is a default language defined
|
|
switch ($fname) {
|
|
case 'english':
|
|
case 'french':
|
|
case 'spanish':
|
|
case 'german':
|
|
case 'italian':
|
|
case 'punjabi':
|
|
case 'hindi':
|
|
case 'japanese':
|
|
case 'chinese':
|
|
case 'vietnamese':
|
|
case 'korean':
|
|
case 'bengali':
|
|
case 'arabic':
|
|
break;
|
|
|
|
default:
|
|
$fname = "english";
|
|
break;
|
|
}
|
|
|
|
// Get the text from the database
|
|
if (is_numeric($field_id)) {
|
|
$text = db_getVal("SELECT $fname FROM language_text WHERE record_num = $field_id");
|
|
}
|
|
else {
|
|
$field_id = strtoupper(str_replace(' ','-',$field_id));
|
|
$id = $field_id;
|
|
// writeLog("$moduleName: id: $id");
|
|
|
|
// Check for a country specific code word
|
|
if (!isset($school_record) || !array_key_exists('country', $school_record)) $school_record['country'] = 'Canada';
|
|
if (!isset($text) && $fname == 'english' && $school_record['country'] == 'Canada') {
|
|
$id = $field_id . ".CANADA";
|
|
if (array_key_exists($id, $LanguageEntries)) $text = $LanguageEntries[$id][$fname];
|
|
}
|
|
|
|
// Get the text defined for the current field id
|
|
if (!isset($text) || !$text) {
|
|
$id = $field_id;
|
|
if (array_key_exists($id, $LanguageEntries)) $text = $LanguageEntries[$id][$fname];
|
|
}
|
|
}
|
|
// if (isset($fname)) writeLog("fname: $fname");
|
|
// if (isset($id)) writeLog("id: $id");
|
|
// if (isset($text)) writeLog("text: $text");
|
|
|
|
// If there is no text for the selected language then get the english text
|
|
if ((!isset($text) || strlen($text) == 0) && $fname != 'english') {
|
|
$fname = 'english';
|
|
if (is_numeric($field_id)) {
|
|
$text = db_getVal("SELECT $fname FROM language_text WHERE record_num = $field_id");
|
|
}
|
|
else {
|
|
// If this organization is a Business then check for custom text for a business
|
|
if ($school_record['type'] == 'Business') {
|
|
$id = $field_id . ".BUSINESS";
|
|
// $text = db_getVal("SELECT $fname FROM language_text WHERE message_id = '".db_escape_string($id)."'");
|
|
if (array_key_exists($id, $LanguageEntries)) $text = $LanguageEntries[$id][$fname];
|
|
// if (!$text) unset($text);
|
|
}
|
|
|
|
// Get the text defined for the current field id
|
|
if (!isset($text) || !$text) {
|
|
// $text = db_getVal("SELECT $fname FROM language_text WHERE message_id = '".db_escape_string($field_id)."'");
|
|
if (array_key_exists($id, $LanguageEntries)) $text = $LanguageEntries[$id][$fname];
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!isset($text)) $text = '';
|
|
|
|
$text = str_replace("<","<",$text);
|
|
$text = str_replace(">",">",$text);
|
|
$text = str_replace('"','"',$text);
|
|
|
|
return($text);
|
|
}
|
|
|
|
|
|
//
|
|
// Display the language text based on the language and the user type
|
|
//
|
|
function displayLanguageText($field_id,$selectedLanguage="",$selected_case="") {
|
|
|
|
global $currLanguage;
|
|
$language = $currLanguage;
|
|
|
|
if (isset($selectedLanguage) && strlen($selectedLanguage) > 0) $language = $selectedLanguage;
|
|
|
|
$text = getLanguageText($field_id,$language);
|
|
|
|
if (isset($selected_case) && strlen($selected_case)) {
|
|
switch ($selected_case) {
|
|
case 'UpperCase':
|
|
$text = strtoupper($text);
|
|
break;
|
|
}
|
|
}
|
|
|
|
echo(nl2br($text));
|
|
}
|
|
|
|
|
|
//
|
|
// Function to translate user account text
|
|
//
|
|
function translateText($text) {
|
|
$matches = array(
|
|
'Order for',
|
|
'Order Deleted',
|
|
'Additional Order Fee',
|
|
'Order Items Deleted',
|
|
'Previous Order Total',
|
|
'New Order Total',
|
|
'Previous Year Balance Posted',
|
|
'Bambora Transaction Fee',
|
|
'Bambora Transaction Credit',
|
|
'Bambora Payment',
|
|
'PayPal Payment',
|
|
'PayPal Transaction Fee',
|
|
'PayPal Checkout Payment',
|
|
'Payment Discount',
|
|
'Open',
|
|
'Closed',
|
|
'Generated Credit',
|
|
'Generated Charge',
|
|
'Generated fee to offset costs',
|
|
'Generated credit for first order',
|
|
'Charge Adjustment',
|
|
'Credit Adjustment',
|
|
'Transaction Credit',
|
|
'Account Posted to Zero',
|
|
'Multiple Order Discount',
|
|
'Donation',
|
|
'Council Gift',
|
|
'TRX Note',
|
|
'Additional Fee',
|
|
'Payment',
|
|
'Order',
|
|
'Bambora',
|
|
'Cash',
|
|
'Check',
|
|
'Posting',
|
|
'Unpaid',
|
|
'Complimentary',
|
|
);
|
|
|
|
$replace = array(
|
|
getLanguageText('TEXT-ORDER-FOR'),
|
|
getLanguageText('TEXT-ORDER-DELETED'),
|
|
getLanguageText('TEXT-ADDITIONAL-ORDER-FEE'),
|
|
getLanguageText('TEXT-ORDER-FOR-MENU-DATE-DELETED'),
|
|
getLanguageText('TEXT-PREVIOUS-ORDER-TOTAL'),
|
|
getLanguageText('TEXT-NEW-ORDER-TOTAL'),
|
|
getLanguageText('TEXT-PREVIOUS-YEAR-BALANCE-POSTED'),
|
|
getLanguageText('TEXT-BAMBORA-TRANSACTION-FEE'),
|
|
getLanguageText('TEXT-BAMBORA-TRANSACTION-CREDIT'),
|
|
getLanguageText('TEXT-BAMBORA-PAYMENT'),
|
|
getLanguageText('TEXT-PAYPAL-PAYMENT'),
|
|
getLanguageText('TEXT-PAYPAL-TRANSACTION-FEE'),
|
|
getLanguageText('TEXT-PAYPAL-CHECKOUT-PAYMENT'),
|
|
getLanguageText('TEXT-PAYMENT-DISCOUNT'),
|
|
getLanguageText('TEXT-OPEN'),
|
|
getLanguageText('TEXT-CLOSED'),
|
|
getLanguageText('TEXT-GENERATED-CREDIT'),
|
|
getLanguageText('TEXT-GENERATED-CHARGE'),
|
|
getLanguageText('TEXT-GENERATED-FEE-TO-OFFSET-COSTS'),
|
|
getLanguageText('TEXT-GENERATED-CREDIT-FOR-FIRST-ORDER'),
|
|
getLanguageText('TEXT-CHARGE-ADJUSTMENT'),
|
|
getLanguageText('TEXT-CREDIT-ADJUSTMENT'),
|
|
getLanguageText('TEXT-TRANSACTION-CREDIT'),
|
|
getLanguageText('TEXT-ACCOUNT-POSTED-TO-ZERO'),
|
|
getLanguageText('TEXT-MULTI-ORDER-DISCOUNTS'),
|
|
getLanguageText('TEXT-DONATION'),
|
|
getLanguageText('TEXT-COUNCIL-GIFT'),
|
|
getLanguageText('TEXT-TRX-NOTE'),
|
|
getLanguageText('TEXT-ADDITIONAL-FEE'),
|
|
getLanguageText('TEXT-PAYMENT'),
|
|
getLanguageText('TEXT-ORDER'),
|
|
getLanguageText('TEXT-BAMBORA'),
|
|
getLanguageText('TEXT-CASH'),
|
|
getLanguageText('TEXT-CHECK'),
|
|
getLanguageText('TEXT-POSTING'),
|
|
getLanguageText('TEXT-UNPAID'),
|
|
getLanguageText('TEXT-COMPLIMENTARY'),
|
|
);
|
|
|
|
$text = str_replace($matches, $replace, $text);
|
|
return($text);
|
|
}
|
|
|
|
|
|
//
|
|
// Get number of orders per class schedule
|
|
//
|
|
function getNumClassOrders($class_num,$schedule_num) {
|
|
|
|
global $school_num, $base_school_num;
|
|
|
|
$query = "SELECT count(*) FROM hotlunch_order_header AS hloh, people AS p " .
|
|
"WHERE hloh.school_num = $school_num " .
|
|
"AND hloh.ordered_by_num = p.record_num " .
|
|
"AND hloh.schedule_num = $schedule_num " .
|
|
"AND p.school_num = $base_school_num " .
|
|
"AND p.class_num = $class_num";
|
|
return(db_getVal($query));
|
|
}
|
|
|
|
|
|
//
|
|
// Get the orders per class schedule
|
|
//
|
|
function getClassOrders($class_num,$schedule_num,$status=array()) {
|
|
|
|
global $school_num, $base_school_num;
|
|
|
|
$ostatus = "";
|
|
if (isset($status) && is_array($status) && count($status)) {
|
|
$s = implode("','",$status);
|
|
$ostatus = "AND hloh.status IN ('$s') ";
|
|
}
|
|
|
|
$query = "SELECT hloh.*,p.first_name,p.last_name,p.user_num FROM hotlunch_order_header AS hloh, people AS p " .
|
|
"WHERE hloh.school_num = $school_num " .
|
|
"AND hloh.ordered_by_num = p.record_num " .
|
|
"AND hloh.schedule_num = $schedule_num " .
|
|
$ostatus .
|
|
"AND p.school_num = $base_school_num " .
|
|
"AND p.class_num = $class_num " .
|
|
"ORDER BY last_name,first_name";
|
|
$results = db_query($query);
|
|
$num = db_num_rows($results);
|
|
return($results);
|
|
}
|
|
|
|
|
|
//
|
|
// Update user account balance
|
|
//
|
|
function updateUserBalance($user_num,$snum=0) {
|
|
|
|
global $school_num;
|
|
if ($snum == 0) $snum = $school_num;
|
|
|
|
$orders = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND transaction_type = 'Order' ORDER BY order_num");
|
|
if (db_num_rows($orders) > 0) {
|
|
$prevOrder = 0;
|
|
while ($row = db_fetch_assoc($orders)) {
|
|
$order_num = $row['order_num'];
|
|
if ($order_num == $prevOrder) {
|
|
$rnum = $row['record_num'];
|
|
db_query("DELETE FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND order_num = $order_num AND transaction_type = 'Order' AND record_num = $rnum");
|
|
}
|
|
else {
|
|
$r = db_query("SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $order_num");
|
|
if (db_num_rows($r) == 0) {
|
|
$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 = 'Order'");
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$rnum = $row['record_num'];
|
|
db_query("DELETE FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND order_num = $order_num AND transaction_type = 'Order' AND record_num = $rnum");
|
|
}
|
|
db_query("DELETE FROM hotlunch_order_items WHERE school_num = $school_num AND order_num = $order_num");
|
|
}
|
|
}
|
|
$prevOrder = $order_num;
|
|
}
|
|
}
|
|
|
|
|
|
// Get user balance
|
|
$query = "SELECT sum(transaction_amount) AS balance FROM user_account " .
|
|
"WHERE school_num = $snum " .
|
|
"AND user_num = $user_num " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL)";
|
|
$balance = db_getVal($query);
|
|
if (!$balance) $balance = '0.00';
|
|
|
|
// Get the number of orders
|
|
$query = "SELECT count(*) FROM hotlunch_order_header AS hlh, people AS p " .
|
|
"WHERE p.school_num = $school_num " .
|
|
"AND p.school_num = hlh.school_num " .
|
|
"AND p.record_num = hlh.ordered_by_num " .
|
|
"AND hlh.ordered_by_type != 'Concession' " .
|
|
"AND p.user_num = $user_num";
|
|
$num_orders = db_getVal($query);
|
|
if (!$num_orders) $num_orders = 0;
|
|
|
|
// Update the user account
|
|
$query = "UPDATE users SET balance_owing = $balance, num_orders = $num_orders " .
|
|
"WHERE school_num = $snum " .
|
|
"AND record_num = $user_num";
|
|
db_query($query);
|
|
|
|
|
|
// Get overall account balance
|
|
$query = "SELECT sum(transaction_amount) AS balance FROM user_account " .
|
|
"WHERE school_num = $snum " .
|
|
"AND user_num = $user_num " .
|
|
"AND (deleted != 'Y' OR deleted IS NULL)";
|
|
$balance = db_getVal($query);
|
|
if (!$balance) $balance = '0.00';
|
|
|
|
// Update the user account
|
|
$query = "UPDATE users SET account_balance = $balance " .
|
|
"WHERE record_num = $user_num";
|
|
db_query($query);
|
|
|
|
|
|
return($balance);
|
|
}
|
|
|
|
|
|
//
|
|
// Update user account orders to a status
|
|
//
|
|
function updateOrders($user_num,$status='Paid') {
|
|
global $school_num, $base_school_num;
|
|
|
|
// Update orders
|
|
$today = date("Y-m-d",time());
|
|
$query = "UPDATE hotlunch_order_header " .
|
|
"SET status = '$status', " .
|
|
"amount_paid = order_total, " .
|
|
"paid_date = '$today' " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND status NOT IN ('Paid','Complimentary','Concession') " .
|
|
"AND order_total > 0 " .
|
|
"AND ordered_by_num IN (SELECT record_num FROM people WHERE user_num = $user_num)";
|
|
db_query($query);
|
|
|
|
// Set user account to enable ordering again
|
|
db_query("UPDATE users SET can_order = 'Yes' WHERE school_num = $base_school_num AND can_order = 'Balance' AND record_num = $user_num");
|
|
}
|
|
|
|
|
|
//
|
|
// Get the supplier costs of a menu or a schedule
|
|
//
|
|
function getSupplierCosts($schedule_num, $menu_num=0, $item_num = 0) {
|
|
global $school_num;
|
|
|
|
// Handle parameters
|
|
$where = "";
|
|
if ($menu_num > 0) {
|
|
// Get set of menu items and products
|
|
$results = db_query("SELECT DISTINCT supplier_product_num FROM hotlunch_menu_products " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND menu_item_num IN (SELECT record_num FROM hotlunch_menu_items " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND menu_num = $menu_num)");
|
|
if (db_num_rows($results)) {
|
|
$spNums = array();
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$spNums[] = $row['supplier_product_num'];
|
|
}
|
|
|
|
$products = implode(",",$spNums);
|
|
|
|
// Check for actual totals
|
|
$actual_cost = db_getVal("SELECT sum(actual_cost) FROM supplier_order_items_actual " .
|
|
"WHERE school_num = $school_num " .
|
|
// "AND actual_cost > 0 " .
|
|
"AND schedule_num = $schedule_num " .
|
|
"AND menu_num = $menu_num " .
|
|
"AND supplier_product_num IN ($products)");
|
|
if ($actual_cost > 0.00) {
|
|
return($actual_cost);
|
|
}
|
|
}
|
|
|
|
$where .= "and hotlunch_order_items.menu_num = $menu_num ";
|
|
}
|
|
|
|
if (isset($item_num) && $item_num > 0) $where .= "and hotlunch_menu_products.menu_item_num = $item_num ";
|
|
if (isset($order_num) && $order_num > 0) $where .= "and hotlunch_order_items.order_num = $order_num ";
|
|
|
|
// Build query
|
|
$query = "select sum(qty), hotlunch_order_items.menu_num, hotlunch_menu_products.supplier_product_num, " .
|
|
"package_qty, package_cost, (round(sum(qty) / package_qty + 0.49) * package_cost) as cost " .
|
|
"from hotlunch_order_items, hotlunch_order_header, hotlunch_menu_products, supplier_products, supplier_order_items_actual " .
|
|
"where hotlunch_order_items.school_num = $school_num " .
|
|
"and hotlunch_order_header.school_num = $school_num " .
|
|
"and hotlunch_menu_products.school_num = $school_num " .
|
|
"and supplier_order_items_actual.school_num = $school_num " .
|
|
"and supplier_products.school_num = $school_num " .
|
|
"and hotlunch_order_items.order_num = hotlunch_order_header.record_num " .
|
|
"and hotlunch_order_items.active != 'N' " .
|
|
"and hotlunch_order_header.schedule_num = $schedule_num " .
|
|
"and hotlunch_order_items.schedule_num = $schedule_num " .
|
|
"and hotlunch_menu_products.menu_item_num = hotlunch_order_items.menu_item_num " .
|
|
"and supplier_products.record_num = hotlunch_menu_products.supplier_product_num " .
|
|
"and hotlunch_order_header.status NOT IN ('Inactive','Deleted') " .
|
|
"and supplier_order_items_actual.schedule_num = $schedule_num " .
|
|
"and supplier_order_items_actual.menu_num = hotlunch_order_items.menu_num " .
|
|
"and supplier_order_items_actual.actual_cost > 0 " .
|
|
$where .
|
|
"group by 2,3,4,5";
|
|
$query = "select sum(qty), hotlunch_order_items.menu_num, hotlunch_menu_products.supplier_product_num, " .
|
|
"package_qty, package_cost, (round(sum(qty) / package_qty + 0.49) * package_cost) as cost " .
|
|
"from hotlunch_order_items, hotlunch_order_header, hotlunch_menu_products, supplier_products " .
|
|
"where hotlunch_order_items.school_num = $school_num " .
|
|
"and hotlunch_order_header.school_num = $school_num " .
|
|
"and hotlunch_menu_products.school_num = $school_num " .
|
|
"and supplier_products.school_num = $school_num " .
|
|
"and hotlunch_order_items.order_num = hotlunch_order_header.record_num " .
|
|
"and hotlunch_order_items.active != 'N' " .
|
|
"and hotlunch_order_header.schedule_num = $schedule_num " .
|
|
"and hotlunch_order_items.schedule_num = $schedule_num " .
|
|
"and hotlunch_menu_products.menu_item_num = hotlunch_order_items.menu_item_num " .
|
|
"and supplier_products.record_num = hotlunch_menu_products.supplier_product_num " .
|
|
"and hotlunch_order_header.status NOT IN ('Inactive','Deleted') " .
|
|
$where .
|
|
"group by 2,3,4,5";
|
|
$results = db_query($query);
|
|
|
|
// Process the set of records to get the total
|
|
$total_cost = 0.00;
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$total_cost += floatval($row['cost']);
|
|
}
|
|
|
|
return($total_cost);
|
|
}
|
|
|
|
|
|
//
|
|
// Get the supplier margin of a menu or a schedule
|
|
//
|
|
function getSupplierMargin($schedule_num, $menu_num=0, $item_num = 0) {
|
|
global $school_num;
|
|
|
|
// Handle parameters
|
|
$where = "";
|
|
if ($menu_num > 0) $where .= "and hotlunch_order_items.menu_num = $menu_num ";
|
|
if ($item_num > 0) $where .= "and hotlunch_menu_products.menu_item_num = $item_num ";
|
|
if ($order_num > 0) $where .= "and hotlunch_order_items.order_num = $order_num ";
|
|
|
|
// Build query
|
|
$query = "select sum(qty), menu_num, supplier_product_num, package_qty, margin_cost, (round(sum(qty) / package_qty + 0.49) * margin_cost) as cost " .
|
|
"from hotlunch_order_items, hotlunch_menu_products, supplier_products " .
|
|
"where hotlunch_order_items.school_num = $school_num " .
|
|
"and hotlunch_order_items.active != 'N' " .
|
|
"and schedule_num = $schedule_num " .
|
|
"and hotlunch_menu_products.school_num = $school_num " .
|
|
"and hotlunch_menu_products.menu_item_num = hotlunch_order_items.menu_item_num " .
|
|
"and supplier_products.school_num = $school_num " .
|
|
"and supplier_products.record_num = supplier_product_num " .
|
|
$where .
|
|
"group by 2,3,4,5";
|
|
$results = db_query($query);
|
|
|
|
// Process the set of records to get the total
|
|
$total_cost = 0.00;
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$total_margin += floatval($row['cost']);
|
|
}
|
|
|
|
return($total_margin);
|
|
}
|
|
|
|
|
|
//
|
|
// Get name of person associated with order number
|
|
//
|
|
function getOrderedByName($order_num) {
|
|
global $school_num;
|
|
|
|
$ordered_by_num = db_getVal("SELECT ordered_by_num FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $order_num");
|
|
$ordered_by_num = intval($ordered_by_num);
|
|
if ($ordered_by_num <= 0) return('');
|
|
|
|
$name = db_getVal("SELECT concat(first_name,' ',last_name) FROM people WHERE school_num = $school_num AND record_num = $ordered_by_num");
|
|
return($name);
|
|
}
|
|
|
|
|
|
//
|
|
// Echo the formatted form text
|
|
//
|
|
function echoFormText($text) {
|
|
echo(formatText($text));
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Set reply email address
|
|
//
|
|
function setReplyAddress($email="", $type="") {
|
|
global $school_record;
|
|
global $school_num;
|
|
global $ApplicationURLS;
|
|
global $EmailReplyAddress;
|
|
|
|
$baseURL = $school_record['base_url'];
|
|
|
|
// Set email reply address
|
|
$EmailReplyAddress = $school_record['support_email'];
|
|
|
|
switch ($baseURL) {
|
|
case 'hotlunches.net':
|
|
case 'fundraiserorders.com':
|
|
case 'parentcouncil.net':
|
|
case 'payschoolfees.net':
|
|
case 'pitapitottawa.ca':
|
|
case 'pitapitmilton.ca':
|
|
case 'schoolcouncil.net':
|
|
case 'schooltripfundraising.com':
|
|
case 'schoollunchorders.net':
|
|
case 'registrationnow.net':
|
|
case 'schoolsuppliesorder.com':
|
|
case 'coldlunchcounts.com':
|
|
case 'schoolclothingorder.com':
|
|
case 'milkprogram.com':
|
|
case 'happymeals.ca':
|
|
case 'yearbookorders.net':
|
|
case 'buyticketsnow.net':
|
|
case 'hotdogday.net':
|
|
$EmailReplyAddress = $school_record['default_url_code'].'@'.$baseURL;
|
|
break;
|
|
}
|
|
|
|
$return_email = $EmailReplyAddress;
|
|
return($return_email);
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Format text
|
|
//
|
|
function formatText($text) {
|
|
$text = str_replace("'","'",$text);
|
|
return($text);
|
|
}
|
|
|
|
|
|
//
|
|
// Normalize strings to remove accented characters
|
|
//
|
|
function normalizeString($String, $mode = 'file') {
|
|
|
|
$map = array(
|
|
'É' => 'E',
|
|
'é' => 'e',
|
|
'è' => 'e',
|
|
'ë' => 'e',
|
|
'À' => 'A',
|
|
'à' => 'a',
|
|
);
|
|
|
|
$String = strtr($String, $map);
|
|
|
|
if ($mode == 'file') {
|
|
$String = str_replace(' ','_',$String);
|
|
$String = str_replace('/','_',$String);
|
|
$String = str_replace(',','_',$String);
|
|
$String = str_replace(';','_',$String);
|
|
$String = str_replace("'",'',$String);
|
|
$String = str_replace("___",'_',$String);
|
|
$String = str_replace("__",'_',$String);
|
|
}
|
|
|
|
return($String);
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Check remote address to see if it is an address against a set of allowed addresses
|
|
//
|
|
function checkRemoteAddress() {
|
|
global $markIP;
|
|
|
|
$remoteADDR = '';
|
|
if (isset($_SERVER) && array_key_exists('REMOTE_ADDR', $_SERVER)) $remoteADDR = $_SERVER["REMOTE_ADDR"];
|
|
|
|
switch ($remoteADDR) {
|
|
case $markIP:
|
|
return(true);
|
|
break;
|
|
|
|
default:
|
|
return(false);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
// Get current menu dates
|
|
//
|
|
function getCurrentMenuDates($schoolNum=0) {
|
|
global $school_record;
|
|
global $school_num;
|
|
global $base_school_num;
|
|
|
|
$menu_dates = array();
|
|
|
|
if ($schoolNum > 0) $school_num = $schoolNum;
|
|
|
|
$results = db_query("SELECT * FROM schools WHERE record_num = $school_num");
|
|
$school_record = db_fetch_assoc($results);
|
|
|
|
// $base_school_num = $school_num;
|
|
// if ($school_record['status'] == 'Linked') $base_school_num = $school_record['linked_site'];
|
|
|
|
// Get set of linked sites and store in school_record
|
|
$query = "SELECT * FROM schools " .
|
|
"WHERE linked_site = $base_school_num " .
|
|
"AND record_num != $base_school_num " .
|
|
"AND status = 'Linked' " .
|
|
"ORDER BY link_sequence,link_title";
|
|
$linked_sites = db_query($query);
|
|
$num_linked = db_num_rows($linked_sites);
|
|
$snums = $base_school_num;
|
|
if ($num_linked > 0) {
|
|
while ($row = db_fetch_assoc($linked_sites)) {
|
|
$snums .= "," . $row['record_num'];
|
|
}
|
|
}
|
|
|
|
$school_record['linked_sites'] = $snums;
|
|
$school_record['num_linked_sites'] = $num_linked;
|
|
|
|
|
|
$stime = time();
|
|
$start = date("Y-m-d H:i:s",$stime);
|
|
$menu_start_date = date("Y-m-d",$stime);
|
|
|
|
$email_reminder_weeks = $school_record['email_reminder_weeks'];
|
|
$menu_end_date = date("Y-m-d",$stime + 60 * 60 * 24 * 7 * $email_reminder_weeks);
|
|
|
|
// Get menu dates in range
|
|
$linked_sites = $school_record['linked_sites'];
|
|
$query = "SELECT hlmd.* " .
|
|
"FROM hotlunch_menu_dates AS hlmd, hotlunch_schedules as hls " .
|
|
"WHERE hlmd.school_num IN ($linked_sites) " .
|
|
"AND hls.school_num = hlmd.school_num " .
|
|
"AND hls.status IN ('Active','Completed','Closed') " .
|
|
"AND hls.schedule_type IN ('Hot Lunch','Date Sensitive') " .
|
|
"AND hlmd.schedule_num = hls.record_num " .
|
|
"AND hlmd.menu_date BETWEEN '$menu_start_date' AND '$menu_end_date' " .
|
|
"ORDER BY menu_date,sequence";
|
|
$menu_results = db_query($query);
|
|
|
|
if (db_num_rows($menu_results) > 0) {
|
|
$mdates = "0";
|
|
while ($mdate = db_fetch_assoc($menu_results)) {
|
|
$snum = $mdate['schedule_num'];
|
|
|
|
$entry[] = array();
|
|
$entry['num'] = $mdate['record_num'];
|
|
|
|
$menu_title = '';
|
|
if (array_key_exists('menu_title', $mdate)) $menu_title = $mdate['menu_title'];
|
|
$entry['title'] = $menu_title;
|
|
$entry['schedule_num'] = $snum;
|
|
$entry['schedule'] = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE record_num = $snum");
|
|
|
|
$menu_date = '';
|
|
if (array_key_exists('menu_date', $mdate)) $menu_date = $mdate['menu_date'];
|
|
$entry['mdate'] = $menu_date;
|
|
|
|
$entry['date'] = date("D M jS, Y",strtotime($mdate['menu_date']." 12:00:00"));
|
|
$entry['email_msg'] = $mdate['email_message'];
|
|
$entry['menu_start_date'] = $menu_start_date;
|
|
$entry['menu_end_date'] = $menu_end_date;
|
|
|
|
$Title = $entry['title'];
|
|
$Menu_date = $entry['date'] . " (" . $entry['mdate'] . ")";
|
|
|
|
$mdates .= "," . $mdate['record_num'];
|
|
|
|
// Get set of classes with access to this schedule
|
|
$schedule_classes = db_query("SELECT * FROM hotlunch_schedules_classes WHERE school_num = $school_num AND schedule_num = $snum");
|
|
$entry['schedule_classes'] = array();
|
|
if (db_num_rows($schedule_classes) > 0) {
|
|
while ($srow = db_fetch_assoc($schedule_classes)) {
|
|
$entry['schedule_classes'][] = $srow['class_num'];
|
|
}
|
|
$entry['schedule_classes'][] = 0;
|
|
}
|
|
|
|
$menu_dates[] = $entry;
|
|
}
|
|
}
|
|
|
|
return($menu_dates);
|
|
}
|
|
|
|
|
|
//
|
|
// Update menu date costs and revenue
|
|
//
|
|
function updateMenuDate($schedule_num, $menu_num) {
|
|
global $school_record;
|
|
global $school_num;
|
|
global $supplier_school_num;
|
|
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog("updateMenuDate");
|
|
|
|
$query = "SELECT record_num FROM hotlunch_menu_items " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND menu_num = $menu_num";
|
|
// writeLog($query);
|
|
$items = db_query($query);
|
|
|
|
$menu_revenue = 0;
|
|
$menu_profit = 0;
|
|
$menu_cost = 0;
|
|
$menu_qty = 0;
|
|
|
|
if (db_num_rows($items)) {
|
|
|
|
while ($row = db_fetch_assoc($items)) {
|
|
$menu_item_num = $row['record_num'];
|
|
|
|
// Get ordered totals
|
|
$query = "SELECT sum(qty) AS total_qty, sum(qty * menu_item_price) as total_revenue " .
|
|
"FROM hotlunch_order_items AS hloi, hotlunch_order_header AS hloh " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hloi.schedule_num = $schedule_num " .
|
|
"AND hloh.schedule_num = $schedule_num " .
|
|
"AND hloi.order_num = hloh.record_num " .
|
|
"AND hloi.menu_item_num = $menu_item_num " .
|
|
"AND hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"AND hloi.active != 'N'";
|
|
$results = db_query($query);
|
|
|
|
$item_qty = 0;
|
|
|
|
if (db_num_rows($results)) {
|
|
$r = db_fetch_assoc($results);
|
|
|
|
$total_item_qty = $r['total_qty'];
|
|
$menu_qty += $total_item_qty;
|
|
|
|
|
|
// Get ordered totals without Complimentary and Concession
|
|
$query = "SELECT hloh.status, sum(qty) AS total_qty, sum(qty * menu_item_price) as total_revenue " .
|
|
"FROM hotlunch_order_items AS hloi, hotlunch_order_header AS hloh " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hloi.schedule_num = $schedule_num " .
|
|
"AND hloh.schedule_num = $schedule_num " .
|
|
"AND hloi.order_num = hloh.record_num " .
|
|
"AND hloi.menu_item_num = $menu_item_num " .
|
|
"AND hloh.status IN ('Paid','Unpaid') " .
|
|
"AND hloi.active != 'N' " .
|
|
"GROUP BY 1";
|
|
$results = db_query($query);
|
|
$r = db_fetch_assoc($results);
|
|
|
|
$item_qty = $r['total_qty'];
|
|
$menu_revenue += $r['total_revenue'];
|
|
// writeLog("item_qty: $item_qty");
|
|
// writeLog("menu_qty: $menu_qty");
|
|
|
|
// Get the cost of each item
|
|
$query = "SELECT sum(package_cost / package_qty) " .
|
|
"FROM supplier_products AS sp,hotlunch_menu_products AS hlp " .
|
|
"WHERE hlp.school_num = $school_num " .
|
|
"AND sp.school_num = $supplier_school_num " .
|
|
"AND hlp.menu_item_num = $menu_item_num " .
|
|
"AND hlp.supplier_product_num = sp.record_num";
|
|
$item_cost = round(100 * db_getVal($query)) / 100;
|
|
|
|
$menu_cost += $total_item_qty * $item_cost;
|
|
}
|
|
}
|
|
}
|
|
|
|
$menu_net = $menu_revenue - $menu_costs;
|
|
// writeLog("menu_revenue: $menu_revenue");
|
|
// writeLog("menu_cost: $menu_cost");
|
|
// writeLog("menu_net: $menu_net");
|
|
|
|
$query = "UPDATE hotlunch_menu_dates " .
|
|
"SET order_revenue = $menu_revenue, " .
|
|
"supplier_costs = $menu_cost, " .
|
|
"net_revenue = $menu_net " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND record_num = $menu_num";
|
|
// writeLog($query);
|
|
db_query($query);
|
|
|
|
return($menu_qty);
|
|
}
|
|
|
|
|
|
//
|
|
// Get set of students associated with a user account
|
|
//
|
|
function getUserStudents($user_num,$schoolNum=0) {
|
|
global $school_record;
|
|
global $school_num;
|
|
global $language;
|
|
|
|
if ($schoolNum > 0) $school_num = $schoolNum;
|
|
|
|
$Students = array();
|
|
|
|
$students = db_query("SELECT * FROM people WHERE school_num = $school_num AND user_num = $user_num");
|
|
while ($student = db_fetch_assoc($students)) {
|
|
$entry['class_num'] = $student['class_num'];
|
|
$entry['people_type'] = $student['people_type'];
|
|
$entry['student_num'] = $student['record_num'];
|
|
$entry['name'] = $student['first_name'].' '.$student['last_name'];
|
|
|
|
$Students[] = $entry;
|
|
}
|
|
|
|
return($Students);
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Get lunch orders for a user account
|
|
//
|
|
function getUserOrders($user_num,$schoolNum) {
|
|
global $school_record;
|
|
global $school_num;
|
|
global $language;
|
|
|
|
if ($schoolNum > 0) $school_num = $schoolNum;
|
|
|
|
$results = db_query("SELECT * FROM users WHERE school_num = $school_num AND record_num = $user_num");
|
|
$user = db_fetch_assoc($results);
|
|
|
|
$menu_dates = getCurrentMenuDates($school_num);
|
|
$Students = getUserStudents($user_num,$school_num);
|
|
$msg = "";
|
|
|
|
if (count($Students) > 0) {
|
|
$msg .= str_replace("\r","",trim(db_getVal("SELECT text_data FROM text_data WHERE school_num = $school_num AND text_id = 'Lunch Reminder'")));
|
|
$msg .= "\n";
|
|
$msg .= "\n";
|
|
$msg .= sprintf("%10s: %s\n", getLanguageText('TEXT-USER-ID'), $user['userid']);
|
|
$msg .= sprintf("%10s: %s\n", getLanguageText('TEXT-NAME'), $user['first_name'].' '.$user['last_name']);
|
|
$msg .= sprintf("%10s: %s\n", getLanguageText('TEXT-EMAIL'), $user['email']);
|
|
$msg .= "\n";
|
|
|
|
for ($i = 0; $i < count($Students); $i++) {
|
|
$student = $Students[$i];
|
|
$class_num = $student['class_num'];
|
|
$people_type = $student['people_type'];
|
|
$student_num = $student['student_num'];
|
|
$name = $student['name'];
|
|
|
|
$msg .= "================================================================================\n";
|
|
$msg .= "$name:\n\n";
|
|
if (count($menu_dates)) {
|
|
for ($d = 0; $d < count($menu_dates); $d++) {
|
|
// If this schedule is restricted to a set of classes then check if this student is in that set
|
|
$schedule_classes = $menu_dates[$d]['schedule_classes'];
|
|
if ($people_type == 'Student' && count($schedule_classes) > 0) {
|
|
if (!in_array($class_num,$schedule_classes)) continue;
|
|
}
|
|
|
|
$menu_num = $menu_dates[$d]['num'];
|
|
$msg .= " " . $menu_dates[$d]['schedule'] . "\n";
|
|
$menu_title = '';
|
|
if (array_key_exists('menu_title', $menu_dates[$d])) $menu_title = $menu_dates[$d]['menu_title'];
|
|
if (strlen($menu_title)) $menu_title .= " - ";
|
|
$menu_title .= dateString('default',strtotime($menu_dates[$d]['mdate']));
|
|
$msg .= " $menu_title\n";
|
|
$msg .= getStudentLunchOrder($student_num,$menu_num,$school_num);
|
|
$msg .= "\n";
|
|
}
|
|
}
|
|
else {
|
|
$msg .= " " . getLanguageText('TEXT-NO-HOTLUNCH-OFFERED',$language) . "\n";
|
|
}
|
|
}
|
|
$msg .= "================================================================================\n";
|
|
$msg .= "\n";
|
|
$msg .= "\n";
|
|
}
|
|
|
|
return($msg);
|
|
}
|
|
|
|
|
|
//
|
|
// Get all student orders
|
|
//
|
|
function getStudentOrders($snum, $icon_flag = 'Y') {
|
|
global $school_record;
|
|
global $school_num;
|
|
global $language;
|
|
|
|
// Get set of orders for student
|
|
$query = "SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND ordered_by_num = $snum ORDER BY added_time";
|
|
$orders = db_query($query);
|
|
|
|
if (db_num_rows($orders) == 0) {
|
|
$return_text = "<p><b> --- ".getLanguageText('TEXT-NO-ORDERS-FOUND')." --- </b></p>";
|
|
return($return_text);
|
|
}
|
|
|
|
while ($order = db_fetch_assoc($orders)) {
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Get student lunch order info for a date
|
|
//
|
|
function getStudentLunchOrder($student_num,$menu_num,$schoolNum=0) {
|
|
global $school_record;
|
|
global $school_num;
|
|
global $language;
|
|
|
|
if ($schoolNum > 0) {
|
|
$school_num = $schoolNum;
|
|
$results = db_query("SELECT * FROM schools WHERE record_num = $school_num");
|
|
$school_record = db_fetch_assoc($results);
|
|
}
|
|
|
|
$query = "SELECT hloi.*,hlmi.item_title,hlmi.item_description 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.menu_num = $menu_num " .
|
|
"AND hloi.menu_num = hlmi.menu_num " .
|
|
"AND hloi.menu_item_num = hlmi.record_num " .
|
|
"AND ordered_by_num = $student_num " .
|
|
"AND hloi.active != 'N' " .
|
|
"AND hlmi.active != 'N' " .
|
|
"AND hloi.qty > 0 " .
|
|
"ORDER BY hlmi.sequence,hlmi.item_title";
|
|
$items = db_query($query);
|
|
|
|
$msg = '';
|
|
if (db_num_rows($items)) {
|
|
while ($row = db_fetch_assoc($items)) {
|
|
$msg .= sprintf(" %3d - %s\n",$row['qty'],$row['item_title']);
|
|
if ($school_record['email_reminder_description'] == 'Y' && strlen(trim($row['item_description']))) $msg .= sprintf(" - %s\n",trim($row['item_description']));
|
|
}
|
|
}
|
|
else {
|
|
$msg = " -> " . getLanguageText('TEXT-NO-ITEMS-ORDERED',$language) . "\n";
|
|
}
|
|
|
|
return($msg);
|
|
}
|
|
|
|
|
|
//
|
|
// Display status message with specified class
|
|
//
|
|
function displayStatusMessage($message, $class) {
|
|
|
|
// $message = strip_tags($message);
|
|
// $message = str_replace("\n","<br>",$message);
|
|
// echo("<span class='$class' style='margin: 3px 0 3px 0'>$message</span>\n");
|
|
echo("<span class='$class' style='margin: 1px 0 1px 0'>$message</span>\n");
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Application Notifications Header
|
|
//
|
|
function displayApplicationNotificationHeader() {
|
|
echo("<br>");
|
|
$message = "<span style='color: #000000'>".getLanguageText('TEXT-APPLICATION-NOTIFICATIONS')."</span>";
|
|
$message = getLanguageText('TEXT-APPLICATION-NOTIFICATIONS');
|
|
$class = "infoheader";
|
|
displayStatusMessage($message,$class);
|
|
}
|
|
|
|
|
|
//
|
|
// Format file name for downloading
|
|
//
|
|
function genFileName($name) {
|
|
global $school_record;
|
|
$code = $school_record['default_url_code'];
|
|
return($code . ".$name");
|
|
}
|
|
|
|
|
|
//
|
|
// Format the phone number entered and return the formatted value
|
|
//
|
|
function formatPhoneNumber($phone,$school_country="Canada") {
|
|
|
|
global $school_record;
|
|
|
|
if (strlen($phone) == 0) return("");
|
|
|
|
// Format phone number based on the country the school is located in
|
|
switch ($school_country) {
|
|
case 'Canada':
|
|
case 'USA':
|
|
// Strip any non-digits from the phone number
|
|
$phone = preg_replace('/[^0-9]/','',$phone);
|
|
$ext = "";
|
|
|
|
if (substr($phone,0,1) == '1' || substr($phone,0,1) == '0') $phone = substr($phone,1);
|
|
|
|
// Phone numbers with less than 7 digits, 8 or 9 digits or more than 10 digits are not acceptable
|
|
if (strlen($phone) < 7) return($phone);
|
|
if (strlen($phone) == 8 || strlen($phone) == 9) return($phone);
|
|
if (strlen($phone) > 10) $ext = substr($phone,10);
|
|
|
|
// Phone number must be 10 digits long
|
|
if (strlen($phone) < 10) return($phone);
|
|
|
|
$phone = "(" . substr($phone,0,3) . ")" . substr($phone,3,3) . "-" . substr($phone,6,4);
|
|
if (strlen($ext)) $phone .= " x$ext";
|
|
break;
|
|
|
|
case 'Australia':
|
|
// Strip any non-digits from the phone number
|
|
$phone = preg_replace('/[^0-9]/','',$phone);
|
|
|
|
// Phone number must be 10 digits long
|
|
if (strlen($phone) != 10) return($phone);
|
|
|
|
// Handle mobile phone numbers
|
|
if (substr($phone,0,2) == "04") {
|
|
$phone = substr($phone,0,4) . " " . substr($phone,4,3) . " " . substr($phone,7,3);
|
|
}
|
|
else {
|
|
// All other Australian phone numbers
|
|
$phone = "(" . substr($phone,0,2) . ")" . substr($phone,2,4) . " " . substr($phone,6,4);
|
|
}
|
|
break;
|
|
}
|
|
|
|
return("$phone");
|
|
}
|
|
|
|
|
|
?>
|