-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_delete.php
78 lines (63 loc) · 2.42 KB
/
user_delete.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
<?php
require_once 'include/user.php';
require 'admin_required.php';
$userID = $_GET['userID'];
$query = $db->prepare(
'SELECT library_users.user_id AS userID, library_users.name AS userName
FROM library_users
WHERE user_id = '.$userID.'
ORDER BY library_users.name ASC');
$query->execute();
$user = $query->fetch();
$BooksQuery = $db->prepare(
'SELECT library_loaned_books.loan_id AS loan_id, user_id as userID
FROM library_loaned_books
WHERE user_id = '.$userID.'');
$BooksQuery->execute();
$hasBook = $BooksQuery->fetch();
if(empty($user)){
echo '<div class="alert alert-info">Nebyly nalezeny žádné knihy.</div>';
}else{
$userID = $user['userID'];
$userName = $user['userName'];
};
if ($_SERVER["REQUEST_METHOD"] == "POST") {
#region smazani knihy
if(!empty($hasBook)){
echo '<div class="alert alert-danger">Nelze smazat uživatele, pokud má vypůjčené nějaké knihy!</div>';
}else{
if(empty($errors)){
$delQuery=$db->prepare('DELETE FROM library_users WHERE user_id=?;');
$delQuery->execute(array(
$userID
));
header('Location: user_mgmt.php');
exit();
}
#endregion smazani knihy
}
};
$pageTitle="Smazání uživatele";
include 'include/header.php';
?>
<div class="row">
<h2 class="col">Odstranění žánru</h2>
</div>
<div class="new_book-form pt-5">
<form method="POST">
<h2 class="text-center mb-4 pl-4">Opravdu chcete tohoto uživatele odstranit 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($userName).'';?>"/>
</div>
<div class="form-group">
<div class="input-group">
<a href="user_mgmt.php" class="col btn btn-outline-secondary mr-2">Zrušit</a>
<button type="submit" class="btn btn-danger col form-control ml-2">Odstranit</button>
</div>
</div>
</form>
</div>
<?php
include 'include/footer.php';
?>