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
{
25 var $visiblepathtosection;
28 // this function works around the inability to store the section name
29 // in default block, maybe we should "improve" the blocks a bit?
30 function init_extra($section) {
33 if($this->full_init_done
) {
37 $adminroot = admin_get_root();
39 // fetch the path parameter
40 $this->section
= $section;
42 $this->visiblepathtosection
= array();
44 // this part is (potentially) processor-intensive... there's gotta be a better way
46 if ($this->pathtosection
= $adminroot->path($this->section
)) {
47 foreach($this->pathtosection
as $element) {
48 if ($pointer = $adminroot->locate($element)) {
49 array_push($this->visiblepathtosection
, $pointer->visiblename
);
55 $this->full_init_done
= true;
58 function blocks_get_default() {
59 return 'admin_tree,admin_bookmarks';
62 // seems reasonable that the only people that can edit blocks on the admin pages
63 // are the admins... but maybe we want a role for this?
64 function user_allowed_editing() {
65 return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM
, SITEID
));
68 // has to be fixed. i know there's a "proper" way to do this
69 function user_is_editing() {
71 return $USER->adminediting
;
74 function url_get_path() {
77 $adminroot = admin_get_root();
79 $root = $adminroot->locate($this->section
);
80 if (is_a($root, 'admin_externalpage')) {
83 return ($CFG->wwwroot
. '/' . $CFG->admin
. '/settings.php');
87 function url_get_parameters() { // only handles parameters relevant to the admin pagetype
88 return array('section' => (isset($this->section
) ?
$this->section
: ''));
91 function blocks_get_positions() {
92 return array(BLOCK_POS_LEFT
, BLOCK_POS_RIGHT
);
95 function blocks_default_position() {
96 return BLOCK_POS_LEFT
;
99 function blocks_move_position(&$instance, $move) {
100 if($instance->position
== BLOCK_POS_LEFT
&& $move == BLOCK_MOVE_RIGHT
) {
101 return BLOCK_POS_RIGHT
;
102 } else if ($instance->position
== BLOCK_POS_RIGHT
&& $move == BLOCK_MOVE_LEFT
) {
103 return BLOCK_POS_LEFT
;
105 return $instance->position
;
108 // does anything need to be done here?
109 function init_quick($data) {
110 parent
::init_quick($data);
113 function print_header($section = '') {
114 global $USER, $CFG, $SITE;
116 $this->init_full($section); // we're trusting that init_full() has already been called by now; it should have.
117 // if not, print_header() has to be called with a $section parameter
119 // The search page currently doesn't handle block editing
120 if ($this->section
!= 'search' and $this->user_allowed_editing()) {
121 $buttons = '<div><form '.$CFG->frametarget
.' method="get" action="' . $this->url_get_path() . '">'.
122 '<div><input type="hidden" name="adminedit" value="'.($this->user_is_editing()?
'off':'on').'" />'.
123 '<input type="hidden" name="section" value="'.$this->section
.'" />'.
124 '<input type="submit" value="'.get_string($this->user_is_editing()?
'blockseditoff':'blocksediton').'" /></div></form></div>';
130 foreach ($this->visiblepathtosection
as $element) {
131 $navlinks[] = array('name' => $element, 'link' => null, 'type' => 'misc');
133 $navigation = build_navigation($navlinks);
135 print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection
), $SITE->fullname
, $navigation,'', '', true, $buttons, '');
138 function get_type() {