View file File name : vm_ff_to_xm_live_data_prod.php Content :<?php session_start(); include("../include/config.php"); include("../include/functions.php"); include("../include/simpleimage.php"); 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); echo "target_file==".$target_file = $_FILES['csv_file']['tmp_name']; $store_code = $_REQUEST['store_code']; $csvArr = parse_csv_file($target_file); echo "<pre>==csvArr11="; //print_r($csvArr); $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); /*$store_identifier= str_replace( array( "'",'"' ),'',$store_identifier); $slug= strtolower($store_identifier); echo $store_slug = str_replace(' ', '-', $slug);*/ $slug = sanitize_slug($store_identifier); $store_nmsl= str_replace( array( "'",'"' ),'',$slug); $slug= strtolower($store_nmsl); echo $store_slug = str_replace(' ', '-', $slug); //slug fixes $strName=removeLineBreakSpaces($csvArrs['Name']); $slug = sanitize_slug($strName); $storeaddress= $csvArrs['Street_Address']; $storeaddress= str_replace( array( "'",'"' ),'',$storeaddress); $state = $csvArrs['State']; $city =$csvArrs['City']; echo $mm_store_id = $csvArrs['Store_ID']; $tmpAddrs = explode(' ',$storeaddress); $streetNum=$tmpAddrs[0]; $streetName=$tmpAddrs[1].' '.$tmpAddrs[2].' '.$tmpAddrs[3].' '.$tmpAddrs[4].' '.$tmpAddrs[5]; //$straddr = preg_replace('/[^0-9]/', '', $storeaddress); echo "<pre>==fflookup="; // print_r($tmpAddrs); $pickup_enabled = 0; $delivery_enabled = 0; $mmStroeLkp = mmStoreLookup($mm_store_id); //echo "<pre>==mmStoreLookup="; //print_r($mmStroeLkp); $phoneNo = $mmStroeLkp['stores'][0]['phone_number']; $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']; $pickup_enabled=$mmStroeLkp['stores'][0]['pickup_enabled']; $delivery_enabled=$mmStroeLkp['stores'][0]['delivery_enabled']; if($pickup_enabled==1) { $pickup_enabled=1; } if($delivery_enabled==1) { $delivery_enabled=1; } echo $locahrsD['Monday']; if($locahrsD['Sunday']=='Open 24 hours') { $suno='00:00:00'; $sunc='23:59:59'; $sunday='1'; }else { $tmarrP = explode('-',$locahrsD['Sunday']); echo $suno=$tmarrP[0]; $sunday='1'; echo $sunc = end($tmarrP); } if($locahrsD['Monday']=='Open 24 hours') { $mono='00:00:00'; $monc='23:59:59'; $monday='1'; }else { $tmarrP = explode('-',$locahrsD['Monday']); echo $mono=$tmarrP[0]; $monday='1'; echo $monc = end($tmarrP); } if($locahrsD['Tuesday']=='Open 24 hours') { $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); //$locahrsD['Tuesday'] ="12:00AM - 01:00AM, 06:00AM - 01:00AM"; $tmarrP = explode('-',$locahrsD['Tuesday']); echo $tueo=$tmarrP[0]; //echo $tuesday='1'; $tuesday='1'; echo $tuec = end($tmarrP); //echo "<pre>==tmarrP="; //print_r($tmarrP);die; } if($locahrsD['Wednesday']=='Open 24 hours') { $wedo='00:00:00'; $wedc='23:59:59'; $wednesday='1'; }else { $tmarrP = explode('-',$locahrsD['Wednesday']); echo $wedo=$tmarrP[0]; $wednesday='1'; echo $wedc = end($tmarrP); } if($locahrsD['Thursday']=='Open 24 hours') { $thuo='00:00:00'; $thuc='23:59:59'; $thursday='1'; }else { $tmarrP = explode('-',$locahrsD['Thursday']); echo $thuo=$tmarrP[0]; $thursday='1'; echo $thuc = end($tmarrP); } if($locahrsD['Friday']=='Open 24 hours') { $frio='00:00:00'; $fric='23:59:59'; $friday='1'; }else { $tmarrP = explode('-',$locahrsD['Friday']); echo $frio=$tmarrP[0]; $friday='1'; echo $fric = end($tmarrP); } if($locahrsD['Saturday']=='Open 24 hours') { $sato='00:00:00'; $satc='23:59:59'; $saturday='1'; }else { $tmarrP = explode('-',$locahrsD['Saturday']); echo $sato=$tmarrP[0]; $saturday='1'; echo $satc = end($tmarrP); } //$mm_cuisines = $csvArrs['Cuisines']; //$mm_cuisines= str_replace( array( "'",'"' ),'',$mm_cuisines); $mm_cuisines = $csvArrs['Cuisines']; $mm_cuisines= str_replace( array( "'",'"' ),' ',$mm_cuisines); $mm_cuisines= str_replace(',',',',$mm_cuisines); //$mm_cuisines= str_replace(',',', ',$mm_cuisines); $mm_zipcode = $csvArrs['Zipcode']; $mm_latitude= $csvArrs['Latitude']; $mm_longitude = $csvArrs['Longitude']; $mm_country = $csvArrs['Country']; $storeaddress =$storeaddress.", ". $city.", ". $state.", ". $mm_zipcode.", ".$mm_country; //$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']; $minimum_special=number_format(($minimum_special /100), 2); $minimum = $storeMinOrderFee['quote']['small_order_fee']['minimum_order_value']; $minimum = number_format(($minimum /100), 2); $zip_minimum = $storeMinOrderFee['quote']['small_order_fee']['minimum_order_value']; $zip_minimum = number_format(($zip_minimum /100), 2); if($storeMinOrderFee['quote']['small_order_fee']['small_order_fee_flat'] >0 ){ $delivery_fees_type='amount'; $zip_minimum_fee = $storeMinOrderFee['quote']['small_order_fee']['small_order_fee_flat']; }else{ $delivery_fees_type='percentage'; $zip_minimum_fee = $storeMinOrderFee['quote']['small_order_fee']['small_order_fee_percent']; } $zip_minimum_fee=number_format(($zip_minimum_fee /100), 2); //die; //echo "<pre>==storeMinOrderFee="; //print_r($storeMinOrderFee); //print_r($csvArr); $chkStrSql = $obj->query("SELECT storeid,mm_store_id,uid, status FROM `stores` WHERE `mm_store_id` LIKE '$mm_store_id'"); $chkStrSqlArr=$obj->fetchNextObject($chkStrSql); $chkMStoreId =$chkStrSqlArr->mm_store_id; $minimum_special = 2.99; $minimum = 15; $zip_minimum=15; $zip_minimum_fee=2.99; $hike = 1.5; if($cntCsvArr > 0 && $mm_store_id !="" ) { if($mm_store_id !=$chkMStoreId) { echo $insSql = "INSERT INTO stores set sectionid='39', storename ='$store_identifier',phone='$phoneNo', 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=0,store_icon_url='$store_icon_url',store_food_photo_url='$store_food_photo_url', street_num='$streetNum', street_name='$streetName',str_country='$mm_country',minimum_special ='$minimum_special',minimum ='$minimum' ,slug= '$store_slug' "; $obj->query($insSql); $mmStoreInsertId = $obj->lastInsertedId(); $insZipcodeSql = "INSERT INTO tbl_store_zip 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,hike='$hike' ,zone_status=1,store_status=1,status=1,minimum ='$zip_minimum',minimum_fee='$zip_minimum_fee',delivery_fees_type= '$delivery_fees_type',delivery='$delivery_enabled',pickup='$pickup_enabled' "; $obj->query($insZipcodeSql); $insZipcodeSqlH = "INSERT INTO store_delivery 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); } else { echo $insUdSql = "update stores 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', street_num='$streetNum', street_name='$streetName',str_country='$mm_country',minimum_special ='$minimum_special',minimum ='$minimum' ,slug= '$store_slug', phone='$$phoneNo' where mm_store_id='$mm_store_id' "; //$obj->query($insUdSql); } } //die; } //die; $_SESSION['sess_msg'] = "File processed successfully!".'<br>'; header("location:vm_ff_to_xm_live_data_prod.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_prod.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; } function sanitize_slug($text) { $text = preg_replace('/[^A-Za-z0-9-]+/', '-', $text); $text = trim($text, '-'); $text = preg_replace('~-+~', '-', $text); return strtolower($text); } function hkperc($prcAmt){ $percentage=15; $new_width_ch = ($percentage / 100) * $prcAmt; $totalWidthFnf = $prcAmt+$new_width_ch; return $totalWidthFnf3 = round($totalWidthFnf, 2); } ?> <!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 Store Csv </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 Csv 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>