View file File name : vm_ff_to_xm_categoryfilter-mapping.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='Category_list_for_ordering_sequence.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);die; $cntCsvArr = count($csvArr); //move_uploaded_file($_FILES["csv_file"]["tmp_name"], "ubr_inventory/in_files/" . $destination_file); foreach($csvArr as $csvArrs) { $strid=$csvArrs['RefId']; $Sequence=removeLineBreakSpaces($csvArrs['Sequence_']); $category=removeLineBreakSpaces($csvArrs['category']); //die; if($cntCsvArr > 0 && $strid !="" ) { //if($mm_store_id !=$chkMStoreId) { $insZipcodeSql = "update `tbl_maincategory` set sort_order='$Sequence' WHERE section_id=39 and id ='$strid' "; $obj->query($insZipcodeSql); //} } //die; } //die; $_SESSION['sess_msg'] = "File processed successfullyzmp!".'<br>'; header("location:vm_ff_to_xm_categoryfilter-mapping.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_categoryfilter-mapping.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>