Commit | Line | Data |
---|---|---|
0df0df23 | 1 | <?php |
90a73bb3 | 2 | |
3 | require_once('../config.php'); | |
6e4dc10f | 4 | require_once($CFG->libdir.'/adminlib.php'); |
63aafc9e | 5 | |
f8b80dbd | 6 | $section = required_param('section', PARAM_SAFEDIR); |
7 | $return = optional_param('return','', PARAM_ALPHA); | |
220a90c5 | 8 | $adminediting = optional_param('adminedit', -1, PARAM_BOOL); |
eef868d1 | 9 | |
9a7a7851 | 10 | /// no guest autologin |
11 | require_login(0, false); | |
f230ce19 | 12 | $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); |
a6855934 | 13 | $PAGE->set_url('/admin/settings.php', array('section' => $section)); |
f8b80dbd | 14 | $PAGE->set_pagetype('admin-setting-' . $section); |
191b267b | 15 | $PAGE->set_pagelayout('admin'); |
f5b5a822 | 16 | $PAGE->navigation->clear_cache(); |
90a73bb3 | 17 | |
4d933beb | 18 | $adminroot = admin_get_root(); // need all settings |
f8b80dbd | 19 | $settingspage = $adminroot->locate($section, true); |
90a73bb3 | 20 | |
f8b80dbd | 21 | if (empty($settingspage) or !($settingspage instanceof admin_settingpage)) { |
1d8bf5f0 | 22 | print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/"); |
6fcbab99 | 23 | die; |
63aafc9e | 24 | } |
90a73bb3 | 25 | |
f8b80dbd | 26 | if (!($settingspage->check_access())) { |
1d8bf5f0 | 27 | print_error('accessdenied', 'admin'); |
6fcbab99 | 28 | die; |
63aafc9e | 29 | } |
90a73bb3 | 30 | |
e268cc4a | 31 | /// WRITING SUBMITTED DATA (IF ANY) ------------------------------------------------------------------------------- |
c6d33fce | 32 | |
e268cc4a | 33 | $statusmsg = ''; |
220a90c5 | 34 | $errormsg = ''; |
90a73bb3 | 35 | |
294ce987 | 36 | if ($data = data_submitted() and confirm_sesskey()) { |
220a90c5 | 37 | if (admin_write_settings($data)) { |
38 | $statusmsg = get_string('changessaved'); | |
39 | } | |
40 | ||
41 | if (empty($adminroot->errors)) { | |
42 | switch ($return) { | |
f8b80dbd | 43 | case 'site': redirect("$CFG->wwwroot/"); |
220a90c5 | 44 | case 'admin': redirect("$CFG->wwwroot/$CFG->admin/"); |
6fcbab99 | 45 | } |
46 | } else { | |
220a90c5 | 47 | $errormsg = get_string('errorwithsettings', 'admin'); |
48 | $firsterror = reset($adminroot->errors); | |
220a90c5 | 49 | } |
f8b80dbd | 50 | $adminroot = admin_get_root(true); //reload tree |
ac9e2207 | 51 | $settingspage = $adminroot->locate($section, true); |
220a90c5 | 52 | } |
53 | ||
830dd6e9 | 54 | if ($PAGE->user_allowed_editing() && $adminediting != -1) { |
55 | $USER->editing = $adminediting; | |
90a73bb3 | 56 | } |
57 | ||
e268cc4a | 58 | /// print header stuff ------------------------------------------------------------ |
e5afdd27 | 59 | if (empty($SITE->fullname)) { |
69d77c23 | 60 | $PAGE->set_title($settingspage->visiblename); |
61 | $PAGE->set_heading($settingspage->visiblename); | |
20207b82 | 62 | |
69d77c23 | 63 | echo $OUTPUT->header(); |
8fbce1c8 | 64 | echo $OUTPUT->box(get_string('configintrosite', 'admin')); |
e5afdd27 | 65 | |
220a90c5 | 66 | if ($errormsg !== '') { |
8fbce1c8 | 67 | echo $OUTPUT->notification($errormsg); |
220a90c5 | 68 | |
69 | } else if ($statusmsg !== '') { | |
8fbce1c8 | 70 | echo $OUTPUT->notification($statusmsg, 'notifysuccess'); |
e5afdd27 | 71 | } |
72 | ||
73 | // --------------------------------------------------------------------------------------------------------------- | |
74 | ||
75 | echo '<form action="settings.php" method="post" id="adminsettings">'; | |
0dc89caf | 76 | echo '<div class="settingsform clearfix">'; |
6ea66ff3 | 77 | echo html_writer::input_hidden_params($PAGE->url); |
d4a1fcaf | 78 | echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; |
220a90c5 | 79 | echo '<input type="hidden" name="return" value="'.$return.'" />'; |
e5afdd27 | 80 | |
f8b80dbd | 81 | echo $settingspage->output_html(); |
e5afdd27 | 82 | |
220a90c5 | 83 | echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>'; |
e5afdd27 | 84 | |
85 | echo '</div>'; | |
86 | echo '</form>'; | |
e5afdd27 | 87 | |
220a90c5 | 88 | } else { |
f8b80dbd | 89 | if ($PAGE->user_allowed_editing()) { |
5c2ed7e2 | 90 | $url = clone($PAGE->url); |
f8b80dbd | 91 | if ($PAGE->user_is_editing()) { |
92 | $caption = get_string('blockseditoff'); | |
5c2ed7e2 | 93 | $url->param('adminedit', 'off'); |
f8b80dbd | 94 | } else { |
95 | $caption = get_string('blocksediton'); | |
5c2ed7e2 | 96 | $url->param('adminedit', 'on'); |
f8b80dbd | 97 | } |
5c2ed7e2 | 98 | $buttons = $OUTPUT->single_button($url, $caption, 'get'); |
6be4afb1 | 99 | $PAGE->set_button($buttons); |
f8b80dbd | 100 | } |
101 | ||
102 | $visiblepathtosection = array_reverse($settingspage->visiblepath); | |
90a73bb3 | 103 | |
69d77c23 | 104 | $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection)); |
105 | $PAGE->set_heading($SITE->fullname); | |
69d77c23 | 106 | echo $OUTPUT->header(); |
e268cc4a | 107 | |
220a90c5 | 108 | if ($errormsg !== '') { |
8fbce1c8 | 109 | echo $OUTPUT->notification($errormsg); |
220a90c5 | 110 | |
111 | } else if ($statusmsg !== '') { | |
8fbce1c8 | 112 | echo $OUTPUT->notification($statusmsg, 'notifysuccess'); |
e5afdd27 | 113 | } |
e268cc4a | 114 | |
e5afdd27 | 115 | // --------------------------------------------------------------------------------------------------------------- |
90a73bb3 | 116 | |
e5afdd27 | 117 | echo '<form action="settings.php" method="post" id="adminsettings">'; |
0dc89caf | 118 | echo '<div class="settingsform clearfix">'; |
6ea66ff3 | 119 | echo html_writer::input_hidden_params($PAGE->url); |
d4a1fcaf | 120 | echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; |
220a90c5 | 121 | echo '<input type="hidden" name="return" value="'.$return.'" />'; |
2fff8846 | 122 | echo $OUTPUT->heading($settingspage->visiblename); |
90a73bb3 | 123 | |
f8b80dbd | 124 | echo $settingspage->output_html(); |
90a73bb3 | 125 | |
427649bf PS |
126 | if ($settingspage->show_save()) { |
127 | echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>'; | |
128 | } | |
fa040029 | 129 | |
e5afdd27 | 130 | echo '</div>'; |
131 | echo '</form>'; | |
b1ce7811 | 132 | } |
90a73bb3 | 133 | |
73d6f52f | 134 | echo $OUTPUT->footer(); |
90a73bb3 | 135 | |
0df0df23 | 136 |