Commit | Line | Data |
---|---|---|
83f78f8d SH |
1 | <?php |
2 | // This file is part of Moodle - http://moodle.org/ | |
3 | // | |
4 | // Moodle is free software: you can redistribute it and/or modify | |
5 | // it under the terms of the GNU General Public License as published by | |
6 | // the Free Software Foundation, either version 3 of the License, or | |
7 | // (at your option) any later version. | |
8 | // | |
9 | // Moodle is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | // | |
14 | // You should have received a copy of the GNU General Public License | |
15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | /** | |
18 | * This file is used to display a categories sub categories, external pages, and settings. | |
19 | * | |
5bcfd504 | 20 | * @since Moodle 2.3 |
83f78f8d SH |
21 | * @package admin |
22 | * @copyright 2011 Sam Hemelryk | |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
25 | ||
26 | require_once('../config.php'); | |
27 | require_once($CFG->libdir.'/adminlib.php'); | |
28 | ||
29 | $category = required_param('category', PARAM_SAFEDIR); | |
30 | $return = optional_param('return','', PARAM_ALPHA); | |
31 | $adminediting = optional_param('adminedit', -1, PARAM_BOOL); | |
32 | ||
33 | /// no guest autologin | |
34 | require_login(0, false); | |
bf006d2c | 35 | $PAGE->set_context(context_system::instance()); |
83f78f8d SH |
36 | $PAGE->set_url('/admin/category.php', array('category' => $category)); |
37 | $PAGE->set_pagetype('admin-setting-' . $category); | |
38 | $PAGE->set_pagelayout('admin'); | |
39 | $PAGE->navigation->clear_cache(); | |
40 | ||
41 | $adminroot = admin_get_root(); // need all settings | |
42 | $settingspage = $adminroot->locate($category, true); | |
43 | ||
44 | if (empty($settingspage) or !($settingspage instanceof admin_category)) { | |
45 | print_error('categoryerror', 'admin', "$CFG->wwwroot/$CFG->admin/"); | |
46 | } | |
47 | ||
48 | if (!($settingspage->check_access())) { | |
49 | print_error('accessdenied', 'admin'); | |
50 | } | |
51 | ||
52 | ||
53 | $statusmsg = ''; | |
54 | $errormsg = ''; | |
55 | ||
56 | if ($data = data_submitted() and confirm_sesskey()) { | |
57 | if (admin_write_settings($data)) { | |
58 | $statusmsg = get_string('changessaved'); | |
59 | } | |
60 | ||
61 | if (empty($adminroot->errors)) { | |
62 | switch ($return) { | |
63 | case 'site': redirect("$CFG->wwwroot/"); | |
64 | case 'admin': redirect("$CFG->wwwroot/$CFG->admin/"); | |
65 | } | |
66 | } else { | |
67 | $errormsg = get_string('errorwithsettings', 'admin'); | |
68 | $firsterror = reset($adminroot->errors); | |
69 | } | |
83f78f8d SH |
70 | $settingspage = $adminroot->locate($category, true); |
71 | } | |
72 | ||
73 | if ($PAGE->user_allowed_editing() && $adminediting != -1) { | |
74 | $USER->editing = $adminediting; | |
75 | } | |
76 | ||
77 | if ($PAGE->user_allowed_editing()) { | |
78 | $url = clone($PAGE->url); | |
79 | if ($PAGE->user_is_editing()) { | |
80 | $caption = get_string('blockseditoff'); | |
81 | $url->param('adminedit', 'off'); | |
82 | } else { | |
83 | $caption = get_string('blocksediton'); | |
84 | $url->param('adminedit', 'on'); | |
85 | } | |
86 | $buttons = $OUTPUT->single_button($url, $caption, 'get'); | |
87 | } | |
88 | ||
89 | $savebutton = false; | |
90 | $outputhtml = ''; | |
91 | foreach ($settingspage->children as $childpage) { | |
915f8015 | 92 | if ($childpage->is_hidden() || !$childpage->check_access()) { |
83f78f8d SH |
93 | continue; |
94 | } | |
95 | if ($childpage instanceof admin_externalpage) { | |
96 | $outputhtml .= $OUTPUT->heading(html_writer::link($childpage->url, $childpage->visiblename), 3); | |
97 | } else if ($childpage instanceof admin_settingpage) { | |
98 | $outputhtml .= $OUTPUT->heading(html_writer::link(new moodle_url('/'.$CFG->admin.'/settings.php', array('section' => $childpage->name)), $childpage->visiblename), 3); | |
b8b47a15 SH |
99 | // If its a settings page and has settings lets display them. |
100 | if (!empty($childpage->settings)) { | |
101 | $outputhtml .= html_writer::start_tag('fieldset', array('class' => 'adminsettings')); | |
102 | foreach ($childpage->settings as $setting) { | |
103 | if (empty($setting->nosave)) { | |
104 | $savebutton = true; | |
105 | } | |
106 | $fullname = $setting->get_full_name(); | |
107 | if (array_key_exists($fullname, $adminroot->errors)) { | |
108 | $data = $adminroot->errors[$fullname]->data; | |
109 | } else { | |
110 | $data = $setting->get_setting(); | |
111 | } | |
112 | $outputhtml .= html_writer::tag('div', '<!-- -->', array('class' => 'clearer')); | |
113 | $outputhtml .= $setting->output_html($data); | |
83f78f8d | 114 | } |
b8b47a15 | 115 | $outputhtml .= html_writer::end_tag('fieldset'); |
83f78f8d | 116 | } |
b8b47a15 SH |
117 | } else if ($childpage instanceof admin_category) { |
118 | $outputhtml .= $OUTPUT->heading(html_writer::link(new moodle_url('/'.$CFG->admin.'/category.php', array('category' => $childpage->name)), get_string('admincategory', 'admin', $childpage->visiblename)), 3); | |
83f78f8d SH |
119 | } |
120 | } | |
121 | if ($savebutton) { | |
122 | $outputhtml .= html_writer::start_tag('div', array('class' => 'form-buttons')); | |
2f3f8e45 | 123 | $outputhtml .= html_writer::empty_tag('input', array('class' => 'btn btn-primary form-submit', 'type' => 'submit', 'value' => get_string('savechanges','admin'))); |
83f78f8d SH |
124 | $outputhtml .= html_writer::end_tag('div'); |
125 | } | |
126 | ||
127 | $visiblepathtosection = array_reverse($settingspage->visiblepath); | |
128 | $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection)); | |
129 | $PAGE->set_heading($SITE->fullname); | |
130 | $PAGE->set_button($buttons); | |
131 | ||
132 | echo $OUTPUT->header(); | |
133 | ||
134 | if ($errormsg !== '') { | |
135 | echo $OUTPUT->notification($errormsg); | |
136 | } else if ($statusmsg !== '') { | |
137 | echo $OUTPUT->notification($statusmsg, 'notifysuccess'); | |
138 | } | |
139 | ||
140 | $path = array_reverse($settingspage->visiblepath); | |
141 | if (is_array($path)) { | |
142 | $visiblename = join(' / ', $path); | |
143 | } else { | |
144 | $visiblename = $path; | |
145 | } | |
146 | echo $OUTPUT->heading(get_string('admincategory', 'admin', $visiblename), 2); | |
147 | ||
148 | echo html_writer::start_tag('form', array('action' => '', 'method' => 'post', 'id' => 'adminsettings')); | |
149 | echo html_writer::start_tag('div'); | |
150 | echo html_writer::input_hidden_params(new moodle_url($PAGE->url, array('sesskey' => sesskey(), 'return' => $return))); | |
151 | echo html_writer::end_tag('div'); | |
152 | echo html_writer::start_tag('fieldset'); | |
153 | echo html_writer::tag('div', '<!-- -->', array('class' => 'clearer')); | |
154 | echo $outputhtml; | |
155 | echo html_writer::end_tag('fieldset'); | |
156 | echo html_writer::end_tag('form'); | |
157 | ||
8babb960 | 158 | echo $OUTPUT->footer(); |