Commit b97813ea authored by Elliot Pahl's avatar Elliot Pahl Committed by Elliot Pahl
Browse files

Only create suspendform if is set. Set to i in pieform, NOT id.

parent d8f3c3f8
......@@ -488,87 +488,89 @@ function institution_cancel_submit() {
redirect('/admin/users/institutions.php');
}
$_institution = get_record('institution', 'name', $institution);
// Suspension controls
$suspended = $_institution->suspended;
if (empty($suspended)) {
$suspendformdef = array(
'name' => 'institution_suspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $institution,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('suspendinstitution','admin'),
'description' => get_string('suspendinstitutiondescription','admin'),
),
)
);
$suspendform = pieform($suspendformdef);
}
else {
$suspendformdef = array(
'name' => 'institution_unsuspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $institution,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('unsuspendinstitution','admin'),
'description' => get_string('unsuspendinstitutiondescription','admin'),
),
)
);
$suspendform = pieform($suspendformdef);
// Create a second forms for unsuspension to go in the suspend message.
// This keeps the HTML IDs unique
$suspendformdef['name'] = 'institution_unsuspend_top';
$suspendformdef['renderer'] = 'oneline';
$suspendformdef['successcallback'] = 'institution_unsuspend_submit';
$suspendform_top = pieform($suspendformdef);
}
if ($institution) {
function institution_suspend_submit(Pieform $form, $values) {
global $SESSION, $USER;
if (!$USER->get('admin')) {
$SESSION->add_error_msg(get_string('errorwhilesuspending', 'admin'));
}
else {
set_field('institution', 'suspended', 1, 'name', $values['i']);
$SESSION->add_ok_msg(get_string('institutionsuspended', 'admin'));
}
redirect('/admin/users/institutions.php?i=' . $values['i']);
}
$smarty->assign('suspendform', $suspendform);
if (isset($suspendform_top)) {
$smarty->assign('suspendform_top', $suspendform_top);
}
function institution_unsuspend_submit(Pieform $form, $values) {
global $SESSION, $USER;
if (!$USER->get('admin')) {
$SESSION->add_error_msg(get_string('errorwhileunsuspending', 'admin'));
}
else {
set_field('institution', 'suspended', 0, 'name', $values['i']);
$SESSION->add_ok_msg(get_string('institutionunsuspended', 'admin'));
}
redirect('/admin/users/institutions.php?i=' . $values['i']);
}
if ($suspended) {
$smarty->assign('suspended', get_string('suspendedinstitutionmessage', 'admin'));
}
$_institution = get_record('institution', 'name', $institution);
// Suspension controls
$suspended = $_institution->suspended;
if (empty($suspended)) {
$suspendformdef = array(
'name' => 'institution_suspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'i' => array(
'type' => 'hidden',
'value' => $institution,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('suspendinstitution','admin'),
'description' => get_string('suspendinstitutiondescription','admin'),
),
)
);
function institution_suspend_submit(Pieform $form, $values) {
global $SESSION, $USER;
if (!$USER->get('admin')) {
$SESSION->add_error_msg(get_string('errorwhilesuspending', 'admin'));
$suspendform = pieform($suspendformdef);
}
else {
set_field('institution', 'suspended', 1, 'name', $values['id']);
$SESSION->add_ok_msg(get_string('institutionsuspended', 'admin'));
$suspendformdef = array(
'name' => 'institution_unsuspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'i' => array(
'type' => 'hidden',
'value' => $institution,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('unsuspendinstitution','admin'),
'description' => get_string('unsuspendinstitutiondescription','admin'),
),
)
);
$suspendform = pieform($suspendformdef);
// Create a second forms for unsuspension to go in the suspend message.
// This keeps the HTML IDs unique
$suspendformdef['name'] = 'institution_unsuspend_top';
$suspendformdef['renderer'] = 'oneline';
$suspendformdef['successcallback'] = 'institution_unsuspend_submit';
$suspendform_top = pieform($suspendformdef);
}
redirect('/admin/users/institutions.php?i=' . $values['id']);
}
function institution_unsuspend_submit(Pieform $form, $values) {
global $SESSION, $USER;
if (!$USER->get('admin')) {
$SESSION->add_error_msg(get_string('errorwhileunsuspending', 'admin'));
$smarty->assign('suspendform', $suspendform);
if (isset($suspendform_top)) {
$smarty->assign('suspendform_top', $suspendform_top);
}
else {
set_field('institution', 'suspended', 0, 'name', $values['id']);
$SESSION->add_ok_msg(get_string('institutionunsuspended', 'admin'));
if ($suspended) {
$smarty->assign('suspended', get_string('suspendedinstitutionmessage', 'admin'));
}
redirect('/admin/users/institutions.php?i=' . $values['id']);
}
$smarty->assign('heading', get_string('admininstitutions', 'admin'));
......
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