Commit ae28f4a7 authored by Hugh Davenport's avatar Hugh Davenport Committed by Gerrit Code Review
Browse files

Add logged in filter to admin search



Added form entries
Added strings
Fixed links for non-js enabled browsers
Added function for js enabled browsers

Change-Id: I24887725d0be67c1bfab30338fb3cadf96ec362e
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 412f5437
......@@ -49,7 +49,7 @@ if (!$USER->get('admin')) {
$users = get_records_sql_assoc('
SELECT
u.id, u.username, u.email, u.firstname, u.lastname, u.suspendedcusr, u.authinstance, u.studentid,
u.preferredname, CHAR_LENGTH(u.password) AS haspassword, aru.remoteusername AS remoteuser
u.preferredname, CHAR_LENGTH(u.password) AS haspassword, aru.remoteusername AS remoteuser, u.lastlogin
FROM {usr} u
LEFT JOIN {auth_remote_user} aru ON u.id = aru.localusr AND u.authinstance = aru.authinstance
WHERE id IN (' . join(',', array_fill(0, count($userids), '?')) . ')
......
......@@ -71,7 +71,7 @@ if (!$USER->get('admin') && !$USER->get('staff')) {
$users = get_records_sql_assoc('
SELECT
u.id, u.username, u.email, u.firstname, u.lastname, u.studentid, u.preferredname, u.urlid,
aru.remoteusername AS remoteuser
aru.remoteusername AS remoteuser, u.lastlogin
FROM {usr} u
LEFT JOIN {auth_remote_user} aru ON u.id = aru.localusr AND u.authinstance = aru.authinstance
WHERE id IN (' . join(',', array_fill(0, count($userids), '?')) . ')
......@@ -125,10 +125,10 @@ if ($selected == 'users') {
$userlisthtml = $smarty->fetch('admin/users/userlist.tpl');
if ($USER->get('admin') || $USER->is_institutional_admin()) {
$csvfields = array('username', 'email', 'firstname', 'lastname', 'studentid', 'preferredname', 'remoteuser');
$csvfields = array('username', 'email', 'firstname', 'lastname', 'studentid', 'preferredname', 'remoteuser', 'lastlogin');
}
else {
$csvfields = array('username', 'firstname', 'lastname', 'studentid', 'preferredname');
$csvfields = array('username', 'firstname', 'lastname', 'studentid', 'preferredname', 'lastlogin');
}
$USER->set_download_file(generate_csv($users, $csvfields), 'users.csv', 'text/csv');
......
......@@ -42,7 +42,7 @@ $search = (object) array(
'sortby' => param_alpha('sortby', 'firstname'),
'sortdir' => param_alpha('sortdir', 'asc'),
'loggedin' => param_alpha('loggedin', 'any'),
'loggedindate'=> param_variable('loggedindate', null),
'loggedindate'=> param_variable('loggedindate', strftime(get_string('strftimedatetimeshort'))),
);
$offset = param_integer('offset', 0);
......@@ -62,9 +62,40 @@ else {
);
}
$loggedintypes = array();
$loggedintypes[] = array('name' => 'any', 'string' => get_string('anyuser', 'admin'));
$loggedintypes[] = array('name' => 'ever', 'string' => get_string('usershaveloggedin', 'admin'));
$loggedintypes[] = array('name' => 'never', 'string' => get_string('usershaveneverloggedin', 'admin'));
$loggedintypes[] = array('name' => 'since', 'string' => get_string('usershaveloggedinsince', 'admin'));
$loggedintypes[] = array('name' => 'notsince', 'string' => get_string('usershavenotloggedinsince', 'admin'));
$calendar = array(
'name' => 'loggedindate',
'id' => 'loggedindate',
'tabindex' => false,
'type' => 'calendar',
'title' => get_string('date'),
'imagefile' => $THEME->get_url('images/calendar.gif'),
'defaultvalue' => strtotime($search->loggedindate),
'caloptions' => array(
'showsTime' => true,
'ifFormat' => get_string('strftimedatetimeshort'),
),
);
$calendarform = new Pieform(array(
'name' => 'loggedinform',
'elements' => array(
'loggedindate' => $calendar,
),
));
$calendarform->include_plugin('element', 'calendar');
$loggedindate = pieform_element_calendar($calendarform, $calendar);
$smarty = smarty(array('adminusersearch'));
$smarty->assign('search', $search);
$smarty->assign('limit', $limit);
$smarty->assign('loggedintypes', $loggedintypes);
$smarty->assign('loggedindate', $loggedindate);
$smarty->assign('alphabet', explode(',', get_string('alphabet')));
$smarty->assign('institutions', $institutions);
$smarty->assign('results', build_admin_user_search_results($search, $offset, $limit));
......
......@@ -33,7 +33,8 @@ function UserSearch() {
self.rewriteSetLimit();
self.selectusers = {};
self.rewriteCheckboxes();
self.params = {};
self.rewriteLoggedInFilter();
self.params = {'loggedindate' : $('loggedinform_loggedindate').value};
};
this.rewriteInitials = function() {
......@@ -195,6 +196,26 @@ function UserSearch() {
}
};
this.rewriteLoggedInFilter = function() {
connect($('loggedin'), 'onchange', function(e) {
e.stop();
var type = this.value;
self.params.loggedin = type;
if (type === 'since' || type === 'notsince') {
removeElementClass($('loggedindate_container'), 'js-hidden');
}
else {
addElementClass($('loggedindate_container'), 'js-hidden');
}
self.doSearch();
});
$('loggedinform_loggedindate').onchange = function(e) {
// Set handler directly so that calendar works
self.params.loggedindate = this.value;
self.doSearch();
};
};
addLoadEvent(self.init);
}
......
......@@ -995,3 +995,13 @@ $string['managegroupdescription'] = 'Use the form below to promote and demote ad
$string['userscandisabledevicedetection'] = 'Users can disable device detection';
$string['userscandisabledevicedetectiondescription'] = 'If checked, users will be allowed to disable mobile device detection when they are browsing this site.';
// Admin user search logged in filter
$string['loggedinfilter'] = 'Filter by login date:';
$string['anyuser'] = 'Any user';
$string['usershaveloggedin'] = 'Users have logged in';
$string['usershaveneverloggedin'] = 'Users have never logged in';
$string['usershaveloggedinsince'] = 'Users have logged in since';
$string['usershavenotloggedinsince'] = 'Users have not logged in since';
$string['lastlogin'] = 'Last login';
......@@ -310,7 +310,7 @@ function get_admin_user_search_results($search, $offset, $limit) {
function build_admin_user_search_results($search, $offset, $limit) {
global $USER, $THEME;
$wantedparams = array('query', 'f', 'l', 'sortby', 'sortdir');
$wantedparams = array('query', 'f', 'l', 'sortby', 'sortdir', 'loggedin', 'loggedindate');
$params = array();
foreach ($search as $k => $v) {
if (!in_array($k, $wantedparams)) {
......@@ -376,6 +376,12 @@ function build_admin_user_search_results($search, $offset, $limit) {
);
}
$cols['lastlogin'] = array(
'name' => get_string('lastlogin', 'admin'),
'sort' => true,
'template' => 'strftimedatetime.tpl',
);
$cols['select'] = array(
'headhtml' => '<a href="" id="selectall">' . get_string('All') . '</a>&nbsp;<a href="" id="selectnone">' . get_string('none') . '</a>',
'template' => 'admin/users/searchselectcolumn.tpl',
......
......@@ -320,7 +320,6 @@ input#register_register {
/* USERS > USER SEARCH */
#initials {
font-size: 1.1667em;
margin: 0 0 5px 0;
line-height: 2em;
}
......@@ -336,6 +335,10 @@ input#register_register {
.withselectedusers {
margin: 0;
float: right;
padding-top: 60px;
}
.searchform-gap {
height: 30px;
}
.searchform .institutions {
margin-left: 10px;
......
......@@ -55,6 +55,18 @@
{if $limit}
<input type="hidden" name="limit" id="limit" value="{$limit}">
{/if}
<div class="loggedin-filter">
<label for="loggedin">{str tag="loggedinfilter" section="admin"}</label>
<select name="loggedin" id="loggedin">
{foreach from=$loggedintypes item=t}
<option value="{$t['name']}"{if $search->loggedin === $t['name']} selected="selected"{/if}>{$t['string']}</option>
{/foreach}
</select>
<span id="loggedindate_container"{if !($search->loggedin == 'since' || $search->loggedin == 'notsince')} class="js-hidden"{/if}>
{$loggedindate|safe}
</span>
</div>
<div class="searchform-gap nojs-hidden-block"></div>
<div class="searchform">
<label>{str tag='Search' section='admin'}:</label>
<input type="text" name="query" id="query"{if $search->query} value="{$search->query}"{/if}>
......
......@@ -8,6 +8,7 @@
<th>{str tag=studentid}</th>
<th>{str tag=preferredname}</th>
{if $USER->get('admin') || $USER->is_institutional_admin()}<th>{str tag=remoteuser section=admin}</th>{/if}
<th>{str tag=lastlogin section=admin}</th>
</tr>
</thead>
<tbody>
......@@ -20,6 +21,7 @@
<td>{$user->studentid}</td>
<td>{$user->preferredname}</td>
{if $USER->get('admin') || $USER->is_institutional_admin()}<td>{if $user->hideemail}<span class="dull">({str tag=hidden})</span>{else}{$user->remoteuser}{/if}</td>{/if}
<td>{if $user->lastlogin}{$user->lastlogin|strtotime|format_date:'strftimedatetime'}{/if}</td>
</tr>
{/foreach}
</tbody>
......
......@@ -34,7 +34,7 @@
{if !$c.template}
{$r[$f]}
{else}
{include file=$c.template r=$r}
{include file=$c.template r=$r f=$f}
{/if}
</td>{/strip}
{/foreach}
......
{$time = $r.$f}
{if $time}
{$time|strtotime|format_date:'strftimedatetime'}
{/if}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment