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