-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTable_accountNo.php
336 lines (313 loc) · 15.6 KB
/
Table_accountNo.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<?php
session_start(); // Make sure to start the session
include('DBconnect.php');
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$librarianID = $_SESSION['user_id'];
$row = mysqli_fetch_assoc(mysqli_query($connect, "Select * from librarians where librarian_id = '$librarianID'"));
?>
<!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">
<title>Account No</title>
<link rel="stylesheet" href="BOOTSTRAP/css/bootstrap.min.css">
<link rel="stylesheet" href="Font/css/all.css">
<link rel="stylesheet" href="Font/css/all.min.css">
<link href='boxicons/css/boxicons.min.css' rel='stylesheet'>
<script src="js/bootstrap.min.js"></script>
<script src="JS/popper.min.js"></script>
<link rel="stylesheet" href="Design/datatables.css">
<script src="DataTables/jquery.min.js"></script>
<script src="package/dist/sweetalert2.min.js"></script>
<link rel="stylesheet" href="package/dist/sweetalert2.min.css">
<link rel="stylesheet" type="text/css" href="DataTables/dataTables.bootrap5.min.css">
<!-- Add the DataTables plugin script and its dependencies -->
<script defer src="DataTables/jquery.dataTables.min.js"></script>
<script defer src="DataTables/dataTables.bootstrap5.min.js"></script>
<link rel="stylesheet" href="Design/datatables.css">
<link rel="stylesheet" href="Design/side.css">
</head>
<body>
<?php include "sidebar.php" ?>
<section class="home-section">
<div class="home-content header">
<i class='bx bx-menu'></i>
<span class="text text-white m-0">LIBRARY MANAGEMENT SYSTEM</span>
</div>
<hr class=" text-white">
<div class="col-md-9 col-lg-11 bg-light mt-3 rounded-start-4 bg-transparent" class="container-fuid px-4" role="main" id="main-content" style=" margin:auto; overflow:auto;">
<main>
<div class="card border-0 bg-transparent text-white rounded-1 mt-lg-5 rounded-4 p-4">
<div class="card-header bg-transparent py-4">
<h2 class="mb-5 d-grid row card-title px-4">Accounts Table</h2>
<form id="addAccountForm" method="POST" class="align-items-center d-flex w-100 justify-content-between gap-1">
<div class="col-auto flex-fill">
<label for="accountNo" class="visually-hidden">Account Number:</label>
<input type="text" class="form-control" id="accountNo" placeholder="Enter Account number" name="accountNo" required>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-success"><i class="fa fa-3 fa-add"></i></button>
</div>
</form>
<div id="message"></div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover text-center bg-white" id="accountsTable">
<thead class="table-success">
<tr>
<th scope="col">ID</th>
<th scope="col" class="col-10">Account Number</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody class="table-light border-success">
<?php
include 'DBconnect.php';
$result = mysqli_query($connect, "SELECT * FROM accounts");
while ($row = mysqli_fetch_array($result)) {
if ($row['account_no'] != null) {
?>
<tr>
<td><?php echo $row['account_id'] ?></td>
<td><?php echo $row['account_no'] ?></td>
<td>
<button type="button" class="btn btn-sm btn-dark update-account" data-Eaccount-id="<?php echo $row['account_id'] ?>" data-Eaccount-no="<?php echo $row['account_no'] ?>" data-bs-toggle="modal" data-bs-target="#update-account-modal">
Edit
</button>
<button type="button" class="btn btn-sm btn-danger delete-account" data-account-id="<?php echo $row['account_id'] ?>" data-bs-toggle="modal" data-bs-target="#delete-account-modal">
Delete
</button>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</main>
</div>
</section>
<!-- Update Account Modal -->
<div class="modal fade" id="update-account-modal" tabindex="-1" aria-labelledby="update-account-modal-label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content modal-md text-white" style="background-color: #333;">
<div class="modal-header">
<h5 class="modal-title" id="update-account-modal-label">Edit Account</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="account-no-input">Account Number</label>
<input type="text" class="form-control" id="account-no-input" style="background-color: #555; color: #fff;">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn bg-dark text-white" id="update-account-btn">Update</button>
</div>
</div>
</div>
</div>
<!-- Delete account modal -->
<div class="modal fade" id="delete-account-modal" tabindex="-1" aria-labelledby="delete-account-modal-label" aria-hidden="true">
<div class="modal-dialog modal-md modal-dialog-centered">
<div class="modal-content bg-dark text-white">
<div class="modal-header border-0">
<h5 class="modal-title text-white" id="delete-account-modal-label">Confirm Delete</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p class="text-center mb-0">Are you sure you want to delete this account?</p>
</div>
<div class="modal-footer border-0">
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">No</button>
<button type="button" class="btn btn-danger btn-sm confirm-delete" id="confirm-delete-btn" data-account-id="<?php echo $row['account_id'] ?>">Yes</button>
</div>
</div>
</div>
</div>
<!-- Initialize the DataTables plugin -->
<script>
$(document).ready(function() {
$('#accountsTable').DataTable({
"searching": true,
"lengthChange": false,
"pageLength": 5,
"language": {
"search": "Search:",
"zeroRecords": "No matching records found",
"info": "Showing _START_ to _END_ of _TOTAL_ entries",
"infoEmpty": "Showing 0 to 0 of 0 entries",
"infoFiltered": "(filtered from _MAX_ total entries)"
}
});
$(document).on('click', '.delete-account', function() {
var accountId = $(this).data('account-id');
//alert(accountId);
$('#delete-account-modal').modal('show');
// Send accountId to the modal
$('#delete-account-modal').data('account-id', accountId);
});
// Handle confirm delete button click event
$('#confirm-delete-btn').click(function() {
// Get accountId from the modal
var accountId = $('#delete-account-modal').data('account-id');
Swal.fire({
title: 'Loading...',
background: '#232323',
color: 'white',
allowOutsideClick: false,
allowEscapeKey: false,
showConfirmButton: false,
onBeforeOpen: () => {
Swal.showLoading();
}
});
$.ajax({
url: 'Delete_account.php',
type: 'POST',
data: {
account_id: accountId
},
success: function(response) {
Swal.close();
Swal.fire({
icon: 'success',
title: 'Success',
text: 'Account Number Deleted Successfully',
background: '#232323',
color: 'white',
showConfirmButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: 'OK',
}).then((result) => {
if (result.isConfirmed) {
location.reload(); // Refresh the page
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
// Hide the modal
$('#delete-account-modal').modal('hide');
});
// Handle click event on the Edit button
$(document).on('click', '.update-account', function() {
// Get account ID and number from the button's data attributes
var accountId = $(this).data('eaccount-id');
var accountNo = $(this).data('eaccount-no');
// Set the account number in the modal input field
$('#account-no-input').val(accountNo);
// Update button click event
$('#update-account-btn').on('click', function() {
// Get the updated account number from the input field
var updatedAccountNo = $('#account-no-input').val();
Swal.fire({
title: 'Loading...',
background: '#232323',
color: 'white',
allowOutsideClick: false,
allowEscapeKey: false,
showConfirmButton: false,
onBeforeOpen: () => {
Swal.showLoading();
}
});
// Send AJAX request to update_account.php
$.ajax({
url: 'edit_account.php',
type: 'POST',
data: {
account_id: accountId,
account_no: updatedAccountNo
},
success: function(response) {
swal.close();
if (response == "success") {
Swal.fire({
icon: 'success',
title: 'Success',
text: 'Account Number Successfully Edited',
background: '#232323',
color: 'white',
showConfirmButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: 'OK',
}).then((result) => {
if (result.isConfirmed) {
location.reload(); // Refresh the page
}
});
} else alert(response);
},
error: function(jqXHR, textStatus, errorThrown) {
// Handle error response
console.log(textStatus, errorThrown);
}
});
// Hide the modal
//$('#update-account-modal').modal('hide');
});
});
$("#addAccountForm").submit(function(e) {
e.preventDefault();
Swal.fire({
title: 'Loading...',
background: '#232323',
color: 'white',
allowOutsideClick: false,
allowEscapeKey: false,
showConfirmButton: false,
onBeforeOpen: () => {
Swal.showLoading();
}
});
$.ajax({
url: "Process_AddAccounNo.php", // PHP script to handle form data
type: "POST",
data: $(this).serialize(), // serialize form data
success: function(response) {
swal.close();
if (response == "success") {
Swal.fire({
icon: 'success',
title: 'Success',
text: 'Account Number Successfully Added',
background: '#232323',
color: 'white',
showConfirmButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: 'OK',
}).then((result) => {
if (result.isConfirmed) {
location.reload(); // Refresh the page
}
});
}
}
});
});
});
</script>
<script src="js/side.js"></script>
<script>
$(document).ready(function() {
$(".acc").addClass('active');
$(".book-li").addClass('nav-link');
}); // Get the menu parent element
</script>
<script src="DataTables/jquery-3.6.0.min.js"></script>
</body>
</html>