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 //TODO: add 'my' only if user has role assigned in system or any course category context
26 return array('site' => true, 'admin' => true, 'my' => true);
29 function preferred_width() {
33 function open_folder($visiblename) {
35 $strfolderopened = s(get_string('folderopened'));
37 for ($i = 0; $i < $this->currentdepth
; $i++
) {
38 $this->tempcontent
.= " ";
40 $this->tempcontent
.= '<a href="#" onclick="toggle(\'vh_span' . $this->spancounter
. '\');return false">';
41 $this->tempcontent
.= '<span id="vh_span' . $this->spancounter
. 'indicator"><img src="' . $CFG->wwwroot
. '/blocks/admin_tree/open.gif" alt="'.$strfolderopened.'" /></span> ';
42 $this->tempcontent
.= $visiblename . '</a><br /><span id="vh_span' . $this->spancounter
. '">' . "\n";
43 $this->currentdepth++
;
47 function close_folder() {
48 $this->currentdepth
--;
49 $this->tempcontent
.= "</span>\n";
52 function create_item($visiblename,$link,$icon,$class) {
54 for ($i = 0; $i < $this->currentdepth
; $i++
) {
55 $this->tempcontent
.= " ";
57 $this->tempcontent
.= '<a class="'.$class.'" href="'.$link.'"><img src="'.$icon.'" alt="" />'.
58 $visiblename.'</a><br />'."\n";
61 function build_tree (&$content) {
63 if (is_a($content, 'admin_settingpage')) {
64 if ($content->check_access() and !$content->is_hidden()) {
65 $class = ($content->name
== $this->section
) ?
'link current' : 'link';
66 $this->create_item($content->visiblename
,$CFG->wwwroot
.'/'.$CFG->admin
.'/settings.php?section=' . $content->name
,$CFG->wwwroot
.'/blocks/admin_tree/item.gif', $class);
68 } else if (is_a($content, 'admin_externalpage')) {
69 if ($content->check_access() and !$content->is_hidden()) {
70 $class = ($content->name
== $this->section
) ?
'link current' : 'link';
71 $this->create_item($content->visiblename
, $content->url
, $CFG->wwwroot
. '/blocks/admin_tree/item.gif', $class);
73 } else if (is_a($content, 'admin_category')) {
74 if ($content->check_access() and !$content->is_hidden()) {
76 // check if the category we're currently printing is a parent category for the current page; if it is, we
77 // make a note (in the javascript) that it has to be expanded after the page has loaded
78 if ($this->pathtosection
[count($this->pathtosection
) - 1] == $content->name
) {
79 $this->expandjavascript
.= 'expand("vh_span' . ($this->spancounter
) . '");' . "\n";
80 array_pop($this->pathtosection
);
83 $this->open_folder($content->visiblename
);
85 $entries = array_keys($content->children
);
87 foreach ($entries as $entry) {
88 $this->build_tree($content->children
[$entry]);
91 $this->close_folder();
96 function get_content() {
100 if ($this->content
!== NULL) {
101 return $this->content
;
104 if (isguestuser() or !isloggedin()) {
105 // these users can not change any settings
110 require_once($CFG->libdir
.'/adminlib.php');
111 $adminroot = admin_get_root();
113 if ($this->pathtosection
= $adminroot->path($this->section
)) {
114 $this->pathtosection
= array_reverse($this->pathtosection
);
115 array_pop($this->pathtosection
);
118 // we need to do this instead of $this->build_tree($adminroot) because the top-level folder
119 // is redundant (and ideally ignored). (the top-level folder is "administration".)
121 $entries = array_keys($adminroot->children
);
125 foreach ($entries as $entry) {
126 $this->build_tree($adminroot->children
[$entry]);
129 if ($this->tempcontent
!== '') {
130 $strfolderopened = s(get_string('folderopened'));
131 $strfolderclosed = s(get_string('folderclosed'));
133 $this->content
= new stdClass
;
134 $this->content
->text
= '<script type="text/javascript">'."\n";
135 $this->content
->text
.= '//<![CDATA[' . "\n";
136 $this->content
->text
.= 'var vh_numspans = ' . ($this->spancounter
- 1) . ';' . "\n";
137 $this->content
->text
.= 'var vh_content = new Array();' . "\n";
138 $this->content
->text
.= 'function getspan(spanid) {' . "\n";
139 $this->content
->text
.= ' if (document.getElementById) {' . "\n";
140 $this->content
->text
.= ' return document.getElementById(spanid);' . "\n";
141 $this->content
->text
.= ' } else if (window[spanid]) {' . "\n";
142 $this->content
->text
.= ' return window[spanid];' . "\n";
143 $this->content
->text
.= ' }' . "\n";
144 $this->content
->text
.= ' return null;' . "\n";
145 $this->content
->text
.= '}' . "\n";
147 $this->content
->text
.= 'function toggle(spanid) {' . "\n";
148 $this->content
->text
.= ' if (getspan(spanid).innerHTML == "") {' . "\n";
149 $this->content
->text
.= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n";
150 $this->content
->text
.= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->wwwroot
. '/blocks/admin_tree/open.gif" alt="'.$strfolderopened.'" />\';' . "\n";
151 $this->content
->text
.= ' } else {' . "\n";
152 $this->content
->text
.= ' vh_content[spanid] = getspan(spanid).innerHTML;' . "\n";
153 $this->content
->text
.= ' getspan(spanid).innerHTML = "";' . "\n";
154 $this->content
->text
.= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->wwwroot
. '/blocks/admin_tree/closed.gif" alt="'.$strfolderclosed.'" />\';' . "\n";
155 $this->content
->text
.= ' }' . "\n";
156 $this->content
->text
.= '}' . "\n";
158 $this->content
->text
.= 'function collapse(spanid) {' . "\n";
159 $this->content
->text
.= ' if (getspan(spanid).innerHTML !== "") {' . "\n";
160 $this->content
->text
.= ' vh_content[spanid] = getspan(spanid).innerHTML;' . "\n";
161 $this->content
->text
.= ' getspan(spanid).innerHTML = "";' . "\n";
162 $this->content
->text
.= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->wwwroot
. '/blocks/admin_tree/closed.gif" alt="'.$strfolderclosed.'" />\';' . "\n";
163 $this->content
->text
.= ' }' . "\n";
164 $this->content
->text
.= '}' . "\n";
166 $this->content
->text
.= 'function expand(spanid) {' . "\n";
167 $this->content
->text
.= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n";
168 $this->content
->text
.= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->wwwroot
. '/blocks/admin_tree/open.gif" alt="'.$strfolderopened.'" />\';' . "\n";
169 $this->content
->text
.= '}' . "\n";
171 $this->content
->text
.= 'function expandall() {' . "\n";
172 $this->content
->text
.= ' for (i = 1; i <= vh_numspans; i++) {' . "\n";
173 $this->content
->text
.= ' expand("vh_span" + String(i));' . "\n";
174 $this->content
->text
.= ' }' . "\n";
175 $this->content
->text
.= '}' . "\n";
177 $this->content
->text
.= 'function collapseall() {' . "\n";
178 $this->content
->text
.= ' for (i = vh_numspans; i > 0; i--) {' . "\n";
179 $this->content
->text
.= ' collapse("vh_span" + String(i));' . "\n";
180 $this->content
->text
.= ' }' . "\n";
181 $this->content
->text
.= '}' . "\n";
183 $this->content
->text
.= '//]]>' . "\n";
184 $this->content
->text
.= '</script>' . "\n";
185 $this->content
->text
.= '<div class="admintree">' . "\n";
187 $this->content
->text
.= $this->tempcontent
;
189 $this->content
->text
.= '</div>' . "\n";
190 $this->content
->text
.= '<script type="text/javascript">' . "\n";
191 $this->content
->text
.= '//<![CDATA[' . "\n";
192 $this->content
->text
.= 'collapseall();' . "\n";
193 $this->content
->text
.= $this->expandjavascript
;
195 $this->content
->text
.= '//]]>' . "\n";
196 $this->content
->text
.= '</script>' . "\n";
198 $searchcontent = isset($CFG->adminsearchquery
) ?
$CFG->adminsearchquery
: '';
200 $this->content
->footer
= '<div class="adminsearchform">'.
201 '<form action="'.$CFG->wwwroot
.'/admin/search.php" method="get"><div>'.
202 '<label for="query" class="accesshide">'.get_string('searchinsettings', 'admin').'</label>'.
203 '<input type="text" name="query" id="query" size="8" value="'.s($searchcontent).'" />'.
204 '<input type="submit" value="'.get_string('search').'" /></div>'.
207 $this->content
= new stdClass
;
208 $this->content
->text
= '';
211 return $this->content
;