AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.216.139
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/www/lrsys_projetos/sopizzas/application/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_projetos/sopizzas/application/controllers/frontend.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
// require_once APPPATH.'libraries/facebook/facebook.php';
require_once APPPATH.'libraries/Facebook/autoload.php';

class Frontend extends CI_Controller {

  function __construct()
  {
     parent::__construct();
     $this->load->helper("url");
     $this->load->helper('form');
     $this->load->library('session');
     $this->load->model('frontend_model');
     $this->load->library('form_validation');
     $this->load->model('user','',TRUE);
     $this->load->model('dashboard_model');
     $session_data = $this->session->userdata('logged_in');
     $this->load->library('session');  //Load the Session 
    $this->config->load('facebook'); //Load the facebook.php file which is located in config directory
    $this->load->library('myemail');
    if($this->session->userdata('user_language'))
    {
      $language = $this->session->userdata('user_language');
    }
    else
    {
      $language = $this->config->item("language");
    }
    $data['user_language'] =  $language;
    $this->lang->load('frontpage', $language);
  }
  //if(empty($session_data)) { redirect('login', 'refresh'); }

  function index( $offset = 0 )
  {
    $data['random_restaurant'] = $this->frontend_model->random_restaurant();
    $data['popular_locality'] = $this->frontend_model->popular_locality();
    $data['top_restaurant'] = $this->frontend_model->top_restaurant();
    $data['feature_restaurant'] = $this->frontend_model->top_restaurant();
    $data['feature_restaurant_fav'] = $this->frontend_model->feature_restaurant();
    $data['populer_cuisine']    = $this->frontend_model->populer_cuisine();
    $query['StateList'] =$this->dashboard_model->StateList();
    //$feature_restaurant = $this->frontend_model->feature_restaurant();

    $data['page'] = 'index';
    if($this->session->userdata('user_language'))
    {
      $language = $this->session->userdata('user_language');
    }
    else
    {
      $language = $this->config->item("language");
    }
    $data['user_language'] =  $language;
    $this->lang->load('frontpage', $language);
    $this->load->view('frontend/header_index');
    $this->load->view('frontend/index', $data);
    $this->load->view('frontend/footer');

    //$data['page'] = 'index';
    //$this->load->view('frontend/home', $data);
  }

  function trackOrder() {
    $orderid = $this->input->post('orderid');
    $result = $this->frontend_model->orderStatus($orderid);
    if ($result) {
      if (strtolower($result->status) == 'in preparation') {
        $msg = 'Your order is <strong>'.$result->status.'!</strong>';
        $type = 'info';
      }
      else if (strtolower($result->status) == 'out for delivery') {
        $msg = 'Your order is <strong>'.$result->status.'!</strong>';
        $type = 'warning';
      }
      else if (strtolower($result->status) == 'delivered') {
        $msg = 'Your order is <strong>'.$result->status.'!</strong>';
        $type = 'success';
      }
      else if (strtolower($result->status) == 'canceled') {
        $msg = 'Your order is <strong>'.$result->status.'!</strong>';
        $type = 'danger';
      }
      else {
        $msg = '<strong>Order id does not exist!<strong>';
        $type = 'danger';
      }
    }
    else {
      $msg = '<strong>Order id does not exist!<strong>';
      $type = 'danger';
    }
    $data['msg'] = $msg;
    $data['type'] = $type;
    echo json_encode($data);
  }
  public function checkdataUniquesness()
  {
    $input_data=array();
    $input_data = $this->input->post();
    $con_array=array();
    if($input_data['txt']=='email'){
      $con_array['diver_email']=$input_data['inputtxt'];
    }

    $chk_email_existancequery=$this->userdata->chk_email_existance($con_array);
    if($chk_email_existancequery==0){
      if($input_data['txt']=='email'){
        $pattern = "/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i";
        if(!preg_match($pattern,$con_array['diver_email']))  {
          echo "1";
        }
        else {
          echo "0";
        }
      }
      else {
        echo "0";
      }
    }
    else {
      echo "1";
    }
  }



  function about_us()
  {
    $data['about_us'] = $this->frontend_model->cms_data($content_id=1);

    $data['page'] = 'index';
    $data['title'] = $data['about_us']['content_title'];
    $data['keywords'] = $data['about_us']['metatagkeyword'];
    $data['description'] = $data['about_us']['metatagkeyword'];

    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/about_us');
    $this->load->view('frontend/footer');

  }


  function privacy_policy()
  {
    $data['privacy_policy'] = $this->frontend_model->cms_data($content_id=2);

    $data['page'] = 'index';
    $data['title'] = $data['privacy_policy']['content_title'];
    $data['keywords'] = $data['privacy_policy']['metatagkeyword'];
    $data['description'] = $data['privacy_policy']['metatagkeyword'];
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/privacy_policy');
    $this->load->view('frontend/footer');
  }

  function terms()
  {
    $data['terms'] = $this->frontend_model->cms_data($content_id=4);

    $data['page'] = 'index';
    $data['title'] = $data['terms']['content_title'];
    $data['keywords'] = $data['terms']['metatagkeyword'];
    $data['description'] = $data['terms']['metatagkeyword'];
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/terms');
    $this->load->view('frontend/footer');
  }

  function how_to_order()
  {
    $data['how_to_order'] = $this->frontend_model->cms_data($content_id=15);

    $data['page'] = 'index';
    $data['title'] = $data['how_to_order']['content_title'];
    $data['keywords'] = $data['how_to_order']['metatagkeyword'];
    $data['description'] = $data['how_to_order']['metatagkeyword'];
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/how_to_order');
    $this->load->view('frontend/footer');
  }

function help()
  {
    $data['help'] = $this->frontend_model->cms_data($content_id=23);

    $data['page'] = 'index';
    $data['title'] = $data['help']['content_title'];
    $data['keywords'] = $data['help']['metatagkeyword'];
    $data['description'] = $data['help']['metatagkeyword'];
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/help');
    $this->load->view('frontend/footer');
  }


  function faq()
  {
    //$data['faq'] = $this->frontend_model->cms_data($content_id=5);
    $data['faq'] = $this->frontend_model->faq_data();
    $data['page'] = 'index';
    $data['title'] = 'FAQ';
    $data['keywords'] = 'FAQ';
    $data['description'] = 'FAQ';
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/faq');
    $this->load->view('frontend/footer');
  }
function faqApplication()
{
    //$data['faq'] = $this->frontend_model->cms_data($content_id=5);
    $data['faq'] = $this->frontend_model->faq_data();
    $data['page'] = 'appFAQ';
    $data['title'] = 'FAQ';
    $data['keywords'] = 'FAQ';
    $data['description'] = 'FAQ';
    $this->load->view('frontend/faq', $data);
}

  function how_it_works()
  {
    //$data['how_to_order'] = $this->frontend_model->cms_data($content_id=15);

    $data['page'] = 'index';
    $data['title'] = $data['how_it_work']['content_title'];
    $data['keywords'] = $data['how_it_work']['metatagkeyword'];
    $data['description'] = $data['how_it_work']['metatagkeyword'];
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/howitworks');
    $this->load->view('frontend/footer');
  }

  function services()
  {
    $data['services'] = $this->frontend_model->cms_data($content_id=25);

    $data['page'] = 'index';
    $data['title'] = $data['services']['content_title'];
    $data['keywords'] = $data['services']['metatagkeyword'];
    $data['description'] = $data['services']['metatagkeyword'];
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/services');
    $this->load->view('frontend/footer');
  }


  function feellikeeating()
  {
    $data['feellikeeating'] = $this->frontend_model->cms_data($content_id=26);

    $data['page'] = 'index';
    $data['title'] = $data['feellikeeating']['content_title'];
    $data['keywords'] = $data['feellikeeating']['metatagkeyword'];
    $data['description'] = $data['feellikeeating']['metatagkeyword'];
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/feellikeeating');
    $this->load->view('frontend/footer');
  }


function login()
{

    $session_data = $this->session->userdata('logged_in_customer');
    if($session_data) { redirect('customeradmin', 'refresh'); }

    $cookieData = $this->input->cookie('remember_me_token_customer');
    $cookieDataPass = $this->input->cookie('remember_me_token_customer_pass');
    $data['username'] = '';
    $data['password'] = '';
    $data['ischecked'] = '';


      if ($cookieData != "") {
      $result = $this->user->login_cookie_customer($cookieData);
      if($result)
      {
        $sess_array = array();
        foreach($result as $row)
        {

        $data['username'] = $row->customer_email;
        $data['password'] = $cookieDataPass;
        $data['ischecked'] = 'checked';

        }
      }
    }
    $data['requestPage']='';
    $data['page'] = 'index';
    $data['title'] = '';
    $data['keywords'] = '';
    $data['description'] = '';
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/login');
    $this->load->view('frontend/footer');


}
  function customerLogin($verify_code = '') {
    if ($verify_code != '') {
      $this->db->select('customer_email');
      $this->db->from('rt_customer');
      $this->db->where('customer_validate_id', $verify_code);
      $query = $this->db->get();
      if ($query->num_rows() > 0) {
        $data['username'] = $query->row()->customer_email;
        $data['password'] = '';
        $data['ischecked'] = '';
      }
      $data['requestPage']='';
      $data['page'] = 'index';
      $data['title'] = '';
      $data['keywords'] = '';
      $data['description'] = '';
      $this->load->view('frontend/header', $data);
      $this->load->view('frontend/login');
      $this->load->view('frontend/footer');
    }
    else {
      redirect('login/');
    }
  }


function fblogin(){
    $base_url=$this->config->item('base_url');
    $facebook = new Facebook\Facebook([
      'app_id' =>  $this->config->item('appID'),
      'app_secret' => $this->config->item('appSecret'),
      'default_graph_version' => 'v2.8',
    ]);
    $helper = $facebook->getJavaScriptHelper();
    if($helper){
      try{
        $accessToken = $helper->getAccessToken();
        $response = $facebook->get('/me?fields=email,name,picture', $accessToken);  //Get the facebook user profile data
        $user_profile = $response->getGraphUser();
        // echo $user_profile['picture']['url'].'<br>';
        // echo "<img src='".$user_profile['picture']['url']."'></img>".'<br>';
        // exit();
        $result = $this->user->login_customer_fb($user_profile['id']);
        $AlreadyCustomer = $this->frontend_model->customerByEmail($user_profile['email']);
        if($result)
          {
            $sess_array = array();
            foreach($result as $row)
            {
              $customer_id = $row->customer_id;
              $sess_array = array(
                'id'          => $row->customer_id,
                'is_admin'    => 1,
                'is_active'   => $row->status,
                'username'    => $row->customer_name,
                'customer_image' => '',
                'facebook_image' => $row->image,
                'fb_id'          => $row->fb_id
              );
            }
            if($sess_array['is_active']==1)
            {
              $this->session->set_userdata('logged_in_customer', $sess_array);
            }
            else {
              $this->form_validation->set_message('check_password', $this->lang->line('sorry_suspend'));
              $data['requestPage']='';
              $data['page'] = 'index';
              $data['title'] = '';
              $data['keywords'] = '';
              $data['description'] = '';
              $this->load->view('frontend/header', $data);
              $this->load->view('frontend/login');
              $this->load->view('frontend/footer');
            }
          }
          else if ($AlreadyCustomer) {
            $this->db->trans_start();
            $data_up = array(
              'fb_id' => $user_profile['id']
            );
            $this->db->where('customer_id', $AlreadyCustomer->customer_id);
            $this->db->update('rt_customer', $data_up);
            $this->db->trans_complete();
            $customer_id = $AlreadyCustomer->customer_id;
            $sess_array = array(
              'id'          => $AlreadyCustomer->customer_id,
              'is_admin'    => 1,
              'is_active'   => $AlreadyCustomer->status,
              'username'    => $AlreadyCustomer->customer_name,
              'customer_image' => '',
              'facebook_image' => $AlreadyCustomer->image,
              'fb_id'          => $AlreadyCustomer->fb_id
            );
            if($sess_array['is_active']==1) {
              $this->session->set_userdata('logged_in_customer', $sess_array);
            }
            else {
              $this->form_validation->set_message('check_password', $this->lang->line('sorry_suspend'));
              $data['requestPage']='';
              $data['page'] = 'index';
              $data['title'] = '';
              $data['keywords'] = '';
              $data['description'] = '';
              $this->load->view('frontend/header', $data);
              $this->load->view('frontend/login');
              $this->load->view('frontend/footer');
            }
          }
          else{
            // $imgpath = "https://graph.facebook.com/". $user_profile['id'] ."/picture";
            $imgpath = $user_profile['picture']['url'];
            $now = date('Y-m-d H:i:s');
            $this->db->trans_start();
            $data_in = array(
              'customer_name'       =>  $user_profile['name'],
              'fb_id'               =>  $user_profile['id'],
              'customer_email'      =>  $user_profile['email'],
              'addeddate'           => $now,
              'image'               => $imgpath
            );
            $this->db->insert('rt_customer', $data_in);
            $customer_id=$this->db->insert_id();
            $this->db->trans_complete();
              $sess_array = array(
                'id'          => $customer_id,
                'is_admin'    => 1,
                'is_active'   => 1,
                'username'    => $user_profile['name'],
                'customer_image' => '',
                'facebook_image' => $imgpath,
                'fb_id'          => $user_profile['id']
              );
              $this->session->set_userdata('logged_in_customer', $sess_array);
          }
        if ($this->cart->contents()) {
          redirect('createorderfrontend/placeOrder');
        }
        else {
          redirect(base_url().'restaurantslisting/');
        }
      }
      catch(\Facebook\Exceptions\FacebookSDKException $e){
        error_log($e);
        $user = NULL;
        // echo 'Facebook SDK returned an error: ' . $e->getMessage();
        // exit;
      }
    }
    $this->login();
  }


  function logout(){
    $base_url=$this->config->item('base_url'); //Read the baseurl from the config.php file
    $this->session->sess_destroy();  //session destroy
    $this->cart->destroy();
    header('Location: '.$base_url);  //redirect to the home page

  }


function updateLocation()
{
    $longitude = $this->input->post('long');
    $latitude = $this->input->post('lat');



    if($longitude=='')
    {
      $longitude = DEFAULT_LONG;
    }

    if($latitude=='')
    {
      $latitude = DEFAULT_LAT;
    }



    $sess_array = array(
          'longitude'   => $longitude,
          'latitude'    => $latitude
        );
    $this->session->set_userdata('customer_location', $sess_array);

    $addr = $this->getAddress($latitude, $longitude);

    echo $addr;

}


function updateAddress()
{

  $address = $this->input->post('address');
	$restaurant = $this->input->post('restaurant');
	$latitude = "32.926395";
  $longitude = "-117.207948";

	if($address!='')
      {
		  $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
		  // We convert the JSON to an array
		  $geo = json_decode($geo, true);
		  // If everything is cool
      if ($geo['status'] = 'OK') {
		  // We set our values
		  $latitude = isset($geo['results'][0]['geometry']['location']['lat'])? $geo['results'][0]['geometry']['location']['lat']: "32.926395" ;
		  $longitude = isset($geo['results'][0]['geometry']['location']['lng'])? $geo['results'][0]['geometry']['location']['lng'] : "-117.207948";

     }else{
      $latitude = "32.926395";
      $longitude = "-117.207948";
      }
	  }

    $sess_array = array(
          'longitude'   => $longitude,
          'latitude'    => $latitude
        );
    $this->session->set_userdata('customer_location', $sess_array);
    $this->session->set_userdata('search_restaurant', $restaurant);
    $this->session->set_userdata('search_location', $address);

    $addr = $this->getAddress($latitude, $longitude);

    echo $address;

}

function updateLanguage()
{
    $lang = $this->input->post('lang');
    $this->session->set_userdata('customer_location', $sess_array);
    $this->session->set_userdata('search_restaurant', $restaurant);
    $this->session->set_userdata('user_language', $lang);
    echo $lang;
}



function restaurantslisting($cuisine_id = '')
{
    $session_data = $this->session->userdata('customer_location');
    // $this->session->unset_userdata('search_location');
    /*Safety precautions start*/
    //$longitude = DEFAULT_LONG;
    //$latitude = DEFAULT_LAT;
    /*Safety precautions end*/
    if($this->session->userdata('user_language'))
    {
      $language = $this->session->userdata('user_language');
    }
    else
    {
      $language = $this->config->item("language");
    }
    $data['user_language'] =  $language;
    $this->lang->load('frontpage', $language);
    $longitude = $session_data['longitude'] == ''?DEFAULT_LONG:$session_data['longitude'];
    $latitude = $session_data['latitude'] == ''?DEFAULT_LAT:$session_data['latitude'];

    $orerby = $this->input->post('opt_order');
    $datatable ='';

    $res_list=$this->frontend_model->restaurantList($longitude,$latitude,$orerby);
    if ($this->session->userdata('search_location')) {
      $search_location = $this->session->userdata('search_location');
    }
    else {
      $search_location = '';
    }
    #echo "search_location: ".$search_location;
    $i = 0;
    if(is_array($res_list) && sizeof($res_list)>0)
    {
      $datatable ='';
        //print_r($res_list);
      $servingcuisine='';
      foreach($res_list as $key=>$row)
      {
          #echo "is Ture: ".$this->mypolygon->checkPolygon($search_location, $row->delivery_zone_1, '');
        if ($search_location !== '') {
          if($this->mypolygon->checkPolygon($search_location, $row->delivery_zone_1, '') == false && $this->mypolygon->checkPolygon($search_location, $row->delivery_zone_2, '') == false && $this->mypolygon->checkPolygon($search_location, $row->delivery_zone_3, '') == false) continue;
        }
        $i++;
        $avgRating = $this->frontend_model->avgRestaurantrating($row->restaurant_id);
        if ($this->session->userdata('logged_in_customer')) {
          $session_data = $this->session->userdata('logged_in_customer');
          $customer_id = $session_data['id'];
          $restaurant_id = $row->restaurant_id;
          $isFavourite = $this->frontend_model->isFavourite($restaurant_id, $customer_id);
          if ($isFavourite) {
            $favData = '<a href="javascript:void(0);" class="fav"><i class="fa fa-heart" aria-hidden="true" data-status="0" onclick="setFavourite('.$row->restaurant_id.', this)"></i></a>';
          }
          else {
            $favData = '<a href="javascript:void(0);" class="fav"><i class="fa fa-heart-o" aria-hidden="true" data-status="1" onclick="setFavourite('.$row->restaurant_id.', this)"></i></a>';
          }
        }
        else {
          $favData = '';
        }

       $rsclose='';
      $current_time = date('H:i A');
      $day = strtolower(date('D'));
      $isopen=0;

      $fild1 = 'restaurant_delivery_'.$day.'_opentime';
      $fild2 = 'restaurant_delivery_'.$day.'_closetime';

      //echo $fild1;
      //exit();

      $Estimated_delivery_time = $row->restaurant_estimated_time;

      $starttime1=$row->$fild1;
      $starttime3=date("H:i", strtotime($starttime1));
      $closetime1=$row->$fild2;
      $closetime3=date("H:i", strtotime($closetime1));

      if(($current_time >= $starttime3 &&  $current_time <= $closetime3) || $row->business_type == 1)
      {
        $isopen=1;
        $ordercls='<a class="vieworder" href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><button type="button"  class="btn-order">'.$this->lang->line('Order_Now').'</button></a>';
        $rsclose='<div class="restoOpen"></div><div class="offertext">'.$this->lang->line('Open_Now').'</div>';
      }

      if($isopen==0)
      {
        $ordercls='<a class="vieworder" href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><button type="button"  class="pre-order">'.$this->lang->line('View_Now').'</button></a>';
        $rsclose='<div class="restoClose"></div><div class="offertext1">'.$this->lang->line('Closed_Now').'</div>';
      }

      $user_miles = number_format($row->distance, 2, '.', '');
      $servingcuisine=$this->frontend_model->getArrayCuisinesInfo($row->restaurant_serving_cuisines);

      $cuisinePhoto=$this->frontend_model->getCuisinesPhoto($row->restaurant_serving_cuisines);

      if(isset($cuisinePhoto) && $cuisinePhoto!=''){
        $image_file_path=FCPATH.CUISINE_IMAGE_PATH_THUMBS.$cuisinePhoto;
        if (file_exists($image_file_path)) //file_exists of a url returns false.It should be real file path
           {
              $image_name_with_path=base_url().CUISINE_IMAGE_PATH_THUMBS.$cuisinePhoto;
           }
           else
           {
              $image_name_with_path=base_url().CUISINE_IMAGE_PATH_THUMBS.CUISINE_DEFAULT_IMAGE;
           }
        }else{
          $image_name_with_path=base_url().CUISINE_IMAGE_PATH_THUMBS.CUISINE_DEFAULT_IMAGE;
        }

        $businessType = '';
        if ($row->business_type == 0) {
          $businessType .= '<lable class="restaurantstat" style="display:none">'.$this->lang->line('TYPE_Restaurant').'</lable>';
        }
        else if ($row->business_type == 1) {
          $businessType .= '<lable class="catererstat" style="display:none">'.$this->lang->line('Caterer').'</lable>';
        }
      $datatable .='<div class="col-md-12 col-sm-12 col-xs-12">
                <div class="restro-box">
                    <div class="restaurant-box-inner">
                      '.$rsclose.'
                      <div class="col-md-3 col-sm-3 col-xs-12">
                        <div class="restothumb">
                          <img src="'.$image_name_with_path.'">
                        </div>
                      </div>
                      <div class="col-md-5 col-sm-5 col-xs-8 paddleft xs-gap">
                        <form>
                            <div class="star-ratings-sprite" style="float: left;margin-bottom: 10px;"><span style="width: '.$avgRating.'%" class="star-ratings-sprite-rating"></span></div>
                            <div class="clearfix"></div>
                        </form>
                        <a href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><p class="restoname">'.$row->restaurant_name.'</p></a>
                        <p class="cuisinetype"><span>'.$this->lang->line('Type_of_food').' :</span> <span>'.$servingcuisine.'</span></p>
                        <p class="deliveryloc">';
                        if ($row->restaurant_delivery == "Yes") {
                          $datatable .='<span class="deliverystat" title="Delivery"><i class="fa fa-truck" aria-hidden="true"></i></span>';
                        }
                        if ($row->restaurant_dinein == "Yes") {
                            $datatable .='<span class="deliverystat" title="Dine In"><i class="fa fa-cutlery" aria-hidden="true"></i></span>';
                        }
                        if ($row->restaurant_booktable == "Yes") {
                            $datatable .='<span class="deliverystat" title="Table Booking"><i class="fa fa-book" aria-hidden="true"></i></span>';
                        }
                        if ($row->restaurant_pickup == "Yes") {
                            $datatable .='<span class="deliverystat"  title="Pick Up"><i class="fa fa-shopping-basket" aria-hidden="true"></i></span>';
                        }
          $datatable .= $row->restaurant_city.'</p>
                      </div>
                      <div class="col-md-4 col-sm-4 col-xs-4 paddleft0">
                        '.$businessType.'
                        <div class="clearfix"></div>
                        <div class="veiwdetails">
                          '.$favData.'
                          '.$ordercls.'
                        </div>
                      </div>
                    </div>
                </div>
              </div>';

            }

          }
    if ($i == 0) {
      $datatable='<div class="col-md-12 col-sm-12 col-xs-12">
                  <lable class="findnull">'.$this->lang->line('No_result_found').'</lable>
                </div>';
    }
    $data['StateList'] =$this->dashboard_model->StateList();
    $data['CityList'] =$this->dashboard_model->GetCityByState();
    $data['CuisineList'] =$this->dashboard_model->CuisineList();
    $data['CuisineSearchId'] = $cuisine_id;

    $data['restaurant_list'] = $datatable;
    $data['page'] = 'index';
    $data['title'] = '';
    $data['keywords'] = '';
    $data['description'] = '';
    $this->load->view('frontend/header', $data);
    $this->load->view('frontend/restaurants_listing');
    $this->load->view('frontend/footer');
}

function restaurantslistingbyorder()
{
    //print_r($this->input->post());
    //exit();
    $session_data = $this->session->userdata('customer_location');
    $longitude = $session_data['longitude'] == ''?DEFAULT_LONG:$session_data['longitude'];
    $latitude = $session_data['latitude'] == ''?DEFAULT_LAT:$session_data['latitude'];

    $orerby = $this->input->post('opt_order');
    $cuisineids = $this->input->post('cuisineids');

    $opennow = $this->input->post('opennow');
    $closednow = $this->input->post('closednow');
    $freedelivery = $this->input->post('freedelivery');

	$searchnm = $this->input->post('search_nm');
  $restaurant_state = $this->input->post('restaurant_state');
  $restaurant_city  = $this->input->post('restaurant_city');
    $res_list=$this->frontend_model->restaurantList($longitude,$latitude,$orerby,$cuisineids,$searchnm,$restaurant_state,$restaurant_city);
    if ($this->session->userdata('search_location')) {
      $search_location = $this->session->userdata('search_location');
    }
    else {
      $search_location = '';
    }
    $i = 0;
    if(is_array($res_list) && sizeof($res_list)>0)
    {
      $datatable ='';

      $servingcuisine='';
      foreach($res_list as $key=>$row)
      {
        if (($row->restaurant_delivery_charge > 0 || $row->restaurant_delivery_charge_1 > 0 || $row->restaurant_delivery_charge_2 > 0) && $freedelivery == 1) {
          continue;
        }
        if ($search_location !== '') {
          if($this->mypolygon->checkPolygon($search_location, $row->delivery_zone_1, '') == false && $this->mypolygon->checkPolygon($search_location, $row->delivery_zone_2, '') == false && $this->mypolygon->checkPolygon($search_location, $row->delivery_zone_3, '') == false) continue;
        }
        // $i++;
        $avgRating = $this->frontend_model->avgRestaurantrating($row->restaurant_id);
        if ($this->session->userdata('logged_in_customer')) {
          $session_data = $this->session->userdata('logged_in_customer');
          $customer_id = $session_data['id'];
          $restaurant_id = $row->restaurant_id;
          $isFavourite = $this->frontend_model->isFavourite($restaurant_id, $customer_id);
          if ($isFavourite) {
            $favData = '<a href="javascript:void(0);" class="fav"><i class="fa fa-heart" aria-hidden="true" data-status="0" onclick="setFavourite('.$row->restaurant_id.', this)"></i></a>';
          }
          else {
            $favData = '<a href="javascript:void(0);" class="fav"><i class="fa fa-heart-o" aria-hidden="true" data-status="1" onclick="setFavourite('.$row->restaurant_id.', this)"></i></a>';
          }
        }
        else {
          $favData = '';
        }
       $rsclose='';
      $current_time = date('H:i A');
      $day = strtolower(date('D'));
      $isopen=0;

      $fild1 = 'restaurant_delivery_'.$day.'_opentime';
      $fild2 = 'restaurant_delivery_'.$day.'_closetime';

      //echo $fild1;
      //exit();

      $Estimated_delivery_time = $row->restaurant_estimated_time;

      $starttime1=$row->$fild1;
      $starttime3=date("H:i", strtotime($starttime1));
      $closetime1=$row->$fild2;
      $closetime3=date("H:i", strtotime($closetime1));

      if(($current_time >= $starttime3 &&  $current_time <= $closetime3) || $row->business_type == 1)
      {
        if ($closednow == 1) {
          continue;
        }
        $isopen=1;
        $ordercls='<a class="vieworder" href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><button type="button"  class="btn-order">'.$this->lang->line('Order_Now').'</button></a>';
        $rsclose='<div class="restoOpen"></div><div class="offertext">'.$this->lang->line('Open_Now').'</div>';
      }

      if($isopen==0)
      {
        if ($opennow == 1) {
          continue;
        }
        $ordercls='<a class="vieworder" href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><button type="button"  class="pre-order">'.$this->lang->line('View_Now').'</button></a>';
        $rsclose='<div class="restoClose"></div><div class="offertext1">'.$this->lang->line('Closed_Now').'</div>';
      }

      $user_miles = number_format($row->distance, 2, '.', '');
      $servingcuisine=$this->frontend_model->getArrayCuisinesInfo($row->restaurant_serving_cuisines);

      $cuisinePhoto=$this->frontend_model->getCuisinesPhoto($row->restaurant_serving_cuisines);

      if(isset($cuisinePhoto) && $cuisinePhoto!=''){
        $image_file_path=FCPATH.CUISINE_IMAGE_PATH_THUMBS.$cuisinePhoto;
        if (file_exists($image_file_path)) //file_exists of a url returns false.It should be real file path
           {
              $image_name_with_path=base_url().CUISINE_IMAGE_PATH_THUMBS.$cuisinePhoto;
           }
           else
           {
              $image_name_with_path=base_url().CUISINE_IMAGE_PATH_THUMBS.CUISINE_DEFAULT_IMAGE;
           }
        }else{
          $image_name_with_path=base_url().CUISINE_IMAGE_PATH_THUMBS.CUISINE_DEFAULT_IMAGE;
        }

        $businessType = '';
        if ($row->business_type == 0) {
          $businessType .= '<lable class="restaurantstat" style="display:none">Restaurant</lable>';
        }
        else if ($row->business_type == 1) {
          $businessType .= '<lable class="catererstat" style="display:none">Caterer</lable>';
        }
      $datatable .='<div class="col-md-12 col-sm-12 col-xs-12">
                <div class="restro-box">
                    <div class="restaurant-box-inner">
                      '.$rsclose.'
                      <div class="col-md-3 col-sm-3 col-xs-12">
                        <div class="restothumb">
                          <img src="'.$image_name_with_path.'">
                        </div>
                      </div>
                      <div class="col-md-5 col-sm-5 col-xs-8 paddleft xs-gap">
                        <form>
                            <div class="star-ratings-sprite" style="float: left;margin-bottom: 10px;"><span style="width: '.$avgRating.'%" class="star-ratings-sprite-rating"></span></div>
                            <div class="clearfix"></div>
                        </form>
                        <a href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><p class="restoname">'.$row->restaurant_name.'</p></a>
                        <p class="cuisinetype"><span>'.$this->lang->line('Typeoffood').' :</span> <span>'.$servingcuisine.'</span></p>
                         <p class="deliveryloc">';
                        if ($row->restaurant_delivery == "Yes") {
                          $datatable .='<span class="deliverystat" title="Delivery"><i class="fa fa-truck" aria-hidden="true"></i></span>';
                        }
                        if ($row->restaurant_dinein == "Yes") {
                            $datatable .='<span class="deliverystat" title="Dine In"><i class="fa fa-cutlery" aria-hidden="true"></i></span>';
                        }
                        if ($row->restaurant_booktable == "Yes") {
                            $datatable .='<span class="deliverystat" title="Table Booking"><i class="fa fa-book" aria-hidden="true"></i></span>';
                        }
                        if ($row->restaurant_pickup == "Yes") {
                            $datatable .='<span class="deliverystat"  title="Pick Up"><i class="fa fa-shopping-basket" aria-hidden="true"></i></span>';
                        }
          $datatable .= $row->restaurant_city.'</p>
                      </div>
                      <div class="col-md-4 col-sm-4 col-xs-4 paddleft0">
                        '.$businessType.'
                        <div class="clearfix"></div>
                        <div class="veiwdetails">
                          '.$favData.'
                          '.$ordercls.'
                        </div>
                      </div>
                    </div>
                </div>
              </div>';
              $i++;
            }

          }else{
				$datatable='<div class="col-md-12 col-sm-12 col-xs-12">
                  <lable class="findnull">No search result found!</lable>
                </div>';

		  }
    if ($i == 0) {
      $datatable='<div class="col-md-12 col-sm-12 col-xs-12">
                  <lable class="findnull">No search result found!</lable>
                </div>';
    }
    echo $datatable;
}


function getAddress($lat, $lon){ $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=". $lat.",".$lon."&sensor=false"; $json = @file_get_contents($url); $data = json_decode($json); $status = $data->status; $address = ''; if($status == "OK"){ $address = $data->results[0]->formatted_address; } return $address; } # Call function echo getAddress("28.6292", "77.0805");


function search_restaurant() {

    $usersearchkey = $this->input->post('usersearchkey');

    $this->db->select('*');
    $this->db->from('rt_restaurant');
    $this->db->like('restaurant_name', $usersearchkey, 'both');
    $this->db->where('restaurant_status', '1');
    $this->db->where('restaurant_validate','1');
    $this->db->where('braintree_sub_merchant_status','active');
    $this->db->group_by('restaurant_name');
    $this->db->limit('10');
    $query = $this->db->get();
    // echo $this->db->last_query();
    // exit();
    if ($query->num_rows() > 0) {
      $data['response'] = 'true'; //If username exists set true
      $data['search_data'] = array();
      foreach ($query->result() as $key => $value) {

        echo "<div style=\"\" class=\"suggestionlist\" onclick=\"setCustDetails('".addslashes($value->restaurant_name)."')\"><b>".$value->restaurant_name." </b></div>";
      }
    }
    else {
       // $data['response'] = 'false'; //Set false if user not valid
    }
    //echo json_encode($data);
  }


  function register() {
    $data['StateList'] = $this->frontend_model->StateList();
    $data['CityList'] = $this->frontend_model->CityList();
    $session_data = $this->session->userdata('logged_in_customer');
    if(empty($session_data)) {
        $data['title'] = 'Customer Register';
        $data['page'] = 'customer_register';
        $this->load->view('frontend/header', $data);
        $this->load->view('frontend/sign-up');
        $this->load->view('frontend/footer');
    }else{
        redirect('customeradmin');
     // echo "go to dashboard";
    }
  }



  function addCustomer() {
    /*echo "<pre>";
    print_r ($this->input->post());
    echo "</pre>";
    exit();*/
    $now = date('Y-m-d H:i:s');
    $this->form_validation->set_rules('customer_email', 'Customer Email', 'trim|required|is_unique[rt_customer.customer_email]');
    $this->form_validation->set_message('is_unique', 'Entered email is already registered!');
    $this->form_validation->set_rules('customer_name', 'trim|xss_clean');
    $this->form_validation->set_rules('customer_lastname', 'trim|xss_clean');
    $this->form_validation->set_rules('customer_street', 'trim|xss_clean');
    $this->form_validation->set_rules('customer_zip', 'trim|xss_clean');
    $this->form_validation->set_rules('customer_state', 'trim|xss_clean');
    $this->form_validation->set_rules('customer_city', 'trim|xss_clean');
    $this->form_validation->set_rules('customer_phone', 'trim|xss_clean');

    //$required_if = $this->input->post('password') ? '|required' : '' ;
$this->form_validation->set_rules('customer_password', 'Password', 'trim|min_length[6]');
$this->form_validation->set_rules('customer_password', 'password', 'trim|min_length[6]|matches[customer_repassword]');
$this->form_validation->set_rules('customer_repassword', 'password confirmation', 'trim');
    /*$this->form_validation->set_rules('customer_password', 'trim|xss_clean');

    $this->form_validation->set_rules("input[customer_repassword]", "Confirm Password", 'required');
$this->form_validation->set_rules("input[customer_password]", "Password", 'matches[input[customer_repassword]]');*/


    if ($this->form_validation->run() == FALSE) {
      $this->register();
    }
    else {

      // We define our address
      $address = $this->input->post('customer_street');
      $zip = $this->input->post('customer_zip');
      $fulladdress = $address.' '.$zip;
      // We get the JSON results from this request
      if($address!='') {
        $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($fulladdress).'&sensor=false');
        // We convert the JSON to an array
        $geo = json_decode($geo, true);
        // If everything is cool
        if ($geo['status'] = 'OK') {
        // We set our values
        $latitude = isset($geo['results'][0]['geometry']['location']['lat'])? $geo['results'][0]['geometry']['location']['lat']: DEFAULT_LAT;
        $longitude = isset($geo['results'][0]['geometry']['location']['lng'])? $geo['results'][0]['geometry']['location']['lng'] : DEFAULT_LONG;
        }
        else {
          $latitude = DEFAULT_LAT;
          $longitude = DEFAULT_LONG;
        }
      }
      else {
        $latitude = DEFAULT_LAT;
        $longitude = DEFAULT_LONG;
      }

      /*$customer_full_name = $this->input->post('customer_name'); //none
      $space = strrpos($customer_full_name, ' '); //none
      $length = strlen($customer_full_name); //none
      if ($space != 0) {
        $customer_name = substr($customer_full_name, 0, $space);
        $customer_lastname = substr($customer_full_name, $space, $length);
      }
      else {
        $customer_name = $customer_full_name;
        $customer_lastname = '';
      }*/

      $this->db->trans_start();
      $data_in = array(
          'customer_name'          =>  $this->input->post('customer_name'),
          'customer_lastname'          =>  $this->input->post('customer_lastname'),
          'customer_street'        =>  $this->input->post('customer_street'),
          'customer_zip'            =>  $this->input->post('customer_zip'),
          'customer_state'            =>  $this->input->post('customer_state'),
          'customer_city'            =>  $this->input->post('customer_city'),
          'customer_phone'          =>  $this->input->post('customer_phone'),
          'customer_email'          =>  $this->input->post('customer_email'),
          'customer_password'    =>  md5($this->input->post('customer_password')),
          'addeddate' =>   $now
        );
      $this->db->insert('rt_customer', $data_in);
      $custmer_registration_id = $this->db->insert_id();
    if($this->input->post('newsletter_signup') == "on"){
        $this->frontend_model->newsletterSubscribe($this->input->post('newsletter_subscriber'), $this->input->post('customer_email'));
    }
      $this->session->set_userdata('custmer_registration_id', $custmer_registration_id);
      redirect('frontend/thankyou');
    }
  }


  function thankyou() {
    $customer_id = $this->session->userdata('custmer_registration_id');
    //$restaurant_id = 227;
    $data['customer_id'] = $customer_id;
    $this->db->trans_start();
    $data_up = array(
        'customer_validate_id'  =>  md5($customer_id)
      );
    $this->db->where('customer_id', $customer_id);
    $this->db->update('rt_customer', $data_up);
    $this->db->trans_complete();

    $logo=base_url().'assets/logo-main.png';
    $image_path = base_url().'assets/';
    $variables = array();
    $customer_data = $this->frontend_model->getCustomerData($customer_id);


    /*$sess_array = array(
          'id'          => $customer_data['customer_id'],
          'is_admin'    => 0,
          'is_active'   => $customer_data['status'],
          'username'    => $customer_data['customer_name'],
          'customer_image' => $customer_data['image']
        );

    $this->session->set_userdata('logged_in_customer', $sess_array);*/


    $to = $customer_data['customer_email'];
    $driver_name = $customer_data['customer_name'];
    $link_button=anchor('frontend/validateCustomer/' . md5($customer_id),'<button>Verify Email</button>');
    $link = anchor('frontend/validateCustomer/' . md5($customer_id));
    $only_link = base_url().'frontend/validateCustomer/' . md5($customer_id);
    //$logo="<img src='". $path."' style='height:48px; width:auto;'>";
    //$variables['recipient'] = $driver_name;
    //$variables['name'] = $driver_name;
    $variables['link_button'] = $link_button;
    $variables['link'] = $link;
    $variables['only_link'] = $only_link;
    $variables['logo'] = $logo;
    $variables['image_path'] = $image_path;
    $variables['to_email'] = $to;

    $variables['customer_id'] = $customer_data['customer_id'];
    $variables['customer_email'] = $customer_data['customer_email'];
    $variables['customer_password'] = $customer_data['customer_password'];



    $variables['site_address'] = SITE_ADDRESS;
    $variables['sender_name'] = SITENAME;
    $variables['site_name'] = SITENAME;
    //$template_name = 'welcome_customer';
    $template_name = 'customer_email_verification';
    $mail_data = $this->frontend_model->getEmailTemplate($template_name);
    $mailcontent=htmlspecialchars_decode($mail_data->template);
    $subject = $mail_data->subject;
    foreach($variables as $key => $value) {
      $mailcontent = str_replace('{{'.$key.'}}', $value, $mailcontent);
    }
    /*$this->load->library('email');
    $config['charset'] = 'utf-8';
    $config['wordwrap'] = TRUE;
    $config['mailtype'] = 'html';
    $this->email->initialize($config);

    $this->email->from(SITENAME);
    $this->email->to($to);
    $this->email->subject($subject);
    $this->email->message($mailcontent);
    $this->email->send();*/
    $this->send_my_mail($to,$subject,$mailcontent);
    $this->session->unset_userdata('restaurant_registration_id');
    $data['title']  = "Thank You";
    $data['page'] = "customer_registration";
    $this->load->view('frontend/header',$data);
    $this->load->view('frontend/thankyou');
    $this->load->view('frontend/footer');
  }



  /*function validateRestaurantOwner($verify_code) {
    if ($verify_code != '') {
      $checkDriver = $this->restaurantmanagement_model->validateRestaurantOwner($verify_code);
      if ($checkDriver == 1) {
        $data['title']  = "Thank You";
        $data['page'] = "restaurant_owner_valid";
        $this->load->view('frontend/header',$data);
        $this->load->view('frontend/thankyou');
        $this->load->view('frontend/footer');
      }
      else if ($checkDriver == 2) {
        $data['title']  = "Thank You";
        $data['page'] = "restaurant_owner_already_valid";
        $this->load->view('frontend/header',$data);
        $this->load->view('frontend/thankyou');
        $this->load->view('frontend/footer');
      }
      else if ($checkDriver == 0) {
        $data['title']  = "Thank You";
        $data['page'] = "restaurant_owner_invalid";
        $this->load->view('frontend/header',$data);
        $this->load->view('frontend/thankyou');
        $this->load->view('frontend/footer');
      }
    }
  }*/


  function send_my_mail($mail_To,$mail_subject,$mail_Body,$mail_CC="")
{
    $mail_From = SITENAME;

    $mail = new PHPMailer();

    //Your SMTP servers details

    $mail->IsSMTP(); // set mailer to use SMTP
    $mail->Host = SMTP_HOST; // specify main and backup server or localhost
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = SMTP_USER; // SMTP username
    $mail->Password = SMTP_PASSWORD; // SMTP password It should be same as that of the SMTP user
    //$mail->AddCustomHeader("Precedence: bulk");
    //$mail->PluginDir = "/home/phpaucti/public_html/website_development/coding/includes/";
    $mail->From = $mail->Username; //Default From email same as smtp user
    $mail->FromName = $mail_From;
    $emailArr = explode(',',$mail_To);
    foreach($emailArr AS $emailVal) {
    $mail->AddAddress($emailVal, ""); //Email address where you wish to receive/collect those emails.
    }

    /*$emailCCArr = explode(',',$mail_CC);
    foreach($emailCCArr AS $emailCCVal) {
    $mail->AddCC($emailCCVal, ""); //Email address where you wish to receive/collect those emails.
    }*/


    $mail->WordWrap = 100; // set word wrap to 50 characters
    $mail->IsHTML(true); // set email format to HTML
    $mail->Subject = $mail_subject;
    $message = $mail_Body;
    $mail->Body = $message;

    if(!$mail->Send())
    {
    /*echo "Message could not be sent. <p>";
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;*/
    }
    else
    {
    //echo 'ok';
    }

}


function validateCustomer($verify_code) {
    if ($verify_code != '') {
      $checkCustomer = $this->frontend_model->validateCustomer($verify_code);
      if ($checkCustomer == 1) {
        $data['title']  = "Thank You";
        $data['page'] = "customer_valid";
        $data['verify_code'] = $verify_code;
        $this->load->view('frontend/header',$data);
        $this->load->view('frontend/thankyou');
        $this->load->view('frontend/footer');
      }
      else if ($checkCustomer == 2) {
        /*$data['title']  = "Thank You";
        $data['page'] = "restaurant_owner_already_valid";
        $this->load->view('frontend/header',$data);
        $this->load->view('frontend/thankyou');
        $this->load->view('frontend/footer');*/
        redirect('customerLogin/'.$verify_code.'');
      }
      else if ($checkCustomer == 0) {
        $data['title']  = "Thank You";
        $data['page'] = "restaurant_owner_invalid";
        $this->load->view('frontend/header',$data);
        $this->load->view('frontend/thankyou');
        $this->load->view('frontend/footer');
      }
    }
  }


