Commit fbe3a7e6 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow users to specify student id when requesting institution membership

parent b6800b4e
......@@ -339,11 +339,15 @@ if (!empty($institutions) &&
'elements' => array(
'institution' => array(
'type' => 'select',
'title' => get_string('requestmembershipofaninstitution'),
'collapseifoneoption' => false,
'options' => $options,
'defaultvalue' => key($options),
),
'studentid' => array(
'type' => 'text',
'title' => get_string('optionalinstitutionid'),
'defaultvalue' => $USER->studentid,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('sendrequest'),
......@@ -358,7 +362,7 @@ function requestmembership_submit(Pieform $form, $values) {
global $USER, $SESSION;
if (!empty($values['institution'])) {
if (get_field('institution', 'registerallowed', 'name', $values['institution'])) {
$USER->add_institution_request($values['institution']);
$USER->add_institution_request($values['institution'], $values['studentid']);
}
else {
$SESSION->add_error_msg(get_string('registrationnotallowed'));
......
......@@ -387,13 +387,13 @@ class User {
$this->set('admininstitutions', array_combine($institutions, $institutions));
}
public function add_institution_request($institution) {
public function add_institution_request($institution, $studentid = null) {
if (empty($institution) || $institution == 'mahara') {
return;
}
require_once('institution.php');
$institution = new Institution($institution);
$institution->addRequestFromUser($this);
$institution->addRequestFromUser($this, $studentid);
}
protected function reset_institutions() {
......
......@@ -293,6 +293,7 @@ $string['youhavebeeninvitedtojoin'] = 'You have been invited to join %s';
$string['confirminvitation'] = 'Confirm invitation';
$string['joininstitution'] = 'Join institution';
$string['requestmembershipofaninstitution'] = 'Request membership of an institution';
$string['optionalinstitutionid'] = 'Institution ID (optional)';
$string['institutionmemberconfirmsubject'] = 'Institution membership confirmation';
$string['institutionmemberconfirmmessage'] = 'You have been added as a member of %s.';
......
......@@ -227,12 +227,19 @@ class Institution {
}
$userinst = new StdClass;
$userinst->institution = $this->name;
if (!empty($user->studentid)) {
$studentid = get_field('usr_institution_request', 'studentid', 'usr', $user->id,
'institution', $this->name);
if (!empty($studentid)) {
$userinst->studentid = $studentid;
}
else if (!empty($user->studentid)) {
$userinst->studentid = $user->studentid;
}
$userinst->usr = $user->id;
$now = time();
$userinst->ctime = db_format_timestamp($now);
if (!empty($this->defaultmembershipperiod)) {
$userinst->expiry = db_format_timestamp(time() + $this->defaultmembershipperiod);
$userinst->expiry = db_format_timestamp($now + $this->defaultmembershipperiod);
}
$message = (object) array(
'users' => array($user->id),
......@@ -251,14 +258,14 @@ class Institution {
db_commit();
}
public function addRequestFromUser($user) {
public function addRequestFromUser($user, $studentid = null) {
$request = get_record('usr_institution_request', 'usr', $user->id, 'institution', $this->name);
if (!$request) {
$request = (object) array(
'usr' => $user->id,
'institution' => $this->name,
'confirmedusr' => 1,
'studentid' => $user->studentid,
'studentid' => empty($studentid) ? $user->studentid : $studentid,
'ctime' => db_format_timestamp(time())
);
$message = (object) array(
......
......@@ -826,19 +826,23 @@ p {
.maincontent #cancelrequest,
.maincontent #confirminvite,
.maincontent #requestmembership {
margin-top: 10px;
margin-top: 5px;
width: 450px;
}
.maincontent #leaveinstitution label,
.maincontent #cancelrequest label,
.maincontent #confirminvite label,
.maincontent #requestmembership label {
width: 450px;
padding-left: 10px;
padding-right: 10px;
}
.maincontent #leaveinstitution input.submit,
.maincontent #cancelrequest input.submit,
.maincontent #confirminvite input.submit,
.maincontent #requestmembership input.submit {
display: block !important;
}
.maincontent #requestmembership select {
margin-right: 10px;
}
acronym {
......
......@@ -10,6 +10,9 @@
{$memberform}
{$requestedform}
{$invitedform}
{$joinform}
{if !empty($joinform)}
<h6>{str tag="requestmembershipofaninstitution"}</h6>
{$joinform}
{/if}
{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