-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit_book.php
511 lines (466 loc) · 27.3 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
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<?php
require_once 'init.php';
$pageTitle = lang('edit_book');
require_once $tmpl . 'header.php';
echo '<br><br><br><br><br>';
//check if has privilege
if (!isset($_SESSION['UserEmail'])) {
redirect_user();
}
//message
$statusMsg = "";
$msgContainer = "d-none";
// File upload path
$upload_dir = "upload/books/";
// insert and upload status code
$insert_status = -1;
$uploadImgStatus = -1;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$book_id = filter_var($_POST['book_id'], FILTER_VALIDATE_INT);
if ($book_id === false || $book_id === null) {
// Handle invalid book ID
echo "Invalid book ID";
exit;
}
// here work on img
$book_photo = "test.png";
// validate post param
$book_title = filter_var(strip_tags($_POST['book_title']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$book_sub_title = filter_var(strip_tags($_POST['book_sub_title']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$book_description = filter_var(strip_tags($_POST['book_description']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$category = filter_var(strip_tags($_POST['category']), FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
$dewyNo = filter_var(strip_tags($_POST['dewyNo']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$author_name = filter_var(strip_tags($_POST['author_name']), FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
$work_id = filter_var(strip_tags($_POST['work_on_book']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$publisher = filter_var(strip_tags($_POST['publisher']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$publish_place = filter_var(strip_tags($_POST['publish_place']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$language = filter_var(strip_tags($_POST['language']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$isbn = filter_var(strip_tags($_POST['isbn']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$depository_no = filter_var(strip_tags($_POST['depository_no']), FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE) ?? NULL;
// UPDATE_BOOK_INFO
$result = update_book(UPDATE_BOOK_INFO, [$book_title, $book_sub_title, $book_description, $depository_no, $isbn, $dewyNo, 3, $publish_place, $category, $book_id]);
$work_on_book = "";
switch ($work_id) {
case 1:
$work_on_book = lang('authoring');
break;
case 2:
$work_on_book = lang('translate');
break;
case 3:
$work_on_book = lang('checking');
break;
default:
$work_on_book = lang('reviewing');
break;
}
// UPDATE_BOOK_AUTHOR_INFO
$result2 = update_book(UPDATE_BOOK_AUTHOR_INFO, [$work_on_book, $work_id, $author_name, $book_id]);
// UPDATE_BOOK_PUBLISHER_INFO
$result3 = update_book(UPDATE_BOOK_PUBLISHER_INFO, [$publisher, $book_id]);
// UPDATE_BOOK_LANG_INFO
$result4 = update_book(UPDATE_BOOK_LANG_INFO, [$language, $book_id]);
if ($result) {
// Book updated successfully
redirect_user(lang('book_edit_success'), 5, "index.php", "info");
} else {
// Handle the update failure
$msgContainer = "alert-danger";
$statusMsg = lang("unexpected_error");
}
}
// validate get param
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if (!filter_input(INPUT_GET, 'book', FILTER_VALIDATE_INT)) {
redirect_user(lang("redirect_book_message"), 5, "index.php");
}
$book_id = filter_input(INPUT_GET, 'book', FILTER_VALIDATE_INT);
}
echo $book_id;
$row = get_data(SELECT_BOOK_UPDATE, [$book_id]);
if (count($row) > 0) {
// var_dump($row);
?>
<h1>his </h1>
<!-- edit book section -->
<div class="container rounded card shadow pb-5 mb-5" id="edit_book">
<!-- page title -->
<div class="row my-4">
<div class="col-12">
<h1 class="display-6 mx-4 text-center" id="edit_book_title">
<?= lang("edit_book") ?>
</h1>
<hr>
</div>
</div>
<!-- message that display after submit is made -->
<div class="alert <?= $msgContainer ?> alert-dismissible fade show mx-5" role="alert">
<p class='fw-bold'><?= $statusMsg ?></p>
<?php
// redirect user if add author success
if ($msgContainer == "alert-success") {
echo ('<p class="fs-6">' . lang('redirect_after') . '<span id="second"></span>' . lang('second') . '</p>');
echo ("
<script>
var second = 5;
$('#second').text(second);
var redirectTime = setInterval(myTimer, 1000, 'index.php');
</script>
");
}
?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<form name="add_book" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data">
<input class="form-control" type="hidden" id="book_id" name="book_id" value="<?php echo $row['book_id'] ?>" />
<div class="row px-5">
<!-- book photo -->
<div class="text-center mt-3 mb-5">
<label for="book_photo" class="profile-upload">
<div class="profile-container">
<img src="upload/books/<?= $row['photo'] ?>" alt="author image" id="profile_img">
</div>
<div class="camera-icon d-flex align-items-center justify-content-center">
<i class="fa-solid fa-camera-circle"></i>
</div>
</label>
<input type="file" name="book_photo" id="book_photo" hidden accept="image/png, image/jpeg">
<div class="invalid-feedback"></div>
</div>
<hr>
<!-- book title and subtitle -->
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="book_title" class="blue-text mb-2 me-4"><?= lang('book_title'); ?></label>
<input value="<?php echo $row['title'] ?>" required class="form-control" type="text" id="book_title" name="book_title" onkeyup="checkField('book_title', '#book_title', '#check_book_title')" placeholder="<?php echo lang('book_title_place') ?>" autofocus />
<span class="invalid-feedback" id="check_book_title"></span>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="book_sub_title" class="blue-text mb-2 me-4"><?= lang('book_sub_title'); ?></label>
<input value="<?php echo $row['subtitle'] . 'lll' ?>" class="form-control" type="text" id="book_sub_title" name="book_sub_title" placeholder="<?php echo lang('book_sub_title_place') ?>" autocomplete="off" required />
</div>
</div>
</div>
<!-- description -->
<div class="row">
<div class="mt-3 text-end">
<label for="book_description" class="blue-text mb-2 me-4"><?= lang('book_description'); ?></label>
<textarea class="form-control" id="book_description" name="book_description" rows="3" placeholder="<?php echo lang('book_description_place') ?>" autocomplete="off" required><?php echo $row['description']; ?></textarea>
</div>
</div>
<!-- book_category and dewy number -->
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="category" class="blue-text mb-2 me-4"><?= lang('category'); ?></label>
<select class="form-control" id="category" name="category" required>
<option value="" disabled><?= lang('select_category'); ?></option>
<?php
$cats = get_all_data("select * from categories");
foreach ($cats as $cat) {
echo '<option value="' . $cat['cat_id'] . '"';
if ($row['cat_id'] == $cat['cat_id']) {
echo 'selected';
}
echo '>' . $cat['cat_name'] . '</option>';
}
?>
</select>
<div class="invalid-feedback"></div>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="dewyNo" class="blue-text mb-2 me-4"><?= lang('dewyNo'); ?></label>
<input value="<?php echo $row['dewey_no'] ?>" class="form-control" type="number" id="dewyNo" name="dewyNo" placeholder="<?php echo lang('dewy_no_place') ?> " autocomplete="off" required />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<!-- author_name and work_on_book -->
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="author_name" class="blue-text mb-2 me-4"><?= lang('author_name'); ?></label>
<select class="form-control" id="author_name" name="author_name" required>
<option value="" disabled selected><?= lang('select_author_name'); ?></option>
<?php
$authors = get_all_data("select * from author");
foreach ($authors as $author) {
echo '<option value="' . $author['author_id'] . '"';
if ($row['author_id'] == $author['author_id']) {
echo 'selected';
}
echo '>' . $author['author_name'] . '</option>';
}
?>
</select>
<div class="invalid-feedback"></div>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="work_on_book" class="blue-text mb-2 me-4"><?= lang('work_on_book'); ?></label>
<select class="form-control" id="work_on_book" name="work_on_book" required>
<option value="" disabled selected><?= lang('select_work_on_book'); ?></option>
<option value="1" <?php echo ($row['work_id'] == 1) ? 'selected' : '' ?>> <?= lang('authoring'); ?></option>
<option value="2" <?php echo ($row['work_id'] == 2) ? 'selected' : '' ?>><?= lang('translate'); ?></option>
<option value="3" <?php echo ($row['work_id'] == 3) ? 'selected' : '' ?>><?= lang('checking'); ?></option>
<option value="4" <?php echo ($row['work_id'] == 4) ? 'selected' : '' ?>><?= lang('reviewing'); ?></option>
</select>
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<!-- publisher and publish_place -->
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="publisher" class="blue-text mb-2 me-4"><?= lang('publisher'); ?></label>
<select class="form-control" id="publisher" name="publisher" required>
<option value="" disabled selected><?= lang('select_publisher'); ?></option>
<?php
$publishers = get_all_data("select * from publisher");
foreach ($publishers as $pub) {
echo '<option value="' . $pub['pub_id'] . '"';
if ($row['pub_id'] == $pub['pub_id']) {
echo 'selected';
}
echo '>' . $pub['pub_name'] . '</option>';
}
?>
</select>
<div class="invalid-feedback"></div>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="publish_place" class="blue-text mb-2 me-4"><?= lang('publish_place'); ?></label>
<input value="<?php echo $row['publication_place'] ?>" class="form-control" type="text" id="publish_place" name="publish_place" placeholder="<?= lang('publish_placeholder'); ?>" autocomplete="off" required />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<!-- language and book_location -->
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="language" class="blue-text mb-2 me-4"><?= lang('language'); ?></label>
<select class="form-control" name="language" required>
<option value="" disabled selected><?= lang('select_pub_lang'); ?></option>
<?php
$langs = get_all_data(SELECT_LANG);
foreach ($langs as $lang) {
echo '<option value="' . $lang['lang_id'] . '"';
if ($row['lang_id'] == $lang['lang_id']) {
echo 'selected';
}
echo '>' . $lang['lang_name'] . '</option>';
}
?>
</select>
<div class="invalid-feedback"></div>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="book_location" class="blue-text mb-2 me-4"><?= lang('book_location'); ?></label>
<input class="form-control" type="text" id="book_location" name="book_location" placeholder="<?php echo lang('book_location_place') ?>" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<!-- isbn and depository_no -->
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="isbn" class="blue-text mb-2 me-4"><?= lang('isbn'); ?></label>
<input value="<?php echo $row['isbn'] ?>" class="form-control" type="text" id="isbn" name="isbn" placeholder="<?php echo lang('isbn_place') ?>" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="depository_no" class="blue-text mb-2 me-4"><?= lang('depository_no'); ?></label>
<input value="<?php echo $row['depository_no'] ?>" class="form-control" type="text" id="depository_no" name="depository_no" placeholder="<?php echo lang('depository_no_place') ?>" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<!-- Radio button for part or multi part -->
<!-- <div class="chose-how-part mt-4">
<span class="dark-blue-text">
<?php echo lang('is_book') ?>
</span>
<div class="form-check form-check-inline">
<label class="form-check-label blue-text" for="one_part">
<?php echo lang('one_part') ?>
</label>
<input class="form-check-input" type="radio" name="chose_part" id="one_part" value="one" checked>
</div>
<div class="form-check form-check-inline">
<label class="form-check-label blue-text" for="multi_parts">
<?php echo lang('multi_parts') ?>
</label>
<input class="form-check-input" type="radio" name="chose_part" value="multi" id="multi_parts">
</div>
</div> -->
<!-- one-part-container -->
<!-- <div class="one-part-container">
<input class="form-control" type="hidden" id="part_number" name="part_number[]" value="1" />
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="edition_no" class="blue-text mb-2 me-4"><?= lang('edition_no'); ?></label>
<input class="form-control" type="number" id="edition_no" name="edition_no[]" placeholder="1" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="edition_desc" class="blue-text mb-2 me-4"><?= lang('edition_desc'); ?></label>
<input class="form-control" type="text" id="edition_desc" name="edition_desc[]" placeholder="<?php echo lang('edition_desc_place') ?>" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="publish_date" class="blue-text mb-2 me-4"><?= lang('publish_date'); ?></label>
<input class="form-control" type="month" id="publish_date[]" name="publish_date[]" />
<div class="invalid-feedback"></div>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="pages_no" class="blue-text mb-2 me-4"><?= lang('pages_no'); ?></label>
<input class="form-control" type="number" id="pages_no" name="pages_no[]" placeholder="512" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="price" class="blue-text mb-2 me-4"><?= lang('price'); ?></label>
<input class="form-control" type="number" id="price" name="price[]" placeholder="20 $" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="no_of_copy" class="blue-text mb-2 me-4"><?= lang('no_of_copy'); ?></label>
<input class="form-control" type="number" id="no_of_copy" name="no_of_copy[]" placeholder="20" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
</div> -->
<!-- multi-part-container -->
<!-- <div class="multi-part-container">
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="part_no" class="blue-text mb-2 me-4"><?= lang('part_no'); ?></label>
<input class="form-control" type="number" id="part_no" name="part_no" placeholder="3" onkeyup="howParts()" />
<div class="invalid-feedback" id="no_part_check"></div>
</div>
</div>
</div>
<div id="more_part">
</div>
</div> -->
<!-- series details -->
<!-- <div class="row">
<div class="col-md-6">
<div class="mt-3 mb-2 text-end">
<div class="form-group">
<input class="form-check-input" type="checkbox" id="checkbox_has_series" name="checkbox_has_series" />
<label for="checkbox_has_series" class="dark-blue-text"><?= lang('is_book_has_series'); ?></label>
<div class="invalid-feedback"></div>
</div>
</div>
</div>
</div>
<div class="series-group">
<div class="row series_group">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="series_name" class="blue-text mb-2 me-4"><?= lang('series_name'); ?></label>
<input type="text" autocomplete="off" list="series_auto_complete" class="form-control mb-3" id="series_name" name="series_name" placeholder="<?php echo lang('series_name_place') ?>">
<datalist id="series_auto_complete">
<?php
$rows = get_all_data("SELECT * FROM series");
if ($rows != 0) {
foreach ($rows as $row) {
echo ' <option value="' . $row['series_name'] . '"></option>';
}
}
?>
</datalist>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="no_in_series" class="blue-text mb-2 me-4"><?= lang('no_in_series'); ?></label>
<input class="form-control" type="number" id="no_in_series" name="no_in_series" placeholder="4" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
</div> -->
<!-- attachment details -->
<!-- <div class="row">
<div class="col-md-6">
<div class="mt-3 mb-3 text-end">
<div class="form-group">
<input class="form-check-input" type="checkbox" id="checkbox_has_attachment" name="checkbox_has_attachment" />
<label for="checkbox_has_attachment" class="dark-blue-text"><?= lang('is_book_has_attachment'); ?></label>
<div class="invalid-feedback"></div>
</div>
</div>
</div>
</div> -->
<!-- <div class="attachment-group">
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="attachment_name" class="blue-text mb-2 me-4"><?= lang('attachment_name'); ?></label>
<input class="form-control" type="text" id="attachment_name" name="attachment_name" placeholder="<?php echo lang('attachment_name_place') ?>" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="attachment_type" class="blue-text mb-2 me-4"><?= lang('attachment_type'); ?></label>
<input class="form-control" type="text" id="attachment_type" name="attachment_type" placeholder="<?php echo lang('attachment_type_place') ?>" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mt-3 text-end">
<label for="attachment_loc" class="blue-text mb-2 me-4"><?= lang('attachment_loc'); ?></label>
<input class="form-control" type="text" id="attachment_loc" name="attachment_loc" placeholder="<?php echo lang('attachment_loc_place') ?>" autocomplete="off" />
<div class="invalid-feedback"></div>
</div>
</div>
</div>
</div> -->
<!-- buttons -->
<div class="modal-footer mt-4 mb-2 justify-content-evenly">
<button class="btn blue-btn add rounded-3 fw-bold" type="submit" id="submit"><?php echo lang('update') ?></button>
<button class="btn blue-btn cancel me-auto rounded-3 fw-bold" type="button" onclick="window.location.href='index.php'"><?php echo lang('cancel') ?></button>
</div>
</div>
</form>
</div>
<?php
}
include $tmpl . 'footer.php';
?>