moodle_page: MDL-12212 reimplement user_is_editing, deprecate isediting
[moodle.git] / admin / pagelib.php
CommitLineData
90a73bb3 1<?php // $Id$
2
90a73bb3 3require_once($CFG->libdir.'/pagelib.php');
4
02cc05a7 5define('PAGE_ADMIN', 'admin');
90a73bb3 6
c15816ce 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;
13
14define('BLOCK_L_MIN_WIDTH', $lmin);
15define('BLOCK_L_MAX_WIDTH', $lmax);
16define('BLOCK_R_MIN_WIDTH', $rmin);
17define('BLOCK_R_MAX_WIDTH', $rmax);
73c24ef8 18
90a73bb3 19page_map_class(PAGE_ADMIN, 'page_admin');
20
90a73bb3 21class page_admin extends page_base {
92f00846 22 var $extrabutton = '';
90a73bb3 23
ad52c04f 24 function _legacy_blocks_get_default() {
02cc05a7 25 return 'admin_tree,admin_bookmarks';
90a73bb3 26 }
27
28 // seems reasonable that the only people that can edit blocks on the admin pages
29 // are the admins... but maybe we want a role for this?
73c24ef8 30 function user_allowed_editing() {
957f6fc9 31 return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM));
90a73bb3 32 }
33
92f00846 34 /**
35 * Use this to pass extra HTML that is added after the turn blocks editing on/off button.
36 *
37 * @param string $extrabutton HTML code.
38 */
39 function set_extra_button($extrabutton) {
40 $this->extrabutton = $extrabutton;
41 }
42
ad52c04f 43 function print_header($focus='') {
90a73bb3 44 global $USER, $CFG, $SITE;
45
ad52c04f 46 $adminroot = admin_get_root(false, false); //settings not required - only pages
47
48 // fetch the path parameter
49 $section = $this->url->param('section');
50 $current = $adminroot->locate($section, true);
51 $visiblepathtosection = array_reverse($current->visiblepath);
90a73bb3 52
73c24ef8 53 // The search page currently doesn't handle block editing
ad52c04f 54 if ($this->user_allowed_editing()) {
55 $options = $this->url->params();
92f00846 56 if ($this->user_is_editing()) {
57 $caption = get_string('blockseditoff');
58 $options['adminedit'] = 'off';
59 } else {
60 $caption = get_string('blocksediton');
61 $options['adminedit'] = 'on';
62 }
ad52c04f 63 $buttons = print_single_button($this->url->out(false), $options, $caption, 'get', '', true);
90a73bb3 64 }
92f00846 65 $buttons .= $this->extrabutton;
a044c05d 66
73c24ef8 67 $navlinks = array();
ad52c04f 68 foreach ($visiblepathtosection as $element) {
73c24ef8 69 $navlinks[] = array('name' => $element, 'link' => null, 'type' => 'misc');
70 }
71 $navigation = build_navigation($navlinks);
72
ad52c04f 73 print_header("$SITE->shortname: " . implode(": ",$visiblepathtosection), $SITE->fullname, $navigation, $focus, '', true, $buttons, '');
90a73bb3 74 }
90a73bb3 75}
76
b1ce7811 77?>