| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: block_admin_tree.php,v 1.28.2.9 2008/08/21 15:31:10 skodak Exp $ 2 3 class block_admin_tree extends block_base { 4 5 var $currentdepth; 6 var $divcounter; 7 var $tempcontent; 8 var $pathtosection; 9 var $expandjavascript; 10 var $destination; 11 12 function init() { 13 global $PAGE; 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 = ''; 22 } 23 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); 27 } else { 28 return array('site' => true, 'admin' => true); 29 } 30 } 31 32 function preferred_width() { 33 return 210; 34 } 35 36 function open_folder($visiblename) { 37 global $CFG; 38 $strfolderopened = s(get_string('folderopened')); 39 40 $this->tempcontent .= '<div class="depth'.$this->currentdepth.'"><a href="#" onclick="menu_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++; 44 $this->divcounter++; 45 } 46 47 function close_folder() { 48 $this->currentdepth--; 49 $this->tempcontent .= "</div>\n"; 50 } 51 52 function create_item($visiblename,$link,$icon,$class) { 53 global $CFG; 54 $this->tempcontent .= '<div class="depth'.$this->currentdepth.'"><a class="'.$class.'" href="'.$link.'"><img src="'.$icon.'" alt="" />'. 55 $visiblename.'</a></div>'."\n"; 56 } 57 58 function build_tree (&$content) { 59 global $CFG; 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()) { 65 $class .= ' hidden'; 66 } 67 $this->create_item($content->visiblename, $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section='.$content->name,$CFG->pixpath.'/i/item.gif', $class); 68 } 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->name === 'adminnotifications') { 74 if (admin_critical_warnings_present()) { 75 $class .= ' criticalnotification'; 76 } 77 } 78 if ($content->is_hidden()) { 79 $class .= ' hidden'; 80 } 81 $this->create_item($content->visiblename, $content->url, $CFG->pixpath.'/i/item.gif', $class); 82 } 83 } else if (is_a($content, 'admin_category')) { 84 if ($content->check_access() and !$content->is_hidden()) { 85 86 // check if the category we're currently printing is a parent category for the current page; if it is, we 87 // make a note (in the javascript) that it has to be expanded after the page has loaded 88 if ($this->section != '' and $this->pathtosection[count($this->pathtosection) - 1] == $content->name) { 89 $this->expandjavascript .= 'expand('.$this->divcounter.');'."\n"; 90 array_pop($this->pathtosection); 91 } 92 93 $this->open_folder($content->visiblename); 94 95 $entries = array_keys($content->children); 96 97 foreach ($entries as $entry) { 98 $this->build_tree($content->children[$entry]); 99 } 100 101 $this->close_folder(); 102 } 103 } 104 } 105 106 function get_content() { 107 108 global $CFG; 109 110 if ($this->content !== NULL) { 111 return $this->content; 112 } 113 114 if (isguestuser() or !isloggedin()) { 115 // these users can not change any settings 116 $this->content = ''; 117 return ''; 118 } 119 120 require_once($CFG->libdir.'/adminlib.php'); 121 $adminroot =& admin_get_root(false, false); // settings not required - only pages 122 123 if ($current = $adminroot->locate($this->section, true)) { 124 $this->pathtosection = $current->path; 125 array_pop($this->pathtosection); 126 } 127 128 // we need to do this instead of $this->build_tree($adminroot) because the top-level folder 129 // is redundant (and ideally ignored). (the top-level folder is "administration".) 130 131 $entries = array_keys($adminroot->children); 132 133 asort($entries); 134 135 foreach ($entries as $entry) { 136 $this->build_tree($adminroot->children[$entry]); 137 } 138 139 if ($this->tempcontent !== '') { 140 $closedimg = '<img src="'.$CFG->pixpath.'/i/closed.gif" alt="'.s(get_string('folderclosed')).'" />'; 141 $openedimg = '<img src="'.$CFG->pixpath.'/i/open.gif" alt="'.s(get_string('folderopened')).'" />'; 142 143 $this->content = new object(); 144 $this->content->text = ' 145 <script type="text/javascript"> 146 //<![CDATA[ 147 var vh_numdivs = '.($this->divcounter - 1).'; 148 var parkplatz = new Array(); 149 for (var i=1; i<=vh_numdivs; i++) { 150 parkplatz[i] = null; 151 } 152 153 function menu_toggle(i) { 154 i = parseInt(i); 155 if (parkplatz[i] === null) { 156 collapse(i); 157 } else { 158 expand(i); 159 } 160 } 161 162 function collapse(i) { 163 if (parkplatz[i] !== null) { 164 return; 165 } 166 var obj = document.getElementById("vh_div"+String(i)); 167 if (obj === null) { 168 return; 169 } 170 var nothing = document.createElement("span"); 171 nothing.setAttribute("id", "vh_div"+String(i)); 172 parkplatz[i] = obj; 173 obj.parentNode.replaceChild(nothing, obj); 174 var icon = document.getElementById("vh_div"+String(i)+"indicator"); 175 icon.innerHTML = "'.addslashes_js($closedimg).'"; 176 } 177 178 function expand(i) { 179 if (parkplatz[i] === null) { 180 return; 181 } 182 var nothing = document.getElementById("vh_div"+String(i)); 183 var obj = parkplatz[i]; 184 parkplatz[i] = null; 185 nothing.parentNode.replaceChild(obj, nothing); 186 var icon = document.getElementById("vh_div"+String(i)+"indicator"); 187 icon.innerHTML = "'.addslashes_js($openedimg).'"; 188 } 189 190 function expandall() { 191 for (i=1; i<=vh_numdivs; i++) { 192 expand(i); 193 } 194 } 195 196 function collapseall() { 197 for (var i=vh_numdivs; i>0; i--) { 198 collapse(i); 199 } 200 } 201 202 //]]> 203 </script> 204 <div class="admintree"> 205 206 '.$this->tempcontent.' 207 208 </div> 209 <script type="text/javascript"> 210 //<![CDATA[ 211 collapseall(); 212 '.$this->expandjavascript.'; 213 //]]> 214 </script>'; 215 216 // only do search if you have moodle/site:config 217 if (has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) ) { 218 $this->content->footer = '<div class="adminsearchform">'. 219 '<form action="'.$CFG->wwwroot.'/'.$CFG->admin.'/search.php" method="get"><div>'. 220 '<label for="query" class="accesshide">'.get_string('searchinsettings', 'admin').'</label>'. 221 '<input type="text" name="query" id="query" size="8" value="'.s($adminroot->search).'" />'. 222 '<input type="submit" value="'.get_string('search').'" /></div>'. 223 '</form></div>'; 224 } else { 225 $this->content->footer = ''; 226 } 227 } else { 228 $this->content = new object(); 229 $this->content->text = ''; 230 } 231 232 return $this->content; 233 234 } 235 } 236 237 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |