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