1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Kernel\Handlers\XoopsModule;
13:
14: 15: 16: 17: 18: 19: 20: 21:
22:
23: class UserconfigsConfigsForm extends Xoops\Form\SimpleForm
24: {
25: 26: 27: 28: 29:
30: public function __construct($obj = null)
31: {
32: }
33:
34: 35: 36: 37:
38: public function getForm(&$obj, XoopsModule $mod)
39: {
40: $xoops = Xoops::getInstance();
41: $helper = Userconfigs::getInstance();
42: $config_handler = $helper->getHandlerConfig();
43:
44: if ($plugin = \Xoops\Module\Plugin::getPlugin($mod->getVar('dirname'), 'userconfigs')) {
45:
46: parent::__construct('', 'pref_form', 'index.php', 'post', true);
47: if ($mod->getVar('dirname') !== 'system') {
48: $xoops->loadLanguage('modinfo', $mod->getVar('dirname'));
49: $xoops->loadLocale($mod->getVar('dirname'));
50: }
51: $configs = $plugin->configs();
52: $configNames = array();
53: foreach (array_keys($configs) as $i) {
54: $configNames[$configs[$i]['name']] =& $configs[$i];
55: }
56: $configCats = $plugin->categories();
57: if (!$configCats) {
58: $configCats = array(
59: 'default' => array(
60: 'name' => _MD_USERCONFIGS_CONFIGS,
61: 'description' => ''
62: )
63: );
64: }
65:
66: if (!in_array('default', array_keys($configCats))) {
67: $configCats['default'] = array(
68: 'name' => _MD_USERCONFIGS_CONFIGS,
69: 'description' => ''
70: );
71: }
72:
73: foreach (array_keys($configNames) as $name) {
74: if (!isset($configNames[$name]['category'])) {
75: $configNames[$name]['category'] = 'default';
76: }
77: }
78:
79: $tabTray = new Xoops\Form\TabTray('', 'pref_tabtay');
80: $tabs = array();
81: foreach ($configCats as $name => $info) {
82: $tabs[$name] = new Xoops\Form\Tab($info['name'], 'pref_tab_' . $name);
83: if (isset($info['description']) && $info['description'] != '') {
84: $tabs[$name]->addElement(new Xoops\Form\Label('', $info['description']));
85: }
86: }
87: $count = count($obj);
88: for ($i = 0; $i < $count; ++$i) {
89: $title = \Xoops\Locale::translate($obj[$i]->getVar('conf_title'), $mod->getVar('dirname'));
90: $desc = ($obj[$i]->getVar('conf_desc') != '') ? \Xoops\Locale::translate($obj[$i]->getVar('conf_desc'), $mod->getVar('dirname')) : '';
91: switch ($obj[$i]->getVar('conf_formtype')) {
92:
93: case 'textarea':
94: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
95: if ($obj[$i]->getVar('conf_valuetype') === 'array') {
96:
97: $ele = ($obj[$i]->getVar('conf_value') != '') ? new Xoops\Form\TextArea($title, $obj[$i]->getVar('conf_name'), $myts->htmlSpecialChars(implode('|', $obj[$i]->getConfValueForOutput())), 5, 5) : new Xoops\Form\TextArea($title, $obj[$i]->getVar('conf_name'), '', 5, 5);
98: } else {
99: $ele = new Xoops\Form\TextArea($title, $obj[$i]->getVar('conf_name'), $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()), 5, 5);
100: }
101: break;
102:
103: case 'select':
104: $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
105: $options = $config_handler->getConfigOptions(new Criteria('conf_id', $obj[$i]->getVar('conf_id')));
106: $opcount = count($options);
107: for ($j = 0; $j < $opcount; ++$j) {
108: $optval = \Xoops\Locale::translate($options[$j]->getVar('confop_value'), $mod->getVar('dirname'));
109: $optkey = \Xoops\Locale::translate($options[$j]->getVar('confop_name'), $mod->getVar('dirname'));
110: $ele->addOption($optval, $optkey);
111: }
112: break;
113:
114: case 'select_multi':
115: $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput(), 5, true);
116: $options = $config_handler->getConfigOptions(new Criteria('conf_id', $obj[$i]->getVar('conf_id')));
117: $opcount = count($options);
118: for ($j = 0; $j < $opcount; ++$j) {
119: $optval = \Xoops\Locale::translate($options[$j]->getVar('confop_value'), $mod->getVar('dirname'));
120: $optkey = \Xoops\Locale::translate($options[$j]->getVar('confop_name'), $mod->getVar('dirname'));
121: $ele->addOption($optval, $optkey);
122: }
123: break;
124:
125: case 'yesno':
126: $ele = new Xoops\Form\RadioYesNo($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
127: break;
128:
129: case 'theme':
130: case 'theme_multi':
131: $ele = ($obj[$i]->getVar('conf_formtype') !== 'theme_multi') ? new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput()) : new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput(), 5, true);
132: $dirlist = XoopsLists::getThemesList();
133: if (!empty($dirlist)) {
134: asort($dirlist);
135: $ele->addOptionArray($dirlist);
136: }
137: break;
138: case 'tplset':
139: $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
140: $tplset_handler = $xoops->getHandlerTplSet();
141: $tplsetlist = $tplset_handler->getNameList();
142: asort($tplsetlist);
143: foreach ($tplsetlist as $key => $name) {
144: $ele->addOption($key, $name);
145: }
146: break;
147:
148: case 'cpanel':
149: $ele = new Xoops\Form\Hidden($obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
150: 151: 152: 153: 154:
155: break;
156:
157: case 'timezone':
158: $ele = new Xoops\Form\SelectTimeZone($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
159: break;
160:
161: case 'language':
162: $ele = new Xoops\Form\SelectLanguage($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
163: break;
164:
165: case 'locale':
166: $ele = new Xoops\Form\SelectLocale($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
167: break;
168:
169: case 'startpage':
170: $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
171:
172: $module_handler = $xoops->getHandlerModule();
173: $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
174: $criteria->add(new Criteria('isactive', 1));
175: $moduleslist = $module_handler->getNameList($criteria, true);
176: $moduleslist['--'] = XoopsLocale::NONE;
177: $ele->addOptionArray($moduleslist);
178: break;
179:
180: case 'group':
181: $ele = new Xoops\Form\SelectGroup($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 1, false);
182: break;
183:
184: case 'group_multi':
185: $ele = new Xoops\Form\SelectGroup($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 5, true);
186: break;
187:
188:
189: case 'user':
190: $ele = new Xoops\Form\SelectUser($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 1, false);
191: break;
192:
193: case 'user_multi':
194: $ele = new Xoops\Form\SelectUser($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 5, true);
195: break;
196: case 'module_cache':
197: $module_handler = $xoops->getHandlerModule();
198: $modules = $module_handler->getObjectsArray(new Criteria('hasmain', 1), true);
199: $currrent_val = $obj[$i]->getConfValueForOutput();
200: $cache_options = array(
201: '0' => XoopsLocale::NO_CACHE,
202: '30' => sprintf(XoopsLocale::F_SECONDS, 30),
203: '60' => XoopsLocale::ONE_MINUTE,
204: '300' => sprintf(XoopsLocale::F_MINUTES, 5),
205: '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
206: '3600' => XoopsLocale::ONE_HOUR,
207: '18000' => sprintf(XoopsLocale::F_HOURS, 5),
208: '86400' => XoopsLocale::ONE_DAY,
209: '259200' => sprintf(XoopsLocale::F_DAYS, 3),
210: '604800' => XoopsLocale::ONE_WEEK,
211: '2592000' => XoopsLocale::ONE_MONTH
212: );
213: if (count($modules) > 0) {
214: $ele = new Xoops\Form\ElementTray($title, '<br />');
215: foreach (array_keys($modules) as $mid) {
216: $c_val = isset($currrent_val[$mid]) ? (int)($currrent_val[$mid]) : null;
217: $selform = new Xoops\Form\Select($modules[$mid]->getVar('name'), $obj[$i]->getVar('conf_name') . "[$mid]", $c_val);
218: $selform->addOptionArray($cache_options);
219: $ele->addElement($selform);
220: unset($selform);
221: }
222: } else {
223: $ele = new Xoops\Form\Label($title, SystemLocale::NO_MODULE_TO_CACHE);
224: }
225: break;
226:
227: case 'site_cache':
228: $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
229: $ele->addOptionArray(array(
230: '0' => XoopsLocale::NO_CACHE,
231: '30' => sprintf(XoopsLocale::F_SECONDS, 30),
232: '60' => XoopsLocale::ONE_MINUTE,
233: '300' => sprintf(XoopsLocale::F_MINUTES, 5),
234: '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
235: '3600' => XoopsLocale::ONE_HOUR,
236: '18000' => sprintf(XoopsLocale::F_HOURS, 5),
237: '86400' => XoopsLocale::ONE_DAY,
238: '259200' => sprintf(XoopsLocale::F_DAYS, 3),
239: '604800' => XoopsLocale::ONE_WEEK,
240: '2592000' => XoopsLocale::ONE_MONTH
241: ));
242: break;
243:
244: case 'password':
245: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
246: $ele = new Xoops\Form\Password($title, $obj[$i]->getVar('conf_name'), 32, 255, $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()));
247: break;
248:
249: case 'color':
250: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
251: $ele = new Xoops\Form\ColorPicker($title, $obj[$i]->getVar('conf_name'), $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()));
252: break;
253:
254: case 'hidden':
255: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
256: $ele = new Xoops\Form\Hidden($obj[$i]->getVar('conf_name'), $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()));
257: break;
258:
259: case 'textbox':
260: default:
261: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
262: $ele = new Xoops\Form\Text($title, $obj[$i]->getVar('conf_name'), 5, 255, $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()));
263: break;
264: }
265: $hidden = new Xoops\Form\Hidden('conf_ids[]', $obj[$i]->getVar('conf_id'));
266: if (isset($ele)) {
267: $ele->setDescription($desc);
268: if ($obj[$i]->getVar('conf_formtype') !== 'hidden') {
269: $name = 'default';
270: if (isset($configNames[$obj[$i]->getVar('conf_name')]['category'])) {
271: $name = $configNames[$obj[$i]->getVar('conf_name')]['category'];
272: }
273: $tabs[$name]->addElement($ele);
274: } else {
275: $this->addElement($ele);
276: }
277: $this->addElement($hidden);
278: unset($ele);
279: unset($hidden);
280: }
281: }
282: foreach (array_keys($tabs) as $name) {
283: if ($tabs[$name]->getElements()) {
284: $tabTray->addElement($tabs[$name]);
285: }
286: }
287: $this->addElement($tabTray);
288: $this->addElement(new Xoops\Form\Hidden('op', 'save'));
289: $this->addElement(new Xoops\Form\Hidden('mid', $mod->getVar('mid')));
290: $this->addElement(new Xoops\Form\Button('', 'button', XoopsLocale::A_SUBMIT, 'submit'));
291: }
292: }
293: }
294: