3 require_once('../config.php');
4 require_once($CFG->libdir
.'/adminlib.php');
6 $section = required_param('section', PARAM_SAFEDIR
);
7 $return = optional_param('return','', PARAM_ALPHA
);
8 $adminediting = optional_param('adminedit', -1, PARAM_BOOL
);
10 /// no guest autologin
11 require_login(0, false);
12 $PAGE->set_context(context_system
::instance());
13 $PAGE->set_url('/admin/settings.php', array('section' => $section));
14 $PAGE->set_pagetype('admin-setting-' . $section);
15 $PAGE->set_pagelayout('admin');
16 $PAGE->navigation
->clear_cache();
17 navigation_node
::require_admin_tree();
19 $adminroot = admin_get_root(); // need all settings
20 $settingspage = $adminroot->locate($section, true);
22 if (empty($settingspage) or !($settingspage instanceof admin_settingpage
)) {
23 if (moodle_needs_upgrading()) {
24 redirect(new moodle_url('/admin/index.php'));
26 print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
31 if (!($settingspage->check_access())) {
32 print_error('accessdenied', 'admin');
36 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
41 // Form is submitted with changed settings. Do not want to execute when modifying a block.
42 if ($data = data_submitted() and confirm_sesskey() and isset($data->action
) and $data->action
== 'save-settings') {
44 $count = admin_write_settings($data);
45 // Regardless of whether any setting change was written (a positive count), check validation errors for those that didn't.
46 if (empty($adminroot->errors
)) {
47 // No errors. Did we change any setting? If so, then redirect with success.
49 redirect($PAGE->url
, get_string('changessaved'), null, \core\output\notification
::NOTIFY_SUCCESS
);
51 // We didn't change a setting.
53 case 'site': redirect("$CFG->wwwroot/");
54 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
58 $errormsg = get_string('errorwithsettings', 'admin');
59 $firsterror = reset($adminroot->errors
);
61 $settingspage = $adminroot->locate($section, true);
64 if ($PAGE->user_allowed_editing() && $adminediting != -1) {
65 $USER->editing
= $adminediting;
68 /// print header stuff ------------------------------------------------------------
69 if (empty($SITE->fullname
)) {
70 $PAGE->set_title($settingspage->visiblename
);
71 $PAGE->set_heading($settingspage->visiblename
);
73 echo $OUTPUT->header();
74 echo $OUTPUT->box(get_string('configintrosite', 'admin'));
76 if ($errormsg !== '') {
77 echo $OUTPUT->notification($errormsg);
79 } else if ($statusmsg !== '') {
80 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
83 // ---------------------------------------------------------------------------------------------------------------
85 $pageparams = $PAGE->url
->params();
87 'actionurl' => $PAGE->url
->out(false),
88 'params' => array_map(function($param) use ($pageparams) {
91 'value' => $pageparams[$param]
93 }, array_keys($pageparams)),
94 'sesskey' => sesskey(),
97 'settings' => $settingspage->output_html(),
101 echo $OUTPUT->render_from_template('core_admin/settings', $context);
104 if ($PAGE->user_allowed_editing()) {
105 $url = clone($PAGE->url
);
106 if ($PAGE->user_is_editing()) {
107 $caption = get_string('blockseditoff');
108 $url->param('adminedit', 'off');
110 $caption = get_string('blocksediton');
111 $url->param('adminedit', 'on');
113 $buttons = $OUTPUT->single_button($url, $caption, 'get');
114 $PAGE->set_button($buttons);
117 $visiblepathtosection = array_reverse($settingspage->visiblepath
);
119 $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
120 $PAGE->set_heading($SITE->fullname
);
121 echo $OUTPUT->header();
123 if ($errormsg !== '') {
124 echo $OUTPUT->notification($errormsg);
126 } else if ($statusmsg !== '') {
127 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
130 // ---------------------------------------------------------------------------------------------------------------
132 $pageparams = $PAGE->url
->params();
134 'actionurl' => $PAGE->url
->out(false),
135 'params' => array_map(function($param) use ($pageparams) {
138 'value' => $pageparams[$param]
140 }, array_keys($pageparams)),
141 'sesskey' => sesskey(),
143 'title' => $settingspage->visiblename
,
144 'settings' => $settingspage->output_html(),
145 'showsave' => $settingspage->show_save()
148 echo $OUTPUT->render_from_template('core_admin/settings', $context);
151 $PAGE->requires
->yui_module('moodle-core-formchangechecker',
152 'M.core_formchangechecker.init',
154 'formid' => 'adminsettings'
157 $PAGE->requires
->string_for_js('changesmadereallygoaway', 'moodle');
159 echo $OUTPUT->footer();