PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/pharmacy_tz/pharmacy_tz_new_product.php

https://bitbucket.org/vincentbii/amurt
PHP | 311 lines | 196 code | 58 blank | 57 comment | 53 complexity | 99e10c799fe286e6a96c86bf518dd813 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, MIT, BSD-3-Clause, LGPL-2.0, GPL-3.0
  1. <?php
  2. if ($GO_BACK_TO_SEARCH) {
  3. if ($mode!="delete" && $mode!="update") {
  4. header('Location: pharmacy_tz_search.php?keyword='.$keyword.'&category='.$category);
  5. exit();
  6. }
  7. }
  8. if (empty($item_classification)) $item_classification=$category;
  9. error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
  10. require('./roots.php');
  11. require($root_path.'include/inc_environment_global.php');
  12. require($root_path.'include/care_api_classes/class_tz_pharmacy.php');
  13. /**
  14. * CARE2X Integrated Hospital Information System Deployment 2.1 - 2004-10-02
  15. * GNU General Public License
  16. * Copyright 2005 Robert Meggle based on the development of Elpidio Latorilla (2002,2003,2004,2005)
  17. * elpidio@care2x.org, meggle@merotech.de
  18. * Updated by: Alexander Irro - alexander.irro@merotech.de
  19. * Updated by: Robert Meggle - meggle@merotech.de
  20. * See the file "copy_notice.txt" for the licence notice
  21. */
  22. $lang_tables[]='pharmacy.php';
  23. define('NO_2LEVEL_CHK',1);
  24. require($root_path.'include/inc_front_chain_lang.php');
  25. $debug=false;
  26. if ($debug) {
  27. echo "debugging mode is ON<br>";
  28. // output debug informations
  29. function print_debug_info($name, $value) {
  30. if (isset($value))
  31. echo $name." is set to value: ".$value."<br>";
  32. }
  33. print_debug_info ("mode",$mode);
  34. print_debug_info("Peadric check box", $is_peadric);
  35. print_debug_info("Adult check box", $is_adult);
  36. print_debug_info("Other check box", $is_other);
  37. print_debug_info("Consumable check box", $is_consumable);
  38. print_debug_info("Items full description", $items_full_description);
  39. print_debug_info("Item classification", $item_classification);
  40. print_debug_info("Selian Item number", $selian_item_number);
  41. print_debug_info("Pack size",$pack_size);
  42. print_debug_info("Selians Item Description",$selians_item_description);
  43. print_debug_info("Price",$selians_item_price);
  44. print_debug_info ("mode",$mode);
  45. }
  46. // Endable db-debugging if variable debug is true
  47. ($debug) ? $db->debug=TRUE : $db->debug=FALSE;
  48. $product_obj = new Product();
  49. $product_obj->usePriceDescriptionTable();
  50. /*
  51. * Seciton to read out the Configuration of price accounts
  52. */
  53. $allItems=$product_obj->getAllDataObject();
  54. $index=0;
  55. while($row=$allItems->FetchRow()){
  56. $short[$index] = $row['ShowDescription'];
  57. $long[$index] = $row['FullDescription'];
  58. $is_insurance[$index] = $row['is_insurance_price'];
  59. $timestamp=$row['last_change'];
  60. $user=$row['UID'];
  61. $index ++;
  62. }
  63. // quite navie, but's working:
  64. $short_1=$short[0]; $long_1=$long[0]; $is_insured_1 = $is_insurance[0];
  65. $short_2=$short[1]; $long_2=$long[1]; $is_insured_2 = $is_insurance[1];
  66. $short_3=$short[2]; $long_3=$long[2]; $is_insured_3 = $is_insurance[2];
  67. $short_4=$short[3]; $long_4=$long[3]; $is_insured_4 = $is_insurance[3];
  68. //------------------------------------------------------------------------------
  69. /**
  70. * This page can have several kinds of modes:
  71. * case 1: mode is not set -> New item for the database (just for entering first time)
  72. * case 2: mode is set to insert -> Item description is availabe, just checking the values before database entry
  73. * case 3: mode is set to update -> update the items of this form, but check at first before database entry
  74. * case 4: mode is set to erase -> delete a specific item out of the database
  75. * case 5: mode is set to show -> just show the data, but no possibility to change it
  76. * case 6: mode is set to edit -> likely the same like update but show at first the data just with update functionallity
  77. * case 7: mode is set to erase -> same like delete, but from external call
  78. */
  79. // Check form values if variable mode is set to "insert"
  80. //------------------------------------------------------------------------------
  81. if (!empty($mode)) {
  82. if ( ($mode!="show") && ($mode!="edit") && ($mode!="erase") && (!$GO_BACK_TO_SEARCH)) { // show or edit are external calls of this site
  83. if ($product_obj->check_form_variable($selian_item_number)) {
  84. if ($debug) echo "ERROR: <b> item Number is empty</b>";
  85. $ERROR=TRUE; print_r($_GET);
  86. $ERROR_SELIAN_ITEM_NUMBER = TRUE;
  87. }
  88. if ($mode=="insert") {
  89. if ($product_obj->check_form_variable($selians_item_description)) {
  90. $ERROR=TRUE;
  91. $ERROR_SELIANS_ITEM_DESCRIPTION = TRUE;
  92. }
  93. }
  94. if ($ERROR)
  95. $ERROR_MSG.="THERE ARE SOME IMPORTANT FIELDS MISSING! MISSING FIELDS ARE MARKED<br>";
  96. }
  97. // if show or edit then preload the missing informations for editing
  98. if ($mode=="show" || $mode=="edit" || $mode=="erase" || $mode=="update") {
  99. if (!empty($item_id) && empty($formular_sent)) {
  100. $is_peadric = $product_obj->get_item_peadric($item_id);
  101. $is_adult = $product_obj->get_item_adult($item_id);
  102. $is_other = $product_obj->get_item_other($item_id);
  103. $is_consumable = $product_obj->get_item_consumable($item_id);
  104. $selian_item_number = $product_obj->get_itemnumber($item_id);
  105. $partcode = $product_obj->get_itemnumber($item_id);
  106. $selians_item_description = $product_obj->get_selians_item_description($item_id);
  107. $items_full_description = $product_obj->get_items_full_description($item_id);
  108. $item_classification = $product_obj->get_item_classification($item_id);
  109. //$selians_item_price = $product_obj->get_selians_item_price($item_id);
  110. $selians_item_price = $product_obj->get_selians_item_alt_price($item_id,0);
  111. $selians_item_price_1 = $product_obj->get_selians_item_alt_price($item_id,1);
  112. $selians_item_price_2 = $product_obj->get_selians_item_alt_price($item_id,2);
  113. $selians_item_price_3 = $product_obj->get_selians_item_alt_price($item_id,3);
  114. }
  115. }
  116. }
  117. //-----------------------------
  118. if (empty($is_peadric))
  119. $is_peadric = 0;
  120. else
  121. $is_peadric = 1;
  122. //---
  123. if (empty($is_adult))
  124. $is_adult = 0;
  125. else
  126. $is_adult = 1;
  127. //---
  128. if (empty($is_other))
  129. $is_other = 0;
  130. else
  131. $is_other = 1;
  132. //---
  133. if (empty($is_consumable))
  134. $is_consumable = 0;
  135. else
  136. $is_consumable = 1;
  137. //-----------------------------
  138. //------------------------------------------------------------------------------
  139. if ( !empty($mode) && !$ERROR ) {
  140. //------------------------------------------------------------------------------
  141. (empty($is_peadric)) ? $is_peadric = "0" : $is_peadric = "1";
  142. (empty($is_adult)) ? $is_adult = "0" : $is_adult = "1";
  143. (empty($is_other)) ? $is_other = "0" : $is_other = "1";
  144. (empty($is_consumable)) ? $is_consumable = "0" : $is_consumable = "1";
  145. if (empty($selians_item_price)) $selians_item_price="0";
  146. if (empty($selians_item_price_1)) $selians_item_price_1="0";
  147. if (empty($selians_item_price_2)) $selians_item_price_2="0";
  148. if (empty($selians_item_price_3)) $selians_item_price_3="0";
  149. $db_buffer = array();
  150. $db_buffer['is_pediatric'] = $is_peadric;
  151. $db_buffer['is_adult'] = $is_adult;
  152. $db_buffer['is_other'] = $is_other;
  153. $db_buffer['is_consumable'] = $is_consumable;
  154. $db_buffer['item_number'] = $selian_item_number;
  155. $db_buffer['partcode'] = $selian_item_number;
  156. $db_buffer['item_description'] = $selians_item_description;
  157. $db_buffer['item_full_description'] = $items_full_description;
  158. $db_buffer['purchasing_class'] = $item_classification;
  159. $db_buffer['unit_price'] = $selians_item_price;
  160. $db_buffer['unit_price_1'] = $selians_item_price_1;
  161. $db_buffer['unit_price_2'] = $selians_item_price_2;
  162. $db_buffer['unit_price_3'] = $selians_item_price_3;
  163. $product_obj->useProductTable();
  164. //------------------------------------------------------------------------------
  165. if ($mode=="insert") {
  166. // Check at first that this item is still not available in the database:
  167. if ($debug) echo "current mode is insert!<br>";
  168. if ($product_obj -> item_number_exists ($selian_item_number)) {
  169. // The item still exists in the database!
  170. $ERROR_MSG.="Sorry, this item with code \"".$selian_item_number."\" still exists in the database! <br>
  171. Please check the field item number, you can just update or delete it!<br>";
  172. $ERROR_SELIAN_ITEM_NUMBER = TRUE;
  173. $ERROR=TRUE;
  174. } else {
  175. // This is a new item, store it into the database
  176. $product_obj->setDataArray($db_buffer);
  177. $product_obj->insertDataFromInternalArray();
  178. $MSG.="Item with code \"".$selian_item_number."\" is now archived in the database<br>";
  179. }
  180. } // end of if ($mode=="insert")
  181. //------------------------------------------------------------------------------
  182. if ($mode=="update") {
  183. if ($debug) echo "current mode is update!<br>";
  184. if ($product_obj -> item_number_exists ($selian_item_number)) {
  185. // The item still exists in the database!
  186. if ($debug) { echo "Database fields are:"; print_r($db_buffer); }
  187. $product_obj->setDataArray($db_buffer);
  188. $product_obj->updatePharmacyDataFromInternalArray($item_id,FALSE);
  189. $MSG.="Item with code \"".$selian_item_number."\" is now updated<br>";
  190. } else {
  191. // There is no item with such an item number in the database
  192. $ERROR_MSG.="Something is wrong, the item code \"".$selian_item_number."\" is not available in the database! <br>";
  193. $ERROR_SELIAN_ITEM_NUMBER = TRUE;
  194. $ERROR=TRUE;
  195. }
  196. if ($GO_BACK_TO_SEARCH && !$ERROR) {
  197. header('Location: pharmacy_tz_search.php?keyword='.$keyword.'&category='.$item_classification);
  198. }
  199. } // end of if ($mode=="update")
  200. //------------------------------------------------------------------------------
  201. if ($mode=="delete") {
  202. if ($debug) echo "current mode is DELETE!<br>";
  203. if ($product_obj -> item_number_exists ($selian_item_number)) {
  204. // The item still exists in the database!
  205. $product_obj->delete_item($selian_item_number);
  206. $MSG.="Item with code \"".$selian_item_number."\" is deleted now<br>";
  207. } else {
  208. // This is a new item
  209. // There is no item with such an item number in the database
  210. $ERROR_MSG.="Something is wrong, the item code \"".$selian_item_number."\" is not available in the database! <br>";
  211. $ERROR_SELIAN_ITEM_NUMBER = TRUE;
  212. $ERROR=TRUE;
  213. }
  214. if ($GO_BACK_TO_SEARCH && !$ERROR) {
  215. header('Location: pharmacy_tz_search.php?keyword='.$keyword.'&category='.$item_classification);
  216. }
  217. } // end of if ($mode=="erase")
  218. //------------------------------------------------------------------------------
  219. if ($mode=="show") {
  220. $html_disabler="disabled";
  221. $GO_BACK_TO_SEARCH=TRUE;
  222. #d.r. from merotech
  223. $help_file="pharmacy_product_edit.php";
  224. $src="Pharmacy :: My Product Catalog :: Show";
  225. }
  226. //------------------------------------------------------------------------------
  227. if ($mode=="edit") {
  228. $mode="update";
  229. $UPDATE_FORM=TRUE;
  230. $GO_BACK_TO_SEARCH=TRUE;
  231. #d.r. from merotech
  232. $help_file="pharmacy_product_edit.php";
  233. $src="Pharmacy :: My Product Catalog :: Edit";
  234. }
  235. //------------------------------------------------------------------------------
  236. if ($mode=="erase") {
  237. $html_disabler="disabled";
  238. $DELETE_FORM=TRUE;
  239. $GO_BACK_TO_SEARCH=TRUE;
  240. #d.r. from merotech
  241. $help_file="pharmacy_product_edit.php";
  242. $src="Pharmacy :: My Product Catalog :: Delete";
  243. }
  244. //------------------------------------------------------------------------------
  245. } // end of if (!empty($mode))
  246. else {
  247. #d.r from merotech
  248. $help_file="pharmacy_product_insert.php";
  249. $src="Pharmacy :: My Product Catalog :: New Product";
  250. }
  251. //------------------------------------------------------------------------------
  252. require ("gui/gui_pharmacy_tz_new_product.php");
  253. ?>