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
|
<?php
// User Account Edit Interface.
//
// webtrees: Web based Family History software
// Copyright (C) 2011 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
//
// 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.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// $Id$
define('WT_SCRIPT_NAME', 'edituser.php');
require './includes/session.php';
require_once WT_ROOT.'includes/functions/functions_print_lists.php';
require WT_ROOT.'includes/functions/functions_edit.php';
// prevent users with editing account disabled from being able to edit their account
if (!get_user_setting(WT_USER_ID, 'editaccount')) {
header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH);
exit;
}
$controller=new WT_Controller_Base();
$controller->setPageTitle(WT_I18N::translate('User administration'));
// Valid values for form variables
$ALL_THEMES_DIRS=array();
foreach (get_theme_names() as $themename=>$themedir) {
$ALL_THEME_DIRS[]=$themedir;
}
// Extract form variables
$form_action =safe_POST('form_action' );
$form_username =safe_POST('form_username', WT_REGEX_USERNAME);
$form_realname =safe_POST('form_realname' );
$form_pass1 =safe_POST('form_pass1', WT_REGEX_PASSWORD);
$form_pass2 =safe_POST('form_pass2', WT_REGEX_PASSWORD);
$form_email =safe_POST('form_email', WT_REGEX_EMAIL, 'email@example.com');
$form_rootid =safe_POST('form_rootid', WT_REGEX_XREF, WT_USER_ROOT_ID );
$form_theme =safe_POST('form_theme', $ALL_THEME_DIRS);
$form_language =safe_POST('form_language', array_keys(WT_I18N::installed_languages()), WT_LOCALE );
$form_contact_method=safe_POST('form_contact_method');
$form_visible_online=safe_POST_bool('form_visible_online');
// Respond to form action
if ($form_action=='update') {
if ($form_username!=WT_USER_NAME && get_user_id($form_username)) {
$controller->pageHeader();
echo '<span class="error">', WT_I18N::translate('Duplicate user name. A user with that user name already exists. Please choose another user name.'), '</span><br>';
} elseif ($form_email!=getUserEmail(WT_USER_ID) && get_user_by_email($form_email)) {
$controller->pageHeader();
echo '<span class="error">', WT_I18N::translate('Duplicate email address. A user with that email already exists.'), '</span><br>';
} else {
// Change password
if (!empty($form_pass1)) {
set_user_password(WT_USER_ID, $form_pass1);
}
$old_realname =getUserFullName(WT_USER_ID);
$old_email =getUserEmail(WT_USER_ID);
// Change other settings
setUserFullName(WT_USER_ID, $form_realname);
setUserEmail (WT_USER_ID, $form_email);
set_user_setting(WT_USER_ID, 'theme', $form_theme);
$WT_SESSION->theme_dir=$form_theme; // switch to the new theme right away
set_user_setting(WT_USER_ID, 'language', $form_language);
$WT_SESSION->locale=$form_language; // switch to the new language right away
set_user_setting(WT_USER_ID, 'contactmethod', $form_contact_method);
set_user_setting(WT_USER_ID, 'visibleonline', $form_visible_online);
set_user_gedcom_setting(WT_USER_ID, WT_GED_ID, 'rootid', $form_rootid);
// Change username
if ($form_username!=WT_USER_NAME) {
AddToLog('User renamed to ->'.$form_username.'<-', 'auth');
rename_user(WT_USER_ID, $form_username);
}
// Reload page to pick up changes such as theme and user_id
header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH.WT_SCRIPT_NAME);
exit;
}
} else {
$controller->pageHeader();
if ($ENABLE_AUTOCOMPLETE) require WT_ROOT.'js/autocomplete.js.htm';
}
// Form validation
?>
<script type="text/javascript">
<!--
function checkform(frm) {
if (frm.form_username.value=="") {
alert("<?php echo WT_I18N::translate('You must enter a user name.'); ?>");
frm.form_username.focus();
return false;
}
if (frm.form_realname.value=="") {
alert("<?php echo WT_I18N::translate('You must enter a real name.'); ?>");
frm.form_realname.focus();
return false;
}
if (frm.form_email.value.indexOf("@")==-1) {
alert("<?php echo WT_I18N::translate('You must enter an email address.'); ?>");
frm.user_email.focus();
return false;
}
if (frm.form_pass1.value!=frm.form_pass2.value) {
alert("<?php echo WT_I18N::translate('Passwords do not match.'); ?>");
frm.form_pass1.focus();
return false;
}
if (frm.form_pass1.value.length > 0 && frm.form_pass1.value.length < 6) {
alert("<?php echo WT_I18N::translate('Passwords must contain at least 6 characters.'); ?>");
frm.form_pass1.focus();
return false;
}
return true;
}
var pastefield;
function paste_id(value) {
pastefield.value=value;
}
-->
</script>
<?php
// show the form to edit a user account details
$tab=0;
echo '<form name="editform" method="post" action="" onsubmit="return checkform(this);">';
echo '<input type="hidden" name="form_action" value="update">';
echo '<table class="list_table">';
echo '<tr><td class="topbottombar" colspan="2"><h2>', WT_I18N::translate('My account'), '</h2></td></tr>';
echo '<tr><td class="descriptionbox width20 wrap">';
echo WT_I18N::translate('Username'), help_link('username'), '</td><td class="optionbox">';
echo '<input type="text" name="form_username" value="', WT_USER_NAME, '" autofocus>';
echo '</td></tr>';
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Real name'), help_link('real_name'), '</td><td class="optionbox">';
echo '<input type="text" name="form_realname" value="', getUserFullName(WT_USER_ID), '">';
echo '</td></tr>';
$person=WT_Person::getInstance(WT_USER_GEDCOM_ID);
if ($person) {
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Individual record'), help_link('edituser_gedcomid'), '</td><td class="optionbox">';
echo $person->format_list('span');
echo '</td></tr>';
}
$person=WT_Person::getInstance(WT_USER_ROOT_ID);
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Pedigree chart root person'), help_link('edituser_rootid'), '</td><td class="optionbox">';
echo '<input type="text" name="form_rootid" id="rootid" value="', WT_USER_ROOT_ID, '">';
echo print_findindi_link('rootid', '', true), '<br>';
if ($person) {
echo $person->format_list('span');
}
echo '</td></tr>';
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Password'), help_link('password'), '</td><td class="optionbox">';
echo '<input type="password" name="form_pass1"> ', WT_I18N::translate('Leave password blank if you want to keep the current password.'), '</td></tr>';
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Confirm password'), help_link('password_confirm'), '</td><td class="optionbox">';
echo '<input type="password" name="form_pass2"></td></tr>';
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Language'), help_link('edituser_change_lang');
echo '</td><td class="optionbox" valign="top">';
echo edit_field_language('form_language', get_user_setting(WT_USER_ID, 'language'));
echo '</td></tr>';
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Email address'), help_link('email'), '</td><td class="optionbox" valign="top">';
echo '<input type="text" name="form_email" value="', getUserEmail(WT_USER_ID), '" size="50"></td></tr>';
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Theme'), help_link('THEME'), '</td><td class="optionbox" valign="top">';
echo '<select name="form_theme">';
echo '<option value="">', htmlspecialchars(/* I18N: default option in list of themes */ WT_I18N::translate('<default theme>')), '</option>';
foreach (get_theme_names() as $themename=>$themedir) {
echo '<option value="', $themedir, '"';
if ($themedir==get_user_setting(WT_USER_ID, 'theme')) {
echo ' selected="selected"';
}
echo '>', $themename, '</option>';
}
echo '</select></td></tr>';
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Preferred contact method'), help_link('edituser_contact_meth');
echo '</td><td class="optionbox">';
echo edit_field_contact('form_contact_method', get_user_setting(WT_USER_ID, 'contactmethod'));
echo '</td></tr>';
echo '<tr><td class="descriptionbox wrap">';
echo WT_I18N::translate('Visible to other users when online'), help_link('useradmin_visibleonline');
echo '</td><td class="optionbox">';
echo checkbox('form_visible_online', get_user_setting(WT_USER_ID, 'visibleonline'));
echo '</td></tr>';
echo '<tr><td class="topbottombar" colspan="2"><input type="submit" value="', WT_I18N::translate('Save'), '"></td></tr>';
echo '</table></form>';
|