90a73bb3 |
1 | <?php // $Id$ |
2 | |
3 | require_once('../config.php'); |
6e4dc10f |
4 | require_once($CFG->libdir.'/adminlib.php'); |
02cc05a7 |
5 | require_once($CFG->libdir.'/blocklib.php'); |
6 | require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php'); |
63aafc9e |
7 | |
8 | if ($site = get_site()) { |
9 | require_login(); |
eef868d1 |
10 | } |
63aafc9e |
11 | |
90a73bb3 |
12 | |
02cc05a7 |
13 | page_map_class(PAGE_ADMIN, 'page_admin'); |
90a73bb3 |
14 | |
e9a20759 |
15 | $PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number |
63aafc9e |
16 | |
6fcbab99 |
17 | $section = optional_param('section', '', PARAM_ALPHAEXT); |
18 | |
02cc05a7 |
19 | $PAGE->init_extra($section); // hack alert! |
63aafc9e |
20 | |
21 | $adminediting = optional_param('adminedit', -1, PARAM_BOOL); |
e0f6e995 |
22 | $return = optional_param('return','', PARAM_ALPHA); |
eef868d1 |
23 | |
3d8ef99d |
24 | if (!isset($USER->adminediting)) { |
d83f27ce |
25 | $USER->adminediting = false; |
3d8ef99d |
26 | } |
27 | |
28 | if ($PAGE->user_allowed_editing()) { |
63aafc9e |
29 | if ($adminediting == 1) { |
3d8ef99d |
30 | $USER->adminediting = true; |
63aafc9e |
31 | } elseif ($adminediting == 0) { |
3d8ef99d |
32 | $USER->adminediting = false; |
33 | } |
34 | } |
35 | |
6e4dc10f |
36 | $adminroot = admin_get_root(); |
90a73bb3 |
37 | |
6e4dc10f |
38 | $root = $adminroot->locate($PAGE->section); |
90a73bb3 |
39 | |
63aafc9e |
40 | if (!is_a($root, 'admin_settingpage')) { |
41 | error(get_string('sectionerror', 'admin')); |
6fcbab99 |
42 | die; |
63aafc9e |
43 | } |
90a73bb3 |
44 | |
63aafc9e |
45 | if (!($root->check_access())) { |
46 | error(get_string('accessdenied', 'admin')); |
6fcbab99 |
47 | die; |
63aafc9e |
48 | } |
90a73bb3 |
49 | |
6ea5ff3a |
50 | $CFG->pagepath = 'admin/setting/'.$section; |
51 | |
90a73bb3 |
52 | // WRITING SUBMITTED DATA (IF ANY) ------------------------------------------------------------------------------- |
53 | |
54 | if ($data = data_submitted()) { |
55 | if (confirm_sesskey()) { |
fefea008 |
56 | $olddbsessions = !empty($CFG->dbsessions); |
90a73bb3 |
57 | $errors = $root->write_settings((array)$data); |
fefea008 |
58 | //force logout if dbsession setting changes |
59 | if ($olddbsessions != !empty($CFG->dbsessions)) { |
60 | require_logout(); |
61 | } |
90a73bb3 |
62 | if (empty($errors)) { |
e0f6e995 |
63 | switch ($return) { |
64 | case 'site': |
55f3a4db |
65 | redirect("$CFG->wwwroot/"); |
e0f6e995 |
66 | case 'admin': |
55f3a4db |
67 | redirect("$CFG->wwwroot/admin/"); |
e0f6e995 |
68 | default: |
55f3a4db |
69 | // following redirect should display confirmation message because it redirects |
70 | // to the same page, user might not know if save button worked |
71 | redirect("$CFG->wwwroot/admin/settings.php?section=" . $PAGE->section, get_string('changessaved'),2); |
e0f6e995 |
72 | } |
6fcbab99 |
73 | } else { |
74 | error(get_string('errorwithsettings', 'admin') . ' <br />' . $errors); |
75 | } |
76 | } else { |
77 | error(get_string('confirmsesskeybad', 'error')); |
78 | die; |
79 | } |
90a73bb3 |
80 | } |
81 | |
82 | // --------------------------------------------------------------------------------------------------------------- |
83 | |
90a73bb3 |
84 | |
b1ce7811 |
85 | if (!empty($SITE->fullname)) { |
86 | $pageblocks = blocks_setup($PAGE); |
87 | |
eef868d1 |
88 | $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), |
b1ce7811 |
89 | BLOCK_L_MAX_WIDTH); |
eef868d1 |
90 | $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), |
b1ce7811 |
91 | BLOCK_R_MAX_WIDTH); |
eef868d1 |
92 | |
b1ce7811 |
93 | // print header stuff |
94 | $PAGE->print_header(); |
95 | |
96 | echo '<table id="layout-table"><tr>'; |
97 | echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">'; |
98 | blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); |
99 | echo '</td>'; |
100 | echo '<td id="middle-column" width="*">'; |
101 | } else { |
102 | |
103 | print_header(); |
104 | print_simple_box(get_string('configintrosite', 'admin'), 'center', '50%'); |
105 | |
106 | } |
90a73bb3 |
107 | |
90a73bb3 |
108 | echo '<form action="settings.php" method="post" name="mainform">'; |
109 | echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />'; |
110 | echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />'; |
e0f6e995 |
111 | echo '<input type="hidden" name="return" value="' . $return . '" />'; |
50999a0b |
112 | print_heading($root->visiblename); |
90a73bb3 |
113 | print_simple_box_start('','100%','',5,'generalbox',''); |
114 | |
115 | echo $root->output_html(); |
116 | |
7f35bd73 |
117 | echo '<center><input type="submit" value="' . get_string('savechanges','admin') . '" /></center>'; |
90a73bb3 |
118 | print_simple_box_end(); |
d83f27ce |
119 | echo '</form>'; |
b1ce7811 |
120 | |
121 | if (!empty($SITE->fullname)) { |
122 | echo '</td>'; |
123 | echo '<td style="width: ' . $preferred_width_right . 'px;" id="right-column">'; |
124 | blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); |
125 | echo '</td></tr></table>'; |
126 | } |
90a73bb3 |
127 | |
63aafc9e |
128 | print_footer(); |
90a73bb3 |
129 | |
bee4702d |
130 | ?> |