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