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/qcr24/app/application/controllers/admin/OdometerNew.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');

class OdometerNew extends MY_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->model('admin/modometerNew');
	}
	/**
	 * 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/odometer_guide/general/urls.html
	 */
	public function index()
	{
		$data = array('menu_id'=> 4);
		$data['odometers'] = array();
		$data['odometers'] = $this->modometer->get_odometer_list();
		//echo '<pre>'; print_r($data['odometers']);die;
		$data['content'] = 'admin/odometer/list';
		$this->load->view('admin/layouts/index', $data);
	}

	public function search()
	{
		$data = array('menu_id'=> 4);

		$car_id=$this->input->get('car_id');
		$data['rent_out_id']=$this->input->get('rent_out_id');
		$data['odometers'] = array();
		$data['odometers'] = $this->modometerNew->get_odometer_list($car_id,$data['rent_out_id']);
		//echo '<pre>'; print_r($data['odometers']);die;
		$data['content'] = 'admin/odometer_new/list';
		$this->load->view('admin/layouts/index', $data);
	}

	public function add()
	{
		
		$data = array();
		$data['content'] = 'admin/odometer/add';
		$data['cars'] = $this->modometer->get_car();

		$this->load->view('admin/layouts/index', $data);
	}

	public function edit($odometer_id)
	{
		
		$data = array();
		$data['content'] = 'admin/odometer/edit';
		$data['cars'] = $this->modometer->get_car();
		$data['odometer_details'] = $this->modometer->get_odometer_details($odometer_id);
//echo '<pre>'; print_r($data['odometer_details']);die;
		$this->load->view('admin/layouts/index', $data);
	}

	public function getRentOutDriver()
	{
		$car_id=$this->input->post('car_id');
		$rent_out_driver_data= $this->modometer->getRentOutDriver($car_id);
		
		echo json_encode(array('status'=>true,'rent_out_driver_data'=>$rent_out_driver_data));
	}

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

			$odometer_data = array();
			$odometer_data['odometer_update_date'] = date('Y-m-d H:i:s',strtotime(str_replace('/', '-', $this->input->post('odometer_updated_date'))));
			$odometer_data['driver_id'] = $this->input->post('driver_id');
			$odometer_data['car_id'] = $this->input->post('car_id');
			$odometer_data['rent_out_id'] = $this->input->post('rent_out_id');
			$odometer_data['previous_odometer_reading'] = $this->input->post('total_odometer_reading');
			$odometer_data['odometer_reading'] = $this->input->post('odometer_reading');
			$odometer_data['service_due_kilometer'] = $this->input->post('service_due_kilometer');
			$odometer_data['created_by'] = $this->admin_session_data['user_id'];
			$odometer_data['created_ts'] = date('Y-m-d H:i:s');
			
			if(isset($_FILES['odometer_image_1']['name']) && !empty($_FILES['odometer_image_1']['name'])){

				$path = './public/admin_images/odometer/';
				$upload_file = $this->single_image_upload($path, $_FILES['odometer_image_1'],'odometer_image_1');
				
				if($upload_file['status']==1){
					$odometer_data['odometer_image_1']=$upload_file['result'];
				}
			}

			if(isset($_FILES['odometer_image_2']['name']) && !empty($_FILES['odometer_image_2']['name'])){

				$path = './public/admin_images/odometer/';
				$upload_file = $this->single_image_upload($path, $_FILES['odometer_image_2'],'odometer_image_2');
				
				if($upload_file['status']==1){
					$odometer_data['odometer_image_2']=$upload_file['result'];
				}
			}

			

			

			$this->db->trans_start(); # Starting Transaction

			$this->db->insert('odometers',$odometer_data);
			
			
			$update_car_data = array();
			$update_car_data['total_odometer_reading'] = $odometer_data['odometer_reading'];
			$update_car_data['created_by'] = $this->admin_session_data['user_id'];
			$update_car_data['created_ts'] = date('Y-m-d H:i:s');

			$this->db->update('master_car',$update_car_data,array('car_id'=>$odometer_data['car_id']));

			
			$this->db->trans_complete(); # Completing transaction

			if ($this->db->trans_status() === FALSE) {
				# Something went wrong.
				$this->db->trans_rollback();
				
				$this->session->set_flashdata('error_msg', 'Oops!Something went wrong...');
				$this->add();
			} else {
				# Everything is Perfect. 
				# Committing data to the database.
				$this->db->trans_commit();

				//************************************************************************************//	
				//************************This Part is for Activity Log*******************************//

				$activityLogData = array(
					'activity_type' => '<b>Add Odometer</b>',
					'description' => 'New Odometer Reading - '.$this->input->post('odometer_reading').' Added',
					'link' => 'admin/odometer',
					'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
				);

				$this->activity_log($activityLogData);

				//************************This Part is for Activity Log*******************************//
				//************************************************************************************//

				$this->session->set_flashdata('success_msg', 'Odometer data submitted Successfully');
				redirect("admin/odometer");
			}
			
		
		} else {

			$this->session->set_flashdata('error_msg', 'Please fill up all the required fields');
			$this->add();
		}
		
		redirect("admin/odometer");
		

		
	}

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

			$odometer_data = array();
			$odometer_data['odometer_update_date'] = date('Y-m-d H:i:s',strtotime(str_replace('/', '-', $this->input->post('odometer_updated_date'))));
			$odometer_data['previous_odometer_reading'] = $this->input->post('total_odometer_reading');
			$odometer_data['odometer_reading'] = $this->input->post('odometer_reading');
			$odometer_data['service_due_kilometer'] = $this->input->post('service_due_kilometer');
			$odometer_data['updated_by'] = $this->admin_session_data['user_id'];
			$odometer_data['updated_ts'] = date('Y-m-d H:i:s');
			
			if(isset($_FILES['odometer_image_1']['name']) && !empty($_FILES['odometer_image_1']['name'])){

				$path = './public/admin_images/odometer/';
				$upload_file = $this->single_image_upload($path, $_FILES['odometer_image_1'],'odometer_image_1');
				
				if($upload_file['status']==1){
					$odometer_data['odometer_image_1']=$upload_file['result'];
				}
			}

			if(isset($_FILES['odometer_image_2']['name']) && !empty($_FILES['odometer_image_2']['name'])){

				$path = './public/admin_images/odometer/';
				$upload_file = $this->single_image_upload($path, $_FILES['odometer_image_2'],'odometer_image_2');
				
				if($upload_file['status']==1){
					$odometer_data['odometer_image_2']=$upload_file['result'];
				}
			}

			
			//echo '<pre>';print_r($odometer_data);die;
			

			$this->db->trans_start(); # Starting Transaction

			$this->db->update('odometers',$odometer_data,array('odometer_id'=>$this->input->post('odometer_id')));
			
			
			$update_car_data = array();
			$update_car_data['total_odometer_reading'] = $odometer_data['odometer_reading'];
			$update_car_data['updated_by'] = $this->admin_session_data['user_id'];
			$update_car_data['updated_ts'] = date('Y-m-d H:i:s');

			$this->db->update('master_car',$update_car_data,array('car_id'=>$this->input->post('car_id')));

			
			$this->db->trans_complete(); # Completing transaction

			if ($this->db->trans_status() === FALSE) {
				# Something went wrong.
				$this->db->trans_rollback();
				
				$this->session->set_flashdata('error_msg', 'Oops!Something went wrong...');
				$this->add();
			} else {
				# Everything is Perfect. 
				# Committing data to the database.
				$this->db->trans_commit();

				//************************************************************************************//	
				//************************This Part is for Activity Log*******************************//

				$activityLogData = array(
					'activity_type' => '<b>Update Odometer</b>',
					'description' => 'Odometer Reading - '.$this->input->post('odometer_reading').' Updated',
					'link' => 'admin/odometer/edit/.'.$this->input->post('odometer_id'),
					'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
				);

				$this->activity_log($activityLogData);

				//************************This Part is for Activity Log*******************************//
				//************************************************************************************//

				$this->session->set_flashdata('success_msg', 'Odometer data updated Successfully');
				redirect("admin/odometer");
			}
			
		
		} else {

			$this->session->set_flashdata('error_msg', 'Please fill up all the required fields');
			$this->add();
		}
		
		redirect("admin/odometer");
		

		
	}
	public function viewodometer($pre_data = array())
	{
		$data = array();
		$data = $pre_data;
		$data['roles'] = $this->modometer->get_role();
		//$data['states'] = $this->modometer->get_state();
		$data['parent_odometer'] = $this->modometer->edit_odometer($this->admin_session_data['odometer_id']);
		$data['content'] = 'admin/odometer/add';
		$this->load->view('admin/layouts/index', $data);
	}

	public function make_payment($odometer_id)
	{
		
		$data = array();
		$data['content'] = 'admin/odometer/payment';
		$data['odometer_details'] = $this->modometer->get_odometer_details($odometer_id);
		$data['odometer_payment_details'] = $this->modometer->get_odometer_payment_details($odometer_id);
		//echo '<pre>';print_r($data);die;
		$this->load->view('admin/layouts/index', $data);
	}

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

			$this->db->trans_start(); # Starting Transaction

			
			$odometer_id = $this->input->post('odometer_id');

			$total_due_amount = floatval($this->input->post('total_due_amount')) - floatval($this->input->post('payment_amount'));
			if($total_due_amount == 0){
				$payment_type = 'Full';
			} else {
				$payment_type = 'Partial';
			}
			
			$odometer_payment_data = array();
			$odometer_payment_data['odometer_id'] = $odometer_id;
			$odometer_payment_data['payment_date'] = date('Y-m-d');
			$odometer_payment_data['payable_amount'] = $this->input->post('total_due_amount');
			$odometer_payment_data['payment_type'] = $payment_type;
			$odometer_payment_data['payment_method'] = $this->input->post('payment_method');
			$odometer_payment_data['payment_amount'] = $this->input->post('payment_amount');
			$odometer_payment_data['created_by'] = $this->admin_session_data['user_id'];
			$odometer_payment_data['created_ts'] = date('Y-m-d H:i:s');

			$this->db->insert('odometer_payments',$odometer_payment_data);

			
			$odometer_update_qry = "UPDATE odometers SET total_payment_amount = total_payment_amount + '".$odometer_payment_data['payment_amount']."',total_due_amount='".$total_due_amount."',payment_type='".$payment_type."',updated_by='".$this->admin_session_data['user_id']."',updated_ts='".date('Y-m-d H:i:s')."'
			WHERE odometer_id = ".$odometer_id."";
			//echo $odometer_update_qry;die;
			$this->db->query($odometer_update_qry);
			
			
			$this->db->trans_complete(); # Completing transaction

			if ($this->db->trans_status() === FALSE) {
				# Something went wrong.
				$this->db->trans_rollback();
				
				$this->session->set_flashdata('error_msg', 'Oops!Something went wrong...');
				$this->make_payment($odometer_id);
			} else {
				# Everything is Perfect. 
				# Committing data to the database.
				$this->db->trans_commit();
				$this->session->set_flashdata('success_msg', 'Odometer payment done successfully');
				redirect("admin/odometer");
			}
			
		
		} else {

			$this->session->set_flashdata('error_msg', 'Please fill up all the required fields');
			redirect("admin/odometer");
		}
		
		redirect("admin/odometer");
		

		
	}

	

	private function upload_multiple_images($path,$files,$user_id,$document_type){  
        //echo"<pre>";print_r($product_id); die;
		$config = array(
			'upload_path'   => $path,
			'allowed_types' => 'gif|jpg|png|jpeg|pdf|doc|docx',
			'overwrite'     => 1,  
							 
		);

		$this->load->library('upload', $config);

        $images = array();

        foreach ($files['name'] as $key => $image) {
            $_FILES['images[]']['name']= $files['name'][$key];
            $_FILES['images[]']['type']= $files['type'][$key];
            $_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
            $_FILES['images[]']['error']= $files['error'][$key];
            $_FILES['images[]']['size']= $files['size'][$key];

                $fileName = $document_type.'_'.time() .'_'. $key .'_'. str_replace(" ","_",$image);
            $images[] = $fileName;

            $config['file_name'] = $fileName;

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

            if ($this->upload->do_upload('images[]')) {

				if($document_type == 'signature'){
					$this->mcommon->delete('user_docs',array('document_type'=>'signature','user_id'=>$user_id));
				}
				
				$ap['user_id'] 			= $user_id; 
				$ap['document_type']	= $document_type;
				$ap['document_path'] 	= $fileName;
				$ap['created_ts'] 		= date('Y-m-d H:i:s'); 

			/************ Sreela (21/10/19) end ********************/
				$this->mcommon->insert('user_docs',$ap);
				
			} else {
                //echo $this->upload->display_errors(); die;
                return false;
            }
        }

        return $images;
	}
	 
	private function single_image_upload($path,$files,$document_type){
		
		$config = array(
			'upload_path'   => $path . $document_type,
			'allowed_types' => 'gif|jpg|png|jpeg',
			'overwrite'     => 1,
			'encrypt_name'  => true
		);
		//print_r($config);die;
		$this->load->library('upload', $config); 
		$this->upload->initialize($config);
		
		if (!$this->upload->do_upload($document_type)){
			//echo $this->upload->display_errors();die;
			$message = array('result' => 'The file you are attempting is not correct. Please select jpg|png|jpeg file','status'=>0);
		}else{ 
			
			$data = array('upload_data' => $this->upload->data());
			$message = array('result' => $data['upload_data']['file_name'],'status'=>1);
		}
		//print_r($message);
		return $message;
	}
}