Allowinng tables to create fields/keys/indexes using the one-pass-setters
[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);
e0f6e995 28$return = optional_param('return','', PARAM_ALPHA);
3d8ef99d 29
30if (!isset($USER->adminediting)) {
d83f27ce 31 $USER->adminediting = false;
3d8ef99d 32}
33
34if ($PAGE->user_allowed_editing()) {
63aafc9e 35 if ($adminediting == 1) {
3d8ef99d 36 $USER->adminediting = true;
63aafc9e 37 } elseif ($adminediting == 0) {
3d8ef99d 38 $USER->adminediting = false;
39 }
40}
41
6e4dc10f 42$adminroot = admin_get_root();
90a73bb3 43
6e4dc10f 44$root = $adminroot->locate($PAGE->section);
90a73bb3 45
63aafc9e 46if (!is_a($root, 'admin_settingpage')) {
47 error(get_string('sectionerror', 'admin'));
6fcbab99 48 die;
63aafc9e 49}
90a73bb3 50
63aafc9e 51if (!($root->check_access())) {
52 error(get_string('accessdenied', 'admin'));
6fcbab99 53 die;
63aafc9e 54}
90a73bb3 55
56// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
57
58if ($data = data_submitted()) {
59 if (confirm_sesskey()) {
60 $errors = $root->write_settings((array)$data);
61 if (empty($errors)) {
e0f6e995 62 switch ($return) {
63 case 'site':
64 redirect("$CFG->wwwroot/", get_string('changessaved'),1);
65 case 'admin':
66 redirect("$CFG->wwwroot/admin/", get_string('changessaved'),1);
67 default:
68 redirect("$CFG->wwwroot/admin/settings.php?section=" . $PAGE->section, get_string('changessaved'),1);
69 }
6fcbab99 70 } else {
71 error(get_string('errorwithsettings', 'admin') . ' <br />' . $errors);
72 }
73 } else {
74 error(get_string('confirmsesskeybad', 'error'));
75 die;
76 }
90a73bb3 77}
78
79// ---------------------------------------------------------------------------------------------------------------
80
81$pageblocks = blocks_setup($PAGE);
82
83$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
84
85// print header stuff
86$PAGE->print_header();
87echo '<table id="layout-table"><tr>';
88echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
89blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
90echo '</td>';
91echo '<td id="middle-column" width="*">';
92echo '<form action="settings.php" method="post" name="mainform">';
93echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />';
94echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
e0f6e995 95echo '<input type="hidden" name="return" value="' . $return . '" />';
90a73bb3 96print_simple_box_start('','100%','',5,'generalbox','');
97
98echo $root->output_html();
99
100echo '<center><input type="submit" value="Save Changes" /></center>';
90a73bb3 101print_simple_box_end();
d83f27ce 102echo '</form>';
63aafc9e 103echo '</td></tr></table>';
90a73bb3 104
63aafc9e 105print_footer();
90a73bb3 106
107?>