1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24:
25: class cGuiTree extends cTree {
26:
27: 28: 29: 30:
31: const TREEVIEW_GRIDLINE_SOLID = 'solid';
32:
33: 34: 35: 36:
37: const TREEVIEW_GRIDLINE_DASHED = 'dashed';
38:
39: 40: 41: 42:
43: const TREEVIEW_GRIDLINE_DOTTED = 'dotted';
44:
45: 46: 47: 48:
49: const TREEVIEW_GRIDLINE_NONE = 'none';
50:
51: 52: 53: 54: 55: 56:
57: const TREEVIEW_BACKGROUND_NONE = 'none';
58:
59: 60: 61: 62: 63: 64:
65: const TREEVIEW_BACKGROUND_SHADED = 'shaded';
66:
67: 68: 69: 70: 71: 72:
73: const TREEVIEW_MOUSEOVER_NONE = 'none';
74:
75: 76: 77: 78: 79: 80:
81: const TREEVIEW_MOUSEOVER_MARK = 'mark';
82:
83: 84: 85:
86: protected $_user;
87:
88: 89: 90:
91: protected $_uuid;
92:
93: 94: 95:
96: protected $_gridlineMode;
97:
98: 99: 100:
101: private $_baseLink;
102:
103: 104: 105: 106: 107: 108:
109: public function __construct($uuid, $treename = false) {
110: global $cfg, $auth;
111:
112: parent::__construct();
113:
114: $this->_uuid = $uuid;
115:
116:
117: if ($treename != false) {
118: $this->setTreeName($treename);
119: }
120:
121: $this->_user = new cApiUser($auth->auth["uid"]);
122: }
123:
124: 125: 126:
127: public function processParameters() {
128: if (($items = $this->_user->getUserProperty("expandstate", $this->_uuid)) !== false) {
129: $list = unserialize($items);
130:
131: foreach ($list as $litem) {
132: $this->setCollapsed($litem);
133: }
134: }
135:
136: if (!empty($this->_name)) {
137: $treename = $this->_name . "_";
138: }
139:
140: if (array_key_exists($treename . "collapse", $_GET)) {
141: $this->setCollapsed($_GET[$treename . "collapse"]);
142: }
143:
144: if (array_key_exists($treename . "expand", $_GET)) {
145: $this->setExpanded($_GET[$treename . "expand"]);
146: }
147:
148: $xlist = array();
149: $this->getCollapsedList($xlist);
150: $slist = serialize($xlist);
151:
152: $this->_user->setUserProperty("expandstate", $this->_uuid, $slist);
153: }
154:
155: 156: 157: 158: 159: 160: 161: 162:
163: public function setGridlineMode($mode) {
164: $this->_gridlineMode = $mode;
165: }
166:
167: 168: 169: 170: 171: 172:
173: public function setBackgroundMode($mode) {
174: cDeprecated('This method is deprecated and is not needed any longer');
175: $this->_backgroundMode = $mode;
176: }
177:
178: 179: 180: 181: 182: 183:
184: public function setMouseoverMode($mode) {
185: cDeprecated('This method is deprecated and is not needed any longer');
186: $this->_mouseoverMode = $mode;
187: }
188:
189: 190: 191: 192: 193: 194:
195: public function setBackgroundColors($colors) {
196: cDeprecated('This method is deprecated and is not needed any longer');
197: $this->_backgroundColors = $colors;
198: }
199:
200: 201: 202: 203: 204:
205: public function render($with_root = true) {
206:
207:
208: $objects = $this->flatTraverse(0);
209:
210: if ($with_root == false) {
211: unset($objects[0]);
212: }
213:
214: $img = new cHTMLImage;
215: $r_table = new cHTMLTable;
216: $r_row = new cHTMLTableRow;
217: $r_leftcell = new cHTMLTableData;
218: $r_rightcell = new cHTMLTableData;
219: $r_actioncell = new cHTMLTableData;
220:
221: $img_spacer = new cHTMLImage;
222: $img_spacer->updateAttributes(array('width' => '16', 'height' => '20'));
223: $img_spacer->setAlt("");
224: $img_spacer->setSrc("images/spacer.gif");
225: $img_spacer->advanceID();
226:
227: $r_table->setCellPadding(0);
228: $r_table->setCellSpacing(0);
229: $r_table->setWidth("100%");
230: $r_rightcell->appendStyleDefinition("padding-left", "3px");
231: $r_rightcell->setVerticalAlignment("middle");
232: $r_leftcell->setVerticalAlignment("middle");
233: $r_leftcell->updateAttributes(array("nowrap" => "nowrap"));
234: $r_rightcell->updateAttributes(array("nowrap" => "nowrap"));
235: $r_actioncell->updateAttributes(array("nowrap" => "nowrap"));
236: $r_leftcell->setWidth("1%");
237: $r_rightcell->setWidth("100%");
238: $r_actioncell->setAlignment("right");
239: $r_actioncell->setWidth("1%");
240:
241: if (!is_object($this->_baseLink)) {
242: $this->_baseLink = new cHTMLLink();
243: }
244:
245: $out = $result = '';
246:
247: $lastitem = array();
248: foreach ($objects as $key => $object) {
249: $img->setAlt("");
250: $r_table->advanceID();
251: $r_rightcell->advanceID();
252: $r_leftcell->advanceID();
253: $r_row->advanceID();
254: $r_actioncell->advanceID();
255:
256: for ($level = 1; $level < $object->_level + 1; $level++) {
257: if ($object->_level == $level) {
258: if ($object->_next === false) {
259: if (count($object->_subitems) > 0) {
260: $link = $this->_setExpandCollapseLink($this->_baseLink, $object);
261: $link->advanceID();
262: $img->setSrc($this->_getExpandCollapseIcon($object));
263: $img->advanceID();
264: $link->setContent($img);
265: $out .= $link->render();
266: } else {
267: if ($level == 1 && $with_root == false) {
268: $out .= $img_spacer->render();
269: } else {
270: $img->setSrc($this->_buildImagePath("grid_linedownrightend.gif"));
271: $img->advanceID();
272: $out .= $img->render();
273: }
274: }
275: $lastitem[$level] = true;
276: } else {
277: if (count($object->_subitems) > 0) {
278: $link = $this->_setExpandCollapseLink($this->_baseLink, $object);
279: $link->advanceID();
280: $img->setSrc($this->_getExpandCollapseIcon($object));
281: $img->advanceID();
282: $link->setContent($img);
283: $out .= $link->render();
284: } else {
285: if ($level == 1 && $with_root == false) {
286: $out .= $img_spacer->render();
287: } else {
288: $img->setSrc($this->_buildImagePath("grid_linedownright.gif"));
289: $out .= $img->render();
290: }
291: }
292:
293: $lastitem[$level] = false;
294: }
295: } else {
296: if ($lastitem[$level] == true) {
297: $out .= $img_spacer->render();
298: } else {
299: if ($level == 1 && $with_root == false) {
300: $out .= $img_spacer->render();
301: } else {
302: $img->setSrc($this->_buildImagePath("/grid_linedown.gif"));
303: $img->advanceID();
304: $out .= $img->render();
305: }
306: }
307: }
308: }
309:
310:
311: if (is_object($object->payload)) {
312:
313: $meta = $object->payload->getMetaObject();
314:
315: if (is_object($meta)) {
316: $icon = $meta->getIcon();
317: $actions = $meta->getActions();
318:
319: $r_actioncell->setContent($actions);
320:
321: $img->setAlt($meta->getDescription());
322: $img->advanceID();
323:
324:
325: if (count($meta->_editAction) > 0) {
326: $meta->defineActions();
327:
328: $edit = $meta->getAction($meta->_editAction);
329:
330: $edit->setIcon($icon);
331:
332: $renderedIcon = $edit->render();
333:
334: $edit->_link->setContent($object->getName());
335: $edit->_link->advanceID();
336: $renderedName = $edit->_link->render();
337: } else {
338: $img->setSrc($icon);
339: $renderedIcon = $img->render();
340: $renderedName = $object->getName();
341: }
342: }
343: } else {
344: if (isset($object->_attributes["icon"])) {
345: $img->setSrc($object->_attributes["icon"]);
346: $renderedIcon = $img->render();
347: $renderedName = $object->getName();
348: } else {
349:
350: if ($object->getId() == 0) {
351: $icon = $object->getTreeIcon();
352: $img->setSrc($icon);
353: $renderedIcon = $img->render();
354: $renderedName = $object->getName();
355: } else {
356: $icon = $object->getTreeIcon();
357: $img->setSrc($icon);
358: $renderedIcon = $img->render();
359: $renderedName = $object->getName();
360: }
361: }
362: }
363:
364: $img->setSrc($icon);
365: $r_leftcell->setContent($out . $renderedIcon);
366: $r_rightcell->setContent($renderedName);
367:
368: $r_row->setContent(array($r_leftcell, $r_rightcell, $r_actioncell));
369:
370: $r_table->setContent($r_row);
371:
372: $result .= $r_table->render();
373:
374: unset($out);
375: }
376:
377: return '<table cellspacing="0" cellpadding="0" width="100%" border="0"><tr><td>' . $result . '</td></tr></table>';
378: }
379:
380: 381: 382: 383: 384:
385: public function _getExpandCollapseIcon($object) {
386:
387: $img = $object->getCollapsed() ? "grid_expand.gif" : "grid_collapse.gif";
388:
389: return $this->_buildImagePath($img);
390: }
391:
392: 393: 394: 395: 396: 397: 398:
399: public function _setExpandCollapseLink($link, $object) {
400: if (!empty($this->_name)) {
401: $treename = $this->_name . "_";
402: }
403:
404: $link->unsetCustom($treename . "expand");
405: $link->unsetCustom($treename . "collapse");
406:
407: if ($object->getCollapsed() == true) {
408: $link->setCustom($treename . "expand", $object->getId());
409: } else {
410: $link->setCustom($treename . "collapse", $object->getId());
411: }
412:
413: return $link;
414: }
415:
416: 417: 418: 419: 420:
421: public function _buildImagePath($image) {
422: return "./images/" . $this->_gridlineMode . "/" . $image;
423: }
424:
425: 426: 427: 428:
429: public function setBaseLink($link) {
430: $this->_baseLink = $link;
431: }
432:
433: }
434: