-
Notifications
You must be signed in to change notification settings - Fork 2
/
add_staff.php
70 lines (50 loc) · 2.34 KB
/
add_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
70
<?php
session_start();
require "vendor/autoload.php";
$fname = $_POST["staff-fname"];
$lname = $_POST["staff-lname"];
$email = $_POST["staff-email"];
$password = $_POST["password"];
$phoneno = $_POST["staff-phone"];
$role = $_POST["role"];
$error_msg;
try {
$m = new MongoDB\Client("mongodb://vinay0410:[email protected]:23725/pizza");
$db = $m->pizza;
$collection = $db->users;
} catch (MongoDB\Driver\Exception\ConnectionTimeoutException $e) {
//die("Caught Exception failed to Connect".$e->getMessage()."\n");
$var = array('error' => True, 'msg' => "Couldn't Connect to Database");
echo json_encode($var);
exit();
} catch (Exception $e) {
$var = array('error' => True, 'msg' => $e->getMessage());
echo json_encode($var);
exit();
}
$result_email = $collection->findOne(['email' => $email]);
if (empty($result_email)) {
$document = array(
"fname" => $fname,
"lname" => $lname,
"email" => $email,
"address" => array(),
"password" => $password,
"phoneno" => $phoneno,
"role" => $role,
"ofOutlet" => new MongoDB\BSON\ObjectID($_SESSION["logged"]["ofOutlet"])
);
$inserted_id = $collection->insertOne($document)->getInsertedId();
$document["_id"] = $inserted_id;
} else {
$var = array('error' => True, 'msg' => "Email Address already exists");
echo json_encode($var);
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);" data-title="<?php echo $role; ?>" ><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>