Commit 724a1eff authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge "Add dropdown on institution members page for last institution"

parents e29f0a13 18d5b56f
......@@ -173,7 +173,7 @@ if (count($authinstances) > 1) {
}
$tags = get_column('usr_tag', 'tag', 'usr', $user->id);
$tags = get_column_sql('SELECT tag FROM {usr_tag} WHERE usr = ? AND NOT tag ' . db_ilike() . " 'lastinstitution:%'", array($user->id));
$elements['tags'] = array(
'defaultvalue' => $tags,
......
......@@ -56,22 +56,37 @@ else if (!empty($institution)) {
// Show either requesters, members, or nonmembers on the left hand side
$usertype = param_alpha('usertype', 'requesters');
$usertypeselectorelements = array(
'usertype' => array(
'type' => 'select',
'title' => get_string('userstodisplay', 'admin'),
'options' => array(
'requesters' => get_string('institutionusersrequesters', 'admin'),
'nonmembers' => get_string('institutionusersnonmembers', 'admin'),
'lastinstitution' => get_string('institutionuserslastinstitution', 'admin'),
'members' => get_string('institutionusersmembers', 'admin'),
'invited' => get_string('institutionusersinvited', 'admin'),
),
'defaultvalue' => $usertype,
),
);
if ($usertype == 'lastinstitution') {
// Change intitution dropdown to show possible last insitutions
$lastinstitution = param_alphanum('lastinstitution', false);
$usertypeselectorelements['lastinstitution'] = get_institution_selector(false);
$usertypeselectorelements['lastinstitution']['title'] = get_string('lastinstitution', 'admin');
if ($lastinstitution) {
$usertypeselectorelements['lastinstitution']['defaultvalue'] = $lastinstitution;
}
else {
$lastinstitution = $usertypeselectorelements['lastinstitution']['defaultvalue'];
}
}
$usertypeselector = pieform(array(
'name' => 'usertypeselect',
'elements' => array(
'usertype' => array(
'type' => 'select',
'title' => get_string('userstodisplay', 'admin'),
'options' => array(
'requesters' => get_string('institutionusersrequesters', 'admin'),
'nonmembers' => get_string('institutionusersnonmembers', 'admin'),
'members' => get_string('institutionusersmembers', 'admin'),
'invited' => get_string('institutionusersinvited', 'admin'),
),
'defaultvalue' => $usertype
),
'institution' => $institutionelement,
)
'elements' => $usertypeselectorelements,
));
if ($usertype == 'requesters') {
......@@ -93,6 +108,18 @@ if ($usertype == 'requesters') {
);
$submittext = get_string('removeusers', 'admin');
}
else if ($usertype == 'lastinstitution') {
// LHS shows Users who have left institution "BLAH"
// RHS shows users to be invited
$lastinstitutionobj = new Institution($lastinstitution);
$userlistelement = array(
'title' => get_string('inviteuserstojoin', 'admin'),
'lefttitle' => get_string('userswhohaveleft', 'admin', $lastinstitutionobj->displayname),
'righttitle' => get_string('userstobeinvited', 'admin'),
'searchparams' => array('member' => 0, 'invitedby' => 0, 'requested' => 0, 'lastinstitution' => $lastinstitution),
);
$submittext = get_string('inviteusers', 'admin');
}
else if ($usertype == 'nonmembers') {
// Behaviour depends on whether we allow users to have > 1 institution
// LHS either shows all nonmembers or just users with no institution
......@@ -127,17 +154,13 @@ $userlistelement['searchparams']['institution'] = $institution;
$userlistform = array(
'name' => 'institutionusers',
'elements' => array(
'institution' => $institutionelement,
'users' => $userlistelement,
'usertype' => array(
'type' => 'hidden',
'value' => $usertype,
'rules' => array('regex' => '/^[a-z]+$/')
),
'institution' => array(
'type' => 'hidden',
'value' => $institution,
'rules' => array('regex' => '/^[a-zA-Z0-9]+$/')
),
'submit' => array(
'type' => 'submit',
'value' => $submittext
......@@ -145,13 +168,21 @@ $userlistform = array(
)
);
if ($usertype == 'lastinstitution') {
$userlistform['elements']['lastinstitution'] = array(
'type' => 'hidden',
'value' => $lastinstitution,
'rules' => array('regex' => '/^[a-zA-Z0-9]+$/'),
);
}
if ($usertype == 'requesters') {
$userlistform['elements']['reject'] = array(
'type' => 'submit',
'value' => get_string('declinerequests', 'admin'),
);
}
if ($usertype == 'nonmembers' && $USER->get('admin')) {
if (($usertype == 'nonmembers' || $usertype == 'lastinstitution') && $USER->get('admin')) {
$userlistform['elements']['add'] = array(
'type' => 'submit',
'value' => get_string('addmembers', 'admin'),
......@@ -164,14 +195,14 @@ function institutionusers_submit(Pieform $form, $values) {
global $SESSION, $USER;
$inst = $values['institution'];
$url = '/admin/users/institutionusers.php?usertype=' . $values['usertype'] . '&institution=' . $inst;
$url = '/admin/users/institutionusers.php?usertype=' . $values['usertype'] . (isset($values['lastinstitution']) ? '&lastinstitution=' . $values['lastinstitution'] : '') . '&institution=' . $inst;
if (empty($inst) || !$USER->can_edit_institution($inst)) {
$SESSION->add_error_msg(get_string('notadminforinstitution', 'admin'));
redirect($url);
}
$dataerror = false;
if (!in_array($values['usertype'], array('requesters', 'members', 'nonmembers', 'invited'))
if (!in_array($values['usertype'], array('requesters', 'members', 'lastinstitution', 'nonmembers', 'invited'))
|| !is_array($values['users'])) {
$dataerror = true;
} else {
......@@ -244,16 +275,23 @@ function institutionusers_submit(Pieform $form, $values) {
$wwwroot = get_config('wwwroot');
$js = <<< EOF
function reloadUsers() {
var last = '';
if ($('usertypeselect_lastinstitution')) {
last = '&lastinstitution=' + $('usertypeselect_lastinstitution').value;
}
var inst = '';
if ($('usertypeselect_institution')) {
inst = '&institution=' + $('usertypeselect_institution').value;
if ($('institutionusers_institution')) {
inst = '&institution=' + $('institutionusers_institution').value;
}
window.location.href = '{$wwwroot}admin/users/institutionusers.php?usertype='+$('usertypeselect_usertype').value+inst;
window.location.href = '{$wwwroot}admin/users/institutionusers.php?usertype='+$('usertypeselect_usertype').value+last+inst;
}
addLoadEvent(function() {
connect($('usertypeselect_usertype'), 'onchange', reloadUsers);
if ($('usertypeselect_institution')) {
connect($('usertypeselect_institution'), 'onchange', reloadUsers);
if ($('usertypeselect_lastinstitution')) {
connect($('usertypeselect_lastinstitution'), 'onchange', reloadUsers);
}
if ($('institutionusers_institution')) {
connect($('institutionusers_institution'), 'onchange', reloadUsers);
}
});
EOF;
......
......@@ -34,6 +34,7 @@ require_once('searchlib.php');
$params = new StdClass;
$params->query = trim(param_variable('query', ''));
$params->institution = param_alphanum('institution', null);
$params->lastinstitution = param_alphanum('lastinstitution', null);
$params->requested = param_integer('requested', null);
$params->invitedby = param_integer('invitedby', null);
$params->member = param_integer('member', null);
......
......@@ -96,6 +96,7 @@ $string['institutions'] = 'Institutions';
$string['institutiondetails'] = 'Institution Details';
$string['institutionauth'] = 'Institution Authorities';
$string['institutionsdescription'] = 'Install and manage installed institutions';
$string['lastinstitution'] = 'Previous Institution';
$string['adminnotifications'] = 'Admin Notifications';
$string['adminnotificationsdescription'] = 'Overview of how administrators receive system notifications';
$string['uploadcsv'] = 'Add Users by CSV';
......@@ -694,6 +695,7 @@ $string['institutionmemberspagedescription'] = 'On this page you can see users w
$string['institutionusersinstructionsrequesters'] = 'The list of users on the left shows all users who have asked to join your institution. You can use the search box to reduce the number of users displayed. If you would like to add users to the institution, or decline their membership requests, first move some users to the right hand side by selecting one or more users and then clicking on the right arrow. The "Add members" button will add all the users on the right to the institution. The "Decline requests" button will remove the membership requests of the users on the right.';
$string['institutionusersinstructionsnonmembers'] = 'The list of users on the left shows all users who are not yet members of your institution. You can use the search box to reduce the number of users displayed. To invite users to join the institution, first move some users to the right hand side by selecting one or more users and then clicking on the right arrow to move those users to the list on the right. The "Invite Users" button will send invitations to all the users on the right. These users will not be associated with the institution until they accept the invitation.';
$string['institutionusersinstructionslastinstitution'] = 'The list of users on the left shows all users who are not yet members of your institution and who have left the selected institution. You can use the search box to reduce the number of users displayed. To invite users to join the institution, first move some users to the right hand side by selecting one or more users and then clicking on the right arrow to move those users to the list on the right. The "Invite Users" button will send invitations to all the users on the right. These users will not be associated with the institution until they accept the invitation.';
$string['institutionusersinstructionsmembers'] = 'The list of users on the left shows all members of the institution. You can use the search box to reduce the number of users displayed. To remove users from the institution, first move some users to the right hand side by selecting one or more users on the left and then clicking on the right arrow. The users you selected will move to the right hand side. The "Remove Users" button will remove all the users on the right from the institution. The users on the left will remain in the institution.';
$string['institutionusersinstructionsinvited'] = 'The list of users on the left shows all users who have been sent an invitation to join the institution and who have not yet accepted or declined. You can use the search box to reduce the number of users displayed. To revoke invitations to the institution, first move some users to the right hand side by selecting one or more users on the left and then clicking on the right arrow. The users you selected will move to the right hand side. The "Revoke Invitations" button will remove all invitations to the users on the right. The users on the left will retain their invitations and will still be able to join at any time.';
......@@ -708,6 +710,7 @@ $string['institutionstudentiddescription'] = 'An optional identifier specific to
$string['userstodisplay'] = 'Users to display:';
$string['institutionusersrequesters'] = 'People who have requested institution membership';
$string['institutionusersnonmembers'] = 'People who have not requested membership yet';
$string['institutionuserslastinstitution'] = 'People who have left a given institution';
$string['institutionusersmembers'] = 'People who are already institution members';
$string['institutionusersinvited'] = 'People who have been invited';
......@@ -717,6 +720,7 @@ $string['userstobeadded'] = 'Users to be added as members';
$string['userstoaddorreject'] = 'Users to be added/rejected';
$string['addmembers'] = 'Add members';
$string['inviteuserstojoin'] = 'Invite users to join the institution';
$string['userswhohaveleft'] = 'Users who have left institution %s';
$string['Non-members'] = 'Non-members';
$string['userstobeinvited'] = 'Users to be invited';
$string['inviteusers'] = 'Invite Users';
......
......@@ -471,13 +471,6 @@ class Institution {
array($user->id)
);
insert_record(
'usr_tag',
(object) array(
'usr' => $user->id,
'tag' => 'lastinstitution:' . strtolower($this->displayname),
)
);
insert_record(
'usr_tag',
(object) array(
......
......@@ -90,7 +90,7 @@ function search_user($query_string, $limit, $offset = 0, $data = array()) {
function get_institutional_admin_search_results($search, $limit) {
$institution = new StdClass;
$institution->name = $search->institution;
foreach (array('member', 'requested', 'invitedby') as $p) {
foreach (array('member', 'requested', 'invitedby', 'lastinstitution') as $p) {
$institution->{$p} = $search->{$p};
}
$results = institutional_admin_user_search($search->query, $institution, $limit);
......
......@@ -584,6 +584,10 @@ class PluginSearchInternal extends PluginSearch {
}
}
}
if (!is_null($institution->lastinstitution)) {
$where .= " AND t.tag = ?";
$values[] = 'lastinstitution:' . $institution->lastinstitution;
}
$count = get_field_sql('SELECT COUNT(*) ' . $sql . $where, $values);
......
Markdown is supported
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