3 require_once($CFG->libdir
.'/pagelib.php');
5 define('PAGE_ADMIN', 'admin');
7 // Bounds for block widths
8 // more flexible for theme designers taken from theme config.php
9 $lmin = (empty($THEME->block_l_min_width
)) ?
0 : $THEME->block_l_min_width
;
10 $lmax = (empty($THEME->block_l_max_width
)) ?
210 : $THEME->block_l_max_width
;
11 $rmin = (empty($THEME->block_r_min_width
)) ?
0 : $THEME->block_r_min_width
;
12 $rmax = (empty($THEME->block_r_max_width
)) ?
210 : $THEME->block_r_max_width
;
14 define('BLOCK_L_MIN_WIDTH', $lmin);
15 define('BLOCK_L_MAX_WIDTH', $lmax);
16 define('BLOCK_R_MIN_WIDTH', $rmin);
17 define('BLOCK_R_MAX_WIDTH', $rmax);
19 page_map_class(PAGE_ADMIN
, 'page_admin');
21 class page_admin
extends page_base
{
24 var $visiblepathtosection;
25 var $extraurlparams = array();
26 var $extrabutton = '';
30 // this function works around the inability to store the section name
31 // in default block, maybe we should "improve" the blocks a bit?
32 function init_extra($section) {
35 if($this->full_init_done
) {
39 $adminroot =& admin_get_root(false, false); //settings not required - only pages
41 // fetch the path parameter
42 $this->section
= $section;
43 $current =& $adminroot->locate($section, true);
44 $this->visiblepathtosection
= array_reverse($current->visiblepath
);
47 $this->full_init_done
= true;
50 function blocks_get_default() {
51 return 'admin_tree,admin_bookmarks';
54 // seems reasonable that the only people that can edit blocks on the admin pages
55 // are the admins... but maybe we want a role for this?
56 function user_allowed_editing() {
57 return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM
));
60 // has to be fixed. i know there's a "proper" way to do this
61 function user_is_editing() {
63 return $USER->adminediting
;
66 function url_get_path() {
68 if (!empty($this->url
)) {
72 $adminroot =& admin_get_root(false, false); //settings not required - only pages
74 $root =& $adminroot->locate($this->section
);
75 if (is_a($root, 'admin_externalpage')) {
78 return ($CFG->wwwroot
. '/' . $CFG->admin
. '/settings.php');
83 * Use this to pass extra HTML that is added after the turn blocks editing on/off button.
85 * @param string $extrabutton HTML code.
87 function set_extra_button($extrabutton) {
88 $this->extrabutton
= $extrabutton;
92 * Use this to pass extra URL parameters that, for example, the blocks editing controls need to reload the current page accurately.
94 * @param array $extraurlparams paramname => value array.
96 function set_extra_url_params($extraurlparams, $actualurl = '') {
97 $this->extraurlparams
= $extraurlparams;
98 if (!empty($actualurl)) {
99 $this->url
= $actualurl;
103 function url_get_parameters() { // only handles parameters relevant to the admin pagetype
104 return array_merge($this->extraurlparams
, array('section' => $this->section
));
107 function blocks_get_positions() {
108 return array(BLOCK_POS_LEFT
, BLOCK_POS_RIGHT
);
111 function blocks_default_position() {
112 return BLOCK_POS_LEFT
;
115 function blocks_move_position(&$instance, $move) {
116 if($instance->position
== BLOCK_POS_LEFT
&& $move == BLOCK_MOVE_RIGHT
) {
117 return BLOCK_POS_RIGHT
;
118 } else if ($instance->position
== BLOCK_POS_RIGHT
&& $move == BLOCK_MOVE_LEFT
) {
119 return BLOCK_POS_LEFT
;
121 return $instance->position
;
124 // does anything need to be done here?
125 function init_quick($data) {
126 parent
::init_quick($data);
129 function print_header($section = '', $focus='') {
130 global $USER, $CFG, $SITE;
132 $this->init_full($section); // we're trusting that init_full() has already been called by now; it should have.
133 // if not, print_header() has to be called with a $section parameter
135 // The search page currently doesn't handle block editing
136 if ($this->section
!= 'search' and $this->user_allowed_editing()) {
137 $options = $this->url_get_parameters();
138 if ($this->user_is_editing()) {
139 $caption = get_string('blockseditoff');
140 $options['adminedit'] = 'off';
142 $caption = get_string('blocksediton');
143 $options['adminedit'] = 'on';
145 $buttons = print_single_button($this->url_get_path(), $options, $caption, 'get', '', true);
149 $buttons .= $this->extrabutton
;
152 foreach ($this->visiblepathtosection
as $element) {
153 $navlinks[] = array('name' => $element, 'link' => null, 'type' => 'misc');
155 $navigation = build_navigation($navlinks);
157 print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection
), $SITE->fullname
, $navigation, $focus, '', true, $buttons, '');
160 function get_type() {