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