File: //var/www/html/qcr24/app/application/controllers/admin/Driver.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Driver extends MY_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('admin/mdriver');
$this->load->library('advantagepay');
}
/**
* 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/driver_guide/general/urls.html
*/
public function index()
{
$data = array('menu_id'=> 4);
$data['drivers'] = array();
// if(check_user_permission($data['menu_id'], 'delete_flag')){
// $data['drivers'] = $this->mdriver->get_driver();
// }
$data['drivers'] = $this->mdriver->get_driver();
$data['content'] = 'admin/driver/list';
$this->load->view('admin/layouts/index', $data);
}
public function validatedriver($driver_id)
{
$data = array('menu_id'=> 4);
$data = array();
//if(check_user_permission($data['menu_id'], 'delete_flag')){
$data['content'] = 'admin/driver/validate';
$data['utility_bills'] = $this->mdriver->get_address_proof_list();
$data['driver_details'] = $this->mdriver->get_driver_details($driver_id);
//}
$this->load->view('admin/layouts/index', $data);
}
public function validate_driver_submit()
{
// echo '<pre>'; print_r($this->input->post());
// echo '<pre>'; print_r($_FILES); die;
if(!empty($this->input->post())){
$driver_id = $this->input->post('driver_id');
if(empty($driver_id)){
$return_data = array('status'=>false,'msg'=>'Please fill up the details');
echo json_encode($return_data);die;
}
$result = $this->mdriver->get_driver_details($driver_id);
if (empty($result)) {
$return_data = array('status'=>false, 'msg' => 'Driver ID not exist');
echo json_encode($return_data);die;
}
if ($result['status'] != '0') {
$return_data = array('status'=>false, 'msg' => 'Driver already validated');
echo json_encode($return_data);die;
}
$driver_data = array();
$driver_data['first_name'] = $this->input->post('first_name');
$driver_data['middle_name'] = $this->input->post('middle_name');
$driver_data['last_name'] = $this->input->post('last_name');
$driver_data['flat_no'] = $this->input->post('flat_no');
$driver_data['street_no'] = $this->input->post('street_no');
$driver_data['street_name'] = $this->input->post('street_name');
$driver_data['suburb'] = $this->input->post('suburb');
$driver_data['pin'] = $this->input->post('pin');
$driver_data['mobile'] = $this->input->post('mobile');
if($this->input->post('dob')){
$driver_data['dob'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('dob'))));
}
if(isset($_FILES['profile_image']['name']) && !empty($_FILES['profile_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['profile_image'],'profile_image');
if($upload_file['status']==1){
$driver_data['profile_photo']=$upload_file['result'];
}
}
$driver_data['licence_no'] = $this->input->post('licence_no');
if($this->input->post('licence_expiry')){
$driver_data['licence_expiry'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('licence_expiry'))));
}
$driver_data['is_australian_licence'] = $this->input->post('is_australian_licence');
$driver_data['passport_no'] = $this->input->post('passport_no');
if($this->input->post('passport_expiry')){
$driver_data['passport_expiry'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('passport_expiry'))));
}
$driver_data['utility_bill_id'] = $this->input->post('utility_bill_id');
$driver_data['bank_name'] = $this->input->post('bank_name');
$driver_data['bsb'] = $this->input->post('bsb');
$driver_data['account_no'] = $this->input->post('account_no');
$driver_data['no_of_at_fault_accidents'] = $this->input->post('no_of_at_fault_accidents');
$driver_data['no_of_not_at_fault_accidents'] = $this->input->post('no_of_not_at_fault_accidents');
$driver_data['admin_notes'] = $this->input->post('admin_notes');
$driver_data['status'] = '1';
$driver_data['updated_by'] = $this->admin_session_data['user_id'];
$driver_data['updated_ts'] = date('Y-m-d H:i:s');
if(isset($_FILES['licence_image']['name']) && !empty($_FILES['licence_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['licence_image'],'licence_image');
if($upload_file['status']==1){
$driver_data['licence_image']=$upload_file['result'];
}
}
if(isset($_FILES['licence_expiry_image']['name']) && !empty($_FILES['licence_expiry_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['licence_image'],'licence_expiry_image');
if($upload_file['status']==1){
$driver_data['licence_expiry_image']=$upload_file['result'];
}
}
if(isset($_FILES['passport_no_image']['name']) && !empty($_FILES['passport_no_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['passport_no_image'],'passport_no_image');
if($upload_file['status']==1){
$driver_data['passport_no_image']=$upload_file['result'];
}
}
if(isset($_FILES['passport_expiry_image']['name']) && !empty($_FILES['passport_expiry_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['passport_expiry_image'],'passport_expiry_image');
if($upload_file['status']==1){
$driver_data['passport_expiry_image']=$upload_file['result'];
}
}
if(isset($_FILES['utility_bill_image']['name']) && !empty($_FILES['utility_bill_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['utility_bill_image'],'utility_bill_image');
if($upload_file['status']==1){
$driver_data['utility_bill_image']=$upload_file['result'];
}
}
try {
$this->db->trans_start(); # Starting Transaction
$this->db->update('master_driver',$driver_data,array('driver_id'=>$driver_id));
//********/ As discuss with Lovedep on 22/01/2023 remove bond from driver validation as we take bond with 1st rent out by Mrityunjoy************//
// $bond_data = array(
// 'driver_id' => $driver_id,
// 'bond_amount' => $this->input->post('bond_amount'),
// 'transaction_type' => 'CREDIT',
// 'bond_date' => date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('bond_date')))),
// 'bond_payment_method' => $this->input->post('bond_payment_method'),
// 'bond_reference_no' => $this->input->post('bond_reference_no'),
// 'bond_reference_type' => 'VALIDATE',
// 'bond_reference_id' => $driver_id,
// 'created_by'=>$this->admin_session_data['user_id'],
// 'created_ts' => date('Y-m-d H:i:s')
// );
// $this->db->insert('bond_wallet',$bond_data);
//********/ As discuss with Lovedep on 22/01/2023 remove bond from driver validation as we take bond with 1st rent out by Mrityunjoy************//
$this->db->trans_complete(); # Completing transaction
if ($this->db->trans_status() === FALSE) {
# Something went wrong.
$this->db->trans_rollback();
$return_data = array('status' => false, 'msg' => 'Oops!Something went wrong...');
} else {
# Everything is Perfect.
# Committing data to the database.
$this->db->trans_commit();
$return_data = array('status'=>true,'msg'=>'Driver validated successfully');
}
} catch (Exception $e) {
// this will not catch DB related errors. But it will include them, because this is more general.
$return_data = array('status' => false, 'msg' => $e->getMessage());
echo json_encode($return_data);die;
}
} else {
$return_data = array('status'=>false,'msg'=>'Please fill up the details');
}
echo json_encode($return_data);die;
}
public function viewdriver($driver_id)
{
$data['driver_details'] = $this->mdriver->get_driver_details($driver_id);
$data['driver_bond_details'] = $this->mdriver->get_driver_bond_details($driver_id);
$data['utility_bills'] = $this->mdriver->get_address_proof_list();
$data['content'] = 'admin/driver/view';
$this->load->view('admin/layouts/index', $data);
}
public function editdriver($driver_id)
{
$data['driver_details'] = $this->mdriver->get_driver_details($driver_id);
$data['driver_bond_details'] = $this->mdriver->get_driver_bond_details($driver_id);
$data['utility_bills'] = $this->mdriver->get_address_proof_list();
$data['content'] = 'admin/driver/edit';
$this->load->view('admin/layouts/index', $data);
}
public function edit_driver_submit(){
// echo '<pre>'; print_r($this->input->post());
// echo '<pre>'; print_r($_FILES); die;
if(!empty($this->input->post())){
$driver_id = $this->input->post('driver_id');
if(empty($driver_id)){
$return_data = array('status'=>false,'msg'=>'Please fill up the details');
echo json_encode($return_data);die;
}
$driver_data = array();
$driver_data['first_name'] = $this->input->post('first_name');
$driver_data['middle_name'] = $this->input->post('middle_name');
$driver_data['last_name'] = $this->input->post('last_name');
$driver_data['flat_no'] = $this->input->post('flat_no');
$driver_data['street_no'] = $this->input->post('street_no');
$driver_data['street_name'] = $this->input->post('street_name');
$driver_data['suburb'] = $this->input->post('suburb');
$driver_data['pin'] = $this->input->post('pin');
$driver_data['mobile'] = $this->input->post('mobile');
if($this->input->post('dob')){
$driver_data['dob'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('dob'))));
}
if(isset($_FILES['profile_image']['name']) && !empty($_FILES['profile_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['profile_image'],'profile_image');
if($upload_file['status']==1){
$driver_data['profile_photo']=$upload_file['result'];
}
}
$driver_data['licence_no'] = $this->input->post('licence_no');
if($this->input->post('licence_expiry')){
$driver_data['licence_expiry'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('licence_expiry'))));
}
$driver_data['is_australian_licence'] = $this->input->post('is_australian_licence');
$driver_data['passport_no'] = $this->input->post('passport_no');
if($this->input->post('passport_expiry')){
$driver_data['passport_expiry'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('passport_expiry'))));
}
$driver_data['utility_bill_id'] = $this->input->post('utility_bill_id');
$driver_data['bank_name'] = $this->input->post('bank_name');
$driver_data['bsb'] = $this->input->post('bsb');
$driver_data['account_no'] = $this->input->post('account_no');
$driver_data['no_of_at_fault_accidents'] = $this->input->post('no_of_at_fault_accidents');
$driver_data['no_of_not_at_fault_accidents'] = $this->input->post('no_of_not_at_fault_accidents');
$driver_data['admin_notes'] = $this->input->post('admin_notes');
$driver_data['status'] = $this->input->post('status');
$driver_data['updated_by'] = $this->admin_session_data['user_id'];
$driver_data['updated_ts'] = date('Y-m-d H:i:s');
if(isset($_FILES['licence_image']['name']) && !empty($_FILES['licence_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['licence_image'],'licence_image');
if($upload_file['status']==1){
$driver_data['licence_image']=$upload_file['result'];
}
}
if(isset($_FILES['licence_expiry_image']['name']) && !empty($_FILES['licence_expiry_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['licence_image'],'licence_expiry_image');
if($upload_file['status']==1){
$driver_data['licence_expiry_image']=$upload_file['result'];
}
}
if(isset($_FILES['passport_no_image']['name']) && !empty($_FILES['passport_no_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['passport_no_image'],'passport_no_image');
if($upload_file['status']==1){
$driver_data['passport_no_image']=$upload_file['result'];
}
}
if(isset($_FILES['passport_expiry_image']['name']) && !empty($_FILES['passport_expiry_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['passport_expiry_image'],'passport_expiry_image');
if($upload_file['status']==1){
$driver_data['passport_expiry_image']=$upload_file['result'];
}
}
if(isset($_FILES['utility_bill_image']['name']) && !empty($_FILES['utility_bill_image']['name'])){
$path = './public/admin_images/driver/';
$upload_file = $this->single_image_upload($path, $_FILES['utility_bill_image'],'utility_bill_image');
if($upload_file['status']==1){
$driver_data['utility_bill_image']=$upload_file['result'];
}
}
$this->db->trans_start(); # Starting Transaction
$this->db->update('master_driver',$driver_data,array('driver_id'=>$driver_id));
$this->db->trans_complete(); # Completing transaction
if ($this->db->trans_status() === FALSE) {
# Something went wrong.
$this->db->trans_rollback();
$return_data = array('status' => false, 'msg' => 'Oops!Something went wrong...');
} 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 Driver</b>',
'description' => 'Driver - '.$this->input->post('first_name').' '.$this->input->post('middle_name').' '.$this->input->post('last_name').' Updated',
'link' => 'admin/driver/editdriver/'.$driver_id,
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
);
$this->activity_log($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$return_data = array('status'=>true,'msg'=>'Driver updated successfully');
}
} else {
$return_data = array('status'=>false,'msg'=>'Please fill up the details');
}
echo json_encode($return_data);die;
}
public function validate_reject_driver_submit(){
//echo '<pre>'; print_r($this->input->post()); die;
// echo '<pre>'; print_r($_FILES); die;
if(!empty($this->input->post())){
$driver_id = $this->input->post('driver_id');
$admin_notes = $this->input->post('admin_notes');
if(empty($driver_id)){
$return_data = array('status'=>false,'msg'=>'Please fill up the details');
echo json_encode($return_data);die;
}
if(empty($admin_notes)){
$return_data = array('status'=>false,'msg'=>'Please fill up admin notes');
echo json_encode($return_data);die;
}
$driver_data = array();
$driver_data['status'] = '4';
$driver_data['admin_notes'] = $this->input->post('admin_notes');
$driver_data['updated_by'] = $this->admin_session_data['user_id'];
$driver_data['updated_ts'] = date('Y-m-d H:i:s');
$this->db->update('master_driver',$driver_data,array('driver_id'=>$driver_id));
$return_data = array('status'=>true,'msg'=>'Driver Rejected successfully');
} else {
$return_data = array('status'=>false,'msg'=>'Please fill up the details');
}
echo json_encode($return_data);die;
}
public function submitdriver()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confirm_password', 'Password Confirmation', 'required|matches[password]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[master_admin.email]');
if ($this->form_validation->run() == FALSE)
{
$this->adddriver();
}
else
{
$data = array(
'role_id' => $this->input->post('role_id'),
'full_name' => $this->input->post('full_name'),
'password' => md5($this->input->post('password')),
'email' => $this->input->post('email'),
'gender' => $this->input->post('gender'),
'mobile_no' => $this->input->post('mobile_no'),
'address' => $this->input->post('address'),
'abn'=> $this->input->post('abn'),
'tfn'=> $this->input->post('tfn'),
'status' => $this->input->post('status'),
'created_by' => $this->admin_session_data['driver_id'],
'created_ts' => date('Y-m-d H:i:s')
);
$result = $this->mdriver->submit_driver($data);
if ($result) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Add Driver</b>',
'description' => 'New Driver - '.$this->input->post('full_name').' Added',
'link' => 'admin/driver',
'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', 'driver Added Successfully');
redirect("admin/driver");
}
}
}
public function updatedriver()
{
$this->load->library('form_validation');
$hid_driver_id=$this->input->post('hid_driver_id');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[master_admin.driver_id.'.$hid_driver_id.']');
if ($this->form_validation->run() == FALSE)
{
$this->editdriver();
}
else
{
$data = array(
'role_id' => $this->input->post('role_id'),
'full_name' => $this->input->post('full_name'),
'email' => $this->input->post('email'),
'gender' => $this->input->post('gender'),
'mobile_no' => $this->input->post('mobile_no'),
'address' => $this->input->post('address'),
'abn'=> $this->input->post('abn'),
'tfn'=> $this->input->post('tfn'),
'status' => $this->input->post('status'),
'updated_by' => $this->admin_session_data['driver_id'],
'updated_ts' => date('Y-m-d H:i:s')
);
if(!empty($this->input->post('password'))){
$data['password'] = md5($this->input->post('password'));
}
$condition = array('driver_id' => $hid_driver_id);
$result = $this->mdriver->update_driver($condition, $data);
if ($result) {
$this->session->set_flashdata('success_msg', 'driver Updated Successfully');
redirect("admin/driver");
}
}
}
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)){
$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);
}
return $message;
}
}