Advertisement
red_devi3321

Restaurants.php

Jun 17th, 2021 (edited)
1,474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.17 KB | None | 0 0
  1. <?php
  2. if (!defined('BASEPATH'))
  3.     exit('No direct script access allowed');
  4. class Restaurants extends MY_Controller {
  5.  
  6.     public function __construct() {
  7.         parent::__construct();
  8.         $language= $this->session->userdata('lang') ? $this->session->userdata('lang') : 'english';
  9.         $this->lang->load("common",$language);
  10.         $this->dataModule['country']= $this->Sitefunction->get_rows(TBL_COUNTRY, 'id, name', array('status'=>1));
  11.         $this->dataModule['owners']= $this->Sitefunction->get_rows(TBL_OWNERS, 'id, first_name, last_name', array('status'=>1));
  12.      
  13.     }
  14.     public function index() {
  15.         $where = array('r.status!='=>9);
  16.         $columns = "r.*, o.first_name, o.last_name, s.name as state_name, ct.name as city_name, c.name as country_name";
  17.         $join = array(TBL_STATE.' as s' => "s.id=r.state_id", TBL_CITY.' as ct'=> "ct.id=r.city_id", TBL_COUNTRY." as c" => "c.id=r.country_id", TBL_OWNERS." as o" => "o.id=r.owner_id");
  18.         $group_by = 'r.id';
  19.         $this->dataModule['results']=  $this->Sitefunction->get_all_rows(TBL_RESTAURANTS.' as r', $columns, $where, $join, array(), '', 'LEFT', array(), $group_by, array(), array());
  20.        
  21.         $this->load->view('restaurants/index', $this->dataModule);
  22.     }
  23.    
  24.     public function delete() {
  25.        
  26.         $this->Sitefunction->delete(TBL_RESTAURANTS, array('id'=>$this->input->get_post('id')));
  27.        
  28.     }
  29.    
  30.     public function multiple_delete() {
  31.         $ids= $this->input->get_post('id');
  32.  
  33.         foreach($ids as $id){
  34.             $this->Sitefunction->delete(TBL_RESTAURANTS, array('id'=>$id));
  35.         }
  36.  
  37.     }
  38.  
  39.     public function add(){
  40.         $postData= $this->input->post();
  41.         if($postData && !empty($postData)) {
  42.             $this->form_validation->set_rules('name', 'name', 'required|min_length[3]|max_length[125]');
  43.             $this->form_validation->set_rules('owner_id', 'owner', 'required');
  44.             $this->form_validation->set_rules('phone_number', 'phone', 'required|min_length[10]|max_length[12]');
  45.             $this->form_validation->set_rules('email_id', 'email', 'required|valid_email|min_length[3]|max_length[125]');
  46.             $this->form_validation->set_rules('city_id', 'city', 'required');
  47.             $this->form_validation->set_rules('state_id', 'state', 'required');
  48.             $this->form_validation->set_rules('country_id', 'country', 'required');
  49.             $this->form_validation->set_rules('pincode', 'pincode', 'required|min_length[5]|max_length[7]');
  50.             $this->form_validation->set_rules('address', 'address', 'required|min_length[10]');
  51.             $this->form_validation->set_rules('opening_time', 'opening time', 'required');
  52.             $this->form_validation->set_rules('closing_time', 'closing time', 'required');
  53.             $this->form_validation->set_error_delimiters( '<p class="error">','</p>' );
  54.             if ($this->form_validation->run() != FALSE)
  55.             {
  56.                 $data_array['name']=urlencode($this->input->post('name'));
  57.                 $data_array['owner_id']=$this->input->post('owner_id');
  58.                 $data_array['email']=urlencode($this->input->post('email_id'));
  59.                 $data_array['phone']=$this->input->post('phone_number');
  60.                 $data_array['city_id']=$this->input->post('city_id');
  61.                 $data_array['state_id']=$this->input->post('state_id');
  62.                 $data_array['country_id']=$this->input->post('country_id');
  63.                 $data_array['pincode']=$this->input->post('pincode');
  64.                 $data_array['address']=urlencode($this->input->post('address'));
  65.                 $data_array['discount']=$this->input->post('discount');
  66.                 $data_array['discount_type']=$this->input->post('discount_type');
  67.                 $data_array['average_price']=$this->input->post('average_price');
  68.                 $data_array['opening_time']=date('H:i:s', strtotime($this->input->post('opening_time')));
  69.                 $data_array['closing_time']=date('H:i:s', strtotime($this->input->post('closing_time')));
  70.                 $data_array['updated']=$this->utc_time;
  71.                 $data_array['created']=$this->utc_time;
  72.                 $address = urldecode($data_array['address']).' '.$data_array['pincode']; // Google HQ
  73.                 $prepAddr = str_replace(' ','+',$address);
  74.                 $geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false'.'&key='.$this->settings->map_api_key);
  75.                 $output= json_decode($geocode);
  76.                 if($output->results[0] && $output->results[0]->geometry && $output->results[0]->geometry->location && $output->results[0]->geometry->location->lat) {
  77.                     $latitude = $output->results[0]->geometry->location->lat;
  78.                     $longitude = $output->results[0]->geometry->location->lng;
  79.                     $data_array['latitude']=$latitude;
  80.                     $data_array['longitude']=$longitude;
  81.                     if(isset($_FILES['profile_image']) && $_FILES['profile_image'] != '')
  82.                     {
  83.                         $fileCount = count($_FILES["profile_image"]['name']);
  84.    
  85.                         $p_profile_image= array();
  86.                         for($pi=0; $pi < $fileCount; $pi++)
  87.                         {
  88.                             $randdom= round(microtime(time()*1000)).rand(000, 999);
  89.                             $file_extension1 =pathinfo($_FILES["profile_image"]["name"][$pi], PATHINFO_EXTENSION);
  90.                             $file_name1= $randdom.'.'.$file_extension1;
  91.                             if ($_FILES["profile_image"]["error"][$pi] > 0) {
  92.                                 $file_name1='';
  93.                             } else {
  94.                                 move_uploaded_file($_FILES['profile_image']['tmp_name'][$pi], UPLOAD_PATH.'restaurants/profile/'. $file_name1);
  95.                                 array_push($p_profile_image,  $file_name1);
  96.                                
  97.                             }
  98.                        
  99.                         }
  100.                         $p_profile_image1= implode(',', $p_profile_image);
  101.                     }else {
  102.                         $p_profile_image1='';
  103.                     }
  104.                     $data_array['profile_image']=$p_profile_image1;
  105.                     if($this->Sitefunction->insert(TBL_RESTAURANTS, $data_array)){
  106.                         $this->session->set_flashdata('success', $this->lang->line('restaurant_added_successfully'));
  107.                         redirect(RESTAURANTS_PATH);
  108.                     }else {
  109.                         $this->session->set_flashdata('error', $this->lang->line('error_try_again'));
  110.                     }
  111.                 }else {
  112.                     $this->session->set_flashdata('error', $this->lang->line('invalid_address'));
  113.                 }
  114.                
  115.             }
  116.            
  117.         }
  118.         $this->load->view('restaurants/add',$this->dataModule);      
  119.     }
  120.  
  121.     public function edit($id){
  122.         $this->dataModule['results']= $this->Sitefunction->get_single_row(TBL_RESTAURANTS, '*', array('id'=>$id));
  123.         if(!$id || empty($this->dataModule['results'])) {
  124.             redirect(ERROR_PATH);
  125.         }
  126.         $postData= $this->input->post();
  127.         if($postData && !empty($postData)) {
  128.             $this->form_validation->set_rules('name', 'name', 'required|min_length[3]|max_length[125]');
  129.             $this->form_validation->set_rules('owner_id', 'owner', 'required');
  130.             $this->form_validation->set_rules('phone_number', 'phone', 'required|min_length[10]|max_length[12]');
  131.             $this->form_validation->set_rules('email_id', 'email', 'required|valid_email|min_length[3]|max_length[125]');
  132.             $this->form_validation->set_rules('city_id', 'city', 'required');
  133.             $this->form_validation->set_rules('state_id', 'state', 'required');
  134.             $this->form_validation->set_rules('country_id', 'country', 'required');
  135.             $this->form_validation->set_rules('pincode', 'pincode', 'required|min_length[5]|max_length[7]');
  136.             $this->form_validation->set_rules('address', 'address', 'required|min_length[10]');
  137.             $this->form_validation->set_rules('opening_time', 'opening time', 'required');
  138.             $this->form_validation->set_rules('closing_time', 'closing time', 'required');
  139.             $this->form_validation->set_error_delimiters( '<p class="error">','</p>' );
  140.             if ($this->form_validation->run() != FALSE)
  141.             {
  142.                 $data_array['name']=urlencode($this->input->post('name'));
  143.                 $data_array['owner_id']=$this->input->post('owner_id');
  144.                 $data_array['email']=urlencode($this->input->post('email_id'));
  145.                 $data_array['phone']=$this->input->post('phone_number');
  146.                 $data_array['city_id']=$this->input->post('city_id');
  147.                 $data_array['state_id']=$this->input->post('state_id');
  148.                 $data_array['country_id']=$this->input->post('country_id');
  149.                 $data_array['pincode']=$this->input->post('pincode');
  150.                 $data_array['address']=urlencode($this->input->post('address'));
  151.                 $data_array['discount']=$this->input->post('discount');
  152.                 $data_array['discount_type']=$this->input->post('discount_type');
  153.                 $data_array['average_price']=$this->input->post('average_price');
  154.                 $data_array['opening_time']=date('H:i:s', strtotime($this->input->post('opening_time')));
  155.                 $data_array['closing_time']=date('H:i:s', strtotime($this->input->post('closing_time')));
  156.                 $address = urldecode($data_array['address']).' '.$data_array['pincode']; // Google HQ
  157.                 $prepAddr = str_replace(' ','+',$address);
  158.                 $geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false'.'&key='.$this->settings->map_api_key);
  159.                 $output= json_decode($geocode);
  160.            
  161.                 if($output->results[0] && $output->results[0]->geometry && $output->results[0]->geometry->location && $output->results[0]->geometry->location->lat) {
  162.                     $latitude = $output->results[0]->geometry->location->lat;
  163.                     $longitude = $output->results[0]->geometry->location->lng;
  164.                     $data_array['latitude']=$latitude;
  165.                     $data_array['longitude']=$longitude;
  166.                     if(isset($_FILES['profile_image']) && $_FILES['profile_image'] != '')
  167.                     {
  168.                        
  169.            
  170.                         $fileCount = count($_FILES["profile_image"]['name']);
  171.  
  172.                         $p_profile_image= $_POST['happening_gallery_image']!=''?$_POST['happening_gallery_image']:array();
  173.                         for($pi=0; $pi < $fileCount; $pi++)
  174.                         {
  175.                             $randdom= round(microtime(time()*1000)).rand(000, 999);
  176.                             $file_extension1 =pathinfo($_FILES["profile_image"]["name"][$pi], PATHINFO_EXTENSION);
  177.                             $file_name1= $randdom.'.'.$file_extension1;
  178.                             if ($_FILES["profile_image"]["error"][$pi] > 0) {
  179.                                 $file_name1='';
  180.                             } else {
  181.                                 move_uploaded_file($_FILES['profile_image']['tmp_name'][$pi], UPLOAD_PATH.'restaurants/profile/'. $file_name1);
  182.                                 array_push($p_profile_image,  $file_name1);
  183.                                
  184.                             }
  185.                        
  186.                         }
  187.                         $p_profile_image1= implode(',', $p_profile_image);
  188.                     }else {
  189.                         $p_profile_image1=$this->dataModule['results']->profile_image;
  190.                     }
  191.                     $data_array['profile_image']=$p_profile_image1;
  192.                     $data_array['updated']=$this->utc_time;
  193.                     if($this->Sitefunction->update(TBL_RESTAURANTS, $data_array, array('id'=>$id))){
  194.                         $this->session->set_flashdata('success', $this->lang->line('restaurant_updated_successfully'));
  195.                         redirect(RESTAURANTS_PATH);
  196.                     }else {
  197.                         $this->session->set_flashdata('error', $this->lang->line('error_try_again'));
  198.                     }
  199.                 }else {
  200.                     $this->session->set_flashdata('error', $this->lang->line('invalid_address'));
  201.                 }
  202.             }
  203.            
  204.         }
  205.         $this->dataModule['state']= $this->Sitefunction->get_rows(TBL_STATE, 'id, name', array('status'=>1, 'country_id'=>$this->dataModule['results']->country_id));
  206.         $this->dataModule['city']= $this->Sitefunction->get_rows(TBL_CITY, 'id, name', array('status'=>1, 'state_id'=>$this->dataModule['results']->state_id));
  207.         $this->load->view('restaurants/edit',$this->dataModule);      
  208.     }
  209.  
  210.     function getState() {
  211.         $country_id= $this->input->get_post('country_id');
  212.         $getstate= $this->Sitefunction->get_rows(TBL_STATE, 'id, name', array('status'=>1, 'country_id'=>$country_id));
  213.         $result= '<option value="">'.$this->lang->line('select_state').'</option>';
  214.         foreach($getstate as $value) {
  215.             $result.='<option value="'.$value['id'].'">'.urldecode($value['name']).'</option>';
  216.         }
  217.         echo $result;
  218.     }
  219.     function getCity() {
  220.         $state_id= $this->input->get_post('state_id');
  221.         $getcity= $this->Sitefunction->get_rows(TBL_CITY, 'id, name', array('status'=>1, 'state_id'=>$state_id));
  222.         $result= '<option value="">'.$this->lang->line('select_city').'</option>';
  223.         foreach($getcity as $value) {
  224.             $result.='<option value="'.$value['id'].'">'.urldecode($value['name']).'</option>';
  225.         }
  226.         echo $result;
  227.     }
  228.  
  229.     public function view($id) {
  230.  
  231.         $this->dataModule['restaurant_info']=  $this->Sitefunction->get_single_by_query("SELECT r.*, ct.name as city_name, s.name as state_name, c.name as country_name FROM ".TBL_RESTAURANTS." as r INNER JOIN ".TBL_CITY." as ct ON ct.id=r.city_id INNER JOIN ".TBL_STATE." as s ON s.id=r.state_id  INNER JOIN ".TBL_COUNTRY." as c ON c.id=r.country_id WHERE r.id=".$id." and r.status=1");
  232.         $this->dataModule['controller']=$this;
  233.  
  234.         $where = array('s.restaurant_id='=>$id, 's.status'=>1);
  235.         $columns = "c.*";
  236.         $join = array(TBL_SUBCATEGORIES.' as s'=>"s.category_id=c.id");
  237.         $group_by = 'c.id';
  238.         $this->dataModule['categories']=  $this->Sitefunction->get_all_rows(TBL_CATEGORIES.' as c', $columns, $where, $join, array(), '', 'LEFT', array(), $group_by, array(), array());
  239.  
  240.        
  241.  
  242.      
  243.       if(empty($this->dataModule['restaurant_info'])) {
  244.         $this->session->set_flashdata('error', $this->lang->line('order_not_found'));
  245.         redirect(RESTAURANTS_PATH);
  246.       }
  247.  
  248.         $this->load->view("restaurants/view", $this->dataModule);
  249.  
  250.     }
  251.  
  252.     function invoice($id) {
  253.  
  254.         $where = array('o.restaurent_id='=>$id, 'o.status'=>1, 'e.status'=>1);
  255.         $columns = "o.*, e.admin_charge_amount, e.owners_amount, e.total_amount, e.payment_status, e.payment_date";
  256.         $join = array(TBL_EARNINGS.' as e'=>"e.order_id=o.id");
  257.         $group_by = 'o.id';
  258.         $this->dataModule['invoice_info']=  $this->Sitefunction->get_all_rows(TBL_ORDERS.' as o', $columns, $where, $join, array('o.id'=>'desc'), '', 'INNER', array(), $group_by, array(), array());
  259.  
  260.         $this->dataModule['controller']=$this;
  261.         $this->dataModule['restaurant_id']= $id;
  262.         $this->load->view("restaurants/invoice", $this->dataModule);
  263.  
  264.  
  265.     }
  266.  
  267.     function pay($id, $payable_Amount) {
  268.  
  269.        
  270.         if($this->sendInvoiceEmailToOwner($id, $payable_Amount)) {
  271.             $this->Sitefunction->update(TBL_EARNINGS, array('payment_status'=>1, 'payment_date'=>$this->utc_time), array('restaurent_id'=>$id, 'payment_status'=>0, 'status'=>1));          
  272.             $this->session->set_flashdata('success', $this->lang->line('payment_mail_sent'));
  273.         }else {
  274.             $this->session->set_flashdata('error', $this->lang->line('error_try_again'));
  275.         }
  276.         redirect(RESTAURANTS_PATH.'/invoice/'.$id);
  277.     }
  278. }
  279. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement