-
Notifications
You must be signed in to change notification settings - Fork 0
/
author.php
183 lines (162 loc) · 5.38 KB
/
author.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
<?php
session_start();
# If not author ID is set
if (!isset($_GET['id'])) {
header("Location: index.php");
exit;
}
# Get author ID from GET request
$id = $_GET['id'];
# Database Connection File
include "db_conn.php";
# Book helper function
include "php/func-book.php";
$books = get_books_by_author($conn, $id);
# author helper function
include "php/func-author.php";
$authors = get_all_author($conn);
$current_author = get_author($conn, $id);
# 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><?=$current_author['name']?></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>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="index.php">Online Book Store</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 active"
aria-current="page"
href="index.php">Store</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="#">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="#">About</a>
</li>
<li class="nav-item">
<?php if (isset($_SESSION['user_id'])) {?>
<a class="nav-link"
href="admin.php">Admin</a>
<?php }else{ ?>
<a class="nav-link"
href="login.php">Login</a>
<?php } ?>
</li>
</ul>
</div>
</div>
</nav>
<h1 class="display-4 p-3 fs-3">
<a href="index.php"
class="nd">
<img src="img/back-arrow.PNG"
width="35">
</a>
<?=$current_author['name']?>
</h1>
<div class="d-flex pt-3">
<?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{ ?>
<div class="pdf-list d-flex flex-wrap">
<?php foreach ($books as $book) { ?>
<div class="card m-1">
<img src="uploads/cover/<?=$book['cover']?>"
class="card-img-top">
<div class="card-body">
<h5 class="card-title">
<?=$book['title']?>
</h5>
<p class="card-text">
<i><b>By:
<?php foreach($authors as $author){
if ($author['id'] == $book['author_id']) {
echo $author['name'];
break;
}
?>
<?php } ?>
<br></b></i>
<?=$book['description']?>
<br><i><b>Category:
<?php foreach($categories as $category){
if ($category['id'] == $book['category_id']) {
echo $category['name'];
break;
}
?>
<?php } ?>
<br></b></i>
</p>
<a href="uploads/files/<?=$book['file']?>"
class="btn btn-success">Open</a>
<a href="uploads/files/<?=$book['file']?>"
class="btn btn-primary"
download="<?=$book['title']?>">Download</a>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
<div class="category">
<!-- List of categories -->
<div class="list-group">
<?php if ($categories == 0){
// do nothing
}else{ ?>
<a href="#"
class="list-group-item list-group-item-action active">Category</a>
<?php foreach ($categories as $category ) {?>
<a href="category.php?id=<?=$category['id']?>"
class="list-group-item list-group-item-action">
<?=$category['name']?></a>
<?php } } ?>
</div>
<!-- List of authors -->
<div class="list-group mt-5">
<?php if ($authors == 0){
// do nothing
}else{ ?>
<a href="#"
class="list-group-item list-group-item-action active">Author</a>
<?php foreach ($authors as $author ) {?>
<a href="author.php?id=<?=$author['id']?>"
class="list-group-item list-group-item-action">
<?=$author['name']?></a>
<?php } } ?>
</div>
</div>
</div>
</div>
</body>
</html>