forked from rpiambulance/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.defaults.php
52 lines (44 loc) · 1.63 KB
/
.defaults.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
<?php
//header("Access-Control-Allow-Origin: *");
//header("Content-Type: application/json; charset=UTF-8");
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`");
if($_SERVER['REQUEST_METHOD'] === 'POST') {
if(checkIfAdmin($connection)) {
$data = json_decode($_POST['data'], true);
try {
foreach($data as $elem) {
$sql = "UPDATE default_crews SET cc=:cc, driver=:driver, attendant=:attendant, observer=:observer, dutysup=:dutysup WHERE day=:day";
$statement = $connection->prepare($sql);
$statement->bindParam(':cc', $elem['cc']);
$statement->bindParam(':driver', $elem['driver']);
$statement->bindParam(':attendant', $elem['attendant']);
$statement->bindParam(':observer', $elem['observer']);
$statement->bindParam(':dutysup', $elem['dutysup']);
$statement->bindParam(':day', $elem['day']);
$result = $statement->execute();
}
echo(json_encode(array('success' => true, 'message' => 'Updated')));
} catch (PDOException $e) {
echo(json_encode(array('success' => false, 'error' => $e)));
}
} else {
echo 'nice try';
}
} else {
$statement= $connection->prepare("SELECT * FROM default_crews");
$statement->execute();
$results=$statement->fetchAll(PDO::FETCH_ASSOC);
$json=json_encode($results);
echo($json);
// LOAD DATA
}
?>