Commit 69b28b54 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add institution options to account prefs page

parent 24559ee2
......@@ -141,18 +141,6 @@ $prefsform = array(
'elements' => $elements
);
$smarty = smarty();
$smarty->assign('form', pieform($prefsform));
$smarty->assign('INLINEJAVASCRIPT', "
function clearPasswords(form, data) {
formSuccess(form, data);
$('accountprefs_oldpassword').value = '';
$('accountprefs_password1').value = '';
$('accountprefs_password2').value = '';
}");
$smarty->display('account/index.tpl');
function accountprefs_validate(Pieform $form, $values) {
global $USER;
......@@ -196,4 +184,199 @@ function accountprefs_submit(Pieform $form, $values) {
}
// Institution forms
$institutions = get_records_assoc('institution', '', '', '', 'name,displayname');
// For all institutions the user is already a member of, create a
// button to leave the institution
$member = $USER->get('institutions');
if (!empty($member)) {
$elements = array();
foreach ($member as $i) {
$elements[] = array(
'type' => 'submit',
'name' => 'leave_' . $i->institution,
'title' => get_string('youareamemberof', 'mahara',
$institutions[$i->institution]->displayname),
'value' => get_string('leaveinstitution')
);
unset($institutions[$i->institution]);
}
$memberform = pieform(array(
'name' => 'leaveinstitution',
'method' => 'post',
'renderer' => 'table',
'plugintype' => 'core',
'pluginname' => 'account',
'elements' => $elements
));
} else {
$memberform = null;
}
function leaveinstitution_submit(Pieform $form, $values) {
global $USER;
foreach ($values as $k => $v) {
if (preg_match('/^leave\_([a-z0-9]+)$/', $k, $m)) {
$institution = $m[1];
break;
}
}
if (!empty($institution)) {
$USER->leave_institution($institution);
}
redirect(get_config('wwwroot') . 'account/index.php');
}
// List all institutions the user has requested membership, with a
// cancel request button
$requested = get_column('usr_institution_request', 'institution',
'usr', $USER->id, 'confirmedusr', 1);
if (!empty($requested)) {
$elements = array();
foreach ($requested as $i) {
$elements[] = array(
'type' => 'submit',
'name' => 'cancelrequest_' . $i,
'title' => get_string('youhaverequestedmembershipof', 'mahara',
$institutions[$i]->displayname),
'value' => get_string('cancelrequest')
);
unset($institutions[$i]);
}
$requestedform = pieform(array(
'name' => 'cancelrequest',
'method' => 'post',
'renderer' => 'table',
'plugintype' => 'core',
'pluginname' => 'account',
'elements' => $elements
));
} else {
$requestedform = null;
}
function cancelrequest_submit(Pieform $form, $values) {
global $USER;
foreach ($values as $k => $v) {
if (preg_match('/^cancelrequest\_([a-z0-9]+)$/', $k, $m)) {
$institution = $m[1];
break;
}
}
if (!empty($institution)) {
delete_records('usr_institution_request', 'usr', $USER->id, 'institution', $institution);
handle_event('updateuser', $USER->id);
}
redirect(get_config('wwwroot') . 'account/index.php');
}
// List all institutions the user has been invited to join, with a
// confirm membership button
$invited = get_column('usr_institution_request', 'institution',
'usr', $USER->id, 'confirmedinstitution', 1);
if (!empty($invited)) {
$elements = array();
foreach ($invited as $i) {
$elements[] = array(
'type' => 'submit',
'name' => 'confirminvite_' . $i,
'title' => get_string('youhavebeeninvitedtojoin', 'mahara',
$institutions[$i]->displayname),
'value' => get_string('confirminvitation')
);
unset($institutions[$i]);
}
$invitedform = pieform(array(
'name' => 'confirminvite',
'method' => 'post',
'renderer' => 'table',
'plugintype' => 'core',
'pluginname' => 'account',
'elements' => $elements
));
} else {
$invitedform = null;
}
function confirminvite_submit(Pieform $form, $values) {
global $USER;
foreach ($values as $k => $v) {
if (preg_match('/^confirminvite\_([a-z0-9]+)$/', $k, $m)) {
$institution = $m[1];
break;
}
}
if (!empty($institution) && count_records('usr_institution_request', 'usr', $USER->id,
'institution', $institution, 'confirmedinstitution', 1)) {
$USER->join_institution($institution);
}
redirect(get_config('wwwroot') . 'account/index.php');
}
unset($institutions['mahara']);
// Request institution membership button for the remaining insitutions
if (!empty($institutions)) {
$options = array();
foreach ($institutions as $i) {
$options[$i->name] = $i->displayname;
}
$joinform = pieform(array(
'name' => 'requestmembership',
'method' => 'post',
'renderer' => 'table',
'plugintype' => 'core',
'pluginname' => 'account',
'elements' => array(
'institution' => array(
'type' => 'select',
'title' => get_string('joininstitution'),
'collapseifoneoption' => false,
'options' => $options,
'defaultvalue' => key($options),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('requestmembership'),
),
)
));
} else {
$joinform = null;
}
function requestmembership_submit(Pieform $form, $values) {
global $USER;
if (!empty($values['institution'])) {
$USER->add_institution_request($values['institution']);
}
redirect(get_config('wwwroot') . 'account/index.php');
}
$smarty = smarty();
$smarty->assign('form', pieform($prefsform));
$smarty->assign('memberform', $memberform);
$smarty->assign('requestedform', $requestedform);
$smarty->assign('invitedform', $invitedform);
$smarty->assign('joinform', $joinform);
$smarty->assign('INLINEJAVASCRIPT', "
function clearPasswords(form, data) {
formSuccess(form, data);
$('accountprefs_oldpassword').value = '';
$('accountprefs_password1').value = '';
$('accountprefs_password2').value = '';
}");
$smarty->display('account/index.tpl');
?>
......@@ -353,6 +353,14 @@ class User {
}
}
public function leave_institution($institution) {
if ($institution != 'mahara' && $this->in_institution($institution)) {
require_once('institution.php');
$institution = new Institution($institution);
$institution->removeMember($this);
}
}
public function in_institution($institution, $role = null) {
$institutions = $this->get('institutions');
return isset($institutions[$institution])
......
......@@ -277,6 +277,13 @@ $string['preferences'] = 'Preferences';
$string['activityprefs'] = 'Activity preferences';
$string['changepassword'] = 'Change password';
$string['notifications'] = 'Notifications';
$string['institutionmembership'] = 'Institution membership';
$string['youareamemberof'] = 'You are a member of %s';
$string['leaveinstitution'] = 'Leave institution';
$string['youhaverequestedmembershipof'] = 'You have requested membership of %s';
$string['cancelrequest'] = 'Cancel request';
$string['joininstitution'] = 'Join institution';
$string['requestmembership'] = 'Request membership';
// my views
$string['accessstartdate'] = 'Access start date';
......
......@@ -5,5 +5,11 @@
<h2>{str tag="preferences"}</h2>
{$form}
<h4>{str tag="institutionmembership"}</h4>
{$memberform}
{$requestedform}
{$inviteform}
{$joinform}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
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