Merge branch 'MDL-48946-master' of https://github.com/sammarshallou/moodle
[moodle.git] / admin / settings.php
blob2acbc835e0ec3fcce7bba023b5e5184ffe91bbd6
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.'" />';
81 echo $settingspage->output_html();
83 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
85 echo '</div>';
86 echo '</form>';
88 } else {
89 if ($PAGE->user_allowed_editing()) {
90 $url = clone($PAGE->url);
91 if ($PAGE->user_is_editing()) {
92 $caption = get_string('blockseditoff');
93 $url->param('adminedit', 'off');
94 } else {
95 $caption = get_string('blocksediton');
96 $url->param('adminedit', 'on');
98 $buttons = $OUTPUT->single_button($url, $caption, 'get');
99 $PAGE->set_button($buttons);
102 $visiblepathtosection = array_reverse($settingspage->visiblepath);
104 $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
105 $PAGE->set_heading($SITE->fullname);
106 echo $OUTPUT->header();
108 if ($errormsg !== '') {
109 echo $OUTPUT->notification($errormsg);
111 } else if ($statusmsg !== '') {
112 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
115 // ---------------------------------------------------------------------------------------------------------------
117 echo '<form action="settings.php" method="post" id="adminsettings">';
118 echo '<div class="settingsform clearfix">';
119 echo html_writer::input_hidden_params($PAGE->url);
120 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
121 echo '<input type="hidden" name="return" value="'.$return.'" />';
122 echo $OUTPUT->heading($settingspage->visiblename);
124 echo $settingspage->output_html();
126 if ($settingspage->show_save()) {
127 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
130 echo '</div>';
131 echo '</form>';
134 $PAGE->requires->yui_module('moodle-core-formchangechecker',
135 'M.core_formchangechecker.init',
136 array(array(
137 'formid' => 'adminsettings'
140 $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
142 echo $OUTPUT->footer();