110 lines
3.7 KiB
PHP
110 lines
3.7 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = "";
|
|
$headerArgs = "";
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Supplier');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
$action = '';
|
|
$naction = '';
|
|
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
|
|
$subtitle = "";
|
|
$swhere = "";
|
|
unset($selected_supplier);
|
|
if (array_key_exists('selected_supplier',$_GET) && strlen($_GET['selected_supplier']) > 0) $selected_supplier = $_GET['selected_supplier'];
|
|
if (array_key_exists('selected_supplier',$_POST) && strlen($_POST['selected_supplier']) > 0) $selected_supplier = $_POST['selected_supplier'];
|
|
|
|
if (isset($selected_supplier)) {
|
|
$results = db_query("select * from suppliers where school_num = $supplier_school_num and record_num = $selected_supplier");
|
|
if (db_num_rows($results) != 1) {
|
|
echo("<br>\n");
|
|
$error_message = "Invalid supplier number";
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
$supplier = db_fetch_array($results);
|
|
$subtitle = " - " . $supplier['supplier_name'];
|
|
$swhere = "and supplier_num = $selected_supplier ";
|
|
}
|
|
|
|
|
|
//
|
|
// Process all actions to list and edit records
|
|
//
|
|
$naction = "";
|
|
|
|
$templatePageTitle = getLanguageText('TEXT-SUPPLIER-PRODUCT-UPDATE');
|
|
|
|
|
|
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
|
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
|
|
|
|
|
switch (strtolower($naction)) {
|
|
case "update":
|
|
|
|
// Loop through the products and update the prices
|
|
$query = "select s.supplier_name,sp.* from supplier_products as sp, suppliers as s " .
|
|
"where sp.school_num = $supplier_school_num " .
|
|
"and s.school_num = $supplier_school_num " .
|
|
"and sp.supplier_num = s.record_num " .
|
|
"AND sp.status = 'Active' " .
|
|
$swhere .
|
|
"order by supplier_name,product_name";
|
|
$products = db_query($query);
|
|
|
|
while ($product = db_fetch_array($products)) {
|
|
$product_num = $product['record_num'];
|
|
|
|
// Setup field names
|
|
$sfield = "supplier_$product_num";
|
|
$nfield = "name_$product_num";
|
|
$dfield = "description_$product_num";
|
|
$lfield = "label_$product_num";
|
|
$hfield = "hot_cold_$product_num";
|
|
|
|
$snum = $_POST[$sfield];
|
|
$name = db_escape_string($_POST[$nfield]);
|
|
$descr = db_escape_string($_POST[$dfield]);
|
|
$label = db_escape_string($_POST[$lfield]);
|
|
$hotcold = $_POST[$hfield];
|
|
|
|
// Update database
|
|
$query = "update supplier_products " .
|
|
"set supplier_num = $snum, " .
|
|
"product_name = '$name', " .
|
|
"product_description = '$descr', " .
|
|
"label_name = '$label', " .
|
|
"hot_cold_food = '$hotcold' " .
|
|
"where school_num = $school_num " .
|
|
"and record_num = $product_num";
|
|
db_query($query);
|
|
}
|
|
|
|
$form_message = "Products Have Been Updated";
|
|
break;
|
|
}
|
|
|
|
// Display the selected menu form
|
|
include "supplier_products_update.description.form.php";
|
|
|
|
endTemplate();
|
|
?>
|