Пример #1
0
function update_user($data)
{
    if (user\update_user($data)) {
        return functions\json_respond('OK', 'Updated!');
    } else {
        return functions\json_respond('ERROR', 'Couldn\'t update user.');
    }
}
Пример #2
0
function search_get($data)
{
    $logged_in_user = user\get_logged_in_user();
    if (!$logged_in_user) {
        return functions\json_respond('ERROR', 'Login Required!');
    }
    $user_id = $logged_in_user['id'];
    $users = user\get_all_users();
    functions\json_respond('OK', 'Query Performed!', array("users" => $users));
}
Пример #3
0
function update_ride_request_status($driver_id, $data)
{
    $trip = database\get_trip($data['trip_id']);
    if ($trip['driver_id'] != $driver_id) {
        return functions\json_respond('ERROR', 'Unauthorized access!');
    }
    $spots_remaining = database\update_ride_request_status($data['user_id'], $data['trip_id'], $data['status']);
    if ($spots_remaining < 0) {
        return functions\json_respond('ERROR', 'Insufficient spots!');
    }
    functions\json_respond('OK', 'Query performed!', array("spots_remaining" => $spots_remaining));
}
Пример #4
0
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');
    }
}
Пример #5
0
function share_post()
{
    $data = json_decode($_POST['data'], true);
    // Get driver info
    $driver_id = $_SESSION['user_id'];
    if (!$driver_id) {
        return functions\json_respond('ERROR', "User not logged in!");
    }
    // Store places
    $origin_id = database\add_place($data['route']['origin']);
    $destination_id = database\add_place($data['route']['destination']);
    if (!($origin_id or $destination_id)) {
        return functions\json_respond('ERROR', "Couldn't store places!");
    }
    // Store trip
    $trip_data = array('driver_id' => $driver_id, 'spots' => $data['spots'], 'length' => $data['route']['trip_length'], 'message' => $data['message'], 'women_only' => $data['women_only'], 'departure_time' => $data['departure'], 'origin_id' => $origin_id, 'destination_id' => $destination_id);
    $trip_id = database\add_trip($trip_data);
    if (!$trip_id) {
        return json_respond('ERROR', "Couldn't store trip!");
    }
    functions\json_respond('OK', 'Trip saved!');
}
Пример #6
0
function request_ride($data)
{
    // TODO: Add request to the database
    functions\json_respond('OK', 'Request Sent!');
}