3 class block_admin_tree
extends block_base
{
14 $this->title
= get_string('administrationsite');
15 $this->version
= 2006090300;
16 $this->currentdepth
= 0;
17 $this->spancounter
= 1;
18 $this->tempcontent
= '';
19 $this->section
= (isset($PAGE->section
) ?
$PAGE->section
: '');
20 $this->pathtosection
= array();
21 $this->expandjavascript
= '';
24 function applicable_formats() {
25 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
26 return array('site' => true, 'admin' => true);
28 return array('site' => true);
32 function preferred_width() {
36 function open_folder($visiblename) {
38 $strfolderopened = s(get_string('folderopened'));
40 for ($i = 0; $i < $this->currentdepth
; $i++
) {
41 $this->tempcontent
.= " ";
43 $this->tempcontent
.= '<a href="#" onclick="toggle(\'vh_span' . $this->spancounter
. '\');return false">';
44 $this->tempcontent
.= '<span id="vh_span' . $this->spancounter
. 'indicator"><img src="' . $CFG->wwwroot
. '/blocks/admin_tree/open.gif" alt="'.$strfolderopened.'" /></span> ';
45 $this->tempcontent
.= $visiblename . '</a><br /><span id="vh_span' . $this->spancounter
. '">' . "\n";
46 $this->currentdepth++
;
50 function close_folder() {
51 $this->currentdepth
--;
52 $this->tempcontent
.= "</span>\n";
55 function create_item($visiblename,$link,$icon,$class) {
57 for ($i = 0; $i < $this->currentdepth
; $i++
) {
58 $this->tempcontent
.= " ";
60 $this->tempcontent
.= '<a class="'.$class.'" href="'.$link.'"><img src="'.$icon.'" alt="" />'.
61 $visiblename.'</a><br />'."\n";
64 function build_tree (&$content) {
66 if (is_a($content, 'admin_settingpage')) {
67 if ($content->check_access() and !$content->is_hidden()) {
68 $class = ($content->name
== $this->section
) ?
'link current' : 'link';
69 $this->create_item($content->visiblename
,$CFG->wwwroot
.'/'.$CFG->admin
.'/settings.php?section=' . $content->name
,$CFG->wwwroot
.'/blocks/admin_tree/item.gif', $class);
71 } else if (is_a($content, 'admin_externalpage')) {
72 if ($content->check_access() and !$content->is_hidden()) {
73 $class = ($content->name
== $this->section
) ?
'link current' : 'link';
74 $this->create_item($content->visiblename
, $content->url
, $CFG->wwwroot
. '/blocks/admin_tree/item.gif', $class);
76 } else if (is_a($content, 'admin_category')) {
77 if ($content->check_access() and !$content->is_hidden()) {
79 // check if the category we're currently printing is a parent category for the current page; if it is, we
80 // make a note (in the javascript) that it has to be expanded after the page has loaded
81 if ($this->pathtosection
[count($this->pathtosection
) - 1] == $content->name
) {
82 $this->expandjavascript
.= 'expand("vh_span' . ($this->spancounter
) . '");' . "\n";
83 array_pop($this->pathtosection
);
86 $this->open_folder($content->visiblename
);
88 $entries = array_keys($content->children
);
90 foreach ($entries as $entry) {
91 $this->build_tree($content->children
[$entry]);
94 $this->close_folder();
99 function get_content() {
103 require_once($CFG->libdir
.'/adminlib.php');
104 $adminroot = admin_get_root();
106 if ($this->content
!== NULL) {
107 return $this->content
;
110 if ($this->pathtosection
= $adminroot->path($this->section
)) {
111 $this->pathtosection
= array_reverse($this->pathtosection
);
112 array_pop($this->pathtosection
);
115 // we need to do this instead of $this->build_tree($adminroot) because the top-level folder
116 // is redundant (and ideally ignored). (the top-level folder is "administration".)
118 $entries = array_keys($adminroot->children
);
122 foreach ($entries as $entry) {
123 $this->build_tree($adminroot->children
[$entry]);
126 if ($this->tempcontent
!== '') {
127 $strfolderopened = s(get_string('folderopened'));
128 $strfolderclosed = s(get_string('folderclosed'));
130 $this->content
= new stdClass
;
131 $this->content
->text
= '<script type="text/javascript">'."\n";
132 $this->content
->text
.= '//<![CDATA[' . "\n";
133 $this->content
->text
.= 'var vh_numspans = ' . ($this->spancounter
- 1) . ';' . "\n";
134 $this->content
->text
.= 'var vh_content = new Array();' . "\n";
135 $this->content
->text
.= 'function getspan(spanid) {' . "\n";
136 $this->content
->text
.= ' if (document.getElementById) {' . "\n";
137 $this->content
->text
.= ' return document.getElementById(spanid);' . "\n";
138 $this->content
->text
.= ' } else if (window[spanid]) {' . "\n";
139 $this->content
->text
.= ' return window[spanid];' . "\n";
140 $this->content
->text
.= ' }' . "\n";
141 $this->content
->text
.= ' return null;' . "\n";
142 $this->content
->text
.= '}' . "\n";
144 $this->content
->text
.= 'function toggle(spanid) {' . "\n";
145 $this->content
->text
.= ' if (getspan(spanid).innerHTML == "") {' . "\n";
146 $this->content
->text
.= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n";
147 $this->content
->text
.= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->wwwroot
. '/blocks/admin_tree/open.gif" alt="'.$strfolderopened.'" />\';' . "\n";
148 $this->content
->text
.= ' } else {' . "\n";
149 $this->content
->text
.= ' vh_content[spanid] = getspan(spanid).innerHTML;' . "\n";
150 $this->content
->text
.= ' getspan(spanid).innerHTML = "";' . "\n";
151 $this->content
->text
.= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->wwwroot
. '/blocks/admin_tree/closed.gif" alt="'.$strfolderclosed.'" />\';' . "\n";
152 $this->content
->text
.= ' }' . "\n";
153 $this->content
->text
.= '}' . "\n";
155 $this->content
->text
.= 'function collapse(spanid) {' . "\n";
156 $this->content
->text
.= ' if (getspan(spanid).innerHTML !== "") {' . "\n";
157 $this->content
->text
.= ' vh_content[spanid] = getspan(spanid).innerHTML;' . "\n";
158 $this->content
->text
.= ' getspan(spanid).innerHTML = "";' . "\n";
159 $this->content
->text
.= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->wwwroot
. '/blocks/admin_tree/closed.gif" alt="'.$strfolderclosed.'" />\';' . "\n";
160 $this->content
->text
.= ' }' . "\n";
161 $this->content
->text
.= '}' . "\n";
163 $this->content
->text
.= 'function expand(spanid) {' . "\n";
164 $this->content
->text
.= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n";
165 $this->content
->text
.= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->wwwroot
. '/blocks/admin_tree/open.gif" alt="'.$strfolderopened.'" />\';' . "\n";
166 $this->content
->text
.= '}' . "\n";
168 $this->content
->text
.= 'function expandall() {' . "\n";
169 $this->content
->text
.= ' for (i = 1; i <= vh_numspans; i++) {' . "\n";
170 $this->content
->text
.= ' expand("vh_span" + String(i));' . "\n";
171 $this->content
->text
.= ' }' . "\n";
172 $this->content
->text
.= '}' . "\n";
174 $this->content
->text
.= 'function collapseall() {' . "\n";
175 $this->content
->text
.= ' for (i = vh_numspans; i > 0; i--) {' . "\n";
176 $this->content
->text
.= ' collapse("vh_span" + String(i));' . "\n";
177 $this->content
->text
.= ' }' . "\n";
178 $this->content
->text
.= '}' . "\n";
180 $this->content
->text
.= '//]]>' . "\n";
181 $this->content
->text
.= '</script>' . "\n";
182 $this->content
->text
.= '<div class="admintree">' . "\n";
184 $this->content
->text
.= $this->tempcontent
;
186 $this->content
->text
.= '</div>' . "\n";
187 $this->content
->text
.= '<script type="text/javascript">' . "\n";
188 $this->content
->text
.= '//<![CDATA[' . "\n";
189 $this->content
->text
.= 'collapseall();' . "\n";
190 $this->content
->text
.= $this->expandjavascript
;
192 $this->content
->text
.= '//]]>' . "\n";
193 $this->content
->text
.= '</script>' . "\n";
195 $searchcontent = isset($CFG->adminsearchquery
) ?
$CFG->adminsearchquery
: '';
197 $this->content
->footer
= '<div class="adminsearchform">'.
198 '<form action="'.$CFG->wwwroot
.'/admin/search.php" method="get"><div>'.
199 '<label for="query" class="accesshide">'.get_string('searchinsettings', 'admin').'</label>'.
200 '<input type="text" name="query" id="query" size="8" value="'.s($searchcontent).'" />'.
201 '<input type="submit" value="'.get_string('search').'" /></div>'.
204 $this->content
= new stdClass
;
205 $this->content
->text
= '';
208 return $this->content
;