-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax.php
46 lines (39 loc) · 1.15 KB
/
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
40
41
42
43
44
45
46
<?php
require("db/database.php");
$dbh = new DatabaseHelper("localhost", "root", "", "UniTicket");
$response = new \stdClass();
$response->state = 'error';
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'modifyQuantity':
if($dbh->addTicketToCart($_COOKIE["sessionId"], $_POST['eventId'], $_POST['quantity'])){
$response->state = 'done';
} else {
$response->state = 'action failed';
}
break;
case 'buyTicket':
$result = $dbh->buyTicket($_COOKIE["sessionId"], $_POST['eventId']);
if($result == 1){
$response->state = 'done';
} else if($result == 0){
$response->state = 'not enought tickets available';
} else if($result == -1){
$response->state = 'user or event error';
} else {
$response->state = $result;
}
break;
case 'getTicketsAvailable':
$response->state = 'done';
$response->quantity = $dbh->ticketAvailable($_POST["eventId"]);
break;
default:
$response->state = 'Unknown request';
break;
}
}
$responseJSON = json_encode($response);
echo $responseJSON;
$dbh->close();
?>