  function forgot_password()
  {
    $customer_email = $this->input->get('forgot_password');
    $this->db->select('*');
    $this->db->from('rt_customer');
    $this->db->where('customer_email', $customer_email);
    $query = $this->db->get();
    $num_rows = $query->num_rows();
    if ($num_rows && preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $customer_email)) {
      echo http_response_code(200);
    }
    else {
      echo http_response_code(418);
    }
    //echo http_response_code(418);
  }


  function sendForgotPasswordMail() {
    $customer_email = $this->input->post('forgot_password');
    $this->db->trans_start();
    $this->db->select('customer_id');
    $this->db->from('rt_customer');
    $this->db->where('customer_email', $customer_email);
    $query = $this->db->get();
    $customer_data = $query->row();
    $data['customer_id'] = $customer_data->customer_id;
    $customer_id = $customer_data->customer_id;
    $new_password = rand(100000, 999999);
    $data_up = array(
        'customer_password'  =>  md5($new_password)
      );
    $this->db->where('customer_id', $customer_id);
    $this->db->update('rt_customer', $data_up);
    $this->db->trans_complete();
    /*echo($new_password);
    exit();*/

    $logo=base_url().'assets/logo-main.png';
    $image_path=base_url().'assets/';
    $variables = array();


    $customer_data = $this->frontend_model->getCustomerData($customer_id);

    $to = $customer_data['customer_email'];

    $customer_name = $customer_data['customer_name'];

    $link_button=anchor('restaurantadmin/validateRestaurantOwner/' . md5($customer_id),'<button>Verify Email</button>');
    $link = anchor('restaurantadmin/validateRestaurantOwner/' . md5($customer_id));
    //$logo= $path."' style='height:48px; width:auto;'>";
    //$variables['recipient'] = $restaurant_contact_name;
    //$variables['name'] = $restaurant_contact_name;
    $variables['link_button'] = $link_button;
    $variables['link'] = $link;
    $variables['logo'] = $logo;
    $variables['image_path'] = $image_path;
    $variables['to_email'] = $to;

    $variables['email'] = $customer_data['customer_email'];
    $variables['password'] = $new_password;

    $variables['site_address'] = SITE_ADDRESS;
    $variables['sender_name'] = SITENAME;
    $variables['site_name'] = SITENAME;
    $template_name = 'forgot_password';
    $mail_data = $this->frontend_model->getEmailTemplate($template_name);
    $mailcontent=htmlspecialchars_decode($mail_data->template);
    $subject = $mail_data->subject;
    foreach($variables as $key => $value) {
      $mailcontent = str_replace('{{'.$key.'}}', $value, $mailcontent);
    }
    $this->send_my_mail($to,$subject,$mailcontent, $mail_CC = '');
    //$this->session->unset_userdata('restaurant_registration_id');
    $this->session->set_userdata('success_msg', 'Your login details has been sent to your email address');
    //redirect('login');
    $this->login();
    


  }

  function setFavourite() {
    $now = date('Y-m-d H:i:s');
    $restaurant_id = $this->input->post('restaurant_id');
    $set_fav = $this->input->post('set_fav');
    $session_data = $this->session->userdata('logged_in_customer');
    $customer_id = $session_data['id'];
    if ($set_fav == 0) {
      $this->db->where('restaurant_id', $restaurant_id);
      $this->db->where('customerid', $customer_id);
      $this->db->delete('rt_myfavorties');
    }
    else if($set_fav == 1) {
      $data_in = array(
          'restaurant_id'   =>    $restaurant_id,
          'customerid'      =>    $customer_id,
          'ip_address'      =>    $this->input->ip_address(),
          'adddate'         =>    $now
        );
      $this->db->insert('rt_myfavorties', $data_in);
    }
  }
  function track_on_map($accesstoken)
  {
      $delimiter = "SPECIAL_STRING@#$%^";
      $delimiter2 = "SPECIAL_STRING@#$%^1";
      //$accesstoken = base64_encode("user".$delimiter."77");
      //$accesstoken = base64_encode("admin".$delimiter."allRes");
      $resultInfo = false;
      $userType = "0";
      $data["allRes"] = json_encode(array());

      if(isset($accesstoken) && !empty($accesstoken))
      {
          //customerid, restaurantownerid, adminid
          $orderId = explode($delimiter, base64_decode($accesstoken))[1];
          $userIs = explode($delimiter, base64_decode($accesstoken))[0];

          if($userIs === "admin")
          {
              $userType = "3";//Super Admin
          }

          if($userIs === "restaurant")
          {
              $userType = "2";//Restaurant Owner
          }

          if($userIs === "user")
          {
              $userType = "1";//Customer
          }

          if(!empty($orderId))
          {
              if(is_numeric($orderId)) {
                  $this->db->select('deliverylatitude, deliverylongitude, restaurant_id');
                  $this->db->from('rt_order');
                  $this->db->where('orderid', $orderId);
                  $query = $this->db->get();
                  $orderDetails = $query->result_array();

                  $restaurant_id = $orderDetails[0]["restaurant_id"];
                  $this->db->select('latitude, longitude');
                  $this->db->from('rt_restaurant');
                  $this->db->where('restaurant_id', $restaurant_id);
                  $query = $this->db->get();
                  $restaurantDetails = $query->result_array();

                  $data["deliveryLatitude"] = $orderDetails[0]["deliverylatitude"];
                  $data["deliveryLongitude"] = $orderDetails[0]["deliverylongitude"];

                  $data["restaurant_latitude"] = $restaurantDetails[0]["latitude"];
                  $data["restaurant_longitude"] = $restaurantDetails[0]["longitude"];
              }else{
                  if($userType == 3){
                      $this->db->select('latitude, longitude, restaurant_id, restaurant_name, restaurant_streetaddress, restaurant_logo');
                      $this->db->from('rt_restaurant');
                      $query = $this->db->get();
                      $allRes = $query->result_array();

                      if(!empty($allRes))
                      {
                          foreach ($allRes as $k=>$val)
                          {
                              if($val['restaurant_logo'] != '' && file_exists(FCPATH.RESTAURAT_LOGO_PATH_THUMBS.$val['restaurant_logo'])) {
                                  $imgurl = base_url().RESTAURAT_LOGO_PATH_THUMBS.$val['restaurant_logo'];
                              } else{
                                  $imgurl = base_url().RESTAURAT_LOGO_PATH_THUMBS.RESTAURAT_DEFAULT_IMAGE;
                              }
                              $allRes[$k]["restaurant_logo_path"] = $imgurl;
                          }
                      }
                      $data["allRes"] = json_encode($allRes);
                  }
              }

              $resultInfo = true;
              if($userType == "0")
              {
                  $resultInfo = false;
              }
          }else if($userType == "3")
          {
              $resultInfo = true;
          }
      }

     $data["userType"] = $userType;
     $data["showMap"] = $resultInfo;
      $data['title']  = "Track On Map";
      $data['page'] = "activity_track_on_map";
      //print_r($data);
      if ($userType == "1") {
          $this->load->view('frontend/header',$data);
          $this->load->view('track-on-map');
          $this->load->view('frontend/footer');
      }
      if ($userType == "2") {
          $this->load->view('restaurantadmin/header',$data);
          $this->load->view('track-on-map');
          $this->load->view('restaurantadmin/footer');
      }
      if ($userType == "3") {
          $this->load->view('superadmin/header',$data);
          $this->load->view('track-on-map');
          $this->load->view('superadmin/footer');
      }
  }
}

Anon7 - 2022
AnonSec Team