-
Notifications
You must be signed in to change notification settings - Fork 2
/
edit_staff.php
69 lines (45 loc) · 2.28 KB
/
edit_staff.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
<?php
session_start();
require "vendor/autoload.php";
$staff_id = $_POST["staff_id"];
$fname = $_POST["edit-staff-fname"];
$lname = $_POST["edit-staff-lname"];
$email = $_POST["edit-staff-email"];
$password = $_POST["password"];
$phoneno = $_POST["edit-staff-phone"];
try {
$m = new MongoDB\Client("mongodb://vinay0410:[email protected]:23725/pizza");
$db = $m->pizza;
$collection = $db->users;
$result_email = $collection->findOne(['email' => $email]);
if (empty($result_email)) {
$document = array(
"fname" => $fname,
"lname" => $lname,
"email" => $email,
"address" => array(),
"password" => $password,
"phoneno" => $phoneno
);
$collection->updateOne([ '_id' => new MongoDB\BSON\ObjectID($staff_id)], [ '$set' => $document ]);
$document["_id"] = $staff_id;
} else {
$var = array('error' => True, 'msg' => "Email Address already exists");
echo json_encode($var);
exit();
}
} catch (MongoDB\Driver\Exception\ConnectionTimeoutException $e) {
echo json_encode(array('error' => True, 'msg' => "Couldn't Connect to Database"));
exit();
} catch (Exception $e) {
#die("Caught Exception failed to Connect".$e->getMessage()."\n");
echo json_encode(array('error' => True, 'msg' => $e->getMessage()));
exit();
}
?>
<h4 class="list-group-item-heading accordion-toggle"><?php echo $document["fname"] . " " . $document["lname"]; ?>
<button type="button" class="btn btn-danger btn-space pull-right" id="<?php echo $document["_id"]; ?>" onclick="delete_staff(this);" data-role="<?php echo $document['role']; ?>"><span class="glyphicon glyphicon-remove"></span></button>
<button type="button" name="edit_modal" class="btn btn-default btn-space pull-right" data-toggle="modal" data-target="#editStaff" data-staff='<?php echo json_encode($document); ?>' onclick="putContents(this);" ><span class="glyphicon glyphicon-pencil"></span></button>
</h4>
<p class="list-group-item-text"><?php echo $document['email']; ?></p>
<p class="list-group-item-text"><?php echo $document['phoneno']; ?></p>