update template for new events system
[diogenes.git] / include / phplayersmenu / treemenu.inc.php
CommitLineData
6855525e
JL
1<?php
2// PHP Layers Menu 3.1.1 (C) 2001-2003 Marco Pratesi (marco at telug dot it)
3
4/**
5* This file contains the code of the TreeMenu class.
6* @package PHPLayersMenu
7*/
8
9/**
10* This is the TreeMenu class of the PHP Layers Menu library.
11*
12* This class depends on the LayersMenuCommon class and on the PEAR conforming version of the PHPLib Template class, i.e. on HTML_Template_PHPLIB
13*
14* @version 3.1.1
15* @package PHPLayersMenu
16*/
17class TreeMenu extends LayersMenuCommon {
18
19/**
20* Type of images used for the Tree Menu
21* @access private
22* @var string
23*/
24var $treeMenuImagesType;
25/**
26* An array where we store the Tree Menu code for each menu
27* @access private
28* @var array
29*/
30var $_treeMenu;
31
32/**
33* The constructor method; it initializates the menu system
34* @return void
35*/
36function TreeMenu() {
37 $this->LayersMenuCommon();
38
39 $this->treeMenuImagesType = "png";
40 $this->_treeMenu = array();
41
42 $this->_nodesCount = 0;
43 $this->tree = array();
44 $this->_maxLevel = array();
45 $this->_firstLevelCnt = array();
46 $this->_firstItem = array();
47 $this->_lastItem = array();
48}
49
50/**
51* The method to set the dirroot directory
52* @access public
53* @return boolean
54*/
55function setDirroot($dirroot) {
56 return $this->setDirrootCommon($dirroot);
57}
58
59/**
60* The method to set the type of images used for the Tree Menu
61* @access public
62* @return void
63*/
64function setTreeMenuImagesType($treeMenuImagesType) {
65 $this->treeMenuImagesType = $treeMenuImagesType;
66}
67
68/**
69* Method to prepare a new Tree Menu.
70*
71* This method processes items of a menu to prepare and return
72* the corresponding Tree Menu code.
73*
74* @access public
75* @param string $menu_name the name of the menu whose items have to be processed
76* @return string
77*/
78function newTreeMenu(
79 $menu_name = "" // non consistent default...
80 ) {
81 if (!isset($this->_firstItem[$menu_name]) || !isset($this->_lastItem[$menu_name])) {
82 $this->error("newTreeMenu: the first/last item of the menu '$menu_name' is not defined; please check if you have parsed its menu data.");
83 return 0;
84 }
85
86 $this->_treeMenu[$menu_name] = "";
87
88 $img_space = $this->imgwww . "tree_space." . $this->treeMenuImagesType;
89 $alt_space = " ";
90 $img_vertline = $this->imgwww . "tree_vertline." . $this->treeMenuImagesType;
91 $alt_vertline = "| ";
92 $img_expand = $this->imgwww . "tree_expand." . $this->treeMenuImagesType;
93 $alt_expand = "+-";
94 $img_expand_first = $this->imgwww . "tree_expand_first." . $this->treeMenuImagesType;
95 $alt_expand_first = "+-";
96 $img_expand_corner = $this->imgwww . "tree_expand_corner." . $this->treeMenuImagesType;
97 $alt_expand_corner = "+-";
98 $img_collapse = $this->imgwww . "tree_collapse." . $this->treeMenuImagesType;
99 $alt_collapse = "--";
100 $img_collapse_first = $this->imgwww . "tree_collapse_first." . $this->treeMenuImagesType;
101 $alt_collapse_first = "--";
102 $img_collapse_corner = $this->imgwww . "tree_collapse_corner." . $this->treeMenuImagesType;
103 $alt_collapse_corner = "--";
104 $img_split = $this->imgwww . "tree_split." . $this->treeMenuImagesType;
105 $alt_split = "|-";
106 $img_split_first = $this->imgwww . "tree_split_first." . $this->treeMenuImagesType;
107 $alt_split_first = "|-";
108 $img_corner = $this->imgwww . "tree_corner." . $this->treeMenuImagesType;
109 $alt_corner = "`-";
110 $img_folder_closed = $this->imgwww . "tree_folder_closed." . $this->treeMenuImagesType;
111 $alt_folder_closed = "->";
112 $img_folder_open = $this->imgwww . "tree_folder_open." . $this->treeMenuImagesType;
113 $alt_folder_open = "->";
114 $img_leaf = $this->imgwww . "tree_leaf." . $this->treeMenuImagesType;
115 $alt_leaf = "->";
116
117 for ($i=0; $i<=$this->_maxLevel[$menu_name]; $i++) {
118 $levels[$i] = 0;
119 }
120
121 // Find last nodes of subtrees
122 $last_level = $this->_maxLevel[$menu_name];
123 for ($i=$this->_lastItem[$menu_name]; $i>=$this->_firstItem[$menu_name]; $i--) {
124 if ($this->tree[$i]["level"] < $last_level) {
125 for ($j=$this->tree[$i]["level"]+1; $j<=$this->_maxLevel[$menu_name]; $j++) {
126 $levels[$j] = 0;
127 }
128 }
129 if ($levels[$this->tree[$i]["level"]] == 0) {
130 $levels[$this->tree[$i]["level"]] = 1;
131 $this->tree[$i]["last_item"] = 1;
132 } else {
133 $this->tree[$i]["last_item"] = 0;
134 }
135 $last_level = $this->tree[$i]["level"];
136 }
137
138 $toggle = "";
139 $toggle_function_name = "toggle" . $menu_name;
140
141 for ($cnt=$this->_firstItem[$menu_name]; $cnt<=$this->_lastItem[$menu_name]; $cnt++) {
142 $this->_treeMenu[$menu_name] .= "<div id=\"jt" . $cnt . "\" class=\"treemenudiv\">\n";
143
144 // vertical lines from higher levels
145 for ($i=0; $i<$this->tree[$cnt]["level"]-1; $i++) {
146 if ($levels[$i] == 1) {
147 $img = $img_vertline;
148 $alt = $alt_vertline;
149 } else {
150 $img = $img_space;
151 $alt = $alt_space;
152 }
153 $this->_treeMenu[$menu_name] .= "<img class=\"imgs\" src=\"" . $img . "\" alt=\"" . $alt . "\" />";
154 }
155
156 $not_a_leaf = $cnt<$this->_lastItem[$menu_name] && $this->tree[$cnt+1]["level"]>$this->tree[$cnt]["level"];
157
158 if ($this->tree[$cnt]["last_item"] == 1) {
159 // corner at end of subtree or t-split
160 if ($not_a_leaf) {
161 $this->_treeMenu[$menu_name] .= "<a onmousedown=\"". $toggle_function_name . "('" . $cnt . "')\"><img class=\"imgs\" id=\"jt" . $cnt . "node\" src=\"" . $img_collapse_corner . "\" alt=\"" . $alt_collapse_corner . "\" /></a>";
162 } else {
163 $this->_treeMenu[$menu_name] .= "<img class=\"imgs\" src=\"" . $img_corner . "\" alt=\"" . $alt_corner . "\" />";
164 }
165 $levels[$this->tree[$cnt]["level"]-1] = 0;
166 } else {
167 if ($not_a_leaf) {
168 if ($cnt == $this->_firstItem[$menu_name]) {
169 $img = $img_collapse_first;
170 $alt = $alt_collapse_first;
171 } else {
172 $img = $img_collapse;
173 $alt = $alt_collapse;
174 }
175 $this->_treeMenu[$menu_name] .= "<a onmousedown=\"". $toggle_function_name . "('" . $cnt . "');\"><img class=\"imgs\" id=\"jt" . $cnt . "node\" src=\"" . $img . "\" alt=\"" . $alt . "\" /></a>";
176 } else {
177 if ($cnt == $this->_firstItem[$menu_name]) {
178 $img = $img_split_first;
179 $alt = $alt_split_first;
180 } else {
181 $img = $img_split;
182 $alt = $alt_split;
183 }
184 $this->_treeMenu[$menu_name] .= "<a onmousedown=\"". $toggle_function_name . "('" . $cnt . "');\"><img class=\"imgs\" id=\"jt" . $cnt . "node\" src=\"" . $img . "\" alt=\"" . $alt . "\" /></a>";
185 }
186 $levels[$this->tree[$cnt]["level"]-1] = 1;
187 }
188
189 if ($this->tree[$cnt]["parsed_href"] == "" || $this->tree[$cnt]["parsed_href"] == "#") {
190 $a_href_open_img = "";
191 $a_href_close_img = "";
192 $a_href_open = "<a class=\"phplmnormal\">";
193 $a_href_close = "</a>";
194 } else {
195 $a_href_open_img = "<a href=\"" . $this->tree[$cnt]["parsed_href"] . "\"" . $this->tree[$cnt]["parsed_title"] . $this->tree[$cnt]["parsed_target"] . ">";
196 $a_href_close_img = "</a>";
197 $a_href_open = "<a href=\"" . $this->tree[$cnt]["parsed_href"] . "\"" . $this->tree[$cnt]["parsed_title"] . $this->tree[$cnt]["parsed_target"] . " class=\"phplm\">";
198 $a_href_close = "</a>";
199 }
200
201 if ($not_a_leaf) {
202 $this->_treeMenu[$menu_name] .= $a_href_open_img . "<img class=\"imgs\" id=\"jt" . $cnt . "folder\" src=\"" . $img_folder_open . "\" alt=\"" . $alt_folder_open . "\" />" . $a_href_close_img;
203 } else {
204 if ($this->tree[$cnt]["parsed_icon"] != "") {
205 $this->_treeMenu[$menu_name] .= $a_href_open_img . "<img class=\"imgs\" src=\"" . $this->imgwww . $this->tree[$cnt]["parsed_icon"] . "\" width=\"" . $this->tree[$cnt]["iconwidth"] . "\" height=\"" . $this->tree[$cnt]["iconheight"] . "\" alt=\"" . $alt_leaf . "\" />" . $a_href_close_img;
206 } else {
207 $this->_treeMenu[$menu_name] .= $a_href_open_img . "<img class=\"imgs\" src=\"" . $img_leaf . "\" alt=\"" . $alt_leaf . "\" />" . $a_href_close_img;
208 }
209 }
210 $this->_treeMenu[$menu_name] .= "&nbsp;" . $a_href_open . $this->tree[$cnt]["text"] . $a_href_close . "\n";
211 $this->_treeMenu[$menu_name] .= "</div>\n";
212
213 if ($cnt<$this->_lastItem[$menu_name] && $this->tree[$cnt]["level"]<$this->tree[$cnt+1]["level"]) {
214 $this->_treeMenu[$menu_name] .= "<div id=\"jt" . $cnt . "son\" class=\"treemenudiv\">\n";
215 if ($this->tree[$cnt]["expanded"] != 1) {
216 $toggle .= "if (expand[" . $cnt . "] != 1) " . $toggle_function_name . "('" . $cnt . "');\n";
217 } else {
218 $toggle .= "if (collapse[" . $cnt . "] == 1) " . $toggle_function_name . "('" . $cnt . "');\n";
219 }
220 }
221
222 if ($cnt>$this->_firstItem[$menu_name] && $this->tree[$cnt]["level"]>$this->tree[$cnt+1]["level"]) {
223 for ($i=max(1, $this->tree[$cnt+1]["level"]); $i<$this->tree[$cnt]["level"]; $i++) {
224 $this->_treeMenu[$menu_name] .= "</div>\n";
225 }
226 }
227 }
228
229/*
230 $this->_treeMenu[$menu_name] =
231 "<div class=\"phplmnormal\">\n" .
232 $this->_treeMenu[$menu_name] .
233 "</div>\n";
234*/
235 // Some (old) browsers do not support the "white-space: nowrap;" CSS property...
236 $this->_treeMenu[$menu_name] =
237 "<table cellspacing=\"0\" cellpadding=\"0\" style=\"border: 0;\">\n" .
238 "<tr>\n" .
239 "<td class=\"phplmnormal\" style=\"white-space: nowrap;\">\n" .
240 $this->_treeMenu[$menu_name] .
241 "</td>\n" .
242 "</tr>\n" .
243 "</table>\n";
244
245 $t = new Template_PHPLIB();
246 $t->setFile("tplfile", $this->libjsdir . "layerstreemenu.ijs");
247 $t->setVar(array(
248 "toggle_function_name" => $toggle_function_name,
249 "img_expand" => $img_expand,
250 "img_expand_first" => $img_expand_first,
251 "img_collapse" => $img_collapse,
252 "img_collapse_first" => $img_collapse_first,
253 "img_collapse_corner" => $img_collapse_corner,
254 "img_folder_open" => $img_folder_open,
255 "img_expand_corner" => $img_expand_corner,
256 "img_folder_closed" => $img_folder_closed
257 ));
258 $toggle_function = $t->parse("out", "tplfile");
259 $toggle_function =
260 "<script type=\"text/javascript\">\n" .
261 "<!--\n" .
262 $toggle_function .
263 "// -->\n" .
264 "</script>\n";
265
266 $toggle =
267 "<script type=\"text/javascript\">\n" .
268 "<!--\n" .
269 "if ((DOM && !Opera56 && !Konqueror22) || IE4) {\n" .
270 $toggle .
271 "}\n" .
272 "if (NS4) alert('Only the accessibility is provided to Netscape 4 on the JavaScript Tree Menu.\\nWe *strongly* suggest you to upgrade your browser.');\n" .
273 "// -->\n" .
274 "</script>\n";
275
276 $this->_treeMenu[$menu_name] = $toggle_function . "\n" . $this->_treeMenu[$menu_name] . "\n" . $toggle;
277
278 return $this->_treeMenu[$menu_name];
279}
280
281/**
282* Method that returns the code of the requested Tree Menu
283* @access public
284* @param string $menu_name the name of the menu whose Tree Menu code
285* has to be returned
286* @return string
287*/
288function getTreeMenu($menu_name) {
289 return $this->_treeMenu[$menu_name];
290}
291
292/**
293* Method that prints the code of the requested Tree Menu
294* @access public
295* @param string $menu_name the name of the menu whose Tree Menu code
296* has to be printed
297* @return void
298*/
299function printTreeMenu($menu_name) {
300 print $this->_treeMenu[$menu_name];
301}
302
303} /* END OF CLASS */
304
305?>