-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminDeleteUser.php
75 lines (55 loc) · 1.48 KB
/
AdminDeleteUser.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
<?php
require "/Model/ModelFacade.php";
/*
* This controller is used to allow an admin to delete a users account.
*
*/
//redirect if user not logged in as admin
ModelFacade::redirectUnauthorisedNotAdmin();
//get all categories and subcategories
OnRequest();
function OnRequest()
{
if ($_SERVER['REQUEST_METHOD'] == "GET") {
if (isset($_GET['id'])) {
DeleteUser($_GET['id']);
}
}
}
function DeleteUser($id)
{
$result = ModelFacade::DeleteUser($id);
if ($result[0] == 0) {
header('Location: /AdminUsers.php');
} else {
header('Location: /AdminUser.php?id=' . $id);
}
}
function UpdateUser()
{
$user = GetUserById($_GET['id']);
if (isset($_POST['is_admin']) && isset($_POST['is_banned'])) {
$userArray = array('id' => $user->id,
'is_admin' => $_POST['is_admin'],
'is_banned' => $_POST['is_banned']);
$result = ModelFacade::UpdateUser($userArray);
switch ($result[0]) {
case 0:
$success = 'User ' . $user->username . ' updated successfully';
break;
default:
$error = 'There was an error updating the users database';
break;
}
$user = GetUserById($_GET['id']);
include_once('/Views/Admin/User.html');
} else {
header("Location: /AdminUsers.php");
}
}
function GetUserById($id)
{
$user = ModelFacade::GetUserById($id);
return $user;
}
?>