Merge branch 'MDL-27515_m19' of git://github.com/rwijaya/moodle into MOODLE_19_STABLE
[moodle.git] / admin / pagelib.php
blob1dee158b54cc35247e1874393a4d399cdcf49a84
1 <?php // $Id$
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 {
23 var $section = '';
24 var $visiblepathtosection;
25 var $extraurlparams = array();
26 var $extrabutton = '';
27 var $url = '';
29 // hack alert!
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) {
33 global $CFG;
35 if($this->full_init_done) {
36 return;
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);
46 // all done
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() {
62 global $USER;
63 return $USER->adminediting;
66 function url_get_path() {
67 global $CFG;
68 if (!empty($this->url)) {
69 return $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')) {
76 return $root->url;
77 } else {
78 return ($CFG->wwwroot . '/' . $CFG->admin . '/settings.php');
82 /**
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;
91 /**
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';
141 } else {
142 $caption = get_string('blocksediton');
143 $options['adminedit'] = 'on';
145 $buttons = print_single_button($this->url_get_path(), $options, $caption, 'get', '', true);
146 } else {
147 $buttons = '&nbsp;';
149 $buttons .= $this->extrabutton;
151 $navlinks = array();
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() {
161 return PAGE_ADMIN;