Guest User

Untitled

a guest
Mar 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', 2);
  4.  
  5. /* Settings */
  6. $basePrice = $_POST['wellprice']; // The price of a Well drink.
  7. $newPricing = array(
  8. $_POST['callcat']=> $_POST['catprice'], // Call
  9. $_POST['premcat']=> $_POST['premprice'], // Prem
  10. $_POST['spremcat']=>$_POST['spremprice']); // SPrem
  11.  
  12. /* Processing */
  13. foreach($newPricing as $catNumber => $newPrice)
  14. {
  15. var_dump($newPricing);
  16. $ids = getIdsByCategory($catNumber);
  17.  
  18. updateItems($ids, $newPrice - $basePrice); // Update for the adjusted price
  19. }
  20.  
  21. /* Functions */
  22. function getIdsByCategory($categoryId)
  23. {
  24.  
  25. $itemsList = array(); // We will store the item ids in this list
  26.  
  27. $dbf = dbase_open('CIT.DBF', 0) or die();
  28.  
  29. $record_count = dbase_numrecords($dbf);
  30.  
  31. for ($cit_records=1; $cit_records<=$record_count; $cit_records++)
  32. {
  33. $row = dbase_get_record_with_names($dbf, $cit_records);
  34. if ($row['CATEGORY'] == $categoryId)
  35. $itemsList[] = $row['ITEMID']; // Add the item id to the list.
  36. }
  37. dbase_close($dbf);
  38. return $itemsList;
  39. }
  40.  
  41.  
  42. function recordCount()
  43. {
  44. $dbf = dbase_open('ITM.DBF', 2) or die();
  45.  
  46. $record_count = dbase_numrecords($dbf);
  47.  
  48. dbase_close($dbf);
  49. return $record_count;
  50.  
  51. }
  52.  
  53.  
  54. function updateItems($items, $price) {
  55. // For each record in the ITM file...
  56. for ($itm_record=1; $itm_record<=recordCount(); $itm_record++)
  57. {
  58.  
  59. $dbf = dbase_open('ITM.DBF', 2) or die();
  60. $record_count = dbase_numrecords($dbf);
  61. $row = dbase_get_record_with_names($dbf, $itm_record);
  62.  
  63.  
  64. // If the item id is found in the list of items to update...
  65. $key = array_search($row['ID'], $items);
  66.  
  67. if ($key !== false)
  68. {
  69. unset($row['deleted']);
  70.  
  71. $row['PRICE'] = $price; // Update Price
  72. $row=array_values($row);
  73. dbase_replace_record($dbf, $row, $itm_record); // Save record
  74.  
  75. unset($items[$key]); // Remove the item from the list.
  76. if (!count($items))
  77. break;
  78.  
  79.  
  80. } dbase_close($dbf);
  81. }
  82.  
  83.  
  84. }
  85.  
  86. ?>
Add Comment
Please, Sign In to add comment