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