This repository has been archived by the owner on Nov 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
145 lines (120 loc) · 3.92 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php include('db.php');
$db = new DB(DB_USER, DB_NAME, DB_PASS);
header('Content-Type: application/json');
if (!isset($_GET['app_key'])) {
header("HTTP/1.0 403 Not Authorized");
echo json_encode(array(
"id" => "",
"username" => "",
"message" => "Pas de clé !"
));
exit;
}
$query = $db->request(
"SELECT * FROM evenements WHERE id = ?",
array($_GET['app_key'])
);
if ($query->rowCount() == 0) {
header("HTTP/1.0 400 Bad Request");
echo json_encode(array(
"id" => "",
"username" => "",
"message" => "Clé incorrecte !"
));
exit;
}
$event = $query->fetch();
$split = explode("?", $_SERVER["REQUEST_URI"]);
$split = explode("/", $split[0]);
if (end($split) == "validate") {
$db->request(
"UPDATE reservations SET validated = ? WHERE id = ?",
array((isset($_POST['validate']) && $_POST['validate'] == 0 ? 0 : 1), $split[count($split) - 2])
);
echo json_encode(array(
"id" => $split[count($split) - 2],
"username" => "",
"message" => "Place ".((isset($_POST['validate']) && $_POST['validate'] == 0 ? 'dé' : ''))."validée"
));
exit;
}
$query = $db->request(
"SELECT * FROM reservations WHERE username = ? AND event_id = ?",
array(end($split), $event['id'])
);
if ($query->rowCount() == 0) {
if ($event['idShotgun'] == NULL) {
header("HTTP/1.0 404 Not Found");
echo json_encode(array(
"id" => "",
"username" => "",
"message" => "Pas trouvé"
));
exit;
}
else {
$query = $db->request(
"SELECT * FROM shotgun.prod2_choice, shotgun.prod2_option
WHERE shotgun.prod2_choice.fk_desc_id = ? AND shotgun.prod2_choice.choice_id = shotgun.prod2_option.fk_choice_id AND shotgun.prod2_option.user_login = ? AND shotgun.prod2_option.option_status = ?",
array($event['idShotgun'], end($split), 'V')
);
if ($query->rowCount() == 0) {
header("HTTP/1.0 404 Not Found");
echo json_encode(array(
"id" => "",
"username" => "",
"message" => "Pas trouvé"
));
exit;
}
$data = $query->fetch();
$db->request(
"INSERT INTO reservations VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, 0)",
array($data['user_login'], $data['user_nom'], $data['user_prenom'], $data['user_mail'], $data['choice_name'], $data['option_id'], $event['id'])
);
$query = $db->request(
"SELECT * FROM reservations WHERE username = ? AND event_id = ?",
array(end($split), $event['id'])
);
}
}
$data = $query->fetch();
if ($data["validated"]) {
header("HTTP/1.0 410 Gone");
}
echo json_encode(array(
"id" => $data['id'],
"username" => $data['username'],
"creationDate" => $event["creation_date"] == NULL ? 1 : $event["creation_date"],
"expirationDate" => $event["expires_at"] == NULL ? 99999999999 : $event["expires_at"],
"data" => array(
"Informations générales" => array(
"Nom" => $data['lastname'],
"Prénom" => $data['firstname'],
"Email" => $data['email'],
),
"Informations complémentaires" => array(
"Evènement" => $event["seance"],
"Type de place" => $data["type"],
"Numéro de réserv." => $data["reservation_id"],
),
),
"positiveCommand" => array(
'name' => $data["validated"] ? 'Dévalider' : 'Valider',
'command' => 'validate',
'arguments' => array(
'validate' => $data["validated"] ? '0' : '1'
)
)
));
/*
$file = file_get_contents("data.csv");
$reservations = explode(PHP_EOL, $file);
foreach ($reservations as $reservation) {
$data = explode(',', $reservation);
$db->request(
"INSERT INTO reservations(reservation_id, username, firstname, lastname, email, type) VALUES(?, ?, ?, ?, ?, ?)",
array($data[0], $data[1], $data[2], $data[3], $data[4], $data[5])
);
}
*/