3 class block_admin_tree
extends block_base
{
14 $this->title
= get_string('administrationsite');
15 $this->version
= 2007101509;
16 $this->currentdepth
= 0;
17 $this->divcounter
= 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, 'my' => true);
28 return array('site' => true, 'admin' => true);
32 function preferred_width() {
36 function open_folder($visiblename) {
38 $strfolderopened = s(get_string('folderopened'));
40 $this->tempcontent
.= '<div class="depth'.$this->currentdepth
.'"><a href="#" onclick="toggle(\''.$this->divcounter
.'\');return false">';
41 $this->tempcontent
.= '<span id="vh_div'.$this->divcounter
.'indicator"><img src="'.$CFG->pixpath
.'/i/open.gif" alt="'.$strfolderopened.'" /></span> ';
42 $this->tempcontent
.= $visiblename.'</a></div><div id="vh_div'.$this->divcounter
.'">'."\n";
43 $this->currentdepth++
;
47 function close_folder() {
48 $this->currentdepth
--;
49 $this->tempcontent
.= "</div>\n";
52 function create_item($visiblename,$link,$icon,$class) {
54 $this->tempcontent
.= '<div class="depth'.$this->currentdepth
.'"><a class="'.$class.'" href="'.$link.'"><img src="'.$icon.'" alt="" />'.
55 $visiblename.'</a></div>'."\n";
58 function build_tree (&$content) {
60 if (is_a($content, 'admin_settingpage')) {
61 // show hidden pages in tree if hidden page active
62 if ($content->check_access() and (($content->name
== $this->section
) or !$content->is_hidden())) {
63 $class = ($content->name
== $this->section
) ?
'link current' : 'link';
64 if ($content->is_hidden()) {
67 $this->create_item($content->visiblename
, $CFG->wwwroot
.'/'.$CFG->admin
.'/settings.php?section='.$content->name
,$CFG->pixpath
.'/i/item.gif', $class);
69 } else if (is_a($content, 'admin_externalpage')) {
70 // show hidden pages in tree if hidden page active
71 if ($content->check_access() and (($content->name
== $this->section
) or !$content->is_hidden())) {
72 $class = ($content->name
== $this->section
) ?
'link current' : 'link';
73 if ($content->is_hidden()) {
76 $this->create_item($content->visiblename
, $content->url
, $CFG->pixpath
.'/i/item.gif', $class);
78 } else if (is_a($content, 'admin_category')) {
79 if ($content->check_access() and !$content->is_hidden()) {
81 // check if the category we're currently printing is a parent category for the current page; if it is, we
82 // make a note (in the javascript) that it has to be expanded after the page has loaded
83 if ($this->section
!= '' and $this->pathtosection
[count($this->pathtosection
) - 1] == $content->name
) {
84 $this->expandjavascript
.= 'expand('.$this->divcounter
.');'."\n";
85 array_pop($this->pathtosection
);
88 $this->open_folder($content->visiblename
);
90 $entries = array_keys($content->children
);
92 foreach ($entries as $entry) {
93 $this->build_tree($content->children
[$entry]);
96 $this->close_folder();
101 function get_content() {
105 if ($this->content
!== NULL) {
106 return $this->content
;
109 if (isguestuser() or !isloggedin()) {
110 // these users can not change any settings
115 require_once($CFG->libdir
.'/adminlib.php');
116 $adminroot =& admin_get_root(false, false); // settings not required - only pages
118 if ($current = $adminroot->locate($this->section
, true)) {
119 $this->pathtosection
= $current->path
;
120 array_pop($this->pathtosection
);
123 // we need to do this instead of $this->build_tree($adminroot) because the top-level folder
124 // is redundant (and ideally ignored). (the top-level folder is "administration".)
126 $entries = array_keys($adminroot->children
);
130 foreach ($entries as $entry) {
131 $this->build_tree($adminroot->children
[$entry]);
134 if ($this->tempcontent
!== '') {
135 $closedimg = '<img src="'.$CFG->pixpath
.'/i/closed.gif" alt="'.s(get_string('folderclosed')).'" />';
136 $openedimg = '<img src="'.$CFG->pixpath
.'/i/open.gif" alt="'.s(get_string('folderopened')).'" />';
138 $this->content
= new object();
139 $this->content
->text
= '
140 <script type="text/javascript">
142 var vh_numdivs = '.($this->divcounter
- 1).';
143 var parkplatz = new Array();
144 for (var i=1; i<=vh_numdivs; i++) {
150 if (parkplatz[i] === null) {
157 function collapse(i) {
158 if (parkplatz[i] !== null) {
161 var obj = document.getElementById("vh_div"+String(i));
165 var nothing = document.createElement("span");
166 nothing.setAttribute("id", "vh_div"+String(i));
168 obj.parentNode.replaceChild(nothing, obj);
169 var icon = document.getElementById("vh_div"+String(i)+"indicator");
170 icon.innerHTML = "'.addslashes_js($closedimg).'";
174 if (parkplatz[i] === null) {
177 var nothing = document.getElementById("vh_div"+String(i));
178 var obj = parkplatz[i];
180 nothing.parentNode.replaceChild(obj, nothing);
181 var icon = document.getElementById("vh_div"+String(i)+"indicator");
182 icon.innerHTML = "'.addslashes_js($openedimg).'";
185 function expandall() {
186 for (i=1; i<=vh_numdivs; i++) {
191 function collapseall() {
192 for (var i=vh_numdivs; i>0; i--) {
199 <div class="admintree">
201 '.$this->tempcontent
.'
204 <script type="text/javascript">
207 '.$this->expandjavascript
.';
211 $this->content
->footer
= '<div class="adminsearchform">'.
212 '<form action="'.$CFG->wwwroot
.'/'.$CFG->admin
.'/search.php" method="get"><div>'.
213 '<label for="query" class="accesshide">'.get_string('searchinsettings', 'admin').'</label>'.
214 '<input type="text" name="query" id="query" size="8" value="'.s($adminroot->search
).'" />'.
215 '<input type="submit" value="'.get_string('search').'" /></div>'.
218 $this->content
= new object();
219 $this->content
->text
= '';
222 return $this->content
;