PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/theme/templates/admin/upload_product.php

https://bitbucket.org/dpxlogistic/digitalefs
PHP | 176 lines | 90 code | 38 blank | 48 comment | 10 complexity | 906858eebcb5656e0f9287b0d02cf4e2 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, MPL-2.0-no-copyleft-exception, CC-BY-3.0, GPL-2.0, GPL-3.0, Apache-2.0, LGPL-2.1, 0BSD
  1. <?PHP
  2. // header("Content-Type: application/json; charset=utf-8");
  3. include "../models/SQLServer.php";
  4. require_once '../Excel/reader.php';
  5. function get_data($file_path){
  6. $data = new Spreadsheet_Excel_Reader();
  7. $data->setOutputEncoding('utf-8');
  8. $data->setUTFEncoder('iconv');
  9. $data->read($file_path);
  10. $header = $data->sheets[0]['cells'][1];
  11. $allrow = count( $data->sheets[0]['cells']);
  12. for ($i = 2; $i <= $allrow; $i++) {
  13. $row= $data->sheets[0]['cells'][$i];
  14. foreach ($row as $key=>$r){
  15. //echo $header[$key]."=". $r."\n";
  16. $r=str_replace(array("\r\n", "\r", "\n"), "", $r);
  17. //if(!empty($r)){
  18. $newRow[$key] = $r;
  19. //}
  20. }
  21. $returnVal[] = $newRow;
  22. $newRow = null;
  23. }
  24. return $returnVal;
  25. }
  26. function upload_product($client,$client_name,$data){
  27. $sql = new SQLServer();
  28. $sql -> SetConnection();
  29. set_time_limit(0);
  30. ob_implicit_flush(true);
  31. ob_end_flush();
  32. print_r($returnVal);die();
  33. for($i=0;$i<count($returnVal);$i++){
  34. //foreach($returnVal as $item){
  35. echo $i;
  36. $sqlText=" web_ins_product_master @client='".$client."',
  37. @item_no = '".$returnVal[$i][0]."',
  38. @item_no_customer = '".$returnVal[$i][1]."',
  39. @barcode = '".$returnVal[$i][2]."',
  40. @description1 = '".addslashes($returnVal[$i][3])."',
  41. @description2 = '".addslashes($returnVal[$i][4])."',
  42. @color = '".$returnVal[$i][6]."',
  43. @label_name = '".$returnVal[$i][5]."',
  44. @product_size = '".$returnVal[$i][7]."',
  45. @reference = '".$returnVal[$i][8]."',
  46. @price='".$returnVal[$i][11]."',
  47. @maker='".$client_name."',@status='ACTIVE'";
  48. print_r($sqlText)."\n\n";
  49. //$result = sqlsrv_fetch_array($sql -> QueryStore($sqlText));
  50. //echo $result."\n". PHP_EOL;
  51. usleep(100000);
  52. //$i++;
  53. }
  54. }
  55. /*****************************************************************************************************************/
  56. /*****************************************************************************************************************/
  57. /*****************************************************************************************************************/
  58. /*****************************************************************************************************************/
  59. /*****************************************************************************************************************/
  60. if (!empty($_FILES["uploaded_file"])) {
  61. //Check if the file is JPEG image and it's size is less than 350Kb
  62. $filename = basename($_FILES['uploaded_file']['name']);
  63. $ext = substr($filename, strrpos($filename, '.') + 1);
  64. $newname ='../xls_upload/'.md5(uniqid()).".". $ext;
  65. if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
  66. $success = true;
  67. } else {
  68. $success = false;
  69. break;
  70. }
  71. }
  72. // check and process based on successful status
  73. if ($success === true) {
  74. // call the function to save all data to database
  75. // code for the following function `save_data` is not
  76. // mentioned in this example
  77. $returnVal = get_data($newname);
  78. print_r($returnVal);die();
  79. //$i=1;
  80. $sql = new SQLServer();
  81. $sql -> SetConnection();
  82. $client="307";
  83. $client_name = "myladyjane";
  84. set_time_limit(0);
  85. ob_implicit_flush(true);
  86. ob_end_flush();
  87. //for($i=0;$i<count($returnVal);$i++){
  88. $j=0;
  89. for($i=0;$i<count($returnVal);$i++){
  90. /*foreach($returnVal as $item){
  91. $sqlText=" web_ins_product_master @client='".$client."',
  92. @description1 = '".addslashes(iconv('UTF-8','TIS-620',trim($returnVal[$i][4])))."',
  93. @color = '".addslashes(iconv('UTF-8','TIS-620',trim($returnVal[$i][7])))."',
  94. @label_name = '".addslashes(iconv('UTF-8','TIS-620',trim($returnVal[$i][6])))."',
  95. @product_size = '".iconv('UTF-8','TIS-620',trim($returnVal[$i][8]))."',
  96. @price='".$returnVal[$i][12]."',
  97. @maker='".$client_name."',
  98. @status='ACTIVE';";
  99. //echo $sqlText."\n";
  100. */ $refcode = trim($returnVal[$i][15]);
  101. $item_no =trim($returnVal[$i][3]);
  102. if ($refcode != ''){
  103. $sql = "update product_master set reference='".trim($returnVal[$i][15])."' where item_no='".$item_no."' and client = '307';";
  104. echo $sql."\n";
  105. $j++;
  106. }
  107. // if($returnVal[$i][8] !=''){
  108. //$sqlText = "update product_master set reference = '".$returnVal[$i][8]."' where item_no = '".$returnVal[$i][0]."' and client ='307'";
  109. //$sqlText=str_replace(array("\r\n", "\r", "\n"), "", $sqlText);
  110. //echo $sqlText."\n". PHP_EOL;
  111. //$result = sqlsrv_fetch_array($sql -> QueryStore($sqlText));
  112. //print_r($result)."\n". PHP_EOL;
  113. // }
  114. //usleep(100000);
  115. }
  116. echo json_encode(array("total"=>$j));
  117. // store a successful response (default at least an empty array). You
  118. // could return any additional response info you need to the plugin for
  119. // advanced implementations.
  120. $output = [];
  121. // for example you can get the list of files uploaded this way
  122. $output = ['uploaded' => $newname];
  123. } elseif ($success === false) {
  124. $output = ['error'=>'Error while uploading images. Contact the system administrator'];
  125. // delete any uploaded files
  126. foreach ($paths as $file) {
  127. unlink($file);
  128. }
  129. } else {
  130. $output = ['error'=>'No files were processed.'];
  131. }
  132. // return a json encoded response for plugin to process successfully
  133. echo json_encode($output);
  134. ?>