Merge branch 'install_33_STABLE' of https://git.in.moodle.com/amosbot/moodle-install...
[moodle.git] / admin / settings.php
blob72f7f9cbe2a985b7b8b996d118ac80099f96d6a8
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 redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
46 if (empty($adminroot->errors)) {
47 switch ($return) {
48 case 'site': redirect("$CFG->wwwroot/");
49 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
51 redirect($PAGE->url);
52 } else {
53 $errormsg = get_string('errorwithsettings', 'admin');
54 $firsterror = reset($adminroot->errors);
56 $settingspage = $adminroot->locate($section, true);
59 if ($PAGE->user_allowed_editing() && $adminediting != -1) {
60 $USER->editing = $adminediting;
63 /// print header stuff ------------------------------------------------------------
64 if (empty($SITE->fullname)) {
65 $PAGE->set_title($settingspage->visiblename);
66 $PAGE->set_heading($settingspage->visiblename);
68 echo $OUTPUT->header();
69 echo $OUTPUT->box(get_string('configintrosite', 'admin'));
71 if ($errormsg !== '') {
72 echo $OUTPUT->notification($errormsg);
74 } else if ($statusmsg !== '') {
75 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
78 // ---------------------------------------------------------------------------------------------------------------
80 $pageparams = $PAGE->url->params();
81 $context = [
82 'actionurl' => $PAGE->url->out(false),
83 'params' => array_map(function($param) use ($pageparams) {
84 return [
85 'name' => $param,
86 'value' => $pageparams[$param]
88 }, array_keys($pageparams)),
89 'sesskey' => sesskey(),
90 'return' => $return,
91 'title' => null,
92 'settings' => $settingspage->output_html(),
93 'showsave' => true
96 echo $OUTPUT->render_from_template('core_admin/settings', $context);
98 } else {
99 if ($PAGE->user_allowed_editing()) {
100 $url = clone($PAGE->url);
101 if ($PAGE->user_is_editing()) {
102 $caption = get_string('blockseditoff');
103 $url->param('adminedit', 'off');
104 } else {
105 $caption = get_string('blocksediton');
106 $url->param('adminedit', 'on');
108 $buttons = $OUTPUT->single_button($url, $caption, 'get');
109 $PAGE->set_button($buttons);
112 $visiblepathtosection = array_reverse($settingspage->visiblepath);
114 $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
115 $PAGE->set_heading($SITE->fullname);
116 echo $OUTPUT->header();
118 if ($errormsg !== '') {
119 echo $OUTPUT->notification($errormsg);
121 } else if ($statusmsg !== '') {
122 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
125 // ---------------------------------------------------------------------------------------------------------------
127 $pageparams = $PAGE->url->params();
128 $context = [
129 'actionurl' => $PAGE->url->out(false),
130 'params' => array_map(function($param) use ($pageparams) {
131 return [
132 'name' => $param,
133 'value' => $pageparams[$param]
135 }, array_keys($pageparams)),
136 'sesskey' => sesskey(),
137 'return' => $return,
138 'title' => $settingspage->visiblename,
139 'settings' => $settingspage->output_html(),
140 'showsave' => $settingspage->show_save()
143 echo $OUTPUT->render_from_template('core_admin/settings', $context);
146 $PAGE->requires->yui_module('moodle-core-formchangechecker',
147 'M.core_formchangechecker.init',
148 array(array(
149 'formid' => 'adminsettings'
152 $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
154 echo $OUTPUT->footer();