90a73bb3 |
1 | <?php // $Id$ |
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)); |
ad52c04f |
13 | $PAGE->set_url($CFG->admin . '/settings.php', array('section' => $section)); |
f8b80dbd |
14 | $PAGE->set_pagetype('admin-setting-' . $section); |
90a73bb3 |
15 | |
4d933beb |
16 | $adminroot = admin_get_root(); // need all settings |
f8b80dbd |
17 | $settingspage = $adminroot->locate($section, true); |
90a73bb3 |
18 | |
f8b80dbd |
19 | if (empty($settingspage) or !($settingspage instanceof admin_settingpage)) { |
1d8bf5f0 |
20 | print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/"); |
6fcbab99 |
21 | die; |
63aafc9e |
22 | } |
90a73bb3 |
23 | |
f8b80dbd |
24 | if (!($settingspage->check_access())) { |
1d8bf5f0 |
25 | print_error('accessdenied', 'admin'); |
6fcbab99 |
26 | die; |
63aafc9e |
27 | } |
90a73bb3 |
28 | |
e268cc4a |
29 | /// WRITING SUBMITTED DATA (IF ANY) ------------------------------------------------------------------------------- |
c6d33fce |
30 | |
e268cc4a |
31 | $statusmsg = ''; |
220a90c5 |
32 | $errormsg = ''; |
33 | $focus = ''; |
90a73bb3 |
34 | |
294ce987 |
35 | if ($data = data_submitted() and confirm_sesskey()) { |
220a90c5 |
36 | if (admin_write_settings($data)) { |
37 | $statusmsg = get_string('changessaved'); |
38 | } |
39 | |
40 | if (empty($adminroot->errors)) { |
41 | switch ($return) { |
f8b80dbd |
42 | case 'site': redirect("$CFG->wwwroot/"); |
220a90c5 |
43 | case 'admin': redirect("$CFG->wwwroot/$CFG->admin/"); |
6fcbab99 |
44 | } |
45 | } else { |
220a90c5 |
46 | $errormsg = get_string('errorwithsettings', 'admin'); |
47 | $firsterror = reset($adminroot->errors); |
48 | $focus = $firsterror->id; |
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)) { |
f8b80dbd |
60 | print_header($settingspage->visiblename, $settingspage->visiblename, '', $focus); |
e5afdd27 |
61 | print_simple_box(get_string('configintrosite', 'admin'), 'center', '50%'); |
62 | |
220a90c5 |
63 | if ($errormsg !== '') { |
64 | notify ($errormsg); |
65 | |
66 | } else if ($statusmsg !== '') { |
67 | notify ($statusmsg, 'notifysuccess'); |
e5afdd27 |
68 | } |
69 | |
70 | // --------------------------------------------------------------------------------------------------------------- |
71 | |
72 | echo '<form action="settings.php" method="post" id="adminsettings">'; |
0dc89caf |
73 | echo '<div class="settingsform clearfix">'; |
ac9e2207 |
74 | echo $PAGE->url->hidden_params_out(); |
d4a1fcaf |
75 | echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; |
220a90c5 |
76 | echo '<input type="hidden" name="return" value="'.$return.'" />'; |
e5afdd27 |
77 | |
f8b80dbd |
78 | echo $settingspage->output_html(); |
e5afdd27 |
79 | |
220a90c5 |
80 | echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>'; |
e5afdd27 |
81 | |
82 | echo '</div>'; |
83 | echo '</form>'; |
e5afdd27 |
84 | |
220a90c5 |
85 | } else { |
f8b80dbd |
86 | if ($PAGE->user_allowed_editing()) { |
87 | $options = $PAGE->url->params(); |
88 | if ($PAGE->user_is_editing()) { |
89 | $caption = get_string('blockseditoff'); |
90 | $options['adminedit'] = 'off'; |
91 | } else { |
92 | $caption = get_string('blocksediton'); |
93 | $options['adminedit'] = 'on'; |
94 | } |
95 | $buttons = print_single_button($PAGE->url->out(false), $options, $caption, 'get', '', true); |
96 | } |
97 | |
98 | $visiblepathtosection = array_reverse($settingspage->visiblepath); |
99 | $navlinks = array(); |
100 | foreach ($visiblepathtosection as $element) { |
101 | $navlinks[] = array('name' => $element, 'link' => null, 'type' => 'misc'); |
102 | } |
103 | $navigation = build_navigation($navlinks); |
90a73bb3 |
104 | |
f8b80dbd |
105 | print_header("$SITE->shortname: " . implode(": ",$visiblepathtosection), $SITE->fullname, $navigation, $focus, '', true, $buttons, ''); |
e268cc4a |
106 | |
220a90c5 |
107 | if ($errormsg !== '') { |
108 | notify ($errormsg); |
109 | |
110 | } else if ($statusmsg !== '') { |
111 | notify ($statusmsg, 'notifysuccess'); |
e5afdd27 |
112 | } |
e268cc4a |
113 | |
e5afdd27 |
114 | // --------------------------------------------------------------------------------------------------------------- |
90a73bb3 |
115 | |
e5afdd27 |
116 | echo '<form action="settings.php" method="post" id="adminsettings">'; |
0dc89caf |
117 | echo '<div class="settingsform clearfix">'; |
ac9e2207 |
118 | echo $PAGE->url->hidden_params_out(); |
d4a1fcaf |
119 | echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; |
220a90c5 |
120 | echo '<input type="hidden" name="return" value="'.$return.'" />'; |
2fff8846 |
121 | echo $OUTPUT->heading($settingspage->visiblename); |
90a73bb3 |
122 | |
f8b80dbd |
123 | echo $settingspage->output_html(); |
90a73bb3 |
124 | |
220a90c5 |
125 | echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>'; |
fa040029 |
126 | |
e5afdd27 |
127 | echo '</div>'; |
128 | echo '</form>'; |
b1ce7811 |
129 | } |
90a73bb3 |
130 | |
73d6f52f |
131 | echo $OUTPUT->footer(); |
90a73bb3 |
132 | |
bee4702d |
133 | ?> |