-
Notifications
You must be signed in to change notification settings - Fork 1
/
changeuserinfo.php
208 lines (186 loc) · 6.39 KB
/
changeuserinfo.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
<?php
require_once('application.inc.php');
if (!authorized()) { exit; }
if (!$_SESSION['AUTH_ISCALENDARADMIN']) { exit; } // additional security
if (!isset($_POST['cancel']) || !setVar($cancel, $_POST['cancel'], 'cancel')) { unset($cancel); }
if (!isset($_POST['save']) || !setVar($save, $_POST['save'], 'save')) { unset($save); }
if (!isset($_POST['check']) || !setVar($check, $_POST['check'], 'check')) { unset($check); }
if (!isset($_POST['userid']) || !setVar($userid, $_POST['userid'], 'userid')) {
if (!isset($_GET['userid']) || !setVar($userid, $_GET['userid'], 'userid')) { unset($userid); }
}
if (!isset($_POST['chooseuser']) || !setVar($chooseuser, $_POST['chooseuser'], 'chooseuser')) {
if (!isset($_GET['chooseuser']) || !setVar($chooseuser, $_GET['chooseuser'], 'chooseuser')) { unset($chooseuser); }
}
if (isset($_POST['user'])) {
if (!isset($_POST['user']['password']) || !setVar($user['password'], $_POST['user']['password'], 'password')) { unset($user['password']); }
if (!isset($_POST['user']['email']) || !setVar($user['email'], $_POST['user']['email'], 'email')) { unset($user['email']); }
}
else { unset($user); }
// prepend the prefix when creating new users
if (isset($userid) && !isset($chooseuser)) {
if (substr($userid, 0, strlen(AUTH_DB_USER_PREFIX)) != AUTH_DB_USER_PREFIX) {
$userid = AUTH_DB_USER_PREFIX . $userid;
}
}
function checkuser(&$user)
{
return (!empty($user['id']) && isValidInput($user['id'], 'userid') && !empty($user['password']));
}
function emailuseraccountchanged(&$user)
{
$subject = lang('email_account_updated_subject', false);
$body = lang('email_account_updated_body', false) . "\n";
$body .= ' ' . lang('user_id', false) . ': ' . stripslashes($user['id']) . "\n";
if ($user['password'] != '#nochange$') {
$body .= ' ' . lang('password', false) . ' ' . stripslashes($user['password']) . "\n";
}
$body .= ' ' . lang('email', false) . ': ' . stripslashes($user['email']) . "\n";
sendemail2user($user['email'], $subject, $body);
}
if (isset($cancel)) {
redirect2URL('manageusers.php');
exit;
};
if (isset($userid)) { $user['id'] = $userid; }
if (isset($save) && checkuser($user) && ($chooseuser || !userExistsInDB($user['id'])) ) { // save user into DB
if (!empty($chooseuser)) { // update an existing user
if ($user['password'] == '#nochange$') { // update only the e-mail address
$result = DBQuery("
UPDATE
" . SCHEMANAME . "vtcal_user
SET
email='" . sqlescape($user['email']) . "'
WHERE
id='" . sqlescape($user['id']) . "'
");
}
else { // update password and email address
$result = DBQuery("
UPDATE
" . SCHEMANAME . "vtcal_user
SET
password='" . sqlescape(crypt($user['password'])) . "',
email='" . sqlescape($user['email']) . "'
WHERE
id='" . sqlescape($user['id']) . "'
");
}
emailuseraccountchanged($user);
redirect2URL('manageusers.php');
}
else { // insert as a new user
$query = "
INSERT INTO
" . SCHEMANAME . "vtcal_user
(
id,
password,
email
)
VALUES
(
'" . sqlescape($user['id']) . "',
'" . sqlescape(crypt($user['password'])) . "',
'" . sqlescape($user['email']) . "'
)
";
$result = DBQuery($query);
emailuseraccountchanged($user);
// reroute to sponsormenu page
redirect2URL('manageusers.php');
}
exit;
}
// print page header
if (!empty($chooseuser)) {
if (empty($userid)) { // no user was selected
// reroute to sponsormenu page
redirect2URL('update.php?fbid=userupdatefailed');
exit;
}
else {
pageheader(lang('edit_user', false), 'Update');
contentsection_begin(lang('edit_user'));
}
}
else {
pageheader(lang('add_new_user', false), 'Update');
contentsection_begin(lang('add_new_user'));
}
if (isset($user['id']) && (!isset($check) || $check != 1)) {
// load user to update information if it's the first time the form is viewed
$result = DBQuery("
SELECT
*
FROM
" . SCHEMANAME . "vtcal_user
WHERE
id='" . sqlescape($user['id']) . "'
");
$user = $result->fetchRow(DB_FETCHMODE_ASSOC);
}
// set the allowed length for the input fields
$maxlength_id = 50;
?>
<form action="changeuserinfo.php" method="post">
<input type="hidden" name="check" value="1" />
<?php
if (!empty($chooseuser)) {
echo '<input type="hidden" name="chooseuser" value="1" />' . "\n";
if (!empty($userid)) { echo '<input type="hidden" name="userid" value="' . htmlspecialchars($userid, ENT_COMPAT, 'UTF-8') . '" />' . "\n"; }
}
?>
<table border="0" cellpadding="2" cellspacing="0">
<tbody><tr>
<td><?php
if (!empty($chooseuser)) { echo '<strong>' . lang('user_id') . ':</strong></td>
<td><b>' . $userid . '</b>'; }
else {
echo '<label for="userid"><strong>' . lang('user_id') . ':</strong></label> <span class="txtWarn">*</span></td>
<td>';
if (isset($check) && $check && (empty($userid))) {
feedback(lang('choose_user_id'), FEEDBACKNEG);
}
if (isset($check) && $check && userExistsInDB($userid)) {
feedback(lang('user_id_already_exists'), FEEDBACKNEG);
}
echo AUTH_DB_USER_PREFIX;
echo '<input type="text" id="userid" name="userid" value="';
if (isset($check) && $check) { $userid = stripslashes($userid); }
if (isset($userid)) { echo htmlspecialchars(substr($userid, strlen(AUTH_DB_USER_PREFIX)), ENT_COMPAT, 'UTF-8'); }
echo '" size="10" maxlength="' . $maxlength_id . '" /> <i>(e.g. ' .
AUTH_DB_USER_PREFIX . 'jsmith)</i>';
}
?></td>
</tr><tr>
<td><label for="userpassword"><strong><?php echo lang('password'); ?></strong></label> <span class="txtWarn">*</span></td>
<td><?php
if (isset($check) && $check && (empty($user['password']))) {
feedback(lang('choose_password'), FEEDBACKNEG);
}
echo '<input type="password" id="userpassword" name="user[password]" value="';
if (!empty($chooseuser)) { echo '#nochange$'; }
echo '" size="14" maxlength="' . MAXLENGTH_PASSWORD . '" autocomplete="off" />';
?></td>
</tr><tr>
<td><label for="useremail"><strong><?php echo lang('email'); ?>:</strong></label></td>
<td><?php
echo '<input type="text" id="useremail" name="user[email]" value="';
if (isset($user) && isset($user['email'])) {
if (isset($check) && $check) { $user['email'] = stripslashes($user['email']); }
echo htmlspecialchars($user['email'], ENT_COMPAT, 'UTF-8');
}
echo '" size="20" maxlength="' . MAXLENGTH_EMAIL . '" /> <i>' .
lang('email_example') . '</i>';
?></td>
</tr></tbody>
</table><br />
<p><input type="submit" name="save" value="<?php echo lang('ok_button_text', false); ?>" />
<input type="submit" name="cancel" value="<?php echo lang('cancel_button_text', false); ?>" /></p>
</form>
<?php
contentsection_end();
pagefooter();
DBclose();
?>