-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_user.php
executable file
·262 lines (227 loc) · 6.34 KB
/
admin_user.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
/*
==============================================================================
Copyright (c) 2013 Marc Augier
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact: m.augier@me.com
==============================================================================
*/
/*
UserCake Version: 2.0.2
http://usercake.com
*/
require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
require_once("inc/functions.php");
openPage("Modification d'un utilisateur");
$userId = $_GET['id'];
//Check if selected user exists
if(!userIdExists($userId)){
header("Location: admin_users.php"); die();
}
$userdetails = fetchUserDetails(NULL, NULL, $userId); //Fetch user details
//Forms posted
if(!empty($_POST))
{
//Delete selected account
if(!empty($_POST['delete'])){
$deletions = $_POST['delete'];
if ($deletion_count = deleteUsers($deletions)) {
$successes[] = lang("ACCOUNT_DELETIONS_SUCCESSFUL", array($deletion_count));
}
else {
$errors[] = lang("SQL_ERROR");
}
}
else
{
//Update display name
if ($userdetails['display_name'] != $_POST['display']){
$displayname = trim($_POST['display']);
//Validate display name
if(displayNameExists($displayname))
{
$errors[] = lang("ACCOUNT_DISPLAYNAME_IN_USE",array($displayname));
}
elseif(minMaxRange(5,25,$displayname))
{
$errors[] = lang("ACCOUNT_DISPLAY_CHAR_LIMIT",array(5,25));
}
elseif(!ctype_alnum($displayname)){
$errors[] = lang("ACCOUNT_DISPLAY_INVALID_CHARACTERS");
}
else {
if (updateDisplayName($userId, $displayname)){
$successes[] = lang("ACCOUNT_DISPLAYNAME_UPDATED", array($displayname));
}
else {
$errors[] = lang("SQL_ERROR");
}
}
}
else {
$displayname = $userdetails['display_name'];
}
//Activate account
if(isset($_POST['activate']) && $_POST['activate'] == "activate"){
if (setUserActive($userdetails['activation_token'])){
$successes[] = lang("ACCOUNT_MANUALLY_ACTIVATED", array($displayname));
}
else {
$errors[] = lang("SQL_ERROR");
}
}
//Update email
if ($userdetails['email'] != $_POST['email']){
$email = trim($_POST["email"]);
//Validate email
if(!isValidEmail($email))
{
$errors[] = lang("ACCOUNT_INVALID_EMAIL");
}
elseif(emailExists($email))
{
$errors[] = lang("ACCOUNT_EMAIL_IN_USE",array($email));
}
else {
if (updateEmail($userId, $email)){
$successes[] = lang("ACCOUNT_EMAIL_UPDATED");
}
else {
$errors[] = lang("SQL_ERROR");
}
}
}
//Update title
if ($userdetails['title'] != $_POST['title']){
$title = trim($_POST['title']);
//Validate title
if(minMaxRange(1,50,$title))
{
$errors[] = lang("ACCOUNT_TITLE_CHAR_LIMIT",array(1,50));
}
else {
if (updateTitle($userId, $title)){
$successes[] = lang("ACCOUNT_TITLE_UPDATED", array ($displayname, $title));
}
else {
$errors[] = lang("SQL_ERROR");
}
}
}
//Remove permission level
if(!empty($_POST['removePermission'])){
$remove = $_POST['removePermission'];
if ($deletion_count = removePermission($remove, $userId)){
$successes[] = lang("ACCOUNT_PERMISSION_REMOVED", array ($deletion_count));
}
else {
$errors[] = lang("SQL_ERROR");
}
}
if(!empty($_POST['addPermission'])){
$add = $_POST['addPermission'];
if ($addition_count = addPermission($add, $userId)){
$successes[] = lang("ACCOUNT_PERMISSION_ADDED", array ($addition_count));
}
else {
$errors[] = lang("SQL_ERROR");
}
}
$userdetails = fetchUserDetails(NULL, NULL, $userId);
}
}
$userPermission = fetchUserPermissions($userId);
$permissionData = fetchAllPermissions();
echo resultBlock($errors,$successes);
echo "
<form name='adminUser' action='".$_SERVER['PHP_SELF']."?id=".$userId."' method='post'>
<table class='admin'><tr><td>
<h3>User Information</h3>
<div id='regbox'>
<p>
<label>ID:</label>
".$userdetails['id']."
</p>
<p>
<label>Username:</label>
".$userdetails['user_name']."
</p>
<p>
<label>Display Name:</label>
<input type='text' name='display' value='".$userdetails['display_name']."' />
</p>
<p>
<label>Email:</label>
<input type='text' name='email' value='".$userdetails['email']."' />
</p>
<p>
<label>Active:</label>";
//Display activation link, if account inactive
if ($userdetails['active'] == '1'){
echo "Yes";
}
else{
echo "No
</p>
<p>
<label>Activate:</label>
<input type='checkbox' name='activate' id='activate' value='activate'>
";
}
echo "
</p>
<p>
<label>Title:</label>
<input type='text' name='title' value='".$userdetails['title']."' />
</p>
<p>
<label>Sign Up:</label>
".date("j M, Y", $userdetails['sign_up_stamp'])."
</p>
<p>
<label>Last Sign In:</label>";
//Last sign in, interpretation
if ($userdetails['last_sign_in_stamp'] == '0'){
echo "Never";
}
else {
echo date("j M, Y", $userdetails['last_sign_in_stamp']);
}
echo "
</p>
<p>
<label>Delete:</label>
<input type='checkbox' name='delete[".$userdetails['id']."]' id='delete[".$userdetails['id']."]' value='".$userdetails['id']."'>
</p>
<p>
<label> </label>
<input type='submit' value='Update' class='submit' />
</p>
</div>
</td>
<td>
<h3>Permission Membership</h3>
<div id='regbox'>
<p>Remove Permission:";
//List of permission levels user is apart of
foreach ($permissionData as $v1) {
if(isset($userPermission[$v1['id']])){
echo "<br><input type='checkbox' name='removePermission[".$v1['id']."]' id='removePermission[".$v1['id']."]' value='".$v1['id']."'> ".$v1['name'];
}
}
//List of permission levels user is not apart of
echo "</p><p>Add Permission:";
foreach ($permissionData as $v1) {
if(!isset($userPermission[$v1['id']])){
echo "<br><input type='checkbox' name='addPermission[".$v1['id']."]' id='addPermission[".$v1['id']."]' value='".$v1['id']."'> ".$v1['name'];
}
}
closePage();
?>