Commit 21d79193 authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon

Bug 1558361: Remove window.opener() from institution auth config

behatnotneeded - should be covered by existing tests

Change-Id: Ia4592c9bd261c978dc911999e81f906fa0b13450
parent bdd98def
......@@ -14,15 +14,8 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('institutions', 'admin'));
require_once('pieforms/pieform.php');
require_once(get_config('docroot') . '/lib/htmloutput.php');
define('MENUITEM', 'manageinstitutions/institutions');
// CHECK FOR CANCEL BEFORE THE 'REQUIRED' PARAMS:
$cancel = param_boolean('c');
if ($cancel) {
execute_javascript_and_close();
}
// NOT CANCELLING? OK - OTHER PARAMS THEN:
$institution = param_variable('i');
$plugin = param_variable('p');
$add = param_boolean('add');
......@@ -80,7 +73,7 @@ if ($institution && $plugin) {
$form['elements']['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('submit'), get_string('cancel')),
'goto' => 'addauthority.php?c=1'
'goto' => get_config('wwwroot') . 'admin/users/institutions.php?i=' . $institution
);
$form = pieform($form);
......@@ -112,21 +105,9 @@ function auth_config_submit(Pieform $form, $values) {
$classname = 'PluginAuth' . ucfirst(strtolower($plugin));
safe_require('auth', strtolower($plugin));
try {
$values = call_static_method($classname, 'save_instance_config_options', $values, $form);
} catch (Exception $e) {
log_info($e->getMessage());
log_info($e->getTrace());
$SESSION->add_error_msg("An error occurred while processing this form: " . $e->getMessage());
redirect('/admin/users/addauthority.php?'. $_SERVER['QUERY_STRING']);
}
$values = call_static_method($classname, 'save_instance_config_options', $values, $form);
if (array_key_exists('create', $values) && $values['create']) {
execute_javascript_and_close('window.opener.addAuthority('.$values['instance'].', "'.addslashes($values['instancename']).'", "'.$values['authname'].'");');
} else {
execute_javascript_and_close();
}
exit;
redirect(get_config('wwwroot') . 'admin/users/institutions.php?i=' . $values['institution']);
}
$js = <<<EOF
......@@ -134,18 +115,10 @@ function authloginmsgVisibility() {
// If Parent authority is 'None'
if ($('auth_config_parent').value != 0) {
addElementClass('auth_config_authloginmsg_container', 'hidden');
addElementClass(nextSiblingTR($('auth_config_authloginmsg_container')), 'hidden');
}
else {
removeElementClass('auth_config_authloginmsg_container', 'hidden');
removeElementClass(nextSiblingTR($('auth_config_authloginmsg_container')), 'hidden');
}
}
function nextSiblingTR(node) {
while (node.nextSibling.tagName != 'TR') {
node = node.nextSibling;
}
return node.nextSibling;
}
var ssoAllOptions = {
'updateuserinfoonlogin': 'theyssoin',
......
......@@ -77,3 +77,18 @@ function pieform_element_authlist_get_value(Pieform $form, $element) {
return $value;
}
function pieform_element_authlist_js() {
return <<<EOF
// Since this menu is just a dummy selector, don't let it trigger the form change checker.
jQuery(document).on('pieform_postinit', function(event, form) {
jQuery('form[name=' + form.data.name + ']').find('select#dummySelect').unbind('change.changechecker');
});
EOF;
}
function pieform_element_authlist_get_headdata() {
$result = '<script type="application/javascript">' . pieform_element_authlist_js() . "</script>";
return array($result);
}
\ No newline at end of file
......@@ -107,22 +107,6 @@ function print_extractprogress_footer($message, $next) {
<?php
}
function execute_javascript_and_close($js='') {
echo '<html>
<head>
<title>You may close this window</title>
<script language="Javascript">
function closeMe() {
'.$js.'
window.close();
}
</script>
</head>
<body onLoad="closeMe();" style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center;">This window should close automatically</body>'.
"\n</html>";
exit;
}
function print_meta_redirect($url, $title = 'Mahara Redirect') {
print '<html><head><meta http-equiv="Refresh" content="0; url=' . $url . '">';
print "<title>$title</title>";
......
......@@ -148,6 +148,10 @@ function Pieform(data) {//{{{
connect(self.data.name, 'onsubmit', self.processForm);
self.connectSubmitButtons();
// Hook for pieform elements that need to execute Javascript
// *after* the Pieform has been initialized.
jQuery(document).triggerHandler('pieform_postinit', self);
}//}}}
this.processForm = function(e) {//{{{
......
{include file="microheader.tpl"}
{include file="header.tpl"}
<h3>{str tag="adminauthorities" section="admin"}</h3>
{$auth_imap_form|safe}
{include file="microfooter.tpl"}
{include file="footer.tpl"}
......@@ -23,7 +23,7 @@
{if !$institution->site}</a>{/if}</td>
<td class="center">{if $institution->suspended}<span class="suspended">{str tag="suspendedinstitution" section=admin}</span>{/if}</td>
<td class="controls">
<form action="" method="post">
<form action="" method="get">
<input type="hidden" name="i" value="{$institution->name}">
<input type="hidden" name="edit" value=1>
<input type="image" name="edit" title="{str tag="edit"}" src="{theme_url filename="images/btn_edit.png"}" alt="{str(tag=editspecific arg1=$institution->displayname)|escape:html|safe}">
......
......@@ -136,7 +136,7 @@
}
if (requiresConfig(selectedPlugin) == 1) {
window.open('addauthority.php?add=1&i={{$institution}}&p=' + selectedPlugin, 'addinstance', 'height=600,width=800,screenx=250,screenY=200,scrollbars=1');
window.location = 'addauthority.php?add=1&i={{$institution}}&p=' + selectedPlugin;
return;
}
......@@ -153,7 +153,7 @@
function editinstance(id, plugin) {
if (requiresConfig(plugin)) {
window.open('addauthority.php?id='+id+'&edit=1&i={{$institution}}&p=' + plugin, 'editinstance', 'height=520,width=550,screenx=250,screenY=200,scrollbars=1');
window.location = 'addauthority.php?id='+id+'&edit=1&i={{$institution}}&p=' + plugin;
} else {
alert({{$noauthpluginconfigoptions|safe}});
}
......@@ -171,10 +171,6 @@
}
instanceArray.push(id);
rebuildInstanceList(instanceArray);
if (typeof formchangemanager !== 'undefined') {
var form = jQuery('div#instanceList').closest('form')[0];
formchangemanager.setFormState(form, FORM_CHANGED);
}
replaceChildNodes('messages');
}
......
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