Moodle release 2.7.19
[moodle.git] / admin / settings.php
blobe8f57825e761bd0acf51bfbe066cb523b0f4e890
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 print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
24 die;
27 if (!($settingspage->check_access())) {
28 print_error('accessdenied', 'admin');
29 die;
32 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
34 $statusmsg = '';
35 $errormsg = '';
37 if ($data = data_submitted() and confirm_sesskey()) {
38 if (admin_write_settings($data)) {
39 $statusmsg = get_string('changessaved');
42 if (empty($adminroot->errors)) {
43 switch ($return) {
44 case 'site': redirect("$CFG->wwwroot/");
45 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
47 } else {
48 $errormsg = get_string('errorwithsettings', 'admin');
49 $firsterror = reset($adminroot->errors);
51 $settingspage = $adminroot->locate($section, true);
54 if ($PAGE->user_allowed_editing() && $adminediting != -1) {
55 $USER->editing = $adminediting;
58 /// print header stuff ------------------------------------------------------------
59 if (empty($SITE->fullname)) {
60 $PAGE->set_title($settingspage->visiblename);
61 $PAGE->set_heading($settingspage->visiblename);
63 echo $OUTPUT->header();
64 echo $OUTPUT->box(get_string('configintrosite', 'admin'));
66 if ($errormsg !== '') {
67 echo $OUTPUT->notification($errormsg);
69 } else if ($statusmsg !== '') {
70 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
73 // ---------------------------------------------------------------------------------------------------------------
75 echo '<form action="settings.php" method="post" id="adminsettings">';
76 echo '<div class="settingsform clearfix">';
77 echo html_writer::input_hidden_params($PAGE->url);
78 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
79 echo '<input type="hidden" name="return" value="'.$return.'" />';
80 // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
81 echo prevent_form_autofill_password();
83 echo $settingspage->output_html();
85 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
87 echo '</div>';
88 echo '</form>';
90 } else {
91 if ($PAGE->user_allowed_editing()) {
92 $url = clone($PAGE->url);
93 if ($PAGE->user_is_editing()) {
94 $caption = get_string('blockseditoff');
95 $url->param('adminedit', 'off');
96 } else {
97 $caption = get_string('blocksediton');
98 $url->param('adminedit', 'on');
100 $buttons = $OUTPUT->single_button($url, $caption, 'get');
101 $PAGE->set_button($buttons);
104 $visiblepathtosection = array_reverse($settingspage->visiblepath);
106 $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
107 $PAGE->set_heading($SITE->fullname);
108 echo $OUTPUT->header();
110 if ($errormsg !== '') {
111 echo $OUTPUT->notification($errormsg);
113 } else if ($statusmsg !== '') {
114 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
117 // ---------------------------------------------------------------------------------------------------------------
119 echo '<form action="settings.php" method="post" id="adminsettings">';
120 echo '<div class="settingsform clearfix">';
121 echo html_writer::input_hidden_params($PAGE->url);
122 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
123 echo '<input type="hidden" name="return" value="'.$return.'" />';
124 // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
125 echo prevent_form_autofill_password();
126 echo $OUTPUT->heading($settingspage->visiblename);
128 echo $settingspage->output_html();
130 if ($settingspage->show_save()) {
131 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
134 echo '</div>';
135 echo '</form>';
138 $PAGE->requires->yui_module('moodle-core-formchangechecker',
139 'M.core_formchangechecker.init',
140 array(array(
141 'formid' => 'adminsettings'
144 $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
146 echo $OUTPUT->footer();