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: cInclude("includes", "functions.str.php");
19: cInclude("includes", "functions.tpl.php");
20: cInclude('includes', 'functions.lang.php');
21:
22: function showTree($iIdcat, &$aWholelist) {
23: global $check_global_rights, $sess, $cfg, $perm, $db, $db2, $db3, $area, $client, $lang, $navigationTree;
24:
25: $tpl = new cTemplate();
26: $tpl->reset();
27:
28: $iIdcat = (int) $iIdcat;
29:
30: foreach ($navigationTree[$iIdcat] as $sKey => $aValue) {
31:
32: $cfgdata = '';
33: $aCssClasses = array();
34:
35:
36: if (!$check_global_rights) {
37: $check_rights = false;
38: } else {
39: $check_rights = true;
40: }
41:
42: if (!$check_rights) {
43: $check_rights = ($aValue['forcedisplay'] == 1) ? true : false;
44: }
45:
46: $idcat = (int) $aValue['idcat'];
47: $level = $aValue['level'] - 1;
48: $name = $aValue['name'];
49:
50: if ($check_rights) {
51:
52: $idtpl = ($aValue['idtpl'] != '') ? $aValue['idtpl'] : 0;
53:
54: if (($aValue["idlang"] != $lang) || ($aValue['articles'] == true)) {
55:
56: }
57:
58: $check_rights = $perm->have_perm_area_action_item("con", "con_changetemplate", $aValue['idcat']);
59: if (!$check_rights) {
60: $check_rights = $perm->have_perm_area_action("con", "con_changetemplate");
61: }
62:
63: $changetemplate = ($check_rights) ? 1 : 0;
64:
65: $check_rights = $perm->have_perm_area_action_item("con", "con_makecatonline", $aValue['idcat']);
66: if (!$check_rights) {
67: $check_rights = $perm->have_perm_area_action("con", "con_makecatonline");
68: }
69:
70: $onoffline = ($check_rights) ? 1 : 0;
71:
72: $check_rights = $perm->have_perm_area_action_item("con", "con_makepublic", $aValue['idcat']);
73: if (!$check_rights) {
74: $check_rights = $perm->have_perm_area_action("con", "con_makepublic");
75: }
76:
77: $makepublic = ($check_rights) ? 1 : 0;
78:
79: $check_rights = $perm->have_perm_area_action_item("con", "con_tplcfg_edit", $aValue['idcat']);
80: if (!$check_rights) {
81: $check_rights = $perm->have_perm_area_action("con", "con_tplcfg_edit");
82: }
83:
84: $templateconfig = ($check_rights) ? 1 : 0;
85:
86: if ($aValue["idlang"] == $lang) {
87:
88: $cfgdata = $idcat . "-" . $idtpl . "-" . $aValue['online'] . "-" . $aValue['public'] . "-" .
89: $changetemplate . "-" .
90: $onoffline . "-" .
91: $makepublic . "-" . $templateconfig;
92: } else {
93: $cfgdata = "";
94: }
95:
96:
97:
98: if ($aValue['online'] == 1) {
99:
100:
101: if ($aValue['public'] == 0) {
102:
103: if ($aValue['no_start'] || $aValue['no_online']) {
104: $aAnchorClass = 'on_error_locked';
105: } else {
106: $aAnchorClass = 'on_locked';
107: }
108: } else {
109:
110: if ($aValue['no_start'] || $aValue['no_online']) {
111: $aAnchorClass = 'on_error';
112: } else {
113: $aAnchorClass = 'on';
114: }
115: }
116: } else {
117:
118:
119: if ($aValue['public'] == 0) {
120:
121: if ($aValue['no_start'] || $aValue['no_online']) {
122: $aAnchorClass = 'off_error_locked';
123: } else {
124: $aAnchorClass = 'off_locked';
125: }
126: } else {
127:
128: if ($aValue['no_start'] || $aValue['no_online']) {
129: $aAnchorClass = 'off_error';
130: } else {
131: $aAnchorClass = 'off';
132: }
133: }
134: }
135:
136: if ($aValue['islast'] == 1) {
137: $aCssClasses[] = 'last';
138: }
139:
140: if ($aValue['collapsed'] == 1 && is_array($navigationTree[$idcat])) {
141: $aCssClasses[] = 'collapsed';
142: }
143:
144: if ($aValue['active']) {
145: $aCssClasses[] = 'active';
146: }
147:
148: $bIsSyncable = false;
149: if ($aValue["idlang"] != $lang) {
150:
151: $sql = "SELECT parentid FROM %s WHERE idcat = '%s'";
152: $db->query(sprintf($sql, $cfg["tab"]["cat"], $idcat));
153: if ($db->nextRecord()) {
154: if ($db->f("parentid") != 0) {
155: $parentid = $db->f("parentid");
156: $sql = "SELECT idcatlang FROM %s WHERE idcat = '%s' AND idlang = '%s'";
157: $db->query(sprintf($sql, $cfg["tab"]["cat_lang"], cSecurity::toInteger($parentid), cSecurity::toInteger($lang)));
158:
159: if ($db->nextRecord()) {
160: $aCssClasses[] = 'con_sync';
161: $bIsSyncable = true;
162: }
163: } else {
164: $aCssClasses[] = 'con_sync';
165: $bIsSyncable = true;
166: }
167: }
168: }
169:
170:
171: if ($bIsSyncable) {
172: if ($cfgdata != '') {
173: $cfgdata .= '-1';
174: } else {
175: $cfgdata = $idcat . "-" . $idtpl . "-" . $aValue['online'] . "-" . $aValue['public'] .
176: "-0-0-0-0-1";
177: }
178: } else {
179: if ($cfgdata != '') {
180: $cfgdata .= '-0';
181: } else {
182: $cfgdata = $idcat . "-" . $idtpl . "-" . $aValue['online'] . "-" . $aValue['public'] .
183: "-0-0-0-0-0";
184: }
185: }
186:
187: $strName = cSecurity::unFilter($name);
188: $mstr = '<a class="' . $aAnchorClass . '" href="#" title="idcat' . ': ' . $idcat . '">' . $strName . '</a>';
189:
190:
191: $tpl->set('d', 'CFGDATA', $cfgdata);
192: if (is_array($navigationTree[$idcat])) {
193: $tpl->set('d', 'SUBCATS', showTree($idcat, $aWholelist));
194: $tpl->set('d', 'COLLAPSE', '<a href="#"> </a>');
195: $aWholelist[] = $idcat;
196: } else {
197: $tpl->set('d', 'SUBCATS', '');
198: $tpl->set('d', 'COLLAPSE', '<span> </span>');
199: }
200: $tpl->set('d', 'CAT', $mstr);
201: $tpl->set('d', 'CSS_CLASS', ' class="' . implode(' ', $aCssClasses) . '"');
202:
203: $tpl->next();
204: } else {
205: if (is_array($navigationTree[(int) $aValue['idcat']])) {
206: $sTpl = showTree((int) $aValue['idcat'], $aWholelist);
207: if (!preg_match('/^<ul>\s*<\/ul>$/', $sTpl)) {
208: $tpl->set('d', 'CFGDATA', '0-0-0-0-0-0-0-0-0');
209: $tpl->set('d', 'SUBCATS', $sTpl);
210: $tpl->set('d', 'COLLAPSE', '<a href="#"></a>');
211: $tpl->set('d', 'CAT', '<a class="off_disabled" href="#">' . $name . '</a>');
212: $tpl->set('d', 'CSS_CLASS', ' class="active"');
213: $tpl->next();
214: }
215: $aWholelist[] = $aValue['idcat'];
216: }
217: }
218: }
219: return $tpl->generate($cfg['path']['templates'] . 'template.con_str_overview.list.html', 1);
220: }
221:
222: $db2 = cRegistry::getDb();
223: $db3 = cRegistry::getDb();
224:
225:
226: $tpl->reset();
227:
228: if ($action == "con_synccat" || isset($_GET['refresh_syncoptions']) && $_GET['refresh_syncoptions'] == 'true') {
229: $tpl->set('s', 'RELOAD_RIGHT', 'reloadRightFrame();');
230: } else {
231: $tpl->set('s', 'RELOAD_RIGHT', '');
232: }
233:
234: if ($action == "con_synccat") {
235: strSyncCategory($syncidcat, $syncfromlang, $lang, $multiple);
236: $remakeStrTable = true;
237: }
238:
239: if (!is_object($db2))
240: $db2 = cRegistry::getDb();
241:
242: if (!isset($remakeStrTable)) {
243: $remakeStrTable = false;
244: }
245:
246: if (!isset($remakeCatTable)) {
247: $remakeCatTable = false;
248: }
249:
250: $sess->register("remakeCatTable");
251: $sess->register("CatTableClient");
252: $sess->register("CatTableLang");
253: $sess->register("remakeStrTable");
254:
255: if (isset($syncoptions)) {
256: $syncfrom = $syncoptions;
257: $remakeCatTable = true;
258: }
259:
260: if (!isset($syncfrom)) {
261: $syncfrom = 0;
262: }
263:
264: $sess->register("syncfrom");
265:
266: $syncoptions = $syncfrom;
267:
268: if (!isset($CatTableClient)) {
269: $CatTableClient = 0;
270: }
271:
272: if ($CatTableClient != $client) {
273: $remakeCatTable = true;
274: }
275:
276: if (!isset($CatTableLang)) {
277: $CatTableLang = 0;
278: }
279:
280: if ($CatTableLang != $lang) {
281: $remakeCatTable = true;
282: }
283:
284: $CatTableClient = $client;
285: $CatTableLang = $lang;
286:
287: if ($syncoptions == -1) {
288: $sql = "SELECT
289: a.preid AS preid,
290: a.postid AS postid,
291: a.parentid AS parentid,
292: c.idcat AS idcat,
293: c.level AS level,
294: b.name AS name,
295: b.public AS public,
296: b.visible AS online,
297: d.idtpl AS idtpl,
298: b.idlang AS idlang
299: FROM
300: (" . $cfg["tab"]["cat"] . " AS a,
301: " . $cfg["tab"]["cat_lang"] . " AS b,
302: " . $cfg["tab"]["cat_tree"] . " AS c)
303: LEFT JOIN
304: " . $cfg["tab"]["tpl_conf"] . " AS d
305: ON d.idtplcfg = b.idtplcfg
306: WHERE
307: a.idclient = '" . cSecurity::toInteger($client) . "' AND
308: b.idlang = '" . cSecurity::toInteger($lang) . "' AND
309: c.idcat = b.idcat AND
310: b.idcat = a.idcat
311: ORDER BY
312: c.idtree ASC";
313: } else {
314: $sql = "SELECT
315: a.preid AS preid,
316: a.postid AS postid,
317: a.parentid AS parentid,
318: c.idcat AS idcat,
319: c.level AS level,
320: b.name AS name,
321: b.public AS public,
322: b.visible AS online,
323: d.idtpl AS idtpl,
324: b.idlang AS idlang
325: FROM
326: (" . $cfg["tab"]["cat"] . " AS a,
327: " . $cfg["tab"]["cat_lang"] . " AS b,
328: " . $cfg["tab"]["cat_tree"] . " AS c)
329: LEFT JOIN
330: " . $cfg["tab"]["tpl_conf"] . " AS d
331: ON d.idtplcfg = b.idtplcfg
332: WHERE
333: a.idclient = '" . cSecurity::toInteger($client) . "' AND
334: (b.idlang = '" . cSecurity::toInteger($lang) . "' OR
335: b.idlang = '" . cSecurity::toInteger($syncoptions) . "') AND
336: c.idcat = b.idcat AND
337: b.idcat = a.idcat
338: ORDER BY
339: c.idtree ASC";
340: }
341:
342: $db->query($sql);
343:
344: if (isset($syncoptions)) {
345: $remakeCatTable = true;
346: }
347:
348: if (isset($online)) {
349: $remakeCatTable = true;
350: }
351:
352: if (isset($public)) {
353: $remakeCatTable = true;
354: }
355:
356: if (isset($idtpl)) {
357: $remakeCatTable = true;
358: }
359:
360: if (isset($force)) {
361: $remakeCatTable = true;
362: }
363:
364: $arrIn = array();
365: while ($db->nextRecord()) {
366: $arrIn[] = $db->f('idcat');
367: }
368:
369: $arrArtCache = array();
370:
371: if (count($arrIn) > 0) {
372: $sIn = implode(',', $arrIn);
373:
374: $sql2 = "SELECT b.idcat, a.idart, idlang FROM " . $cfg["tab"]["art_lang"] . " AS a,
375: " . $cfg["tab"]["cat_art"] . " AS b
376: WHERE b.idcat IN (" . cSecurity::escapeDB($sIn, $db) . ") AND (a.idlang = '" . cSecurity::toInteger($syncoptions) . "' OR a.idlang = '" . cSecurity::toInteger($lang) . "')
377: AND b.idart = a.idart";
378: $db->query($sql2);
379:
380: while ($db->nextRecord()) {
381: $arrArtCache[$db->f('idcat')][$db->f('idart')][$db->f('idlang')] = 'x';
382: }
383: }
384:
385: $db->query($sql);
386:
387: while ($db->nextRecord()) {
388: $entry = array();
389:
390: $entry['articles'] = false;
391:
392: if ($db->f("idlang") == $lang) {
393:
394: $arts = Array();
395:
396: if (isset($arrArtCache[$db->f("idcat")])) {
397: foreach ($arrArtCache[$db->f("idcat")] as $key => $value) {
398: foreach ($value as $key2 => $value2) {
399: $arts[$key][$key2] = 1;
400: }
401: }
402: }
403:
404: foreach ($arts as $idart => $entry) {
405: if (is_array($entry)) {
406: if (!array_key_exists($lang, $entry)) {
407:
408: $aIsArticles[$db->f("idcat")] = true;
409: break;
410: }
411: }
412: }
413: }
414: }
415:
416: if ($syncoptions == -1) {
417: $sql2 = "SELECT
418: c.idcat AS idcat,
419: SUM(a.online) AS online,
420: d.startidartlang
421: FROM
422: " . $cfg["tab"]["art_lang"] . " AS a,
423: " . $cfg["tab"]["art"] . " AS b,
424: " . $cfg["tab"]["cat_art"] . " AS c,
425: " . $cfg["tab"]["cat_lang"] . " AS d
426: WHERE
427: a.idlang = " . cSecurity::toInteger($lang) . " AND
428: a.idart = b.idart AND
429: b.idclient = '" . cSecurity::toInteger($client) . "' AND
430: b.idart = c.idart AND
431: c.idcat = d.idcat
432: GROUP BY c.idcat
433: ";
434: } else {
435: $sql2 = "SELECT
436: c.idcat AS idcat,
437: SUM(a.online) AS online,
438: d.startidartlang
439: FROM
440: " . $cfg["tab"]["art_lang"] . " AS a,
441: " . $cfg["tab"]["art"] . " AS b,
442: " . $cfg["tab"]["cat_art"] . " AS c,
443: " . $cfg["tab"]["cat_lang"] . " AS d
444: WHERE
445: a.idart = b.idart AND
446: b.idclient = '" . cSecurity::toInteger($client) . "' AND
447: b.idart = c.idart AND
448: c.idcat = d.idcat
449: GROUP BY c.idcat";
450: }
451:
452: $db->query($sql2);
453: $aStartOnlineArticles = array();
454: while ($db->nextRecord()) {
455: if ($db->f('startidartlang') > 0) {
456: $aStartOnlineArticles[$db->f('idcat')]['is_start'] = true;
457: } else {
458: $aStartOnlineArticles[$db->f('idcat')]['is_start'] = false;
459: }
460: if ($db->f('online') > 0) {
461: $aStartOnlineArticles[$db->f('idcat')]['is_online'] = true;
462: } else {
463: $aStartOnlineArticles[$db->f('idcat')]['is_online'] = false;
464: }
465: }
466:
467: $_cecIterator = $_cecRegistry->getIterator("Contenido.ArticleCategoryList.ListItems");
468:
469: if ($_cecIterator->count() > 0) {
470: while ($chainEntry = $_cecIterator->next()) {
471: $listItem = $chainEntry->execute();
472:
473: if (is_array($listItem)) {
474: if (!array_key_exists("expandcollapseimage", $listItem) || $listItem["expandcollapseimage"] == "") {
475: $collapseImage = '<img src="images/spacer.gif" width="11" height="11">';
476: } else {
477: $collapseImage = $listItem["expandcollapseimage"];
478: }
479:
480: if (!array_key_exists("image", $listItem) || $listItem["image"] == "") {
481: $image = '<img src="images/spacer.gif">';
482: } else {
483: $image = $listItem["image"];
484: }
485:
486: if (!array_key_exists("id", $listItem) || $listItem["id"] == "") {
487: $id = rand();
488: } else {
489: $id = $listItem["id"];
490: }
491:
492: if (array_key_exists("markable", $listItem)) {
493: if ($listItem["markable"] == true) {
494: $mmark = $markscript;
495: } else {
496: $mmark = "";
497: }
498: } else {
499: $mmark = "";
500: }
501: }
502: }
503: }
504:
505: $languages = getLanguageNamesByClient($client);
506:
507:
508:
509: $selflink = "main.php";
510: $expandlink = $sess->url($selflink . "?area=$area&frame=$frame&expand=all&syncoptions=$syncoptions");
511: $collapselink = $sess->url($selflink . "?area=$area&frame=$frame&collapse=all&syncoptions=$syncoptions");
512: $collapseimg = '<a href="' . $collapselink . '" alt="' . i18n("Close all categories") . '" title="' . i18n("Close all categories") . '"><img src="images/but_minus.gif" border="0"></a>';
513: $expandimg = '<a href="' . $expandlink . '" alt="' . i18n("Open all categories") . '" title="' . i18n("Open all categories") . '"><img src="images/but_plus.gif" border="0"></a>';
514: $allLinks = $expandimg . '<img src="images/spacer.gif" width="3">' . $collapseimg;
515: $text_direction = langGetTextDirection($lang);
516:
517:
518: $check_global_rights = $perm->have_perm_area_action("con", "con_makestart");
519: if (!$check_global_rights) {
520: $check_global_rights = $perm->have_perm_area_action("con_editart", "con_edit");
521: }
522: if (!$check_global_rights) {
523: $check_global_rights = $perm->have_perm_area_action("con_editart", "con_saveart");
524: }
525: if (!$check_global_rights) {
526: $check_global_rights = $perm->have_perm_area_action("con_editcontent", "con_editart");
527: }
528: if (!$check_global_rights) {
529: $check_global_rights = $perm->have_perm_area_action("con_editart", "con_newart");
530: }
531: if (!$check_global_rights) {
532: $check_global_rights = $perm->have_perm_area_action("con", "con_deleteart");
533: }
534: if (!$check_global_rights) {
535: $check_global_rights = $perm->have_perm_area_action("con", "con_makeonline");
536: }
537: if (!$check_global_rights) {
538: $check_global_rights = $perm->have_perm_area_action("con", "con_tplcfg_edit");
539: }
540: if (!$check_global_rights) {
541: $check_global_rights = $perm->have_perm_area_action("con", "con_makecatonline");
542: }
543: if (!$check_global_rights) {
544: $check_global_rights = $perm->have_perm_area_action("con", "con_changetemplate");
545: }
546:
547: if ($lang > $syncoptions) {
548: $sOrder = 'DESC';
549: } else {
550: $sOrder = 'ASC';
551: }
552:
553: $client = (int) $client;
554: $sql = "SELECT DISTINCT " .
555: "a.idcat, " .
556: "a.parentid, " .
557: "a.preid, " .
558: "a.postid, " .
559: "a.parentid, " .
560: "b.name, " .
561: "b.idlang, " .
562: "b.visible, " .
563: "b.public, " .
564: "c.level, " .
565: "d.idtpl " .
566: "FROM {$cfg['tab']['cat']} AS a " .
567: "LEFT JOIN {$cfg['tab']['cat_lang']} AS b ON a.idcat = b.idcat " .
568: "LEFT JOIN {$cfg['tab']['cat_tree']} AS c ON (a.idcat = c.idcat AND b.idcat = c.idcat) " .
569: "LEFT JOIN {$cfg["tab"]["tpl_conf"]} AS d ON b.idtplcfg = d.idtplcfg " .
570: "WHERE " .
571: " a.idclient = {$client} " .
572: "ORDER BY b.idlang {$sOrder}, c.idtree ASC ";
573: $db->query($sql);
574: if ($client == 0) {
575: $client = '';
576: }
577:
578:
579: $sExpandList = $currentuser->getUserProperty("system", "con_cat_expandstate");
580: if ($sExpandList != '') {
581: $conexpandedList = unserialize($currentuser->getUserProperty("system", "con_cat_expandstate"));
582: }
583:
584: if (!is_array($conexpandedList)) {
585: $conexpandedList = array();
586: }
587:
588: $navigationTree = array();
589: $aWholelist = array();
590:
591: while ($db->nextRecord()) {
592: if (!isset($navigationTree[$db->f('parentid')][$db->f('idcat')]) && ($db->f('idlang') == $lang || $db->f('idlang') == $syncoptions)) {
593: if (in_array($db->f('idcat'), $conexpandedList)) {
594: $collapsed = false;
595: } else {
596: $collapsed = true;
597: }
598: if ($perm->have_perm_item("con", $db->f('idcat'))) {
599: $forcedisplay = 1;
600: } else {
601: $forcedisplay = 0;
602: }
603: if ($idcat == $db->f('idcat')) {
604: $active = true;
605: } else {
606: $active = false;
607: }
608: $navigationTree[$db->f('parentid')][$db->f('idcat')] = array(
609: 'idcat' => $db->f('idcat'),
610: 'preid' => $db->f('preid'),
611: 'postid' => $db->f('postid'),
612: 'visible' => $db->f('visible'),
613: 'online' => $db->f('visible'),
614: 'public' => $db->f('public'),
615: 'name' => $db->f('name'),
616: 'idlang' => $db->f('idlang'),
617: 'idtpl' => $db->f('idtpl'),
618: 'collapsed' => $collapsed,
619: 'forcedisplay' => $forcedisplay,
620: 'active' => $active,
621: 'islast' => false,
622: 'articles' => $aIsArticles[$db->f("idcat")],
623: 'level' => $db->f('level')
624: );
625: if ($aStartOnlineArticles[$db->f('idcat')]['is_start']) {
626: $navigationTree[$db->f('parentid')][$db->f('idcat')]['no_start'] = false;
627: } else {
628: $navigationTree[$db->f('parentid')][$db->f('idcat')]['no_start'] = true;
629: }
630: if ($aStartOnlineArticles[$db->f('idcat')]['is_online']) {
631: $navigationTree[$db->f('parentid')][$db->f('idcat')]['no_online'] = false;
632: } else {
633: $navigationTree[$db->f('parentid')][$db->f('idcat')]['no_online'] = true;
634: }
635: }
636: }
637:
638: cDebug::out(print_r($navigationTree, true));
639:
640: if (count($navigationTree[0])) {
641: $sCategories = showTree(0, $aWholelist);
642: }
643:
644: $tpl->set('s', 'SID', $sess->id);
645: $tpl->set('s', 'CATS', $sCategories);
646: $tpl->set('s', 'AREA', $area);
647: $tpl->set('s', 'SESSION', $contenido);
648: $tpl->set('s', 'DIRECTION', 'dir="' . langGetTextDirection($lang) . '"');
649: $tpl->set('s', 'SYNCOPTIONS', $syncoptions);
650:
651: $tpl->set('s', 'AJAXURL', cRegistry::getBackendUrl() . 'ajaxmain.php');
652: $tpl->set('s', 'WHOLELIST', implode(', ', $aWholelist));
653: $tpl->set('s', 'EXPANDEDLIST', implode(', ', $conexpandedList));
654:
655: $tpl->generate($cfg['path']['templates'] . $cfg['templates']['con_str_overview']);
656:
657: ?>