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: 128:
129: public function processParameters() {
130: if (($items = $this->_user->getUserProperty("expandstate", $this->_uuid)) !== false) {
131: $list = unserialize($items);
132:
133: foreach ($list as $litem) {
134: $this->setCollapsed($litem);
135: }
136: }
137:
138: if (!empty($this->_name)) {
139: $treename = $this->_name . "_";
140: }
141:
142: if (array_key_exists($treename . "collapse", $_GET)) {
143: $this->setCollapsed($_GET[$treename . "collapse"]);
144: }
145:
146: if (array_key_exists($treename . "expand", $_GET)) {
147: $this->setExpanded($_GET[$treename . "expand"]);
148: }
149:
150: $xlist = array();
151: $this->getCollapsedList($xlist);
152: $slist = serialize($xlist);
153:
154: $this->_user->setUserProperty("expandstate", $this->_uuid, $slist);
155: }
156:
157: 158: 159: 160: 161: 162: 163: 164:
165: public function setGridlineMode($mode) {
166: $this->_gridlineMode = $mode;
167: }
168:
169: 170: 171: 172: 173: 174:
175: public function setBackgroundMode($mode) {
176: cDeprecated('This method is deprecated and is not needed any longer');
177: $this->_backgroundMode = $mode;
178: }
179:
180: 181: 182: 183: 184: 185:
186: public function setMouseoverMode($mode) {
187: cDeprecated('This method is deprecated and is not needed any longer');
188: $this->_mouseoverMode = $mode;
189: }
190:
191: 192: 193: 194: 195: 196:
197: public function setBackgroundColors($colors) {
198: cDeprecated('This method is deprecated and is not needed any longer');
199: $this->_backgroundColors = $colors;
200: }
201:
202: 203: 204: 205: 206:
207: public function render($with_root = true) {
208:
209:
210: $objects = $this->flatTraverse(0);
211:
212: if ($with_root == false) {
213: unset($objects[0]);
214: }
215:
216: $img = new cHTMLImage;
217: $r_table = new cHTMLTable;
218: $r_row = new cHTMLTableRow;
219: $r_leftcell = new cHTMLTableData;
220: $r_rightcell = new cHTMLTableData;
221: $r_actioncell = new cHTMLTableData;
222:
223: $img_spacer = new cHTMLImage;
224: $img_spacer->updateAttributes(array('width' => '16', 'height' => '20'));
225: $img_spacer->setAlt("");
226: $img_spacer->setSrc("images/spacer.gif");
227: $img_spacer->advanceID();
228:
229: $r_table->setCellPadding(0);
230: $r_table->setCellSpacing(0);
231: $r_table->setWidth("100%");
232: $r_rightcell->appendStyleDefinition("padding-left", "3px");
233: $r_rightcell->setVerticalAlignment("middle");
234: $r_leftcell->setVerticalAlignment("middle");
235: $r_leftcell->updateAttributes(array("nowrap" => "nowrap"));
236: $r_rightcell->updateAttributes(array("nowrap" => "nowrap"));
237: $r_actioncell->updateAttributes(array("nowrap" => "nowrap"));
238: $r_leftcell->setWidth("1%");
239: $r_rightcell->setWidth("100%");
240: $r_actioncell->setAlignment("right");
241: $r_actioncell->setWidth("1%");
242:
243: if (!is_object($this->_baseLink)) {
244: $this->_baseLink = new cHTMLLink();
245: }
246:
247: $out = $result = '';
248:
249: $lastitem = array();
250: foreach ($objects as $key => $object) {
251: $img->setAlt("");
252: $r_table->advanceID();
253: $r_rightcell->advanceID();
254: $r_leftcell->advanceID();
255: $r_row->advanceID();
256: $r_actioncell->advanceID();
257:
258: for ($level = 1; $level < $object->_level + 1; $level++) {
259: if ($object->_level == $level) {
260: if ($object->_next === false) {
261: if (count($object->_subitems) > 0) {
262: $link = $this->_setExpandCollapseLink($this->_baseLink, $object);
263: $link->advanceID();
264: $img->setSrc($this->_getExpandCollapseIcon($object));
265: $img->advanceID();
266: $link->setContent($img);
267: $out .= $link->render();
268: } else {
269: if ($level == 1 && $with_root == false) {
270: $out .= $img_spacer->render();
271: } else {
272: $img->setSrc($this->_buildImagePath("grid_linedownrightend.gif"));
273: $img->advanceID();
274: $out .= $img->render();
275: }
276: }
277: $lastitem[$level] = true;
278: } else {
279: if (count($object->_subitems) > 0) {
280: $link = $this->_setExpandCollapseLink($this->_baseLink, $object);
281: $link->advanceID();
282: $img->setSrc($this->_getExpandCollapseIcon($object));
283: $img->advanceID();
284: $link->setContent($img);
285: $out .= $link->render();
286: } else {
287: if ($level == 1 && $with_root == false) {
288: $out .= $img_spacer->render();
289: } else {
290: $img->setSrc($this->_buildImagePath("grid_linedownright.gif"));
291: $out .= $img->render();
292: }
293: }
294:
295: $lastitem[$level] = false;
296: }
297: } else {
298: if ($lastitem[$level] == true) {
299: $out .= $img_spacer->render();
300: } else {
301: if ($level == 1 && $with_root == false) {
302: $out .= $img_spacer->render();
303: } else {
304: $img->setSrc($this->_buildImagePath("/grid_linedown.gif"));
305: $img->advanceID();
306: $out .= $img->render();
307: }
308: }
309: }
310: }
311:
312:
313: if (is_object($object->payload)) {
314:
315: $meta = $object->payload->getMetaObject();
316:
317: if (is_object($meta)) {
318: $icon = $meta->getIcon();
319: $actions = $meta->getActions();
320:
321: $r_actioncell->setContent($actions);
322:
323: $img->setAlt($meta->getDescription());
324: $img->advanceID();
325:
326:
327: if (count($meta->_editAction) > 0) {
328: $meta->defineActions();
329:
330: $edit = $meta->getAction($meta->_editAction);
331:
332: $edit->setIcon($icon);
333:
334: $renderedIcon = $edit->render();
335:
336: $edit->_link->setContent($object->getName());
337: $edit->_link->advanceID();
338: $renderedName = $edit->_link->render();
339: } else {
340: $img->setSrc($icon);
341: $renderedIcon = $img->render();
342: $renderedName = $object->getName();
343: }
344: }
345: } else {
346: if (isset($object->_attributes["icon"])) {
347: $img->setSrc($object->_attributes["icon"]);
348: $renderedIcon = $img->render();
349: $renderedName = $object->getName();
350: } else {
351:
352: if ($object->getId() == 0) {
353: $icon = $object->getTreeIcon();
354: $img->setSrc($icon);
355: $renderedIcon = $img->render();
356: $renderedName = $object->getName();
357: } else {
358: $icon = $object->getTreeIcon();
359: $img->setSrc($icon);
360: $renderedIcon = $img->render();
361: $renderedName = $object->getName();
362: }
363: }
364: }
365:
366: $img->setSrc($icon);
367: $r_leftcell->setContent($out . $renderedIcon);
368: $r_rightcell->setContent($renderedName);
369:
370: $r_row->setContent(array($r_leftcell, $r_rightcell, $r_actioncell));
371:
372: $r_table->setContent($r_row);
373:
374: $result .= $r_table->render();
375:
376: unset($out);
377: }
378:
379: return '<table cellspacing="0" cellpadding="0" width="100%" border="0"><tr><td>' . $result . '</td></tr></table>';
380: }
381:
382: 383: 384: 385: 386:
387: public function _getExpandCollapseIcon($object) {
388:
389: $img = $object->getCollapsed() ? "grid_expand.gif" : "grid_collapse.gif";
390:
391: return $this->_buildImagePath($img);
392: }
393:
394: 395: 396: 397: 398: 399: 400:
401: public function _setExpandCollapseLink($link, $object) {
402: if (!empty($this->_name)) {
403: $treename = $this->_name . "_";
404: }
405:
406: $link->unsetCustom($treename . "expand");
407: $link->unsetCustom($treename . "collapse");
408:
409: if ($object->getCollapsed() == true) {
410: $link->setCustom($treename . "expand", $object->getId());
411: } else {
412: $link->setCustom($treename . "collapse", $object->getId());
413: }
414:
415: return $link;
416: }
417:
418: 419: 420: 421: 422:
423: public function _buildImagePath($image) {
424: return "./images/" . $this->_gridlineMode . "/" . $image;
425: }
426:
427: 428: 429: 430:
431: public function setBaseLink($link) {
432: $this->_baseLink = $link;
433: }
434:
435: }
436: