1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16:
17: $client = cRegistry::getClientId();
18: $lang = cRegistry::getLanguageId();
19: $idart = cRegistry::getArticleId();
20:
21:
22: $art = new cApiArticleLanguage();
23: $art->loadByArticleAndLanguageId($idart, $lang);
24: $content = $art->getContent('CMS_TEXT', 1);
25: $level = $art->getContent('CMS_TEXT', 2);
26: $article = $art->getContent('CMS_TEXT', 3);
27:
28:
29: $tpl = cSmartyFrontend::getInstance();
30: $tpl->assign('isBackendEditMode', cRegistry::isBackendEditMode());
31:
32:
33: $tpl->assign('trans', array(
34: 'headline' => mi18n("HEADLINE"),
35: 'categoryLabel' => mi18n("CATEGORY_LABEL"),
36: 'levelLabel' => mi18n("LEVEL_LABEL"),
37: 'articleLabel' => mi18n("ARTICLE_LABEL"),
38: 'articleHintLabel' => mi18n("ARTICLE_HINT_LABEL"),
39: 'categoryHintLabel' => mi18n("GATEGORY_HINT_LABEL"),
40: 'levelHintLabel' => mi18n("LEVEL_HINT_LABEL")
41: ));
42:
43:
44: $tpl->assign('category', "CMS_TEXT[1]");
45: $tpl->assign('level', "CMS_TEXT[2]");
46: $tpl->assign('article', "CMS_TEXT[3]");
47: $tpl->assign('first', false);
48:
49:
50: if (false === is_numeric($content) || false === is_numeric($level)) {
51: $tpl->assign('error', mi18n("NOT_NUMERIC_VALUE"));
52: } else if ($article != 0 && $article != 1) {
53: $tpl->assign('error', mi18n("NOT_ZERO_OR_ONE"));
54: } else {
55:
56: $categoryHelper = cCategoryHelper::getInstance();
57: $categoryHelper->setAuth(cRegistry::getAuth());
58: $tree = $categoryHelper->getSubCategories($content, $level);
59: if (1 == $article) {
60: $tree = addArticlesToTree($tree);
61: }
62: $tpl->assign('tree', $tree);
63: }
64:
65: $tpl->display('get.tpl');
66:
67: 68: 69: 70: 71: 72: 73:
74: function addArticlesToTree(array $tree) {
75:
76: $startidartlang = getStartIdArtLang();
77:
78: foreach ($tree as $key => $wrapper) {
79: $tree[$key]['articles'] = getArticlesFromCategory($wrapper['idcat'], $startidartlang);
80: $tree[$key]['subcats'] = addArticlesToTree($tree[$key]['subcats']);
81: }
82:
83: return $tree;
84:
85: }
86:
87: 88: 89: 90: 91:
92: function getStartIdArtLang() {
93: $cfg = cRegistry::getConfig();
94: $db = cRegistry::getDb();
95:
96:
97: $startidartlang = array();
98:
99: $sql = 'SELECT startidartlang FROM `' . $cfg['tab']['cat_lang'] . '` WHERE visible = 1 AND public = 1';
100: $ret = $db->query($sql);
101: while ($db->next_record()) {
102: $startidartlang[] = $db->f('startidartlang');
103: }
104:
105: return $startidartlang;
106: }
107:
108: 109: 110: 111: 112:
113: function getArticlesFromCategory($categoryId, $startidartlang) {
114:
115: $cfg = cRegistry::getConfig();
116: $db = cRegistry::getDb();
117:
118:
119:
120: $sql = '-- getArticlesFromCategory()
121: SELECT
122: al.idartlang
123: , UNIX_TIMESTAMP(al.lastmodified) AS lastmod
124: , al.changefreq
125: , al.sitemapprio
126: , al.title
127: FROM
128: `' . $cfg['tab']['art_lang'] . '` AS al
129: , `' . $cfg['tab']['cat_art'] . '` AS ca
130: WHERE
131: al.idart = ca.idart
132: AND al.idlang = ' . cSecurity::toInteger(cRegistry::getLanguageId()) . '
133: AND ca.idcat IN (' . $categoryId . ')
134: AND al.online = 1
135: AND al.searchable = 1
136: ;';
137:
138: $ret = $db->query($sql);
139:
140: $array = array();
141: if (false !== $ret) {
142: while ($db->next_record()) {
143:
144: if (!in_array($db->f('idartlang'), $startidartlang)) {
145:
146: $article = new cApiArticleLanguage();
147: $article->loadByPrimaryKey($db->f('idartlang'));
148: $array[] = $article;
149: }
150: }
151: }
152:
153: return $array;
154:
155: }
156:
157: ?>