1: ?><?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: $db = cRegistry::getDb();
16: $cfg = cRegistry::getConfig();
17: $client = cRegistry::getClientId();
18:
19: $selected = "CMS_VALUE[1]";
20: $filename = "CMS_VALUE[2]";
21: $selectName = "CMS_VAR[1]";
22:
23:
24: if ($selected == '') {
25: $query = 'SELECT * FROM ' . $cfg['tab']['cat_tree'] . ' AS a, ' . $cfg['tab']['cat'] . ' AS b WHERE (a.idcat) AND (b.idcat) AND (b.idclient = ' . $client . ') ORDER BY a.idtree';
26: $db->query($query);
27: $db->nextRecord();
28: $selected = $db->f('idcat');
29: }
30:
31: $categories = buildCategoryArray();
32:
33: $table = new cHTMLTable();
34: $trs = array();
35:
36:
37: $tr = new cHTMLTableRow();
38: $tds = array();
39: $td = new cHTMLTableData();
40: $td->setContent(conHtmlSpecialChars(mi18n("Choose tree:")));
41: $tds[] = $td;
42: $td = new cHTMLTableData();
43:
44: $select = new cHTMLSelectElement($selectName);
45:
46: foreach ($categories as $key => $value) {
47: $option = new cHTMLOptionElement($value['name_indented'], $value['idcat']);
48: if ($selected == $value['idcat']) {
49: $option->setSelected(true);
50: }
51: $select->appendOptionElement($option);
52: }
53: $td->setContent($select);
54: $tds[] = $td;
55: $tr->setContent($tds);
56: $trs[] = $tr;
57:
58:
59: $tr = new cHTMLTableRow();
60: $tds = array();
61: $td = new cHTMLTableData();
62: $td->setContent(conHtmlSpecialChars(mi18n("Enter filename (optional):")));
63: $tds[] = $td;
64: $td = new cHTMLTableData();
65: $input = new cHTMLTextbox("CMS_VAR[2]", $filename, 20);
66:
67: $td->setContent($input);
68: $tds[] = $td;
69: $tr->setContent($tds);
70: $trs[] = $tr;
71:
72: $table->setContent($trs);
73:
74:
75: echo $table->render();
76:
77: 78: 79: 80: 81: 82: 83:
84: function buildCategoryArray() {
85: $cfg = cRegistry::getConfig();
86: $lang = cRegistry::getLanguageId();
87: $db = cRegistry::getDb();
88:
89: $query = 'SELECT * FROM ' . $cfg['tab']['cat_lang'] . ' AS a, ' . $cfg['tab']['cat_tree'] . ' as b WHERE (a.idcat = b.idcat) AND (a.visible = 1) AND (a.public = 1) AND (a.idlang = ' . $lang . ') ORDER BY b.idtree';
90: $db->query($query);
91:
92: $categories = array();
93: while ($db->nextRecord()) {
94: $category = array();
95: $category['idcat'] = $db->f('idcat');
96: $category['level'] = $db->f('level');
97:
98: $prefix = '';
99: for ($i = 0; $i < $db->f('level'); $i++) {
100: $prefix .= '-->';
101: }
102:
103: $category['name'] = $db->f('name');
104: $category['name_indented'] = $prefix . $db->f('name');
105:
106: $categories[] = $category;
107: }
108:
109: return $categories;
110: }
111:
112: ?><?php