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