<?php
defined('BASEPATH') OR exit('No direct script access allowed');
define("SITE_URL", 'http://techimmense.in/CineramaMaps/');

class Admin extends CI_Controller

{
    
  /**
   * Index Page for this controller.
   *
   * Maps to the following URL
   *    http://example.com/index.php/welcome
   *  - or -
   *    http://example.com/index.php/welcome/index
   *  - or -
   * Since this controller is set as the default controller in
   * config/routes.php, it's displayed at http://example.com/
   *
   * So any other public methods not prefixed with an underscore will
   * map to /index.php/welcome/<method_name>
   * @see https://codeigniter.com/user_guide/general/urls.html
   */ function upt_user_stts()
  {
      $status = $this->input->post('status');
      $id = $this->input->post('id');
      $this->admin_common_model->update_data("users",['status'=>$status],['id'=>$id]);
      
  }
  function __construct()
  {
                parent::__construct();
                $this->load->helper('url');
                $this->load->model('admin/authentication_model');                
                $this->load->model('admin/admin_common_model');
                $this->load->library(array('form_validation','session'));
                $this->load->helper('string');
                $this->load->model('Webservice_model');
                error_reporting(0);
                 define("SITE_EMAIL",'info@CineramaMaps.com'); 
               
  

  }

  public

  function index()
  {
    $this->load->view('admin/index');
  }


  public

  function dashboard()
  {
    $this->load->view('admin/dashboard');
    
  }
  
  

public

function upload_user()
{
                $arr_data = $this->input->post();
 $lot_id = $arr_data['lot_id'];
 $warranty_month= $arr_data['warranty_month'];

	  $file = $_FILES['user_file']['name'];
	  $ext = end(explode('.', $file));
	
//echo "dfdf";die;
	
	if($ext =="xls" || $ext =="xlsx")
  {
		
        //  $file = $_FILES['user_file']['tmp_name'];
      
      $this->load->library("excel");
  if(isset($_FILES["user_file"]["name"]))
  {
     
                         
      
   $path = $_FILES["user_file"]["tmp_name"];
   $object = PHPExcel_IOFactory::load($path);
   foreach($object->getWorksheetIterator() as $worksheet)
   {
    $highestRow = $worksheet->getHighestRow();
    $highestColumn = $worksheet->getHighestColumn();
    for($row=2; $row<=$highestRow; $row++)
    {
		
	
        
		
     $item0 = $worksheet->getCellByColumnAndRow(0, $row)->getValue();
    
         $arrr_data =   array(
                                  
'serial_number' => $item0 ,
'lot_id' => $lot_id,
'warranty_month' => $warranty_month ,
);
                  
             
          $fetch = $this->admin_common_model->insert_data('lots', $arrr_data);

    }
   }
   
  //print_r($data);die;
  

           $this->session->set_flashdata('msg','file data import successfully');
           redirect("admin/view_page/uploadLocationList");


	}

  } else{
		//echo "other";die;
           $this->session->set_flashdata('msg','The file you are trying to upload is invalid format');
           redirect("admin/view_page/uploadLocationList");
        }
}
 public

  function view_page($page)
  {
     $this->load->view('admin/'.$page);
  }
  

       ///////////////////////



	function insert($table,$data)
 {
  $this->db->insert_batch($table, $data);
 }


function goProDe()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
       $delete = $this->db->query("DELETE FROM users WHERE id IN ($idStr)");
       }
       
       //echo"hello1";die;
        redirect('admin/view_page/driver_list_deactive');
        
	  }
	  
	  if($_POST['APPROVE'] == 'APPROVE'){
		     $idStr = implode(',',$_POST['checked_id']);
		     if($idStr){
		     $delete = $this->db->query("UPDATE users set status = 'Active' WHERE id IN ($idStr)");
		     }
        redirect('admin/view_page/driver_list_deactive');
	   }
	  
	   if($_POST['DISAPPROVE'] == 'DISAPPROVE'){
		     $idStr = implode(',',$_POST['checked_id']);
		     if($idStr){
		   $delete = $this->db->query("UPDATE users set status = 'Deactive' WHERE id IN ($idStr)");
		     }
        redirect('admin/view_page/driver_list_deactive');
		   
	   }
	  
	  
  } 
	
 function goPro_timeSlot()
  {
     
	  
	 
	  
	  if($_POST['UPDATE'] == 'UPDATE'){
		     $idStr = implode(',',$_POST['checked_id']);
		     if($idStr){
		     $delete = $this->db->query("UPDATE barber_time_slot set status = 'Active' WHERE id IN ($idStr)");
		     }
        redirect('admin/view_page/setting_list1');
	   }
	  
	  
	  
	  
  } 
		
	
	
  function goPro()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
       $delete = $this->db->query("DELETE FROM users WHERE id IN ($idStr)");
       }
       
       //echo"hello1";die;
        redirect('admin/view_page/driver_list');
        
	  }
	  
	  if($_POST['APPROVE'] == 'APPROVE'){
		     $idStr = implode(',',$_POST['checked_id']);
		     if($idStr){
		     $delete = $this->db->query("UPDATE users set status = 'Active' WHERE id IN ($idStr)");
		     }
        redirect('admin/view_page/driver_list');
	   }
	  
	   if($_POST['DISAPPROVE'] == 'DISAPPROVE'){
		     $idStr = implode(',',$_POST['checked_id']);
		     if($idStr){
		   $delete = $this->db->query("UPDATE users set status = 'Deactive' WHERE id IN ($idStr)");
		     }
        redirect('admin/view_page/driver_list');
		   
	   }
	  
	  
  } 
	
		
  function goOffer()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
             $result = $this->admin_common_model->get_where('coupons',['id'=>$idStr]);

$c_new = $result[0]['code'];
       $delete = $this->db->query("DELETE FROM coupons WHERE code = '$c_new'");
       $delete = $this->db->query("DELETE FROM notification WHERE code = '$c_new'");
       }
       
       //echo"hello1";die;
        redirect('admin/view_page/couponList');
        
	  }
	  
	  
	  
  } 
	
	
		
  function goProService()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
                  $delete = $this->db->query("DELETE FROM category_service WHERE id IN ($idStr)");

       }
       
       //echo"hello1";die;
        redirect('admin/view_page/category_service_list');
        
	  }
	  
	  
	  
  } 
  
   function goRequest1()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
                  $delete = $this->db->query("DELETE FROM user_request WHERE id IN ($idStr)");

       }
       
       //echo"hello1";die;
        redirect('admin/view_page/pending_ride');
        
	  }
	  
	  
  } 

  function goRequest2()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
                  $delete = $this->db->query("DELETE FROM user_request WHERE id IN ($idStr)");

       }
       
       //echo"hello1";die;
        redirect('admin/view_page/just_booked');
        
	  }
	  
	  
  } 
  
    function goRequest3()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
                  $delete = $this->db->query("DELETE FROM user_request WHERE id IN ($idStr)");

       }
       
       //echo"hello1";die;
        redirect('admin/view_page/complete_ride');
        
	  }
	  
	  
  } 

	
	
	  function goRequest4()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
                  $delete = $this->db->query("DELETE FROM user_request WHERE id IN ($idStr)");

       }
       
       //echo"hello1";die;
        redirect('admin/view_page/cancel_ride');
        
	  }
	  
	  
  } 

	function goAdminNoti(){
	    
	    	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
       $delete = $this->db->query("DELETE FROM notification WHERE id IN ($idStr)");
       }
       
       //echo"hello1";die;
        redirect('admin/view_page/adminNoti_list');
        
	  }
	  
	}
	
	function goUserNoti()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
                       $user_d = $this->admin_common_model->get_where('notification',['id'=>$idStr]);
