HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //var/www/html/pmw24/pmw_live_testing/app/application/controllers/customer/Customer.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Customer extends MY_Controller {
	public function __construct() {
		parent::__construct();
		$this->redirect_customer();
        $this->customer=$this->session->userdata('customer_data');
        //print_r($this->admin);die;
		$this->load->model('admin/mcustomer');
		$this->load->library('session');
	}
		
	public function dashboard() { //echo 'aa';die;
		$data['content'] = 'customer/index'; 
		$data['customer_data']= $this->customer;
		$this->load->view('customer/layouts/index', $data);		
	}

	public function logout(){
		$this->session->unset_userdata('customer_data');
		redirect(WEBSITE_URL,false);
	}

	public function my_profile() { 
		$data['content'] = 'customer/profile'; 
		$customer_data = $this->mcustomer->getRow('customer',array('customer_id'=>$this->customer['customer_id']));
		$data['customer_data']= $customer_data;
		$this->load->view('customer/layouts/index', $data);		
	}

	public function change_password() { 
		$data['content'] = 'customer/change_password'; 
		$this->load->view('customer/layouts/index', $data);		
	}

	public function edit_customer(){
		//echo '<pre>';print_r($_FILES);die;
		if($this->input->post()){

			$this->form_validation->set_rules('customer_type','Customer Type','required');
			$this->form_validation->set_rules('first_name','First Name','required');				
			$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback_check_email',array('check_email'=>'This %s already exists.'));			
			$this->form_validation->set_rules('mobile','Mobile','required');
			
			
			
			if($this->form_validation->run()==FALSE){
				$this->my_profile();
			}else{
				$customer_data['customer_type']=$this->input->post('customer_type');
				if($this->input->post('customer_type') == 'B'){
					$customer_data['business_name']=$this->input->post('business_name');
				}
				$customer_data['first_name']=$this->input->post('first_name');
				$customer_data['middle_name']=$this->input->post('middle_name');
				$customer_data['last_name']=$this->input->post('last_name');
				$customer_data['abn']=$this->input->post('abn');
				$customer_data['landline_no']=$this->input->post('landline_no');
				$customer_data['mobile']=$this->input->post('mobile');
				$customer_data['email']=$this->input->post('email');
				$customer_data['flat_no']=$this->input->post('flat_no');
				$customer_data['street_no']=$this->input->post('street_no');
				$customer_data['street_name']=$this->input->post('street_name');
				$customer_data['suburb']=$this->input->post('suburb');
				$customer_data['state']=$this->input->post('state');
				$customer_data['pin']=$this->input->post('pin');
				$customer_data['updated_by']= 0;
				$customer_data['updated_ts']=date('Y-m-d H:i:s');

				if($_FILES['profile_image']['name']){

					$path = './public/customer_assets/profile_image/';
					$upload_file = $this->single_image_upload($path, $_FILES['profile_image'],'profile_image');
					
					if($upload_file['status']==1){
						$customer_data['profile_image']=$upload_file['result'];
					}else{
						$this->session->set_flashdata('cus_error_msg',$upload_file['result']);
						redirect('customer/customer/my_profile');
					}
				}
				 
				$customer_id = $this->mcustomer->update(array('customer_id'=>$this->input->post('customer_id')),$customer_data);
				$customer_upd_data=$this->mcommon->getRow('customer',array('customer_id'=>$this->input->post('customer_id')));
				$this->session->set_userdata('customer_data',$customer_upd_data);
				$this->session->set_flashdata('cus_success_msg','Customer updated successfully');
				redirect('customer/customer/my_profile');
			}
		
		}else{
			$this->session->set_flashdata('cus_error_msg','Oops!something went wrong...');
			redirect('customer/customer/my_profile');
		}
		
	}

	public  function check_email() {
		$email = $this->input->post('email');
		$customer_id = $this->input->post('customer_id');
		$result = $this->mcustomer->check_email_exist($email,$customer_id);
		//echo $result;die;
		return $result;
	}
	
	public function change_password_submit() { 
		
		if($this->input->post()){

			$this->form_validation->set_rules('old_password', 'Old password is wrong', 'trim|required|callback_check_old_password',array('check_old_password'=>'Old password is wrong'));			
			
			if($this->form_validation->run()==FALSE){
				$this->change_password();
			}else{
				
				$customer_data['password']=md5($this->input->post('pwd'));
				$customer_data['org_password']=$this->input->post('pwd');
				$customer_data['updated_by']= 0;
				$customer_data['updated_ts']=date('Y-m-d H:i:s');
				 
				$customer_id = $this->mcustomer->update(array('customer_id'=>$this->customer['customer_id']),$customer_data);
				$this->session->set_flashdata('cus_success_msg','Password changed successfully');
				redirect('customer/customer/change_password');
			}
		
		}else{
			$this->session->set_flashdata('cus_error_msg','Oops!something went wrong...');
			redirect('customer/customer/change_password');
		}
	}

	public  function check_old_password() {
		$password = $this->input->post('old_password');
		$customer_id = $this->customer['customer_id'];
		$result = $this->mcustomer->check_old_password($password,$customer_id);
		//echo $result;die;
		return $result;
	}

	private function single_image_upload($path,$files,$document_type){
		
		$fileName = $document_type.'_'.time().'_'. str_replace(" ","_",$files['name']);
		$config = array(
			'upload_path'   => $path,
			'allowed_types' => 'gif|jpg|png|jpeg|pdf|doc|docx',
			'overwrite'     => 1,
			'file_name'		=>$fileName
		);
		//print_r($config);die;
		$this->load->library('upload', $config); 
		
		if (!$this->upload->do_upload($document_type)){
			$message = array('result' => $this->upload->display_errors(),'status'=>0);
		}else{ 
			
			$data = array('upload_data' => $this->upload->data());
			$message = array('result' => $data['upload_data']['file_name'],'status'=>1);
		}
		return $message;
	}
	

}