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: plugin_include('repository', 'custom/FrontendNavigation.php');
19:
20: 21: 22: 23: 24: 25:
26: class pApiContentAllocationTreeView extends pApiTree {
27:
28: 29:
30: var $tpl = NULL;
31:
32: 33:
34: var $template = '';
35:
36: 37:
38: function pApiContentAllocationTreeView($uuid) {
39: global $cfg;
40:
41: parent::pApiTree($uuid);
42: $this->tpl = new cTemplate();
43: $this->template = $cfg['pica']['treetemplate'];
44: }
45:
46: 47:
48: function _buildRenderTree($tree) {
49: global $action, $frame, $area, $sess;
50: $result = array();
51: foreach ($tree as $item_tmp) {
52: $item = array();
53:
54: if ($_GET['step'] == 'rename' && $item_tmp['idpica_alloc'] == $_GET['idpica_alloc']) {
55: $item = array();
56: $item['ITEMNAME'] = '
57: <table cellspacing="0" cellpaddin="0" border="0">
58: <form name="rename" action="main.php" method="POST" onsubmit="return fieldCheck();">
59: <input type="hidden" name="action" value="' . $action . '">
60: <input type="hidden" name="frame" value="' . $frame . '">
61: <input type="hidden" name="contenido" value="' . $sess->id . '">
62: <input type="hidden" name="area" value="' . $area . '">
63: <input type="hidden" name="step" value="storeRename">
64: <input type="hidden" name="treeItemPost[idpica_alloc]" value="' . $item_tmp['idpica_alloc'] . '">
65: <tr>
66: <td class="text_medium"><input id="itemname" class="text_medium" type="text" name="treeItemPost[name]" value="' . conHtmlentities($item_tmp['name']) . '"></td>
67: <td>
68: <a href="main.php?action=' . $action . '&frame=' . $frame . '&area=' . $area . '&contenido=' . $sess->id . '"><img src="images/but_cancel.gif" border="0"></a>
69: <input type="image" src="images/but_ok.gif">
70: </td></tr>
71: </form>
72: </table>
73: <script type="text/javascript">
74: var controller = document.getElementById("itemname");
75: controller.focus();
76: function fieldCheck() {
77: if (controller.value == "") {
78: alert("' . i18n("Please enter a category name", 'content_allocation') . '");
79: controller.focus();
80: return false;
81: }
82: return true;
83: }
84: </script>';
85: } else {
86: if ($item_tmp['children'] || $item_tmp['status'] == 'collapsed') {
87: $expandCollapseImg = 'images/close_all.gif';
88: if ($item_tmp['status'] == 'collapsed') {
89: $expandCollapseImg = 'images/open_all.gif';
90: }
91:
92: $expandCollapse = '<a href="main.php?contenido=' . $sess->id . '&idart=' . $idart . '&action=' . $action . '&frame=' . $frame . '&area=' . $area . '&oldstate=' . 'huhu' . '&step=collapse&idpica_alloc=' . $item_tmp['idpica_alloc'] . '"><img src="' . $expandCollapseImg . '" border="0" class="vAlignMiddle" alt="" width="7" height="7"></a>';
93: } else {
94: $expandCollapseImg = 'images/spacer.gif';
95: $expandCollapse = '<img src="' . $expandCollapseImg . '" border="0" alt="" class="vAlignMiddle" width="11" height="11">';
96: }
97:
98: if ($item_tmp['status'] == 'collapsed') {
99: $expandCollapse = '<a href="main.php?contenido=' . $sess->id . '&idart=' . $idart . '&action=' . $action . '&frame=' . $frame . '&area=' . $area . '&step=expanded&idpica_alloc=' . $item_tmp['idpica_alloc'] . '"><img src="' . $expandCollapseImg . '" border="0" alt="" class="vAlignMiddle" width="7" height="7"></a>';
100: }
101: $item['ITEMNAME'] = $expandCollapse . ' ' . $item_tmp['name'];
102: }
103: $item['ITEMINDENT'] = $item_tmp['level'] * 15 + 3;
104: $item['ACTION_CREATE'] = '<a href="main.php?contenido=' . $sess->id . '&action=' . $action . '&frame=' . $frame . '&area=' . $area . '&step=add&parentid=' . $item_tmp['idpica_alloc'] . '"><img src="images/folder_new.gif" border="0" alt="" title="' . i18n("New category", 'content_allocation') . '" alt="' . i18n("New category", 'content_allocation') . '"></a>';
105:
106: $item['ACTION_RENAME'] = '<a href="main.php?contenido=' . $sess->id . '&action=' . $action . '&frame=' . $frame . '&area=' . $area . '&step=rename&idpica_alloc=' . $item_tmp['idpica_alloc'] . '"><img src="images/but_todo.gif" width="16" height="16" border="0" alt="' . i18n("Rename category", 'content_allocation') . '" title="' . i18n("Rename category", 'content_allocation') . '"></a>';
107: $item['ACTION_MOVE_UP'] = (count($result) >= 1) ? '<a href="main.php?contenido=' . $sess->id . '&action=' . $action . '&frame=' . $frame . '&area=' . $area . '&step=moveup&idpica_alloc=' . $item_tmp['idpica_alloc'] . '"><img src="images/folder_moveup.gif" border="0" alt="' . i18n("Move category up", 'content_allocation') . '" title="' . i18n("Move category up", 'content_allocation') . '"></a>' : '<img src="images/spacer.gif" width="16" height="16"></a>';
108: $item['ACTION_MOVE_DOWN'] = (count($result) >= 1) ? '<img src="images/folder_movedown.gif" border="0" alt="' . i18n("Move category down", 'content_allocation') . '" title="' . i18n("Move category down", 'content_allocation') . '">' : '<img src="images/spacer.gif" width="16" height="16">';
109: $item['ACTION_MOVE_DOWN'] = '';
110:
111: if ($item_tmp['online'] == 1) {
112: $item['ACTION_ONOFFLINE'] = '<a href="main.php?contenido=' . $sess->id . '&action=' . $action . '&frame=' . $frame . '&area=' . $area . '&step=offline&idpica_alloc=' . $item_tmp['idpica_alloc'] . '"><img src="images/online.gif" alt="' . i18n("Set category offline", 'content_allocation') . '" title="' . i18n("Set category offline", 'content_allocation') . '"></a>';
113: } else {
114: $item['ACTION_ONOFFLINE'] = '<a href="main.php?contenido=' . $sess->id . '&action=' . $action . '&frame=' . $frame . '&area=' . $area . '&step=online&idpica_alloc=' . $item_tmp['idpica_alloc'] . '"><img src="images/offline.gif" alt="' . i18n("Set category online", 'content_allocation') . '" title="' . i18n("Set category online", 'content_allocation') . '"></a>';
115: }
116:
117: if ($item_tmp['children']) {
118: $item['ACTION_DELETE'] = '<img src="images/delete_inact.gif" border="0" alt="' . i18n("One or more subcategories exist, unable to delete", 'content_allocation') . '" title="' . i18n("One or more subcategories exist, unable to delete", 'content_allocation') . '">';
119: } else {
120: $name = str_replace("\"", "&quot;", str_replace("'", "\'", $item_tmp['name']));
121: $item['ACTION_DELETE'] = '<a href="javascript:void(0)" onclick="Con.showConfirmation("' . i18n("Are you sure to delete the following category", 'content_allocation') . '", function() { deleteCategory(' . $item_tmp['idpica_alloc'] . '); });return false;"><img src="images/delete.gif" border="0" alt="' . i18n("Delete category") . '" title="' . i18n("Delete category", 'content_allocation') . '"></a>';
122: }
123:
124: $result[] = $item;
125:
126: if ($item_tmp['children']) {
127: $children = $this->_buildRenderTree($item_tmp['children']);
128: $result = array_merge($result, $children);
129: }
130:
131:
132: if ($_GET['step'] == 'add' && $item_tmp['idpica_alloc'] == $_GET['parentid']) {
133: $item = array();
134:
135: $item['ITEMNAME'] = '
136: <table cellspacing="0" cellpaddin="0" border="0">
137: <form name="create" action="main.php" method="POST" onsubmit="return fieldCheck();">
138: <input type="hidden" name="action" value="' . $action . '">
139: <input type="hidden" name="frame" value="' . $frame . '">
140: <input type="hidden" name="contenido" value="' . $sess->id . '">
141: <input type="hidden" name="area" value="' . $area . '">
142: <input type="hidden" name="step" value="store">
143: <input type="hidden" name="treeItemPost[parentid]" value="' . $_GET['parentid'] . '">
144: <tr>
145: <td class="text_medium"><input id="itemname" class="text_medium" type="text" name="treeItemPost[name]" value=""></td>
146: <td>
147: <a href="main.php?action=' . $action . '&frame=' . $frame . '&area=' . $area . '&contenido=' . $sess->id . '"><img src="images/but_cancel.gif" alt="" border="0"></a>
148: <input type="image" src="images/but_ok.gif">
149: </td></tr>
150: </form>
151: </table>
152: <script type="text/javascript">
153: var controller = document.getElementById("itemname");
154: controller.focus();
155: function fieldCheck() {
156: if (controller.value == "") {
157: alert("' . i18n("Please enter a category name", 'content_allocation') . '");
158: controller.focus();
159: return false;
160: }
161: return true;
162: }
163: </script>';
164: $item['ITEMINDENT'] = ($item_tmp['level'] + 1) * 15;
165: $item['ACTION_CREATE'] = '<img src="images/spacer.gif" alt="" width="15" height="13">';
166: $item['ACTION_RENAME'] = '<img src="images/spacer.gif" alt="" width="23" height="14">';
167: $item['ACTION_MOVE_UP'] = '<img src="images/spacer.gif" alt="" width="15" height="13">';
168: $item['ACTION_MOVE_DOWN'] = '<img src="images/spacer.gif" alt="" width="15" height="13">';
169: $item['ACTION_MOVE_DOWN'] = '';
170: $item['ACTION_DELETE'] = '<img src="images/spacer.gif" alt="" width="14" height="13">';
171: $item['ACTION_ONOFFLINE'] = '<img src="images/spacer.gif" alt="" width="11" height="12">';
172:
173: array_push($result, $item);
174: }
175: }
176: return $result;
177: }
178:
179: 180:
181: function renderTree($return = true) {
182: $this->tpl->reset();
183:
184: $tree = $this->fetchTree(false, 0, true);
185:
186: if ($tree === false) {
187: return false;
188: }
189:
190: $tree = $this->_buildRenderTree($tree);
191:
192: $even = true;
193: foreach ($tree as $item) {
194: $even = !$even;
195: $bgcolor = ($even) ? '#FFFFFF' : '#F1F1F1';
196: $this->tpl->set('d', 'BACKGROUND_COLOR', $bgcolor);
197: foreach ($item as $key => $value) {
198: $this->tpl->set('d', $key, $value);
199: }
200: $this->tpl->next();
201: }
202:
203: $this->tpl->set('s', 'CATEGORY', i18n("Category", 'content_allocation'));
204: $this->tpl->set('s', 'ACTIONS', i18n("Actions", 'content_allocation'));
205:
206: if ($return === true) {
207: return $this->tpl->generate($this->template, true);
208: } else {
209: $this->tpl->generate($this->template);
210: }
211: }
212:
213: }
214: