Commit 1d4b0228 authored by Son Nguyen's avatar Son Nguyen
Browse files

Registration reason textbox is missing (bug #1030664)



Display the 'registration reason' box if there is only one institution
available to register and its approval is required

Change-Id: Iad8d0b645943e68cdec17787c5c245554a8bf36b
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent ae3de44c
......@@ -1910,7 +1910,7 @@ function auth_generate_registration_form($formname, $authname='internal', $goto)
$registerconfirm = array();
$reason = false;
if (count($institutions) > 1) {
if (count($institutions) > 0) {
$options = array();
foreach ($institutions as $institution) {
$options[$institution->name] = $institution->displayname;
......@@ -1927,7 +1927,9 @@ function auth_generate_registration_form($formname, $authname='internal', $goto)
}
}
natcasesort($options);
if (count($institutions) > 1) {
array_unshift($options, get_string('chooseinstitution', 'mahara'));
}
$elements['institution'] = array(
'type' => 'select',
'title' => get_string('institution'),
......@@ -1937,19 +1939,6 @@ function auth_generate_registration_form($formname, $authname='internal', $goto)
)
);
}
else if ($institutions) { // Only one option - probably mahara ('No Institution') but that's not certain
$institution = array_shift($institutions);
$elements['institution'] = array(
'type' => 'hidden',
'value' => $institution->name
);
$reason = (bool) $institution->registerconfirm;
if ($reason) {
$authinstance = get_record('auth_instance', 'institution', $institution->name, 'authname', $authname);
$auth = AuthFactory::create($authinstance->id);
$reason = !$auth->weautocreateusers;
}
}
else {
return;
}
......@@ -2023,15 +2012,25 @@ function auth_generate_registration_form($formname, $authname='internal', $goto)
return array($form, $registerconfirm);
}
function auth_generate_registration_form_js($form, $registerconfirm) {
function auth_generate_registration_form_js($aform, $registerconfirm) {
// The javascript needs to refer to field names, but they are obfuscated in this form,
// so construct and build the form in separate steps, so we can get the field names.
$form = new Pieform($form);
$form = new Pieform($aform);
$institutionid = $form->get_name() . '_' . $form->hashedfields['institution'];
$reasonid = $form->get_name() . '_' . $form->hashedfields['reason'];
$formhtml = $form->build();
if (count($registerconfirm) == 1) {
$js = '
$j(function() {
$j("#' . $reasonid . '_container").removeClass("js-hidden");
$j("#' . $reasonid . '_container textarea").removeClass("js-hidden");
$j("#' . $reasonid . '_container").next("tr.textarea").removeClass("js-hidden");
});
';
}
else {
$js = '
var registerconfirm = ' . json_encode($registerconfirm) . ';
$j(function() {
......@@ -2049,6 +2048,7 @@ function auth_generate_registration_form_js($form, $registerconfirm) {
});
});
';
}
return array($formhtml, $js);
}
......
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