$code = $user_d[0]['code'];
         //  echo"hello";die;
           
       $delete = $this->db->query("DELETE FROM notification WHERE code IN ($code)");
       }
       
       //echo"hello1";die;
        redirect('admin/view_page/userNoti_list');
        
	  }
	  
	  
	  
  } 
	
	
	
	
	function goUser()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
       $delete = $this->db->query("DELETE FROM users WHERE id IN ($idStr)");
       }
       
       //echo"hello1";die;
        redirect('admin/view_page/user_list');
        
	  }
	  
	  
	  
  } 
	
	
	
		function goDriverNoti()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
             $user_d = $this->admin_common_model->get_where('notification',['id'=>$idStr]);
$code = $user_d[0]['code'];
         //  echo"hello";die;
           
       $delete = $this->db->query("DELETE FROM notification WHERE code IN ($code)");
       
           
         //  echo"hello";die;
           
       }
       
       //echo"hello1";die;
        redirect('admin/view_page/driverNoti_list');
        
	  }
	  
	  
	  
  } 
	
	
		function goFeedback1()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
       $delete = $this->db->query("DELETE FROM rating_review WHERE id IN ($idStr)");
       }
       
       //echo"hello1";die;
        redirect('admin/view_page/feedback_list1');
        
	  }
	  
	  
	  
  } 
	
	
	function goFeedback()
  {
     
	  
	  if($_POST['DELETE'] == 'DELETE'){
	      
	       
	       
      $idStr = implode(',',$_POST['checked_id']);
      //print_r($idStr);die;
       // $delete = $this->$db->query("DELETE FROM users WHERE id IN ($idStr)");
       if($idStr){
           
         //  echo"hello";die;
           
       $delete = $this->db->query("DELETE FROM rating_review WHERE id IN ($idStr)");
       }
       
       //echo"hello1";die;
        redirect('admin/view_page/feedback_list');
        
	  }
	  
	  
	  
  } 
	
	
	
	public function upt_provider_profile_details(){
	    
	     $status = $this->input->post('status');
      $id = $this->input->post('id');
      
      if($status == 'Active'){
          
            $user_d = $this->admin_common_model->get_where('user_update',['id'=>$id]);

            $store_id = $user_d[0]['store_id'];
            
                        $user_p = $this->admin_common_model->get_where('users',['id'=>$store_id]);

if($user_d[0]['store_logo']){
    $store_logo = $user_d[0]['store_logo'];
}else{
    $store_logo = $user_p[0]['store_logo'];
    
}

if($user_d[0]['store_cover_image']){
    $store_cover_image = $user_d[0]['store_cover_image'];
}else{
    $store_cover_image = $user_p[0]['store_cover_image'];
    
}
           
            $arr_data = [
           'first_name'=>$user_d[0]['first_name'],
           'last_name'=>$user_d[0]['last_name'],
           'email'=>$user_d[0]['email'],
           'store_name'=>$user_d[0]['store_name'],
           'tax_number'=>$user_d[0]['tax_number'],
           'address'=>$user_d[0]['address'],
           'lat'=>$user_d[0]['lat'],
           'lon'=>$user_d[0]['lon'],
           'gender_type'=>$user_d[0]['gender_type'],
           'cat_id'=>$user_d[0]['cat_id'],
           'cat_name'=>$user_d[0]['cat_name'],
           'indoor_service'=>$user_d[0]['indoor_service'],
           'outdoor_service'=>$user_d[0]['outdoor_service'],
           'about_store'=>$user_d[0]['about_store'],
           'licence_id'=>$user_d[0]['licence_id'],
           'licence_issue_date'=>$user_d[0]['licence_issue_date'],
           'licence_expire_date'=>$user_d[0]['licence_expire_date'],
           'bank_name'=>$user_d[0]['bank_name'],
           'Iban_id'=>$user_d[0]['Iban_id'],
           'account_number'=>$user_d[0]['account_number'],
           'store_logo'=>$store_logo,
           'store_cover_image'=>$store_cover_image,
            ];

          
           $this->admin_common_model->update_data("users",$arr_data,['id'=>$store_id]);
           
           $this->admin_common_model->update_data("user_update",['status'=>$status],['id'=>$id]);



   // send notification for Andriod

                 
           
            $key = "your profile details has been approved by admin";
            
                   $user_message_apk = array(
                             "message" => array(
                             "result" => "successful",
                             "key" => $key,
                             "date"=> date('Y-m-d h:i:s')
                           )
                         );
                         
                         
                         $user_message_apk_ios = array(
            "message" => array(
              "result" => "successful",
              "key" => $key,
              "ios_status" =>$key,
              "title" => $key,
              "message" => $key,
              "user_id" => '',
              "provider_id" =>'',
              "category_name" => '',
              "user_name" => '',
              "receiver_id" => '',
              "request_id" => ''
            )
        );
                  
                        $register_userid = array($user_p[0]['register_id']);
                        $this->admin_common_model->driver_apk_notification($register_userid, $user_message_apk);
                        $this->admin_common_model->ios_provider_notification_new($user_p[0]['ios_register_id'],$user_message_apk_ios['message']);
                        // end send notification for Andriod  
  
  

      }

 
 
	}
	



 public function update_driver_choice(){
     
        $driver_choice = $this->input->post('driver_choice');
        $id = $this->input->post('id');
        
        $this->admin_common_model->update_data('admin',['driver_choice'=>$driver_choice],['id'=>$id]);


 }


 public function update_direct_accepted(){
     
        $direct_accepted = $this->input->post('direct_accepted');
        $id = $this->input->post('id');
        
        $this->admin_common_model->update_data('admin',['direct_accepted'=>$direct_accepted],['id'=>$id]);


 }

 public function remove_status(){
     
        $table = $this->input->post('table');
        $id = $this->input->post('id');
        
        $this->admin_common_model->update_data($table,['remove_status'=>'Yes'],['id'=>$id]);

       // $this->admin_common_model->delete_data($table,['id'=>$id]);
  
 }
 
 
 
 
 public function update_noti_status(){
     
        $table = 'notification';
        $id = $this->input->post('id');
        
        $this->admin_common_model->update_data($table,['seen_status'=>'SEEN'],['notification_type'=>'Profile']);

       // $this->admin_common_model->delete_data($table,['id'=>$id]);
  
 }
 
 
 
 function getTag()
{
  $category_id = $_POST['country_id'];
  $result = $this->admin_common_model->get_where('tags',['country_id'=>$category_id]);
  foreach($result as $val){
   echo "<option  value='".$val['id']."'>". $val['tag_name']."</option>";
 }
 

}


 function getTag1()
{
  $category_id = $_POST['city_id'];
  $result = $this->admin_common_model->get_where('tags',['city_id'=>$category_id]);
  foreach($result as $val){
   echo "<option  value='".$val['id']."'>". $val['tag_name']."</option>";
 }
 

}

 function get_sub_category()
{
  $category_id = $_POST['country_id'];
  $result = $this->admin_common_model->get_where('country_map_city',['country_id'=>$category_id]);
  foreach($result as $val){
   echo "<option value='".$val['id']."'>".$val['name']."</option>";
 }
 

}


 function get_sub_category1()
{
 
              
  $category_id = $_POST['lot_id'];
  $roll_id = $_POST['roll_id'];
  $result = $this->admin_common_model->get_where('lots',['lot_id'=>$category_id,'roll_id'=>$roll_id]);
  foreach($result as $val){
   echo "<option value='".$val['serial_number']."'>".$val['serial_number']."</option>";
 }
 

}



