Edit file File name : oos_automp_insta_usa.php Content :<?php session_start(); include("../include/config.php"); include("../include/functions.php"); include("../include/simpleimage.php"); validate_admin(); $cat_id=mysqli_real_escape_string($GLOBALS['conn'],$_POST['cat_id']); $url=SITE_URL; //$csvMimes = array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'); $csvMimes = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'); // Validate whether selected file is a CSV file if($_REQUEST['submitForm']=='yes'){ //echo $_FILES['csv_file']['type']; //echo "<pre>";print_r($csvMimes);die; if(!empty($_FILES['csv_file']['name']) && in_array($_FILES['csv_file']['type'], $csvMimes)){ $curTime = date('Y-m-d_H:i:s'); $destination_file = $_FILES["csv_file"]["name"]."_".$curTime.".csv"; $target_file = $_FILES['csv_file']['tmp_name']; $store_code = $_REQUEST['store_code']; $csvArr = parse_csv_file($target_file); $cntCsvArr = count($csvArr); echo "<pre>oos";print_r($csvArr); //Make previsious items item as in stock when new oos data recived $obj->query("UPDATE `usa_insta_ff_inventory_sync_v1` SET `available` = '1' "); foreach($csvArr as $csvArrs) { $lookup_code=mysqli_real_escape_string($GLOBALS['conn'],$csvArrs['ordered_upc']); $store_identifier=mysqli_real_escape_string($GLOBALS['conn'],$csvArrs['retailer_location_code_picked']); $shopper_reason_cd=mysqli_real_escape_string($GLOBALS['conn'],$csvArrs['shopper_reason_cd']); if(!empty($shopper_reason_cd) && $shopper_reason_cd='out_of_stock') { $prechk = $obj->query("SELECT store_identifier,oos_cnt FROM `usa_insta_ff_inventory_sync_v1` WHERE lookup_code='$lookup_code' AND store_identifier='$store_identifier'"); $prechkdArr=$obj->fetchNextObject($prechk); $trackOos =$prechkdArr->oos_cnt; $oos_cnt = $trackOos+1; echo "<pre>".$insSql = "UPDATE `usa_insta_ff_inventory_sync_v1` SET `available` = '0',oos_cnt='$oos_cnt' WHERE lookup_code='$lookup_code' AND store_identifier='$store_identifier' "; } $obj->query($insSql); } $_SESSION['sess_msg'] = "File processed successfully!".'<br>'; header("location:oos_automp_insta_usa.php"); exit; //echo "<pre>==ff="; //print_r($csvArr); //die; } else { $_SESSION['sess_msg'] = "Invalid csv file.Please upload valid csv file!".'<br>'; header("location:oos_automp_insta_usa.php"); exit; } } function parse_csv_file($csvfile) { $csv = Array(); $rowcount = 0; if (($handle = fopen($csvfile, "r")) !== FALSE) { $max_line_length = defined('MAX_LINE_LENGTH') ? MAX_LINE_LENGTH : 100000; $header = fgetcsv($handle, $max_line_length); $header = str_replace(' ', '_', $header); $header = str_replace('/', '_', $header); $header_colcount = count($header); while (($row = fgetcsv($handle, $max_line_length)) !== FALSE) { $row_colcount = count($row); if ($row_colcount == $header_colcount) { $entry = array_combine($header, $row); $csv[] = $entry; } else { error_log("csvreader: Invalid number of columns at line " . ($rowcount + 2) . " (row " . ($rowcount + 1) . "). Expected=$header_colcount Got=$row_colcount"); return null; } $rowcount++; } //echo "Totally $rowcount rows found\n"; fclose($handle); } else { error_log("csvreader: Could not read CSV \"$csvfile\""); return null; } return $csv; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo SITE_TITLE; ?></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="css/admin.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" language="javascript"> function validate(obj) { if(obj.cat_id.value==''){ alert("Please select category"); obj.cat_id.focus(); return false; } } </script> </head> <body> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <?php include("header.php") ?> <tr> <td align="right" class="paddRtLt70" valign="top"> <table width="99%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="right" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="middle" class="headingbg bodr text14"> <em><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /></em>Admin: OOS Instacart USA </td> </tr> <tr> <td height="100" align="left" valign="top" bgcolor="#f3f4f6" class="bodr"> <form name="frm" method="POST" enctype="multipart/form-data" action="" onsubmit="return validate(this)"> <input type="hidden" name="submitForm" value="yes" /> <input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" /> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td align="center" colspan="2" class="paddRt14 paddBot11"> <font color="#FF0000"><strong><?php echo $_SESSION['sess_msg']; $_SESSION['sess_msg']='';?></strong></font></td> </tr> <tr> <td align="right" class="paddBot11 paddRt14"><strong>Upload OOS File:</strong></td> <td align="left" class="paddBot11"><input name="csv_file" type="file" /><br/> </td> </tr> <tr> <td align="right" class="paddRt14 paddBot11"> </td> <td align="left" class="paddBot11"> </td> </tr> <tr> <td width="18%" align="right" class="paddRt14 paddBot11"> </td> <td width="82%" align="left" class="paddBot11"> <input type="submit" name="submit" value="Submit" class="submit" border="0"/> </td> </tr> </table></form> </td> </tr> </table> </td> </tr> </table> </td> </tr> <?php include('footer.php'); ?> </table> </body> </html> Save