forked from rpiambulance/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.modify_schedule.php
42 lines (33 loc) · 1.27 KB
/
.modify_schedule.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
<?php
require_once ".db_config.php";
require_once ".functions.php";
$connection = new PDO("mysql:host=$dhost;dbname=$dname", $duser, $dpassword);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(!isset($dname)) {
$dname = 'ambulanc_web';
}
// Selecting Database
//$db = mysql_select_db("$dname", $connection);
$connection->exec("USE `$dname`");
$secret = "SUPERSECRETADMINKEYWOOHOO";
parse_str(file_get_contents("php://input"), $post);
$weeks = ['currentWeek', 'nextWeek'];
if (checkIfAdmin()){
$post['data'] = json_decode($post['data'], true);
foreach($weeks as $w) {
foreach($post['data'][$w] as $elem) {
$sql = "UPDATE crews SET cc=:cc, driver=:driver, attendant=:attendant, observer=:observer WHERE id=:id";
$statement = $connection->prepare($sql);
$statement->bindValue(':cc', $elem["spots"]["cc"]["id"]);
$statement->bindValue(':driver', $elem["spots"]["driver"]["id"]);
$statement->bindValue(':attendant', $elem["spots"]["attendant"]["id"]);
$statement->bindValue(':observer', $elem["spots"]["observer"]["id"]);
$statement->bindValue(':id', $elem['id']);
$result = $statement->execute();
}
}
echo(json_encode(array('success' => true, 'message' => 'Updated')));
} else {
echo 'Nice Try.';
}
?>