This repository was archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserslist.php
More file actions
178 lines (161 loc) · 11.2 KB
/
Copy pathuserslist.php
File metadata and controls
178 lines (161 loc) · 11.2 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
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
<?php
require_once('core/Main.php');
if (!$userSystem->isLoggedIn()) {
$log->info('userslist.php', 'User was not logged in');
$redirect->redirectTo('login.php');
}
if ($currentUser->getRole() != Constants::USER_ROLES['admin']) {
$log->error('userslist.php', 'User was not admin');
$redirect->redirectTo('articles.php');
}
$postStatus = NULL;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$passwordHash = filter_input(INPUT_POST, 'passwordHash', FILTER_SANITIZE_SPECIAL_CHARS);
$role = filter_input(INPUT_POST, 'role', FILTER_SANITIZE_ENCODED);
$status = filter_input(INPUT_POST, 'status', FILTER_SANITIZE_ENCODED);
$lastLoggedIn = filter_input(INPUT_POST, 'lastLoggedIn', FILTER_SANITIZE_SPECIAL_CHARS);
$language = filter_input(INPUT_POST, 'language', FILTER_SANITIZE_ENCODED);
$comment = filter_input(INPUT_POST, 'comment', FILTER_SANITIZE_SPECIAL_CHARS);
$userID = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_ENCODED);
if ($passwordHash != '' && $role != '' && $language != '' && is_numeric($userID)) {
$result = $userSystem->updateUser($userID, $passwordHash, $role, $status, $lastLoggedIn, $language, $comment);
if ($result) {
$postStatus = 'UPDATED_USER_DATA';
$log->debug('userslist.php', 'Successfully updated user data');
} else {
$postStatus = 'ERROR_ON_UPDATING_USER_DATA';
$log->debug('userslist.php', 'Error on updating user data');
}
} else {
$postStatus = 'ERROR_ON_UPDATING_USER_DATA';
$log->debug('userslist.php', 'Missing on updating user data');
}
}
$page = 0;
$role = '';
$username = '';
$userID = '';
$open = '';
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$pageValue = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_ENCODED);
$role = filter_input(INPUT_GET, 'role', FILTER_SANITIZE_ENCODED);
$username = filter_input(INPUT_GET, 'username', FILTER_SANITIZE_ENCODED);
$userIDValue = filter_input(INPUT_GET, 'userID', FILTER_SANITIZE_ENCODED);
$deleteID = filter_input(INPUT_GET, 'deleteID', FILTER_SANITIZE_ENCODED);
if (is_numeric($pageValue)) {
$page = intval($pageValue);
} else {
if ($pageValue != '') {
$log->debug('userslist.php', 'Page value is not numeric: ' . $pageValue);
}
}
if (isset($_GET['userID'])) {
if (is_numeric($userIDValue)) {
$userID = intval($userIDValue);
} else {
$log->info('userslist.php', 'User ID value is not numeric: ' . $userIDValue);
}
}
if (isset($_GET['role']) || isset($_GET['username']) || isset($_GET['userID'])) {
$open = ' open';
}
if (isset($_GET['deleteID'])) {
if (is_numeric($deleteID)) {
if ($deleteID != '1') {
$user = $userSystem->getUser($deleteID);
if ($user != null) {
$result = $userSystem->updateUser($deleteID, $user->getPasswordHash(), 'TO_BE_DELETED', $user->getStatus(), $user->getlastLoggedIn(), $user->getLanguage(), $user->getComment());
if (!$result) {
$postStatus = 'ERROR_ON_UPDATING_USER_DATA';
$log->error('userslist.php', 'User could not be marked for deletion with user ID: ' . $deleteID);
}
} else {
$postStatus = 'ERROR_ON_UPDATING_USER_DATA';
$log->error('userslist.php', 'User ID to be deleted not found: ' . $deleteID);
}
} else {
$postStatus = 'ERROR_ON_UPDATING_USER_DATA';
$log->error('userslist.php', 'Can not delete the admin user with ID 1');
}
} else {
$postStatus = 'ERROR_ON_UPDATING_USER_DATA';
$log->error('userslist.php', 'ID of user to be deleted is not numeric: ' . $deleteID);
}
}
}
echo $header->getHeader($i18n->get('title'), $i18n->get('allUsers'), array('button.css'));
echo $mainMenu->getMainMenu($i18n, $currentUser);
$passwordExample = $hashUtil->generateRandomString();
echo '<center>
<details' . $open . '>
<summary id="styledButton" style="line-height: 10px; margin: 5px;">' . $i18n->get('filter') . '</summary>
<div style="width: 15%; display: inline-block; text-align: left; margin: 0px;">
<form action="userslist.php" method="GET">
<input type="text" size="8" name="username" placeholder="' . $i18n->get('username') . '">
<input type="submit" value="' . $i18n->get('ok') . '">
</form>
</div>
<div style="width: 15%; display: inline-block; text-align: left; margin: 0px;">
<form action="userslist.php" method="GET">
<input type="text" size="8" name="userID" placeholder="' . $i18n->get('user') . ' ' . $i18n->get('ID') . '">
<input type="submit" value="' . $i18n->get('ok') . '">
</form>
</div>
<div style="width: 6%; display: inline-block; text-align: center; margin: 0px;">' . $i18n->get('or') . '</div>
<div style="left: 0%; width: 60%; display: inline-block; text-align: right; margin: 0px;">
<a href="?role=' . Constants::USER_ROLES['user'] . '" id="styledButtonGreen" style="margin: 0px;">' . Constants::USER_ROLES['user'] . 's</a>
<a href="?role=' . Constants::USER_ROLES['admin'] . '" id="styledButtonGreen" style="margin: 0px;">' . Constants::USER_ROLES['admin'] . 's</a>
<a href="?role=' . Constants::USER_ROLES['notActivated'] . '" id="styledButtonGreen" style="margin: 0px;">' . Constants::USER_ROLES['notActivated'] . '_USERs</a>
<a href="?role=' . Constants::USER_ROLES['blocked'] . '" id="styledButtonGreen" style="margin: 0px;">' . Constants::USER_ROLES['blocked'] . '_USERs</a>
<a href="?role=' . Constants::USER_ROLES['toBeDeleted'] . '" id="styledButtonGreen" style="margin: 0px;">' . Constants::USER_ROLES['toBeDeleted'] . '_USERs</a>
</div>
<div style="left: 0%; width: 100%; display: inline-block; margin: 0px;">
<br><center>' . $i18n->get('passwordExample') . ': ' . $passwordExample . ', ' . $i18n->get('hash') . ': ' . $hashUtil->hashPasswordWithSaltIncluded($passwordExample) . '</center><br>
</div>
</details>
</center>';
if ($postStatus == 'UPDATED_USER_DATA') {
echo '<br><center>' . $i18n->get('updatedUserDataSuccessfully') . '</center><br>';
} else if ($postStatus == 'ERROR_ON_UPDATING_USER_DATA') {
echo '<br><center>' . $i18n->get('errorOnUpdatingUserData') . '</center><br>';
}
$numberOfUsersTotal = $userSystem->getNumberOfUsersTotal($role, $username, $userID);
echo $pagedContentUtil->getNavigation($page, Constants::NUMBER_OF_ENTRIES_PER_PAGE, $numberOfUsersTotal);
echo '<br><br>';
echo '<div style="width: 5%; display: inline-block; text-align: center;">' . $i18n->get('ID') . '</div>';
echo '<div style="width: 10%; display: inline-block;">' . $i18n->get('user') . '</div>';
echo '<div style="width: 10%; display: inline-block;">' . $i18n->get('passwordHash') . '</div>';
echo '<div style="width: 5%; display: inline-block;">' . $i18n->get('role') . '</div>';
echo '<div style="width: 5%; display: inline-block;">' . $i18n->get('status') . '</div>';
echo '<div style="width: 15%; display: inline-block;">' . $i18n->get('lastLoggedIn') . '</div>';
echo '<div style="width: 5%; display: inline-block;">' . $i18n->get('language') . '</div>';
echo '<div style="width: 20%; display: inline-block;">' . $i18n->get('comment') . '</div>';
echo '<div style="width: 15%; display: inline-block; text-align: center;">' . $i18n->get('markForDeletion') . '</div>';
echo '<div style="width: 10%; display: inline-block; text-align: center;">' . $i18n->get('save') . '</div>';
$allUsers = $userSystem->getUsers(Constants::NUMBER_OF_ENTRIES_PER_PAGE, $page, $role, $username, $userID);
foreach ($allUsers as &$user) {
echo '<form method="POST" action="userslist.php">';
echo '<div style="width: 5%; display: inline-block; text-align: center;">' . $user->getID() . '</div>';
echo '<div style="width: 10%; display: inline-block;">' . '<input type="text" readonly name="username" value="' . $user->getUsername() . '" style="display: table-cell; width: calc(100% - 18px);">' . '</div>';
echo '<div style="width: 10%; display: inline-block;">' . '<input type="text" name="passwordHash" value="' . $user->getPasswordHash() . '" style="display: table-cell; width: calc(100% - 18px);">' . '</div>';
echo '<div style="width: 5%; display: inline-block;">' . '<input type="text" name="role" value="' . $user->getRole() . '" style="display: table-cell; width: calc(100% - 18px);">' . '</div>';
echo '<div style="width: 5%; display: inline-block;">' . '<input type="text" name="status" value="' . $user->getStatus() . '" style="display: table-cell; width: calc(100% - 18px);">' . '</div>';
echo '<div style="width: 15%; display: inline-block;">' . '<input type="text" name="lastLoggedIn" value="' . $user->getLastLoggedIn() . '" style="display: table-cell; width: calc(100% - 18px);">' . '</div>';
echo '<div style="width: 5%; display: inline-block;">' . '<input type="text" name="language" value="' . $user->getLanguage() . '" style="display: table-cell; width: calc(100% - 18px);">' . '</div>';
echo '<div style="width: 20%; display: inline-block;">' . '<input type="text" name="comment" value="' . $user->getComment() . '" style="display: table-cell; width: calc(100% - 18px);">' . '</div>';
echo '<div style="width: 15%; display: inline-block; text-align: center;">
<a href="?deleteID=' . $user->getID() . '" id="styledButtonRed">
<img src="static/img/delete.png' . $GLOBALS['VERSION_STRING'] . '" alt="delete user" style="height: 24px; vertical-align: middle;">
</a>
</div>';
echo '<div style="width: 10%; display: inline-block; text-align: center;">' .
'<button type="submit" id="styledButton" name="id" value="' . $user->getID() . '" style="padding: 3px; width: 40px; height: 40px; vertical-align: middle;">
<img src="static/img/save.png' . $GLOBALS['VERSION_STRING'] . '" alt="submit" style="height: 24px;">
</button>' .
'</div>';
echo '</form>';
}
echo '<br>';
echo $pagedContentUtil->getNavigation($page, Constants::NUMBER_OF_ENTRIES_PER_PAGE, $numberOfUsersTotal);
echo $footer->getFooter();
?>