function getTimeSlot(){
    
            $day_id = $_POST['day_id'];


        $fetch_day = $this->db->query("SELECT * FROM days where id = '$day_id' ")->result_array();
$day_name=$fetch_day[0]['name'];

        $fetch = $this->db->query("SELECT * FROM users where id = '0' ")->result_array();

 $a_open_time = '08:00';
$a_close_time = '21:00';
 $diff = strtotime($a_close_time) - strtotime($a_open_time);
$diff = $diff/3600;


$k = $diff*2;
for($j =1; $j <= $k; $j++){
  // echo $q = 30 * $j;
   
   $Start = "12:00:00";
$Minutes = 30 ;
if($j == '1'){
 $To = date("H:i", strtotime($a_open_time)+($Minutes*60));
}else{
    
 $To = date("H:i", strtotime($To)+($Minutes*60));
    
}

    $v1 = date('H:i',strtotime('-30 minutes',strtotime($To)));

   $fetch[0]['time_slot'] = $v1 .' - '.$To; 
   $time_slot1 = $v1 .' - '.$To;
   
    
    $fetch_check = $this->db->query("SELECT * FROM barber_time_slot where barber_id = '$barber_id' AND day_name = '$day_name' AND time_slot = '$time_slot1'")->result_array();
if($fetch_check){
   $fetch[0]['add_time_slot'] = 'Yes';
   
         echo "<option selected='selected' value='".$time_slot1."'>".$time_slot1."</option>";

}else{
   $fetch[0]['add_time_slot'] = 'No';
   

}

            echo "<option  value='".$time_slot1."'>".$time_slot1."</option>";



      
      }
      
      
      
    $category_id = $_POST['category_id'];
  $result = $this->admin_common_model->get_where('sub_category',['category_id'=>$category_id]);
  echo "<option value=''>Select Subcategory</option>";
  foreach($result as $val){
   echo "<option value='".$val['id']."'>".$val['name']."</option>";
 }
 
}
 
 function get_child_category()
{
  $category_id = $_POST['sub_cat_id'];
  $result = $this->admin_common_model->get_where('chaild_sub_category',['sub_cat_id'=>$category_id]);
  echo "<option value=''>Select Child category</option>";
  foreach($result as $val){
   echo "<option value='".$val['id']."'>".$val['name']."</option>";
 }
 

}


  public

  function go()
  {
    
      $result = $this->authentication_model->admin_login();
     // echo $result;die;
      if($result=='0') {
          // echo $result;die;
        $msg = array(
           'msg' =>'<strong>Error!</strong> Invalid Username and Password. Log in failed.','res' => 0
              );
                             $this->session->set_userdata($msg);
                             redirect('admin');
      }else if($result =='2'){
          // echo $result;die;
          $msg = array(
           'msg' =>'<strong>Error!</strong> Wait for admin approval.','res' => 0
              );
                             $this->session->set_userdata($msg);
                             redirect('admin');
      }
      else {
          // echo $result;die;
        redirect('admin/dashboard', $message);
      }
    
  }  

  

  public function admin_logout(){
        $this->session->unset_userdata('admin');
        return redirect('admin');   
  }






function update_category_status()
  {
      $status = $this->input->post('status');
      $id = $this->input->post('id');

 
                 
                	  $this->admin_common_model->update_data("category",['status'=>$status],['id'=>$id]);
  


  }
  
  

 
 
 
 
 
 
 
 
  public

  function find_location()
  {	 
	 $locaion = $this->input->get_post('locaion');
	 $type = $this->input->get_post('type');
	 if($type=='USER'){
		 $data['lat'] = $this->input->get_post('lat'); $data['lon'] = $this->input->get_post('lon');
	 	 $this->load->view('admin/map_avail_users',$data);
	 }else{
		 $data['lat'] = $this->input->get_post('lat'); $data['lon'] = $this->input->get_post('lon');
		 $this->load->view('admin/map_avail_drivers',$data);
	 } 
  }
	
	
  function upt_driver_stts()
  {
		  $status = $this->input->post('available_status');
		  $id = $this->input->post('id');
	   
      	  $this->admin_common_model->update_data("users",['available_status'=>$status],['id'=>$id]);
      	   

  }	
  
  
  
  

  
  
  
  
  
  function upt_driver_stts123()
  {
		  $status = $this->input->post('payment_verified');
		  $id = $this->input->post('id');
	   
      	  $this->admin_common_model->update_data("user_request",['payment_verified'=>$status],['id'=>$id]);
      	   
      	   
      	           $arr_get_user = ['id'=>$id];

                   $login_request = $this->admin_common_model->get_where('user_request',$arr_get_user);
                   
                   
                   $arr_get_user = ['id'=>$login_request[0]['user_id']];

                   $login_user = $this->admin_common_model->get_where('users',$arr_get_user);
                   
                   
                   
                      
                             // send notification for user driver


                   
   if($status == 'Unverified'){     
                   $key = "Payment not paid";

                   $user_message_apk = array(
                             "message" => array(
                             "result" => "successful",
                             "key" => $key,
                             "request_id" => $id,
                             "date"=> date('Y-m-d h:i:s')
                           )
                         );
                  

                        $register_userid = array($login_user[0]['register_id']);

                      $this->admin_common_model->user_apk_notification($register_userid, $user_message_apk);
}else{
    
      $key = "Payment has been confirmed and Ambulance in is on the way";

                   $user_message_apk = array(
                             "message" => array(
                             "result" => "successful",
                             "key" => $key,
                             "request_id" => $id,
                             "date"=> date('Y-m-d h:i:s')
                           )
                         );
                  

                        $register_userid = array($login_user[0]['register_id']);

                      $this->admin_common_model->user_apk_notification($register_userid, $user_message_apk);
}
              // end send notification for Andriod  user
  }	

  


  function upt_withdraw_status()
  {
		  $status = $this->input->post('status');
		  $id = $this->input->post('id');
	   
      	  $this->admin_common_model->update_data("withdraw_request",['status'=>$status],['id'=>$id]);
      	  
      	 if($status == 'Complete'){
      	   $result_req = $this->admin_common_model->get_where('withdraw_request',['id'=>$id]);
  $user_id=  $result_req[0]['user_id'];
  $amount =  $result_req[0][amount];
  
  $result_user = $this->admin_common_model->get_where('users',['id'=>$user_id]);
  $user_wallet = $result_user[0]['wallet'];
  $req_wallet = $user_wallet - $amount;
  
      $this->admin_common_model->update_data("users",['wallet'=>$req_wallet],['id'=>$user_id]);
      
      	 }
      	   
  }	



  public function forgot_password()
    {
      $email = $this->input->post('email', TRUE);
      $arr_login = ['email' => $email];

      $login = $this->admin_common_model->fetch_recordbyid('admin', $arr_login);

      if ($login)
      {
        $pass = random_string('alnum', 6);

        $to = $email;
        $subject = "Forgot Password";
        $body = "<div style='max-width: 600px; width: 100%; margin-left: auto; margin-right: auto;'>
        <header style='color: #fff; width: 100%;'>
           <img alt='' src='".base_url('uploads/images/logo.png')."' width ='120' height='120'/>
        </header>
        
        <div style='margin-top: 10px; padding-right: 10px; 
      padding-left: 125px;
      padding-bottom: 20px;'>
          <hr>
          <h3 style='color: #232F3F;'>Hello ".$login->name.",</h3>
          <p>You have requested a new password for your doctor account.</p>
          <p>Your new password is <span style='background:#2196F3;color:white;padding:0px 5px'>".$pass."</span></p>
          <hr>
          
            <p>Warm Regards<br>CineramaMaps<br>Support Team</p>
            
          </div>
        </div>

    </div>";

       

        $headers = "From: info@CineramaMaps.com" . "\r\n";
        $headers.= "MIME-Version: 1.0" . "\r\n";
        $headers.= "Content-type:text/html;charset=UTF-8" . "\r\n";



          mail($to, $subject, $body, $headers);


          $this->admin_common_model->update_data('admin',['password'=>$pass],$arr_login);
        
      }
      else
      {
          $msg = array(
           'msg' =>'<strong>Error!</strong> This email is not registered to SocialRyde.','res' => 0
              );
                             $this->session->set_userdata($msg);
        redirect('admin/view_page/forgotpassword');
      }

        $msg = array(
              'success' =>'<strong>Success!</strong> Your new password has been send your registered email address.'
              );
                             $this->session->set_flashdata($msg);
        redirect('admin/view_page/forgotpassword');
      
    }

  
 
  public function delete_data(){
        $table = $this->input->post('table');
        $id = $this->input->post('id');
        $this->admin_common_model->delete_data($table,['id'=>$id]);
        //echo $this->db->last_query();
  }
  
  public function delete_data_new(){
        $table = $this->input->post('table');
        $id = $this->input->post('id');
        
                 $fetch = $this->admin_common_model->get_where('coupons',['id'=>$id]);
$code = $fetch[0]['code'];

        $this->admin_common_model->delete_data($table,['code'=>$code]);
        //echo $this->db->last_query();
  }
  
  
  public function send_money(){
        $table = $this->input->post('table');
        $id = $this->input->post('id');
        
         $fetch = $this->admin_common_model->get_where('notification',['id'=>$id]);
         $row = $fetch[0];
        
                $start_date = $row['start_date'];
                $end_date = $row['end_date'];
                $driver_type = $row['driver_type'];

        $apply_amount = $row['apply_amount'];
        $incentive_amount = $row['incentive_amount'];
        $driver_type = $row['driver_type'];
         $driver_list = $this->db->query("SELECT * , sum(total_amount) as total_amount FROM `user_request` WHERE  status = 'Complete' AND  request_type = '$driver_type' AND   date >= '$start_date' AND  date <= '$end_date' group by accept_driver_id  order by total_amount desc")->result_array();
      
      $i=2; foreach($driver_list as $row1){ 
                            if($apply_amount > $row1['total_amount']){
                                continue;
                             }
                           
                             $arr_data = [
                                    'noti_id'=>$id,
                                    'driver_id'=>$row1['accept_driver_id'],
                                    'total_amount'=>$incentive_amount
                                    ];
            
            
                           $id = $this->admin_common_model->insert_data('insentive_amount',$arr_data);
  
  
                          $arrr_get =   array(
                                     'id'=>$row1['accept_driver_id']
                                );
                  
                              $login = $this->admin_common_model->get_where('users',$arrr_get);
$wallet = $login[0]['wallet'];
$wallet = $wallet + $incentive_amount;
                               $this->admin_common_model->update_data('users',['wallet'=>$wallet],$arrr_get);
                            
                             
                  $i++;             
      }
  }

   public function create_owner(){
       
       $user_id = $this->input->post('user_id');
       $shop_id = $this->input->post('shop_id');
       if($shop_id!=''){
         $this->admin_common_model->update_data('shop',['user_id'=>$user_id],['id'=>$shop_id]);
       }
       return redirect('admin/view_page/userList');   
  }

  function updateStatus()
  {
      $status = $_POST['status'];
      $id = $_POST['id'];
      $this->admin_common_model->update_data("place_order",['status'=>$status],['id'=>$id]);
      return redirect('admin/view_page/orderList');
  }


  function upt_cat()
  {
      $status = $this->input->post('status');
      $id = $this->input->post('id');
      $this->admin_common_model->update_data("category",['status'=>$status],['id'=>$id]);
      
  }

  function upt_sub_cat()
  {
      $status = $this->input->post('status');
      $id = $this->input->post('id');
      $this->admin_common_model->update_data("sub_category",['status'=>$status],['id'=>$id]);
      
  }


// end class
}
