-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminUsersDeleteUser.php
More file actions
135 lines (128 loc) · 6.1 KB
/
adminUsersDeleteUser.php
File metadata and controls
135 lines (128 loc) · 6.1 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
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
<?php
session_start();
require_once('config/config.php');
require_once('includes/nav.php');
require_once('util/userUtil.php');
if(!isset($_SESSION['UserType']) || $_SESSION['UserType'] !== UserType::admin->value){
$_SESSION['UserType'] = UserType::visitor->value;
header("Location: index.php");
exit();
}
$pageTitle = $APP_PROPERTIES['app_name'].' - Admin';
if(empty($_GET['userId']) || !filter_var($_GET['userId'], FILTER_VALIDATE_INT))
{
header("Location: adminUsers.php");
exit();
}
$user = new User($_GET['userId']);
$userIdentifier = "(".$user->getId().") ".$user->getUsername();
$errUserDelete = $successUserDelete = "";
if ($_SERVER["REQUEST_METHOD"] === "POST")
if(!empty($_POST['deleteUser']) && $_POST['deleteUser'] === "1" && $user->getId() > 0)
if($user->deleteInDb())
$successUserDelete = 'Profile "'.htmlspecialchars($userIdentifier).'" deleted successfully.';
else
$errUserDelete = "Error on deleting the user.";
else
$errUserDelete = "An error has occurred.";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php require_once('includes/head-includes.php') ?>
<title><?php echo $pageTitle;?></title>
</head>
<body class="d-flex flex-column min-vh-100">
<?php
$navbar = new Navbar(UserType::getEnumFromValue($_SESSION['UserType']));
echo $navbar->getNavBar();
?>
<main class="container flex-grow-1 mt-3 mt-md-5 pt-md-4">
<div class="text-break">
<h1>Admin: Delete User - "<?php echo htmlspecialchars($userIdentifier);?>"</h1>
<?php
if(!empty(($errUserDelete)))
echo'
<div class="mb-3 fw-semibold text-danger">
<p>Error: '.$errUserDelete.'</p>
</div>
';
elseif(!empty($successUserDelete)){
echo'
<div class="mb-3 fw-semibold text-success">
<p>Success: '.$successUserDelete.'</p>
</div>
';
goto skipDisplay;
}
?>
</div>
<form method="POST" action="" class="mt-3 mt-md-5">
<div class="mb-3 form-check text-break">
<input type="checkbox" class="form-check-input" id="deleteUser" name="deleteUser" value="1" required>
<label class="form-check-label" for="deleteUser">* Are you sure you want to delete the user "<?php echo htmlspecialchars($user->getUsername());?>"?</label>
</div>
<button class="btn btn-danger btn-md" type="submit">
<i class="bi bi-trash"></i>
Delete
</button>
</form>
<hr>
<div name="userInfo">
<div class="mb-3">
<label for="id" class="form-label">ID</label>
<input type="text" class="form-control" id="id" value="<?php echo $user->getId();?>" disabled>
</div>
<div class="mb-3">
<label for="user_role" class="form-label">Role</label>
<input type="text" class="form-control" id="user_role" value="<?php echo $user->getRole_name();?>" disabled>
</div>
<div class="mb-3">
<label for="created_at" class="form-label">Created at</label>
<input type="text" class="form-control" id="created_at" value="<?php echo $user->getCreated_at()->format('Y-m-d H:i:s');?>" disabled>
</div>
<div class="mb-3">
<label class="form-label mb-2">Profile picture</label>
<div class="text-center">
<img src="<?php echo ((empty($user->getProfilePicturePath())) || (! file_exists($user->getProfilePicturePath()))) ? 'resources/images/person.svg' : htmlspecialchars($user->getProfilePicturePath()); ?>"
class="profile-pic-edit mb-2"
alt="Profile picture">
</div>
</div>
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" value="<?php echo htmlspecialchars($user->getUsername());?>" disabled>
</div>
<div class="mb-3">
<label for="lastname" class="form-label">Lastname</label>
<input type="text" class="form-control" id="lastname" value="<?php echo htmlspecialchars($user->getLastname());?>" disabled>
</div>
<div class="mb-3">
<label for="firstname" class="form-label">Firstname</label>
<input type="text" class="form-control" id="firstname" value="<?php echo htmlspecialchars($user->getFirstname());?>" disabled>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" value="<?php echo htmlspecialchars($user->getEmail());?>" disabled>
</div>
<div class="mb-3">
<label for="bio" class="form-label">Bio</label>
<textarea name="bio" class="form-control" rows="3" disabled><?= htmlspecialchars($user->getBio()) ?></textarea>
</div>
<hr>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input pe-none" id="publicProfile" <?php echo $user->getPublicProfile() == 1 ? "checked" : "";?>>
<label class="form-check-label pe-none" for="publicProfile">Public profile</label>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input pe-none" id="active" <?php echo $user->getActive() == 1 ? "checked" : "";?>>
<label class="form-check-label pe-none" for="active">Active</label>
</div>
</div>
<?php
skipDisplay:
?>
</main>
<?php require_once('./includes/footer.php'); ?>
</body>
</html>