forked from rpiambulance/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.edit_member.php
66 lines (55 loc) · 2.03 KB
/
.edit_member.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
<?php
//header("Access-Control-Allow-Origin: *");
//header("Content-Type: application/json; charset=UTF-8");
require_once ".functions.php";
$connection = openDatabaseConnection();
$modifiableFields = array(
"username", "password", "first_name", "last_name", "dob", "email",
"rpi_address", "home_address", "cell_phone", "home_phone", "rcs_id", "rin",
"radionum", "cpr_exp", "cpr_assoc", "emt_level",
"emt_num", "emt_exp", "other_training", "dl_state", "dl_exp", "cevo_date",
"epinipherine", "atropine", "glucometry", "nims100", "nims200", "nims700",
"nims800", "admin", "rank", "pres", "vicepres", "captain", "firstlt",
"secondlt", "schedco", "radioco", "traincommchair", "dutysup", "ees",
"cctrainer", "drivertrainer", "firstresponsecc", "crewchief", "driver",
"backupcc", "backupdriver", "clearedcc", "cleareddriver", "attendant", "observer", "active",
"access_revoked", "cprco", "webmaster", "qaco", "devco"
);
if($_SERVER['REQUEST_METHOD'] === 'POST') {
if(checkIfAdmin($connection)) {
$data = json_decode($_POST['data'], true);
$sql = "UPDATE members SET";
if(isset($data['change_password'])){
if(isset($data['password'])) {
$data['password'] = password_hash(hash('sha256', $data['password']), PASSWORD_DEFAULT);
}
}
foreach($modifiableFields as $mf) {
if(isset($data[$mf])) {
$sql .= " $mf = :$mf,";
}
}
// Eliminate last comma
$sql = substr($sql, 0, -1);
$sql .= " WHERE id = :memberId";
$statement = $connection->prepare($sql);
foreach($modifiableFields as $mf) {
if(isset($data[$mf])) {
$statement->bindValue(":$mf", $data[$mf]);
}
}
$statement->bindValue(':memberId', $data['id']);
$result = $statement->execute();
echo(json_encode(array('success' => true)));
} 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
}
?>