View file File name : export-shef-orders.php Content :<?php include("../include/config.php"); include("../include/functions.php"); if($_REQUEST['exportExcel']=='yes'){ $where=''; if($_REQUEST['zipcode']!=''){ $name=$_REQUEST['zipcode']; $where.=" and zipcode='".$name."'"; } if($_REQUEST['storename']!=''){ $name=$_REQUEST['storename']; $where.=" and shefId like '%$name%' "; } if($_REQUEST['search_email']!=''){ $name=$_REQUEST['search_email'] ; $where.=" and email like '%$name%' "; } if($_REQUEST['order_via']!=''){ $name=$_REQUEST['order_via'] ; $where.=" and order_via='".$name."'"; } if($_REQUEST['search_from_date']!='' && $_REQUEST['search_to_date']!=''){ $where.=" and created_on>='".$_REQUEST['search_from_date']."' and created_on<='".$_REQUEST['search_to_date']."' "; } $order_by='id'; $order_by2=' desc '; $sql=$obj->Query("SELECT * FROM shef_checkout where 1=1 $where order by $order_by $order_by2",$debug=-1); $csvData=''; $csvData.="Order Date, Email,User Name, Zipcode, Shef id, Delivery Date, Order Via, Product Info"; $csvData.="\n"; $reccnt=$obj->numRows($sql); if($reccnt>0){ $count=1; while($data=$obj->fetchNextObject($sql)) { $productdetails=''; $pp=json_decode($data->prodsJson,true); if(count($pp)>0){ foreach($pp as $value) { $productdetails.='Itemid: '.$value['foodItemId'].' Qty: '.$value['quantity'].' - '; } } $productdetails=rtrim($productdetails, " - "); $csvData.=date('d/m/Y',strtotime($data->created_on)).","; $csvData.=stripslashes($data->email).","; $csvData.=stripslashes($data->fname).","; $csvData.=stripslashes($data->zipcode).","; $csvData.=stripslashes($data->shefId).","; $csvData.=stripslashes($data->deliveryDate).","; $csvData.=stripslashes($data->order_via).","; $csvData.="$productdetails"; $csvData.="\n"; $count++; } } header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/csv"); header("Content-Disposition: attachment; filename=Shef-Order-Report-".date("dMY_H:i").".csv"); echo $csvData; exit; header("location:".$_SERVER['HTTP_REFERER']); exit(); } ?>