summaryrefslogtreecommitdiff
path: root/admin_users.php
diff options
context:
space:
mode:
authorfisharebest <fisharebest@gmail.com>2011-02-09 19:54:49 +0000
committerfisharebest <fisharebest@gmail.com>2011-02-09 19:54:49 +0000
commitdb5fb7e059c0c36cd53505fca913b77c81a70bd7 (patch)
tree7f7910346ffc5055a7568e000e8daac180bd6218 /admin_users.php
parentda3fe395dcc075d585d1cb52e16ccf29ff1d958b (diff)
downloadwebtrees-db5fb7e059c0c36cd53505fca913b77c81a70bd7.tar.gz
webtrees-db5fb7e059c0c36cd53505fca913b77c81a70bd7.tar.bz2
webtrees-db5fb7e059c0c36cd53505fca913b77c81a70bd7.zip
Tidy up "create new user" code
Diffstat (limited to 'admin_users.php')
-rw-r--r--admin_users.php442
1 files changed, 102 insertions, 340 deletions
diff --git a/admin_users.php b/admin_users.php
index cf3bfcc925..35377649a5 100644
--- a/admin_users.php
+++ b/admin_users.php
@@ -49,10 +49,10 @@ $ALL_EDIT_OPTIONS=array(
// Form actions
$action =safe_GET('action', $ALL_ACTIONS, 'listusers');
-$usrlang =safe_GET('usrlang', array_keys(WT_I18N::installed_languages()));
-$username =safe_GET('username', WT_REGEX_USERNAME);
-$filter =safe_GET('filter', WT_REGEX_NOSCRIPT);
-$ged =safe_GET('ged', WT_REGEX_NOSCRIPT);
+$usrlang =safe_POST('usrlang', array_keys(WT_I18N::installed_languages()));
+$username =safe_POST('username', WT_REGEX_USERNAME);
+$filter =safe_POST('filter', WT_REGEX_NOSCRIPT);
+$ged =safe_POST('ged', WT_REGEX_NOSCRIPT);
// Extract form variables
$oldusername =safe_POST('oldusername', WT_REGEX_USERNAME);
@@ -383,332 +383,10 @@ if ($action=='createuser' || $action=='edituser2') {
}
}
-// Print the form to edit a user
-if ($action=="edituser") {
- $user_id=get_user_id($username);
- init_calendar_popup();
- ?>
- <script type="text/javascript">
- <!--
- function checkform(frm) {
- if (frm.username.value=="") {
- alert("<?php echo WT_I18N::translate('You must enter a user name.'); ?>");
- frm.username.focus();
- return false;
- }
- if (frm.realname.value=="") {
- alert("<?php echo WT_I18N::translate('You must enter a real name.'); ?>");
- frm.realname.focus();
- return false;
- }
- if ((frm.pass1.value!="")&&(frm.pass1.value.length < 6)) {
- alert("<?php echo WT_I18N::translate('Passwords must contain at least 6 characters.'); ?>");
- frm.pass1.value = "";
- frm.pass2.value = "";
- frm.pass1.focus();
- return false;
- }
- if ((frm.emailaddress.value!="")&&(frm.emailaddress.value.indexOf("@")==-1)) {
- alert("<?php echo WT_I18N::translate('You must enter an email address.'); ?>");
- frm.emailaddress.focus();
- return false;
- }
- return true;
- }
- var pastefield;
- function paste_id(value) {
- pastefield.value=value;
- }
- jQuery(document).ready(function() {
- jQuery('.relpath').change(function() {
- var fieldIDx = jQuery(this).attr('id');
- var idNum = fieldIDx.replace('RELATIONSHIP_PATH_LENGTH','');
- var newIDx = "gedcomid"+idNum;
- if (jQuery('#'+newIDx).val()=='') {
- alert("<?php echo WT_I18N::translate('You must specify an individual record before you can restrict the user to their immediate family.'); ?>");
- jQuery(this).val('');
- }
- });
- });
- //-->
- </script>
-
- <form name="editform" method="post" action="admin_users.php?action=edituser2" onsubmit="return checkform(this);" autocomplete="off">
- <input type="hidden" name="filter" value="<?php echo $filter; ?>" />
- <input type="hidden" name="usrlang" value="<?php echo $usrlang; ?>" />
- <input type="hidden" name="oldusername" value="<?php echo $username; ?>" />
- <input type="hidden" name="oldemailaddress" value="<?php echo getUserEmail($user_id); ?>" />
- <!--table-->
- <table id="adduser">
- <tr>
- <td><?php echo WT_I18N::translate('User name'), help_link('useradmin_username'); ?></td>
- <td colspan="3"><input type="text" name="username" value="<?php echo $username; ?>" autofocus /></td>
- </tr>
- <tr>
- <td><?php echo WT_I18N::translate('Real name'), help_link('useradmin_realname'); ?></td>
- <td colspan="3"><input type="text" name="realname" value="<?php echo getUserFullName($user_id); ?>" size="50" /></td>
- </tr>
- <tr>
- <td><?php echo WT_I18N::translate('Password'), help_link('useradmin_password'); ?></td>
- <td><input type="password" name="pass1" /></td>
- <td><?php echo WT_I18N::translate('Confirm password'), help_link('useradmin_conf_password'); ?></td>
- <td><input type="password" name="pass2" /></td>
- </tr>
- <tr>
- <td>&nbsp;</td>
- <td colspan="3"><?php echo WT_I18N::translate('Leave password blank if you want to keep the current password.'); ?></td>
- <tr>
- <td><?php echo WT_I18N::translate('Email address'), help_link('useradmin_email'); ?></td>
- <td><input type="text" name="emailaddress" dir="ltr" value="<?php echo getUserEmail($user_id); ?>" size="50" /></td>
- <td><?php echo WT_I18N::translate('Preferred contact method'), help_link('useradmin_user_contact'); ?></td>
- <td>
- <?php
- echo edit_field_contact('new_contact_method', get_user_setting($user_id, 'contactmethod'));
- ?>
- </td>
- </tr>
- <tr>
- <td><?php echo WT_I18N::translate('Email verified'), help_link('useradmin_verification'); ?></td>
- <td><input type="checkbox" name="verified" value="1" <?php if (get_user_setting($user_id, 'verified')) echo "checked=\"checked\""; ?> /></td>
- <td><?php echo WT_I18N::translate('Approved by administrator'), help_link('useradmin_verification'); ?></td>
- <td><input type="checkbox" name="verified_by_admin" value="1" <?php if (get_user_setting($user_id, 'verified_by_admin')) echo "checked=\"checked\""; ?> /></td>
- </tr>
- <tr>
- <td><?php echo WT_I18N::translate('Automatically approve changes made by this user'), help_link('useradmin_auto_accept'); ?></td>
- <td><input type="checkbox" name="new_auto_accept" value="1" <?php if (get_user_setting($user_id, 'auto_accept')) echo "checked=\"checked\""; ?> /></td>
- <td><?php echo WT_I18N::translate('Allow this user to edit his account information'), help_link('useradmin_editaccount'); ?></td>
- <td><input type="checkbox" name="editaccount" value="1" <?php if (get_user_setting($user_id, 'editaccount')) echo "checked=\"checked\""; ?> /></td>
- </tr>
- <tr>
- <td><?php echo WT_I18N::translate('Administrator'), help_link('role'); ?></td>
- <?php
- // Forms won't send the value of checkboxes if they are disabled, so use a hidden field
- echo '<td>';
- echo two_state_checkbox('canadmin', get_user_setting($user_id, 'canadmin'), ($user_id==WT_USER_ID) ? 'disabled="disabled"' : '');
- echo '</td>';
- ?>
- <td><?php echo WT_I18N::translate('Visible to other users when online'), help_link('useradmin_visibleonline'); ?></td>
- <td><input type="checkbox" name="visibleonline" value="1" <?php if (get_user_setting($user_id, 'visibleonline')) echo "checked=\"checked\""; ?> /></td>
- </tr>
- <tr>
- <td><?php echo WT_I18N::translate('Admin comments on user'), help_link('useradmin_comment'); ?></td>
- <td><textarea cols="38" rows="5" name="new_comment"><?php $tmp = PrintReady(get_user_setting($user_id, 'comment')); echo $tmp; ?></textarea></td>
- <td><?php echo WT_I18N::translate('Admin warning at date'), help_link('useradmin_comment_exp'); ?></td>
- <td><input type="text" name="new_comment_exp" id="new_comment_exp" value="<?php echo get_user_setting($user_id, 'comment_exp'); ?>" />&nbsp;&nbsp;<?php print_calendar_popup("new_comment_exp"); ?></td>
- </tr>
- <tr>
- <td><?php echo WT_I18N::translate('Language'), help_link('edituser_change_lang'); ?></td>
- <td colspan="3">
- <?php
- echo edit_field_language('user_language', get_user_setting($user_id, 'language'));
- ?>
- </td>
- </tr>
- <tr>
- <td><?php echo WT_I18N::translate('Theme'), help_link('THEME'); ?></td>
- <td colspan="3">
- <select name="user_theme" dir="ltr">
- <option value=""><?php echo WT_I18N::translate('&lt;default theme&gt;'); ?></option>
- <?php
- foreach (get_theme_names() as $themename=>$themedir) {
- echo "<option value=\"", $themedir, "\"";
- if ($themedir == get_user_setting($user_id, 'theme')) echo " selected=\"selected\"";
- echo ">", $themename, "</option>";
- }
- ?></select>
- </td>
- </tr>
- <tr>
- <td><?php echo WT_I18N::translate('Default Tab to show on Individual Information page'), help_link('useradmin_user_default_tab'); ?></td>
- <td colspan="3">
- <?php echo edit_field_default_tab('new_default_tab', get_user_setting($user_id, 'defaulttab')); ?>
- </td>
- </tr>
- <!-- access and relationship path details -->
- <tr>
- <td class="subbar" colspan="4"><?php echo WT_I18N::translate('Family tree access and settings'); ?></td>
- </tr>
- <tr>
- <td colspan="4">
- <table id="adduser2">
- <tr>
- <th><?php echo WT_I18N::translate('Family tree'); ?></th>
- <th><?php echo WT_I18N::translate('Pedigree chart root person'), help_link('useradmin_rootid'); ?></th>
- <th><?php echo WT_I18N::translate('Individual record'), help_link('useradmin_gedcomid'); ?></th>
- <th><?php echo WT_I18N::translate('Role'), help_link('role'); ?></th>
- <th><?php echo WT_I18N::translate('Restrict to immediate family'), help_link('RELATIONSHIP_PATH_LENGTH'); ?></th>
- </tr>
- <?php
- foreach ($all_gedcoms as $ged_id=>$ged_name) {
- echo '<tr>',
- '<td >', WT_I18N::translate('%s', get_gedcom_setting($ged_id, 'title')), '</td>',
- //Pedigree root person
- '<td>';
- $varname='rootid'.$ged_id;
- echo '<input type="text" name="', $varname, '" id="', $varname, '" value="';
- $pid=get_user_gedcom_setting($user_id, $ged_id, 'rootid');
- echo $pid, '" />', print_findindi_link($varname, "", false, false, $ged_name);
- $GEDCOM=$ged_name; // library functions use global variable instead of parameter.
- $person=WT_Person::getInstance($pid);
- if ($person) {
- echo '<div class="list_item"><a href="', $person->getHtmlUrl(), '">', PrintReady($person->getFullName()), '</a></div>';
- }
- echo '</td>',
- // GEDCOM INDI Record ID
- '<td>';
- $varname='gedcomid'.$ged_id;
- echo '<input type="text" name="',$varname, '" id="',$varname, '" value="';
- $pid=get_user_gedcom_setting($user_id, $ged_id, 'gedcomid');
- echo $pid, '" />';
- print_findindi_link($varname, "", false, false, $ged_name);
- $GEDCOM=$ged_name; // library functions use global variable instead of parameter.
- $person=WT_Person::getInstance($pid);
- if ($person) {
- echo ' <div class="list_item"><a href="', $person->getHtmlUrl(), '">', PrintReady($person->getFullName()), '</a></div>';
- }
- echo '</td>',
- '<td>';
- $varname='canedit'.$ged_id;
- echo '<select name="', $varname, '" id="', $varname, '">';
- foreach ($ALL_EDIT_OPTIONS as $EDIT_OPTION=>$desc) {
- echo '<option value="', $EDIT_OPTION, '" ';
- if (get_user_gedcom_setting($user_id, $ged_id, 'canedit')==$EDIT_OPTION) {
- echo 'selected="selected" ';
- }
- echo '>', $desc, '</option>';
- }
- echo '</select>',
- '</td>',
- //Relationship path
- '<td>';
- $varname = 'RELATIONSHIP_PATH_LENGTH'.$ged_id;
- echo '<select name="', $varname, '" id="', $varname, '" class="relpath" />';
- for ($n=0; $n<=10; ++$n) {
- echo
- '<option value="', $n, '"',
- get_user_gedcom_setting($user_id, $ged_id, 'RELATIONSHIP_PATH_LENGTH')==$n ? ' selected="selected"' : '',
- '>',
- $n ? $n : WT_I18N::translate('No'),
- '</option>';
- }
- echo '</select>',
- '</td>',
- '</tr>';
- }
- ?>
- </table>
- </td>
- </tr>
- <tr>
- <td colspan="4">
- <input type="submit" value="<?php echo WT_I18N::translate('Update user account'); ?>" />
- <input type="button" value="<?php echo WT_I18N::translate('Back'); ?>" onclick="window.location='<?php echo "admin_users.php?action=listusers&amp;filter={$filter}&amp;usrlang={$usrlang}"; ?>';"/>
- </td>
- </tr>
- </table>
- </form>
- <?php
- print_footer();
- exit;
-}
-
-echo WT_JS_START;
-?>
- jQuery(document).ready(function(){
- var oTable = jQuery('#list').dataTable( {
- "oLanguage": {
- "sLengthMenu": '<?php echo /* I18N: %s is a placeholder for listbox containing numeric options */ WT_I18N::translate('Display %s records', '<select><option value="10">10</option><option value="20">20</option><option value="30">30</option><option value="40">40</option><option value="50">50</option><option value="-1">'.WT_I18N::translate('All').'</option></select>'); ?>',
- "sZeroRecords": '<?php echo WT_I18N::translate('No records to display');?>',
- "sInfo": '<?php echo /* I18N: %s' are placeholders for numbers */ WT_I18N::translate('Showing %1$s to %2$s of %3$s', '_START_', '_END_', '_TOTAL_'); ?>',
- "sInfoEmpty": '<?php echo /* I18N: %s' are placeholders for numbers */ WT_I18N::translate('Showing %1$s to %2$s of %3$s', '0', '0', '0'); ?>',
- "sInfoFiltered": '<?php echo /* I18N: %s is a placeholder for numbers */ WT_I18N::translate('(filtered from %s total entries)', '_MAX_'); ?>',
- "sSearch": '<?php echo WT_I18N::translate('Search');?>:',
- "oPaginate": {
- "sFirst": '<?php echo WT_I18N::translate_c('first page', 'first');?>',
- "sLast": '<?php echo WT_I18N::translate('last');?>',
- "sNext": '<?php echo WT_I18N::translate('next');?>',
- "sPrevious": '<?php echo WT_I18N::translate('previous');?>'
- }
- },
- "bProcessing" : true,
- "bServerSide" : true,
- "sAjaxSource" : "<?php echo WT_SCRIPT_NAME.'?action=loadrows'; ?>",
- "bJQueryUI": true,
- "bAutoWidth":false,
- "iDisplayLength": 10,
- "sPaginationType": "full_numbers",
- "aaSorting": [[2,'asc']],
- "aoColumns": [
- /* details */ { bSortable:false, sClass:"icon-open" },
- /* user-id */ { bVisible:false },
- /* user_name */ null,
- /* real_name */ null,
- /* email */ null,
- /* email link */ { bSortable:false },
- /* language */ null,
- /* registered (sort) */ { bVisible:false },
- /* registered */ { iDataSort:7 },
- /* last_login (sort) */ { bVisible:false },
- /* last_login */ { iDataSort:9 },
- /* verified */ null,
- /* approved */ null,
- /* delete */ { bSortable:false }
- ]
- });
-
- /* When clicking on the +/- icon, we expand/collapse the details block */
- jQuery('#list tbody td.icon-close').live('click', function () {
- var nTr=this.parentNode;
- jQuery(this).removeClass("icon-close");
- oTable.fnClose(nTr);
- jQuery(this).addClass("icon-open");
- });
- jQuery('#list tbody td.icon-open').live('click', function () {
- var nTr=this.parentNode;
- jQuery(this).removeClass("icon-open");
- var aData=oTable.fnGetData(nTr);
- jQuery.get("<?php echo WT_SCRIPT_NAME.'?action=load1row&user_id='; ?>"+aData[1], function(data) {
- oTable.fnOpen(nTr, data, "details");
- });
- jQuery(this).addClass("icon-close");
- });
-
- });
-<?php
-echo WT_JS_END;
-
-//-- echo out a list of the current users
-if ($action == "listusers") {
- echo
- '<table id="list">',
- '<thead>',
- '<tr>',
- '<th style="margin:0 -2px 1px 1px; padding:3px 0 4px;"> </th>',
- '<th> user-id </th>',
- '<th>', WT_I18N::translate('User name'), '</th>',
- '<th>', WT_I18N::translate('Real name'), '</th>',
- '<th>', WT_I18N::translate('Email'), '</th>',
- '<th> </th>', /* COLSPAN does not work? */
- '<th>', WT_I18N::translate('Language'), '</th>',
- '<th> date_registered </th>',
- '<th>', WT_I18N::translate('Date registered'), '</th>',
- '<th> last_login </th>',
- '<th>', WT_I18N::translate('Last logged in'), '</th>',
- '<th>', WT_I18N::translate('Verified'), '</th>',
- '<th>', WT_I18N::translate('Approved'), '</th>',
- '<th> </th>',
- '</tr>',
- '</thead>',
- '<tbody>',
- '</tbody>',
- '</table>';
- print_footer();
- exit;
-}
-
// -- echo out the form to add a new user
// NOTE: WORKING
-if ($action == "createform") {
+switch ($action) {
+case 'createform':
init_calendar_popup();
?>
<script type="text/javascript">
@@ -913,13 +591,8 @@ if ($action == "createform") {
</table>
</form>
<?php
- print_footer();
- exit;
-}
-
-// Cleanup users and user rights
-//NOTE: WORKING
-if ($action == "cleanup") {
+ break;
+case 'cleanup':
?>
<form name="cleanupform" method="post" action="admin_users.php&action=cleanup2">
<table id="clean" class="<?php echo $TEXT_DIRECTION; ?>">
@@ -986,11 +659,8 @@ if ($action == "cleanup") {
<input type="button" value="<?php echo WT_I18N::translate('Back'); ?>" onclick="window.location='admin_users.php';"/>
</p>
</form><?php
- print_footer();
- exit;
-}
-// NOTE: No table parts
-if ($action == "cleanup2") {
+ break;
+case 'cleanup2':
foreach (get_all_users() as $user_id=>$user_name) {
$var = "del_".str_replace(array(".", "-", " "), array("_", "_", "_"), $user_name);
if (safe_POST($var)=='1') {
@@ -1030,5 +700,97 @@ if ($action == "cleanup2") {
}
}
}
+ break;
+case 'listusers':
+default:
+ echo
+ '<table id="list">',
+ '<thead>',
+ '<tr>',
+ '<th style="margin:0 -2px 1px 1px; padding:3px 0 4px;"> </th>',
+ '<th> user-id </th>',
+ '<th>', WT_I18N::translate('User name'), '</th>',
+ '<th>', WT_I18N::translate('Real name'), '</th>',
+ '<th>', WT_I18N::translate('Email'), '</th>',
+ '<th> </th>', /* COLSPAN does not work? */
+ '<th>', WT_I18N::translate('Language'), '</th>',
+ '<th> date_registered </th>',
+ '<th>', WT_I18N::translate('Date registered'), '</th>',
+ '<th> last_login </th>',
+ '<th>', WT_I18N::translate('Last logged in'), '</th>',
+ '<th>', WT_I18N::translate('Verified'), '</th>',
+ '<th>', WT_I18N::translate('Approved'), '</th>',
+ '<th> </th>',
+ '</tr>',
+ '</thead>',
+ '<tbody>',
+ '</tbody>',
+ '</table>';
+ echo WT_JS_START;
+ ?>
+ jQuery(document).ready(function(){
+ var oTable = jQuery('#list').dataTable( {
+ "oLanguage": {
+ "sLengthMenu": '<?php echo /* I18N: %s is a placeholder for listbox containing numeric options */ WT_I18N::translate('Display %s records', '<select><option value="10">10</option><option value="20">20</option><option value="30">30</option><option value="40">40</option><option value="50">50</option><option value="-1">'.WT_I18N::translate('All').'</option></select>'); ?>',
+ "sZeroRecords": '<?php echo WT_I18N::translate('No records to display');?>',
+ "sInfo": '<?php echo /* I18N: %s' are placeholders for numbers */ WT_I18N::translate('Showing %1$s to %2$s of %3$s', '_START_', '_END_', '_TOTAL_'); ?>',
+ "sInfoEmpty": '<?php echo /* I18N: %s' are placeholders for numbers */ WT_I18N::translate('Showing %1$s to %2$s of %3$s', '0', '0', '0'); ?>',
+ "sInfoFiltered": '<?php echo /* I18N: %s is a placeholder for numbers */ WT_I18N::translate('(filtered from %s total entries)', '_MAX_'); ?>',
+ "sSearch": '<?php echo WT_I18N::translate('Search');?>:',
+ "oPaginate": {
+ "sFirst": '<?php echo WT_I18N::translate_c('first page', 'first');?>',
+ "sLast": '<?php echo WT_I18N::translate('last');?>',
+ "sNext": '<?php echo WT_I18N::translate('next');?>',
+ "sPrevious": '<?php echo WT_I18N::translate('previous');?>'
+ }
+ },
+ "bProcessing" : true,
+ "bServerSide" : true,
+ "sAjaxSource" : "<?php echo WT_SCRIPT_NAME.'?action=loadrows'; ?>",
+ "bJQueryUI": true,
+ "bAutoWidth":false,
+ "iDisplayLength": 10,
+ "sPaginationType": "full_numbers",
+ "aaSorting": [[2,'asc']],
+ "aoColumns": [
+ /* details */ { bSortable:false, sClass:"icon-open" },
+ /* user-id */ { bVisible:false },
+ /* user_name */ null,
+ /* real_name */ null,
+ /* email */ null,
+ /* email link */ { bSortable:false },
+ /* language */ null,
+ /* registered (sort) */ { bVisible:false },
+ /* registered */ { iDataSort:7 },
+ /* last_login (sort) */ { bVisible:false },
+ /* last_login */ { iDataSort:9 },
+ /* verified */ null,
+ /* approved */ null,
+ /* delete */ { bSortable:false }
+ ]
+ });
+
+ /* When clicking on the +/- icon, we expand/collapse the details block */
+ jQuery('#list tbody td.icon-close').live('click', function () {
+ var nTr=this.parentNode;
+ jQuery(this).removeClass("icon-close");
+ oTable.fnClose(nTr);
+ jQuery(this).addClass("icon-open");
+ });
+ jQuery('#list tbody td.icon-open').live('click', function () {
+ var nTr=this.parentNode;
+ jQuery(this).removeClass("icon-open");
+ var aData=oTable.fnGetData(nTr);
+ jQuery.get("<?php echo WT_SCRIPT_NAME.'?action=load1row&user_id='; ?>"+aData[1], function(data) {
+ oTable.fnOpen(nTr, data, "details");
+ });
+ jQuery(this).addClass("icon-close");
+ });
+
+ });
+ <?php
+ echo WT_JS_END;
+ break;
}
+
print_footer();