MDL-22624 help string thanks to Davo Smith for suggested wording
[moodle.git] / admin / settings.php
blob596d6182f502fcaceb82e5b377c36c1ac36628eb
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(get_context_instance(CONTEXT_SYSTEM));
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();
18 $adminroot = admin_get_root(); // need all settings
19 $settingspage = $adminroot->locate($section, true);
21 if (empty($settingspage) or !($settingspage instanceof admin_settingpage)) {
22 print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
23 die;
26 if (!($settingspage->check_access())) {
27 print_error('accessdenied', 'admin');
28 die;
31 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
33 $statusmsg = '';
34 $errormsg = '';
35 $focus = '';
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);
50 $focus = $firsterror->id;
52 $adminroot = admin_get_root(true); //reload tree
53 $settingspage = $adminroot->locate($section, true);
56 if ($PAGE->user_allowed_editing() && $adminediting != -1) {
57 $USER->editing = $adminediting;
60 /// print header stuff ------------------------------------------------------------
61 if (empty($SITE->fullname)) {
62 $PAGE->set_title($settingspage->visiblename);
63 $PAGE->set_heading($settingspage->visiblename);
65 echo $OUTPUT->header();
66 echo $OUTPUT->box(get_string('configintrosite', 'admin'));
68 if ($errormsg !== '') {
69 echo $OUTPUT->notification($errormsg);
71 } else if ($statusmsg !== '') {
72 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
75 // ---------------------------------------------------------------------------------------------------------------
77 echo '<form action="settings.php" method="post" id="adminsettings">';
78 echo '<div class="settingsform clearfix">';
79 echo html_writer::input_hidden_params($PAGE->url);
80 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
81 echo '<input type="hidden" name="return" value="'.$return.'" />';
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');
103 $visiblepathtosection = array_reverse($settingspage->visiblepath);
105 $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
106 $PAGE->set_heading($SITE->fullname);
107 $PAGE->set_button($buttons);
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 echo $OUTPUT->heading($settingspage->visiblename);
126 echo $settingspage->output_html();
128 if ($settingspage->show_save()) {
129 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
132 echo '</div>';
133 echo '</form>';
136 echo $OUTPUT->footer();