-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
290 lines (260 loc) · 7.46 KB
/
admin.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
<?php
session_start();
# If the admin is logged in
if (isset($_SESSION['user_id']) &&
isset($_SESSION['user_email'])) {
# Database Connection File
include "db_conn.php";
# Book helper function
include "php/func-book.php";
$books = get_all_books($conn);
# author helper function
include "php/func-author.php";
$authors = get_all_author($conn);
# Category helper function
include "php/func-category.php";
$categories = get_all_categories($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ADMIN</title>
<!-- bootstrap 5 CDN-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<!-- bootstrap 5 Js bundle CDN-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="admin.php">Admin</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse"
id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link"
aria-current="page"
href="index.php">Store</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="add-book.php">Add Book</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="add-category.php">Add Category</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="add-author.php">Add Author</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<form action="search.php"
method="get"
style="width: 100%; max-width: 30rem">
<div class="input-group my-5">
<input type="text"
class="form-control"
name="key"
placeholder="Search Book..."
aria-label="Search Book..."
aria-describedby="basic-addon2">
<button class="input-group-text
btn btn-primary"
id="basic-addon2">
<img src="img/search.png"
width="20">
</button>
</div>
</form>
<div class="mt-5"></div>
<?php if (isset($_GET['error'])) { ?>
<div class="alert alert-danger" role="alert">
<?=htmlspecialchars($_GET['error']); ?>
</div>
<?php } ?>
<?php if (isset($_GET['success'])) { ?>
<div class="alert alert-success" role="alert">
<?=htmlspecialchars($_GET['success']); ?>
</div>
<?php } ?>
<?php if ($books == 0) { ?>
<div class="alert alert-warning
text-center p-5"
role="alert">
<img src="img/empty.jpg"
width="100">
<br>
There is no book in the database
</div>
<?php }else {?>
<!-- List of all books -->
<h4>All Books</h4>
<table class="table table-bordered shadow">
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Author</th>
<th>Description</th>
<th>Category</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ($books as $book) {
$i++;
?>
<tr>
<td><?=$i?></td>
<td>
<img width="100"
src="uploads/cover/<?=$book['cover']?>" >
<a class="link-dark d-block
text-center"
href="uploads/files/<?=$book['file']?>">
<?=$book['title']?>
</a>
</td>
<td>
<?php if ($authors == 0) {
echo "Undefined";}else{
foreach ($authors as $author) {
if ($author['id'] == $book['author_id']) {
echo $author['name'];
}
}
}
?>
</td>
<td><?=$book['description']?></td>
<td>
<?php if ($categories == 0) {
echo "Undefined";}else{
foreach ($categories as $category) {
if ($category['id'] == $book['category_id']) {
echo $category['name'];
}
}
}
?>
</td>
<td>
<a href="edit-book.php?id=<?=$book['id']?>"
class="btn btn-warning">
Edit</a>
<a href="php/delete-book.php?id=<?=$book['id']?>"
class="btn btn-danger">
Delete</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php }?>
<?php if ($categories == 0) { ?>
<div class="alert alert-warning
text-center p-5"
role="alert">
<img src="img/empty.jpg"
width="100">
<br>
There is no category in the database
</div>
<?php }else {?>
<!-- List of all categories -->
<h4 class="mt-5">All Categories</h4>
<table class="table table-bordered shadow">
<thead>
<tr>
<th>#</th>
<th>Category Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$j = 0;
foreach ($categories as $category ) {
$j++;
?>
<tr>
<td><?=$j?></td>
<td><?=$category['name']?></td>
<td>
<a href="edit-category.php?id=<?=$category['id']?>"
class="btn btn-warning">
Edit</a>
<a href="php/delete-category.php?id=<?=$category['id']?>"
class="btn btn-danger">
Delete</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<?php if ($authors == 0) { ?>
<div class="alert alert-warning
text-center p-5"
role="alert">
<img src="img/empty.jpg"
width="100">
<br>
There is no author in the database
</div>
<?php }else {?>
<!-- List of all Authors -->
<h4 class="mt-5">All Authors</h4>
<table class="table table-bordered shadow">
<thead>
<tr>
<th>#</th>
<th>Author Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$k = 0;
foreach ($authors as $author ) {
$k++;
?>
<tr>
<td><?=$k?></td>
<td><?=$author['name']?></td>
<td>
<a href="edit-author.php?id=<?=$author['id']?>"
class="btn btn-warning">
Edit</a>
<a href="php/delete-author.php?id=<?=$author['id']?>"
class="btn btn-danger">
Delete</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
</dev>
</body>
</html>
<?php }else{
header("Location: login.php");
exit;
} ?>