| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 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 : |
<?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(empty($session_data)) { redirect('login', 'refresh'); }
function index( $offset = 0 )
{
$data['feature_restaurant'] = $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';
$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 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'); //Read the baseurl from the config.php file
//get the Facebook appId and app secret from facebook.php which located in config directory for the creating the object for Facebook class
// $facebook = new Facebook\Facebook(array(
// 'appId' => $this->config->item('appID'),
// 'secret' => $this->config->item('appSecret'),
// ));
$facebook = new Facebook\Facebook([
'app_id' => $this->config->item('appID'),
'app_secret' => $this->config->item('appSecret'),
'default_graph_version' => 'v2.8',
]);
// $helper = $facebook->getRedirectLoginHelper();
$helper = $facebook->getJavaScriptHelper();
// print_r($helper); exit();
// $user = $facebook->getUser(); // Get the facebook user id
//echo $user;
//$this->session->sess_destroy(); //session destroy
//exit();
// $user = true;
if($helper){
//$user_profile = $facebook->api('/me'); //Get the facebook user
//// print_r($user_profile);
// exit();
try{
// $user_profile = $facebook->api('/me?fields=email,name'); //Get the facebook user profile data
$accessToken = $helper->getAccessToken();
$response = $facebook->get('/me?fields=email,name', $accessToken); //Get the facebook user profile data
$user_profile = $response->getGraphUser();
// print_r($user_profile);
// echo '<img src="https://graph.facebook.com/'. $user_profile['id'] .'/picture" width="30" height="30"/><div>'.$user_profile['name'].'</div>';
// exit();
// $params = array('next' => $base_url.'frontend/logout');
// $ses_user=array('User'=>$user_profile,
// 'logout' =>$facebook->getLogoutUrl($params) //generating the logout url for facebook
// );
$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);
//echo "ok";
//exit();
}else{
$this->form_validation->set_message('check_password', 'Sorry! You are 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', 'Sorry! You are 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";
$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);
}
// $this->session->set_userdata($ses_user);
//header('Location: '.$base_url);
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');
$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);
$addr = $this->getAddress($latitude, $longitude);
echo $address;
}
function restaurantslisting($cuisine_id = '')
{
$session_data = $this->session->userdata('customer_location');
/*Safety precautions start*/
//$longitude = DEFAULT_LONG;
//$latitude = DEFAULT_LAT;
/*Safety precautions end*/
$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(is_array($res_list) && sizeof($res_list)>0)
{
$datatable ='';
$servingcuisine='';
foreach($res_list as $key=>$row)
{
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 = '<span style="position: absolute;right: 10px;top: 18px;cursor: pointer;"><i class="fa fa-star" aria-hidden="true" data-status="0" onclick="setFavourite('.$row->restaurant_id.', this)"></i></span>';
}
else {
$favData = '<span style="position: absolute;right: 10px;top: 18px;cursor: pointer;"><i class="fa fa-star-o" aria-hidden="true" data-status="1" onclick="setFavourite('.$row->restaurant_id.', this)"></i></span>';
}
}
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)
{
$isopen=1;
$ordercls='<small class="dist pull-left"><a href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><button type="button" class="btn-order">Order Now</button><a></small>';
}
if($isopen==0)
{
$ordercls='<small class="dist pull-left"><a href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><button type="button" class="pre-order">View Now</button><a></small>';
$rsclose='<img class="status" src="'.base_url().'assets/img/front-end/cerrado.png">';
}
$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;
}
$datatable .='<div class="col-md-4 col-sm-6">
<div class="restro-box">
<div class="restaurant-box-inner">
<div class="restaurant-box-header">
<img width="269" height="134" src="'.$image_name_with_path.'">
</div>
<div class="res-status">
'.$rsclose.'
</div>
<div class="restaurant-box-content">
<div class="delay green">
<span class="time ng-binding"><i class="fa fa-road" aria-hidden="true"></i> '.$user_miles.' mi</span>
</div>
<a href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><h5 class="text-ellipsis">'.$row->restaurant_name.'</h5></a>'.$favData.'
<small class="cuisine text-ellipsis">'.$servingcuisine.'</small>
</div><div class="restaurant-box-footer clearfix">
'.$ordercls.'<small class="rating pull-right"><i class="fa " aria-hidden="true"></i>'.$Estimated_delivery_time.' Mins</small>
</div>
</div>
</div>
</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');
$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(is_array($res_list) && sizeof($res_list)>0)
{
$datatable ='';
$servingcuisine='';
foreach($res_list as $key=>$row)
{
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 = '<span style="position: absolute;right: 10px;top: 18px;cursor: pointer;"><i class="fa fa-star" aria-hidden="true" data-status="0" onclick="setFavourite('.$row->restaurant_id.', this)"></i></span>';
}
else {
$favData = '<span style="position: absolute;right: 10px;top: 18px;cursor: pointer;"><i class="fa fa-star-o" aria-hidden="true" data-status="1" onclick="setFavourite('.$row->restaurant_id.', this)"></i></span>';
}
}
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)
{
$isopen=1;
$ordercls='<small class="dist pull-left"><a href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><button type="button" class="btn-order">Order Now</button><a></small>';
}
if($isopen==0)
{
$ordercls='<small class="dist pull-left"><a href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><button type="button" class="pre-order">View Now</button><a></small>';
$rsclose='<img class="status" src="'.base_url().'assets/img/front-end/cerrado.png">';
}
$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;
}
$datatable .='<div class="col-md-4 col-sm-6">
<div class="restro-box">
<div class="restaurant-box-inner">
<div class="restaurant-box-header">
<img width="269" height="134" src="'.$image_name_with_path.'">
</div>
<div class="res-status">
'.$rsclose.'
</div>
<div class="restaurant-box-content">
<div class="delay green">
<span class="time ng-binding"><i class="fa fa-road" aria-hidden="true"></i> '.$user_miles.' mi</span>
</div>
<a href="'.base_url().'restaurantviewpage/'.$row->restaurant_seourl.'"><h5 class="text-ellipsis">'.$row->restaurant_name.'</h5></a>'.$favData.'
<small class="cuisine text-ellipsis">'.$servingcuisine.'</small>
</div><div class="restaurant-box-footer clearfix">
'.$ordercls.'<small class="rating pull-right"><i class="fa " aria-hidden="true"></i>'.$Estimated_delivery_time.' Mins</small>
</div>
</div>
</div>
</div>';
}
}else{
$datatable='<div class="col-md-4 col-sm-6">
<lable>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();
$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);
}
}
}