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