%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/public_html/website_1ec2d7c2/apps/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/public_html/website_1ec2d7c2/apps/models/User.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class User extends CI_Controller {
	
	
	function __construct(){
		
	 parent::__construct();
	$this->load->library('form_validation');	
    $this->load->helper(array('form', 'url')); 	 
    $this->load->helper('cookie');
    $this->load->helper('common');
   //
  
    $this->load->library('session'); 
    $this->load->helper('security');
    $this->load->library('email'); 
    $this->load->library('encrypt');
  // Custom Ours
  
     $this->load->library('login');   
    // $this->login->check_login();	 
     $this->load->model('content_model');   
     $this->load->model('listing_model');   
     $this->load->model('user_model');   
     $this->load->model('commonmod_model');
	 $this->load->model('address_model');
	 $this->load->model('order_model');   
     $this->load->database();
    require_once APPPATH.'third_party/src/Google_Client.php';
	require_once APPPATH.'third_party/src/contrib/Google_Oauth2Service.php';	 
	}

	
	
	public function glogin()
	{
		//$data['ALL_USER_DATA'] =  $this->user_model->getALLUser();
		$data = array();
		$data['Content'] =  $this->content_model->GetContentByID(13);
		$clientId = '753224894483-7pes72n8b1n2nv670iolp0ntmvjjp7rt.apps.googleusercontent.com'; //Google client ID
		$clientSecret = 'P9GMvudV6lXADMd8heQaq5Bf'; //Google client secret
		$redirectURL = base_url() . 'user/glogin/';
		
		//Call Google API
		$gClient = new Google_Client();
		$gClient->setApplicationName('Login');
		$gClient->setClientId($clientId);
		$gClient->setClientSecret($clientSecret);
		$gClient->setRedirectUri($redirectURL);
		$google_oauthV2 = new Google_Oauth2Service($gClient);
		
		if(isset($_GET['code']))
		{
			$gClient->authenticate($_GET['code']);
			$_SESSION['token'] = $gClient->getAccessToken();
			header('Location: ' . filter_var($redirectURL, FILTER_SANITIZE_URL));
		}

		if (isset($_SESSION['token'])) 
		{
			$gClient->setAccessToken($_SESSION['token']);
		}
		
		if ($gClient->getAccessToken()) {
            $userProfile = $google_oauthV2->userinfo->get();
			
			
			$email =  $userProfile['email'];
			$first_name =  $userProfile['given_name'];
			$last_name =  $userProfile['family_name'];
			$picture =  $userProfile['picture'];
			$verified_email =  $userProfile['verified_email'];
			$google_id =  $userProfile['id'];
			
			$dataR = $this->user_model->CheckGoogledata($email,$first_name,$last_name,$picture,$verified_email,$google_id);
			if (count($this->cart->contents()) > 0){
			
			redirect(BASE_URL.'tarrif.html?openpopup=1');
			}
        } 
		else 
		{
            $url = $gClient->createAuthUrl();
		    header("Location: $url");
            exit;
        }
          
	}
	
	
		public function login()
	{
		//$data['ALL_USER_DATA'] =  $this->user_model->getALLUser();
		$data = array();
		$data['Content'] =  $this->content_model->GetContentByID(26);
		  if($this->input->post('submitF') && $this->input->post('submitF')!="") 
		 {		
		$config = array(

			array(
			'field' => 'email_id',
			'label' => 'Email Id',
			'rules' => 'trim|required|min_length[5]|xss_clean'
			),
			array(
			'field' => 'password',
			'label' => 'Password',
			'rules' => 'trim|required|min_length[5]|md5|xss_clean'
			)
		); 

	    $this->form_validation->set_rules($config);
        
		if ($this->form_validation->run() === FALSE)
		{

		$this->load->view('front/user/login',$data);
		}
        else
        {
            $email = set_value('email_id');
            $password = set_value('password');
			 $email = $this->security->xss_clean($email);
			 $password = $this->security->xss_clean($password);

            $this->db->select("*");			
			$this->db->from('bh_users');	
			$this->db->where(array("email_id"=>$email));
			$query=$this->db->get();
			$datachk=$query->row_array();             			
				
			
            /* check login */
            $this->login->process_front_login($email, $password);
            /* ------ */			
            if ($this->session->userdata('front_logged_in') == '')
				{ 
                // display login error
				 $this->session->set_flashdata('error','Either your email address or password is incorrect. It May be your account is not approved'); 
				
                  $this->load->view('front/user/login',$data);
                //return redirect(SITEURL."register/signin");				
            }
            else
            {	
				if (count($this->cart->contents()) > 0){
                    redirect(BASE_URL.'search/submit_request');
				}
              else if($this->input->post('return_url')!=""){
					return redirect($this->input->post('return_url'));
			  }
				 else if($this->session->userdata('checkout_cart')=="YES"){
					return redirect(BASE_URL."shipping.htm");
				 }
				else {
					return redirect(BASE_URL."myaccount");
				}
              
            }
			
			 // else password is not blanck 

        }
	 }else{
		$this->load->view('front/user/login',$data);
	 }
	}
	
		public function forgotpassword()
	{
		//$data['ALL_USER_DATA'] =  $this->user_model->getALLUser();
		$data = array();
		$data['Content'] =  $this->content_model->GetContentByID(18);
		  if($this->input->post('submitF') && $this->input->post('submitF')!="") 
		 {		
		$config = array(

			array(
			'field' => 'email_id',
			'label' => 'Email Id',
			'rules' => 'trim|required|min_length[5]|xss_clean'
			)
		); 

	    $this->form_validation->set_rules($config);
        
		if ($this->form_validation->run() === FALSE)
		{

		$this->load->view('front/user/forgotpassword',$data);
		}
        else
        {
            $email = $this->security->xss_clean($this->input->post('email_id'));
         
					

            $this->db->select("*");			
			$this->db->from('bh_users');	
			$this->db->where(array("email_id"=>$email));
			$query=$this->db->get();
			$user_data = $query->row_array();             			
			
			if(count($user_data) > 0){
				$reset_pass_key =  mt_rand(100000, 999999);
				$upd_data = array("reset_pass_key"=>$reset_pass_key);
				  $this->db->where('email_id', $email);
			      $this->db->update('bh_users', $upd_data);
				  
				    $User_EmailId = $email;
		  
		      $config['protocol']    = 'smtp';
        $config['smtp_host']    = 'ssl://mail.mpl-liner.com';
        $config['smtp_port']    = '465';
        $config['smtp_timeout'] = '7';
        $config['smtp_user']    = 'info@mpl-liner.com';
        $config['smtp_pass']    = 'Omsai@123#$';
        $config['charset']    = 'utf-8';
        $config['newline']    = "\r\n";
        $config['mailtype'] = 'html'; // or html
        $config['validation'] = TRUE; // bool whether to validate email or not      

				$this->email->initialize($config);
				$this->email->from(FROM_EMAIL, FROM_NAME);
				$this->email->to($User_EmailId);
				//$this->email->cc(CC_EMAIL_ID);
				//$this->email->bcc('them@their-example.com');

				$this->email->subject('Reset Password |'.WEBSITE_EMAIL_TITLE);
				$message = '<h2>'.WEBSITE_EMAIL_TITLE.'</h2>';
				$message .= '<p>Hi '.trim($user_data['first_name']).'  <br> Please <a href="'.BASE_URL.'user/resetpassword/'.$user_data['user_id'].'/'.$reset_pass_key.'">Click here</a> to reset your password <br> '.BASE_URL.'user/resetpassword/'.$user_data['user_id'].'/'.$reset_pass_key.'</p>';
				

				$message .='<p>Thanks <br>
				'.WEBSITE_SIGNATURE.'
				</p>';

				$this->email->message($message);

				$this->email->send();
			
			$this->session->set_flashdata('error',"A reset password email have sent to you, Please check inbox/spam jumk folders.");
			
			redirect(BASE_URL.'login');
			
			
			
			
			}else{
				
			}
            

        }
	 }else{
		$this->load->view('front/user/forgotpassword',$data);
	 }
	}
	
	public function myaccount()
	{
		$this->login->check_front_login();	
		$data['Content'] =  $this->content_model->GetContentByID(15);
		$data['UserData'] =  $this->user_model->UserByID($this->session->userdata('bh_front_user_id'));
		$this->load->view('front/user/myaccount',$data);	
	}
    
   
	
	public function changepassword()
	{
		$this->login->check_front_login();	
		$data['Content'] =  $this->content_model->GetContentByID(15);
			$data['UserData'] =  $this->user_model->UserByID($this->session->userdata('bh_front_user_id'));
		
		if($this->input->post('submitF') && $this->input->post('submitF')!="") 
		 {	
	 $config = array( 	           
			array('field' => 'password','label' => 'Password','rules' => 'trim|required|xss_clean|matches[password2]'),
			array('field' => 'password2','label' => 'Confirm Password','rules' => 'trim|required|xss_clean'),
			
			);
			
			$this->form_validation->set_rules($config);		
			if ($this->form_validation->run() === FALSE)
			{	

			$this->load->view('front/user/change-password',$data);
			
			}
			else{

		
			// Add new User Details
			$updata = array(
			'password' => md5($this->security->xss_clean($this->input->post('password')))
			); 
			 		

			$this->db->where('user_id', $this->session->userdata('bh_front_user_id'));
			$this->db->update('bh_users', $updata);
			$this->session->set_flashdata('error',"Password Changed");
			redirect(BASE_URL.'myaccount');
			}
			
				
			
			}
		 
		 else{
		$this->load->view('front/user/change-password',$data);
		 }
	}
	
	
	
	public function address()
	{
		$this->login->check_front_login();	
		$data['Content'] =  $this->content_model->GetContentByID(15);
			$data['UserData'] =  $this->user_model->UserByID($this->session->userdata('bh_front_user_id'));
		$data['AddressListing'] =  $this->address_model->GetUserSupportListing();
		$this->load->view('front/user/address',$data);	
	}
	public function order()
	{
		$this->login->check_front_login();	
		$data['Content'] =  $this->content_model->GetContentByID(22);
			$data['UserData'] =  $this->user_model->UserByID($this->session->userdata('bh_front_user_id'));
		$data['AllorderList'] =  $this->order_model->GetsAllorder($this->session->userdata('bh_front_user_id'));
		//$data['AddressListing'] =  $this->order_model->GetOrderListing();
		$this->load->view('front/user/order',$data);	
	}
	public function orderdetail($order_id)
	{
		$this->login->check_front_login();
			
		$data['Content'] =  $this->content_model->GetContentByID(23);
		$data['AllOrderlist'] = $this->order_model->ShoworderHistory($order_id);
			$data['UserData'] =  $this->user_model->UserByID($this->session->userdata('bh_front_user_id'));
		$data['AllorderproductList'] = $this->order_model->GetOrderListing($order_id);
		$data['Oneorder'] =  $this->order_model->GetOneorder($order_id);
		//$data['AddressListing'] =  $this->order_model->GetOrderListing();
		$this->load->view('front/user/orderdetail',$data);	
	}
  
	
	
   
	
	public function add_address()
	{
		$this->login->check_front_login();	
		$data['Content'] =  $this->content_model->GetContentByID(15);
			$data['UserData'] =  $this->user_model->UserByID($this->session->userdata('bh_front_user_id'));
			
			 if($this->input->post('submitF') && $this->input->post('submitF')!="") 
		 {	
	

	      $config = array( 	           
			array('field' => 'firstname','label' => 'First Name','rules' => 'trim|required|xss_clean'),
			array('field' => 'lastname','label' => 'Last Name','rules' => 'trim|required|xss_clean'),
			//array('field' => 'address_1','label' => 'Address1','rules' => 'trim|required|xss_clean'),
			array('field' => 'country_id','label' => 'Country','rules' => 'trim|required|xss_clean'),
			array('field' => 'state_id','label' => 'State','rules' => 'trim|required|xss_clean'),
			array('field' => 'city','label' => 'City','rules' => 'trim|required|xss_clean'),
			
			);
			
			$this->form_validation->set_rules($config);		
			if ($this->form_validation->run() === FALSE)
			{	

			$this->load->view('front/user/add-address',$data);
			
			}
			else{
			// Add new User Details
			$data = array(
			'firstname' => $this->security->xss_clean($this->input->post('firstname')),
			'lastname' => $this->security->xss_clean($this->input->post('lastname')),
			'country_id' => $this->security->xss_clean($this->input->post('country_id')),
			'state_id' => $this->security->xss_clean($this->input->post('state_id')),
			'city' => $this->security->xss_clean($this->input->post('city')),
			'address_1' => $this->security->xss_clean($this->input->post('address_1')),
			'address_2' => $this->security->xss_clean($this->input->post('address_2')),
			'postcode' => $this->security->xss_clean($this->input->post('postcode')),
			
			'user_id' => $this->session->userdata('bh_front_user_id'),
			
			); 
			 		

			$this->db->insert('bh_address', $data);
			$id = $this->db->insert_id();
			
			
			$this->session->set_flashdata('error',"Address Listing added");
			redirect(BASE_URL.'user/address');
			}
		 }else{
		$this->load->view('front/user/add-address',$data);
		 }
	
	}
	
	public function edit_address($id)
	{
		
		
		$this->login->check_front_login();	
		$data['Content'] =  $this->content_model->GetContentByID(15);
		$data['listing'] =  $this->address_model->GetSupportListingById($id);
		$data['UserData'] =  $this->user_model->UserByID($this->session->userdata('bh_front_user_id'));
			
			 if($this->input->post('submitF') && $this->input->post('submitF')!="") 
		 {	
	

	      $config = array( 	           
			//array('field' => 'firstname','label' => 'First Name','rules' => 'trim|required|xss_clean'),
			//array('field' => 'lastname','label' => 'Last Name','rules' => 'trim|required|xss_clean'),
			//array('field' => 'address_1','label' => 'Address1','rules' => 'trim|required|xss_clean'),
			array('field' => 'country_id','label' => 'Country','rules' => 'trim|required|xss_clean'),
			array('field' => 'state_id','label' => 'State','rules' => 'trim|required|xss_clean'),
			array('field' => 'city','label' => 'City','rules' => 'trim|required|xss_clean'),
			
			);
			
			$this->form_validation->set_rules($config);		
			if ($this->form_validation->run() === FALSE)
			{	

			$this->load->view('front/user/edit-address',$data);
			
			}
			else{
			// Add new User Details
			
			$data = array(
			'firstname' => $this->security->xss_clean($this->input->post('firstname')),
			'lastname' => $this->security->xss_clean($this->input->post('lastname')),
			'country_id' => $this->security->xss_clean($this->input->post('country_id')),
			'state_id' => $this->security->xss_clean($this->input->post('state_id')),
			'city' => $this->security->xss_clean($this->input->post('city')),
			'address_1' => $this->security->xss_clean($this->input->post('address_1')),
			'address_2' => $this->security->xss_clean($this->input->post('address_2')),
			'postcode' => $this->security->xss_clean($this->input->post('postcode')),
			'user_id' => $this->session->userdata('bh_front_user_id'),
			
			
			
			); 
			 		
               $this->db->where("address_id",$id);
		       $this->db->update('bh_address', $data);
			
			$this->session->set_flashdata('error',"Address Listing updated");
			redirect(BASE_URL.'user/address');
			}
		 }else{
		$this->load->view('front/user/edit-address',$data);
		 }
	
	}
	
	public function delete_address($id)
	{
		if($id!=''){
		$this->db->where("address_id",$id);
		$this->db->delete("bh_address");
		$this->session->set_flashdata('error',"Address Deleted");
			
		
		}
		redirect(BASE_URL.'user/address');	
	}
	
	
	
	
	
	
	public function edit_profile($id)
	{
		$this->login->check_front_login();	
		$data['Content'] =  $this->content_model->GetContentByID(15);
			$data['UserData'] =  $this->user_model->UserByID($this->session->userdata('bh_front_user_id'));
			
		 if($this->input->post('submitF') && $this->input->post('submitF')!="") 
		 {	
	  
        $config = array( 	           
			array('field' => 'first_name','label' => 'First Name','rules' => 'trim|required|xss_clean'),
			array('field' => 'last_name','label' => 'Last Name','rules' => 'trim|required|xss_clean'),
		
		
			);
			
			$this->form_validation->set_rules($config);		
			if ($this->form_validation->run() === FALSE)
			{	

			$this->load->view('front/user/edit-profile',$data);
			
			}
			else{
			// Add new User Details
			$upddata = array(
			'first_name' => $this->input->post('first_name'),
			'last_name' => $this->input->post('last_name'),
		    'id_proof_type'=>$this->input->post('id_proof_type'),
			'phone' => $this->input->post('phone'),
			'mobile' => $this->input->post('mobile'),
			
			
      );  		

			$this->db->where('user_id', $id);
			$this->db->update('bh_users', $upddata);
			
			if($this->input->post('password')!=""){
			$updata = array("password"=>md5($this->input->post('password')));
			$this->db->where('user_id', $user_id); 
			$this->db->update('bh_users', $updata);
			}
			
				if ($_FILES['user_image1']['name'])
				{	
						$error_view_url = 'admin/user/edit';			
						$FileName =  $this->commonmod_model->uploadCommonFile('./webroot/images/original/','./webroot/images/users/','2048','1000','700','user_image1',$error_view_url);
						if($FileName!=''){
						$upd_data = array("user_image1"=>$FileName);
						$this->db->where('user_id', $id);
						$this->db->update('bh_users', $upd_data);
						}
				}
				if ($_FILES['id_proof_file']['name'])
				{	
						$error_view_url = 'admin/user/edit';			
						$FileName =  $this->commonmod_model->uploadCommonFile('./webroot/images/original/','./webroot/images/users/','2048','1000','700','id_proof_file',$error_view_url);
						if($FileName!=''){
						$upd_data = array("id_proof_file"=>$FileName);
						$this->db->where('user_id', $id);
						$this->db->update('bh_users', $upd_data);
						}
				}
				
				
				
			
			$this->session->set_flashdata('error',"User Profile updated");
			redirect(BASE_URL.'myaccount');
			}
		 }else{
		$this->load->view('front/user/edit-profile',$data);
		 }
	}
	
	
	public function create_account()
	{
		 
	    $data['Content'] =  $this->content_model->GetContentByID(14);
		
	
		  if($this->input->post('submitF') && $this->input->post('submitF')!="") 
		 {	
	

	      $config = array( 	           
			array('field' => 'first_name','label' => 'First Name','rules' => 'trim|required|xss_clean'),
			array('field' => 'last_name','label' => 'Last Name','rules' => 'trim|required|xss_clean'),
			array('field' => 'email_id','label' => 'Email Id','rules' => 'trim|required|xss_clean'),
		
			
			array('field' => 'agree','label' => 'Agree Term and Condition','rules' => 'trim|required|xss_clean')
			);
			
			$this->form_validation->set_rules($config);		
			if ($this->form_validation->run() === FALSE)
			{	

			$this->load->view('front/user/register',$data);
			
			}
			
			$email = $this->input->post('email_id');
			$query = $this->db->get_where('bh_users', array('email_id' => $email));
			if ($query->num_rows() > 0) {
 		    
			   $this->session->set_flashdata('error',"Email already exists");
	           $this->load->view('front/user/register',$data);
			} 
			
			else{
				$verify_key = mt_rand(100000, 999999);
			// Add new User Details
			$data = array(
			'first_name' => $this->security->xss_clean($this->input->post('first_name')),
			'last_name' => $this->security->xss_clean($this->input->post('last_name')),
			'email_id' => $this->security->xss_clean($this->input->post('email_id')),
			'password' => md5($this->input->post('password2')),
			'phone' => $this->security->xss_clean($this->input->post('mobile1')),
			'mobile' => $this->security->xss_clean($this->input->post('mobile1')),
			
			'verify_key' => $verify_key,
			
			'status' => '2'

			
			);  		

			$this->db->insert('bh_users', $data);
			 $User_id = $this->db->insert_id();
			
			 
			 
			 
		
			
			/*  Send Admin Email  */ 
				 $config['protocol']    = 'smtp';
        $config['smtp_host']    = 'ssl://mail.mpl-liner.com';
        $config['smtp_port']    = '465';
        $config['smtp_timeout'] = '7';
        $config['smtp_user']    = 'info@mpl-liner.com';
        $config['smtp_pass']    = 'Omsai@123#$';
        $config['charset']    = 'utf-8';
        $config['newline']    = "\r\n";
        $config['mailtype'] = 'html'; // or html
        $config['validation'] = TRUE; // bool whether to validate email or not      

				$this->email->initialize($config);


				$this->email->from(FROM_EMAIL, FROM_NAME);
				$this->email->to(ADMIN_EMAIL_ID);
				$this->email->cc(CC_EMAIL_ID);
				//$this->email->bcc('them@their-example.com');

				$this->email->subject('New Account Created | '.WEBSITE_EMAIL_TITLE);
				$message = '<h2>'.WEBSITE_EMAIL_TITLE.'</h2>';
				$message .= '<p>'.$this->security->xss_clean($this->input->post('first_name')).' have registered with Us.</p>';
				$message .= '<p>Name: '.trim($this->security->xss_clean($this->input->post('first_name'))).' '.trim($this->security->xss_clean($this->input->post('last_name'))).'</p>';
				$message .= '<p>Email: '.trim($this->security->xss_clean($this->input->post('email_id'))).'</p>';
				
				$message .= '<p>Mobile: '.trim($this->security->xss_clean($this->input->post('mobile1'))).'</p>';
				

				$message .='<p>Thanks <br>
				'.WEBSITE_SIGNATURE.'
				</p>';

				$this->email->message($message);

				$this->email->send();
				
				
          /*  Send User Email  */ 
		  
		  $User_EmailId = $this->input->post('email_id');
		  
		    $config['protocol']    = 'smtp';
        $config['smtp_host']    = 'ssl://mail.mpl-liner.com';
        $config['smtp_port']    = '465';
        $config['smtp_timeout'] = '7';
        $config['smtp_user']    = 'info@mpl-liner.com';
        $config['smtp_pass']    = 'Omsai@123#$';
        $config['charset']    = 'utf-8';
        $config['newline']    = "\r\n";
        $config['mailtype'] = 'html'; // or html
        $config['validation'] = TRUE; // bool whether to validate email or not      

				$this->email->initialize($config);
				$this->email->from(FROM_EMAIL, FROM_NAME);
				$this->email->to($User_EmailId);
				//$this->email->cc(CC_EMAIL_ID);
				//$this->email->bcc('them@their-example.com');

				$this->email->subject('Account is created |'.WEBSITE_EMAIL_TITLE);
				$message = '<h2>'.WEBSITE_EMAIL_TITLE.'</h2>';
				$message .= '<p>Hi '.trim($this->security->xss_clean($this->input->post('first_name'))).' you have successfully created your account, <br> Please <a href="'.BASE_URL.'user/verify/'.$User_id.'/'.$verify_key.'">Click here</a> to activate your account <br> '.BASE_URL.'user/verify/'.$User_id.'/'.$verify_key.'</p>';
				

				$message .='<p>Thanks <br>
				'.WEBSITE_SIGNATURE.'
				</p>';

				$this->email->message($message);

				$this->email->send();
			
			$this->session->set_flashdata('error',"Your Account is created, Please check your email inbox,spam and approve your account");
			if (count($this->cart->contents()) > 0){
                   // redirect(BASE_URL.'search/submit_request');
				   	redirect(BASE_URL.'login');
				}else{
				
			redirect(BASE_URL.'login');
				}
			}
		 }else{
		$this->load->view('front/user/register',$data);
		 }
		
		
	}
	
	
	public function resetpassword($user_id,$reset_pass_key){
		 $data['Content'] =  $this->content_model->GetContentByID(19);
		 $data['user_id'] =  $user_id;
		 $data['reset_pass_key'] =  $reset_pass_key;
		 
		if($user_id!="" && $reset_pass_key!=""){
		  $query = $this->db->query("SELECT * FROM `bh_users` WHERE `user_id` = '".$user_id."' AND `reset_pass_key` = '".$reset_pass_key."'");
 
			$data['UserData'] =  $this->user_model->UserByID($user_id);
    if ($query->num_rows() > 0) {
    
		
		
    } else {
       redirect(BASE_URL);
    } 	
			
		}else{
			redirect(BASE_URL);
			
		}
		
		if($this->input->post('submitF') && $this->input->post('submitF')!="") 
		 {	
	 $config = array( 	           
			array('field' => 'password','label' => 'Password','rules' => 'trim|required|xss_clean|matches[password2]'),
			array('field' => 'password2','label' => 'Confirm Password','rules' => 'trim|required|xss_clean'),
			
			);
			
			$this->form_validation->set_rules($config);		
			if ($this->form_validation->run() === FALSE)
			{	

			$this->load->view('front/user/reset-password',$data);
			
			}
			else{

		
			// Add new User Details
			$updata = array('password' => md5($this->input->post('password')),'reset_pass_key' => ''); 
			 		

	   
	   
			$this->db->where('user_id', $user_id);
			$this->db->update('bh_users', $updata);
			$this->session->set_flashdata('error',"Password is Changed Successfully");
			redirect(BASE_URL.'login');
			}
			
				
			
			}
		 
		 else{
		$this->load->view('front/user/reset-password',$data);
		 }
		
	}
	
	
	public function verify($user_id,$verify_key){
		if($user_id!="" && $verify_key!=""){
		
		  $query = $this->db->query("SELECT * FROM `bh_users` WHERE `user_id` = '".$user_id."' AND `verify_key` = '".$verify_key."'");

    if ($query->num_rows() > 0) {
       $data = array("status"=>'1',"verify_key"=>"");
	   $this->db->where("user_id",$user_id);
	   $this->db->update("bh_users",$data);
	   $this->session->set_flashdata('error',"You have successfully approved your account.");
	   redirect(BASE_URL.'login');
    } else {
       redirect(BASE_URL);
    } 	
			
		}else{
			redirect(BASE_URL);
			
		}
		
	}
	
	
	
	public function show_state()
	{
		$html = "";
		$Country_id = $this->input->post('countryval');
		$current_id = $this->input->post('current_id');
		$this->db->select("*");
		$this->db->from('states');	
		$this->db->where("country_id",$Country_id);		
		$this->db->order_by("name","asc");

		$query=$this->db->get();
		$all_data =  $query->result_array(); 

		if(count($all_data) > 0){
		$html = '<option>Select State</option>';			
		foreach($all_data as $singleData){
		//$url = $this->create_url($singleData['Title']);
		if($current_id==$singleData['id']){ $class= 'selected'; } else{  $class= '';  }
		$html .='<option value="'.$singleData['id'].'" '.$class.'>'.$singleData['name'].'</option>';


		}
		}

		echo json_encode($html);
	}
	
	
	public function show_city()
	{
		$html = "";
		$state_id = $this->input->post('state');
		$current_id = $this->input->post('current_id');
		$this->db->select("*");
		$this->db->from('cities');	
		$this->db->where("state_id",$state_id);		
		$this->db->order_by("name","asc");

		$query=$this->db->get();
		$all_data =  $query->result_array(); 

		if(count($all_data) > 0){
		$html = '<option>Select City</option>';			
		foreach($all_data as $singleData){
		//$url = $this->create_url($singleData['Title']);
		if($current_id==$singleData['id']){ $class= 'selected'; } else{  $class= '';  }
		$html .='<option value="'.$singleData['id'].'" '.$class.'>'.$singleData['name'].'</option>';


		}
		}

		echo json_encode($html);
	
	}
	
	public function delete_user($user_id){
		if($user_id!=''){
		$this->db->where("user_id",$user_id);
		$this->db->delete("bh_users");
		$this->session->set_flashdata('error',"User Deleted");
			
		
		}
		redirect(BASE_URL.'admin/manage-users');
	}
	
	public function logout(){
		$this->session->unset_userdata('front_logged_in');			
		$this->session->unset_userdata('bh_front_user_id');			
		$this->session->unset_userdata('bh_front_email_id');
		$this->session->unset_userdata('bh_front_username');	
		redirect(BASE_URL);

	}
	
	public function addnewsletter(){
	
	$email = $this->security->xss_clean($this->input->post('email'));
	if($email==""){
			echo  '<font style="color:white;">Please Enter Your Email Id.</font>';
			exit();
	}
	
	if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
        // valid address
    }
    else {
        echo  '<font style="color:white;">Please Enter Correct Email Id.</font>';
		exit();
    }
		// check email
		$this->db->select("*");
		$this->db->from('bh_newsletter');	
		$this->db->where("email",$email);		
		$this->db->order_by("id","asc");
		$query=$this->db->get();
		$all_email =  $query->result_array(); 
		if(count($all_email) > 0){
			
			echo  '<font style="color:white;">Email Id Already subscribed.</font>';
			
			
		}else{
			if($email!=""){
			$data = array("email"=>$email);
			$this->db->insert("bh_newsletter",$data);
			echo  '<font style="color:white;">Email Id is subscribed successfully.</font>';
			}
			
			
		}
		
		
		
	}
	
	

	
}

VaKeR 2022