-
Notifications
You must be signed in to change notification settings - Fork 3
/
reserve.php
34 lines (28 loc) · 1.13 KB
/
reserve.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
<?php
require("includes/config.php");
checkTable(SLOT_TABLE);
makeSureLogin();
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$op_id = $_SESSION["id"];
$privilege = $_SESSION["privilege"];
//dump($_POST);
if ($privilege > 1){ //if you are admin op you can cancel other's slot
$updateSlot = sprintf("UPDATE %s SET %s=? ", SLOT_TABLE, SLOT_OP_ID) .
sprintf("WHERE %s=? AND (%s=0 OR ?=0)", SLOT_ID, SLOT_OP_ID);
$result = query($updateSlot, $_POST["op"],$_POST["id"],$_POST["op"]);
} else { //normal op can only take free slot or cancel your own slot
$updateSlot = sprintf("UPDATE %s SET %s=? ", SLOT_TABLE, SLOT_OP_ID) .
sprintf("WHERE %s=? AND (%s=0 OR %s=?)", SLOT_ID, SLOT_OP_ID, SLOT_OP_ID);
$result = query($updateSlot, $_POST["op"],$_POST["id"],$_SESSION["id"]);
}
if ($result === false) {
apologize("Failed to take/cancel slot! Please try again later.");
} else {
redirect($_POST["url"]);
}
}else
{
redirect("index.php");
}
?>