MDL-53691 theme_bootstrapbase: Backport of MDL-53147
[moodle.git] / admin / settings.php
bloba2b486b1280025a46bdf64614865f0f07017fc59
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()) {
42 if (admin_write_settings($data)) {
43 $statusmsg = get_string('changessaved');
46 if (empty($adminroot->errors)) {
47 switch ($return) {
48 case 'site': redirect("$CFG->wwwroot/");
49 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
51 } else {
52 $errormsg = get_string('errorwithsettings', 'admin');
53 $firsterror = reset($adminroot->errors);
55 $settingspage = $adminroot->locate($section, true);
58 if ($PAGE->user_allowed_editing() && $adminediting != -1) {
59 $USER->editing = $adminediting;
62 /// print header stuff ------------------------------------------------------------
63 if (empty($SITE->fullname)) {
64 $PAGE->set_title($settingspage->visiblename);
65 $PAGE->set_heading($settingspage->visiblename);
67 echo $OUTPUT->header();
68 echo $OUTPUT->box(get_string('configintrosite', 'admin'));
70 if ($errormsg !== '') {
71 echo $OUTPUT->notification($errormsg);
73 } else if ($statusmsg !== '') {
74 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
77 // ---------------------------------------------------------------------------------------------------------------
79 echo '<form action="settings.php" method="post" id="adminsettings">';
80 echo '<div class="settingsform clearfix">';
81 echo html_writer::input_hidden_params($PAGE->url);
82 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
83 echo '<input type="hidden" name="return" value="'.$return.'" />';
84 // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
85 echo prevent_form_autofill_password();
87 echo $settingspage->output_html();
89 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
91 echo '</div>';
92 echo '</form>';
94 } else {
95 if ($PAGE->user_allowed_editing()) {
96 $url = clone($PAGE->url);
97 if ($PAGE->user_is_editing()) {
98 $caption = get_string('blockseditoff');
99 $url->param('adminedit', 'off');
100 } else {
101 $caption = get_string('blocksediton');
102 $url->param('adminedit', 'on');
104 $buttons = $OUTPUT->single_button($url, $caption, 'get');
105 $PAGE->set_button($buttons);
108 $visiblepathtosection = array_reverse($settingspage->visiblepath);
110 $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
111 $PAGE->set_heading($SITE->fullname);
112 echo $OUTPUT->header();
114 if ($errormsg !== '') {
115 echo $OUTPUT->notification($errormsg);
117 } else if ($statusmsg !== '') {
118 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
121 // ---------------------------------------------------------------------------------------------------------------
123 echo '<form action="settings.php" method="post" id="adminsettings">';
124 echo '<div class="settingsform clearfix">';
125 echo html_writer::input_hidden_params($PAGE->url);
126 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
127 echo '<input type="hidden" name="return" value="'.$return.'" />';
128 // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
129 echo prevent_form_autofill_password();
130 echo $OUTPUT->heading($settingspage->visiblename);
132 echo $settingspage->output_html();
134 if ($settingspage->show_save()) {
135 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
138 echo '</div>';
139 echo '</form>';
142 $PAGE->requires->yui_module('moodle-core-formchangechecker',
143 'M.core_formchangechecker.init',
144 array(array(
145 'formid' => 'adminsettings'
148 $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
150 echo $OUTPUT->footer();