Admin page cleanup (Google soc 2006)
[moodle.git] / admin / settings.php
CommitLineData
90a73bb3 1<?php // $Id$
2
3require_once('../config.php');
4require_once($CFG->dirroot . '/admin/adminlib.php');
5
6// for external pages, most of this code is duplicated in the admin_externalpage_print_header()
7// and admin_externalpage_print_footer() functions... just include adminlib.php!
8//
9// lines marked //d at the end are handled (for other pages) by admin_externalpage_print_header()
10// and admin_externalpage_print_footer()
11require_once($CFG->libdir . '/blocklib.php'); //d
12require_once($CFG->dirroot . '/admin/pagelib.php'); //d
13
14if ($site = get_site()) { //d
15 require_login(); //d
16} //d
17
18// Question: what pageid should be used for this?
19
20define('TEMPORARY_ADMIN_PAGE_ID',26); //d
21
22define('BLOCK_L_MIN_WIDTH',160); //d
23define('BLOCK_L_MAX_WIDTH',210); //d
24
25$pagetype = PAGE_ADMIN; //d
26$pageclass = 'page_admin'; //d
27page_map_class($pagetype, $pageclass); //d
28
29$PAGE = page_create_object($pagetype,TEMPORARY_ADMIN_PAGE_ID); //d
30
31$PAGE->init_full(); //d
32
33unset($root); //d
34
35$root = $ADMIN->locate($PAGE->section); //d
36
37if (!($root instanceof admin_settingpage)) { //d
38 error('Section does not exist, is invalid, or should not be accessed via this URL.'); //d
39 die; //d
40} //d
41
42if (!($root->check_access())) { //d
43 error('Access denied.'); //d
44 die; //d
45} //d
46
47// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
48
49if ($data = data_submitted()) {
50 if (confirm_sesskey()) {
51 $errors = $root->write_settings((array)$data);
52 if (empty($errors)) {
53 redirect("$CFG->wwwroot/admin/settings.php?section=" . $PAGE->section, get_string('changessaved'),1);
54 } else {
55 error('The following errors occurred when trying to save settings: <br />' . $errors);
56 }
57 } else {
58 error(get_string('confirmsesskeybad', 'error'));
59 die;
60 }
61}
62
63// ---------------------------------------------------------------------------------------------------------------
64
65$pageblocks = blocks_setup($PAGE);
66
67$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
68
69// print header stuff
70$PAGE->print_header();
71echo '<table id="layout-table"><tr>';
72echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
73blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
74echo '</td>';
75echo '<td id="middle-column" width="*">';
76echo '<form action="settings.php" method="post" name="mainform">';
77echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />';
78echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
79print_simple_box_start('','100%','',5,'generalbox','');
80
81echo $root->output_html();
82
83echo '<center><input type="submit" value="Save Changes" /></center>';
84echo '</form>';
85print_simple_box_end();
86echo '</td></tr></table>'; //d
87
88print_footer(); //d
89
90?>