View file File name : vm_ff_to_xm_live_data_vzip_chi_111180.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 $_REQUEST['submitForm']=='yes'; if($_REQUEST['submitForm']=='yes'){ 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='NJ_Restaurants3miles.csv'; //$destination_file = "/ubr_inventory/in_files/".$storagename; //move_uploaded_file($target_file,$destination_file); $target_file = $destination_file; $store_code = $_REQUEST['store_code']; $csvArr = parse_csv_file($target_file); echo "<pre>==csvArr="; print_r($csvArr); $cntCsvArr = count($csvArr); //move_uploaded_file($_FILES["csv_file"]["tmp_name"], "ubr_inventory/in_files/" . $destination_file); foreach($csvArr as $csvArrs) { $lookup_code=$csvArrs['lookup_code']; $zipMappedLs=removeLineBreakSpaces($csvArrs['Zip_Codes_To_Add']); $zipMappedLstAr= explode(', ',$zipMappedLs); echo "zipMappedLstAr==".$zipMappedLstAr['0']; print_r($zipMappedLstAr); $mm_cuisines = $csvArrs['Cuisines']; $mm_cuisines= str_replace( array( "'",'"' ),' ',$mm_cuisines); $mm_cuisines= str_replace(',',', ',$mm_cuisines); echo $mm_zipcode = $csvArrs['Zipcode']; $mm_latitude= $csvArrs['Latitude']; $mm_longitude = $csvArrs['Longitude']; $mm_country = $csvArrs['Country']; echo "mm_store_id=".$mm_store_id = $csvArrs['Store_ID']; //$storeMinOrderFee = mmStoreMinimumOrderFee($mm_store_id,$mm_latitude,$mm_longitude,$streetNum,$streetName,$city,$state,$mm_zipcode,$mm_country); echo "<pre>==hervkchk="; $minimum_special= $storeMinOrderFee['quote']['order_minimum']; echo $minimum_special=number_format(($minimum_special /100), 2); $minimum = $storeMinOrderFee['quote']['small_order_fee']['minimum_order_value']; echo $minimum = number_format(($minimum /100), 2); $zip_minimum = $storeMinOrderFee['quote']['small_order_fee']['minimum_order_value']; echo $zip_minimum = 15; if($storeMinOrderFee['quote']['small_order_fee']['small_order_fee_flat'] >0 ){ echo $delivery_fees_type='amount'; echo $zip_minimum_fee = $storeMinOrderFee['quote']['small_order_fee']['small_order_fee_flat']; }else{ echo $delivery_fees_type='percentage'; echo $zip_minimum_fee = $storeMinOrderFee['quote']['small_order_fee']['small_order_fee_percent']; } echo $zip_minimum_fee=number_format(($zip_minimum_fee /100), 2); $zip_minimum_fee='2.99'; //die; //echo "<pre>==storeMinOrderFee="; //print_r($storeMinOrderFee); //print_r($csvArr); $store_slug = str_replace(' ', '-', $slug); $storeaddress= $csvArrs['Street_Address']; $storeaddress= str_replace( array( "'",'"' ),'',$storeaddress); $state = $csvArrs['State']; $city =$csvArrs['City']; $mm_store_id = $csvArrs['Store_ID']; $chkStrSql = $obj->query("SELECT storeid,mm_store_id,uid, status,mm_zipcode,storename,mm_cuisines FROM `stores` WHERE `mm_zipcode` LIKE '$mm_zipcode' and mm_store_id='$mm_store_id' AND sectionid=39 "); $chkStrSqlZiMapArr=$obj->fetchNextObject($chkStrSql); $chkMStoreId =$chkStrSqlZiMapArr->mm_store_id; $pickup =$chkStrSqlZiMapArr->pickup; $delivery =$chkStrSqlZiMapArr->delivery; $mappedZiptoreId =$chkStrSqlZiMapArr->storeid; $chkMStoreMappZip =$chkStrSqlZiMapArr->mm_zipcode; echo "chkStrSqlZiMapArr==".print_r($chkStrSqlZiMapArr); echo "zipMappedLstAr==". print_r($zipMappedLstAr); //$mm_cuisines=$chkStrSqlZiMapArr->mm_cuisines; echo $insUdSql = "update tbl_store_zip set short_description='$mm_cuisines' WHERE sectionid=39 AND storeid ='$mappedZiptoreId' and `zip` LIKE '$mm_zipcode'"; $obj->query($insUdSql); foreach($zipMappedLstAr as $key=>$val) { $threeRd_zip =$val; if($mm_zipcode !=$threeRd_zip){ $zip_minimum=15; $zip_minimum_fee=2.99; $delivery_fees_type='percentage'; $threeRd_zip =$val; $hike='-1.5'; $insZipcodeSql = "INSERT INTO tbl_store_zip set sectionid='39', storeid ='$mappedZiptoreId',zip_area='Local',state='$state' ,city='$city',zip_str='$threeRd_zip' ,zip='$threeRd_zip',mm_latitude='$mm_latitude',mm_longitude='$mm_longitude',short_description='$mm_cuisines',zone=1,delivery='1',pickup='1' ,zone_status=1,store_status=1,status=1,minimum ='$zip_minimum',minimum_fee='$zip_minimum_fee',delivery_fees_type= '$delivery_fees_type', hike='$hike' "; $obj->query($insZipcodeSql); } } echo "<pre>==mm_store_id=".$mm_zipcode; print_r($chkStrSqlZiMapArr); //die; //die; if($cntCsvArr > 0 && $mm_store_id !="" && $mm_zipcode!="" ) { //if($mm_store_id !=$chkMStoreId) { /*$insZipcodeSql = "INSERT INTO tbl_store_zip_map set sectionid='39', storeid ='$mm_store_id',zip_area='Local',state='$state' ,city='$city' ,zip='$mm_zipcode',mm_latitude='$mm_latitude',mm_longitude='$mm_longitude',short_description='$mm_cuisines',zone=1 ,zone_status=1,store_status=1,status=1,minimum ='$zip_minimum',minimum_fee='$zip_minimum_fee',delivery_fees_type= '$delivery_fees_type',delivery=1";*/ //$obj->query($insZipcodeSql); //} } //die; } //die; $_SESSION['sess_msg'] = "File processed successfullyzmp!".'<br>'; header("location:vm_ff_to_xm_live_data_vzip_chi_111180.php"); exit; //echo "<pre>==ff="; //print_r($csvArr); //die; } else { $_SESSION['sess_msg'] = "Invalid csv file.Please upload valid csv file!".'<br>'; header("location:vm_ff_to_xm_live_data_vzip_chi_111180.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($mm_store_id) { //$mm_store_id = 'd1333fba-7c73-48bf-b73e-d52aae6e70f1'; //sample store for test $apiEndPoint = 'https://api.mealme.ai/utils/store_lookup/v2?store_ids='.$mm_store_id.'&use_new_db=true'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiEndPoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); $headers = array(); //$headers[] = 'Id-Token: quicklly:b062cd2f-df38-4653-91b9-d5e482d5f150'; $headers[] ='Id-Token: quicklly:3de9cc21-56bb-46ba-b75e-adb7ddb1f82d'; $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; } function mmStoreLookup2() { // 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; } function mmStoreMinimumOrderFee_needFix($mm_store_id,$userLatitude,$userLongitude,$streetNum,$streetName,$city,$state,$zipcode,$country) { $mm_store_id = 'd1333fba-7c73-48bf-b73e-d52aae6e70f1'; $userLatitude='37.78886413'; $userLongitude='-122.40139771'; $streetNum='609'; $streetName='Market St'; $city='San Francisco'; $state='CA'; $zipcode='94105'; $country='US'; $apiUrl = 'https://api.mealme.ai/details/inventory?store_id='.$mm_store_id; $apiUrl .='&pickup=true&include_quote=true"e_preference=first_available&include_customizations=true&budget=20'; $apiUrl .='&user_latitude='.$userLatitude.'&user_longitude='.$userLongitude; $apiUrl .='&user_street_num='.$streetNum.'&user_street_name='.$streetName.'&user_city='.$city.'&user_state='.$state.'&user_zipcode='.$zipcode.'&user_country='.$country; $apiUrl .='&image_height=300&image_width=300&available=true&include_fees=true&include_menu=false&use_new_db=true'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); /*curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Id-Token: quicklly:b062cd2f-df38-4653-91b9-d5e482d5f150', 'accept: application/json', ]);*/ curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Id-Token: quicklly:3de9cc21-56bb-46ba-b75e-adb7ddb1f82d', 'accept: application/json', ]); $response = curl_exec($ch); curl_close($ch); $responseArr = json_decode($response, true); echo "<pre>==";print_r($responseArr);die; return $responseArr; } function mmStoreMinimumOrderFee($mm_store_id,$userLatitude,$userLongitude,$streetNum,$streetName,$city,$state,$zipcode,$country) { /*$mm_store_id = 'ceda3b9a-5d10-495e-8fd3-48217a921ffd'; $userLatitude='41.90010833'; $userLongitude='-87.68729401'; $streetNum='1022'; $streetName='North Western Avenue'; $city='Chicago'; $state='IL'; $zipcode='60622'; $country='US';*/ $userLatitude=urlencode ($userLatitude); $userLongitude=urlencode ($userLongitude); $streetNum=urlencode ($streetNum); $streetName=urlencode ($streetName); $city=urlencode ($city); $state=urlencode ($state); $zipcode=urlencode ($zipcode); $country=urlencode ($country); $mstoreURL = "https://api.mealme.ai/details/inventory?store_id=d1333fba-7c73-48bf-b73e-d52aae6e70f1&pickup=true&include_quote=true"e_preference=first_available&include_customizations=true&budget=20&user_latitude=37.7786357&user_longitude=-122.3918135&user_street_num=188&user_street_name=King%20Street&user_city=San%20Francisco&user_state=CA&user_zipcode=94107&user_country=US&image_height=300&image_width=300&available=true&include_fees=true&include_menu=false&use_new_db=true"; $mstoreURLtst ="https://api.mealme.ai/details/inventory?store_id=ceda3b9a-5d10-495e-8fd3-48217a921ffd&pickup=false&include_quote=true"e_preference=first_available&include_customizations=true&budget=20&user_latitude=41.90010833&user_longitude=-87.68729401&user_street_num=1022&user_street_name=North%20Western%20Avenue&user_city=Chicago&user_state=IL&user_zipcode=60622&user_country=US&image_height=300&image_width=300&available=true&include_fees=true&include_menu=true&use_new_db=true"; $mstoreURL2 = "https://api.mealme.ai/details/inventory?store_id=$mm_store_id&pickup=false&include_quote=true"e_preference=first_available&include_customizations=true&budget=20"; $mstoreURL2 .="&user_latitude=$userLatitude&user_longitude=$userLongitude"; $mstoreURL2 .="&user_street_num=$streetNum&user_street_name=$streetName&user_city=$city&user_state=$state&user_zipcode=$zipcode&user_country=$country"; $mstoreURL2 .="&image_height=300&image_width=300&available=true&include_fees=true&include_menu=false&use_new_db=true"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $mstoreURL2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); /*curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Id-Token: quicklly:b062cd2f-df38-4653-91b9-d5e482d5f150', 'accept: application/json', ]);*/ curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Id-Token: quicklly:3de9cc21-56bb-46ba-b75e-adb7ddb1f82d', 'accept: application/json', ]); $response = curl_exec($ch); curl_close($ch); $responseArr = json_decode($response, true); //echo "<pre>hervk==";print_r($responseArr);die; 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>Upload Feed File Csv:</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>