MDL-11515:
[moodle-linuxchix.git] / admin / settings.php
blobad25c9c1c5020c67939bab146451676d345bf3d7
1 <?php // $Id$
3 require_once('../config.php');
4 require_once($CFG->libdir.'/adminlib.php');
5 require_once($CFG->libdir.'/blocklib.php');
6 require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php');
8 if (!empty($THEME->customcorners)) {
9 require_once($CFG->dirroot.'/lib/custom_corners_lib.php');
12 if ($site = get_site()) {
13 require_login();
17 page_map_class(PAGE_ADMIN, 'page_admin');
19 $PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
21 $section = optional_param('section', '', PARAM_ALPHAEXT);
23 $PAGE->init_extra($section); // hack alert!
25 $adminediting = optional_param('adminedit', -1, PARAM_BOOL);
26 $return = optional_param('return','', PARAM_ALPHA);
28 if (!isset($USER->adminediting)) {
29 $USER->adminediting = false;
32 if ($PAGE->user_allowed_editing()) {
33 if ($adminediting == 1) {
34 $USER->adminediting = true;
35 } elseif ($adminediting == 0) {
36 $USER->adminediting = false;
40 $adminroot = admin_get_root();
42 $root = $adminroot->locate($PAGE->section);
44 if (!is_a($root, 'admin_settingpage')) {
45 error(get_string('sectionerror', 'admin'));
46 die;
49 if (!($root->check_access())) {
50 error(get_string('accessdenied', 'admin'));
51 die;
54 $CFG->pagepath = 'admin/setting/'.$section;
58 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
60 $statusmsg = '';
62 if ($data = data_submitted()) {
63 if (confirm_sesskey()) {
64 $olddbsessions = !empty($CFG->dbsessions);
65 $unslashed = (array)stripslashes_recursive($data);
66 $errors = $root->write_settings($unslashed);
67 //force logout if dbsession setting changes
68 if ($olddbsessions != !empty($CFG->dbsessions)) {
69 require_logout();
71 if (empty($errors)) {
72 switch ($return) {
73 case 'site':
74 redirect("$CFG->wwwroot/");
75 case 'admin':
76 redirect("$CFG->wwwroot/$CFG->admin/");
77 default:
78 $statusmsg = get_string('changessaved');
80 } else {
81 $statusmsg = get_string('errorwithsettings', 'admin') . ' <br />' . $errors;
83 } else {
84 error(get_string('confirmsesskeybad', 'error'));
86 // now update $SITE - it might have been changed
87 $SITE = get_record('course', 'id', $SITE->id);
88 $COURSE = clone($SITE);
92 /// print header stuff ------------------------------------------------------------
93 // header must be printed after the redirects and require_logout
95 if (empty($SITE->fullname)) {
96 print_header($root->visiblename, $root->visiblename);
97 print_simple_box(get_string('configintrosite', 'admin'), 'center', '50%');
99 if ($statusmsg != '') {
100 notify ($statusmsg);
103 // ---------------------------------------------------------------------------------------------------------------
105 echo '<form action="settings.php" method="post" id="adminsettings">';
106 echo '<div class="settingsform clearfix">';
107 echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />';
108 echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
109 echo '<input type="hidden" name="return" value="' . $return . '" />';
111 echo $root->output_html();
113 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="' . get_string('savechanges','admin') . '" /></div>';
115 echo '</div>';
116 echo '</form>';
119 if (!empty($SITE->fullname)) {
120 $pageblocks = blocks_setup($PAGE);
122 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
123 BLOCK_L_MAX_WIDTH);
124 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
125 BLOCK_R_MAX_WIDTH);
127 $PAGE->print_header();
129 echo '<table id="layout-table"><tr>';
130 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
131 foreach ($lt as $column) {
132 switch ($column) {
133 case 'left':
134 echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
135 if (!empty($THEME->customcorners)) print_custom_corners_start();
136 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
137 if (!empty($THEME->customcorners)) print_custom_corners_end();
138 echo '</td>';
139 break;
140 case 'middle':
141 echo '<td id="middle-column">';
142 if (!empty($THEME->customcorners)) print_custom_corners_start();
143 echo '<a name="startofcontent"></a>';
145 if ($statusmsg != '') {
146 notify ($statusmsg);
149 // ---------------------------------------------------------------------------------------------------------------
151 echo '<form action="settings.php" method="post" id="adminsettings">';
152 echo '<div class="settingsform clearfix">';
153 echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />';
154 echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
155 echo '<input type="hidden" name="return" value="' . $return . '" />';
156 print_heading($root->visiblename);
158 echo $root->output_html();
160 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="' . get_string('savechanges','admin') . '" /></div>';
162 echo '</div>';
163 echo '</form>';
165 if (!empty($THEME->customcorners)) print_custom_corners_end();
166 echo '</td>';
167 break;
168 case 'right':
169 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) {
170 echo '<td style="width: ' . $preferred_width_right . 'px;" id="right-column">';
171 if (!empty($THEME->customcorners)) print_custom_corners_start();
172 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
173 if (!empty($THEME->customcorners)) print_custom_corners_end();
174 echo '</td>';
176 break;
179 echo '</tr></table>';
182 if (!empty($CFG->adminusehtmleditor)) {
183 use_html_editor();
186 print_footer();