-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthor_delete.php
More file actions
74 lines (60 loc) · 2.34 KB
/
Copy pathauthor_delete.php
File metadata and controls
74 lines (60 loc) · 2.34 KB
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
<?php
require_once 'include/user.php';
require 'librarian_required.php';
$authorID = $_GET['authorID'];
$query = $db->prepare(
'SELECT library_authors.author_id AS authorID, library_authors.name AS authorName
FROM library_authors
WHERE author_id = '.$authorID.'');
$query->execute();
$author = $query->fetch();
$BooksQuery = $db->prepare(
'SELECT books.name AS bookName, author_id as authorID
FROM books
WHERE author_id = '.$authorID.'');
$BooksQuery->execute();
$hasBook = $BooksQuery->fetch();
if(empty($author)){
echo '<div class="alert alert-info">Nebyly nalezeny žádní autoři.</div>';
}else{
$authorID = $author['authorID'];
$authorName = $author['authorName'];
};
if ($_SERVER["REQUEST_METHOD"] == "POST") {
#region smazani autora
if(!empty($hasBook)){
echo '<div class="alert alert-danger">Nelze smazat autora, v knihovně jsou knihy s tímto autorem!</div>';
}else{
$delQuery=$db->prepare('DELETE FROM library_authors WHERE author_id=?;');
$delQuery->execute(array(
$authorID
));
header('Location: authors.php');
exit();
#endregion smazani autora
}
};
$pageTitle="Odstranění autora";
include 'include/header.php';
?>
<div class="row mx-3">
<h2 class="col">Odstranění autora</h2>
</div>
<div class="new_book-form pt-5">
<form method="POST">
<h2 class="text-center mb-4 pl-4">Opravdu chcete tohoto autora smazat z databáze?</h2>
<div class="form-group">
<input id="delete_name" type="text" disabled class="form-control text-center font-weight-bold"
name="delete_name" value="<?php echo ''.htmlspecialchars($authorName).'';?>"/>
</div>
<div class="form-group">
<div class="input-group">
<a href="authors.php" class="col btn btn-outline-secondary mr-2">Zrušit</a>
<button type="submit" class="btn btn-danger col form-control ml-2">Smazat</button>
</div>
</div>
</form>
</div>
<?php
include 'include/footer.php';
?>