MDL-80949 mod_data: Remove unused Allow autolink param for text field
[moodle.git] / admin / settings.php
blob48171745b3a1461ffdda5762efc578599da4e8f5
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 throw new \moodle_exception('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
28 die;
31 if (!($settingspage->check_access())) {
32 throw new \moodle_exception('accessdenied', 'admin');
33 die;
36 // If the context in the admin_settingpage object is explicitly defined and it is not system, reset the current
37 // page context and use that one instead. This ensures that the proper navigation is displayed and highlighted.
38 if ($settingspage->context && !$settingspage->context instanceof \context_system) {
39 $PAGE->set_context($settingspage->context);
42 $hassiteconfig = has_capability('moodle/site:config', context_system::instance());
43 // Display the admin search input element in the page header if the user has the capability to change the site
44 // configuration and the current page context is system.
45 if ($hassiteconfig && $PAGE->context instanceof \context_system) {
46 $PAGE->add_header_action($OUTPUT->render_from_template('core_admin/header_search_input', [
47 'action' => new moodle_url('/admin/search.php'),
48 ]));
51 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
53 $statusmsg = '';
54 $errormsg = '';
56 // Form is submitted with changed settings. Do not want to execute when modifying a block.
57 if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') {
59 $count = admin_write_settings($data);
60 // Regardless of whether any setting change was written (a positive count), check validation errors for those that didn't.
61 if (empty($adminroot->errors)) {
62 // No errors. Did we change any setting? If so, then redirect with success.
63 if ($count) {
64 redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
66 // We didn't change a setting.
67 switch ($return) {
68 case 'site': redirect("$CFG->wwwroot/");
69 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
71 redirect($PAGE->url);
72 } else {
73 $errormsg = get_string('errorwithsettings', 'admin');
74 $firsterror = reset($adminroot->errors);
76 $settingspage = $adminroot->locate($section, true);
79 if ($PAGE->user_allowed_editing() && $adminediting != -1) {
80 $USER->editing = $adminediting;
83 /// print header stuff ------------------------------------------------------------
84 if (empty($SITE->fullname)) {
85 $PAGE->set_title($settingspage->visiblename);
86 $PAGE->set_heading($settingspage->visiblename);
88 echo $OUTPUT->header();
89 echo $OUTPUT->box(get_string('configintrosite', 'admin'));
91 if ($errormsg !== '') {
92 echo $OUTPUT->notification($errormsg);
94 } else if ($statusmsg !== '') {
95 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
98 // ---------------------------------------------------------------------------------------------------------------
100 $pageparams = $PAGE->url->params();
101 $context = [
102 'actionurl' => $PAGE->url->out(false),
103 'params' => array_map(function($param) use ($pageparams) {
104 return [
105 'name' => $param,
106 'value' => $pageparams[$param]
108 }, array_keys($pageparams)),
109 'sesskey' => sesskey(),
110 'return' => $return,
111 'title' => null,
112 'settings' => $settingspage->output_html(),
113 'showsave' => true
116 echo $OUTPUT->render_from_template('core_admin/settings', $context);
118 } else {
119 if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) {
120 $url = clone($PAGE->url);
121 if ($PAGE->user_is_editing()) {
122 $caption = get_string('blockseditoff');
123 $url->param('adminedit', 'off');
124 } else {
125 $caption = get_string('blocksediton');
126 $url->param('adminedit', 'on');
128 $buttons = $OUTPUT->single_button($url, $caption, 'get');
129 $PAGE->set_button($buttons);
132 $PAGE->set_title(implode(moodle_page::TITLE_SEPARATOR, $settingspage->visiblepath));
133 $PAGE->set_heading($SITE->fullname);
134 echo $OUTPUT->header();
136 if ($errormsg !== '') {
137 echo $OUTPUT->notification($errormsg);
139 } else if ($statusmsg !== '') {
140 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
143 // ---------------------------------------------------------------------------------------------------------------
145 $pageparams = $PAGE->url->params();
146 $context = [
147 'actionurl' => $PAGE->url->out(false),
148 'params' => array_map(function($param) use ($pageparams) {
149 return [
150 'name' => $param,
151 'value' => $pageparams[$param]
153 }, array_keys($pageparams)),
154 'sesskey' => sesskey(),
155 'return' => $return,
156 'title' => $settingspage->visiblename,
157 'settings' => $settingspage->output_html(),
158 'showsave' => $settingspage->show_save()
161 echo $OUTPUT->render_from_template('core_admin/settings', $context);
164 // Add the form change checker.
165 $PAGE->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['adminsettings']);
167 if ($settingspage->has_dependencies()) {
168 $opts = [
169 'dependencies' => $settingspage->get_dependencies_for_javascript()
171 $PAGE->requires->js_call_amd('core/showhidesettings', 'init', [$opts]);
174 echo $OUTPUT->footer();