View file File name : vm_ff_to_xm.php Content :<?php session_start(); include("../include/config.php"); include("../include/functions.php"); include("../include/simpleimage.php"); //echo "<pre>==ff="; //print_r($csvArr);die; validate_admin(); error_reporting(E_ALL); ini_set('display_errors', '1'); $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']; 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"; //$destination_file = "/ubr_inventory/in_files/".$storagename; //move_uploaded_file($target_file,$destination_file); $target_file = $_FILES['csv_file']['tmp_name']; $store_code = $_REQUEST['store_code']; $csvArr = parse_csv_file($target_file); //echo "<pre>==ff="; //print_r($csvArr);die; $cntCsvArr = count($csvArr); move_uploaded_file($_FILES["csv_file"]["tmp_name"], "ubr_inventory/in_files/" . $destination_file); //if(is_uploaded_file($_FILES['csv_file']['tmp_name'])) { //$obj->query("DELETE FROM `uber_inventory_process` WHERE `ubr_store_id` LIKE '$store_code'"); //} foreach($csvArr as $csvArrs) { $lookup_code=$csvArrs['lookup_code']; $store_identifier=removeLineBreakSpaces($csvArrs['Name']); $store_identifier= str_replace( array( "'",'"' ),'',$store_identifier); $storeaddress= $csvArrs['Street_Address']; $storeaddress= str_replace( array( "'",'"' ),'',$storeaddress); $state = $csvArrs['State']; $city =$csvArrs['City']; $mm_store_id = $csvArrs['Store_ID']; $mmStroeLkp = mmStoreLookup(); echo "<pre>==ff="; print_r($mmStroeLkp); $store_icon_url =$mmStroeLkp['stores'][0]['logo_photos'][0]; $store_food_photo_url =$mmStroeLkp['stores'][0]['food_photos'][0]; $locahrsD = $mmStroeLkp['stores'][0]['local_hours']['delivery']; echo $locahrsD['Monday']; if($locahrsD['Sunday']=='Open 24 hourss') { $suno='00:00:00'; $sunc='23:59:59'; $sunday='1'; }if($locahrsD['Monday']=='Open 24 hourss') { $mono='00:00:00'; $monc='23:59:59'; $monday='1'; }if($locahrsD['Tuesday']=='Open 24 hourss') { $tueo='00:00:00'; $tuec='23:59:59'; $tuesday='1'; }else { $jayParsedAry = [ "Monday" => "06:00AM - 11:00PM", "Tuesday" => "12:00AM - 01:00AM, 06:00AM - 01:00AM", "Wednesday" => "06:00AM - 01:00AM", "Thursday" => "06:00AM - 01:00AM", "Friday" => "06:00AM - 01:00AM", "Saturday" => "06:00AM - 01:00AM", "Sunday" => "06:00AM - 12:00AM" ]; //$tmarrArr= json_decode($jayParsedAry, true); $tmarrP = explode('-',$jayParsedAry['Tuesday']); echo $tueo=$tmarrP[0]; //echo $tuesday='1'; echo $tuec = end($tmarrP); //echo "<pre>==tmarrP="; //print_r($tmarrP);die; } if($locahrsD['Wednesday']=='Open 24 hourss') { $wedo='00:00:00'; $wedc='23:59:59'; $wednesday='1'; }if($locahrsD['Thursday']=='Open 24 hourss') { $thuo='00:00:00'; $thuc='23:59:59'; $thursday='1'; }if($locahrsD['Friday']=='Open 24 hourss') { $frio='00:00:00'; $fric='23:59:59'; $friday='1'; }if($locahrsD['Saturday']=='Open 24 hourss') { $sato='00:00:00'; $satc='23:59:59'; $saturday='1'; }if($locahrsD['Monday11']=='Open 24 hourss') { $suno='00:00:00'; $sunc='23:59:59'; } echo "<pre>hrs";print_r($locahrsD); $mm_cuisines = $csvArrs['Cuisines']; $mm_cuisines= str_replace( array( "'",'"' ),'',$mm_cuisines); $mm_zipcode = $csvArrs['Zipcode']; $mm_latitude= $csvArrs['Latitude']; $mm_longitude = $csvArrs['Longitude']; /*$price=$csvArrs['price']; $brand_name=$csvArrs['brand_name']; $item_name=mysqli_real_escape_string($GLOBALS['conn'],$csvArrs['item_name']); $cost_unit=$csvArrs['cost_unit']; $size=$csvArrs['size']; $size_uom=$csvArrs['size_uom']; $balance_on_hand=$csvArrs['balance_on_hand']; $available=$csvArrs['available']; $par_weight=$csvArrs['par_weight']; $department=mysqli_real_escape_string($GLOBALS['conn'],$csvArrs['department']); $aisle=mysqli_real_escape_string($GLOBALS['conn'],$csvArrs['aisle']); $item_details=mysqli_real_escape_string($GLOBALS['conn'],$csvArrs['item_details']); $remote_image_URL=$csvArrs['remote_image_URL']; $additional_images_url=$csvArrs['additional_images_url']; $createdAT = date('Y-m-d_H:i:s'); $updatedAT = date('Y-m-d_H:i:s'); $catIdSql = $obj->query("SELECT id,parent_id,maincategory FROM `tbl_maincategory` WHERE `maincategory` LIKE '$department'"); $catIdArr=$obj->fetchNextObject($catIdSql); $mainCategory =$catIdArr->id; $subcatIdSql = $obj->query("SELECT id,parent_id,maincategory FROM `tbl_maincategory` WHERE `maincategory` LIKE '$aisle'"); $subcatIdArr=$obj->fetchNextObject($subcatIdSql); $subCategory =$subcatIdArr->id; $storeIdStr = explode('-',$store_code); $storeId = $storeIdStr[1];*/ //echo "<pre>==ff="; //print_r($catIdArr); //print_r($subcatIdArr); //die; //echo "<pre>==ff="; //print_r($csvArr); $chkStrSql = $obj->query("SELECT storeid,mm_store_id,uid, status FROM `stores_bkp41824` WHERE `mm_store_id` LIKE '$mm_store_id'"); $chkStrSqlArr=$obj->fetchNextObject($chkStrSql); $chkMStoreId =$chkStrSqlArr->mm_store_id; if($cntCsvArr > 0 && $mm_store_id !="" ) { if($mm_store_id !=$chkMStoreId) { echo $insSql = "INSERT INTO stores_bkp41824 set sectionid='39', storename ='$store_identifier',storeaddress='$storeaddress',state='$state' ,city='$city' ,mm_store_id='$mm_store_id',store_mme_flg='1',mm_cuisines='$mm_cuisines',mm_zipcode='$mm_zipcode',mm_latitude='$mm_latitude',mm_longitude='$mm_longitude' ,storetype='$mm_cuisines',in_stock='1',h1_food='$mm_cuisines', status=1,store_icon_url='$store_icon_url',store_food_photo_url='$store_food_photo_url' "; $obj->query($insSql); $mmStoreInsertId = $obj->lastInsertedId(); $insZipcodeSql = "INSERT INTO tbl_store_zip_180424 set sectionid='39', storeid ='$mmStoreInsertId',zip_area='Local',state='$state' ,city='$city' ,zip='$mm_zipcode',mm_latitude='$mm_latitude',mm_longitude='$mm_longitude',short_description='$mm_cuisines',zone=1,minimum='10' ,zone_status=1,store_status=1,status=1 "; $obj->query($insZipcodeSql); $insZipcodeSqlH = "INSERT INTO store_delivery_180424 set storeid ='$mmStoreInsertId',sunday='$sunday',monday='$monday' ,tuesday='$tuesday' ,wednesday='$wednesday',thursday='$thursday',friday='$friday',saturday='$saturday',suno='$suno',mono='$mono' ,tueo='$tueo',wedo='$wedo',thuo='$thuo',frio='$frio',sato='$sato',sunc='$sunc',monc='$monc',tuec='$tuec',wedc='$wedc',thuc='$thuc',fric='$thuc',satc='$satc' "; $obj->query($insZipcodeSqlH); } } //die; } //die; $_SESSION['sess_msg'] = "File processed successfully!".'<br>'; header("location:upload_ff_to_ubr.php"); exit; //echo "<pre>==ff="; //print_r($csvArr); //die; } else { $_SESSION['sess_msg'] = "Invalid csv file.Please upload valid csv file!".'<br>'; header("location:upload_ff_to_ubr.php"); exit; } } function removeLineBreakSpaces($str) { $string = trim(preg_replace('/\s\s+/', ' ', $str)); return $string; } 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; } function mmStoreLookup() { // Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.mealme.ai/utils/store_lookup/v2?store_ids=d1333fba-7c73-48bf-b73e-d52aae6e70f1&use_new_db=true'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); $headers = array(); $headers[] = 'Id-Token: quicklly:b062cd2f-df38-4653-91b9-d5e482d5f150'; $headers[] = 'Accept: application/json'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); $responseArr = json_decode($result, true); return $responseArr; } ?> <!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: Upload Feed To Instacart </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>Store identifier (For ex FRFRM-118) :</strong></td> <td align="left" class="paddBot11"> <input type="text" name="store_code" id="store_code" size="50" > </td> </tr> <tr> <td align="right" class="paddBot11 paddRt14"><strong>Upload Feed File Csv:</strong></td> <td align="left" class="paddBot11"><input name="csv_file" type="file" /><br/> <?php if(is_file("../upload_images/category/".$result->photo)) {?> <img src="../upload_images/category/<?php echo $result->photo; ?>" width="100" height="100" /> <?php } ?> </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>