Commit 848b36a3 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Institution admins can reject membership requests

parent 3cada273
......@@ -76,7 +76,7 @@ if ($usertype == 'requesters') {
$userlistelement = array(
'title' => get_string('addnewmembers', 'admin'),
'lefttitle' => get_string('usersrequested', 'admin'),
'righttitle' => get_string('userstobeadded', 'admin'),
'righttitle' => get_string('userstoaddorreject', 'admin'),
'searchparams' => array('requested' => 1),
);
$submittext = get_string('addmembers', 'admin');
......@@ -110,7 +110,7 @@ $userlistelement['searchparams']['limit'] = 100;
$userlistelement['searchparams']['query'] = '';
$userlistelement['searchparams']['institution'] = $institution;
$userlistform = pieform(array(
$userlistform = array(
'name' => 'institutionusers',
'elements' => array(
'users' => $userlistelement,
......@@ -129,7 +129,16 @@ $userlistform = pieform(array(
'value' => $submittext
)
)
));
);
if ($usertype == 'requesters') {
$userlistform['elements']['reject'] = array(
'type' => 'submit',
'value' => get_string('declinerequests', 'admin'),
);
}
$userlistform = pieform($userlistform);
function institutionusers_submit(Pieform $form, $values) {
global $SESSION, $USER;
......@@ -158,31 +167,39 @@ function institutionusers_submit(Pieform $form, $values) {
redirect($url);
}
if ($values['usertype'] == 'members') {
$action = 'removeMembers';
} else if ($values['usertype'] == 'requesters') {
$action = !empty($values['reject']) ? 'declineRequestFromUser' : 'addUserAsMember';
} else {
$action = 'inviteUser';
}
$institution = new Institution($values['institution']);
$maxusers = $institution->maxuseraccounts;
if (!empty($maxusers)) {
$members = $institution->countMembers();
if ($values['usertype'] == 'requesters' && $members + count($values['users']) >= $maxusers) {
if ($action == 'addUserAsMember' && $members + count($values['users']) >= $maxusers) {
$SESSION->add_error_msg(get_string('institutionuserserrortoomanyusers', 'admin'));
redirect($url);
}
if ($values['usertype'] == 'nonmembers'
if ($action == 'inviteUser'
&& $members + $institution->countInvites() + count($values['users']) >= $maxusers) {
$SESSION->add_error_msg(get_string('institutionuserserrortoomanyinvites', 'admin'));
redirect($url);
}
}
db_begin();
if ($values['usertype'] == 'members') {
if ($action == 'removeMembers') {
$institution->removeMembers($values['users']);
} else {
$update = $values['usertype'] == 'requesters' ? 'addUserAsMember' : 'inviteUser';
} else if (!empty($values['users'])) {
foreach ($values['users'] as $id) {
$institution->{$update}($id);
$institution->{$action}($id);
}
}
db_commit();
$SESSION->add_ok_msg(get_string('institutionusersupdated'.$values['usertype'], 'admin'));
$SESSION->add_ok_msg(get_string('institutionusersupdated_'.$action, 'admin'));
if (!$USER->get('admin') && !$USER->is_institutional_admin()) {
redirect(get_config('wwwroot'));
}
......
......@@ -344,6 +344,7 @@ $string['addnewmembers'] = 'Add new members';
$string['addnewmembersdescription'] = '';
$string['usersrequested'] = 'Users who have requested membership';
$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['Non-members'] = 'Non-members';
......@@ -353,10 +354,12 @@ $string['removeusersfrominstitution'] = 'Remove users from the institution';
$string['currentmembers'] = 'Current Members';
$string['userstoberemoved'] = 'Users to be removed';
$string['removeusers'] = 'Remove Users';
$string['declinerequests'] = 'Decline requests';
$string['institutionusersupdatedrequesters'] = 'Users added';
$string['institutionusersupdatedmembers'] = 'Users removed';
$string['institutionusersupdatednonmembers'] = 'Invitations sent';
$string['institutionusersupdated_addUserAsMember'] = 'Users added';
$string['institutionusersupdated_declineRequestFromUser'] = 'Requests declined';
$string['institutionusersupdated_removeMembers'] = 'Users removed';
$string['institutionusersupdated_inviteUser'] = 'Invitations sent';
$string['maxuseraccounts'] = 'Maximum User Accounts Allowed';
$string['maxuseraccountsdescription'] = 'The maximum number of user accounts that can be associated with the institution. If there is no limit, this field should be left blank.';
......
......@@ -372,6 +372,8 @@ $string['requestmembershipofaninstitution'] = 'Request membership of an institut
$string['optionalinstitutionid'] = 'Institution ID (optional)';
$string['institutionmemberconfirmsubject'] = 'Institution membership confirmation';
$string['institutionmemberconfirmmessage'] = 'You have been added as a member of %s.';
$string['institutionmemberrejectsubject'] = 'Institution membership request declined';
$string['institutionmemberrejectmessage'] = 'Your request for membership of %s was declined.';
$string['emailname'] = 'Mahara System'; // robot!
......
......@@ -293,6 +293,21 @@ class Institution {
}
}
public function declineRequestFromUser($userid) {
$lang = get_user_language($userid);
$message = (object) array(
'users' => array($userid),
'subject' => get_string_from_language($lang, 'institutionmemberrejectsubject'),
'message' => get_string_from_language($lang, 'institutionmemberrejectmessage', 'mahara', $this->displayname),
);
db_begin();
delete_records('usr_institution_request', 'usr', $userid, 'institution', $this->name,
'confirmedusr', 1);
activity_occurred('maharamessage', $message);
handle_event('updateuser', $userid);
db_commit();
}
public function inviteUser($user) {
$userid = is_object($user) ? $user->id : $user;
db_begin();
......
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