2009-11-01 10:55:31 +00:00
|
|
|
<?php
|
2006-08-18 07:25:17 +00:00
|
|
|
|
|
|
|
require_once('../config.php');
|
2006-09-02 13:14:57 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2006-08-19 01:37:38 +00:00
|
|
|
|
2009-05-06 09:11:07 +00:00
|
|
|
$section = required_param('section', PARAM_SAFEDIR);
|
|
|
|
$return = optional_param('return','', PARAM_ALPHA);
|
2007-12-19 17:35:20 +00:00
|
|
|
$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2007-12-23 11:53:31 +00:00
|
|
|
/// no guest autologin
|
|
|
|
require_login(0, false);
|
2012-07-23 14:33:02 +08:00
|
|
|
$PAGE->set_context(context_system::instance());
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/admin/settings.php', array('section' => $section));
|
2009-05-06 09:11:07 +00:00
|
|
|
$PAGE->set_pagetype('admin-setting-' . $section);
|
2009-12-27 12:02:04 +00:00
|
|
|
$PAGE->set_pagelayout('admin');
|
2009-10-12 05:39:32 +00:00
|
|
|
$PAGE->navigation->clear_cache();
|
2013-10-11 09:07:26 +02:00
|
|
|
navigation_node::require_admin_tree();
|
2006-08-18 07:25:17 +00:00
|
|
|
|
2009-01-20 23:53:34 +00:00
|
|
|
$adminroot = admin_get_root(); // need all settings
|
2009-05-06 09:11:07 +00:00
|
|
|
$settingspage = $adminroot->locate($section, true);
|
2006-08-18 07:25:17 +00:00
|
|
|
|
2009-05-06 09:11:07 +00:00
|
|
|
if (empty($settingspage) or !($settingspage instanceof admin_settingpage)) {
|
2016-03-06 19:29:18 +11:00
|
|
|
if (moodle_needs_upgrading()) {
|
|
|
|
redirect(new moodle_url('/admin/index.php'));
|
|
|
|
} else {
|
|
|
|
print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
|
|
|
|
}
|
2006-08-21 04:06:58 +00:00
|
|
|
die;
|
2006-08-19 01:37:38 +00:00
|
|
|
}
|
2006-08-18 07:25:17 +00:00
|
|
|
|
2009-05-06 09:11:07 +00:00
|
|
|
if (!($settingspage->check_access())) {
|
2008-05-30 21:36:57 +00:00
|
|
|
print_error('accessdenied', 'admin');
|
2006-08-21 04:06:58 +00:00
|
|
|
die;
|
2006-08-19 01:37:38 +00:00
|
|
|
}
|
2006-08-18 07:25:17 +00:00
|
|
|
|
2006-10-16 06:52:01 +00:00
|
|
|
/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
|
2006-10-12 03:31:48 +00:00
|
|
|
|
2006-10-16 06:52:01 +00:00
|
|
|
$statusmsg = '';
|
2007-12-19 17:35:20 +00:00
|
|
|
$errormsg = '';
|
2006-08-18 07:25:17 +00:00
|
|
|
|
2008-06-09 16:53:30 +00:00
|
|
|
if ($data = data_submitted() and confirm_sesskey()) {
|
2007-12-19 17:35:20 +00:00
|
|
|
if (admin_write_settings($data)) {
|
2016-03-17 21:17:35 +11:00
|
|
|
redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
|
2007-12-19 17:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($adminroot->errors)) {
|
|
|
|
switch ($return) {
|
2009-05-06 09:11:07 +00:00
|
|
|
case 'site': redirect("$CFG->wwwroot/");
|
2007-12-19 17:35:20 +00:00
|
|
|
case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
|
2006-08-21 04:06:58 +00:00
|
|
|
}
|
2016-03-17 21:17:35 +11:00
|
|
|
redirect($PAGE->url);
|
2006-08-21 04:06:58 +00:00
|
|
|
} else {
|
2007-12-19 17:35:20 +00:00
|
|
|
$errormsg = get_string('errorwithsettings', 'admin');
|
|
|
|
$firsterror = reset($adminroot->errors);
|
|
|
|
}
|
2009-05-08 02:43:06 +00:00
|
|
|
$settingspage = $adminroot->locate($section, true);
|
2007-12-19 17:35:20 +00:00
|
|
|
}
|
|
|
|
|
2009-05-06 08:59:29 +00:00
|
|
|
if ($PAGE->user_allowed_editing() && $adminediting != -1) {
|
|
|
|
$USER->editing = $adminediting;
|
2006-08-18 07:25:17 +00:00
|
|
|
}
|
|
|
|
|
2006-10-16 06:52:01 +00:00
|
|
|
/// print header stuff ------------------------------------------------------------
|
2007-02-06 22:23:08 +00:00
|
|
|
if (empty($SITE->fullname)) {
|
2009-09-03 05:11:33 +00:00
|
|
|
$PAGE->set_title($settingspage->visiblename);
|
|
|
|
$PAGE->set_heading($settingspage->visiblename);
|
2009-11-01 10:57:00 +00:00
|
|
|
|
2009-09-03 05:11:33 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->box(get_string('configintrosite', 'admin'));
|
2007-02-06 22:23:08 +00:00
|
|
|
|
2007-12-19 17:35:20 +00:00
|
|
|
if ($errormsg !== '') {
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->notification($errormsg);
|
2007-12-19 17:35:20 +00:00
|
|
|
|
|
|
|
} else if ($statusmsg !== '') {
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->notification($statusmsg, 'notifysuccess');
|
2007-02-06 22:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-08-15 17:38:24 +08:00
|
|
|
$pageparams = $PAGE->url->params();
|
|
|
|
$context = [
|
|
|
|
'actionurl' => $PAGE->url->out(false),
|
|
|
|
'params' => array_map(function($param) use ($pageparams) {
|
|
|
|
return [
|
|
|
|
'name' => $param,
|
|
|
|
'value' => $pageparams[$param]
|
|
|
|
];
|
|
|
|
}, array_keys($pageparams)),
|
|
|
|
'sesskey' => sesskey(),
|
|
|
|
'return' => $return,
|
|
|
|
'title' => null,
|
|
|
|
'settings' => $settingspage->output_html(),
|
|
|
|
'showsave' => true
|
|
|
|
];
|
|
|
|
|
|
|
|
echo $OUTPUT->render_from_template('core_admin/settings', $context);
|
2007-02-06 22:23:08 +00:00
|
|
|
|
2007-12-19 17:35:20 +00:00
|
|
|
} else {
|
2009-05-06 09:11:07 +00:00
|
|
|
if ($PAGE->user_allowed_editing()) {
|
2010-01-03 15:46:14 +00:00
|
|
|
$url = clone($PAGE->url);
|
2009-05-06 09:11:07 +00:00
|
|
|
if ($PAGE->user_is_editing()) {
|
|
|
|
$caption = get_string('blockseditoff');
|
2010-01-03 15:46:14 +00:00
|
|
|
$url->param('adminedit', 'off');
|
2009-05-06 09:11:07 +00:00
|
|
|
} else {
|
|
|
|
$caption = get_string('blocksediton');
|
2010-01-03 15:46:14 +00:00
|
|
|
$url->param('adminedit', 'on');
|
2009-05-06 09:11:07 +00:00
|
|
|
}
|
2010-01-03 15:46:14 +00:00
|
|
|
$buttons = $OUTPUT->single_button($url, $caption, 'get');
|
2011-12-16 17:16:47 +13:00
|
|
|
$PAGE->set_button($buttons);
|
2009-05-06 09:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$visiblepathtosection = array_reverse($settingspage->visiblepath);
|
2006-08-18 07:25:17 +00:00
|
|
|
|
2009-09-03 05:11:33 +00:00
|
|
|
$PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
|
|
|
|
$PAGE->set_heading($SITE->fullname);
|
|
|
|
echo $OUTPUT->header();
|
2006-10-16 06:52:01 +00:00
|
|
|
|
2007-12-19 17:35:20 +00:00
|
|
|
if ($errormsg !== '') {
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->notification($errormsg);
|
2007-12-19 17:35:20 +00:00
|
|
|
|
|
|
|
} else if ($statusmsg !== '') {
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->notification($statusmsg, 'notifysuccess');
|
2007-02-06 22:23:08 +00:00
|
|
|
}
|
2006-10-16 06:52:01 +00:00
|
|
|
|
2007-02-06 22:23:08 +00:00
|
|
|
// ---------------------------------------------------------------------------------------------------------------
|
2006-08-18 07:25:17 +00:00
|
|
|
|
2016-08-15 17:38:24 +08:00
|
|
|
$pageparams = $PAGE->url->params();
|
|
|
|
$context = [
|
|
|
|
'actionurl' => $PAGE->url->out(false),
|
|
|
|
'params' => array_map(function($param) use ($pageparams) {
|
|
|
|
return [
|
|
|
|
'name' => $param,
|
|
|
|
'value' => $pageparams[$param]
|
|
|
|
];
|
|
|
|
}, array_keys($pageparams)),
|
|
|
|
'sesskey' => sesskey(),
|
|
|
|
'return' => $return,
|
|
|
|
'title' => $settingspage->visiblename,
|
|
|
|
'settings' => $settingspage->output_html(),
|
|
|
|
'showsave' => $settingspage->show_save()
|
|
|
|
];
|
|
|
|
|
|
|
|
echo $OUTPUT->render_from_template('core_admin/settings', $context);
|
2006-09-12 09:22:27 +00:00
|
|
|
}
|
2006-08-18 07:25:17 +00:00
|
|
|
|
2012-02-16 10:25:54 +00:00
|
|
|
$PAGE->requires->yui_module('moodle-core-formchangechecker',
|
|
|
|
'M.core_formchangechecker.init',
|
2012-01-23 11:36:53 +00:00
|
|
|
array(array(
|
|
|
|
'formid' => 'adminsettings'
|
|
|
|
))
|
|
|
|
);
|
|
|
|
$PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
|
2009-11-01 10:55:31 +00:00
|
|
|
|
2012-01-23 11:36:53 +00:00
|
|
|
echo $OUTPUT->footer();
|