MDL-12598 use user context instead of personal; merged from MOODLE_19_STABLE
[moodle.git] / admin / settings.php
CommitLineData
90a73bb3 1<?php // $Id$
2
3require_once('../config.php');
6e4dc10f 4require_once($CFG->libdir.'/adminlib.php');
02cc05a7 5require_once($CFG->libdir.'/blocklib.php');
6require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php');
63aafc9e 7
8if ($site = get_site()) {
9 require_login();
eef868d1 10}
63aafc9e 11
90a73bb3 12
02cc05a7 13page_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 24if (!isset($USER->adminediting)) {
d83f27ce 25 $USER->adminediting = false;
3d8ef99d 26}
27
28if ($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 40if (!is_a($root, 'admin_settingpage')) {
41 error(get_string('sectionerror', 'admin'));
6fcbab99 42 die;
63aafc9e 43}
90a73bb3 44
63aafc9e 45if (!($root->check_access())) {
46 error(get_string('accessdenied', 'admin'));
6fcbab99 47 die;
63aafc9e 48}
90a73bb3 49
6ea5ff3a 50$CFG->pagepath = 'admin/setting/'.$section;
51
c6d33fce 52
53
e268cc4a 54/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
c6d33fce 55
e268cc4a 56$statusmsg = '';
90a73bb3 57
58if ($data = data_submitted()) {
59 if (confirm_sesskey()) {
fefea008 60 $olddbsessions = !empty($CFG->dbsessions);
56909d26 61 $unslashed = (array)stripslashes_recursive($data);
9cdb766d 62 $errors = $root->write_settings($unslashed);
fefea008 63 //force logout if dbsession setting changes
64 if ($olddbsessions != !empty($CFG->dbsessions)) {
65 require_logout();
66 }
90a73bb3 67 if (empty($errors)) {
e0f6e995 68 switch ($return) {
69 case 'site':
55f3a4db 70 redirect("$CFG->wwwroot/");
e0f6e995 71 case 'admin':
6859360c 72 redirect("$CFG->wwwroot/$CFG->admin/");
e0f6e995 73 default:
e268cc4a 74 $statusmsg = get_string('changessaved');
e0f6e995 75 }
6fcbab99 76 } else {
e268cc4a 77 $statusmsg = get_string('errorwithsettings', 'admin') . ' <br />' . $errors;
6fcbab99 78 }
79 } else {
80 error(get_string('confirmsesskeybad', 'error'));
6fcbab99 81 }
23a97d83 82 // now update $SITE - it might have been changed
83 $SITE = get_record('course', 'id', $SITE->id);
b89639f9 84 $COURSE = clone($SITE);
90a73bb3 85}
86
90a73bb3 87
e268cc4a 88/// print header stuff ------------------------------------------------------------
89// header must be printed after the redirects and require_logout
e5afdd27 90
91if (empty($SITE->fullname)) {
99571c3e 92 print_header($root->visiblename, $root->visiblename);
e5afdd27 93 print_simple_box(get_string('configintrosite', 'admin'), 'center', '50%');
94
95 if ($statusmsg != '') {
96 notify ($statusmsg);
97 }
98
99 // ---------------------------------------------------------------------------------------------------------------
100
101 echo '<form action="settings.php" method="post" id="adminsettings">';
0dc89caf 102 echo '<div class="settingsform clearfix">';
e5afdd27 103 echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />';
104 echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
105 echo '<input type="hidden" name="return" value="' . $return . '" />';
e5afdd27 106
107 echo $root->output_html();
108
109 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="' . get_string('savechanges','admin') . '" /></div>';
110
111 echo '</div>';
112 echo '</form>';
113}
114
e268cc4a 115if (!empty($SITE->fullname)) {
116 $pageblocks = blocks_setup($PAGE);
117
118 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
119 BLOCK_L_MAX_WIDTH);
120 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
121 BLOCK_R_MAX_WIDTH);
90a73bb3 122
e268cc4a 123 $PAGE->print_header();
124
125 echo '<table id="layout-table"><tr>';
e5afdd27 126 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
127 foreach ($lt as $column) {
128 switch ($column) {
129 case 'left':
e268cc4a 130 echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
9f7f1a74 131 print_container_start();
e268cc4a 132 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
9f7f1a74 133 print_container_end();
e268cc4a 134 echo '</td>';
e5afdd27 135 break;
136 case 'middle':
137 echo '<td id="middle-column">';
9f7f1a74 138 print_container_start();
e5afdd27 139 echo '<a name="startofcontent"></a>';
e268cc4a 140
e5afdd27 141 if ($statusmsg != '') {
142 notify ($statusmsg);
143 }
e268cc4a 144
e5afdd27 145 // ---------------------------------------------------------------------------------------------------------------
90a73bb3 146
e5afdd27 147 echo '<form action="settings.php" method="post" id="adminsettings">';
0dc89caf 148 echo '<div class="settingsform clearfix">';
e5afdd27 149 echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />';
150 echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
151 echo '<input type="hidden" name="return" value="' . $return . '" />';
152 print_heading($root->visiblename);
90a73bb3 153
e5afdd27 154 echo $root->output_html();
90a73bb3 155
e5afdd27 156 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="' . get_string('savechanges','admin') . '" /></div>';
fa040029 157
e5afdd27 158 echo '</div>';
159 echo '</form>';
b1ce7811 160
9f7f1a74 161 print_container_end();
b1ce7811 162 echo '</td>';
e5afdd27 163 break;
164 case 'right':
86d345d5 165 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) {
ec3938f3 166 echo '<td style="width: ' . $preferred_width_right . 'px;" id="right-column">';
9f7f1a74 167 print_container_start();
ec3938f3 168 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
9f7f1a74 169 print_container_end();
ec3938f3 170 echo '</td>';
e5afdd27 171 }
e5afdd27 172 break;
173 }
174 }
175 echo '</tr></table>';
b1ce7811 176}
90a73bb3 177
fa040029 178if (!empty($CFG->adminusehtmleditor)) {
179 use_html_editor();
180}
181
63aafc9e 182print_footer();
90a73bb3 183
bee4702d 184?>