/theme/templates/admin/upload_product.php
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
- <?PHP
- // header("Content-Type: application/json; charset=utf-8");
- include "../models/SQLServer.php";
- require_once '../Excel/reader.php';
-
- function get_data($file_path){
-
- $data = new Spreadsheet_Excel_Reader();
- $data->setOutputEncoding('utf-8');
- $data->setUTFEncoder('iconv');
- $data->read($file_path);
-
- $header = $data->sheets[0]['cells'][1];
- $allrow = count( $data->sheets[0]['cells']);
- for ($i = 2; $i <= $allrow; $i++) {
-
- $row= $data->sheets[0]['cells'][$i];
- foreach ($row as $key=>$r){
- //echo $header[$key]."=". $r."\n";
-
- $r=str_replace(array("\r\n", "\r", "\n"), "", $r);
- //if(!empty($r)){
- $newRow[$key] = $r;
- //}
- }
- $returnVal[] = $newRow;
- $newRow = null;
- }
-
- return $returnVal;
- }
-
- function upload_product($client,$client_name,$data){
- $sql = new SQLServer();
- $sql -> SetConnection();
- set_time_limit(0);
- ob_implicit_flush(true);
- ob_end_flush();
- print_r($returnVal);die();
- for($i=0;$i<count($returnVal);$i++){
- //foreach($returnVal as $item){
- echo $i;
-
- $sqlText=" web_ins_product_master @client='".$client."',
- @item_no = '".$returnVal[$i][0]."',
- @item_no_customer = '".$returnVal[$i][1]."',
- @barcode = '".$returnVal[$i][2]."',
- @description1 = '".addslashes($returnVal[$i][3])."',
- @description2 = '".addslashes($returnVal[$i][4])."',
- @color = '".$returnVal[$i][6]."',
- @label_name = '".$returnVal[$i][5]."',
- @product_size = '".$returnVal[$i][7]."',
- @reference = '".$returnVal[$i][8]."',
- @price='".$returnVal[$i][11]."',
- @maker='".$client_name."',@status='ACTIVE'";
-
- print_r($sqlText)."\n\n";
- //$result = sqlsrv_fetch_array($sql -> QueryStore($sqlText));
- //echo $result."\n". PHP_EOL;
-
- usleep(100000);
- //$i++;
- }
- }
- /*****************************************************************************************************************/
- /*****************************************************************************************************************/
- /*****************************************************************************************************************/
- /*****************************************************************************************************************/
- /*****************************************************************************************************************/
- if (!empty($_FILES["uploaded_file"])) {
- //Check if the file is JPEG image and it's size is less than 350Kb
- $filename = basename($_FILES['uploaded_file']['name']);
- $ext = substr($filename, strrpos($filename, '.') + 1);
-
-
-
- $newname ='../xls_upload/'.md5(uniqid()).".". $ext;
- if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
- $success = true;
- } else {
- $success = false;
- break;
- }
- }
- // check and process based on successful status
- if ($success === true) {
- // call the function to save all data to database
- // code for the following function `save_data` is not
- // mentioned in this example
- $returnVal = get_data($newname);
- print_r($returnVal);die();
- //$i=1;
- $sql = new SQLServer();
- $sql -> SetConnection();
- $client="307";
- $client_name = "myladyjane";
- set_time_limit(0);
- ob_implicit_flush(true);
- ob_end_flush();
-
- //for($i=0;$i<count($returnVal);$i++){
- $j=0;
- for($i=0;$i<count($returnVal);$i++){
- /*foreach($returnVal as $item){
- $sqlText=" web_ins_product_master @client='".$client."',
-
-
-
- @description1 = '".addslashes(iconv('UTF-8','TIS-620',trim($returnVal[$i][4])))."',
-
- @color = '".addslashes(iconv('UTF-8','TIS-620',trim($returnVal[$i][7])))."',
- @label_name = '".addslashes(iconv('UTF-8','TIS-620',trim($returnVal[$i][6])))."',
- @product_size = '".iconv('UTF-8','TIS-620',trim($returnVal[$i][8]))."',
- @price='".$returnVal[$i][12]."',
- @maker='".$client_name."',
- @status='ACTIVE';";
- //echo $sqlText."\n";
- */ $refcode = trim($returnVal[$i][15]);
- $item_no =trim($returnVal[$i][3]);
- if ($refcode != ''){
- $sql = "update product_master set reference='".trim($returnVal[$i][15])."' where item_no='".$item_no."' and client = '307';";
- echo $sql."\n";
- $j++;
- }
- // if($returnVal[$i][8] !=''){
- //$sqlText = "update product_master set reference = '".$returnVal[$i][8]."' where item_no = '".$returnVal[$i][0]."' and client ='307'";
- //$sqlText=str_replace(array("\r\n", "\r", "\n"), "", $sqlText);
- //echo $sqlText."\n". PHP_EOL;
- //$result = sqlsrv_fetch_array($sql -> QueryStore($sqlText));
- //print_r($result)."\n". PHP_EOL;
-
-
- // }
- //usleep(100000);
-
- }
-
- echo json_encode(array("total"=>$j));
-
- // store a successful response (default at least an empty array). You
- // could return any additional response info you need to the plugin for
- // advanced implementations.
- $output = [];
- // for example you can get the list of files uploaded this way
- $output = ['uploaded' => $newname];
- } elseif ($success === false) {
- $output = ['error'=>'Error while uploading images. Contact the system administrator'];
- // delete any uploaded files
- foreach ($paths as $file) {
- unlink($file);
- }
- } else {
- $output = ['error'=>'No files were processed.'];
- }
- // return a json encoded response for plugin to process successfully
- echo json_encode($output);
- ?>