This repository was archived by the owner on Apr 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax_car_ship.php
More file actions
69 lines (61 loc) · 2.8 KB
/
Copy pathajax_car_ship.php
File metadata and controls
69 lines (61 loc) · 2.8 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require "ajax_header.php";
$response = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['regid'])) {
$regid = $_POST['regid'];
$shipto = $_POST['shipto'];
$user_class = new User($_SESSION['id']);
$date = date('Y-m-d H:i:s');
$db->query("SELECT * FROM garage WHERE id = :regid");
$db->bind(':regid', $regid);
$car = $db->fetch_row(true);
if ($car['manufacturing'] == "1") {
$response['message'] = "Unable to take action due to car in manufacturing status.";
} elseif ($car['manufacturing'] != "1") {
if ($shipto == "player") {
if ($car['owner'] == $user_class->id) {
$db->query("SELECT id, username, city FROM grpgusers WHERE username = :username");
$db->bind(':username', $_POST['username']);
$array = $db->fetch_row(true);
if ($array['city'] != $car['location']) {
$response['message'] = "You have to be in the same location as the car to send it to another player.";
} else {
$db->query("UPDATE garage SET owner = :new_owner WHERE id = :regid");
$db->bind(':new_owner', $array['id']);
$db->bind(':regid', $regid);
$db->execute();
Send_Event($array['id'], "You have received a car from " . $user_class->formattedname);
$response['message'] = "The car ($regid) has been sent to {$_POST['username']}.";
}
} else {
$response['message'] = "You do not own that car.";
}
} else {
$db->query("SELECT name FROM cities WHERE id = :city_id");
$db->bind(':city_id', $shipto);
$city = $db->fetch_row(true);
if ($city) {
$country = $city['id'];
if ($car['owner'] == $user_class->id) {
if ($user_class->city != $car['location']) {
$response['message'] = "You have to be in the same location as the car to send it to another country.";
} else {
$db->query("UPDATE garage SET location = :location WHERE id = :regid");
$db->bind(':location', $user_class->city);
$db->bind(':regid', $regid);
$db->execute();
$response['message'] = "The car ($regid) has been sent to $country successfully.";
}
} else {
$response['message'] = "You do not own that car.";
}
} else {
$response['message'] = "Invalid country selection.";
}
}
}
} else {
$response['message'] = 'Invalid request.';
}
echo json_encode($response);
?>