-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddStaff.php
More file actions
155 lines (148 loc) · 6.47 KB
/
addStaff.php
File metadata and controls
155 lines (148 loc) · 6.47 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
session_start();
include 'connection.php';
if (!isset($_SESSION['id']) || $_SESSION['role'] != 'admin') {
header('Location: login.php');
exit;
}
include_once('includes/header.php');
?>
<style>
.container-center {
display: flex;
justify-content: center;
align-items: center;
}
</style>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header text-center">Add Staff</h1>
</div>
<div class="row container-center">
<div class="col-md-6">
<form class="form-horizontal form-label-left" action="" method="POST">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title text-center " style="font-weight: bold;">Staff Information</h3>
</div>
<div class="panel-body">
<div class="form-group">
<div class="col-md-12">
<label>Name</label>
</div>
<div class="col-md-12">
<input type="text" name="name" class="form-control" placeholder="Enter Name">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label>Email</label>
</div>
<div class="col-md-12">
<input type="email" name="email" class="form-control" placeholder="Enter Email">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label>Password</label>
</div>
<div class="col-md-12">
<input type="text" name="password" class="form-control" placeholder="Enter Password">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="role">Role</label>
</div>
<div class="col-md-12">
<select name="role" class="form-control">
<option selected>- Select a Role -</option>
<option value="manager">Manager</option>
<option value="staff">Others</option>
</select>
</div>
</div>
<div class="form-group" hidden>
<div class="col-md-12">
<label>Status</label>
</div>
<div class="col-md-12">
<input type="text" name="status" class="form-control" value="0">
</div>
</div>
<div class="text-center">
<input type="submit" name="submit" class="btn btn-primary text-center" value="Add Staff">
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Success and Error Modals -->
<div class="modal fade" id="successModal" tabindex="-1" role="dialog" aria-labelledby="successModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="successModalLabel">Success</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="successMessage">
<!-- Success message will be displayed here -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="errorModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="errorModalLabel">Error</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="errorMessage">
<!-- Error message will be displayed here -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
include("connection.php");
if (isset($_POST['submit'])) {
// to receive value from the input fields
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$role = $_POST['role'];
$status = $_POST['status'];
$q = "INSERT INTO authentication (name, email, password, role, status) VALUES ('$name', '$email', '$password', '$role', '$status')";
if (mysqli_query($conn, $q)) {
// Trigger the success modal
echo '<script>
$("#successMessage").text("Successfully Added");
$("#successModal").modal("show");
</script>';
} else {
// Trigger the error modal
echo '<script>
$("#errorMessage").text("Error: ' . mysqli_error($conn) . '");
$("#errorModal").modal("show");
</script>';
}
}
?>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<?php include_once('includes/footer.php'); ?>