moodle_page: MDL-12212 reimplement user_is_editing, deprecate isediting
[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
220a90c5 8$section = required_param('section', PARAM_SAFEDIR);
e0f6e995 9$return = optional_param('return','', PARAM_ALPHA);
220a90c5 10$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
eef868d1 11
9a7a7851 12/// no guest autologin
13require_login(0, false);
f230ce19 14$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
ad52c04f 15$PAGE->set_url($CFG->admin . '/settings.php', array('section' => $section));
90a73bb3 16
4d933beb
JN
17$adminroot = admin_get_root(); // need all settings
18$page = $adminroot->locate($section);
90a73bb3 19
4d933beb 20if (empty($page) or !($page instanceof admin_settingpage)) {
1d8bf5f0 21 print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
6fcbab99 22 die;
63aafc9e 23}
90a73bb3 24
220a90c5 25if (!($page->check_access())) {
1d8bf5f0 26 print_error('accessdenied', 'admin');
6fcbab99 27 die;
63aafc9e 28}
90a73bb3 29
e268cc4a 30/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
c6d33fce 31
e268cc4a 32$statusmsg = '';
220a90c5 33$errormsg = '';
34$focus = '';
90a73bb3 35
294ce987 36if ($data = data_submitted() and confirm_sesskey()) {
220a90c5 37 if (admin_write_settings($data)) {
38 $statusmsg = get_string('changessaved');
39 }
40
41 if (empty($adminroot->errors)) {
42 switch ($return) {
43 case 'site': redirect("$CFG->wwwroot/");
44 case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
6fcbab99 45 }
46 } else {
220a90c5 47 $errormsg = get_string('errorwithsettings', 'admin');
48 $firsterror = reset($adminroot->errors);
49 $focus = $firsterror->id;
50 }
51 $adminroot =& admin_get_root(true); //reload tree
52 $page =& $adminroot->locate($section);
53}
54
55/// very hacky page setup
56page_map_class(PAGE_ADMIN, 'page_admin');
57$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
ad5d5997 58$PAGE->set_pagetype('admin-setting-' . $section);
d7ab8879 59$PAGE->init_extra($section);
220a90c5 60
830dd6e9 61if ($PAGE->user_allowed_editing() && $adminediting != -1) {
62 $USER->editing = $adminediting;
90a73bb3 63}
64
90a73bb3 65
e268cc4a 66/// print header stuff ------------------------------------------------------------
e5afdd27 67
68if (empty($SITE->fullname)) {
220a90c5 69 print_header($page->visiblename, $page->visiblename, '', $focus);
e5afdd27 70 print_simple_box(get_string('configintrosite', 'admin'), 'center', '50%');
71
220a90c5 72 if ($errormsg !== '') {
73 notify ($errormsg);
74
75 } else if ($statusmsg !== '') {
76 notify ($statusmsg, 'notifysuccess');
e5afdd27 77 }
78
79 // ---------------------------------------------------------------------------------------------------------------
80
81 echo '<form action="settings.php" method="post" id="adminsettings">';
0dc89caf 82 echo '<div class="settingsform clearfix">';
220a90c5 83 echo '<input type="hidden" name="section" value="'.$PAGE->section.'" />';
d4a1fcaf 84 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
220a90c5 85 echo '<input type="hidden" name="return" value="'.$return.'" />';
e5afdd27 86
220a90c5 87 echo $page->output_html();
e5afdd27 88
220a90c5 89 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
e5afdd27 90
91 echo '</div>';
92 echo '</form>';
e5afdd27 93
220a90c5 94} else {
e268cc4a 95 $pageblocks = blocks_setup($PAGE);
96
97 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
98 BLOCK_L_MAX_WIDTH);
99 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
100 BLOCK_R_MAX_WIDTH);
90a73bb3 101
ad52c04f 102 $PAGE->print_header($focus);
e268cc4a 103
104 echo '<table id="layout-table"><tr>';
e5afdd27 105 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
106 foreach ($lt as $column) {
107 switch ($column) {
108 case 'left':
220a90c5 109 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
9f7f1a74 110 print_container_start();
e268cc4a 111 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
9f7f1a74 112 print_container_end();
e268cc4a 113 echo '</td>';
e5afdd27 114 break;
115 case 'middle':
116 echo '<td id="middle-column">';
9f7f1a74 117 print_container_start();
e5afdd27 118 echo '<a name="startofcontent"></a>';
e268cc4a 119
220a90c5 120 if ($errormsg !== '') {
121 notify ($errormsg);
122
123 } else if ($statusmsg !== '') {
124 notify ($statusmsg, 'notifysuccess');
e5afdd27 125 }
e268cc4a 126
e5afdd27 127 // ---------------------------------------------------------------------------------------------------------------
90a73bb3 128
e5afdd27 129 echo '<form action="settings.php" method="post" id="adminsettings">';
0dc89caf 130 echo '<div class="settingsform clearfix">';
220a90c5 131 echo '<input type="hidden" name="section" value="'.$PAGE->section.'" />';
d4a1fcaf 132 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
220a90c5 133 echo '<input type="hidden" name="return" value="'.$return.'" />';
134 print_heading($page->visiblename);
90a73bb3 135
220a90c5 136 echo $page->output_html();
90a73bb3 137
220a90c5 138 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
fa040029 139
e5afdd27 140 echo '</div>';
141 echo '</form>';
b1ce7811 142
9f7f1a74 143 print_container_end();
b1ce7811 144 echo '</td>';
e5afdd27 145 break;
146 case 'right':
86d345d5 147 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) {
220a90c5 148 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
9f7f1a74 149 print_container_start();
ec3938f3 150 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
9f7f1a74 151 print_container_end();
ec3938f3 152 echo '</td>';
e5afdd27 153 }
e5afdd27 154 break;
155 }
156 }
157 echo '</tr></table>';
b1ce7811 158}
90a73bb3 159
63aafc9e 160print_footer();
90a73bb3 161
bee4702d 162?>