MDL-61502 questions: add filter tests to gapselect question type.
[moodle.git] / admin / settings.php
blob629224029faf49798c5a4191877331a7c1ce821d
1 <?php
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'));
25 } else {
26 print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
28 die;
31 if (!($settingspage->check_access())) {
32 print_error('accessdenied', 'admin');
33 die;
36 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
38 $statusmsg = '';
39 $errormsg = '';
41 if ($data = data_submitted() and confirm_sesskey()) {
43 $count = admin_write_settings($data);
44 // Regardless of whether any setting change was written (a positive count), check validation errors for those that didn't.
45 if (empty($adminroot->errors)) {
46 // No errors. Did we change any setting? If so, then redirect with success.
47 if ($count) {
48 redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
50 // We didn't change a setting.
51 switch ($return) {
52 case 'site': redirect("$CFG->wwwroot/");
53 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
55 redirect($PAGE->url);
56 } else {
57 $errormsg = get_string('errorwithsettings', 'admin');
58 $firsterror = reset($adminroot->errors);
60 $settingspage = $adminroot->locate($section, true);
63 if ($PAGE->user_allowed_editing() && $adminediting != -1) {
64 $USER->editing = $adminediting;
67 /// print header stuff ------------------------------------------------------------
68 if (empty($SITE->fullname)) {
69 $PAGE->set_title($settingspage->visiblename);
70 $PAGE->set_heading($settingspage->visiblename);
72 echo $OUTPUT->header();
73 echo $OUTPUT->box(get_string('configintrosite', 'admin'));
75 if ($errormsg !== '') {
76 echo $OUTPUT->notification($errormsg);
78 } else if ($statusmsg !== '') {
79 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
82 // ---------------------------------------------------------------------------------------------------------------
84 $pageparams = $PAGE->url->params();
85 $context = [
86 'actionurl' => $PAGE->url->out(false),
87 'params' => array_map(function($param) use ($pageparams) {
88 return [
89 'name' => $param,
90 'value' => $pageparams[$param]
92 }, array_keys($pageparams)),
93 'sesskey' => sesskey(),
94 'return' => $return,
95 'title' => null,
96 'settings' => $settingspage->output_html(),
97 'showsave' => true
100 echo $OUTPUT->render_from_template('core_admin/settings', $context);
102 } else {
103 if ($PAGE->user_allowed_editing()) {
104 $url = clone($PAGE->url);
105 if ($PAGE->user_is_editing()) {
106 $caption = get_string('blockseditoff');
107 $url->param('adminedit', 'off');
108 } else {
109 $caption = get_string('blocksediton');
110 $url->param('adminedit', 'on');
112 $buttons = $OUTPUT->single_button($url, $caption, 'get');
113 $PAGE->set_button($buttons);
116 $visiblepathtosection = array_reverse($settingspage->visiblepath);
118 $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
119 $PAGE->set_heading($SITE->fullname);
120 echo $OUTPUT->header();
122 if ($errormsg !== '') {
123 echo $OUTPUT->notification($errormsg);
125 } else if ($statusmsg !== '') {
126 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
129 // ---------------------------------------------------------------------------------------------------------------
131 $pageparams = $PAGE->url->params();
132 $context = [
133 'actionurl' => $PAGE->url->out(false),
134 'params' => array_map(function($param) use ($pageparams) {
135 return [
136 'name' => $param,
137 'value' => $pageparams[$param]
139 }, array_keys($pageparams)),
140 'sesskey' => sesskey(),
141 'return' => $return,
142 'title' => $settingspage->visiblename,
143 'settings' => $settingspage->output_html(),
144 'showsave' => $settingspage->show_save()
147 echo $OUTPUT->render_from_template('core_admin/settings', $context);
150 $PAGE->requires->yui_module('moodle-core-formchangechecker',
151 'M.core_formchangechecker.init',
152 array(array(
153 'formid' => 'adminsettings'
156 $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
158 echo $OUTPUT->footer();