3 require_once($CFG->libdir
.'/pagelib.php');
5 define('PAGE_ADMIN', 'admin');
7 define('BLOCK_L_MIN_WIDTH',0);
8 define('BLOCK_L_MAX_WIDTH',210);
9 define('BLOCK_R_MIN_WIDTH',0);
10 define('BLOCK_R_MAX_WIDTH',210);
12 page_map_class(PAGE_ADMIN
, 'page_admin');
14 class page_admin
extends page_base
{
18 var $visiblepathtosection;
21 // this function works around the inability to store the section name
22 // in default block, maybe we should "improve" the blocks a bit?
23 function init_extra($section) {
26 if($this->full_init_done
) {
30 $adminroot = admin_get_root();
32 // fetch the path parameter
33 $this->section
= $section;
35 $this->visiblepathtosection
= array();
37 // this part is (potentially) processor-intensive... there's gotta be a better way
39 if ($this->pathtosection
= $adminroot->path($this->section
)) {
40 foreach($this->pathtosection
as $element) {
41 if ($pointer = $adminroot->locate($element)) {
42 array_push($this->visiblepathtosection
, $pointer->visiblename
);
48 $this->full_init_done
= true;
51 function blocks_get_default() {
52 return 'admin_tree,admin_bookmarks';
55 // seems reasonable that the only people that can edit blocks on the admin pages
56 // are the admins... but maybe we want a role for this?
57 function user_allowed_editing() {
58 return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM
, SITEID
));
61 // has to be fixed. i know there's a "proper" way to do this
62 function user_is_editing() {
64 return $USER->adminediting
;
67 function url_get_path() {
70 $adminroot = admin_get_root();
72 $root = $adminroot->locate($this->section
);
73 if (is_a($root, 'admin_externalpage')) {
76 return ($CFG->wwwroot
. '/' . $CFG->admin
. '/settings.php');
80 function url_get_parameters() { // only handles parameters relevant to the admin pagetype
81 return array('section' => (isset($this->section
) ?
$this->section
: ''));
84 function blocks_get_positions() {
85 return array(BLOCK_POS_LEFT
, BLOCK_POS_RIGHT
);
88 function blocks_default_position() {
89 return BLOCK_POS_LEFT
;
92 function blocks_move_position(&$instance, $move) {
93 if($instance->position
== BLOCK_POS_LEFT
&& $move == BLOCK_MOVE_RIGHT
) {
94 return BLOCK_POS_RIGHT
;
95 } else if ($instance->position
== BLOCK_POS_RIGHT
&& $move == BLOCK_MOVE_LEFT
) {
96 return BLOCK_POS_LEFT
;
98 return $instance->position
;
101 // does anything need to be done here?
102 function init_quick($data) {
103 parent
::init_quick($data);
106 function print_header($section = '') {
107 global $USER, $CFG, $SITE;
109 $this->init_full($section); // we're trusting that init_full() has already been called by now; it should have.
110 // if not, print_header() has to be called with a $section parameter
112 if ($this->user_allowed_editing()) {
113 $buttons = '<div><form '.$CFG->frametarget
.' method="get" action="' . $this->url_get_path() . '">'.
114 '<fieldset class="invisiblefieldset"><input type="hidden" name="adminedit" value="'.($this->user_is_editing()?
'off':'on').'" />'.
115 '<input type="hidden" name="section" value="'.$this->section
.'" />'.
116 '<input type="submit" value="'.get_string($this->user_is_editing()?
'blockseditoff':'blocksediton').'" /></fieldset></form></div>';
121 print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection
), $SITE->fullname
,
122 implode(" -> ",$this->visiblepathtosection
),'', '', true, $buttons, '');
125 function get_type() {