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'));
26 print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
31 if (!($settingspage->check_access())) {
32 print_error('accessdenied', 'admin');
36 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
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
)) {
48 case 'site': redirect("$CFG->wwwroot/");
49 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
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 echo '<form action="' . $PAGE->url
. '" method="post" id="adminsettings">';
81 echo '<div class="settingsform clearfix">';
82 echo html_writer
::input_hidden_params($PAGE->url
);
83 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
84 echo '<input type="hidden" name="return" value="'.$return.'" />';
85 // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
86 echo prevent_form_autofill_password();
88 echo $settingspage->output_html();
90 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
96 if ($PAGE->user_allowed_editing()) {
97 $url = clone($PAGE->url
);
98 if ($PAGE->user_is_editing()) {
99 $caption = get_string('blockseditoff');
100 $url->param('adminedit', 'off');
102 $caption = get_string('blocksediton');
103 $url->param('adminedit', 'on');
105 $buttons = $OUTPUT->single_button($url, $caption, 'get');
106 $PAGE->set_button($buttons);
109 $visiblepathtosection = array_reverse($settingspage->visiblepath
);
111 $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
112 $PAGE->set_heading($SITE->fullname
);
113 echo $OUTPUT->header();
115 if ($errormsg !== '') {
116 echo $OUTPUT->notification($errormsg);
118 } else if ($statusmsg !== '') {
119 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
122 // ---------------------------------------------------------------------------------------------------------------
124 echo '<form action="' . $PAGE->url
. '" method="post" id="adminsettings">';
125 echo '<div class="settingsform clearfix">';
126 echo html_writer
::input_hidden_params($PAGE->url
);
127 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
128 echo '<input type="hidden" name="return" value="'.$return.'" />';
129 // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
130 echo prevent_form_autofill_password();
131 echo $OUTPUT->heading($settingspage->visiblename
);
133 echo $settingspage->output_html();
135 if ($settingspage->show_save()) {
136 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
143 $PAGE->requires
->yui_module('moodle-core-formchangechecker',
144 'M.core_formchangechecker.init',
146 'formid' => 'adminsettings'
149 $PAGE->requires
->string_for_js('changesmadereallygoaway', 'moodle');
151 echo $OUTPUT->footer();