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 {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
|
2016-03-06 19:29:18 +11:00
|
|
|
}
|
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())) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('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
|
|
|
|
2022-04-21 16:21:21 +08:00
|
|
|
// If the context in the admin_settingpage object is explicitly defined and it is not system, reset the current
|
|
|
|
// page context and use that one instead. This ensures that the proper navigation is displayed and highlighted.
|
|
|
|
if ($settingspage->context && !$settingspage->context instanceof \context_system) {
|
|
|
|
$PAGE->set_context($settingspage->context);
|
|
|
|
}
|
|
|
|
|
|
|
|
$hassiteconfig = has_capability('moodle/site:config', context_system::instance());
|
|
|
|
// Display the admin search input element in the page header if the user has the capability to change the site
|
|
|
|
// configuration and the current page context is system.
|
|
|
|
if ($hassiteconfig && $PAGE->context instanceof \context_system) {
|
2022-03-31 20:11:34 +01:00
|
|
|
$PAGE->add_header_action($OUTPUT->render_from_template('core_admin/header_search_input', [
|
|
|
|
'action' => new moodle_url('/admin/search.php'),
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-05-25 15:48:04 +10:00
|
|
|
// Form is submitted with changed settings. Do not want to execute when modifying a block.
|
|
|
|
if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') {
|
2007-12-19 17:35:20 +00:00
|
|
|
|
2017-12-06 09:07:25 +08:00
|
|
|
$count = admin_write_settings($data);
|
|
|
|
// Regardless of whether any setting change was written (a positive count), check validation errors for those that didn't.
|
2007-12-19 17:35:20 +00:00
|
|
|
if (empty($adminroot->errors)) {
|
2017-12-06 09:07:25 +08:00
|
|
|
// No errors. Did we change any setting? If so, then redirect with success.
|
|
|
|
if ($count) {
|
|
|
|
redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
|
|
|
|
}
|
|
|
|
// We didn't change a setting.
|
2007-12-19 17:35:20 +00:00
|
|
|
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 {
|
2021-07-06 10:19:09 +02:00
|
|
|
if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) {
|
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
|
|
|
|
2021-02-12 16:28:44 +08:00
|
|
|
// Add the form change checker.
|
|
|
|
$PAGE->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['adminsettings']);
|
2009-11-01 10:55:31 +00:00
|
|
|
|
2017-12-07 14:31:32 +00:00
|
|
|
if ($settingspage->has_dependencies()) {
|
|
|
|
$opts = [
|
|
|
|
'dependencies' => $settingspage->get_dependencies_for_javascript()
|
|
|
|
];
|
|
|
|
$PAGE->requires->js_call_amd('core/showhidesettings', 'init', [$opts]);
|
|
|
|
}
|
|
|
|
|
2012-01-23 11:36:53 +00:00
|
|
|
echo $OUTPUT->footer();
|