fixed site defaults, reorganized administartion tree - new category legacy for obsole...
[moodle.git] / admin / settings.php
CommitLineData
90a73bb3 1<?php // $Id$
2
3require_once('../config.php');
6e4dc10f 4require_once($CFG->libdir.'/adminlib.php');
6fcbab99 5require_once($CFG->libdir . '/blocklib.php');
6e4dc10f 6require_once($CFG->dirroot . '/admin/pagelib.php');
63aafc9e 7
8if ($site = get_site()) {
9 require_login();
10}
11
12define('TEMPORARY_ADMIN_PAGE_ID',26);
13
14define('BLOCK_L_MIN_WIDTH',160);
15define('BLOCK_L_MAX_WIDTH',210);
90a73bb3 16
63aafc9e 17$pagetype = PAGE_ADMIN;
18$pageclass = 'page_admin';
19page_map_class($pagetype, $pageclass);
90a73bb3 20
63aafc9e 21$PAGE = page_create_object($pagetype,TEMPORARY_ADMIN_PAGE_ID);
22
6fcbab99 23$section = optional_param('section', '', PARAM_ALPHAEXT);
24
25$PAGE->init_full($section);
63aafc9e 26
27$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
3d8ef99d 28
29if (!isset($USER->adminediting)) {
d83f27ce 30 $USER->adminediting = false;
3d8ef99d 31}
32
33if ($PAGE->user_allowed_editing()) {
63aafc9e 34 if ($adminediting == 1) {
3d8ef99d 35 $USER->adminediting = true;
63aafc9e 36 } elseif ($adminediting == 0) {
3d8ef99d 37 $USER->adminediting = false;
38 }
39}
40
6e4dc10f 41$adminroot = admin_get_root();
90a73bb3 42
6e4dc10f 43$root = $adminroot->locate($PAGE->section);
90a73bb3 44
63aafc9e 45if (!is_a($root, 'admin_settingpage')) {
46 error(get_string('sectionerror', 'admin'));
6fcbab99 47 die;
63aafc9e 48}
90a73bb3 49
63aafc9e 50if (!($root->check_access())) {
51 error(get_string('accessdenied', 'admin'));
6fcbab99 52 die;
63aafc9e 53}
90a73bb3 54
55// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
56
57if ($data = data_submitted()) {
58 if (confirm_sesskey()) {
59 $errors = $root->write_settings((array)$data);
60 if (empty($errors)) {
6fcbab99 61 redirect("$CFG->wwwroot/admin/settings.php?section=" . $PAGE->section, get_string('changessaved'),1);
62 } else {
63 error(get_string('errorwithsettings', 'admin') . ' <br />' . $errors);
64 }
65 } else {
66 error(get_string('confirmsesskeybad', 'error'));
67 die;
68 }
90a73bb3 69}
70
71// ---------------------------------------------------------------------------------------------------------------
72
73$pageblocks = blocks_setup($PAGE);
74
75$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
76
77// print header stuff
78$PAGE->print_header();
79echo '<table id="layout-table"><tr>';
80echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
81blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
82echo '</td>';
83echo '<td id="middle-column" width="*">';
84echo '<form action="settings.php" method="post" name="mainform">';
85echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />';
86echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
87print_simple_box_start('','100%','',5,'generalbox','');
88
89echo $root->output_html();
90
91echo '<center><input type="submit" value="Save Changes" /></center>';
90a73bb3 92print_simple_box_end();
d83f27ce 93echo '</form>';
63aafc9e 94echo '</td></tr></table>';
90a73bb3 95
63aafc9e 96print_footer();
90a73bb3 97
98?>