Login API - Controller.php
public function __construct(){
parent::__construct();
$this->load->model('DriverModel');
$this->load->model('UserModel');
}
// user login data (Fetch)
public function login_driver()
{
$method = $_SERVER['REQUEST_METHOD'];
if($method != 'POST'){
$json = array("status" => 400, "message" => "Bad request");
}
else {
$post_data = $this->input->post();
$data = array(
'email' => $post_data['email'],
'password' => md5($post_data['password'])
);
$resultDriverGetdata=$this->DriverModel->loginDriverdata($post_data['email'],$post_data['password']);
if($resultDriverGetdata>=1){
$data['result'] = $resultDriverGetdata;
$result[] = array('driver_id'=>$resultDriverGetdata[0]['id'],'type'=>$resultDriverGetdata[0]['type'],'email'=>$resultDriverGetdata[0]['email'],'fullname'=>$resultDriverGetdata[0]['fullname'],'status' => $resultDriverGetdata[0]['status'],'created_date' => $resultDriverGetdata[0]['created_date'],'approvel'=>$resultDriverGetdata[0]['approvel']);
$json = array("status" => 1,"message"=>"success", "data" => $result);
}
else{
$json = array("status" => 0, "message" => "Wrong Email or password");
}
}
echo json_encode($json);
}
// registration (Insert)
public function register_driver()
{
$method = $_SERVER['REQUEST_METHOD'];
if($method != 'POST'){
$json = array("status" => 400, "message" => "Bad request");
}
else {
$post_data = $this->input->post();
$data = array(
'type' => $post_data['type'],
'fullname' => $post_data['fullname'],
'email' => $post_data['email'],
'password' => md5($post_data['password']),
'old_password' => md5($post_data['password']),
'authentication_code' => $post_data['authentication_code'],
'device_id' => $post_data['device_id'],
'device_token' => $post_data['device_token']
);
$resultGetdata=$this->DriverModel->checkDriverdata($post_data['email']);
if($resultGetdata>=1){
$json = array("status" =>0, "message" => "Data already exist");
}
else{
if ($post_data['email'] == "") {
$resp = array("status" => 400,"message" => "Email can not empty");
}
else{
$resp = $this->DriverModel->register_driver_data($data);
$id = $this->db->insert_id();
// insert into driver details
$datadetails = array(
'driver_id' => $id
);
$respdriver = $this->DriverModel->add_driverdetails($datadetails);
if (!file_exists('driver_uploads/'.$id)) {
mkdir('driver_uploads/'.$id, 0777, true);
}
$result[] = array('driver_id'=>$id , 'fullname' => $post_data['fullname'] , 'email'=>$post_data['email']);
$json = array("status" => 1, "message"=>"success", "data" => $result);
}
}
}
echo json_encode($json);
}
//photo
public function updatedriver_photo()
{
$method = $_SERVER['REQUEST_METHOD'];
if($method != 'POST'){
$json = array("status" => 400, "message" => "Bad request");
}
else {
$post_data = $this->input->post();
$driver_id = $post_data['driver_id'];
// profile photo
$photoPath = driver_profile;
if($_FILES['photo']['name']!="")
{
$config['upload_path'] = './driver_uploads/'.$driver_id.'/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|jpe';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('photo'))
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$upload_data=$this->upload->data();
$photo_name=$upload_data['file_name'];
$photoNewpath = $photoPath.$driver_id.'/'.$photo_name;
}
}
else{
$photo_name='no_profile.png';
$photoNewpath = user_profile.$photo_name;
}
// profile photo update
$data = array(
'photo' => $photo_name
);
$resp = $this->DriverModel->update_driver_photo($driver_id,$data);
$result[] = array('driver_id'=>$driver_id,'photo' => $photoNewpath);
$json = array("status" => 1,"message"=>"success", "data" => $result); }
echo json_encode($json);
}
// Multiple Photo
public function addVehicle()
{
$method = $_SERVER['REQUEST_METHOD'];
if($method != 'POST'){
$json = array("status" => 400, "message" => "Bad request");
}
else {
$post_data = $this->input->post();
$vehicledata = array(
'driver_id' => $post_data['driver_id'],
'vehicle_name' => $post_data['vehicle_name'],
'vehicle_type' => $post_data['vehicle_type'],
'vehicle_number' => $post_data['vehicle_number'],
'seats' => $post_data['seats']
);
$resp = $this->DriverModel->add_vehicledata($vehicledata);
$id = $this->db->insert_id();
// upload photoes
if($_FILES['vehicle_photo']['name']!="")
{
$countFile = count($_FILES['vehicle_photo']['name']);
foreach($_FILES['vehicle_photo']['tmp_name'] as $key => $tmp_name)
{
$temp = explode(".", $_FILES["vehicle_photo"]["name"][$key]);
$file_name = round(microtime(true)).$key.'P'.'.' . end($temp);
//$file_name = $_FILES['share_pic']['name'][$key];
$file_size =$_FILES['vehicle_photo']['size'][$key];
$file_tmp =$_FILES['vehicle_photo']['tmp_name'][$key];
$file_type=$_FILES['vehicle_photo']['type'][$key];
move_uploaded_file($file_tmp,"./driver_uploads/".$post_data['driver_id']."/".$file_name);
$data_vehicle = array(
'vehicle_id' => $id,
'driver_id' => $post_data['driver_id'],
'photo_type' => 'photo',
'photo' => $file_name
);
//print_r($data_vehicle);
$resp = $this->DriverModel->add_vehicle_photo($data_vehicle);
//echo $this->db->last_query();
$resultVehicle[] = array('vehicle_id'=>$id,'driver_id'=>$post_data['driver_id'],'photo_type' => 'photo','photo' => $file_name);
//$jsonVehicle = array("status" => 1, "message"=>"success", "vehiclephoto" => $resultVehicle);
}
}
// upload photoes
if($_FILES['numberplate_photo']['name']!="")
{
$countFile = count($_FILES['numberplate_photo']['name']);
foreach($_FILES['numberplate_photo']['tmp_name'] as $key => $tmp_name)
{
$temp = explode(".", $_FILES["numberplate_photo"]["name"][$key]);
$file_platname = round(microtime(true)).$key. '.' . end($temp);
//$file_platname = $_FILES['share_pic']['name'][$key];
$file_size =$_FILES['numberplate_photo']['size'][$key];
$file_tmp =$_FILES['numberplate_photo']['tmp_name'][$key];
$file_type=$_FILES['numberplate_photo']['type'][$key];
move_uploaded_file($file_tmp,"./driver_uploads/".$post_data['driver_id']."/".$file_platname);
$data_vehicle = array(
'vehicle_id' => $id,
'driver_id' => $post_data['driver_id'],
'photo_type' => 'plate',
'photo' => $file_platname
);
//print_r($data_vehicle);
$resp = $this->DriverModel->add_vehicle_photo($data_vehicle);
//echo $this->db->last_query();
$vehicleplate[] = array('vehicle_id'=>$id,'driver_id'=>$post_data['driver_id'],'photo_type' => 'plate','photo' => $file_platname);
//$jsonVehicle = array("status" => 1, "message"=>"success", "vehiclephoto" => $vehicleplate);
}
}
$result[] = array('driver_id'=>$post_data['driver_id'],'vehicle_id'=>$id ,'vehicle_name' => $post_data['vehicle_name'], 'vehicle_type' => $post_data['vehicle_type'], 'vehicle_number' => $post_data['vehicle_number'] , 'seats'=>$post_data['seats'], "vehiclephoto" => $resultVehicle, "vehicleplate" => $vehicleplate);
$json = array("status" => 1, "message"=>"success", "data" => $result);
}
echo json_encode($json);
}
Model.php
//insert data
public function add_numberplate_photo($data_vehicleplate)
{
$this->db->insert('tbl_vehicle_platephoto',$data_vehicleplate);
return array("status" => 201,"message" => "Data has been created");
}
//delete data
public function delete_numberPlate($id)
{
$this->db->where('id', $id);
$this->db->delete('tbl_vehicledetails');
return array("status" => 201,"message" => "Data has been deleted");
}
//Fetch data
public function checkDriverpassword($driver_id,$old_password)
{
$query = $this->db->get_where('tbl_driverdata',array('id'=>$driver_id , 'old_password'=>$old_password));
$res = $query->result_array();
if ($query->num_rows() > 0){
return $res;
}
else{
return false;
}
}
// update data
public function update_driverpassword($driver_id, $data) {
$this->db->where('id', $driver_id);
$this->db->update('tbl_driverdata', $data);
return array("status" => 201,"message" => "Data has been updated");
}
Comments
Post a Comment