file SafeEmbed.php was added on branch MOODLE_19_STABLE on 2010-05-21 11:39:45 +0000
[moodle.git] / admin / settings.php
blob1ee435828488e8813a4b2665e778b65ef85389b8
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 $section = required_param('section', PARAM_SAFEDIR);
9 $return = optional_param('return','', PARAM_ALPHA);
10 $adminediting = optional_param('adminedit', -1, PARAM_BOOL);
12 /// no guest autologin
13 require_login(0, false);
15 $adminroot =& admin_get_root(); // need all settings
16 $page =& $adminroot->locate($section);
18 if (empty($page) or !is_a($page, 'admin_settingpage')) {
19 print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
20 die;
23 if (!($page->check_access())) {
24 print_error('accessdenied', 'admin');
25 die;
28 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
30 $statusmsg = '';
31 $errormsg = '';
32 $focus = '';
34 if ($data = data_submitted() and confirm_sesskey()) {
35 if (admin_write_settings($data)) {
36 $statusmsg = get_string('changessaved');
39 if (empty($adminroot->errors)) {
40 switch ($return) {
41 case 'site': redirect("$CFG->wwwroot/");
42 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
44 } else {
45 $errormsg = get_string('errorwithsettings', 'admin');
46 $firsterror = reset($adminroot->errors);
47 $focus = $firsterror->id;
49 $adminroot =& admin_get_root(true); //reload tree
50 $page =& $adminroot->locate($section);
53 /// very hacky page setup
54 page_map_class(PAGE_ADMIN, 'page_admin');
55 $PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
56 $PAGE->init_extra($section);
57 $CFG->pagepath = 'admin/setting/'.$section;
59 if (!isset($USER->adminediting)) {
60 $USER->adminediting = false;
63 if ($PAGE->user_allowed_editing()) {
64 if ($adminediting == 1) {
65 $USER->adminediting = true;
66 } elseif ($adminediting == 0) {
67 $USER->adminediting = false;
72 /// print header stuff ------------------------------------------------------------
74 if (empty($SITE->fullname)) {
75 print_header($page->visiblename, $page->visiblename, '', $focus);
76 print_simple_box(get_string('configintrosite', 'admin'), 'center', '50%');
78 if ($errormsg !== '') {
79 notify ($errormsg);
81 } else if ($statusmsg !== '') {
82 notify ($statusmsg, 'notifysuccess');
85 // ---------------------------------------------------------------------------------------------------------------
87 echo '<form action="settings.php" method="post" id="adminsettings">';
88 echo '<div class="settingsform clearfix">';
89 echo '<input type="hidden" name="section" value="'.$PAGE->section.'" />';
90 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
91 echo '<input type="hidden" name="return" value="'.$return.'" />';
93 echo $page->output_html();
95 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
97 echo '</div>';
98 echo '</form>';
100 } else {
101 $pageblocks = blocks_setup($PAGE);
103 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
104 BLOCK_L_MAX_WIDTH);
105 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
106 BLOCK_R_MAX_WIDTH);
108 $PAGE->print_header('', $focus);
110 echo '<table id="layout-table"><tr>';
111 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
112 foreach ($lt as $column) {
113 switch ($column) {
114 case 'left':
115 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
116 print_container_start();
117 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
118 print_container_end();
119 echo '</td>';
120 break;
121 case 'middle':
122 echo '<td id="middle-column">';
123 print_container_start();
124 echo '<a name="startofcontent"></a>';
126 if ($errormsg !== '') {
127 notify ($errormsg);
129 } else if ($statusmsg !== '') {
130 notify ($statusmsg, 'notifysuccess');
133 // ---------------------------------------------------------------------------------------------------------------
135 echo '<form action="settings.php" method="post" id="adminsettings">';
136 echo '<div class="settingsform clearfix">';
137 echo '<input type="hidden" name="section" value="'.$PAGE->section.'" />';
138 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
139 echo '<input type="hidden" name="return" value="'.$return.'" />';
140 print_heading($page->visiblename);
142 echo $page->output_html();
144 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
146 echo '</div>';
147 echo '</form>';
149 print_container_end();
150 echo '</td>';
151 break;
152 case 'right':
153 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) {
154 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
155 print_container_start();
156 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
157 print_container_end();
158 echo '</td>';
160 break;
163 echo '</tr></table>';
166 if (!empty($CFG->adminusehtmleditor)) {
167 use_html_editor();
170 print_footer();