-
Notifications
You must be signed in to change notification settings - Fork 0
/
Table_categories.php
333 lines (313 loc) · 15.8 KB
/
Table_categories.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
<?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>Categories</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">Category Table</h2>
<h4>Add Categories here: </h4>
<form id="addCategoryForm" method="POST" class="align-items-center d-flex w-100 justify-content-between gap-3">
<div class="col-auto flex-fill">
<label for="categoryName" class="visually-hidden">Category Name:</label>
<input type="text" class="form-control flex-fill" id="categoryName" placeholder="Enter Categories" name="categoryName" 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 text-center table-hover bg-white" id="categoryTable">
<thead class="border-black table-success">
<tr>
<th scope="col">ID</th>
<th scope="col" class="col-10">Category</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody class="table-light border-success">
<?php
include 'DBconnect.php';
$result = mysqli_query($connect, "SELECT * FROM category");
while ($row = mysqli_fetch_array($result)) {
if ($row['category_name'] != null) {
?>
<tr>
<td class="category-row" data-category-id="<?php echo $row['category_id'] ?>"><?php echo $row['category_id'] ?></td>
<td class="category-row" data-category-id="<?php echo $row['category_id'] ?>"><?php echo $row['category_name'] ?></td>
<td>
<button type="button" class="btn btn-sm btn-dark update-category" data-Ecategory-id="<?php echo $row['category_id'] ?>" data-Ecategory-no="<?php echo $row['category_name'] ?>" data-bs-toggle="modal" data-bs-target="#update-category-modal">
Edit
</button>
<button type="button" class="btn btn-sm btn-danger delete-category" data-category-id="<?php echo $row['category_id'] ?>" data-bs-toggle="modal" data-bs-target="#delete-category-modal">
Delete
</button>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</main>
</div>
</section>
<div class="modal fade" id="delete-category-modal" tabindex="-1" aria-labelledby="delete-category-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-category-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 category?</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-category-id="<?php echo $row['category_id'] ?>">Yes</button>
</div>
</div>
</div>
</div>
<!-- Update category Modal -->
<div class="modal fade" id="update-category-modal" tabindex="-1" aria-labelledby="update-category-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-category-modal-label">Edit category</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="category-no-input">category Number</label>
<input type="text" class="form-control" id="category-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-category-btn">Update</button>
</div>
</div>
</div>
</div>
<!-- Initialize the DataTables plugin -->
<script>
var categoryRows = document.querySelectorAll('.category-row');
categoryRows.forEach(function(row) {
row.addEventListener('click', function() {
var categoryId = row.getAttribute('data-category-id');
window.location.href = 'Table_books.php?categoryId=' + categoryId;
});
});
$(document).ready(function() {
$('#categoryTable').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-category', function() {
var categoryId = $(this).data('category-id');
//alert(categoryId);
$('#delete-category-modal').modal('show');
// Send categoryId to the modal
$('#delete-category-modal').data('category-id', categoryId);
});
// Handle confirm delete button click event
$('#confirm-delete-btn').click(function() {
// Get categoryId from the modal
var categoryId = $('#delete-category-modal').data('category-id');
Swal.fire({
title: 'Loading...',
background: '#232323',
color: 'white',
allowOutsideClick: false,
allowEscapeKey: false,
showConfirmButton: false,
onBeforeOpen: () => {
Swal.showLoading();
}
});
//alert(categoryId);
// Send AJAX request to delete_category.php with categoryId
$.ajax({
url: 'Delete_category.php',
type: 'POST',
data: {
category_id: categoryId
},
success: function(response) {
$('#delete-category-modal').hide();
Swal.close();
Swal.fire({
icon: 'success',
title: 'Success',
text: 'Category 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);
}
});
});
$("#addCategoryForm").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_AddCategory.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: 'Category Successfully Added',
background: '#232323',
color: 'white',
showConfirmButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: 'OK',
}).then((result) => {
if (result.isConfirmed) {
location.reload(); // Refresh the page
}
});
}
}
});
});
$(document).on('click', '.update-category', function() {
var categoryId = $(this).data('ecategory-id');
var categoryNo = $(this).data('ecategory-no');
$('#category-no-input').val(categoryNo);
$('#update-category-btn').on('click', function() {
var updatedcategoryNo = $('#category-no-input').val();
Swal.fire({
title: 'Loading...',
background: '#232323',
color: 'white',
allowOutsideClick: false,
allowEscapeKey: false,
showConfirmButton: false,
onBeforeOpen: () => {
Swal.showLoading();
}
});
$.ajax({
url: 'Edit_category.php',
type: 'POST',
data: {
category_id: categoryId,
category_no: updatedcategoryNo
},
success: function(response) {
swal.close();
if (response == "category updated successfully") {
Swal.fire({
icon: 'success',
title: 'Success',
text: 'Category Successfully updated',
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);
}
});
});
});
});
</script>
<script src="js/side.js"></script>
<script>
$(document).ready(function() {
$(".cat").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>