XOOPS  2.6.0
configs.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
22 {
28  public function __construct($obj = null)
29  {
30  }
31 
36  public function getForm(&$obj, XoopsModule $mod)
37  {
40  $config_handler = $helper->getHandlerConfig();
41  /* @var $plugin UserconfigsPluginInterface */
42  if ($plugin = \Xoops\Module\Plugin::getPlugin($mod->getVar('dirname'), 'userconfigs')) {
43 
44  parent::__construct('', 'pref_form', 'index.php', 'post', true);
45  if ($mod->getVar('dirname') != 'system') {
46  $xoops->loadLanguage('modinfo', $mod->getVar('dirname'));
47  $xoops->loadLocale($mod->getVar('dirname'));
48  }
49  $configs = $plugin->configs();
50  $configNames = array();
51  foreach (array_keys($configs) as $i) {
52  $configNames[$configs[$i]['name']] =& $configs[$i];
53  }
54  $configCats = $plugin->categories();
55  if (!$configCats) {
56  $configCats = array(
57  'default' => array(
58  'name' => _MD_USERCONFIGS_CONFIGS,
59  'description' => ''
60  )
61  );
62  }
63 
64  if (!in_array('default', array_keys($configCats))) {
65  $configCats['default'] = array(
66  'name' => _MD_USERCONFIGS_CONFIGS,
67  'description' => ''
68  );
69  }
70 
71  foreach (array_keys($configNames) as $name) {
72  if (!isset($configNames[$name]['category'])) {
73  $configNames[$name]['category'] = 'default';
74  }
75  }
76 
77  $tabtray = new Xoops\Form\TabTray('', 'pref_tabtay', $xoops->getModuleConfig('jquery_theme', 'system'));
78  $tabs = array();
79  foreach ($configCats as $name => $info) {
80  $tabs[$name] = new Xoops\Form\Tab($info['name'], 'pref_tab_' . $name);
81  if (isset($info['description']) && $info['description'] != '') {
82  $tabs[$name]->addElement(new Xoops\Form\Label('', $info['description']));
83  }
84  }
85  $count = count($obj);
86  for ($i = 0; $i < $count; ++$i) {
87  $title = Xoops_Locale::translate($obj[$i]->getVar('conf_title'), $mod->getVar('dirname'));
88  $desc = ($obj[$i]->getVar('conf_desc') != '') ? Xoops_Locale::translate($obj[$i]->getVar('conf_desc'), $mod->getVar('dirname')) : '';
89  switch ($obj[$i]->getVar('conf_formtype')) {
90 
91  case 'textarea':
93  if ($obj[$i]->getVar('conf_valuetype') == 'array') {
94  // this is exceptional.. only when value type is arrayneed a smarter way for this
95  $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);
96  } else {
97  $ele = new Xoops\Form\TextArea($title, $obj[$i]->getVar('conf_name'), $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()), 5, 5);
98  }
99  break;
100 
101  case 'select':
102  $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
103  $options = $config_handler->getConfigOptions(new Criteria('conf_id', $obj[$i]->getVar('conf_id')));
104  $opcount = count($options);
105  for ($j = 0; $j < $opcount; ++$j) {
106  $optval = Xoops_Locale::translate($options[$j]->getVar('confop_value'), $mod->getVar('dirname'));
107  $optkey = Xoops_Locale::translate($options[$j]->getVar('confop_name'), $mod->getVar('dirname'));
108  $ele->addOption($optval, $optkey);
109  }
110  break;
111 
112  case 'select_multi':
113  $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput(), 5, true);
114  $options = $config_handler->getConfigOptions(new Criteria('conf_id', $obj[$i]->getVar('conf_id')));
115  $opcount = count($options);
116  for ($j = 0; $j < $opcount; ++$j) {
117  $optval = Xoops_Locale::translate($options[$j]->getVar('confop_value'), $mod->getVar('dirname'));
118  $optkey = Xoops_Locale::translate($options[$j]->getVar('confop_name'), $mod->getVar('dirname'));
119  $ele->addOption($optval, $optkey);
120  }
121  break;
122 
123  case 'yesno':
124  $ele = new Xoops\Form\RadioYesNo($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
125  break;
126 
127  case 'theme':
128  case 'theme_multi':
129  $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);
130  $dirlist = XoopsLists::getThemesList();
131  if (!empty($dirlist)) {
132  asort($dirlist);
133  $ele->addOptionArray($dirlist);
134  }
135  break;
136  case 'tplset':
137  $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
138  $tplset_handler = $xoops->getHandlerTplset();
139  $tplsetlist = $tplset_handler->getNameList();
140  asort($tplsetlist);
141  foreach ($tplsetlist as $key => $name) {
142  $ele->addOption($key, $name);
143  }
144  break;
145 
146  case 'cpanel':
147  $ele = new Xoops\Form\Hidden($obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
148  /*
149  $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
150  XoopsLoad::load("cpanel", "system");
151  $list = XoopsSystemCpanel::getGuis();
152  $ele->addOptionArray($list); */
153  break;
154 
155  case 'timezone':
156  $ele = new Xoops\Form\SelectTimeZone($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
157  break;
158 
159  case 'language':
160  $ele = new Xoops\Form\SelectLanguage($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
161  break;
162 
163  case 'locale':
164  $ele = new Xoops\Form\SelectLocale($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
165  break;
166 
167  case 'startpage':
168  $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
169 
170  $module_handler = $xoops->getHandlerModule();
171  $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
172  $criteria->add(new Criteria('isactive', 1));
173  $moduleslist = $module_handler->getNameList($criteria, true);
174  $moduleslist['--'] = XoopsLocale::NONE;
175  $ele->addOptionArray($moduleslist);
176  break;
177 
178  case 'group':
179  $ele = new Xoops\Form\SelectGroup($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 1, false);
180  break;
181 
182  case 'group_multi':
183  $ele = new Xoops\Form\SelectGroup($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 5, true);
184  break;
185 
186  // RMV-NOTIFY: added 'user' and 'user_multi'
187  case 'user':
188  $ele = new Xoops\Form\SelectUser($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 1, false);
189  break;
190 
191  case 'user_multi':
192  $ele = new Xoops\Form\SelectUser($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 5, true);
193  break;
194  case 'module_cache':
195  $module_handler = $xoops->getHandlerModule();
196  $modules = $module_handler->getObjectsArray(new Criteria('hasmain', 1), true);
197  $currrent_val = $obj[$i]->getConfValueForOutput();
198  $cache_options = array(
199  '0' => XoopsLocale::NO_CACHE,
200  '30' => sprintf(XoopsLocale::F_SECONDS, 30),
201  '60' => XoopsLocale::ONE_MINUTE,
202  '300' => sprintf(XoopsLocale::F_MINUTES, 5),
203  '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
204  '3600' => XoopsLocale::ONE_HOUR,
205  '18000' => sprintf(XoopsLocale::F_HOURS, 5),
206  '86400' => XoopsLocale::ONE_DAY,
207  '259200' => sprintf(XoopsLocale::F_DAYS, 3),
208  '604800' => XoopsLocale::ONE_WEEK,
209  '2592000' => XoopsLocale::ONE_MONTH
210  );
211  if (count($modules) > 0) {
212  $ele = new Xoops\Form\ElementTray($title, '<br />');
213  foreach (array_keys($modules) as $mid) {
214  $c_val = isset($currrent_val[$mid]) ? intval($currrent_val[$mid]) : null;
215  $selform = new Xoops\Form\Select($modules[$mid]->getVar('name'), $obj[$i]->getVar('conf_name') . "[$mid]", $c_val);
216  $selform->addOptionArray($cache_options);
217  $ele->addElement($selform);
218  unset($selform);
219  }
220  } else {
222  }
223  break;
224 
225  case 'site_cache':
226  $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
227  $ele->addOptionArray(array(
228  '0' => XoopsLocale::NO_CACHE,
229  '30' => sprintf(XoopsLocale::F_SECONDS, 30),
230  '60' => XoopsLocale::ONE_MINUTE,
231  '300' => sprintf(XoopsLocale::F_MINUTES, 5),
232  '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
233  '3600' => XoopsLocale::ONE_HOUR,
234  '18000' => sprintf(XoopsLocale::F_HOURS, 5),
235  '86400' => XoopsLocale::ONE_DAY,
236  '259200' => sprintf(XoopsLocale::F_DAYS, 3),
237  '604800' => XoopsLocale::ONE_WEEK,
238  '2592000' => XoopsLocale::ONE_MONTH
239  ));
240  break;
241 
242  case 'password':
244  $ele = new Xoops\Form\Password($title, $obj[$i]->getVar('conf_name'), 5, 255, $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()));
245  break;
246 
247  case 'color':
249  $ele = new Xoops\Form\ColorPicker($title, $obj[$i]->getVar('conf_name'), $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()));
250  break;
251 
252  case 'hidden':
254  $ele = new Xoops\Form\Hidden($obj[$i]->getVar('conf_name'), $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()));
255  break;
256 
257  case 'textbox':
258  default:
260  $ele = new Xoops\Form\Text($title, $obj[$i]->getVar('conf_name'), 5, 255, $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()));
261  break;
262  }
263  $hidden = new Xoops\Form\Hidden('conf_ids[]', $obj[$i]->getVar('conf_id'));
264  if (isset($ele)) {
265  $ele->setDescription($desc);
266  if ($obj[$i]->getVar('conf_formtype') != 'hidden') {
267  $name = 'default';
268  if (isset($configNames[$obj[$i]->getVar('conf_name')]['category'])) {
269  $name = $configNames[$obj[$i]->getVar('conf_name')]['category'];
270  }
271  $tabs[$name]->addElement($ele);
272  } else {
273  $this->addElement($ele);
274  }
275  $this->addElement($hidden);
276  unset($ele);
277  unset($hidden);
278  }
279  }
280  foreach (array_keys($tabs) as $name) {
281  if ($tabs[$name]->getElements()) {
282  $tabtray->addElement($tabs[$name]);
283  }
284  }
285  $this->addElement($tabtray);
286  $this->addElement(new Xoops\Form\Hidden('op', 'save'));
287  $this->addElement(new Xoops\Form\Hidden('mid', $mod->getVar('mid')));
288  $this->addElement(new Xoops\Form\Button('', 'button', XoopsLocale::A_SUBMIT, 'submit'));
289  }
290  }
291 }
const ONE_MINUTE
Definition: en_US.php:880
$mid
Definition: index.php:39
const ONE_DAY
Definition: en_US.php:878
const A_SUBMIT
Definition: en_US.php:128
$i
Definition: dialog.php:68
const F_SECONDS
Definition: en_US.php:437
static getInstance()
Definition: Xoops.php:160
addElement(Element $formElement, $required=false)
Definition: Form.php:206
$options['editor']
const ONE_WEEK
Definition: en_US.php:883
static getInstance()
Definition: helper.php:36
getForm(&$obj, XoopsModule $mod)
Definition: configs.php:36
const ONE_MONTH
Definition: en_US.php:881
__construct($obj=null)
Definition: configs.php:28
getVar($key, $format= 's')
const NO_MODULE_TO_CACHE
Definition: en_US.php:350
$xoops
Definition: admin.php:25
const F_DAYS
Definition: en_US.php:405
if($_SERVER['REQUEST_METHOD']== 'POST') $config_handler
if(isset($_POST['name'])) $info
Definition: execute.php:57
const F_MINUTES
Definition: en_US.php:426
$configs
Definition: config.php:27
const ONE_HOUR
Definition: en_US.php:879
getElements($recurse=false)
Definition: Form.php:232
$modules
Definition: userinfo.php:185
$helper
static translate($key, $dirname= 'xoops')
Definition: Locale.php:128
$criteria
$module_handler
Definition: main.php:55
$myts
Definition: edituser.php:38
const _MD_USERCONFIGS_CONFIGS
Definition: main.php:24
$j
Definition: help.php:169
const F_HOURS
Definition: en_US.php:413
const NO_CACHE
Definition: en_US.php:862