summaryrefslogtreecommitdiff
path: root/admin_users.php
diff options
context:
space:
mode:
authorfisharebest <fisharebest@gmail.com>2011-02-08 23:30:54 +0000
committerfisharebest <fisharebest@gmail.com>2011-02-08 23:30:54 +0000
commitb9755091f6b76a98f09c8847176b8f7b4a2a5001 (patch)
tree652464872cdffec33a0648507b6f6a156d752885 /admin_users.php
parent5830cf7128b87a16a2c531984be91d778504e620 (diff)
downloadwebtrees-b9755091f6b76a98f09c8847176b8f7b4a2a5001.tar.gz
webtrees-b9755091f6b76a98f09c8847176b8f7b4a2a5001.tar.bz2
webtrees-b9755091f6b76a98f09c8847176b8f7b4a2a5001.zip
User list - use AJAX to generate data.
Diffstat (limited to 'admin_users.php')
-rw-r--r--admin_users.php382
1 files changed, 151 insertions, 231 deletions
diff --git a/admin_users.php b/admin_users.php
index 7971a15f8e..287c4a6509 100644
--- a/admin_users.php
+++ b/admin_users.php
@@ -34,7 +34,7 @@ if (!WT_USER_IS_ADMIN) {
}
// Valid values for form variables
-$ALL_ACTIONS=array('cleanup', 'cleanup2', 'createform', 'createuser', 'deleteuser', 'edituser', 'edituser2', 'listusers');
+$ALL_ACTIONS=array('cleanup', 'cleanup2', 'createform', 'createuser', 'deleteuser', 'edituser', 'edituser2', 'listusers', 'loadrows', 'load1row');
$ALL_THEMES_DIRS=array();
foreach (get_theme_names() as $themename=>$themedir) {
$ALL_THEME_DIRS[]=$themedir;
@@ -89,16 +89,120 @@ $all_gedcoms = get_all_gedcoms();
//-- sorting by gedcom filename
asort($all_gedcoms);
-// Delete a user
-if ($action=='deleteuser') {
- // don't delete ourselves
+switch ($action) {
+case 'deleteuser':
+ // Delete a user - but don't delete ourselves!
$user_id=get_user_id($username);
if ($user_id!=WT_USER_ID) {
delete_user($user_id);
AddToLog("deleted user ->{$username}<-", 'auth');
}
- // User data is cached, so reload the page to ensure we're up to date
- header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH.WT_SCRIPT_NAME.'?action=listusers');
+ break;
+case 'loadrows':
+ // Generate an AJAX/JSON response for datatables to load a block of rows
+ $sSearch=safe_GET('sSearch');
+ if ($sSearch) {
+ $WHERE=
+ " WHERE".
+ " user_name LIKE CONCAT('%', ?, '%') OR " .
+ " real_name LIKE CONCAT('%', ?, '%') OR " .
+ " email LIKE CONCAT('%', ?, '%')";
+ $ARGS=array($sSearch, $sSearch, $sSearch);
+ } else {
+ $WHERE="";
+ $ARGS=array();
+ }
+ $iDisplayStart =(int)safe_GET('iDisplayStart');
+ $iDisplayLength=(int)safe_GET('iDisplayLength');
+ if ($iDisplayLength>0) {
+ $LIMIT=" LIMIT " . $iDisplayStart . ',' . $iDisplayLength;
+ } else {
+ $LIMIT="";
+ }
+ $iSortingCols=(int)safe_GET('iSortingCols');
+ if ($iSortingCols) {
+ $ORDER_BY=' ORDER BY ';
+ for ($i=0; $i<$iSortingCols; ++$i) {
+ // Datatables numbers columns 0, 1, 2, ...
+ // MySQL numbers columns 1, 2, 3, ...
+ switch (safe_GET('sSortDir_'.$i)) {
+ case 'asc':
+ $ORDER_BY.=(1+(int)safe_GET('iSortCol_'.$i)).' ASC ';
+ break;
+ case 'desc':
+ $ORDER_BY.=(1+(int)safe_GET('iSortCol_'.$i)).' DESC ';
+ break;
+ }
+ if ($i<$iSortingCols-1) {
+ $ORDER_BY.=',';
+ }
+ }
+ } else {
+ $ORDER_BY='';
+ }
+
+ $sql=
+ "SELECT SQL_CACHE SQL_CALC_FOUND_ROWS '', u.user_id, user_name, real_name, email, us1.setting_value, us2.setting_value, us2.setting_value, us3.setting_value, us3.setting_value, us4.setting_value, us5.setting_value".
+ " FROM `##user` u".
+ " LEFT JOIN `##user_setting` us1 ON (u.user_id=us1.user_id AND us1.setting_name='language')".
+ " LEFT JOIN `##user_setting` us2 ON (u.user_id=us2.user_id AND us2.setting_name='reg_timestamp')".
+ " LEFT JOIN `##user_setting` us3 ON (u.user_id=us3.user_id AND us3.setting_name='sessiontime')".
+ " LEFT JOIN `##user_setting` us4 ON (u.user_id=us4.user_id AND us4.setting_name='verified')".
+ " LEFT JOIN `##user_setting` us5 ON (u.user_id=us5.user_id AND us5.setting_name='verified_by_admin')".
+ $WHERE.
+ $ORDER_BY.
+ $LIMIT;
+
+ // This becomes a JSON list, not array, so need to fetch with numeric keys.
+ $aaData=WT_DB::prepare($sql)->execute($ARGS)->fetchAll(PDO::FETCH_NUM);
+
+ // Reformat various columns for display
+ foreach ($aaData as &$aData) {
+ // $aData[0] is a dummy column for the expand-details icon
+ // $aData[1] is the user ID
+ $aData[2]=edit_field_inline('user-user_name-'.$aData[1], $aData[2]);
+ $aData[3]=edit_field_inline('user-real_name-'.$aData[1], $aData[3]);
+ $aData[4]=edit_field_inline('user-email-'. $aData[1], $aData[4]);
+ $aData[5]=edit_field_language_inline('user_setting-langugage-'.$aData[1], $aData[5]);
+ // $aData[6] is the sortable registration timestamp
+ $aData[7]=format_timestamp($aData[7]);
+ if (date("U") - $aData[6] > 604800 && !$aData[10]) {
+ $aData[7]='<span class="red">'.$aData[7].'</span>';
+ }
+ // $aData[8] is the sortable last-login timestamp
+ if ($aData[8]) {
+ $aData[9]=format_timestamp($aData[8]).'<br />'.WT_I18N::time_ago(time() - $aData[8]);
+ } else {
+ $aData[9]=WT_I18N::translate('Never');
+ }
+ $aData[10]=edit_field_yes_no_inline('user_setting-verified-'. $aData[1], $aData[10]);
+ $aData[11]=edit_field_yes_no_inline('user_setting-verified_by_admin-'.$aData[1], $aData[11]);
+ }
+
+ // Total filtered/unfiltered rows
+ $iTotalDisplayRecords=WT_DB::prepare("SELECT FOUND_ROWS()")->fetchOne();
+ $iTotalRecords=WT_DB::prepare("SELECT COUNT(*) FROM `##user`")->fetchOne();
+
+ header('Content-type: application/json');
+ echo json_encode(array( // See http://www.datatables.net/usage/server-side
+ 'sEcho' =>(int)safe_GET('sEcho'),
+ 'iTotalRecords' =>$iTotalRecords,
+ 'iTotalDisplayRecords'=>$iTotalDisplayRecords,
+ 'aaData' =>$aaData
+ ));
+ exit;
+case 'load1row':
+ // Generate an AJAX response for datatables to load expanded row
+ $user_id=(int)safe_GET('user_id');
+ header('Content-type: text/html; charset=UTF-8');
+ echo '<dl>';
+ echo '<dt>', WT_I18N::translate('Administrator'), '</dt>';
+ echo '<dd>', edit_field_yes_no_inline('user_setting-canadmin-'.$user_id, get_user_setting($user_id, 'canadmin')), '</dd>';
+ echo '<dt>', WT_I18N::translate('Preferred contact method'), '</dt>';
+ echo '<dd>', get_user_setting($user_id, 'canadmin'), '</dd>';
+ echo '<dt>TODO ...</dt>';
+ echo '<dd>... the rest of the settings</dd>';
+ echo '</dd>';
exit;
}
@@ -434,24 +538,9 @@ if ($action=="edituser") {
exit;
}
+echo WT_JS_START;
?>
-<script type="text/javascript">
jQuery(document).ready(function(){
- /* Insert a 'details' column to the table */
- var nCloneTh = document.createElement( 'th' );
- var nCloneTd = document.createElement( 'td' );
- nCloneTh.innerHTML = '<?php echo WT_I18N::translate('Details'); ?>';
- nCloneTd.innerHTML = '<img class="open" src="./themes/_administration/images/open.png">';
- nCloneTd.className = "open-close";
-
- jQuery('#list thead tr').each( function () {
- this.insertBefore( nCloneTh, this.childNodes[0] );
- } );
-
- jQuery('#list tbody tr').each( function () {
- this.insertBefore( nCloneTd.cloneNode( true ), this.childNodes[0] );
- } );
-
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>'); ?>',
@@ -467,244 +556,75 @@ if ($action=="edituser") {
"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": [
- /* 0-Details */ { "bSortable": false },
- /* 1-Message */ null,
- /* 2-Name */ null,
- /* 3-User */ null,
- /* 4-Language */ { "bVisible": false },
- /* 5-Role. */ { "bVisible": false },
- /* 6-Auto_approve */ { "bVisible": false },
- /* 7-Theme */ { "bVisible": false },
- /* 8-Default_tab */ { "bVisible": false },
- /* 9-Date registered */ { "iDataSort": 10 },
- /* 10-REG_DATE */ { "bVisible": false },
- /* 11-Last login */ { "iDataSort": 12 },
- /* 12-LOG_DATE */ { "bVisible": false },
- /* 13-Verified */ null,
- /* 14-Approved */ null,
- /* 15-Delete */ null
+ /* details */ { bSortable:false, sClass:"icon-open" },
+ /* user-id */ { bVisible:false },
+ /* user_name */ null,
+ /* real_name */ null,
+ /* email */ null,
+ /* language */ null,
+ /* registered (sort) */ { bVisible:false },
+ /* registered */ { iDataSort:6 },
+ /* last_login (sort) */ { bVisible:false },
+ /* last_login */ { iDataSort:8 },
+ /* verified */ null,
+ /* approved */ null
]
});
- /* Add event listener for opening and closing details
- * Note that the indicator for showing which row is open is not controlled by DataTables,
- * rather it is done here
- */
- jQuery('#list tbody td img.open').live('click', function () {
- var nTr = this.parentNode.parentNode;
- if ( this.src.match('close') )
- {
- /* This row is already open - close it */
- this.src = "./themes/_administration/images/open.png";
- oTable.fnClose( nTr );
- }
- else
- {
- /* Open this row */
- this.src = "./themes/_administration/images/close.png";
- oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
- }
- } );
+ /* 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");
+ });
});
-
- /* Formating function for details row */
- function fnFormatDetails ( oTable, nTr )
- {
- var aData = oTable.fnGetData( nTr );
- var sOut = '<table class="details"><tr>';
- sOut += '<th>'+'<?php echo WT_I18N::translate('Language');?>'+': </th><td>'+aData[4]+'</td>';
- sOut += '<th>'+'<?php echo WT_I18N::translate('Role');?>'+': </th><td>'+aData[5]+'</td>';
- sOut += '<th>'+'<?php echo WT_I18N::translate('Auto accept changes');?>'+': </th><td>'+aData[6]+'</td>';
- sOut += '<th>'+'<?php echo WT_I18N::translate('Theme');?>'+': </th><td>'+aData[7]+'</td>';
- sOut += '<th>'+'<?php echo WT_I18N::translate('Default tab');?>'+': </th><td>'+aData[8]+'</td>';
- sOut += '</tr></table>';
-
- return sOut;
- }
-</script>
<?php
-
-/* echo TEMPORARILY DISABLED UNTIL FISHAREBEST HAS TIME TO COMPLETE ADDING IN-LINE EDITING TO THE TABLE
- '<table id="user-list" width="100%">',
- '<thead>',
- '<tr>',
- '<th>User ID</th>',
- '<th>', WT_I18N::translate('Real name'), '</th>',
- '<th>', WT_I18N::translate('User name'), '</th>',
- '<th>', WT_I18N::translate('Email'), '</th>',
- '<th>', WT_I18N::translate('Language'), '</th>',
- '<th>', WT_I18N::translate('Date registered'), '</th>',
- '<th>', WT_I18N::translate('Last logged in'), '</th>',
- '<th>', WT_I18N::translate('Verified'), '</th>',
- '<th>', WT_I18N::translate('Approved'), '</th>',
- '</tr>',
- '</thead>',
- '<tbody>',
- '</tbody>',
- '</table>',
- WT_JS_START,
- 'jQuery(document).ready(function() {',
- ' jQuery("#user-list").dataTable( {',
- ' "oLanguage": {',
- ' "sLengthMenu": "Display <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>All</option></select> records"',
- ' },',
- ' "bAutoWidth":false,',
- ' "aaSorting": [[ 1, "asc" ]],',
- ' "bProcessing": true,',
- ' "bServerSide": true,',
- ' "sAjaxSource": "', WT_SERVER_NAME, WT_SCRIPT_PATH, 'load.php?src=user_list",',
- ' "aaSorting": [[ 1, "asc" ]],',
- ' "bJQueryUI": true,',
- ' "sPaginationType": "full_numbers"',
- ' } );',
- '} );',
- WT_JS_END;
-*/
+echo WT_JS_END;
//-- echo out a list of the current users
if ($action == "listusers") {
-ob_start();
- $users = get_all_users();
-
- // Then show the users
echo
'<table id="list">',
'<thead>',
'<tr>',
- '<th>', WT_I18N::translate('Message'), '</th>',
- '<th>', WT_I18N::translate('Real name'), '</th>',
+ '<th>', WT_I18N::translate('Details'), '</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>', WT_I18N::translate('Language'), '</th>',
- '<th>', WT_I18N::translate('Role'), '</th>',
- '<th>', WT_I18N::translate('Automatically approve changes made by this user'), '</th>',
- '<th>', WT_I18N::translate('Theme'), '</th>',
- '<th>', WT_I18N::translate('Default tab to show on individual page'), '</th>',
+ '<th> date_registered </th>',
'<th>', WT_I18N::translate('Date registered'), '</th>',
- '<th> REG_DATE </th>',
+ '<th> last_login </th>',
'<th>', WT_I18N::translate('Last logged in'), '</th>',
- '<th> LOG_DATE </th>',
'<th>', WT_I18N::translate('Verified'), '</th>',
'<th>', WT_I18N::translate('Approved'), '</th>',
- '<th>', WT_I18N::translate('Delete'), '</th>',
'</tr>',
'</thead>',
- '<tbody>';
- foreach($users as $user_id=>$user_name) {
- echo "<tr><td>";
- if ($user_id!=WT_USER_ID && get_user_setting($user_id, 'contactmethod')!='none') {
- echo "<a href=\"javascript:;\" onclick=\"return message('", $user_name, "');\"><div class=\"icon-email\">&nbsp;</div></a>";
- } else {
- echo '&nbsp;';
- }
- echo '</td>';
- $userName = getUserFullName($user_id);
- echo "<td><a class=\"icon-edit\" href=\"admin_users.php?action=edituser&amp;username={$user_name}&amp;filter={$filter}&amp;usrlang={$usrlang}&amp;ged={$ged}\" title=\"", WT_I18N::translate('Edit'), "\">", $userName, '</a>';
- if (get_user_setting($user_id, 'canadmin')) {
- echo '<div class="warning">', WT_I18N::translate('Administrator'), '</div>';
- }
- echo "</td>";
- if (get_user_setting($user_id, "comment_exp")) {
- if ((strtotime(get_user_setting($user_id, "comment_exp")) != "-1") && (strtotime(get_user_setting($user_id, "comment_exp")) < time("U")))
- echo '<td class="red">', $user_name;
- else echo '<td>', $user_name;
- }
- else echo '<td>', $user_name;
- if (get_user_setting($user_id, "comment")) {
- $tempTitle = PrintReady(get_user_setting($user_id, "comment"));
- echo '<img class="adminicon" align="top" alt="', $tempTitle, '" title="', $tempTitle, '" src="images/notes.png" />';
- }
- echo "</td>\n";
- echo '<td>', Zend_Locale::getTranslation(get_user_setting($user_id, 'language'), 'language', WT_LOCALE), '</td>';
- echo '<td>';
- echo "<ul>";
- foreach ($all_gedcoms as $ged_id=>$ged_name) {
- $role=get_user_gedcom_setting($user_id, $ged_id, 'canedit');
- switch ($role) {
- case 'admin':
- case 'accept':
- echo '<li class="warning">', $ALL_EDIT_OPTIONS[$role];
- break;
- case 'edit':
- case 'access':
- case 'none':
- echo '<li>', $ALL_EDIT_OPTIONS[$role];
- break;
- default:
- echo '<li>', $ALL_EDIT_OPTIONS['none'];
- break;
- }
- $uged = get_user_gedcom_setting($user_id, $ged_id, 'gedcomid');
- if ($uged) {
- echo ' <a href="individual.php?pid=', $uged, '&amp;ged=', rawurlencode($ged_name), '">', WT_I18N::translate('%s', get_gedcom_setting($ged_id, 'title')), '</a></li>';
- } else {
- echo ' ', $ged_name, '</li>';
- }
- }
- echo "</ul>";
- echo '</td>';
- echo '<td>';
- if (get_user_setting($user_id, 'auto_accept')) echo WT_I18N::translate('Yes');
- else echo WT_I18N::translate('No');
- echo '</td>';
- echo '<td>';
- if (get_user_setting($user_id, 'theme')) {
- foreach (get_theme_names() as $themename=>$themedir) {
- if ($themedir == get_user_setting($user_id, 'theme')) echo $themename;
- }
- } else { echo WT_I18N::translate('&lt;default theme&gt;');}
- echo '</td>';
- echo '<td>';
- $tab = get_user_setting($user_id, 'defaulttab');
- if ($tab===0) {
- echo WT_I18N::translate('&lt;default tab&gt;');
- } else {
- foreach (WT_Module::getActiveTabs() as $module) {
- if ($tab == $module->getName()) {
- echo $module->getTitle();
- break;
- }
- }
- }
- echo '</td>';
- if (((date("U") - (int)get_user_setting($user_id, 'reg_timestamp')) > 604800) && !get_user_setting($user_id, 'verified'))
- echo '<td class="red">';
- else echo '<td>';
- echo format_timestamp((int)get_user_setting($user_id, 'reg_timestamp'));
- echo '</td>';
- echo '<td>', get_user_setting($user_id, 'reg_timestamp'), '</td>'; //for sorting only
- echo '<td>';
- if ((int)get_user_setting($user_id, 'reg_timestamp') > (int)get_user_setting($user_id, 'sessiontime')) {
- echo WT_I18N::translate('Never'), '<br />', WT_I18N::time_ago(time() - (int)get_user_setting($user_id, 'reg_timestamp'));
- } else {
- echo format_timestamp((int)get_user_setting($user_id, 'sessiontime')), '<br />', WT_I18N::time_ago(time() - (int)get_user_setting($user_id, 'sessiontime'));
- }
- echo '</td>';
- echo '<td>', get_user_setting($user_id, 'sessiontime'), '</td>'; //for sorting only
- echo '<td class="center">';
- if (get_user_setting($user_id, 'verified')) echo WT_I18N::translate('Yes');
- else echo WT_I18N::translate('No');
- echo '</td>',
- '<td class="center">';
- if (get_user_setting($user_id, 'verified_by_admin')) echo WT_I18N::translate('Yes');
- else echo WT_I18N::translate('No');
- echo '</td>',
- '<td>';
- if (WT_USER_ID!=$user_id)
- echo "<a href=\"admin_users.php?action=deleteuser&amp;username=", rawurlencode($user_name)."&amp;usrlang={$usrlang}&amp;ged=", rawurlencode($ged), "\" onclick=\"return confirm('", WT_I18N::translate('Are you sure you want to delete the user'), " $user_name');\"><div class=\"icon-delete\">&nbsp;</div></a>";
- echo '</td>',
- '</tr>';
- }
- echo '</tbody>',
+ '<tbody>',
+ '</tbody>',
'</table>';
print_footer();
-ob_flush();
exit;
}