PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/products/includes/inc_products_db_save_mod.php

https://github.com/timschofield/2.8
PHP | 164 lines | 129 code | 21 blank | 14 comment | 33 complexity | b72855fbfa3c756c9f596d78de650e2f MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?php
  2. /*------begin------ This protection code was suggested by Luki R. luki@karet.org ---- */
  3. if (stristr($PHP_SELF,'inc_products_db_save_mod.php')) die('<meta http-equiv="refresh" content="0; url=../">');
  4. /*------end------*/
  5. if(isset($cat)&&($cat=='pharma')) $dbtable='care_pharma_products_main';
  6. else $dbtable='care_med_products_main';
  7. // if mode is save then save the data
  8. if(isset($mode)&&($mode=='save')){
  9. $saveok=false;
  10. $error=false;
  11. $error_bnum=false;
  12. $error_name=false;
  13. $error_besc=false;
  14. $error_minmax=false;
  15. $bestellnum=trim($bestellnum);
  16. if ($bestellnum=='') { $error_bnum=true; $error=true;};
  17. $artname=trim($artname);
  18. if ($artname=='') { $error_name=true; $error=true; };
  19. $besc=trim($besc);
  20. if ($besc=='') { $error_besc=true; $error=true; };
  21. if(!is_numeric($minorder)) $minorder=NULL;
  22. if(!is_numeric($maxorder)) $maxorder=NULL;
  23. $proorder=(int)$proorder;
  24. if($maxorder&&$minorder>$maxorder){ $error_minmax=true; $error=true;}
  25. # Default nr.of pcs. pro order is 1
  26. if(!$proorder) $proorder=1;
  27. if(!$update){
  28. # check if order number exists
  29. if($product_obj->ProductExists($bestellnum,$cat)){
  30. $error='order_nr_exists';
  31. $bestellnum='';
  32. }
  33. }
  34. if(!$error){
  35. //clean and check input data variables
  36. $encoder=trim($encoder);
  37. if($encoder=='') $encoder=$ck_prod_db_user;
  38. // save the uploaded picture
  39. // if a pic file is uploaded move it to the right dir
  40. if(is_uploaded_file($_FILES['bild']['tmp_name']) && $_FILES['bild']['size']){
  41. $picext=substr($_FILES['bild']['name'],strrpos($_FILES['bild']['name'],'.')+1);
  42. # Check if the file format is allowed
  43. if(stristr($picext,'gif')||stristr($picext,'jpg')||stristr($picext,'png'))
  44. {
  45. $n=0;
  46. $picfilename=$_FILES['bild']['name'];
  47. list($f,$x)=explode('.',$picfilename);
  48. $idx=substr($picfilename,strpos($picfilename,'[')+1);
  49. if($idx)
  50. {
  51. $cf=substr($picfilename,0,strpos($picfilename,'['));
  52. $lx=substr($idx,0,strpos($idx,']'));
  53. $n=$lx;
  54. }
  55. while(file_exists($imgpath.$picfilename))
  56. {
  57. $n++;
  58. if($lx) $picfilename=$cf."[$n]".".".$x;
  59. else $picfilename=$f."[$n]".".".$x;
  60. }
  61. # Prepend the order nr to the filename
  62. $picfilename=$bestellnum.'_'.$picfilename;
  63. # Now save the image to the hard drive
  64. copy($_FILES['bild']['tmp_name'],$imgpath.$picfilename);
  65. }
  66. else
  67. {
  68. $picext='';
  69. }
  70. }
  71. $oktosql=true;
  72. if(!($update)){
  73. $data=array('bestellnum'=>$bestellnum,
  74. 'artikelnum'=>$artnum,
  75. 'industrynum'=>$indusnum,
  76. 'artikelname'=>$artname,
  77. 'generic'=>$generic,
  78. 'description'=>$besc,
  79. 'picfile'=>$picfilename,
  80. 'packing'=>$pack,
  81. 'dose'=>$dose,
  82. 'minorder'=>$minorder,
  83. 'maxorder'=>$maxorder,
  84. 'proorder'=>$proorder,
  85. 'encoder'=>$_SESSION['sess_user_name'],
  86. 'enc_date'=>$dstamp,
  87. 'enc_time'=>$tstamp,
  88. 'lock_flag'=>$lockflag,
  89. 'medgroup'=>$medgroup,
  90. 'cave'=>$caveflag,
  91. 'minpcs'=>$minpcs,
  92. 'history'=>"Created ".date('Y-m-d H:i:s')." ".$_SESSION['sess_user_name']."\n",
  93. 'create_id'=>$_SESSION['sess_user_name'],
  94. 'create_time'=>date('YmdHis')
  95. );
  96. # Set core to main products
  97. $product_obj->useProduct($cat);
  98. $product_obj->setDataArray($data);
  99. $saveok=$product_obj->insertDataFromInternalArray();
  100. $oktosql=false;
  101. }else{
  102. $updateok=true;
  103. $tail="generic='$generic',
  104. description='$besc',
  105. packing='$pack',
  106. dose='$dose',
  107. minorder='$minorder',
  108. maxorder='$maxorder',
  109. proorder='$proorder',
  110. minpcs='$minpcs',";
  111. # If the image filename extension is empty do not update picfile
  112. if($picext!="") $tail.="picfile='$picfilename',";
  113. $tail.="encoder='$encoder',
  114. enc_date='$dstamp',
  115. enc_time='$tstamp',
  116. lock_flag='".(int)$lockflag."',
  117. medgroup='$medgroup',
  118. cave='$caveflag',
  119. history=".$product_obj->ConcatHistory("Update ".date('Y-m-d H:i:s')." ".$_SESSION['sess_user_name']."\n").",
  120. create_id = '".$_SESSION['sess_user_name']."',
  121. create_time = '".date('YmdHis')."'";
  122. $sql="UPDATE $dbtable SET ";
  123. if($ref_bnum==$bestellnum)
  124. $sql=$sql."artikelnum='$artnum', industrynum='$indusnum', artikelname='$artname', $tail WHERE bestellnum='$bestellnum'";
  125. else if ($ref_artnum==$artnum)
  126. $sql=$sql."bestellnum='$bestellnum', industrynum='$indusnum', artikelname='$artname', $tail WHERE artikelnum='$artnum'";
  127. else if($ref_indusnum==$indusnum)
  128. $sql=$sql."bestellnum='$bestellnum', artikelnum='$artnum', artikelname='$artname', $tail WHERE industrynum='$indusnum'";
  129. else if($ref_artname==$artname)
  130. $sql=$sql."bestellnum='$bestellnum', artikelnum='$artnum', industrynum='$indusnum', $tail WHERE artikelname='$artname'";
  131. else
  132. { $updateok=false; $oktosql=false;}
  133. if($updateok) $keyword=$bestellnum;else $keyword=$ref_bnum;
  134. }
  135. // echo $sql;
  136. if($oktosql){
  137. if($product_obj->Transact($sql)){
  138. $saveok=true;
  139. }else{print "no save<p>".$sql."<p>$LDDbNoSave";};
  140. }
  141. }
  142. }
  143. ?>