MDL-74312 enrol_lti: fix copytoclipboard trigger element
[moodle.git] / admin / settings.php
blob7adbac3ac2f1390a1c49e250c6a398102b112683
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 $hassiteconfig = has_capability('moodle/site:config', $PAGE->context);
37 if ($hassiteconfig) {
38 $PAGE->add_header_action($OUTPUT->render_from_template('core_admin/header_search_input', [
39 'action' => new moodle_url('/admin/search.php'),
40 ]));
43 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
45 $statusmsg = '';
46 $errormsg = '';
48 // Form is submitted with changed settings. Do not want to execute when modifying a block.
49 if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') {
51 $count = admin_write_settings($data);
52 // Regardless of whether any setting change was written (a positive count), check validation errors for those that didn't.
53 if (empty($adminroot->errors)) {
54 // No errors. Did we change any setting? If so, then redirect with success.
55 if ($count) {
56 redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
58 // We didn't change a setting.
59 switch ($return) {
60 case 'site': redirect("$CFG->wwwroot/");
61 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
63 redirect($PAGE->url);
64 } else {
65 $errormsg = get_string('errorwithsettings', 'admin');
66 $firsterror = reset($adminroot->errors);
68 $settingspage = $adminroot->locate($section, true);
71 if ($PAGE->user_allowed_editing() && $adminediting != -1) {
72 $USER->editing = $adminediting;
75 /// print header stuff ------------------------------------------------------------
76 if (empty($SITE->fullname)) {
77 $PAGE->set_title($settingspage->visiblename);
78 $PAGE->set_heading($settingspage->visiblename);
80 echo $OUTPUT->header();
81 echo $OUTPUT->box(get_string('configintrosite', 'admin'));
83 if ($errormsg !== '') {
84 echo $OUTPUT->notification($errormsg);
86 } else if ($statusmsg !== '') {
87 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
90 // ---------------------------------------------------------------------------------------------------------------
92 $pageparams = $PAGE->url->params();
93 $context = [
94 'actionurl' => $PAGE->url->out(false),
95 'params' => array_map(function($param) use ($pageparams) {
96 return [
97 'name' => $param,
98 'value' => $pageparams[$param]
100 }, array_keys($pageparams)),
101 'sesskey' => sesskey(),
102 'return' => $return,
103 'title' => null,
104 'settings' => $settingspage->output_html(),
105 'showsave' => true
108 echo $OUTPUT->render_from_template('core_admin/settings', $context);
110 } else {
111 if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) {
112 $url = clone($PAGE->url);
113 if ($PAGE->user_is_editing()) {
114 $caption = get_string('blockseditoff');
115 $url->param('adminedit', 'off');
116 } else {
117 $caption = get_string('blocksediton');
118 $url->param('adminedit', 'on');
120 $buttons = $OUTPUT->single_button($url, $caption, 'get');
121 $PAGE->set_button($buttons);
124 $visiblepathtosection = array_reverse($settingspage->visiblepath);
126 $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
127 $PAGE->set_heading($SITE->fullname);
128 if ($section === 'frontpagesettings') {
129 $frontpagenode = $PAGE->settingsnav->find('frontpage', navigation_node::TYPE_SETTING);
130 $frontpagenode->make_active();
131 $PAGE->navbar->add(get_string('frontpage', 'admin'),
132 new moodle_url('/admin/category.php', ['category' => 'frontpage']));
133 $PAGE->navbar->add(get_string('frontpagesettings', 'admin'), $PAGE->url);
135 echo $OUTPUT->header();
137 if ($errormsg !== '') {
138 echo $OUTPUT->notification($errormsg);
140 } else if ($statusmsg !== '') {
141 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
144 // ---------------------------------------------------------------------------------------------------------------
146 $pageparams = $PAGE->url->params();
147 $context = [
148 'actionurl' => $PAGE->url->out(false),
149 'params' => array_map(function($param) use ($pageparams) {
150 return [
151 'name' => $param,
152 'value' => $pageparams[$param]
154 }, array_keys($pageparams)),
155 'sesskey' => sesskey(),
156 'return' => $return,
157 'title' => $settingspage->visiblename,
158 'settings' => $settingspage->output_html(),
159 'showsave' => $settingspage->show_save()
162 echo $OUTPUT->render_from_template('core_admin/settings', $context);
165 // Add the form change checker.
166 $PAGE->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['adminsettings']);
168 if ($settingspage->has_dependencies()) {
169 $opts = [
170 'dependencies' => $settingspage->get_dependencies_for_javascript()
172 $PAGE->requires->js_call_amd('core/showhidesettings', 'init', [$opts]);
175 echo $OUTPUT->footer();