Commit 1867ccda by Tobin

dc

parent 65b69a7a
<?php
ob_start();
defined('BASEPATH')OR exit('No direct script access allowed');
header('Content-Type: text/html; charset=utf-8');
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
class Webservices extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('Webservice_model');
$this->load->helper('url');
$this->load->library('form_validation');
$class = $this->router->fetch_class();
$method = $this->router->fetch_method();
if ($this->input->server('REQUEST_METHOD') == 'GET')
$postdata = json_encode($_GET);
else if ($this->input->server('REQUEST_METHOD') == 'POST')
$postdata = file_get_contents("php://input");
$auth = '';
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
}
$this->last_id = set_log($class, $method, $postdata, $auth);
}
public function user_registration() {
header('Content-type: application/json');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
if(isset($request)){
$config = array(
array(
'field'=>'phone_number',
'label'=>'Phone Number',
'rules'=>'required',
'errors'=>array(
'required'=>'You must provide your phone number', ),
),
array(
'field'=>'password',
'label'=>'Password',
'rules'=>'required',
'errors'=>array(
'required'=>'You must provide your password.',
)
),
array(
'field'=>'company_id',
'label'=>'company_id',
'rules'=>'required',
'errors'=>array(
'required'=>'You must provide company Id',
)
),
array(
'field'=>'first_name',
'label'=>'first name',
'rules'=>'required',
'errors'=>array(
'required'=>'You must provide your first name',
)
)
);
$this->form_validation->set_data($request);
$this->form_validation->set_rules($config);
if($this->form_validation->run()==FALSE){
$err = $this->form_validation->error_array();
$result = array('status'=>'error','message'=>$err, 'error'=>'505');
$this->response($result);
}else{
$result = $this->Webservice_model->user_reg($request);
if ($result['status'] == 'success') {
$result = array('status'=>"success",
'data'=>array('auth_token'=>$result['auth_token'],
'user'=>array('user_id'=>$result['user_id'],
'phone'=>$result['phone'], 'name'=>$result['name'])));
} else {
$result = array('status'=>'error','message'=>$result['message'], 'error'=>'501');
}
$this->response($result);
}
} else {
$result = array('status'=>'error','message'=>'invalid Request','error'=>'505');
$this->response($result);
}
}
public function response($res) {
print json_encode($res);
}
public function do_login() {
header('Content-type: application/json');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$result = $this->Webservice_model->login($request);
if ($result['status'] == 'success') {
$result = array('status'=>"success",
'data'=>array('auth_token'=>$result['auth_token'],
'user'=>array('user_id'=>$result['user_id'],
'phone'=>$result['phone'], 'name'=>$result['name'])));
} else {
$result = array('status'=>'error','message'=>'Unknown Credential! Try Again','error'=>'502');
}
$this->response($result);
}
public function company_list() {
header('Content-type: application/json');
$result = $this->Webservice_model->company_list();
if ($result) {
print json_encode(array('status'=>'success','data'=>$result));
} else {
print json_encode(array('status'=>'error','message'=>'No Result Found','error'=>'502'));
}
}
public function edit_user() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$query = $this->db->where('unique_id', $auth)->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$cust_id = $rs->cust_id;
$phone = $request['phone'];
$this->db->where('phone', $phone);
$this->db->where('customer_id!=', $cust_id);
$count = $this->db->get('customers')->result();
if (count($count) == 0) {
$result = $this->Webservice_model->edit_user($request);
if ($result) {
print json_encode(array('status'=>'success'));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'508'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Mobile Number Already Exists','error'=>'508'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'508'));
}
}
}
public function complaints() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$result = $this->Webservice_model->complaints($request);
if ($result['status'] == 'success') {
print json_encode(array('status'=>'success'));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'601'));
}
} else {
print json_encode(array('status'=>'error','message'=>'You are not authorized to access the server',
'error'=>'Authentication Failed'));
}
}
public function save_fcmtoken() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
if (isset($request['fcm_token'])) {
$result = $this->Webservice_model->save_token($request);
if ($result) {
print json_encode(array('status'=>'success'));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'605'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'605'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'605'));
}
}
public function forgot_password() {
header('Content-type: application/json');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
if(isset($request['phone_number'])){
$res = $this->Webservice_model->forgetPassword($request);
if ($res) {
echo json_encode(array('status'=>'success'));
} else {
echo json_encode(array('status'=>'error','message'=>'Sorry. Please Enter Valid Phone Number'));
}
} else{
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'508'));
}
}
public function update_password() {
header('Content-type: application/json');
if(isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$query = $this->db->where('unique_id', $auth)->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$cust_id = $rs->cust_id;
$this->db->where('customer_id=', $cust_id);
$query1 = $this->db->get('customers');
$result = $query1->row();
if ($result->password == md5($request['current_password'])) {
$result = $this->Webservice_model->update_password($request);
if ($result) {
print json_encode(array('status'=>'success'));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'508'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Invalid Old Password','error'=>'508'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'508'));
}
}
}
public function get_profile() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request = $_GET;
$request['auth'] = $auth;
$result = $this->Webservice_model->profile($request);
if ($result) {
print json_encode(array('status'=>'success','data' =>$result));
} else {
print json_encode(array('status'=>'error','code'=>'205','message'=>'Something Went wrong'));
}
} else {
print json_encode(array('status'=>'error','code'=>'205','message'=>'Something Went wrong'));
}
}
public function update_user_location() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
if ($request['latitude'] && $request['longitude']) {
$result = $this->Webservice_model->update_user_location($request);
if ($result) {
print json_encode(array('status'=>'success'));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'605'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'605'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'605'));
}
}
public function update_profile_photo() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
if (is_uploaded_file($_FILES['profile_photo']['tmp_name'])) {
$uploads_dir = 'assets/uploads/profile_pic/';
$tmp_name = $_FILES['profile_photo']['tmp_name'];
$pic_name = $_FILES['profile_photo']['name'];
$pic_name = str_replace(' ','_', mt_rand().$pic_name);
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
$request = $_POST;
$request['profile_photo'] = $uploads_dir.$pic_name;
$request['auth'] = $auth;
$result = $this->Webservice_model->update_profile_photo($request);
if ($result) {
print json_encode(array('status'=>'success'));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'207'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'207'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'207'));
}
}
public function call_ambulance() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$result = $this->Webservice_model->call_ambulance($request);
if ($result) {
print json_encode(array('status'=>'success','data'=>$result));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'507'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'507'));
}
}
public function nearest_ambulance() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$result = $this->Webservice_model->nearest_ambulance($request);
if ($result) {
print json_encode(array('status'=>'success','data'=>$result));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'503'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'503'));
}
}
public function trip_completion_details() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request = $_GET;
$request['auth'] = $auth;
$result = $this->Webservice_model->trip_completion_details($request);
if ($result) {
print json_encode(array('status'=>'success','data'=>$result));
} else {
print json_encode(array('status'=>'error','message'=>'No Result Found','error'=>'602'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'602'));
}
}
public function request_cancelled() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true); ;
$request['auth'] = $auth;
if (isset($request['request_id'])) {
$result = $this->Webservice_model->cancel_request($request);
if ($result) {
print json_encode(array('status'=>'success'));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'602'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'602'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'602'));
}
}
public function trip_cancel() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true); ;
$request['auth'] = $auth;
if (isset($request['trip_id'])) {
$result = $this->Webservice_model->trip_cancel($request);
if ($result) {
print json_encode(array('status'=>'success'));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'1602'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'608'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'602'));
}
}
public function trip_history() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$result = $this->Webservice_model->trip_history($request);
if ($result) {
print json_encode(array('status'=>'success','data'=>$result));
} else {
print json_encode(array('status'=>'success','data'=>[]));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'503'));
}
}
public function request_status() {
header('Content-type: application/json');
$request = $_GET;
if (isset($request['request_id'])) {
$result = $this->Webservice_model->req_status($request);
if ($result->request_status == '3') {
print json_encode(array('status'=>'success','data'=>array('request_status'=>'0')));
} else if($result->request_status == '4') {
print json_encode(array('status'=>'success','data'=>$result));
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'606'));
}
} else {
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'606'));
}
}
public function app_status() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$result = $this->Webservice_model->statusof_app($request);
if ($result) {
$result->app_status = '1';
$id = $result->trip_id;
$drvr_status = $this->Webservice_model->status_driver($id);
print json_encode(array('status'=>'success','data'=>$result));
} else {
print json_encode(array('status'=>'success','data'=>array('app_status'=>'0')));
}
} else {
print json_encode(array('status'=>'error','code'=>'209','message'=>'Something Went wrong'));
}
}
public function phone_number_availability(){
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
if (!empty($request)) {
$phStatus = $this->Webservice_model->phone_number_availability($request);
if($phStatus){
print json_encode(array('status'=>'success','data'=>array('is_available'=>true)));
} else {
print json_encode(array('status'=>'success','data'=>array('is_available'=>false)));
}
} else {
print json_encode(array('status'=>'error','code'=>'210','message'=>'Required Fields are empty.'));
}
} else {
print json_encode(array('status'=>'error','code'=>'209','message'=>'Something Went wrong'));
}
}
}?>
\ No newline at end of file
<?php
defined('BASEPATH')OR exit('No direct script access allowed');
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
class Webservices_driver extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('Webservices_driver_model');
$class = $this->router->fetch_class();
$method = $this->router->fetch_method();
if ($this->input->server('REQUEST_METHOD') == 'GET')
$postdata = json_encode($_GET);
else if ($this->input->server('REQUEST_METHOD') == 'POST')
$postdata = file_get_contents("php://input");
$auth = '';
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
}
$this->last_id = set_log($class, $method, $postdata, $auth);
}
// *********************** NEMT DRIVER DOCUMENTATION ********************
// *********************** DRIVER LOGIN ********************
public function do_login() {
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$result = $this->Webservices_driver_model->login($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success', 'data' => array('auth_token' => $result['auth_token'], 'user' => array('user_id' => $result['user_id'], 'name' => $result['name'], 'phone' => $result['phone'], 'first_time_user' => $result['first_time_user']))));
} else {
print json_encode(array('status' => 'error', 'message' => 'Unknown Credential! Try Again', 'error' => '202'));
}
}
// *********************** DOCUMENT UPLOAD ********************
public function document_upload() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
if (is_uploaded_file($_FILES['image']['tmp_name'])) {
$uploads_dir = 'assets/uploads/profile_pic/';
$tmp_name = $_FILES['image']['tmp_name'];
$pic_name = $_FILES['image']['name'];
$pic_name = str_replace(' ', '_', mt_rand().$pic_name);
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
$request = $_POST;
$request['image'] = $uploads_dir.$pic_name;
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->doc_upload($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '207'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '207'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '207'));
}
}
// *********************** GET DRIVER STATUS ********************
public function get_driver_status() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->driver_status($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success', 'data' => $result));
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
// *********************** UPDATE DRIVER STATUS ********************
public function update_driver_status() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
if (isset($request['driver_status'])) {
$result = $this->Webservices_driver_model->status($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
$this->Webservices_driver_model->driver_onstatus($request);
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
}
// *********************** ARRIVED AT CUSTOMER ********************
public function arrived_at_customer() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
if (isset($request['trip_id'])) {
$result = $this->Webservices_driver_model->arrived_at_customer($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
}
// *********************** GET DRIVER PROFILE ********************
public function get_profile() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request = $_GET;
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->profile($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success', 'data' =>$result));
} else {
print json_encode(array('status' => 'error', 'code' => '205', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '205', 'message' => 'Something Went wrong'));
}
}
// *********************** UPDATE DRIVER PASSWORD ********************
public function update_password() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$query = $this->db->where('unique_id', $auth)->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driver_id = $rs->driver_id;
$this->db->where('driver_id=', $driver_id);
$query1 = $this->db->get('drivers');
$result = $query1->row();
if ($result->password == md5($request['current_password'])) {
$result = $this->Webservices_driver_model->update_password($request);
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '508'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Invalid Old Password', 'error' => '508'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '508'));
}
}
}
// *********************** UPDATE DRIVER USER NAME ********************
public function update_user_name() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->update_user_name($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '203'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '204'));
}
}
// *********************** UPDATE VEHICLE NUMBER ********************
public function update_vehicle_number() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->update_vehicle_number($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '203'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '204'));
}
}
// *********************** UPDATE DRIVER LOCATION ********************
public function update_driver_location() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->driver_location($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
// *********************** TRIP ACCEPT ********************
public function trip_accept() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$data = $this->db->where('transport_id', $request['request_id'])->get('transport_details')->row();
if ($data->status == 1) {
print json_encode(array('status' => 'error', 'message' => 'Trip Assigned '));
}
elseif($data->status == 3) {
print json_encode(array('status' => 'error', 'message' => 'Trip Cancelled '));
}
else {
$result = $this->Webservices_driver_model->accept($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success', 'data' => $result));
} else {
print json_encode(array('status' => 'error', 'code' => '207', 'message' => 'Something Went wrong'));
}
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
}
// *********************** PAYMENT STATUS ********************
public function payment_status() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request = $_GET;
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->payment_status($request);
if ($result) {
print json_encode(array('status' => 'success', 'data' => $result));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '505'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '534'));
}
}
// *********************** APP STATUS ********************
public function app_status() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->statusof_app($request);
header('Content-type: application/json');
if ($result) {
$result->app_status = '1';
$drvr_status = $this->Webservices_driver_model->status_driver($result->trip_id);
$result->driver_status = $drvr_status;
print json_encode(array('status' => 'success', 'data' => $result));
} else {
print json_encode(array('status' => 'success', 'data' => array('app_status' => '0')));
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
// *********************** EMERGENCY RIDE HISTORY ********************
public function emergency_ride_history() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
if ($page == 0) {
$page = 1;
}
$result = $this->Webservices_driver_model->history_trips_emergency($request);
if ($result) {
$tmp = $this->db->query($result)->result();
$total = $this->db->query($result)->num_rows();
$per_page = 5;
$total_pages = ceil($total / $per_page);
$current_page = $page;
$query = $this->db->where('unique_id', $auth)->get('driver_auth_table');
$rs = $query->row();
$driv_id = $rs->driver_id;
if ($total > 0) {
$limit = ($per_page * ($current_page - 1));
$limit_sql = " ORDER BY t.transport_id DESC LIMIT $limit,$per_page";
$result = $this->db->query($result.$limit_sql)->result();
$query = $this->db->where('unique_id', $auth)->get('driver_auth_table');
$rs = $query->row();
$driv_id = $rs->driver_id;
print json_encode(array('status' => 'success', 'data' => array('trips' => $result), 'meta' => array('total' => $total, 'per_page' => $per_page, 'total_pages' => $total_pages, 'current_page' => $current_page)));
} else {
print json_encode(array('status' => 'success', 'data' => array('trips' => []), 'meta' => array('total' => $total, 'per_page' => $per_page, 'total_pages' => $total_pages, 'current_page' => $current_page)));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '503'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '503'));
}
}
// *********************** EMERGENCY RIDE HISTORY ********************
public function scheduled_ride_history() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
if ($page == 0) {
$page = 1;
}
$result = $this->Webservices_driver_model->history_trips_schedule($request);
if ($result) {
$total = COUNT($result);
$per_page = 5;
$total_pages = ceil($total / $per_page);
$current_page = $page;
$query = $this->db->where('unique_id', $auth)->get('driver_auth_table');
$rs = $query->row();
$driv_id = $rs->driver_id;
if ($total > 0) {
print json_encode(array('status' => 'success', 'data' => array('trips' => $result), 'meta' => array('total' => $total, 'per_page' => $per_page, 'total_pages' => $total_pages, 'current_page' => $current_page)));
} else {
print json_encode(array('status' => 'success', 'data' => array('trips' => []), 'meta' => array('total' => $total, 'per_page' => $per_page, 'total_pages' => $total_pages, 'current_page' => $current_page)));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '503'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '503'));
}
}
// *********************** END NEMT DRIVER DOCUMENTATION ********************
public function registration() {
header('Content-type: application/json');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$result = $this->Webservices_driver_model->driver_reg($request);
header('Content-type: application/json');
$otp = rand(1111, 9999); //print_r($otp);
if ($result['status'] == 'success') {
$result = array('status' => "success", 'data' => array('auth_token' => $result['auth_token'], 'user' => array('user_id' => $result['user_id'], 'name' => $result['name'], 'phone' => $result['phone'], 'email' => $result['email'], 'city' => $result['city'], 'profile_photo' => $result['image'], 'is_phone_verified' => true)));
} else {
//$result = array('status'=>"error",'message' =>'Mobile Number already Exists','error'=>'201');
$result = array('status' => 'error', 'message' => $result['message'], 'error' => '501');
}
$this->response($result);
}
function response($res) {
header('Content-type: application/json');
print json_encode($res);
}
public function get_booster_status() {
header('Content-type: application/json');
$request = $_GET;
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->get_booster_status($request);
if ($result) {
print json_encode(array('status' => 'success', 'data' => $result));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '505'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '508'));
}
}
public function trip_cancel() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true); ;
$request['auth'] = $auth;
if (isset($request['trip_id']) && isset($request['cancellation_reason'])) {
$result = $this->Webservices_driver_model->cancelReason($request);
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '1602'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '608'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '602'));
}
}
public function booster_seat() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true); ;
$request['auth'] = $auth;
if (isset($request['is_booster_seat'])) {
$result = $this->Webservices_driver_model->booster_seat($request);
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '1602'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '608'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '602'));
}
}
public function update_fcm_token() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
// print_r($request);
$result = $this->Webservices_driver_model->update_fcm($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '203'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '204'));
}
}
public function mobile_number_availability() {
header('Content-type: application/json');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
if (isset($request['phone'])) {
$result = $this->Webservices_driver_model->mobile_availability($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success', 'data' => array('phone' => $request['phone'], 'is_available' => filter_var($result['is_available'], FILTER_VALIDATE_BOOLEAN))));
} else {
print json_encode(array('status' => 'success', 'data' => array('phone' => $request['phone'], 'is_available' => filter_var(true, FILTER_VALIDATE_BOOLEAN))));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Mobile Number is missing. Please try again', 'error' => 'phone is missing'));
}
}
public function update_profile() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$query = $this->db->where('unique_id', $auth)->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$cust_id = $rs->cust_id;
}
$postdata = $_POST['profile_update'];
//$request = $_POST;
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$email = $request['email'];
$phone = $request['phone'];
$this->db->where('id!=', $cust_id);
$this->db->where('email', $email);
$this->db->or_where("phone", $phone);
$count = $this->db->get('driver')->result();
//$count = $this->db->count_all_results();
//print_r($count);
if (count($count) == 0) {
$result = $this->Webservices_driver_model->prof_update($request);
if ($result) {
//print_r($result);
print json_encode(array('status' => 'success', 'data' => array('id' => $result->id, 'name' => $result->driver_name, 'phone' => $result->phone, 'email' => $result->email, 'address' => $result->address, 'city' => $result->city, 'state' => $result->state, 'postal_code' => $result->post_code, 'profile_photo' => $result->image, 'is_phone_verified' => false)));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '508'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Email Already Exists', 'error' => '508'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '508'));
}
}
public function document_status() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->doc_status($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success', 'data' => array('documents' => $result)));
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '204', 'message' => 'Something Went wrong'));
}
}
public function update_driver_type() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->type_driver($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
}
public function profile_photo_upload() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = $_POST['image'];
print_r($postdata);
if (is_uploaded_file($_FILES['image']['tmp_name'])) {
$uploads_dir = './assets/uploads/profile_pic/';
$tmp_name = $_FILES['image']['tmp_name'];
$pic_name = $_FILES['image']['name'];
$pic_name = str_replace(' ', '_', mt_rand().$pic_name);
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
$request = $_POST;
$request['image'] = $uploads_dir.$pic_name;
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->photo_upload($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '207'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '207'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '207'));
}
}
public function trip_start() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
if (isset($request['trip_id'])) {
$result = $this->Webservices_driver_model->start_trip($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
//'a534457488937db4b21d0a043eb6581a'
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
public function help() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = $_GET;
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->help_pages($request);
header('Content-type: application/json');
if (isset($request['id'])) {
if ($result) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
$rs = $query->row();
$driv_id = $rs->driver_id;
$is_help = $this->Webservices_driver_model->is_help_status($driv_id, $result['id']);
$rs->is_helpful = $is_help;
print json_encode(array('status' => 'success', 'data' => array('id' => $result['id'], 'title' => $result['title'], 'icon' => $result['icon'], 'content' => $result['content'], 'is_helpful' => $is_help)));
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
//'a534457488937db4b21d0a043eb6581a'
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
public function help_page_list() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
//$request = $_GET;
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->help_list($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success', 'data' => array('help' => $result)));
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
//'a534457488937db4b21d0a043eb6581a'
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
public function help_page_review() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->help_review($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
}
public function update_vehicle_details() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->update_vehicle($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '210', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '210', 'message' => 'Something Went wrong'));
}
}
public function update_accesibility_settings() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->update_settings($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
}
public function fetch_accesibility_settings() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request = $_GET;
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->fetch_settings($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success', 'data' => array('is_deaf' => filter_var($result['is_deaf'], FILTER_VALIDATE_BOOLEAN), 'is_flash_required_for_requests' => filter_var($result['is_flash_required_for_requests'], FILTER_VALIDATE_BOOLEAN))));
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
public function request_details($request_id = null) {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request = $_GET;
$request['auth'] = $auth;
if (isset($request['request_id'])) {
$result = $this->Webservices_driver_model->req_details($request);
header('Content-type: application/json');
if (count($result) > 0) {
$result->request_id = $request['request_id'];
$car_image = $this->Webservices_driver_model->car_type_image($result->car_type);
$result->car_type_image = $car_image;
$car_type = $this->Webservices_driver_model->car_type($result->car_type);
$result->car_type = $car_type;
// $is_help = $this->Webservices_driver_model->is_help_status($driv_id,$result['id']);
// $rs->is_helpful = $is_help;
print json_encode(array('status' => 'success', 'data' => $result));
} else {
print json_encode(array('status' => 'error'));
}
} else {
print json_encode(array('status' => 'error', 'error' => '209', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'error' => '209', 'message' => 'Something Went wrong'));
}
}
public function trip_summary($id = null) {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$request = $_GET;
if (isset($request['trip_id'])) {
$result = $this->Webservices_driver_model->summary_trip($request);
header('Content-type: application/json');
if (count($result) > 0) {
print json_encode(array('status' => 'success', 'data' => $result));
} else {
print json_encode(array('status' => 'error', 'code' => '202', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '203', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
public function confirm_car_arrival() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
if (isset($request['trip_id'])) {
$result = $this->Webservices_driver_model->confirm_arrival($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
}
public function confirm_cash_collection() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
if (isset($request['trip_id'])) {
$result = $this->Webservices_driver_model->confirm_cash($request);
header('Content-type: application/json');
if ($result) {
print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
}
public function rider_feedback_issues() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$page = $_GET['page'] >= 1 ? $_GET['page'] : 1;
$result = $this->Webservices_driver_model->ride_feedback($request);
header('Content-type: application/json');
if ($result) {
$total = count((array)$result);
$per_page = 20;
$total_pages = ceil($total / $per_page);
$current_page = $page;
print json_encode(array('status' => 'success', 'data' => array('issues' => $result), 'meta' => array('total' => $total, 'per_page' => $per_page, 'total_pages' => $total_pages, 'current_page' => $current_page)));
} else {
print json_encode(array('status' => 'success', 'data' => []));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '503'));
}
}
public function rider_feedback_comments() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$page = $_GET['page'] >= 1 ? $_GET['page'] : 1;
$result = $this->Webservices_driver_model->feedback_comments($request);
header('Content-type: application/json');
if ($result) {
//print_r($result);
//$start_time =$result['trip_id'];
//print_r($start_time);
// $total = $this->db->query($result)->num_rows();
$total = count((array)$result);
// print_r($total);
$per_page = 20;
$total_pages = ceil($total / $per_page);
$current_page = $page;
print json_encode(array('status' => 'success', 'data' => array('comments' => $result), 'meta' => array('total' => $total, 'per_page' => $per_page, 'total_pages' => $total_pages, 'current_page' => $current_page)));
} else {
print json_encode(array('status' => 'success', 'data' => []));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '503'));
}
}
public function rating_details() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
//$postdata = file_get_contents("php://input");
$request = $_GET;
$request['auth'] = $auth;
$result = $this->Webservices_driver_model->rating($request);
header('Content-type: application/json');
if ($result) {
//$str =(int)$result->average_rating;
//$str = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', $str);
//print_r($str);
//echo trim($str, '"');
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
$rs = $query->row();
$driv_id = $rs->driver_id;
$average_rating = $this->Webservices_driver_model->avg_rating($driv_id);
//print_r($average_rating);
if ($average_rating == '') {
$avg = '0';
} else {
$avg = $average_rating;
}
$result->average_rating = $avg;
$tot_requests = $this->Webservices_driver_model->num_rides($driv_id);
//print_r($tot_requests);
$result->total_requests = $tot_requests;
$req_accepted = $this->Webservices_driver_model->num_requests($driv_id);
$result->requests_accepted = $req_accepted;
$tot_trips = $this->Webservices_driver_model->num_trips($driv_id);
$result->total_trips = $tot_trips;
$trips_cancelled = $this->Webservices_driver_model->num_cancelled($driv_id);
//print_r($trips_cancelled);
$result->trips_cancelled = $trips_cancelled;
//$test = json_encode(array('status' => 'success','data' =>$result));
//$con = str_replace("\"", "", $test);
//print $con;
print json_encode(array('status' => 'success', 'data' => $result), JSON_NUMERIC_CHECK);
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
//'a534457488937db4b21d0a043eb6581a'
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
public function trip_details($trip_id = null) {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$request = $_GET;
if (isset($request['trip_id'])) {
$result = $this->Webservices_driver_model->tripdetails($request);
header('Content-type: application/json');
if (count($result) > 0) {
//print_r($result);
$rate = $this->Webservices_driver_model->driver_rate($request['trip_id']);
$result->rating = $rate;
print json_encode(array('status' => 'success', 'data' => $result));
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
}
}
public function trip_list_for_today() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$request['auth'] = $auth;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
if ($page == 0) {
$page = 1;
}
// $start_time = strtotime(date('Y-m-d 00:00:00'));
// $end_time = strtotime(date('Y-m-d 23:59:59'));
$start_time = strtotime(date('Y-m-d 00:00:00'));
$end_time = strtotime(date('Y-m-d 23:59:59'));
$result = $this->Webservices_driver_model->today_trips($request, $start_time, $end_time);
if ($result) {
// print_r($result);
$total = $this->db->query($result)->num_rows();
$per_page = 2;
$total_pages = ceil($total / $per_page);
$current_page = $page;
if ($total > 0) {
$limit = ($per_page * ($current_page - 1));
$limit_sql = " LIMIT $limit,$per_page";
$result = $this->db->query($result.$limit_sql)->result();
$id = $result->driver_id;
$start_time = strtotime(date('Y-m-d 00:00:00'));
$end_time = strtotime(date('Y-m-d 23:59:59'));
$id = $result->driver_id;
$query = $this->db->where('unique_id', $auth)->get('driver_auth_table');
$rs = $query->row();
$driv_id = $rs->driver_id;
$fare = $this->Webservices_driver_model->totalfare_today($start_time, $end_time, $driv_id);
$rs->total_fare = $fare;
$rides = $this->Webservices_driver_model->total_rides($start_time, $end_time, $driv_id);
$rs->total_rides_taken = $rides;
$tot_onlinetime = $this->Webservices_driver_model->total_online_time($driv_id);
$rs->total_online_time = $tot_onlinetime;
//print_r($result);
print json_encode(array('status' => 'success', 'data' => array('total_fare' => $fare, 'total_online_time' => $tot_onlinetime, 'total_rides_taken' => $rides, 'trips' => $result), 'meta' => array('total' => $total, 'per_page' => $per_page, 'total_pages' => $total_pages, 'current_page' => $current_page)));
} else {
print json_encode(array('status' => 'success', 'data' => array('total_fare' => 0, 'total_rides_taken' => 0, 'total_online_time' => 0, 'trips' => []), 'meta' => array('total' => $total, 'per_page' => $per_page, 'total_pages' => $total_pages, 'current_page' => $current_page)));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '503'));
}
} else {
print json_encode(array('status' => 'error', 'message' => 'Something Went wrong', 'error' => '503'));
}
}
function fcm_usermessage($request) {
/*$postdata = file_get_contents("php://input");
$request = json_decode($postdata,true);*/
$this->Webservices_driver_model->message($request);
/*
if($result){
print json_encode(array('status'=>'success','data'=>array('id'=>$result['trip_id'])));
}else{
print json_encode(array('status'=>'error','message'=>'Something Went wrong','error'=>'605'));
}
*/
}
public function updatedriver_status() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
if (isset($request['driver_status'])) {
$result = $this->Webservices_driver_model->driver_onstatus($request);
header('Content-type: application/json');
if ($result) {
return 0;
//print json_encode(array('status' => 'success'));
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
} else {
print json_encode(array('status' => 'error', 'code' => '208', 'message' => 'Something Went wrong'));
}
}
public function arrived_on_hospital() {
header('Content-type: application/json');
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$request['auth'] = $auth;
$result = $request['path'];
$trip_path = json_encode($result);
$array = array();
foreach($result as $rs) {
$latlng = $rs['latitude'].','.$rs['longitude'];
$array[] = $latlng;
}
$count = count($array);
$i = 0;
$distance_val = 0;
while ($i < $count - 1) {
list($lat1, $lon1) = explode(',', $array[$i]);
list($lat2, $lon2) = explode(',', $array[$i + 1]);
$unit = 'K';
$distance_val += $this->distance_calculate($lat1, $lon1, $lat2, $lon2, $unit);
$i++;
}
$rs = $distance_val;
$trip_end_time = time();
$this->db->where('transport_id', $request['trip_id'])->update('transport_details', array('trip_end_time' => $trip_end_time, 'trip_path' => $trip_path));
$res = $this->db->where('transport_id', $request['trip_id'])->get('transport_details')->row();
$trip_start_time = $res->trip_start_time;
$trip_end_time = $res->trip_end_time;
$distance = ($rs);
$time = (($trip_end_time - $trip_start_time) / 60);
$total_time = $time;
$hours = floor($time / 60);
$minutes = ($time % 60);
$time = $hours.':'.$minutes;
$minutes_travel = intval($total_time);
if ($minutes_travel == '0') {
$hours = '0 : 01';
} else {
$hours = convertToHoursMins($minutes_travel, '%2d : %02d ');
}
$array = array('trip_distance' => $distance, 'start_time' => $request['start_time'], 'end_time' => $request['end_time'],
'total_time' => $hours,
'status' => 6);
$this->db->where('transport_id', $request['trip_id'])->update('transport_details', $array);
$data = $this->db->select('vehicle_type,transport_id,trip_distance,total_time,pickup_lat AS source_latitude,pickup_lng AS source_longitude, drop_lat AS destination_latitude,drop_lng AS destination_longitude')->where('transport_id', $request['trip_id'])->get('transport_details')->row_array();
$trip_id = $request['trip_id'];
$data['time'] = $total_time;
$fare = $this->Webservices_driver_model->fare_calculate($data, $trip_id);
$result = $this->Webservices_driver_model->get_trip_info($request['trip_id']);
$this->Webservices_driver_model->message($request['trip_id']);
if ($result) {
print json_encode(array('status' => 'success', 'data' => $result));
} else {
print json_encode(array('status' => 'error', 'error' => '211', 'message' => 'Invalid booking details'));
}
} else {
print json_encode(array('status' => 'error', 'error' => '210', 'message' => 'Something Went wrong'));
}
}
public function distance($origins, $destination) {
$data1 = "SELECT * FROM settings WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
$key = $rs->key;
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=$origins&destinations=$destination&mode=driving&key=$key";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response, true);
return $dist = $response_a['rows'][0]['elements'][0]['distance']['value'];
}
function distance_calculate($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
return ($miles * 1.609344);
}
function get_cal() {
$num = 5;
$sum = 0;
for($count = 1; $count <= $num; $count++)
{
$sum += $count;
}
print_r($sum);exit();
return $sum;
}
}
\ No newline at end of file
<?php
class Webservice_model extends CI_Model {
function __construct() {
parent::__construct();
date_default_timezone_set('Asia/Kolkata');
}
public function user_reg($data='') {
$num = $this->db->where('phone', $data['phone_number'])->get('customers')->num_rows();
if ($num > 0) {
$result = array('status'=>'error','message'=>'Mobile number Already Exists');
}
else {
$unique_id = $this->generate_unique();
$this->db->insert('customers', array('phone'=>$data['phone_number'],'first_name'=>$data['first_name'],'last_name'=>$data['last_name'],'password'=>md5($data['password'])));
$db_data = array();
$user_id = $this->db->insert_id();
$this->db->insert('cust_company_list', array('user_id'=>$user_id,'company_id'=>$data['company_id']));
$this->EncryptedPatientKey($unique_id, $user_id);
if ($user_id) {
$result = array('status'=>'success','auth_token'=>$unique_id,'user_id'=>$user_id,
'phone'=>$data['phone_number'],'name'=>$data['first_name']." ".$data['last_name']);
} else {
$result = array('status'=>'error','message'=>'Something Went wrong');
}
}
return $result;
}
public function generate_unique() {
$unqe = md5(uniqid(time().mt_rand(), true));
return $unqe;
}
public function EncryptedPatientKey($unique_id, $user_id) {
$this->db->insert('auth_table', array('cust_id'=>$user_id,'unique_id'=>$unique_id));
}
public function login($request='') {
$this->db->where("phone = '".$request['phone_number']."'");
$this->db->where('password', md5($request['password']));
$this->db->where('status !=', 0);
$query = $this->db->get('customers');
if ($query->num_rows() > 0) {
$unique_id = $this->generate_unique();
$rs = $query->row();
$this->EncryptedPatientKey($unique_id, $rs->customer_id);
return $result = array('status'=>'success','user_id'=>$rs->customer_id,
'auth_token'=>$unique_id,'phone'=>$rs->phone,
'name'=>$rs->first_name." ".$rs->last_name);
} else {
return false;
}
}
public function company_list() {
$data = "SELECT id AS company_id, company_name AS company_name FROM `company` ORDER BY id DESC";
$query = $this->db->query($data)->result();
if($query){
return $query;
}else{
return false;
}
}
public function edit_user($request='') {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$data = array();
$custCompanyId = array();
if (isset($request['company_id']) && $request['company_id'] != '') {
$custCompanyId['company_id'] = $request['company_id'];
}
if (isset($request['first_name']) && $request['first_name'] != '') {
$data['first_name'] = $request['first_name'];
}
if (isset($request['last_name']) && $request['last_name'] != '') {
$data['last_name'] = $request['last_name'];
}
if (EMPTY($request['last_name'])) {
$data['last_name'] = "";
}
if (isset($request['phone']) && $request['phone'] != '') {
$data['phone'] = $request['phone'];
}
$rs = $query->row();
$this->db->where('customer_id', $rs->cust_id)->update('customers', $data);
$this->db->where('user_id', $rs->cust_id)->update('cust_company_list', $custCompanyId);
return true;
} else {
return false;
}
}
public function complaints($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$data = array('complaint'=>$request['complaint'],'user_id'=>$rs->cust_id);
$this->db->insert('complaints', $data);
return $result = array('status'=>'success');
} else {
return false;
}
}
public function save_token($request='') {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$id = $rs->cust_id;
$data = array('fcm_token'=>$request['fcm_token']);
$result = $this->db->where('customer_id', $id)->update('customers', $data);
return $result;
} else {
return false;
}
}
public function forgetpassword($request='') {
$query = $this->db->where('phone', $request['phone_number'])->get('customers');
if ($query->num_rows() > 0) {
$rs = $query->row();
$user_id = $rs->customer_id;
$data = array('password'=>md5($request['new_password']));
$this->db->where('customer_id', $user_id);
$this->db->update('customers',$data);
return $result = array('status'=>'success');
} else {
return false;
}
}
public function update_password($request='') {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$user_id = $rs->cust_id;
$data = array('password'=>md5($request['new_password']));
$this->db->where('customer_id', $user_id);
$this->db->update('customers',$data);
return $result = array('status'=>'success');
} else {
return false;
}
}
public function profile($request='') {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$query_result = $query->row();
$customer_id = $query_result->cust_id;
$data = "SELECT company.id AS company_id, customers.customer_id, customers.phone AS phone,
CONCAT(customers.first_name,' ',customers.last_name) AS name,
company.company_name AS company_name, customers.profile_image
FROM customers INNER JOIN cust_company_list ON customers.customer_id = cust_company_list.user_id
INNER JOIN company ON cust_company_list.company_id = company.id
WHERE customers.customer_id = '$customer_id' ";
//print_r($data);exit();
$result = $this->db->query($data);
$rs = $result->row();
return $result = array('id'=>$rs->customer_id,'phone'=>$rs->phone,
'name'=>$rs->name,'company_name'=>$rs->company_name,
'profile_photo'=>$rs->profile_image,'company_id'=>$rs->company_id);
} else {
return false;
}
}
public function update_user_location($request='') {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$id = $rs->cust_id;
$data = array('user_latitude'=>$request['latitude'],'user_longitude'=>$request['longitude']);
$result = $this->db->where('customer_id', $id)->update('customers', $data);
if($result){
return $result;
}else{
return false;
}
} else {
return false;
}
}
public function update_profile_photo($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$data = array('profile_image'=>$request['profile_photo']);
$this->db->where('customer_id', $rs->cust_id)->update('customers', $data);
return true;
} else {
return false;
}
}
public function call_ambulance($request='') {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$cusrimer_id = $rs->cust_id;
$customerDetails = $data = "SELECT CONCAT(c.first_name,' ',c.last_name) AS patient_name,
cust_company_list.company_id AS company_id, c.phone FROM customers AS c
LEFT JOIN cust_company_list ON cust_company_list.user_id = c.customer_id
WHERE c.customer_id = '$cusrimer_id'";
$result = $this->db->query($customerDetails)->row();
$getDistance = $this->GetDrivingDistance($request['source_latitude'], $request['destination_latitude'], $request['source_longitude'], $request['destination_longitude']);
$distanceValue = $getDistance['distanceValue'] * 0.001;
$timeValue = $getDistance['timeValue'] * 0.0166667;
if($result){
$data = array('total_time'=>$timeValue,
'trip_distance'=>$distanceValue,
'company_id'=>$result->company_id,
'customer_id'=>$cusrimer_id,
'patient_name'=>$result->patient_name,
'phone'=>$result->phone,
'pickup_location'=>$request['source_name'],
'pickup_lat'=>$request['source_latitude'],
'pickup_lng'=>$request['source_longitude'],
'drop_location'=>$request['destination_name'],
'drop_lat'=>$request['destination_latitude'],
'drop_lng'=>$request['destination_longitude'],
'request_type'=>$request['trip_type'],
'driver_assign_status'=>2,
'payment_mode'=>0,
'status'=>'3');
$this->db->insert('transport_details', $data);
$last_id = $this->db->insert_id();
}else{
return false;
}
return $result = array('request_id'=>$last_id);
} else {
return false;
}
}
public function nearest_ambulance($request='') {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$cust_id = $rs->cust_id;
$data1 = "SELECT * FROM setting WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
$radius = $rs->radius;
$customerDetails = $this->db->query("SELECT customers.user_latitude,
customers.user_longitude FROM `customers` WHERE customers.customer_id =".$cust_id)->row();
$data = $this->db->query("SELECT d.book_status, d.driver_id, d.status, d.is_online, d.online_start_time, d.online_end_time, (((acos(sin((".$customerDetails->user_latitude."*pi()/180)) * sin((lat_driver*pi()/180)) + cos((".$customerDetails->user_latitude."*pi()/180)) * cos((lat_driver*pi()/180)) * cos(((".$customerDetails->user_longitude." - lng_driver)*pi()/180))))*180/pi())*60*1.1515) as distance FROM drivers AS d WHERE d.status = '1' AND d.is_online = '1' AND d.book_status = '0' AND d.online_start_time < DATE_FORMAT(now(),'%H:%i') AND d.online_end_time > DATE_FORMAT(now(),'%H:%i') HAVING distance < ".$radius."")->result_array();
$nonScheduledDriver = $this->db->query("SELECT driver_id FROM `transport_details` WHERE is_scheduled = 1")->result_array();
if (EMPTY($nonScheduledDriver)){
$nonScheduledDriver[] = array('driver_id'=>'0' );;
}
foreach($data as $row){
$driverList[] = $row['driver_id'];
foreach ($nonScheduledDriver as $row1) {
$nonScheduledDriver1[] = $row1['driver_id'];
}
}
$nonScheduledDriverList = array_diff($driverList,$nonScheduledDriver1);
if($nonScheduledDriverList){
return $result = array('ambulace_count'=>COUNT($nonScheduledDriverList),'distance'=>$radius.'Km');
}else{
return $result = array('ambulace_count'=>'0','distance'=>'0'.'Km');
}
} else {
return false;
}
}
public function trip_completion_details($request='') {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$cust_id = $rs->cust_id;
$id = $request['trip_id'];
$data = "SELECT CONCAT(transport_details.trip_distance,' ','km') AS distance, transport_details.total_time AS time, transport_details.trip_cost AS total_amount, drivers.profile_image AS driver_photo, CONCAT(drivers.first_name,' ',drivers.last_name) AS driver_name FROM transport_details LEFT JOIN drivers ON transport_details.driver_id = drivers.driver_id WHERE transport_details.transport_id = '$id' AND transport_details.status = '6' AND transport_details.customer_id = '$cust_id' ";
$query = $this->db->query($data);
$result = $query->row();
return $result;
} else {
return false;
}
}
public function cancel_request($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
$queryResult = $this->db->where('transport_id', $request['request_id'])->get('transport_details');
if ($query->num_rows() > 0 && $queryResult->num_rows()) {
$rs = $query->row();
$user_id = $rs->cust_id;
$id = $request["request_id"];
$result = $this->db->where('transport_id', $id)->where('customer_id', $user_id)->update('transport_details', array('status'=>'9'));
if($result){
return $result;
}else{
return false;
}
} else {
return false;
}
}
public function trip_cancel($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
$rs = $query->row();
$cust_id = $rs->cust_id;
if ($query->num_rows() > 0) {
$id = $request["trip_id"];
$result = $this->db->where('transport_id', $id)->update('transport_details', array('status'=>'2'));
$data2 = "SELECT * FROM transport_details WHERE customer_id = '$cust_id' AND transport_id = '$id' ORDER BY transport_id DESC";
$query = $this->db->query($data2);
$rs2 = $query->row();
$driv_id = $rs2->driver_id;
$this->db->where('driver_id', $driv_id)->update('drivers', array('book_status'=>0));
$data3 = "SELECT * FROM drivers WHERE driver_id = '$driv_id'";
$query = $this->db->query($data3);
$rs3 = $query->row();
$fcm = $rs3->fcm_token;
$fcm_data = array('id'=>$id,'title'=>'NEMT','message'=>'Request Cancelled');
$this->push_sent_cancel($fcm, $fcm_data);
return $result;
} else {
return false;
}
}
public function push_sent_cancel($fcm_token, $fcm_data) {
$data1 = "SELECT * FROM setting WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
$key = $rs->google_api_key;
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"ringtone_driver\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"trip_id\" : \"".$fcm_data['id']."\", \"trip_status\" : 0}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json','Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$out = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
public function trip_history($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$cust_id = $rs->cust_id;
$data1 = "SELECT * FROM setting WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
$currency = $rs->currency;
$data = "SELECT transport_details.total_time AS time,
vehicles.vehicle_reg_no AS ambulance_number,
CONCAT(transport_details.trip_cost,'.$currency.') AS total_amount,
CONCAT(drivers.first_name,' ',drivers.last_name) AS driver_name,
transport_details.trip_distance AS total_distance,
transport_details.pickup_location AS source_name,
transport_details.drop_location AS destination_name,
drivers.profile_image AS driver_photo
FROM `transport_details` LEFT JOIN drivers
ON transport_details.driver_id = drivers.driver_id LEFT JOIN
vehicles ON drivers.vehicle = vehicles.vehicle_id
WHERE transport_details.customer_id = '$cust_id'
ORDER BY transport_details.transport_id DESC ";
$query1 = $this->db->query($data)->result();
return $query1;
} else {
return false;
}
}
public function req_status($request='') {
$query = $this->db->where('transport_id', $request['request_id'])->get('transport_details');
if ($query->num_rows() > 0) {
$query = $this->db->select("transport_details.status AS request_status, transport_details.transport_id AS trip_id,
CONCAT(transport_details.total_time,' ','min') AS time, CONCAT(transport_details.trip_distance,' ','km') AS distance, CONCAT(drivers.first_name,' ',drivers.last_name) AS driver_name, vehicles.vehicle_reg_no AS car_number, drivers.profile_image AS driver_photo, drivers.phone AS driver_phone_number, transport_details.pickup_lat AS source_latitude, transport_details.pickup_lng AS source_longitude, transport_details.drop_lat AS destination_latitude, transport_details.drop_lng AS destination_longitude")->from('transport_details')->join('drivers','transport_details.driver_id = drivers.driver_id','left')->join('vehicles','drivers.vehicle = vehicles.vehicle_id','left')->where('transport_details.transport_id', $request['request_id'])->get();
if ($query->num_rows() > 0) {
$result = $query->row();
return $result;
}
} else {
return false;
}
}
function statusof_app($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$cust_id = $rs->cust_id;
$res = "SELECT * FROM transport_details WHERE customer_id = '$cust_id' ORDER BY transport_id DESC LIMIT 0,1";
$query = $this->db->query($res);
$rs = $query->row();
$booking_status = $rs->status;
$driver_id = $rs->driver_id;
$book_id = $rs->transport_id;
if ($booking_status == 4 || $booking_status == 5) {
$query1 = $this->db->select('CONCAT(transport_details.total_time," ","min") AS time,transport_details.transport_id AS trip_id,vehicles.vehicle_reg_no AS car_number, CONCAT(transport_details.trip_distance," ","km") AS distance, drivers.profile_image AS driver_photo, drivers.phone AS driver_phone_number, transport_details.status AS request_status, transport_details.pickup_lat AS source_latitude, transport_details.pickup_lng AS source_longitude, transport_details.drop_lat AS destination_latitude, transport_details.drop_lng AS destination_longitude, CONCAT(drivers.first_name," ",drivers.last_name) AS driver_name')->from('transport_details')->join('drivers','transport_details.driver_id = drivers.driver_id','left')->join('vehicles','drivers.vehicle = vehicles.vehicle_id','left')->where('transport_details.transport_id',
$book_id)->get();
$result = $query1->row();
return $result;
} else {
return $result;
}
} else {
print json_encode(array('status'=>'error','code'=>'209','message'=>'Something Went wrong'));die();
}
}
function status_driver($id) {
$data = $this->db->query("SELECT * FROM `transport_details` WHERE transport_id = '$id'")->row();
if ($data->status == 6 && $data->cash_collection == 1) {
$driver_status = 4;
return $driver_status;
}
elseif($data->status == 6 && $data->cash_collection == 0) {
$driver_status = 3;
return $driver_status;
}
elseif($data->status == 5) {
$driver_status = 2;
return $driver_status;
}
elseif($data->car_arrival == 1 OR $data->car_arrival == 2) {
$driver_status = 1;
return $driver_status;
}
else {
$driver_status = 0;
return $driver_status;
}
}
public function GetDrivingDistance($lat1, $lat2, $long1, $long2) {
$data1 = "SELECT * FROM setting WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
$key = $rs->google_api_key;
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=".$lat1.",".$long1."&destinations=".$lat2.",".$long2."&mode=driving&language=pl-PL"."&key=".$key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response, true);
$dist = $response_a['rows'][0]['elements'][0]['distance']['text'];
$distValue = $response_a['rows'][0]['elements'][0]['distance']['value'];
$time = $response_a['rows'][0]['elements'][0]['duration']['text'];
$timeValue = $response_a['rows'][0]['elements'][0]['duration']['value'];
return array('distance'=>$dist,'distanceValue'=>$distValue,'time'=>$time,'timeValue'=>$timeValue);
}
public function phone_number_availability($data = array()){
if(empty($data) || !isset($data['phone']) || empty($data['phone'])){
return 0;
}
$sql = "SELECT * FROM customers WHERE phone LIKE '%".$data['phone']."' AND status IN (0,1)";
$isAvailable = $this->db->query($sql);
$isAvailable = $isAvailable->num_rows();
return $isAvailable;
}
}
?>
\ No newline at end of file
<?php
class Webservices_driver_model extends CI_Model {
function __construct() {
parent::__construct();
}
// *********************** NEMT DRIVER DOCUMENTATION ********************
public function login($request) {
$this->db->where("phone", $request['phone_number']);
$this->db->where('password', md5($request['password']));
$this->db->where('status !=', 0);
$query = $this->db->get('drivers');
if ($query->num_rows() > 0) {
$unique_id = $this->generate_unique();
$rs = $query->row();
$this->EncryptedPatientKey($unique_id, $rs->driver_id);
$data = array('first_time_login' => 'false');
$first_time_login = ($rs->first_time_login == 'true' ? filter_var(true, FILTER_VALIDATE_BOOLEAN) : filter_var(false, FILTER_VALIDATE_BOOLEAN));
if($first_time_login == true){
$this->db->update('drivers', array('first_time_login' => 'false'));
}
return $result = array('status' => 'success', 'user_id' => $rs->driver_id, 'auth_token' => $unique_id, 'phone' => $rs->phone, 'name' => $rs->first_name." ".$rs->last_name, 'first_time_user' => $first_time_login);
} else {
return false;
}
}
public function generate_unique() {
$unqe = md5(uniqid(time().mt_rand(), true));
return $unqe;
}
public function EncryptedPatientKey($unique_id, $user_id) {
$this->db->insert('driver_auth_table', array('driver_id' => $user_id, 'unique_id' => $unique_id));
}
// *********************** DOCUMENT UPLOAD ********************
function doc_upload($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
if($request['type'] == 1){
$data = array('licence' => $request['image']);
$where = array('driver_id' => $driv_id);
$this->db->where($where)->update('drivers', $data);
}
elseif($request['type'] == 2){
$result = $this->db->query("SELECT vehicle FROM drivers WHERE driver_id=$driv_id")->row();
$data = array('vehicle_reg_image' => $request['image']);
$where = array('vehicle_id' => $result->vehicle);
$this->db->where($where)->update('vehicles', $data);
}
elseif($request['type'] == 3){
$data = array('profile_image' => $request['image']);
$where = array('driver_id' => $driv_id);
$this->db->where($where)->update('drivers', $data);
}
return true;
} else {
return false;
}
}
// *********************** GET DRIVER PROFILE ********************
public function profile($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$query_result = $query->row();
$driv_id = $query_result->driver_id;
$data = "SELECT drivers.driver_id, drivers.first_name,
drivers.last_name, drivers.profile_image, vehicles.vehicle_reg_no FROM drivers
INNER JOIN vehicles ON drivers.vehicle = vehicles.vehicle_id WHERE driver_id = '$driv_id' ";
$result = $this->db->query($data);
$rs = $result->row();
return $result = array('id' => $rs->driver_id,
'name' => $rs->first_name." ".$rs->last_name,
'car_number' => $rs->vehicle_reg_no,
'profile_photo' => $rs->profile_image);
} else {
return false;
}
}
// *********************** GET DRIVER STATUS ********************
public function driver_status($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$query = $this->db->where('driver_id', $rs->driver_id)->get('drivers')->row();
$res = $query->is_online;
$new_array = array('driver_status' => filter_var($res, FILTER_VALIDATE_BOOLEAN));
return $new_array;
} else {
return false;
}
}
// *********************** UPDATE DRIVER STATUS ********************
public function status($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$data = array('is_online' => filter_var($request['driver_status'], FILTER_VALIDATE_BOOLEAN));
$this->db->where('driver_id', $rs->driver_id)->update('drivers', $data);
return true;
} else {
return false;
}
}
// *********************** UPDATE DRIVER STATUS ********************
public function arrived_at_customer($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$this->db->where('transport_id', $request['trip_id'])->update('transport_details', array('car_arrival' => 1));
return true;
} else {
return false;
}
}
// *********************** UPDATE DRIVER STATUS ********************
public function driver_onstatus($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
if ($request['driver_status'] == 'true') {
$array = array('driver_id' => $driv_id, 'cur_date' => date('Y-m-d'), 'sign_in' => time());
$this->db->insert('driver_online', $array);
return true;
} else {
$cur_date = date('Y-m-d');
$rs = $this->db->query("SELECT * FROM driver_online WHERE driver_id='$driv_id' AND cur_date='$cur_date' ORDER BY id DESC LIMIT 0,1")->row();
if (count($rs) > 0) {
if ($rs->sign_out == '') {
$array = array('sign_out' => time());
$this->db->where('id', $rs->id)->update('driver_online', $array);
return true;
} else {
return false;
}
} else {
return false;
}
}
} else {
return false;
}
print json_encode($result);
}
// *********************** UPDATE DRIVER PASSWORD ********************
public function update_password($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$user_id = $rs->driver_id;
$data = array('password' => md5($request['new_password']));
$this->db->where('driver_id', $user_id);
$this->db->update('drivers',$data);
return $result = array('status' => 'success');
} else {
return false;
}
}
// *********************** UPDATE DRIVER USER NAME ********************
public function update_user_name($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$this->db->where('driver_id', $rs->driver_id)->update('drivers', array('first_name' => $request['first_name'],'last_name' => $request['last_name']));
return true;
} else {
return false;
}
}
// *********************** UPDATE VEHICLE NUMBER ********************
public function update_vehicle_number($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$data = $this->db->query("SELECT drivers.vehicle FROM drivers WHERE driver_id=$rs->driver_id")->row();
$this->db->where('vehicle_id', $data->vehicle)->update('vehicles', array('vehicle_reg_no' => $request['vehicle_number']));
return true;
} else {
return false;
}
}
// *********************** UPDATE DRIVER LOCATION ********************
public function driver_location($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
if (!empty($request["latitude"] && $request['longitude'])) {
$data = array('lat_driver' => $request['latitude'], 'lng_driver' => $request['longitude']);
$this->db->where('driver_id', $rs->driver_id)->update('drivers', $data);
return $result = array('status' => 'success');
} else {
return false;
}
} else {
return false;
}
}
// *********************** PAYMENT STATUS ********************
public function payment_status($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$trip_id = $request['trip_id'];
$data = "SELECT payment_status FROM transport_details WHERE transport_id = '$trip_id' ";
$query1 = $this->db->query($data)->row();
return $query1;
} else {
return false;
}
}
// *********************** TRIP ACCEPT ********************
public function accept($request) {
$id = $request['request_id'];
$requestDetails = "SELECT * FROM transport_details WHERE transport_id = '$id' ";
$rquDetails = $this->db->query($requestDetails)->row();
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$data = array('driver_id' => $rs->driver_id);
$this->db->where('transport_id', $id)->update('transport_details', $data);
$data = $this->db->where('transport_id', $id)->get('transport_details')->row_array();
$res = $this->db->select('booking_code')->get('setting')->row();
$code = $res->booking_code;
$rand = rand(1111, 99999);
$book_id = "$code"."$rand";
$driverDetails = $this->db->query("SELECT vehicle_id FROM `drivers` WHERE driver_id = '$rs->driver_id'")->row();
$data2 = array('vehicle_type' => $driverDetails->vehicle_id, 'driver_id' => $data['driver_id'], 'trip_no' => $book_id, 'book_date' => time(), 'start_time' => time(), 'status' => '4');
$this->db->where('transport_id', $request['request_id'])->update('transport_details', $data2);
$this->db->where('driver_id', $rs->driver_id);
$this->db->update('drivers', array('book_status' => 1));
$data4 = array('trip_id' => $rquDetails->transport_id, 'cust_id' => $rquDetails->customer_id, 'driver_id' => $rs->driver_id);
$this->db->insert('feedback', $data4);
$data5 = "SELECT t.transport_id AS trip_id, t.status AS trip_status, t.request_type AS trip_type, c.customer_id AS customer_id, CONCAT(c.first_name,' ',c.last_name) AS customer_name, c.phone AS customer_phone, c.profile_image AS profile_image, t.pickup_location AS source_location, t.pickup_lat AS source_latitude, t.pickup_lng AS source_longitude, t.drop_location AS destination_location, t.drop_lat AS destination_latitude, t.drop_lng AS destination_longitude FROM transport_details AS t LEFT JOIN customers AS c ON c.customer_id = t.customer_id WHERE t.transport_id ='$id'";
$query = $this->db->query($data5);
$result = $query->row();
return $result;
return true;
} else {
return false;
}
}
// *********************** APP STATUS ********************
function statusof_app($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$data1 = "SELECT * FROM transport_details WHERE driver_id = '$driv_id' ORDER BY transport_id DESC LIMIT 0,1";
$query = $this->db->query($data1);
$res = $query->row();
$driver_status = $res->status;
if ($driver_status == 4 || $driver_status == 5) {
$data = "SELECT transport_details.total_time AS time, transport_details.trip_distance AS distance, drivers.profile_image AS driver_photo, drivers.phone AS driver_phone_number, transport_details.status AS request_status, transport_details.transport_id AS trip_id, transport_details.pickup_lat AS source_latitude, transport_details.pickup_lng AS source_longitude, transport_details.drop_lat AS destination_latitude, transport_details.drop_lng AS destination_longitude FROM transport_details LEFT JOIN drivers ON transport_details.driver_id = drivers.driver_id LEFT JOIN customers ON customers.customer_id = transport_details.customer_id WHERE transport_details.driver_id = '$driv_id' AND transport_details.status IN(4,5) ORDER BY transport_details.transport_id DESC LIMIT 0,1";
$result = $this->db->query($data)->row();
return $result;
} else {
return $result;
}
} else {
print json_encode(array('status' => 'error', 'code' => '209', 'message' => 'Something Went wrong'));
die();
}
}
// *********************** STATUs OF RIVER ********************
public function status_driver($id) {
$data = $this->db->query("SELECT * FROM `transport_details` WHERE transport_id = '$id'")->row();
if ($data->status == 6 && $data->cash_collection == 1) {
$driver_status = 4;
return $driver_status;
}
elseif($data->status == 6 && $data->cash_collection == 0) {
$driver_status = 3;
return $driver_status;
}
elseif($data->status == 5) {
$driver_status = 2;
return $driver_status;
}
elseif($data->car_arrival == 1) {
$driver_status = 1;
return $driver_status;
}
else {
$driver_status = 0;
return $driver_status;
}
}
// *********************** EMERGENCY RIDE HISTORY ********************
public function history_trips_emergency($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$data1 = "SELECT * FROM setting WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
$currency = $rs->currency;
$query = "SELECT t.transport_id AS id,
customers.customer_id AS customer_id,
CONCAT(customers.first_name,' ',customers.last_name) AS customer_name,
customers.profile_image AS customer_photo,
t.pickup_location AS source_location,
t.pickup_lng AS source_longitude,
t.pickup_lat AS source_latitude,
t.drop_location AS destination_location,
t.drop_lat AS destination_latitude,
t.drop_lng AS destination_longitude,
CONCAT(t.trip_cost,'','$currency') AS fare FROM transport_details AS t LEFT JOIN drivers AS d ON d.driver_id = t.driver_id LEFT JOIN customers ON t.customer_id = customers.customer_id WHERE t.driver_id = '$driv_id' AND request_type = 1 ";
return $query;
} else {
return false;
}
}
// *********************** EMERGENCY RIDE HISTORY ********************
public function history_trips_schedule($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$data = "SELECT t.transport_id AS id, customers.customer_id AS customer_id, CONCAT(customers.first_name,
' ',customers.last_name) AS customer_name, customers.profile_image AS customer_photo, t.pickup_location AS source_location, t.pickup_lng AS source_longitude, t.pickup_lat AS source_latitude, t.drop_location AS destination_location, t.drop_lat AS destination_latitude, t.drop_lng AS destination_longitude FROM transport_details AS t LEFT JOIN drivers AS d ON d.driver_id = t.driver_id LEFT JOIN customers ON t.customer_id = customers.customer_id WHERE t.driver_id = '$driv_id' AND request_type = 3 AND t.status = 6";
$result = $this->db->query($data)->result_array();
$result[0]['app_status'] = '1';
$data1 = "SELECT t.transport_id AS id, customers.customer_id AS customer_id, CONCAT(customers.first_name,
' ',customers.last_name) AS customer_name, customers.profile_image AS customer_photo, t.pickup_location AS source_location, t.pickup_lng AS source_longitude, t.pickup_lat AS source_latitude, t.drop_location AS destination_location, t.drop_lat AS destination_latitude, t.drop_lng AS destination_longitude FROM transport_details AS t LEFT JOIN drivers AS d ON d.driver_id = t.driver_id LEFT JOIN customers ON t.customer_id = customers.customer_id WHERE t.driver_id = '$driv_id' AND request_type = 3 AND t.status = 3";
$result1 = $this->db->query($data1)->result_array();
$result1[0]['app_status'] = '2';
$resultArray = array_merge($result, $result1);
return $resultArray;
} else {
return false;
}
}
// *********************** END NEMT DRIVER DOCUMENTATION ********************
function insert_trip_deduction($userId_new,$fare){
$wallet = array(
'paid_amount' => $fare,
'payment_status' => 'success',
'created' => date("d/m/Y"),
'modified' => date("d/m/Y"),
'transaction_date' => time() * 1000,
'transaction_type' => "3",
'amount' => $fare * 0.019,
'user_id' => $userId_new,
'payment_type' => "3"
);
$query = $this->db->insert('wallet_transactions',$wallet);
//print_r($this->db->last_query());exit;
}
function update_user_wallet($userId_new,$fare) {
$this->db->where('id', $userId_new);
$query = $this->db->get('customer');
$res = $query->row();
$cur_wallet = $res->wallet_balance;
$fin_wallet = $cur_wallet - $fare;
$array = array(
'wallet_balance' => $fin_wallet);
$this->db->where('id', $userId_new);
$result = $this->db->update('customer', $array);
//print_r($this->db->last_query());exit;
return $result;
}
function booster_seat($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driver_id= $rs->driver_id;
$data=array('status_booster_seat'=>$request['is_booster_seat']);
$this->db->where('id', $driver_id);
$this->db->update('driver',$data);
return true;
} else {
return false;
}
}
public function driver_reg($data) {
$num = $this->db->where('phone', $data['phone'])->get('driver')->num_rows();
$num1 = $this->db->where('email', $data['email'])->get('driver')->num_rows();
if ($num > 0) {
$result = array('status' => 'error', 'message' => 'Mobile number Already Exists');
}
elseif($num1 > 0) {
$result = array('status' => 'error', 'message' => 'Email Already Exists');
}
else {
$unique_id = $this->generate_unique();
$otp = rand(1111, 9999);
$this->db->insert('driver', array('phone' => $data['phone'], 'email' => $data['email'], 'password' => md5($data['password']),'driver_name' => $data['name'], 'city' => $data['city']));
$user_id = $this->db->insert_id();
$this->db->insert('car', array('driv_id' => $user_id));
for ($i = 1; $i <= 12; $i++) {
$data1 = array('driver_id' => $user_id,
'type' => $i);
$new_result[] = $data1;
}
$this->db->insert_batch('driver_document', $new_result);
$this->db->insert('car', array('driv_id' => $user_id));
// echo $this->db->last_query();die;
$this->EncryptedPatientKey($unique_id, $user_id);
if ($user_id) {
$result = array('status' => 'success', 'user_id' => $user_id, 'auth_token' => $unique_id, 'is_phone_verified' => true, 'name' => $data['name'], 'email' => $data['email'], 'city' => $data['city'], 'phone' => $data['phone']);
} else {
$result = array('status' => 'error');
}
}
return $result;
}
function get_booster_status($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$query = $this->db->where('id', $rs->driver_id)->get('driver')->row();
$res = $query->status_booster_seat;
$new_array = array(
'booster_status' => filter_var($res, FILTER_VALIDATE_BOOLEAN));
return $new_array;
} else {
return false;
}
}
public function update_fcm($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$data = array('fcm_token' => $request['fcm_token']);
$this->db->where('id', $rs->driver_id)->update('driver', $data);
return true;
} else {
return false;
}
}
public function mobile_availability($request) {
$phone = $request['phone'];
$num = $this->db->where('phone', $phone)->get('driver')->num_rows();
if ($num > 0) {
return $result = array('status' => 'success', 'phone' => $phone, 'is_available' => 'false');
} else {
return false;
}
}
// public function prof_update($request){
// $query = $this->db->where('unique_id',$request['auth'])->get('driver_auth_table');
// if($query->num_rows()>0){
// $rs = $query->row();
// print_r($rs->driver_id);
// $data = array('driver_name'=>$request['name'],'email'=>$request['email'],'phone'=>$request['phone'],'address'=>$request['address'],'city'=>$request['city'],'state'=>$request['state'],'post_code'=>$request['postal_code'],'image'=>$request['image']);
// $this->db->where('id',$rs->driver_id)->update('driver',$data);
// //echo $this->db->last_query();
// return $result = array('id'=>$rs->driver_id,'name' => $data['driver_name'],'phone'=>$data['phone'],'email'=>$data['email'],'address'=>$data['address'],'city'=>$data['city'],'state'=>$data['state'],'post_code'=>$data['post_code'],'image'=>$data['image']);
// }else{
// return false;
// }
// }
function prof_update($request) {
// print_r($request);
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$data = array();
if (isset($request['name']) && $request['name'] != '') {
$data['driver_name'] = $request['name'];
}
if (isset($request['email']) && $request['email'] != '') {
$data['email'] = $request['email'];
}
if (isset($request['phone']) && $request['phone'] != '') {
$data['phone'] = $request['phone'];
}
if (isset($request['address']) && $request['address'] != '') {
$data['address'] = $request['address'];
}
if (isset($request['city']) && $request['city'] != '') {
$data['city'] = $request['city'];
}
if (isset($request['state']) && $request['state'] != '') {
$data['state'] = $request['state'];
}
if (isset($request['postal_code']) && $request['postal_code'] != '') {
$data['post_code'] = $request['postal_code'];
}
if (isset($_FILES['profile_photo'])) {
$image = '';
if (is_uploaded_file($_FILES['profile_photo']['tmp_name'])) {
$uploads_dir = './assets/uploads/profile_pic/';
$tmp_name = $_FILES['profile_photo']['tmp_name'];
$pic_name = $_FILES['profile_photo']['name'];
$pic_name = str_replace(' ', '_', mt_rand().$pic_name);
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
$image = $uploads_dir.$pic_name;
}
if ($image != '') {
$data['image'] = $image;
}
}
$rs = $query->row();
$this->db->where('id', $rs->driver_id)->update('driver', $data);
$res = $this->db->query("SELECT * FROM `driver` WHERE id = '$rs->driver_id'")->row();
// print_r($res);
return $res;
//return true;
} else {
return false;
}
}
// public function doc_status($request){
// $query = $this->db->where('unique_id',$request['auth'])->get('driver_auth_table');
// if($query->num_rows()>0){
// $rs = $query->row();
// $id = $rs->driver_id;
// $data = "SELECT * FROM driver_document WHERE driver_id = '$id'";
// $query = $this->db->query($data);
// $result = $query->result_array();
// return $result;
// } else {
// return false;
// }
// }
public function doc_status($request) {
$this->load->helper('general');
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$id = $rs->driver_id;
$data = "SELECT * FROM driver_document WHERE driver_id = '$id'";
$query = $this->db->query($data);
//echo $this->db->last_query();
$result = $query->result_array();
$array_type = array();
foreach($result as $rs) {
$array_type[] = $rs['type'];
}
$dr_doc = array();
for ($i = 1; $i <= 6; $i++) {
if (in_array($i, $array_type)) {
//
} else {
$dr_doc[] = array('driver_id' => $id,
'type' => $i);
}
}
if (!empty($dr_doc)) {
$this->db->insert_batch('driver_document', $dr_doc);
$data = "SELECT * FROM driver_document WHERE driver_id = '$id'";
$query = $this->db->query($data);
//echo $this->db->last_query();
$result = $query->result_array();
//print_r($result);
}
foreach($result as $rs) {
if ($rs['status'] != 0) {
$is_uploaded = 'true';
} else {
$is_uploaded = 'false';
}
// print_r($rs['type']);
$name = get_document_name($rs['type']);
$new_array = array('id' => $rs['id'],
'type' => (int)$rs['type'],
'document_status' => (int)$rs['status'],
'is_uploaded' => filter_var($is_uploaded, FILTER_VALIDATE_BOOLEAN),
'name' => $name,
'document_url' => $rs['image']);
$result_array[] = $new_array;
# code...
}
// echo $this->db->last_query();
// $result[] =
// if ($result['status'] != '0'){
// $is_uploaded = 'false';
// }else{
// $is_uploaded = 'true';
// }
//print_r($result_array);
return $result_array;
} else {
return false;
}
}
function type_driver($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$result = $this->db->where('id', $driv_id)->update('driver', array('driver_type' => $request['driver_type']));
return true;
} else {
return false;
}
}
function photo_upload($request) {
//print_r($request);
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$data = array('image' => $request['image']);
$this->db->where('id', $rs->driver_id)->update('driver', $data);
return true;
} else {
return false;
}
}
public function start_trip($request) {
// print_r($request);
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
// echo $this->db->last_query();
if ($query->num_rows() > 0) {
$id = $request['trip_id'];
$start_time = time();
$trip_start_time = time();
$result = $this->db->where('id', $id)->update('booking', array('status' => '2', 'start_time' => $start_time,'trip_start_time' => $trip_start_time));
// echo $this->db->last_query();
return $result;
} else {
return false;
}
}
public function help_pages($request) {
$id = $request['id'];
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$data = "SELECT * FROM help_table WHERE id ='$id' ";
$query = $this->db->query($data);
$rs = $query->row();
return $result = array('id' => $rs->id, 'title' => $rs->head, 'icon' => $rs->image, 'content' => $rs->content);
} else {
return false;
}
}
function is_help_status($driv_id, $id) {
$data = $this->db->query("SELECT help_status AS is_helpful FROM `help_review` WHERE driver_id = '$driv_id' AND help_id = '$id' ")->row();
//return $data->is_helpful;
return filter_var($data->is_helpful, FILTER_VALIDATE_BOOLEAN);
}
public function help_list($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$data = "SELECT id AS id,head AS title,image AS icon FROM help_table WHERE status = 1 ORDER BY id ASC";
$query = $this->db->query($data);
$result = $query->result_array();
return $result;
} else {
return false;
}
}
function help_review($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$data = array('help_status' => filter_var($request['is_helpful'], FILTER_VALIDATE_BOOLEAN), 'help_id' => $request['id'], 'driver_id' => $driv_id);
$this->db->insert('help_review', $data);
return true;
} else {
return false;
}
}
function update_vehicle($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$data = array('model' => $request['car_model'], 'max_seat' => $request['seats_available'], 'vehicle_reg_num' => $request['vehicle_registration_number'], 'car_owner' => $request['car_owner']);
$this->db->where('driv_id', $rs->driver_id)->update('car', $data);
return true;
} else {
return false;
}
}
function update_settings($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$data = array('is_deaf' => filter_var($request['is_deaf'], FILTER_VALIDATE_BOOLEAN), 'is_flash_required' => filter_var($request['is_flash_required_for_requests'], FILTER_VALIDATE_BOOLEAN));
$this->db->where('id', $rs->driver_id)->update('driver', $data);
return true;
} else {
return false;
}
}
function fetch_settings($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$data1 = "SELECT * FROM driver WHERE id = '$driv_id' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
//print_r($rs->is_flash_required);
//echo $this->db->last_query();
return $result = array('status' => 'success', 'is_deaf' => $rs->is_deaf, 'is_flash_required_for_requests' => $rs->is_flash_required);
} else {
return false;
}
}
function req_details($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$id = $request["request_id"];
$data = "SELECT request.stop_list,request.car_type,request.source AS customer_location,request.source_lat AS customer_latitude,request.source_lng AS customer_longitude,customer.id AS customer_id,
customer.name AS customer_name,customer.image AS customer_photo FROM request LEFT JOIN customer ON customer.id = request.cust_id
WHERE request.id = '$id' ";
$query = $this->db->query($data);
$result = $query->row();
$stopList = json_decode($result->stop_list);
$resultArray = array(
'stop_list'=>$stopList,
'car_type'=>$result->car_type,
'customer_location'=>$result->customer_location,
'customer_latitude'=>$result->customer_latitude,
'customer_longitude'=>$result->customer_longitude,
'customer_id'=>$result->customer_id,
'customer_name'=>$result->customer_name,
'customer_photo'=>$result->customer_photo
);
return $resultArray;
} else {
return false;
}
}
function car_type_image($id) {
$data = $this->db->query("SELECT image AS image FROM `car_type` WHERE id = '$id' ")->row();
// echo $this->db->last_query();
return $data->image;
}
// }
function car_type($id) {
// $data = $this->db->query("SELECT car_type FROM `request` WHERE id = '$id' ")->row();
//$car_type_id = $data->car_type;
$data = $this->db->query("SELECT name FROM `car_type` WHERE id = '$id' ")->row();
//echo $this->db->last_query();
return $data->name;
}
public function summary_trip($request) {
$id = $request['trip_id'];
//$currency = '&#8377';
$data = "SELECT booking.id,booking.status AS trip_status,booking.user_id AS customer_id,CONCAT(pattern.currency,'',booking.fare) AS fare,
CONCAT(pattern.currency,'',booking.tax) AS tax,CONCAT(pattern.currency,'',booking.fee) as fee,CONCAT(pattern.currency,'',booking.discount) AS rider_discount,
CONCAT(pattern.currency,'',booking.payout) AS estimated_payout,CONCAT(pattern.currency,'',booking.base_fare) as base_fare ,booking.time AS duration,booking.payment_mode,
ROUND(booking.distance, 2) AS distance FROM booking LEFT JOIN pattern ON booking.pattern_id = pattern.id WHERE booking.id = '$id' ";
// $query1 =$this->db->query($data)->result();
$query1 = $this->db->query($data)->row();
// echo $this->db->last_query();
// print_r($query1);
return $query1;
}
function confirm_arrival($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$data = array('car_arrival' => '1');
$this->db->where('id', $request['trip_id'])->update('booking', $data);
return true;
} else {
return false;
}
}
function confirm_cash($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$data = array(' cash_collection' => '1','payment_status' =>'1');
// $this->db->where('id', $request['trip_id'] && 'driver_id', $driv_id)->update('booking', $data);
$this->db->where('id', $request['trip_id'] )->update('booking', $data);
return true;
} else {
return false;
}
}
public function ride_feedback($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$data = "SELECT feedback.rating AS rating,feedback.id,feedback.bad_feedback AS issue,feedback.comments AS customer_comment,feedback.cust_id AS customer_id,feedback.trip_id AS trip_id FROM feedback WHERE driver_id = '$driv_id'";
$query1 = $this->db->query($data)->result();
foreach($query1 as $result12)
{
if($result12->rating >=3)
{
$issue = "";
}
else{
$issue = $result12->customer_comment;
}
$result123[] = array(
'id'=>$result12->id,
'issue'=>$issue,
'customer_comment'=>$result12->customer_comment,
'customer_id'=>$result12->customer_id,
'trip_id'=>$result12->trip_id
);
}
return $result123;
} else {
return false;
}
}
public function ride_feedback_old($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
// print_r($driv_id);
//$data = "SELECT feedback.id,feedback.bad_feedback AS issue,feedback.driver_feedback AS customer_comment,feedback.cust_id AS customer_id,feedback.trip_id AS trip_id FROM feedback WHERE driver_id = '$driv_id'";
// $data = "SELECT feedback.id,IF(feedback.trip_report!='', feedback.trip_report, feedback.bad_feedback) AS issue,feedback.driver_feedback AS customer_comment,feedback.cust_id AS customer_id,feedback.trip_id AS trip_id FROM feedback WHERE driver_id = '$driv_id' AND feedback.driver_feedback!='' ORDER BY booking.id DESC ";
$data = "SELECT feedback.id,feedback.bad_feedback AS issue,feedback.driver_feedback AS customer_comment,feedback.cust_id AS customer_id,feedback.trip_id AS trip_id FROM feedback WHERE driver_id = '$driv_id' AND feedback.driver_feedback!=''";
$query1 = $this->db->query($data)->result();
//print_r($this->db->last_query());exit;
$query1 = $this->db->query($data)->result();
return $query1;
} else {
return false;
}
}
// public function feedback_comments($request){
// $query = $this->db->where('unique_id',$request['auth'])->get('driver_auth_table');
// if($query->num_rows()>0){
// $rs = $query->row();
// $driv_id = $rs->driver_id;
// $data = "SELECT feedback.id,feedback.driver_feedback AS customer_comment,feedback.cust_id AS customer_id,feedback.trip_id AS trip_id,feedback.rating AS rating FROM feedback WHERE driver_id = '$driv_id'";
// $query1 =$this->db->query($data)->result();
// return $query1;
// }else{
// return false;
// }
// }
public function feedback_comments($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$data = "SELECT feedback.id,feedback.comments AS customer_comment,
feedback.trip_id,feedback.cust_id AS customer_id,feedback.trip_id AS trip_id,booking.start_time AS time,
feedback.rating AS rating FROM feedback INNER JOIN booking ON feedback.trip_id = booking.id WHERE feedback.driver_id = '$driv_id' AND feedback.rating >=3 ORDER BY booking.id DESC ";
$query1 = $this->db->query($data)->result();
return $query1;
} else {
return false;
}
}
public function feedback_comments_old($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
$data = "SELECT feedback.id,feedback.driver_feedback AS customer_comment,
feedback.trip_id,feedback.cust_id AS customer_id,feedback.trip_id AS trip_id,booking.start_time AS time,
feedback.rating AS rating FROM feedback INNER JOIN booking ON feedback.trip_id = booking.id WHERE feedback.driver_id = '$driv_id' AND feedback.driver_feedback!='' ORDER BY booking.id DESC ";
$query1 = $this->db->query($data)->result();
//echo $this->db->last_query();
return $query1;
} else {
return false;
}
}
public function rating($request) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
// print_r($driv_id);
//$data = "SELECT count(*) AS total_rating,AVG(feedback.rating) AS average_rating FROM feedback WHERE driver_id = '$driv_id'";
$data = "SELECT count(*) AS total_ratings FROM feedback WHERE driver_id = '$driv_id' AND rating > 0";
// COALESCE(sum(balance),0)
$query = $this->db->query($data);
//echo $this->db->last_query();
//echo $this->db->last_query();
$result = $query->row();
//$rolltext = (int)implode( $result->average_rating);
// print_r($rolltext);
//var_dump($myVar)
return $result;
} else {
return false;
}
}
function avg_rating($driv_id) {
//$data = $this->db->query("SELECT COALESCE(AVG(feedback.rating),0) AS average_rating FROM `feedback` WHERE driver_id = '94' ")->row();
$data = $this->db->query("SELECT AVG(feedback.rating) AS average_rating FROM `feedback` WHERE driver_id = '$driv_id' AND rating > 0")->row();
//echo $this->db->last_query();
return $data->average_rating;
}
function num_rides($driv_id) {
$data = $this->db->query("SELECT count(id) AS total_requests FROM `driver_request` WHERE driver_id = '$driv_id'")->row();
return $data->total_requests;
}
function num_requests($driv_id) {
$data = $this->db->query("SELECT count(id) AS requests_accepted FROM `request` WHERE driver_id = '$driv_id' AND status = 1")->row();
return $data->requests_accepted;
}
function num_trips($driv_id) {
$data = $this->db->query("SELECT count(id) AS total_trips FROM `booking` WHERE driver_id = '$driv_id'")->row();
return $data->total_trips;
}
function num_cancelled($driv_id) {
$data = $this->db->query("SELECT count(id) AS trips_cancelled FROM `booking` WHERE driver_id = '$driv_id' AND status = 0")->row();
return $data->trips_cancelled;
}
function tripdetails($request) {
$id = $request["trip_id"];
//print_r($id);
// $data = "SELECT driver.id,driver.driver_name AS driver_name,driver.image AS driver_photo,booking.id,
// booking.status AS trip_status,booking.driver_id,booking.source AS source_location,booking.source_lat AS source_latitude,
// booking.source_lng AS source_longitude,booking.destination AS destination_location,
// booking.destination_lat AS destination_latitude,
// booking.destination_lng AS destination_longitude, IF(booking.start_time='',booking.book_date,booking.start_time) AS start_time,booking.end_time AS end_time,
// CONCAT(pattern.currency,'',booking.fare) AS fare,CONCAT(ROUND(booking.time,2),' ','hrs') AS duration,CONCAT(ROUND(booking.distance,3),' ','KM') AS distance,booking.status AS trip_status,
// CONCAT(pattern.currency,'',booking.fee) AS fee,CONCAT(pattern.currency,'',booking.tax) AS tax,
// CONCAT(pattern.currency,'',booking.payout) AS estimated_payout,customer.id AS customer_id,
// customer.name AS customer_name,customer.image AS customer_photo FROM
// booking LEFT JOIN driver ON driver.id = booking.driver_id LEFT JOIN customer ON booking.user_id = customer.id
// LEFT JOIN pattern ON booking.pattern_id = pattern.id WHERE booking.id = '$id'";
$data = "SELECT driver.id,driver.driver_name AS driver_name,driver.image AS driver_photo,booking.id,
booking.status AS trip_status,booking.driver_id,booking.source AS source_location,booking.source_lat AS source_latitude,
booking.source_lng AS source_longitude,booking.destination AS destination_location,
booking.destination_lat AS destination_latitude,
booking.destination_lng AS destination_longitude, IF(booking.start_time='',booking.book_date,booking.start_time) AS start_time,booking.end_time AS end_time,
CONCAT(pattern.currency,'',ROUND(booking.fare,2)) AS fare,CONCAT(ROUND(booking.time,2),' ','hrs') AS duration,CONCAT(ROUND(booking.distance,3),' ','KM') AS distance,booking.status AS trip_status,
CONCAT(pattern.currency,'',ROUND(booking.fee,2)) AS fee,CONCAT(pattern.currency,'',ROUND(booking.tax,2)) AS tax,
CONCAT(pattern.currency,'',ROUND(booking.payout,2)) AS estimated_payout,customer.id AS customer_id,
customer.name AS customer_name,customer.image AS customer_photo FROM
booking LEFT JOIN driver ON driver.id = booking.driver_id LEFT JOIN customer ON booking.user_id = customer.id
LEFT JOIN pattern ON booking.pattern_id = pattern.id WHERE booking.id = '$id'";
$query = $this->db->query($data);
$result = $query->row();
//print_r($result);exit;
return $result;
}
function driver_rate($trip_id) {
$query = $this->db->query("SELECT feedback.rating AS rate FROM `feedback` WHERE trip_id = $trip_id")->row();
return $query->rate;
}
// function history_trips($request){
// //echo "string";
// $query = $this->db->where('unique_id',$request['auth'])->get('driver_auth_table');
// if($query->num_rows()>0){
// $rs = $query->row();
// $driv_id = $rs->driver_id;
// //print_r($driv_id);
// // $data = "SELECT driver.id,driver.driver_name AS driver_name,driver.image AS driver_photo,
// // booking.id,booking.status AS trip_status,booking.driver_id,booking.source AS source_location,
// // booking.source_lat AS source_latitude,booking.source_lng AS source_longitude,
// // booking.destination AS destination_location,booking.destination_lat AS destination_latitude,
// // booking.destination_lng AS destination_longitude,booking.start_time AS start_time,
// // booking.end_time AS end_time,booking.fare AS fare,booking.time AS duration,booking.distance AS distance,
// // booking.status AS trip_status ,booking.fee AS fee,booking.tax AS tax,booking.payout AS estimated_payout,
// // customer.id AS customer_id,customer.name AS customer_name,
// // customer.image AS customer_photo FROM booking
// // LEFT JOIN driver ON driver.id = booking.driver_id LEFT JOIN customer ON booking.user_id = customer.id
// // WHERE booking.driver_id = '$driv_id'";
// $query = "SELECT driver.id,driver.driver_name AS driver_name,driver.image AS driver_photo,
// booking.id,booking.status AS trip_status,booking.driver_id,booking.source AS source_location,
// booking.source_lat AS source_latitude,booking.source_lng AS source_longitude,
// booking.destination AS destination_location,booking.destination_lat AS destination_latitude,
// booking.destination_lng AS destination_longitude,booking.start_time AS start_time,
// booking.end_time AS end_time,booking.fare AS fare,booking.time AS duration,booking.distance AS distance,
// booking.status AS trip_status ,booking.fee AS fee,booking.tax AS tax,booking.payout AS estimated_payout,
// customer.id AS customer_id,customer.name AS customer_name,
// customer.image AS customer_photo FROM booking
// LEFT JOIN driver ON driver.id = booking.driver_id LEFT JOIN customer ON booking.user_id = customer.id
// WHERE booking.driver_id = '$driv_id'";
// //echo $this->db->last_query();
// // $total = $this->db->query->num_rows();
// return $query;
// //return $data;
// }else{
// return false;
// }
// }
function trip_rate($id) {
$query = $this->db->query("SELECT feedback.rating AS rate FROM `feedback` WHERE id = '$id'")->row();
return $query->rate;
}
function total_rides_history($driv_id) {
$query = $this->db->query("SELECT count(id) AS rides FROM booking WHERE driver_id = '$driv_id'")->row();
return $query->rides;
}
function total_online_time($driv_id) {
$query = $this->db->query("SELECT * FROM driver_online WHERE driver_id = '$driv_id'")->result();
//echo $this->db->last_query();
$total_time = 0;
foreach($query as $rs) {
$start_time = $rs->sign_in;
if ($rs->sign_out != '') {
$end_time = $rs->sign_out;
} else {
if ($rs->cur_date == date('Y-m-d')) {
$end_time = time();
} else {
$end_time = strtotime($rs->cur_date.' 23:59:59');
}
}
$end_time = $rs->sign_out != '' ? $rs->sign_out : time();
$total_time += $end_time - $start_time;
}
$dateDiff = intval(($total_time) / 60);
$hours = intval($dateDiff / 60);
$minutes = $dateDiff % 60;
// $start = date('m/d/Y H:i:s', $start_time);
// $end = date('m/d/Y H:i:s', $end_time);
/*$interval = abs($end_time - $start_time)/1000;
$minutes = round($interval / 60);
$min = $minutes;*/
//$hours = floor($min / 60).':'.($min - floor($min / 60) * 60);
return $hours.":".$minutes;
}
// function total_fare($driv_id){
// $query = $this->db->query("SELECT SUM(fare) AS fare FROM booking WHERE driver_id = '$driv_id'")->row();
// return $query->fare;
// echo $this->db->last_query();
// }
function total_fare($driv_id) {
$data1 = $this->db->query("SELECT pattern_id FROM booking WHERE driver_id = $driv_id ")->row();
$pattern = $data1->pattern_id;
// $query = $this->db->query("SELECT CONCAT(patternSUM(fare) AS fare FROM booking WHERE driver_id = '$driv_id'")->row();
$query = $this->db->query("SELECT CONCAT(pattern.currency,'',SUM(fare)) AS fare,pattern_id FROM booking LEFT JOIN pattern ON booking.pattern_id = pattern.id WHERE driver_id = '$driv_id' ")->row();
//echo $this->db->last_query();
if (count($query) > 0) {
return $query->fare;
} else {
return 0;
}
//echo $this->db->last_query();
}
function today_trips($request, $start_time, $end_time) {
$query = $this->db->where('unique_id', $request['auth'])->get('driver_auth_table');
if ($query->num_rows() > 0) {
$rs = $query->row();
$driv_id = $rs->driver_id;
// $data = "SELECT driver.id,driver.driver_name AS driver_name,driver.image AS driver_photo,
// booking.id,booking.status AS trip_status,booking.driver_id,booking.source AS source_location,
// booking.source_lat AS source_latitude,booking.source_lng AS source_longitude,
// booking.destination AS destination_location,booking.destination_lat AS destination_latitude,
// booking.destination_lng AS destination_longitude,booking.start_time AS start_time,
// booking.end_time AS end_time,booking.fare AS fare,booking.time AS duration,booking.distance AS distance,
// booking.status AS trip_status ,booking.fee AS fee,booking.tax AS tax,booking.payout AS estimated_payout,customer.id AS customer_id,customer.name AS customer_name,
// customer.image AS customer_photo FROM booking
// LEFT JOIN driver ON driver.id = booking.driver_id LEFT JOIN customer ON booking.user_id = customer.id
// WHERE booking.driver_id = '$driv_id' AND booking.book_date BETWEEN $start_time AND $end_time";
// $query = "SELECT driver.id,driver.driver_name AS driver_name,driver.image AS driver_photo,
// booking.id,booking.status AS trip_status,booking.driver_id,booking.source AS source_location,
// booking.source_lat AS source_latitude,booking.source_lng AS source_longitude,
// booking.destination AS destination_location,booking.destination_lat AS destination_latitude,
// booking.destination_lng AS destination_longitude,booking.start_time AS start_time,
// booking.end_time AS end_time,booking.fare AS fare,booking.time AS duration,booking.distance AS distance,
// booking.status AS trip_status ,booking.fee AS fee,booking.tax AS tax,booking.payout AS estimated_payout,customer.id AS customer_id,customer.name AS customer_name,
// customer.image AS customer_photo FROM booking
// LEFT JOIN driver ON driver.id = booking.driver_id LEFT JOIN customer ON booking.user_id = customer.id
// LEFT JOIN pattern ON booking.pattern_id = pattern.id WHERE booking.driver_id = '$driv_id' AND booking.book_date BETWEEN $start_time AND $end_time";
// // echo $this->db->last_query();
$query = "SELECT driver.id,driver.driver_name AS driver_name,driver.image AS driver_photo,
booking.id,booking.status AS trip_status,booking.driver_id,booking.source AS source_location,
booking.source_lat AS source_latitude,booking.source_lng AS source_longitude,
booking.destination AS destination_location,booking.destination_lat AS destination_latitude,
booking.destination_lng AS destination_longitude,booking.start_time AS start_time,
booking.end_time AS end_time,CONCAT(pattern.currency,'',booking.fare) AS fare,
booking.time AS duration,booking.distance AS distance,
booking.status AS trip_status ,CONCAT(pattern.currency,'',booking.fee) AS fee,CONCAT(pattern.currency,'',booking.tax) AS tax,
CONCAT(pattern.currency,'',booking.payout) AS estimated_payout,customer.id AS customer_id,customer.name AS customer_name,
customer.image AS customer_photo FROM booking
LEFT JOIN driver ON driver.id = booking.driver_id LEFT JOIN customer ON booking.user_id = customer.id
LEFT JOIN pattern ON booking.pattern_id = pattern.id WHERE booking.driver_id = '$driv_id' AND booking.book_date BETWEEN $start_time AND $end_time AND booking.status != 0";
return $query;
} else {
return false;
}
}
function totalfare_today($start_time, $end_time, $driv_id) {
$data1 = $this->db->query("SELECT pattern_id FROM booking WHERE driver_id = $driv_id ")->row();
$pattern = $data1->pattern_id;
// $data2 = $this->db->query("SELECT currency FROM pattern WHERE id = $pattern ")->row();
// $currency = $data2->currency;
// print_r($currency);
// $query = $this->db->query("SELECT SUM(fare) AS fare FROM booking WHERE driver_id = '$driv_id' AND book_date BETWEEN $start_time AND $end_time")->row();
$query = $this->db->query("SELECT CONCAT(pattern.currency,'',SUM(fare)) AS fare,pattern_id FROM booking LEFT JOIN pattern ON booking.pattern_id = pattern.id WHERE driver_id = '$driv_id' AND book_date BETWEEN $start_time AND $end_time")->row();
return $query->fare;
}
// function total_rides($driv_id){
// $date = strtotime(date('y-m-d'));
// $query = $this->db->query("SELECT (count(id) AS rides FROM booking WHERE driver_id = '$driv_id' AND book_date = '$date' ")->row();
// return $query->rides;
// }
function total_rides($start_time, $end_time, $driv_id) {
//print_r($end_time);
//print_r($end_time);
$query = $this->db->query("SELECT (count(id)) AS rides FROM booking WHERE driver_id = '$driv_id' AND book_date BETWEEN $start_time AND $end_time")->row();
//echo $this->db->last_query();
return $query->rides;
//$query = $this->db->query("SELECT SUM(fare) AS fare FROM booking WHERE driver_id = '$driv_id' AND book_date BETWEEN $start_time AND $end_time")->row();
// return $query->fare;
}
// function total_online_time($driv_id){
// $query = $this->db->query("SELECT * FROM driver_online WHERE driver_id = '$driv_id'")->row();
// //echo $this->db->last_query();
// $start_time = $query->sign_in;
// $end_time = $query->sign_out;
// // $start = date('m/d/Y H:i:s', $start_time);
// // $end = date('m/d/Y H:i:s', $end_time);
// $interval = abs($end_time - $start_time);
// $minutes = round($interval / 60);
// $min = $minutes;
// $hours = floor($min / 60).':'.($min - floor($min / 60) * 60);
// return $hours;
// }
function message($request) {
$id = $request;
$fcm_data = array('id' => $id, 'title' => 'NEMT', 'message' => 'Trip Completed');
$data = array('status ' => '6');
$this->db->where('transport_id', $id)->update('transport_details', $data);
$data = "SELECT * FROM transport_details WHERE transport_id = '$id' ";
$query = $this->db->query($data);
$rs = $query->row();
$cust_id = $rs->customer_id;
$data2 = "SELECT * FROM customers WHERE customer_id = '$cust_id' ";
$query = $this->db->query($data2);
$rs2 = $query->row();
$fcm = $rs2->fcm_token;
$this->push_sent($fcm, $fcm_data);
}
function push_sent($fcm_token, $fcm_data) {
$data1 = "SELECT * FROM setting WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
$key = $rs->google_api_key;
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\" , \"sound\": \"ringtone_user\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"id\" : \"".$fcm_data['id']."\"}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json', 'Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$out = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
public function fare_calculate($request, $trip_id) {
if (!empty($trip_id)) {
if ($trip_id != 0) {
$distance = $request['trip_distance'];
$time = $request['total_time'];
$rs = $this->cal_baseRate();
if ($rs) {
$fare_cal = $rs->base_price + ($rs->km_rate * $distance);
$least_min = $time * $rs->min_rate; //total minute rate
$min_fare = $fare_cal + $least_min; // total fare calculated
$extra_cost = 0;
$min_fare = floor($min_fare + $extra_cost);
$fare = $min_fare;
$sub_total = $fare;
//echo json_encode($sub_total);exit();
$setting = $this->db->get('setting')->row();
$fee = (($fare * $setting->admin_charge) / 100);
$tax = (($fare * $setting->tax) / 100);
$driver_charge = $fare - ($fee + $tax);
$data = array('base_fare' => $rs->base_price, 'km_fare' => $rs->km_rate * $distance, 'min_fare' => $least_min, 'sub_total_fare' => $sub_total, 'trip_cost' => $fare, 'fee' => $fee, 'payout' => $driver_charge, 'tax' => $tax );
$this->db->where('transport_id', $trip_id)->update('transport_details', $data);
$sql = $this->db->query("SELECT driver_id FROM transport_details WHERE transport_id = '$trip_id'")->row();
$this->db->where('driver_id', $sql->driver_id)->update('drivers', array('book_status'=>0));
return $min_fare;
}
}
}
}
function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {
$earth_radius = 6371;
$dLat = deg2rad($latitude2 - $latitude1);
$dLon = deg2rad($longitude2 - $longitude1);
$a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon / 2) * sin($dLon / 2);
$c = 2 * asin(sqrt($a));
$d = $earth_radius * $c;
return $d;
}
function cal_baseRate() {
$data1 = "SELECT * FROM setting WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
return $rs;
}
function push_sent_cancel($fcm_token, $fcm_data) {
// print_r($fcm_data);
$data1 = "SELECT * FROM settings WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
$key = $rs->key;
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"ringtone_driver\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"trip_id\" : \"".$fcm_data['id']."\", \"trip_status\" : 0}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json', 'Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_close($ch);
$out = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
public function get_trip_info($trip_id='') {
if($trip_id)
{
$data1 = "SELECT * FROM setting WHERE id = '1' ";
$query1 = $this->db->query($data1);
$rs = $query1->row();
$currency = $rs->currency;
$rs = $this->db->query("SELECT t.transport_id AS trip_id,(CASE t.status WHEN 9 THEN 'cancelled' WHEN 3 THEN 'booking' WHEN 5 THEN 'inprocess' WHEN 6 THEN 'completed' ELSE 'Invalid' END) AS trip_status,t.trip_distance AS distance, CONCAT(t.trip_cost,' ','$currency') AS fare, t.pickup_location AS source_location, t.pickup_lat AS source_latitude, t.pickup_lng AS source_longitude, t.drop_location AS destination_location, t.drop_lat AS destination_latitude, t.drop_lng AS destination_longitude, c.profile_image AS customer_photo, CONCAT(c.first_name,' ',c.last_name) AS customer_name FROM `transport_details` AS t LEFT JOIN customers AS c ON t.customer_id = c.customer_id WHERE t.transport_id =".$trip_id)->row();
if ($rs) {
return $rs;
} else {
return false;
}
}else{
return false;
}
}
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment