Commit ee0a174a authored by Richard Mansfield's avatar Richard Mansfield

Allow admins to close the site manually

Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 559562d1
......@@ -39,6 +39,7 @@ if (get_config('installed')) {
else {
define('TITLE', get_string('installation', 'admin'));
}
require_once('pieforms/pieform.php');
require(get_config('libroot') . 'upgrade.php');
require(get_config('libroot') . 'registration.php');
......@@ -56,6 +57,22 @@ if (!get_config('registration_lastsent')) {
$register = register_site();
}
$closed = get_config('siteclosedbyadmin');
$closeform = pieform(array(
'name' => 'close_site',
'renderer' => 'oneline',
'elements' => array(
'close' => array(
'type' => 'hidden',
'value' => !$closed,
),
'submit' => array(
'type' => 'submit',
'value' => get_string($closed ? 'Open' : 'Close', 'admin'),
),
),
));
$smarty = smarty();
$smarty->assign('PAGEHEADING', hsc(get_string('administration', 'admin')));
......@@ -66,6 +83,20 @@ if (isset($register)) {
$smarty->assign('register', $register);
}
$smarty->assign('closed', $closed);
$smarty->assign('closeform', $closeform);
$smarty->display('admin/index.tpl');
function close_site_submit(Pieform $form, $values) {
global $closed;
if (!$closed && $values['close']) {
set_config('siteclosedbyadmin', 1);
}
else if ($closed && !$values['close']) {
set_config('siteclosedbyadmin', 0);
}
redirect(get_config('wwwroot') . 'admin/index.php');
}
?>
......@@ -348,13 +348,14 @@ function auth_setup () {
}
$cfgsiteclosed = get_config('siteclosed');
if (
($siteclosed && !$cfgsiteclosed)
|| (!$siteclosed && $cfgsiteclosed)) {
set_config('siteclosed', $siteclosed);
if ($disablelogin && $siteclosed) {
set_config('disablelogin', 1);
if ($siteclosed && !$cfgsiteclosed || !$siteclosed && $cfgsiteclosed) {
// If the admin closed the site manually, open it automatically
// when an upgrade is successful.
if ($cfgsiteclosed && get_config('siteclosedbyadmin')) {
set_config('siteclosedbyadmin', false);
}
set_config('siteclosed', $siteclosed);
set_config('disablelogin', $disablelogin);
}
// Check the time that the session is set to log out. If the user does
......
......@@ -233,22 +233,23 @@ if (!defined('INSTALLER')) {
auth_setup();
}
if (get_config('siteclosed')) {
if ($USER->admin) {
if (get_config('disablelogin')) {
$USER->logout();
}
else if (!defined('INSTALLER')) {
redirect('/admin/upgrade.php');
}
$siteclosedforupgrade = get_config('siteclosed');
if ($siteclosedforupgrade && $USER->admin) {
if (get_config('disablelogin')) {
$USER->logout();
}
if (!$USER->admin) {
if ($USER->is_logged_in()) {
$USER->logout();
}
if (!defined('HOME') && !defined('INSTALLER')) {
redirect();
}
else if (!defined('INSTALLER')) {
redirect('/admin/upgrade.php');
}
}
$siteclosed = $siteclosedforupgrade || get_config('siteclosedbyadmin');
if ($siteclosed && !$USER->admin) {
if ($USER->is_logged_in()) {
$USER->logout();
}
if (!defined('HOME') && !defined('INSTALLER')) {
redirect();
}
}
......
......@@ -130,6 +130,14 @@ $string['registeryourmaharasitedetail'] = '
<p>If you tick &quot;send weekly updates&quot;, Mahara will automatically send an update to mahara.org once a week with your updated information.</p>
<p>Registering will remove this notice. You will be able to change whether you send weekly updates on the <a href="%sadmin/site/options.php">site options</a> page.</p>';
// Close site
$string['Close'] = 'Close';
$string['closesite'] = 'Close Site';
$string['closesitedetail'] = 'You may close the site to everyone except administrators. This will be useful when preparing for a database upgrade. Only administrators will be able to log in until you either reopen the site, or an upgrade is successfully completed.';
$string['Open'] = 'Open';
$string['reopensite'] = 'Reopen Site';
$string['reopensitedetail'] = 'Your site is closed. Site administrators may stay logged in until an upgrade is detected.';
// Site options
$string['adminsonly'] = 'Administrators only';
$string['allowpublicviews'] = 'Allow public views';
......
......@@ -393,13 +393,12 @@ EOF;
$smarty->assign('SESSKEY', $USER->get('sesskey'));
$smarty->assign_by_ref('JAVASCRIPT', $javascript_array);
$smarty->assign_by_ref('HEADERS', $headers);
if (get_config('siteclosed')) {
if (get_config('disablelogin')) {
$smarty->assign('SITECLOSED', get_string('siteclosedlogindisabled', 'mahara', get_config('wwwroot') . 'admin/upgrade.php'));
}
else {
$smarty->assign('SITECLOSED', get_string('siteclosed'));
}
$siteclosedforupgrade = get_config('siteclosed');
if ($siteclosedforupgrade && get_config('disablelogin')) {
$smarty->assign('SITECLOSED', get_string('siteclosedlogindisabled', 'mahara', get_config('wwwroot') . 'admin/upgrade.php'));
}
else if ($siteclosedforupgrade || get_config('siteclosedbyadmin')) {
$smarty->assign('SITECLOSED', get_string('siteclosed'));
}
if ((!isset($extraconfig['pagehelp']) || $extraconfig['pagehelp'] !== false)
......
......@@ -39,6 +39,7 @@
}
/* ADMIN HOME */
#close-site,
#register-site {
text-align: left;
font-weight: normal;
......
......@@ -33,6 +33,7 @@
</div>
{/if}
<h3>{str tag=configsite section=admin}</h3>
<ul>
<li><strong><a href="{$WWWROOT}admin/site/options.php">{str tag=siteoptions section=admin}</a></strong> - {str tag=siteoptionsdescription section=admin}</li>
......@@ -68,4 +69,15 @@
</ul>
</div>
<div class="message" id="close-site">
{if $closed}
<h3>{str tag=reopensite section=admin}</h3>
{str tag=reopensitedetail section=admin}
{else}
<h3>{str tag=closesite section=admin}</h3>
{str tag=closesitedetail section=admin}
{/if}
{$closeform}
</div>
{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