Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', 2);
- /* Settings */
- $basePrice = $_POST['wellprice']; // The price of a Well drink.
- $newPricing = array(
- $_POST['callcat']=> $_POST['catprice'], // Call
- $_POST['premcat']=> $_POST['premprice'], // Prem
- $_POST['spremcat']=>$_POST['spremprice']); // SPrem
- /* Processing */
- foreach($newPricing as $catNumber => $newPrice)
- {
- var_dump($newPricing);
- $ids = getIdsByCategory($catNumber);
- updateItems($ids, $newPrice - $basePrice); // Update for the adjusted price
- }
- /* Functions */
- function getIdsByCategory($categoryId)
- {
- $itemsList = array(); // We will store the item ids in this list
- $dbf = dbase_open('CIT.DBF', 0) or die();
- $record_count = dbase_numrecords($dbf);
- for ($cit_records=1; $cit_records<=$record_count; $cit_records++)
- {
- $row = dbase_get_record_with_names($dbf, $cit_records);
- if ($row['CATEGORY'] == $categoryId)
- $itemsList[] = $row['ITEMID']; // Add the item id to the list.
- }
- dbase_close($dbf);
- return $itemsList;
- }
- function recordCount()
- {
- $dbf = dbase_open('ITM.DBF', 2) or die();
- $record_count = dbase_numrecords($dbf);
- dbase_close($dbf);
- return $record_count;
- }
- function updateItems($items, $price) {
- // For each record in the ITM file...
- for ($itm_record=1; $itm_record<=recordCount(); $itm_record++)
- {
- $dbf = dbase_open('ITM.DBF', 2) or die();
- $record_count = dbase_numrecords($dbf);
- $row = dbase_get_record_with_names($dbf, $itm_record);
- // If the item id is found in the list of items to update...
- $key = array_search($row['ID'], $items);
- if ($key !== false)
- {
- unset($row['deleted']);
- $row['PRICE'] = $price; // Update Price
- $row=array_values($row);
- dbase_replace_record($dbf, $row, $itm_record); // Save record
- unset($items[$key]); // Remove the item from the list.
- if (!count($items))
- break;
- } dbase_close($dbf);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment