File: //var/www/html/qcr24/app/application/controllers/api/Driver.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Driver extends CI_Controller
{
var $arr;
var $obj;
function __construct()
{
parent::__construct();
$this->load->model('api/mdriver');
$this->arr = array();
$this->obj = new stdClass();
$this->http_methods = array('POST', 'GET', 'PUT', 'DELETE');
$this->logo = base_url() . 'public/images/logo_new.jpg';
//$this->load->library('notification');
}
private function displayOutput($response)
{
header('Content-Type: application/json');
echo json_encode($response,true);
exit(0);
}
// register
public function signup()
{
//$ap = json_decode(file_get_contents('php://input'), true);
// echo '<pre>';print_r($this->input->post());
// echo '<pre>';print_r($_FILES);die;
// $response = array('status' => 0, 'message' => 'Post Data', 'post_data' => $this->input->post(),'file_data' =>$_FILES);
// $this->displayOutput($response);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
// if (empty($ap['access_token_key'])) {
// $response = array('status' => array('error_code' => 3, 'message' => 'Access Token key is required'), 'result' => array('details' => $this->obj));
// $this->displayOutput($response);
// }
if (empty($this->input->post('first_name'))) {
$response = array('status' => 0, 'message' => 'First Name field is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('last_name'))) {
$response = array('status' => 0, 'message' => 'Last Name field is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('email'))) {
$response = array('status' => 0, 'message' => 'Email field is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (!empty($this->input->post('email'))) {
$result = $this->mdriver->checkUserRegistered(array('email' => $_POST['email']));
if (!empty($result)) {
$response = array('status' => 0, 'message' => 'Email Already registered', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
}
if (empty($this->input->post('password'))) {
$response = array('status' => 0, 'message' => 'Password field is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (!empty($this->input->post('mobile'))) {
$result = $this->mdriver->checkUserRegistered(array('mobile' => $_POST['mobile']));
if (!empty($result)) {
$response = array('status' => 0, 'message' => 'Mobile Already registered', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
}
if (empty($this->input->post('pin'))) {
$response = array('status' => 0, 'message' => 'Pin is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
// if (empty($_POST['dc_no'])) {
// $response = array('status' => 0, 'message' => 'DC Number field is required', 'driver_details' => $this->obj);
// $this->displayOutput($response);
// }
// if (!empty($this->input->post('dc_no'))) {
// $result = $this->mdriver->checkUserRegistered(array('dc_no' => $_POST['dc_no']));
// if (!empty($result)) {
// $response = array('status' => 0, 'message' => 'DC Number Already registered', 'driver_details' => $this->obj);
// $this->displayOutput($response);
// }
// }
if (empty($this->input->post('licence_no'))) {
$response = array('status' => 0, 'message' => 'Licence Number field is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('is_australian_licence'))) {
$response = array('status' => 0, 'message' => 'Australian licence is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if ($this->input->post('is_australian_licence') == 'No') {
if (empty($this->input->post('passport_no'))) {
$response = array('status' => 0, 'message' => 'Passport no is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('passport_expiry'))) {
$response = array('status' => 0, 'message' => 'Passport Expiry is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('utility_bill_id'))) {
$response = array('status' => 0, 'message' => 'Utility bill is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
}
if (empty($this->input->post('bank_name'))) {
$response = array('status' => 0, 'message' => 'Bank name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('account_no'))) {
$response = array('status' => 0, 'message' => 'Account no. is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
$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['email'] = $this->input->post('email');
$driver_data['password'] = md5($this->input->post('password'));
$driver_data['orginal_password'] = $this->input->post('password');
$driver_data['mobile'] = $this->input->post('mobile');
$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');
if ($this->input->post('dob')) {
$driver_data['dob'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('dob'))));
}
$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');
if ($driver_data['is_australian_licence'] == 'No') {
$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['status'] = '0';
$driver_data['created_ts'] = date('Y-m-d H:i:s');
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'];
}
}
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_expiry_image'], 'licence_expiry_image');
if ($upload_file['status'] == 1) {
$driver_data['licence_expiry_image'] = $upload_file['result'];
}
}
if ($driver_data['is_australian_licence'] == 'No') {
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'];
}
}
}
$driver_id = $this->mdriver->insert('master_driver', $driver_data);
if ($driver_id) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Signup</b>',
'description' => 'Driver - '.$driver_data['first_name'].' '.$driver_data['middle_name'].' '.$driver_data['last_name'].' signup',
'link' => '',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $driver_id,
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Registration successful', 'driver_details' => $this->obj);
} else {
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'driver_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'driver_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'driver_details' => $this->obj);
}
$this->displayOutput($response);
}
//Login
public function login()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['email'])) {
$response = array('status' => 0, 'message' => 'Email field is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['password'])) {
$response = array('status' => 0, 'message' => 'Password field is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
$ap['password'] = md5($ap['password']);
$check_driver_condition = array('email' => $ap['email'], 'password' => $ap['password']);
$driver_details = $this->mdriver->getRow('master_driver', $check_driver_condition);
$rentout_car_no = $this->mdriver->getRentoutAndCarDetails($driver_details['driver_id']);
//echo $this->db->last_query();die;
if (empty($driver_details)) {
$response = array('status' => 0, 'message' => 'Invalid username or password', 'driver_details' => $this->obj);
} elseif ($driver_details['status'] == '3') {
$response = array('status' => 0, 'message' => 'Account Deleted', 'driver_details' => $this->obj);
} elseif ($driver_details['status'] != '1') {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Account Deactivated</b>',
'description' => 'Driver - '.$driver_details['first_name'].' '.$driver_details['middle_name'].' '.$driver_details['last_name'].' Account Deactivated',
'link' => '',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $driver_details['driver_id'],
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 0, 'message' => 'Account Deactivated', 'driver_details' => $this->obj);
} else {
if (!empty($driver_details['licence_image'])) {
$driver_details['licence_image'] = '/public/admin_images/driver/licence_image/' . $driver_details['licence_image'];
}
if (!empty($driver_details['passport_no_image'])) {
$driver_details['passport_no_image'] = '/public/admin_images/driver/passport_no_image/' . $driver_details['passport_no_image'];
}
if (!empty($driver_details['licence_expiry_image'])) {
$driver_details['licence_expiry_image'] = '/public/admin_images/driver/licence_expiry_image/' . $driver_details['licence_expiry_image'];
}
if (!empty($driver_details['passport_expiry_image'])) {
$driver_details['passport_expiry_image'] = '/public/admin_images/driver/passport_expiry_image/' . $driver_details['passport_expiry_image'];
}
if (!empty($driver_details['utility_bill_image'])) {
$driver_details['utility_bill_image'] = '/public/admin_images/driver/utility_bill_image/' . $driver_details['utility_bill_image'];
}
if (!empty($driver_details['profile_photo'])) {
$driver_details['profile_photo'] = '/public/admin_images/driver/profile_image/' . $driver_details['profile_photo'];
}
$condition = array('user_id' => $driver_details['driver_id']);
$login_data['login_status'] = 1;
$login_data['updated_by'] = $driver_details['driver_id'];
$login_data['updated_ts'] = date('Y-m-d h:i:s');
$login_data['date_of_last_logged_in'] = date('Y-m-d H:i:s');
$update_login_status = $this->mdriver->update('master_driver', array('driver_id' => $driver_details['driver_id']), $login_data);
if ($update_login_status) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Login</b>',
'description' => 'Driver - '.$driver_details['first_name'].' '.$driver_details['middle_name'].' '.$driver_details['last_name'].' login',
'link' => '',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $driver_details['driver_id'],
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
if(!empty($rentout_car_no)){
$driver_details['rent_out_no'] = $rentout_car_no['rent_out_no'];
$driver_details['car_no'] = $rentout_car_no['car_no'];
$driver_details['rent_out_date'] = $rentout_car_no['rent_out_date'];
$driver_details['rent_out_unix_ts'] = strtotime($rentout_car_no['created_ts']);
}else{
$driver_details['rent_out_no'] = 'Not Rent Out';
$driver_details['car_no'] = 'No Car';
$driver_details['rent_out_date'] = '';
$driver_details['rent_out_unix_ts'] = '';
}
$response = array('status' => 1, 'message' => 'Login Successfully', 'driver_details' => $driver_details);
$api_token_details = $this->mdriver->getRow('api_token_driver', $condition);
if (empty($api_token_details)) {
$api_token_data['user_id'] = $driver_details['driver_id'];
$api_token_data['device_type'] = $ap['device_type'];
$api_token_data['token_key'] = ($ap['deviceToken'])?$ap['deviceToken']:md5(mt_rand() . '_' . $driver_details['driver_id']);
$api_token_data['date_of_creation'] = date('Y-m-d H:i:s');
$api_token_data['session_start_time'] = date('Y-m-d H:i:s');
$api_token_data['session_end_time'] = '';
$insert_data = $this->mdriver->insert('api_token_driver', $api_token_data);
$api_token_details = $this->mdriver->getRow('api_token_driver', $condition);
if ($insert_data) {
$response = array('status' => 1, 'message' => 'Login Successfully', 'driver_details' => $driver_details, 'api_token_details' => $api_token_details);
} else {
$response = array('status' => 0, 'message' => 'Unable to generate access token', 'driver_details' => $driver_details, 'api_token_details' => $api_token_details);
}
} else {
$api_token_data['session_start_time'] = date('Y-m-d H:i:s');
$api_token_data['token_key'] = ($ap['deviceToken'])?$ap['deviceToken']:md5(mt_rand() . '_' . $driver_details['driver_id']);
$api_token_data['device_type'] = $ap['device_type'];
$update_data = $this->mdriver->update('api_token_driver', $condition, $api_token_data);
$api_token_details = $this->mdriver->getRow('api_token_driver', $condition);
if ($update_data) {
$response = array('status' => 1, 'message' => 'Login Successfully', 'driver_details' => $driver_details, 'api_token_details' => $api_token_details);
} else {
$response = array('status' => 0, 'message' => 'Unable to update access token', 'driver_details' => $driver_details, 'api_token_details' => $api_token_details);
}
}
} else {
$response = array('status' => 0, 'message' => 'Oops!something went wrong...', 'driver_details' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'driver_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'driver_details' => $this->obj);
}
$this->displayOutput($response);
}
//Change Password
public function changePassword()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['old_password'])) {
$response = array('status' => 0, 'message' => 'Old password is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['new_password'])) {
$response = array('status' => 0, 'message' => 'New password is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['driver_id'])) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'result' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['driver_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'result' => $this->obj);
$this->displayOutput($response);
} else {
$condition = array('driver_id' => $ap['driver_id']);
$staff_details = $this->mdriver->getRow('master_driver', $condition);
if ($staff_details['password'] != md5($ap['old_password'])) {
$response = array('status' => 0, 'message' => "Old password didn't match with previous one", 'result' => $this->obj);
$this->displayOutput($response);
}
if (strtolower($ap['new_password']) == strtolower($ap['old_password'])) {
$response = array('status' => 0, 'message' => "New password same as old password,try something else", 'result' => $this->obj);
$this->displayOutput($response);
}
$data = array('updated_by' => $ap['driver_id'], 'updated_ts' => date('Y-m-d H:i:s'), 'password' => md5($ap['new_password']), 'orginal_password' => $ap['new_password']);
$this->mdriver->update('master_driver', $condition, $data);
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Password Changed</b>',
'description' => 'Driver - '.$staff_details['first_name'].' '.$staff_details['middle_name'].' '.$staff_details['last_name'].' Password Changed',
'link' => '',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $ap['driver_id'],
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => "Password changed successfully", 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'result' => $this->obj);
}
$this->displayOutput($response);
}
public function deleteAccount()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['driver_id'])) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'result' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['driver_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'result' => $this->obj);
$this->displayOutput($response);
} else {
$condition = array('driver_id' => $ap['driver_id']);
$staff_details = $this->mdriver->getRow('master_driver', $condition);
$data = array('updated_by' => $ap['driver_id'], 'updated_ts' => date('Y-m-d H:i:s'), 'status' => '3');
$this->mdriver->update('master_driver', $condition, $data);
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Account Deactivated</b>',
'description' => 'Driver - '.$staff_details['first_name'].' '.$staff_details['middle_name'].' '.$staff_details['last_name'].' Account Deactivated',
'link' => '',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $ap['driver_id'],
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => "Account Deactivated successfully", 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'result' => $this->obj);
}
$this->displayOutput($response);
}
public function updateProfile()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('driver_id'))) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('first_name'))) {
$response = array('status' => 0, 'message' => 'First Name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('last_name'))) {
$response = array('status' => 0, 'message' => 'Last Name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('pin'))) {
$response = array('status' => 0, 'message' => 'Pin is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
// if (empty($this->input->post('mobile'))) {
// $response = array('status' => 0, 'message' => 'Mobile is required', 'driver_details' => $this->obj);
// $this->displayOutput($response);
// }
if (empty($this->input->post('is_australian_licence'))) {
$response = array('status' => 0, 'message' => 'Australian licence is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if ($this->input->post('is_australian_licence') == 'No') {
if (empty($this->input->post('passport_no'))) {
$response = array('status' => 0, 'message' => 'Passport no is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('passport_expiry'))) {
$response = array('status' => 0, 'message' => 'Passport Expiry is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('utility_bill_id'))) {
$response = array('status' => 0, 'message' => 'Utility bill is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
}
if (empty($this->input->post('bank_name'))) {
$response = array('status' => 0, 'message' => 'Bank name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('account_no'))) {
$response = array('status' => 0, 'message' => 'Account no. is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
$result = $this->mdriver->checkDriverDetails(array('driver_id' => $this->input->post('driver_id')));
if (empty($result)) {
$response = array('status' => 0, 'message' => 'Driver ID not exist', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('driver_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'driver_details' => $this->obj);
$this->displayOutput($response);
} else {
$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');
if ($this->input->post('dob')) {
$driver_data['dob'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('dob'))));
}
$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');
if ($driver_data['is_australian_licence'] == 'No') {
$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->input->post('driver_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 ($driver_data['is_australian_licence'] == 'No') {
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'];
}
}
}
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'];
}
}
$this->db->trans_start(); # Starting Transaction
$driver_id = $this->input->post('driver_id');
$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();
$response = array('status' => 0, 'message' => 'Oops!Profile not updated', 'driver_details' => $this->obj);
} 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 User</b>',
'description' => 'Driver - '.$driver_data['first_name'].' '.$driver_data['middle_name'].' '.$driver_data['last_name'].' Details Updated',
'link' => 'admin/driver/editdriver/'.$driver_id,
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('driver_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Profile updated successfully', 'driver_details' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'driver_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'driver_details' => $this->obj);
}
$this->displayOutput($response);
}
//Profile Details
public function myProfile()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['driver_id'])) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['driver_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'profile_details' => $this->obj);
$this->displayOutput($response);
} else {
$profile_details = $this->mdriver->get_driver_details($ap['driver_id']);
if (!empty($profile_details['licence_image'])) {
$profile_details['licence_image'] = '/public/admin_images/driver/licence_image/' . $profile_details['licence_image'];
}
if (!empty($profile_details['licence_expiry_image'])) {
$profile_details['licence_expiry_image'] = '/public/admin_images/driver/licence_expiry_image/' . $profile_details['licence_expiry_image'];
}
if (!empty($profile_details['passport_no_image'])) {
$profile_details['passport_no_image'] = '/public/admin_images/driver/passport_no_image/' . $profile_details['passport_no_image'];
}
if (!empty($profile_details['passport_expiry_image'])) {
$profile_details['passport_expiry_image'] = '/public/admin_images/driver/passport_expiry_image/' . $profile_details['passport_expiry_image'];
}
if (!empty($profile_details['utility_bill_image'])) {
$profile_details['utility_bill_image'] = '/public/admin_images/driver/utility_bill_image/' . $profile_details['utility_bill_image'];
}
if (!empty($profile_details['profile_photo'])) {
$profile_details['profile_photo'] = '/public/admin_images/driver/profile_image/' . $profile_details['profile_photo'];
}
if (!empty($profile_details)) {
$response = array('status' => 1, 'message' => 'Profile Details Fetched Successfully', 'profile_details' => $profile_details);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'profile_details' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'profile_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'profile_details' => $this->obj);
}
$this->displayOutput($response);
}
// Logout
public function logout()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['driver_id'])) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'result' => $this->obj);
$this->displayOutput($response);
}
// if (empty($ap['shift_id'])) {
// $response = array('status' => 1, 'message' => 'Shift ID is required', 'result' => $this->obj);
// $this->displayOutput($response);
// }
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['driver_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'result' => $this->obj);
$this->displayOutput($response);
} else {
$condition = array('driver_id' => $ap['driver_id']);
$user_data['login_status'] = 0;
$user_data['updated_by'] = $ap['driver_id'];
$user_data['updated_ts'] = date('Y-m-d h:i:s');
$this->mdriver->update('master_driver', $condition, $user_data);
$condition = array('user_id' => $ap['driver_id'], 'device_type' => $ap['device_type']);
$api_token_data = array();
//$api_token_data['token_key'] = '';
$api_token_data['session_end_time'] = date('Y-m-d H:i:s');
$this->mdriver->update('api_token_driver', $condition, $api_token_data);
$response = array('status' => 1, 'message' => "Logout Successfully", 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'result' => $this->obj);
}
$this->displayOutput($response);
}
//Odometer Details
public function odometerDetails()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'car_details' => $this->obj,'odometer_list'=>array());
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'car_details' => $this->obj,'odometer_list'=>array());
$this->displayOutput($response);
}
if (empty($ap['driver_id'])) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'car_details' => $this->obj,'odometer_list'=>array());
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['driver_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'car_details' => $this->obj,'odometer_list'=>array());
$this->displayOutput($response);
} else {
$getRentOutCar = $this->mdriver->getRentOutCar($ap['driver_id']);
if (!empty($getRentOutCar)) {
$getRentOutCar['weekly_rent'] = $getRentOutCar['weekly_rent'];
$bond_refund_amt = $this->mdriver->getdriverbondamount($ap['driver_id']);
$getRentOutCar['bond_refund_amt'] = !empty($bond_refund_amt)?number_format($bond_refund_amt,2,'.',''):0;
$getOdometerList = $this->mdriver->getOdometerList($getRentOutCar['rent_out_id']);
if(!empty($getOdometerList)){
foreach($getOdometerList as $key => $odometerList){
if (!empty($odometerList['odometer_image_1'])) {
$getOdometerList[$key]['odometer_image_1'] = '/public/admin_images/odometer/odometer_image_1/' . $odometerList['odometer_image_1'];
}
if (!empty($odometerList['odometer_image_2'])) {
$getOdometerList[$key]['odometer_image_2'] = '/public/admin_images/odometer/odometer_image_2/' . $odometerList['odometer_image_2'];
}
}
}
$response = array('status' => 1, 'message' => 'Rent Out Details Fetched Successfully', 'car_details' => $getRentOutCar,'odometer_list'=>$getOdometerList);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'car_details' => $this->obj,'odometer_list'=>array());
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'car_details' => $this->obj,'odometer_list'=>array());
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'car_details' => $this->obj,'odometer_list'=>array());
}
$this->displayOutput($response);
}
public function addOdometerReading()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('driver_id'))) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('car_id'))) {
$response = array('status' => 0, 'message' => 'Car ID is required', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('rent_out_id'))) {
$response = array('status' => 0, 'message' => 'Rent out ID is required', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('odometer_reading'))) {
$response = array('status' => 0, 'message' => 'Odometer Reading is required', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('total_odometer_reading')) && $this->input->post('total_odometer_reading') != 0) {
$response = array('status' => 0, 'message' => 'Total Odometer Reading is required', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('odometer_update_date'))) {
$response = array('status' => 0, 'message' => 'Odometer Update Date is required', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('service_due_kilometer'))) {
$response = array('status' => 0, 'message' => 'Service Due Kilometer is required', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
// echo '<pre>';
// print_r($this->input->post());
// echo '<pre>';
// print_r($_FILES);
// die;
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'odometer_details' => $this->obj);
$this->displayOutput($response);
} else {
$car_details = $this->db->from('master_car')->where('car_id',$this->input->post('car_id'))->get()->row_array();
if(empty($car_details)){
$response = array('status' => 0, 'message' => 'Car details not found', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if($car_details['total_odometer_reading'] == $this->input->post('odometer_reading')){
$response = array('status' => 0, 'message' => 'Total odometer reading must be updated', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if ($car_details['total_odometer_reading'] >= $this->input->post('odometer_reading')) {
$response = array('status' => 0, 'message' => 'Odometer reading must be grater than total odometer reading', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
$rent_out_details = $this->db->from('rent_out_vehcile')->where('rent_out_id',$this->input->post('rent_out_id'))->get()->row_array();
if(empty($rent_out_details)){
$response = array('status' => 0, 'message' => 'Rent out details not found', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
if($rent_out_details['is_rent_in'] == 1){
$response = array('status' => 0, 'message' => 'Odometer reading not updated because rent in completed', 'odometer_details' => $this->obj);
$this->displayOutput($response);
}
$odometer_data = array();
$odometer_data['odometer_update_date'] = date('Y-m-d H:i:s', strtotime(str_replace('/', '-', $this->input->post('odometer_update_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['odometer_reading'] - $odometer_data['previous_odometer_reading']));
$odometer_data['created_by'] = $this->input->post('driver_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['updated_by'] = $this->input->post('driver_id');
$update_car_data['updated_ts'] = date('Y-m-d H:i:s');
$this->db->update('master_car', $update_car_data, array('car_id' => $odometer_data['car_id']));
$sql = "UPDATE rent_out_vehcile SET notification_counter = 0 WHERE rent_out_id = '".$odometer_data['rent_out_id']."'";
$this->db->query($sql);
$this->db->trans_complete(); # Completing transaction
if ($this->db->trans_status() === FALSE) {
# Something went wrong.
$this->db->trans_rollback();
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'odometer_details' => $this->obj);
} 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>',
'created_by' => $this->input->post('driver_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Odometer reading added successfully', 'odometer_details' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'odometer_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'odometer_details' => $this->obj);
}
$this->displayOutput($response);
}
//Odometer Details
public function getNominateFinesList()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'nominate_fines_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'nominate_fines_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['driver_id'])) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'nominate_fines_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['driver_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'nominate_fines_list' => $this->obj);
$this->displayOutput($response);
} else {
$getNominateFinesList = $this->mdriver->getFinetoll_fees($ap['driver_id'],$ap['car_no']);
if(!empty($getNominateFinesList)){
foreach($getNominateFinesList as $key => $nominateFinesList){
if (!empty($nominateFinesList['referance_date'])) {
$getNominateFinesList[$key]['referance_date'] = date('d/m/Y',strtotime($nominateFinesList['referance_date']));
}
if (!empty($nominateFinesList['nomination_date'])) {
$nominateFinesList[$key]['nomination_date'] = date('d/m/Y', strtotime($nominateFinesList['nomination_date']));
}
if (!empty($nominateFinesList['fine_img'])) {
$getNominateFinesList[$key]['fine_img'] = '/public/admin_images/fine_imgs/' . $nominateFinesList['fine_img'];
}
if (!empty($nominateFinesList['nomination_img'])) {
$getNominateFinesList[$key]['nomination_img'] = '/public/admin_images/nomination_imgs/' . $nominateFinesList['nomination_img'];
}
}
}
$response = array('status' => 1, 'message' => 'Nominate Fines List Fetched Successfully', 'nominate_fines_list'=>$getNominateFinesList);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'nominate_fines_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'nominate_fines_list' => $this->obj);
}
$this->displayOutput($response);
}
private function check_access_token($token_key, $device_type, $driver_id = 0)
{
$condition_token = array('token_key' => $token_key, 'device_type' => $device_type);
if ($driver_id > 0) {
$condition_token['user_id'] = $driver_id;
}
$access_token_result = $this->mdriver->getRow('api_token_driver', $condition_token);
return $access_token_result;
}
//Forgot password
public function forgotPassword()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('email'))) {
$response = array('status' => 0, 'message' => 'Email field is required', 'result' => $this->obj);
$this->displayOutput($response);
}
$condition['email'] = $this->input->post('email');
$driver_details = $this->mdriver->getRow('master_driver', $condition);
if (empty($driver_details)) {
$response = array('status' => 0, 'message' => 'Sorry! User does not exist in our database', 'result' => $this->obj);
$this->displayOutput($response);
} else {
$encoded_key = base64_encode(rand().$driver_details['driver_id']);
$user_data['recovery_key'] = $encoded_key;
$condition_user = array('driver_id' => $driver_details['driver_id']);
$this->mdriver->update('master_driver', $condition_user, $user_data);
$mail['name'] = $driver_details['first_name'] . ' ' . $driver_details['middle_name'] . ' ' . $driver_details['last_name'];
$mail['to'] = $driver_details['email'];
$mail['subject'] = 'Quantum Recover Password';
$link = base_url('forgot_password/recover_password_driver/?recovery_key=' . $encoded_key);
$mail_temp = file_get_contents('./global/mail/forgotpassword_template.html');
$mail_temp = str_replace("{web_url}", SITEURL, $mail_temp);
$mail_temp = str_replace("{logo}", base_url('public/admin_assets/img/logo.png'), $mail_temp);
$mail_temp = str_replace("{name}", $mail['name'], $mail_temp);
$mail_temp = str_replace("{link}", $link, $mail_temp);
$mail_temp = str_replace("{current_year}", CURRENT_YEAR, $mail_temp);
$mail['message'] = $mail_temp;
// echo '<pre>';print_r($mail);die;
if ($this->sendMail($mail)) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Forgot Password</b>',
'description' => $driver_details['first_name'] . ' ' . $driver_details['middle_name'] . ' ' . $driver_details['last_name'].'Password Forgotted',
'link' => '',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $driver_details['driver_id'],
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Password recovery mail has been sent to your email', 'result' => $this->obj);
} else {
$response = array('status' => 0, 'message' => 'Uanble to send recovery mail.', 'result' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'result' => $this->obj);
}
$this->displayOutput($response);
}
public function rentalHistory()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'rental_detail' => $this->obj,'odometer_list'=>array());
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'rental_detail' => $this->obj,'odometer_list'=>array());
$this->displayOutput($response);
}
if (empty($ap['driver_id'])) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'rental_detail' => $this->obj,'odometer_list'=>array());
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['driver_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'rental_detail' => $this->obj);
$this->displayOutput($response);
} else {
$rental_detail = $this->mdriver->getRentoutDetails($ap['driver_id']);
if (!empty($rental_detail)) {
foreach ($rental_detail as $rental_key => $rental) {
if (!empty($rental['created_ts'])) {
$rental_detail[$rental_key]['created_ts'] = (date('d-m-Y',strtotime($rental['created_ts'])));
} else {
$rental_detail[$rental_key]['created_ts'] = '';
}
if (!empty($rental['is_rent_in'])) {
$rental_detail[$rental_key]['is_rent_in'] = ($rental['is_rent_in']==0) ? 'No' : 'Yes';
} else {
$rental_detail[$rental_key]['is_rent_in'] = '';
}
if (!empty($rental['expire'])) {
$rental_detail[$rental_key]['expire'] = (date('d-m-Y',strtotime($rental['expire'])));
} else {
$rental_detail[$rental_key]['expire'] = '';
}
if (!empty($rental['cover_note_img'])) {
$rental_detail[$rental_key]['cover_note_img'] = '/public/admin_images/rent_out/cover_note_imgs/' . $rental['cover_note_img'];
} else {
$rental_detail[$rental_key]['cover_note_img'] = '';
}
}
$response = array('status' => 1, 'message' => 'Rental detail Fetched Successfully', 'rental_detail' => $rental_detail);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'rentout_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'rentout_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'rentout_list' => $this->obj);
}
$this->displayOutput($response);
}
public function getUtilityBillList()
{
$utility_bill_list = $this->mdriver->get_address_proof_list();
if (!empty($utility_bill_list)) {
$response = array('status' => 1, 'message' => 'Utility Bill List Fetched Successfully', 'utility_bill_list' => $utility_bill_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'utility_bill_list' => $this->obj);
}
$this->displayOutput($response);
}
public function getTermsCondition()
{
echo 'When Terms & Condition HTML page will be available then you get the full phase of the terms & condition page';
}
public function getReturnNoticeList()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'return_notice_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'return_notice_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'return_notice_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'return_notice_list' => $this->obj);
$this->displayOutput($response);
} else {
$search_text = isset($ap['search_text'])?$ap['search_text']:'';
$return_notice_list = $this->mdriver->get_return_notice_list($ap['user_id'],$search_text);
if (!empty($return_notice_list)) {
$response = array('status' => 1, 'message' => 'Return Notice Fetched Successfully', 'return_notice_list' => $return_notice_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'return_notice_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'return_notice_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'return_notice_list' => $this->obj);
}
$this->displayOutput($response);
}
public function addReturnNotice()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'return_notice_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'return_notice_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'return_notice_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('rent_out_no'))) {
$response = array('status' => 0, 'message' => 'Rent Out No is required', 'return_notice_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('car_no'))) {
$response = array('status' => 0, 'message' => 'Car no field is required', 'return_notice_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'return_notice_details' => $this->obj);
$this->displayOutput($response);
} else {
$rent_out_data_by_rent_out_no = $this->mdriver->get_rent_out_data_by_rent_out_no($this->input->post('rent_out_no'));
$return_notice_data = array();
$return_notice_data['rent_out_id'] = $rent_out_data_by_rent_out_no['rent_out_id'];
$return_notice_data['car_no'] = $this->input->post('car_no');
$return_notice_data['driver_id'] = $this->input->post('user_id');
$return_notice_data['note'] = $this->input->post('note');
$return_notice_data['created_by'] = $this->input->post('user_id');
$return_notice_data['created_ts'] = date('Y-m-d h:i:s');
if ($this->input->post('retrun_notice_date')) {
$return_notice_data['retrun_notice_date'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('retrun_notice_date'))));
}
}
$added_return_notice = $this->mdriver->insert('return_notice', $return_notice_data);
if ($added_return_notice) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Return Notice</b>',
'description' => 'Return Notice'.$return_notice_data['retrun_notice_date'],
'link' => 'admin/return_notice',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('user_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$condition['driver_id'] = $this->input->post('user_id');
$driver_details = $this->mdriver->getRow('master_driver', $condition);
$mail['name'] = $driver_details['first_name'] . ' ' . $driver_details['middle_name'] . ' ' . $driver_details['last_name'];
$mail['email'] = 'lovedeepkhangura@gmail.com'; //To
$mail['subject'] = 'Driver Return Notice';
$mail_temp = file_get_contents('./global/mail/return_notice_template.html');
$mail_temp = str_replace("{web_url}", SITEURL, $mail_temp);
$mail_temp = str_replace("{logo}", base_url('public/admin_assets/img/logo.png'), $mail_temp);
$mail_temp = str_replace("{name}", $mail['name'], $mail_temp);
$mail_temp = str_replace("{email}", $driver_details['email'], $mail_temp);
$mail_temp = str_replace("{notice_date}", $this->input->post('retrun_notice_date'), $mail_temp);
$mail_temp = str_replace("{description}", $this->input->post('note'), $mail_temp);
$mail_temp = str_replace("{current_year}", CURRENT_YEAR, $mail_temp);
$mail['message'] = $mail_temp;
// echo '<pre>';print_r($mail);die;
$this->sendMail($mail);
$response = array('status' => 1, 'message' => 'Return Notice Added successfully', 'return_notice_details' => $this->obj);
} else {
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'return_notice_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'return_notice_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'return_notice_details' => $this->obj);
}
$this->displayOutput($response);
}
public function getDirectDebitFailedPayments()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'failed_payment_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'failed_payment_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'failed_payment_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'failed_payment_list' => $this->obj);
$this->displayOutput($response);
} else {
$search_text = isset($ap['search_text'])?$ap['search_text']:'';
$failed_payment_list = $this->mdriver->get_failed_payment_list($search_text,$ap['user_id']);
if (!empty($failed_payment_list)) {
$response = array('status' => 1, 'message' => 'Direct Debit Failed Payment Fetched Successfully', 'failed_payment_list' => $failed_payment_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'failed_payment_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'failed_payment_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'failed_payment_list' => $this->obj);
}
$this->displayOutput($response);
}
private function sendMail($data)
{
$this->load->library('email');
$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.hostinger.com';
$config['smtp_port'] = '587';
// $config['smtp_user'] = 'quantum@syscentricdev.com';
// $config['smtp_pass'] = 'Syscentric@123';
$config['smtp_user'] = 'info@qcr24.com.au';
$config['smtp_pass'] = '3_6~40baX)';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->set_crlf("\r\n");
$this->email->from('info@qcr24.com.au', 'Quantum');
$this->email->to($data['email']);
$this->email->subject($data['subject']);
$this->email->message($data['message']);
$this->email->send();
// echo $this->email->print_debugger(); die;
return true;
}
private function checkHttpMethods($http_method_type)
{
if ($_SERVER['REQUEST_METHOD'] == $http_method_type) {
return 1;
}
}
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' => $this->upload->display_errors(), 'status' => 0);
} else {
//echo 'success';die;
$data = array('upload_data' => $this->upload->data());
//print_r($data);die;
$message = array('result' => $data['upload_data']['file_name'], 'status' => 1);
}
return $message;
}
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
private function activity_log_app($activityLogData) {
if ($activityLogData) {
$activityLogData['user_type']='Driver';
$activityLogData['created_ts'] = date('Y-m-d H:i:s');
}
$this->db->insert('activity_log_app', $activityLogData);
}
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
}