forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagelib.php
116 lines (88 loc) · 3.66 KB
/
pagelib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php // $Id$
require_once($CFG->libdir.'/pagelib.php');
define('PAGE_ADMIN', 'admin');
page_map_class(PAGE_ADMIN, 'page_admin');
class page_admin extends page_base {
var $section;
var $pathtosection;
var $visiblepathtosection;
// hack alert!
// this function works around the inability to store the section name
// in default block, maybe we should "improve" the blocks a bit?
function init_extra($section) {
global $CFG;
if($this->full_init_done) {
return;
}
$adminroot = admin_get_root();
// fetch the path parameter
$this->section = $section;
$this->visiblepathtosection = array();
// this part is (potentially) processor-intensive... there's gotta be a better way
// of handling this
if ($this->pathtosection = $adminroot->path($this->section)) {
foreach($this->pathtosection as $element) {
if ($pointer = $adminroot->locate($element)) {
array_push($this->visiblepathtosection, $pointer->visiblename);
}
}
}
// all done
$this->full_init_done = true;
}
function blocks_get_default() {
return 'admin_tree,admin_bookmarks';
}
// seems reasonable that the only people that can edit blocks on the admin pages
// are the admins... but maybe we want a role for this?
function user_allowed_editing() {
return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID));
}
// has to be fixed. i know there's a "proper" way to do this
function user_is_editing() {
global $USER;
return $USER->adminediting;
}
function url_get_path() {
global $CFG;
$adminroot = admin_get_root();
$root = $adminroot->locate($this->section);
if (is_a($root, 'admin_externalpage')) {
return $root->url;
} else {
return ($CFG->wwwroot . '/' . $CFG->admin . '/settings.php');
}
}
function url_get_parameters() { // only handles parameters relevant to the admin pagetype
return array('section' => (isset($this->section) ? $this->section : ''));
}
function blocks_get_positions() {
return array(BLOCK_POS_LEFT);
}
function blocks_default_position() {
return BLOCK_POS_LEFT;
}
// does anything need to be done here?
function init_quick($data) {
parent::init_quick($data);
}
function print_header($section = '') {
global $USER, $CFG, $SITE;
$this->init_full($section); // we're trusting that init_full() has already been called by now; it should have.
// if not, print_header() has to be called with a $section parameter
if ($this->user_allowed_editing()) {
$buttons = '<table><tr><td><form target="' . $CFG->framename . '" method="get" action="' . $this->url_get_path() . '">'.
'<input type="hidden" name="adminedit" value="'.($this->user_is_editing()?'off':'on').'" />'.
'<input type="hidden" name="section" value="'.$this->section.'" />'.
'<input type="submit" value="'.get_string($this->user_is_editing()?'blockseditoff':'blocksediton').'" /></form></td>' .
'</tr></table>';
} else {
$buttons = ' ';
}
print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection), $SITE->fullname, implode(" -> ",$this->visiblepathtosection),'', '', true, $buttons, '');
}
function get_type() {
return PAGE_ADMIN;
}
}
?>