1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: plugin_include('repository', 'custom/FrontendNavigation.php');
17:
18: 19: 20: 21: 22: 23:
24: class pApiContentAllocationTreeView extends pApiTree {
25:
26: 27: 28:
29: protected $_tpl = null;
30:
31: 32: 33:
34: protected $_template = '';
35:
36: 37: 38: 39: 40:
41: public function __construct($uuid) {
42: $cfg = cRegistry::getConfig();
43:
44: parent::__construct($uuid);
45: $this->_tpl = new cTemplate();
46: $this->_template = $cfg['pica']['treetemplate'];
47: }
48:
49: 50: 51: 52: 53: 54: 55: 56:
57: public function pApiContentAllocationTreeView($uuid) {
58: cDeprecated('This method is deprecated and is not needed any longer. Please use __construct() as constructor function.');
59: return $this->__construct($uuid);
60: }
61:
62: 63: 64: 65: 66: 67:
68: protected function _buildRenderTree($tree) {
69: global $action, $frame, $area;
70: $idart = cRegistry::getArticleId();
71: $sess = cRegistry::getBackendSessionId();
72:
73: $result = array();
74: foreach ($tree as $item_tmp) {
75: $item = array();
76:
77: if ($_GET['step'] == 'rename' && $item_tmp['idpica_alloc'] == $_GET['idpica_alloc']) {
78: $item = array();
79: $item['ITEMNAME'] = '
80: <table cellspacing="0" cellpaddin="0" border="0">
81: <form name="rename" action="main.php" method="POST" onsubmit="return fieldCheck();">
82: <input type="hidden" name="action" value="' . $action . '">
83: <input type="hidden" name="frame" value="' . $frame . '">
84: <input type="hidden" name="contenido" value="' . $sess . '">
85: <input type="hidden" name="area" value="' . $area . '">
86: <input type="hidden" name="step" value="storeRename">
87: <input type="hidden" name="treeItemPost[idpica_alloc]" value="' . $item_tmp['idpica_alloc'] . '">
88: <tr>
89: <td class="text_medium"><input id="itemname" class="text_medium" type="text" name="treeItemPost[name]" value="' . conHtmlentities($item_tmp['name']) . '"></td>
90: <td>
91: <a href="main.php?action=' . $action . '&frame=' . $frame . '&area=' . $area . '&contenido=' . $sess . '"><img src="images/but_cancel.gif" border="0"></a>
92: <input type="image" src="images/but_ok.gif">
93: </td></tr>
94: </form>
95: </table>
96: <script type="text/javascript">
97: var controller = document.getElementById("itemname");
98: controller.focus();
99: function fieldCheck() {
100: if (controller.value == "") {
101: alert("' . i18n("Please enter a category name", 'content_allocation') . '");
102: controller.focus();
103: return false;
104: }
105: return true;
106: }
107: </script>';
108: } else {
109: if ($item_tmp['children'] || $item_tmp['status'] == 'collapsed') {
110: $expandCollapseImg = 'images/close_all.gif';
111: if ($item_tmp['status'] == 'collapsed') {
112: $expandCollapseImg = 'images/open_all.gif';
113: }
114:
115: $expandCollapse = '<a href="main.php?contenido=' . $sess . '&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>';
116: } else {
117: $expandCollapseImg = 'images/spacer.gif';
118: $expandCollapse = '<img src="' . $expandCollapseImg . '" border="0" alt="" class="vAlignMiddle" width="11" height="11">';
119: }
120:
121: if ($item_tmp['status'] == 'collapsed') {
122: $expandCollapse = '<a href="main.php?contenido=' . $sess . '&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>';
123: }
124: $item['ITEMNAME'] = $expandCollapse . ' ' . $item_tmp['name'];
125: }
126: $item['ITEMINDENT'] = $item_tmp['level'] * 15 + 3;
127: $item['ACTION_CREATE'] = '<a href="main.php?contenido=' . $sess . '&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>';
128:
129: $item['ACTION_RENAME'] = '<a href="main.php?contenido=' . $sess . '&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>';
130: $item['ACTION_MOVE_UP'] = (count($result) >= 1) ? '<a href="main.php?contenido=' . $sess . '&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>';
131: $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">';
132: $item['ACTION_MOVE_DOWN'] = '';
133:
134: if ($item_tmp['online'] == 1) {
135: $item['ACTION_ONOFFLINE'] = '<a href="main.php?contenido=' . $sess . '&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>';
136: } else {
137: $item['ACTION_ONOFFLINE'] = '<a href="main.php?contenido=' . $sess . '&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>';
138: }
139:
140: if ($item_tmp['children']) {
141: $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') . '">';
142: } else {
143: $name = str_replace("\"", "&quot;", str_replace("'", "\'", $item_tmp['name']));
144: $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>';
145: }
146:
147: $result[] = $item;
148:
149: if ($item_tmp['children']) {
150: $children = $this->_buildRenderTree($item_tmp['children']);
151: $result = array_merge($result, $children);
152: }
153:
154:
155: if ($_GET['step'] == 'add' && $item_tmp['idpica_alloc'] == $_GET['parentid']) {
156: $item = array();
157:
158: $item['ITEMNAME'] = '
159: <table cellspacing="0" cellpaddin="0" border="0">
160: <form name="create" action="main.php" method="POST" onsubmit="return fieldCheck();">
161: <input type="hidden" name="action" value="' . $action . '">
162: <input type="hidden" name="frame" value="' . $frame . '">
163: <input type="hidden" name="contenido" value="' . $sess . '">
164: <input type="hidden" name="area" value="' . $area . '">
165: <input type="hidden" name="step" value="store">
166: <input type="hidden" name="treeItemPost[parentid]" value="' . cSecurity::toInteger($_GET['parentid']) . '">
167: <tr>
168: <td class="text_medium"><input id="itemname" class="text_medium" type="text" name="treeItemPost[name]" value=""></td>
169: <td>
170: <a href="main.php?action=' . $action . '&frame=' . $frame . '&area=' . $area . '&contenido=' . $sess . '"><img src="images/but_cancel.gif" alt="" border="0"></a>
171: <input type="image" src="images/but_ok.gif">
172: </td></tr>
173: </form>
174: </table>
175: <script type="text/javascript">
176: var controller = document.getElementById("itemname");
177: controller.focus();
178: function fieldCheck() {
179: if (controller.value == "") {
180: alert("' . i18n("Please enter a category name", 'content_allocation') . '");
181: controller.focus();
182: return false;
183: }
184: return true;
185: }
186: </script>';
187: $item['ITEMINDENT'] = ($item_tmp['level'] + 1) * 15;
188: $item['ACTION_CREATE'] = '<img src="images/spacer.gif" alt="" width="15" height="13">';
189: $item['ACTION_RENAME'] = '<img src="images/spacer.gif" alt="" width="23" height="14">';
190: $item['ACTION_MOVE_UP'] = '<img src="images/spacer.gif" alt="" width="15" height="13">';
191: $item['ACTION_MOVE_DOWN'] = '<img src="images/spacer.gif" alt="" width="15" height="13">';
192: $item['ACTION_MOVE_DOWN'] = '';
193: $item['ACTION_DELETE'] = '<img src="images/spacer.gif" alt="" width="14" height="13">';
194: $item['ACTION_ONOFFLINE'] = '<img src="images/spacer.gif" alt="" width="11" height="12">';
195:
196: array_push($result, $item);
197: }
198: }
199: return $result;
200: }
201:
202: 203: 204: 205: 206: 207:
208: public function renderTree($return = true) {
209: $this->_tpl->reset();
210:
211: $tree = $this->fetchTree(false, 0, true);
212:
213: if ($tree === false) {
214: return false;
215: }
216:
217: $tree = $this->_buildRenderTree($tree);
218:
219: $even = true;
220: foreach ($tree as $item) {
221: $even = !$even;
222: $bgcolor = ($even) ? '#FFFFFF' : '#F1F1F1';
223: $this->_tpl->set('d', 'BACKGROUND_COLOR', $bgcolor);
224: foreach ($item as $key => $value) {
225: $this->_tpl->set('d', $key, $value);
226: }
227: $this->_tpl->next();
228: }
229:
230: $this->_tpl->set('s', 'CATEGORY', i18n("Category", 'content_allocation'));
231: $this->_tpl->set('s', 'ACTIONS', i18n("Actions", 'content_allocation'));
232:
233: if ($return === true) {
234: return $this->_tpl->generate($this->_template, true);
235: } else {
236: $this->_tpl->generate($this->_template);
237: }
238: }
239:
240: }
241: ?>