-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit-book.php
141 lines (127 loc) · 5.91 KB
/
edit-book.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
<?php
session_start();
if (
isset($_SESSION['admin_id'])
&& isset($_SESSION['admin_email'])
) {
# database connectivity function
include 'php/getDBConnection.php';
# if category id is not set
if (!isset($_GET['id'])) {
header("Location: ../admin.php");
exit;
}
$book_id = $_GET['id'];
#authors helper function
include 'php/func_books.php';
$book = get_book($conn, $book_id);
#authors helper function
include 'php/func_author.php';
$authors = getAllAuthor($conn);
#categories helper function
include 'php/func_category.php';
$categories = getAllCategories($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>E-Library - Edit Book</title>
<!-- bootstrap CDN links -->
<?php
include 'template/bootstraplinks.html';
?>
<!-- favicon link -->
<link rel="icon" href="images/book.png" type="image/png">
</head>
<body>
<?php
include 'template/admin-navbar.html';
?>
<div class="container" style="width: 50%; max-width: 50rem; margin: 0px auto;">
<form action="php/editBook.php" method="POST" class="shadow p-4 rounded mt-5" enctype="multipart/form-data">
<h4 class="text-center pb-5 display-4 fs-3">Edit Book</h4>
<!-- display error message -->
<?php if (isset($_GET['error'])) { ?>
<div class="alert alert-danger text-center" role="alert">
<?= htmlspecialchars($_GET['error']); ?>
</div>
<?php } ?>
<!-- display success message -->
<?php if (isset($_GET['success'])) { ?>
<div class="alert alert-success" role="alert">
<?= htmlspecialchars($_GET['success']); ?>
</div>
<?php } ?>
<div class="mb-3">
<input hidden type="text" class="form-control" id="exampleInputText" name="book_id"
value="<?= $book['id'] ?>">
<label for="exampleInputEmail1" class="form-label">Book Title</label>
<input type="text" class="form-control" id="exampleInputText" name="book_title"
value="<?= $book['title'] ?>">
</div>
<div class="mb-3">
<label for="exampleInputSelect" class="form-label">Book Author</label>
<select class="form-select" name="book_author">
<option value="0" selected>Select Author</option>
<?php
if ($authors == 0) {
# Do nothing
} else {
foreach ($authors as $author) {
if ($book['author_id'] == $author['id']) { ?>
<option selected value="<?= $book['author_id'] ?>"><?= $author['name'] ?></option>
<?php } else { ?>
<option value="<?= $author['id'] ?>"><?= $author['name'] ?></option>
<?php }
}
} ?>
</select>
</div>
<div class="mb-3">
<Label class="form-label" for="floatingTextarea">Book Description</Label>
<input type="text" class="form-control" name="book_desc" value="<?= $book['description'] ?>"></input>
</div>
<div class="mb-3">
<label for="exampleInputSelect" class="form-label">Book Category</label>
<select class="form-select" name="book_category" aria-label="Default select example">
<option value="0" selected>Select Category</option>
<?php
if ($categories == 0) {
# Do nothing
} else {
foreach ($categories as $category) {
if ($book['category_id'] == $category['id']) { ?>
?>
<option selected value="<?= $book['category_id'] ?>"><?= $category['name'] ?></option>
<?php } else { ?>
<option value="<?= $category['id'] ?>"><?= $category['name'] ?></option>
<?php }
}
} ?>
</select>
</div>
<div class="mb-3">
<input hidden class="form-control" type="text" id="formFile" name="current_cover"
value="<?= $book['cover'] ?>">
<label for="formFile" class="form-label">Book Cover</label>
<input class="form-control" type="file" id="formFile" name="book_cover">
<a href="uploads/cover/<?= $book['cover'] ?>" class="link-dark" target="_blank">Current Cover</a>
</div>
<div class="mb-3">
<input hidden class="form-control" type="text" id="formFile" name="current_file"
value="<?= $book['filename'] ?>">
<label for="formFile" class="form-label">File</label>
<input class="form-control" type="file" id="formFile" name="book_file">
<a href="uploads/files/<?= $book['filename'] ?>" class="link-dark" target="_blank">Current file</a>
</div>
<button type="submit" class="btn btn-primary">Edit Book</button>
</form>
</div>
</body>
</html>
<?php
} else {
header("Location: index.php");
} ?>