Advertisement
Guest User

find_ride.php

a guest
Jul 17th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.94 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Find_ride extends CI_Controller {
  4.  
  5.     public function __construct() {
  6.         parent::__construct();
  7.     }
  8.    
  9.     public function index(){
  10.         $data = array();
  11.         $data['main_content'] = $this->load->view('find_ride',$data,true);
  12.         $this->load->view('index',$data);
  13.     }
  14.  
  15.     public function find_ride_action(){  
  16.         $error = false;
  17.         $leaving_from=htmlspecialchars($_POST['leaving_from']);
  18.         $destination=htmlspecialchars($_POST['destination']);
  19.         $leaving_date=htmlspecialchars($_POST['leaving_date']);
  20.         $leaving_longitude=htmlspecialchars($_POST['leaving_longitude']);
  21.         $leaving_latitude=htmlspecialchars($_POST['leaving_latitude']);
  22.         $destination_longitude=htmlspecialchars($_POST['destination_longitude']);
  23.         $destination_latitude=htmlspecialchars($_POST['destination_latitude']);
  24.         $customer_id=$this->session->userdata('id');
  25.  
  26.         if(empty($customer_id)){
  27.             $message['customer_id'] = "Login is required.";
  28.             $response['status']=False;
  29.             $response['message']=$message;
  30.             echo json_encode($response);
  31.             exit();
  32.         }
  33.  
  34.         if(empty($leaving_from)){
  35.             $error = true;
  36.             $message['leaving_from'] = "Leaving from is required.";
  37.         }
  38.  
  39.         if(empty($destination)){
  40.             $error = true;
  41.             $message['destination'] = "Destination id is required.";
  42.         }
  43.  
  44.         if(empty($leaving_date)){
  45.             $error = true;
  46.             $message['leaving_date'] = "Leaving date is required.";
  47.         }
  48.  
  49.         if($error){
  50.             $response['status']=False;
  51.             $response['message']=$message;
  52.             echo json_encode($response);
  53.             exit();
  54.         }else{
  55.             $event_id = $this->db->query("SELECT * FROM rides WHERE leaving_from = '$leaving_from' and destination = '$destination' and leaving_date = '$leaving_date'")->result();
  56.  
  57.             $table = '<div class="row">';
  58.             if(count($event_id)){
  59.                 foreach($event_id as $myride){
  60.                     $table .= '<div class="col-md-12">
  61.                            <div class="card">
  62.                                <h5 class="card-header">Ride Details <button class="btn btn-primary float-right" onclick="booking('.$myride->id.')">Book</button> </h5>
  63.                                <div class="card-body">
  64.                                    <p style="margin-bottom:2px;"><span class="text-warning">Source:</span> '.$myride->leaving_from.'</p>
  65.                                    <p style="margin-bottom:2px;"><span class="text-warning">Destination:</span> '.$myride->destination.'</p>
  66.                                    <p style="margin-bottom:2px;"><span class="text-warning">Date:</span> '.$myride->leaving_date.'</p>
  67.                                  
  68.                                </div>
  69.                            </div>
  70.                        </div>';
  71.                 }
  72.             }else{
  73.                 $table .= '<div class="col-md-12">
  74.                        <div class="card">
  75.                            <h5 class="card-header">Ride Details</h5>
  76.                            <div class="card-body">
  77.                                <p><span class="text-danger">No rides Available.</span></p>
  78.                            </div>
  79.                        </div>
  80.                    </div>';
  81.             }
  82.             $table .= "</div>";
  83.  
  84.             $response['status']=true;
  85.             $response['message']=$table;
  86.             echo json_encode($response);
  87.             exit();
  88.         }
  89.     }
  90.  
  91.     public function find_ride_action_perform(){
  92.         $error = false;
  93.         $leaving_from=htmlspecialchars($_POST['leaving_from']);
  94.         $destination=htmlspecialchars($_POST['destination']);
  95.         $leaving_date=htmlspecialchars($_POST['leaving_date']);
  96.         $leaving_longitude=htmlspecialchars($_POST['leaving_longitude']);
  97.         $leaving_latitude=htmlspecialchars($_POST['leaving_latitude']);
  98.         $destination_longitude=htmlspecialchars($_POST['destination_longitude']);
  99.         $destination_latitude=htmlspecialchars($_POST['destination_latitude']);
  100.         $ride_id=htmlspecialchars($_POST['ride_id']);
  101.         $customer_id=$this->session->userdata('id');
  102.  
  103.  
  104.         $created_at = date('Y-m-d G:i:s');
  105.         $updated_at = date('Y-m-d G:i:s');
  106.  
  107.         $pkg= array(
  108.             'customer_id' => $customer_id,
  109.             'leaving_from' => $leaving_from,
  110.             'destination' => $destination,
  111.             'leaving_date' => $leaving_date,
  112.             'ride_id' => $ride_id,
  113.             'leaving_longitude' => $leaving_longitude,
  114.             'leaving_latitude' => $leaving_latitude,
  115.             'destination_longitude' => $destination_longitude,
  116.             'destination_latitude' => $destination_latitude,
  117.             'created_at' => $created_at,
  118.             'updated_at' => $updated_at,
  119.         );
  120.  
  121.         // $data = $this->security->xss_clean($pkg);
  122.         // $event_id = $this->db->q('bookings',$data);
  123.         $event_id = $this->db->query("INSERT INTO bookings (customer_id, leaving_from, destination, leaving_date, ride_id, leaving_longitude, leaving_latitude, destination_longitude, destination_latitude, created_at, updated_at)
  124.        VALUES ('$customer_id', '$leaving_from', '$destination', '$leaving_date', '$ride_id', '$leaving_longitude', '$leaving_latitude', '$destination_longitude', '$destination_latitude', '$created_at', '$updated_at')");
  125.        
  126.         $response['status']=true;
  127.         $response['message']="<div class='alert alert-success' style='width: 100%'> <i class='fa fa-check-circle'></i> Your ride has been booked for you. <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span></button></div>";
  128.         echo json_encode($response);
  129.         exit();
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement