-
Notifications
You must be signed in to change notification settings - Fork 0
/
manageUsers.php
280 lines (261 loc) · 11.1 KB
/
manageUsers.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
session_start();
if ($_SESSION['admin'] == false) {
header("location: index.php");
exit();
}
// Connect to the database
require "./db/db_connect.php";
// Flages to show confirmation message on CRUD operations perfomed
$update = false;
$delete = false;
if (isset($_GET['delete'])) {
// operations perfomed using the GET method to delete the note in databse
$slno = $_GET['delete'];
$sql = "DELETE FROM `users` WHERE `slno` = ?";
$stmt = mysqli_stmt_init($connection);
if (mysqli_stmt_prepare($stmt, $sql)) {
$delete = true;
}
mysqli_stmt_bind_param($stmt, "s", $slno);
mysqli_stmt_execute($stmt);
$sql = "DELETE FROM `users-login` WHERE `slno` = ?";
$stmt = mysqli_stmt_init($connection);
if (mysqli_stmt_prepare($stmt, $sql)) {
$delete = true;
}
mysqli_stmt_bind_param($stmt, "s", $slno);
mysqli_stmt_execute($stmt);
} elseif (isset($_POST['slnoEdit'])) {
// Update the record in database
$slno = $_POST['slnoEdit'];
$userName = $_POST['userName'];
$userFName = $_POST['userFName'];
$userID = $_POST['userID'];
$userRegisterNo = $_POST['userRegisterNo'];
$userNumber = $_POST['userNumber'];
$userAddress = $_POST['userAddress'];
$sql = "UPDATE `users` SET `user_name` = ?, `user_fname` = ?, `user_id` = ?, `user_reg_no` = ?, `user_number` = ?, `user_address` = ? WHERE `slno` = ?";
$stmt = mysqli_stmt_init($connection);
if (mysqli_stmt_prepare($stmt, $sql)) {
$update = true;
}
mysqli_stmt_bind_param($stmt, "sssssss", $userName, $userFName, $userID, $userRegisterNo, $userNumber, $userAddress, $slno);
mysqli_stmt_execute($stmt);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- jQuery CSS -->
<link rel="stylesheet" href="./static/css/jui">
<link rel="stylesheet" href="./static/css/dataTables.jqueryui.min.css">
<link rel="stylesheet" href="./static/css/buttons.jqueryui.min.css">
<link rel="stylesheet" href="./static/css/style.css">
<link rel="shortcut icon" href="./public/images/favicon.ico" type="image/x-icon">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
<style>
th.sorting.ui-state-default,
table.dataTable th,
table.dataTable td {
text-align: center;
}
.alert {
position: absolute;
left: 470px;
top: 67px;
}
</style>
<!-- jQuery JS -->
<script src="./static/js/jquery-3.5.1.js"></script>
<!-- jQuery datatables JS -->
<script src="./static/js/jquery.dataTables.min.js"></script>
<!-- jQuery UI JS -->
<script src="./static/js/dataTables.jqueryui.min.js"></script>
<!-- jQuery buttons JS -->
<script src="./static/js/dataTables.buttons.min.js"></script>
<script src="./static/js/buttons.jqueryui.min.js"></script>
<script src="./static/js/jszip.min.js"></script>
<script src="./static/js/pdfmake.min.js"></script>
<script src="./static/js/vfs_fonts.js"></script>
<script src="./static/js/buttons.html5.min.js"></script>
<script src="./static/js/buttons.print.min.js"></script>
<script src="./static/js/buttons.colVis.min.js"></script>
<!-- Bootstrap JS -->
<script src="./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script>
$(document).ready(function() {
var table = $('#example').DataTable({
lengthChange: false,
lengthMenu: [
[5, 10, 25, -1],
['5 rows', '10 rows', '25 rows', 'Show all']
],
buttons: [
'pageLength', 'colvis', 'copy', 'print',
{
extend: 'spacer',
style: 'bar',
text: '<b>Export files to :- </b>'
},
'excel', 'pdf', 'csv',
{
text: 'JSON',
action: function(e, dt, button, config) {
var data = dt.buttons.exportData();
$.fn.dataTable.fileSave(
new Blob([JSON.stringify(data)]),
'Export.json'
);
},
},
],
});
table.buttons().container().insertBefore('#example_filter');
});
</script>
<title>Students List</title>
</head>
<body>
<!-- Navigation bar -->
<?php require "./apps/navbar.php"; ?>
<!-- Edit & Delete Modal and its Alert -->
<!-- You can also wrap it in a div of certain height to make seperate space for the alert -->
<?php
require "./apps/editModal.php";
require "./apps/deleteModal.php";
if ($update) {
echo '
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="check-circle-fill" viewBox="0 0 16 16">
<path
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z" />
</symbol>
</svg>
<div class="alert alert-success d-flex align-items-center" role="alert" style="height: 48px; margin-bottom: 0; position: absolute; left: 38%; top:69px;">
<svg class="bi flex-shrink-0 me-2" role="img" aria-label="Success:" style="width: 18px">
<use xlink:href="#check-circle-fill" />
</svg>
<div>
Student details have been updated
</div>
</div>';
} elseif ($delete) {
echo '
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="check-circle-fill" viewBox="0 0 16 16">
<path
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z" />
</symbol>
</svg>
<div class="alert alert-danger d-flex align-items-center" role="alert" style="height: 48px; margin-bottom: 0; position: absolute; left: 38%; top:69px;">
<svg class="bi flex-shrink-0 me-2" role="img" aria-label="Success:" style="width: 18px">
<use xlink:href="#check-circle-fill" />
</svg>
<div>
Student details have been deleted
</div>
</div>';
}
?>
<h3 class="py-2 mt-5 text-center"> Students List</h3>
<div class="table-responsive" style="min-height: 85vh;">
<table id="example" class="display">
<thead>
<tr>
<th scope="col">Sl.no</th>
<th scope="col">Student Name</th>
<th scope="col">Father Name</th>
<th scope="col">Student UID</th>
<th scope="col">Reg.no</th>
<th scope="col">Mobile Number</th>
<th scope="col">Student Address</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM `users`";
$result = mysqli_query($connection, $sql);
$num = 1;
while ($fetch_rows = mysqli_fetch_assoc($result)) {
echo '
<tr>
<th scope="row">' . $num . '</th>
<td>' . $fetch_rows['user_name'] . '</td>
<td>' . $fetch_rows['user_fname'] . '</td>
<td>' . $fetch_rows['user_id'] . '</td>
<td>' . $fetch_rows['user_reg_no'] . '</td>
<td>' . $fetch_rows['user_number'] . '</td>
<td>' . $fetch_rows['user_address'] . '</td>
<td>
<div class="d-flex flex-row mb-3">
<div class="p-1 m-auto"><button id="edit' . $fetch_rows['slno'] . '" class="edit btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#editModal">   Edit  </button></div>
<div class="p-1 m-auto"><button id="delete' . $fetch_rows['slno'] . '" class="delete btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">Delete</button></div>
</div>
</td>
</tr>';
$num = $num + 1;
}
?>
</tbody>
</table>
</div>
<!-- Footer -->
<?php require "./apps/footer.php"; ?>
</body>
<script>
// To edit user info from the database
edits = document.getElementsByClassName('edit');
Array.from(edits).forEach((element) => {
element.addEventListener("click", (e) => {
console.log(e);
tr = e.target.parentNode.parentNode.parentNode.parentNode;
user_name = tr.getElementsByTagName("td")[0].innerText;
user_fname = tr.getElementsByTagName("td")[1].innerText;
user_id = tr.getElementsByTagName("td")[2].innerText;
user_reg_no = tr.getElementsByTagName("td")[3].innerText;
user_number = tr.getElementsByTagName("td")[4].innerText;
user_address = tr.getElementsByTagName("td")[5].innerText;
slnoEdit.value = e.target.id.substr(4, );
userName.value = user_name;
userFName.value = user_fname;
userID.value = user_id;
userRegisterNo.value = user_reg_no;
userNumber.value = user_number;
userAddress.value = user_address;
})
})
// To delete user info from the database
deletes = document.getElementsByClassName('delete');
Array.from(deletes).forEach((element) => {
element.addEventListener("click", (e1) => {
slno = e1.target.id.substr(6, );
document.getElementById('delBtn').onclick = function() {
window.location = `manageUsers.php?delete=${slno}`;
}
})
})
// To fix the re-submission error on reloading the webpage
if (window.history.replaceState) {
window.history.replaceState(null, null, window.location.href);
}
// To remove the GET paarmeter from the header when the request is completed
if (typeof window.history.pushState == 'function') {
window.history.pushState({}, "Hide", "http://localhost/rfid-attendance-system/manageUsers.php");
}
// To add active class to the navbar
const addClassActive = document.getElementById('manage-users-tab');
addClassActive.classList.add('active');
// To make the alert auto dismissable
$(document).ready(function() {
$(".alert").fadeTo(2500, 400).slideUp(400, function() {
$(this).alert('close');
})
})
</script>
</html>