-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_ajax.php
39 lines (34 loc) · 1.15 KB
/
index_ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
session_start();
require_once 'functions/functions.php';
require_once 'functions/database.php';
function search_get($data) {
$logged_in_user = user\get_logged_in_user();
$user_id = NULL;
if ($logged_in_user) $user_id = $logged_in_user['id'];
$trips = database\get_trips_near_on(
$data['route'],
$data['departure'],
$user_id);
if ($trips == NULL) $trips = array();
$trips_found = array("trips" => $trips);
functions\json_respond('OK', 'Searched!', $trips_found);
}
function request_post($data) {
$logged_in_user = user\get_logged_in_user();
if (!$logged_in_user)
return functions\json_respond('ERROR', 'Login Required!');
$request_data = array(
"user_id" => $logged_in_user['id'],
"trip_id" => $data['trip_id'],
"message" => $data['message']);
if (database\request_ride($request_data))
return functions\json_respond('OK', 'Request Sent!');
else
return functions\json_respond('ERROR', 'Unable to request ride');
}
if ($_GET) {
search_get(json_decode($_GET['data'], true));
} elseif ($_POST) {
request_post(json_decode($_POST['data'], true));
}