XOOPS  2.6.0
preferences.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 
14 
28 {
34  public function __construct($obj = null)
35  {
36  }
37 
46  public function getForm(&$obj, XoopsModule &$mod)
47  {
49  $config_handler = $xoops->getHandlerConfig();
50 
51  parent::__construct('', 'pref_form', 'admin.php?fct=preferences', 'post', true);
52  if ($mod->getVar('dirname') != 'system') {
53  $xoops->loadLanguage('modinfo', $mod->getVar('dirname'));
54  }
55  $xoops->loadLocale($mod->getVar('dirname'));
56  $configs = $mod->getInfo('config');
57  $configNames = array();
58  foreach (array_keys($configs) as $i) {
59  $configNames[$configs[$i]['name']] =& $configs[$i];
60  }
61  $configCats = $mod->getInfo('configcat');
62  if (!$configCats) {
63  $configCats = array(
64  'default' => array(
66  'description' => ''
67  )
68  );
69  }
70 
71  if (!in_array('default', array_keys($configCats))) {
72  $configCats['default'] = array(
74  'description' => ''
75  );
76  }
77 
78  foreach (array_keys($configNames) as $name) {
79  if (!isset($configNames[$name]['category'])) {
80  $configNames[$name]['category'] = 'default';
81  }
82  }
83 
84  $tabtray = new Xoops\Form\TabTray('', 'pref_tabtay', $xoops->getModuleConfig('jquery_theme', 'system'));
85  $tabs = array();
86  foreach ($configCats as $name => $info) {
87  $tabs[$name] = new Xoops\Form\Tab($info['name'], 'pref_tab_' . $name);
88  if (isset($info['description']) && $info['description'] != '') {
89  $tabs[$name]->addElement(new Xoops\Form\Label('', $info['description']));
90  }
91  }
92 
93  $xoops->preload()->triggerEvent('onSystemPreferencesForm', array($mod));
94 
95  if (!empty($_REQUEST["redirect"])) {
97  $this->addElement(new Xoops\Form\Hidden('redirect', $myts->htmlspecialchars($_REQUEST["redirect"])));
98  } elseif ($mod->getInfo('adminindex')) {
99  $this->addElement(new Xoops\Form\Hidden(
100  'redirect',
101  \XoopsBaseConfig::get('url') . '/modules/' . $mod->getVar('dirname') . '/' . $mod->getInfo('adminindex')
102  ));
103  }
104  $count = count($obj);
105  for ($i = 0; $i < $count; ++$i) {
106  $title = Xoops_Locale::translate($obj[$i]->getVar('conf_title'), $mod->getVar('dirname'));
107  $desc = ($obj[$i]->getVar('conf_desc') != '') ?
108  Xoops_Locale::translate($obj[$i]->getVar('conf_desc'), $mod->getVar('dirname')) : '';
109  switch ($obj[$i]->getVar('conf_formtype')) {
110 
111  case 'textarea':
113  if ($obj[$i]->getVar('conf_valuetype') == 'array') {
114  // this is exceptional.. only when value type is arrayneed a smarter way for this
115  $ele = ($obj[$i]->getVar('conf_value') != '')
116  ? new Xoops\Form\TextArea(
117  $title,
118  $obj[$i]->getVar('conf_name'),
119  $myts->htmlspecialchars(implode('|', $obj[$i]->getConfValueForOutput())),
120  5,
121  5
122  )
123  : new Xoops\Form\TextArea($title, $obj[$i]->getVar('conf_name'), '', 5, 5);
124  } else {
125  $ele = new Xoops\Form\TextArea(
126  $title,
127  $obj[$i]->getVar('conf_name'),
128  $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()),
129  5,
130  5
131  );
132  }
133  break;
134 
135  case 'select':
136  $ele = new Xoops\Form\Select(
137  $title,
138  $obj[$i]->getVar('conf_name'),
139  $obj[$i]->getConfValueForOutput()
140  );
141  $options = $config_handler->getConfigOptions(new Criteria('conf_id', $obj[$i]->getVar('conf_id')));
142  $opcount = count($options);
143  for ($j = 0; $j < $opcount; ++$j) {
144  $optval = Xoops_Locale::translate($options[$j]->getVar('confop_value'), $mod->getVar('dirname'));
145  $optkey = Xoops_Locale::translate($options[$j]->getVar('confop_name'), $mod->getVar('dirname'));
146  $ele->addOption($optval, $optkey);
147  }
148  break;
149 
150  case 'select_multi':
151  $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput(), 5, true);
152  $options = $config_handler->getConfigOptions(new Criteria('conf_id', $obj[$i]->getVar('conf_id')));
153  $opcount = count($options);
154  for ($j = 0; $j < $opcount; ++$j) {
155  $optval = Xoops_Locale::translate($options[$j]->getVar('confop_value'), $mod->getVar('dirname'));
156  $optkey = Xoops_Locale::translate($options[$j]->getVar('confop_name'), $mod->getVar('dirname'));
157  $ele->addOption($optval, $optkey);
158  }
159  break;
160 
161  case 'yesno':
162  $ele = new Xoops\Form\RadioYesNo($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
163  break;
164 
165  case 'theme':
166  case 'theme_multi':
167  $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);
168  $dirlist = XoopsLists::getThemesList();
169  if (!empty($dirlist)) {
170  asort($dirlist);
171  $ele->addOptionArray($dirlist);
172  }
173  break;
174  case 'tplset':
175  $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
176  $tplset_handler = $xoops->getHandlerTplset();
177  $tplsetlist = $tplset_handler->getNameList();
178  asort($tplsetlist);
179  foreach ($tplsetlist as $key => $name) {
180  $ele->addOption($key, $name);
181  }
182  break;
183 
184  case 'cpanel':
185  $ele = new Xoops\Form\Hidden($obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
186  /*
187  $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
188  XoopsLoad::load("cpanel", "system");
189  $list = XoopsSystemCpanel::getGuis();
190  $ele->addOptionArray($list); */
191  break;
192 
193  case 'timezone':
194  $ele = new Xoops\Form\SelectTimeZone($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
195  break;
196 
197  case 'language':
198  $ele = new Xoops\Form\SelectLanguage($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
199  break;
200 
201  case 'locale':
202  $ele = new Xoops\Form\SelectLocale($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
203  break;
204 
205  case 'startpage':
206  $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
207 
208  $module_handler = $xoops->getHandlerModule();
209  $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
210  $criteria->add(new Criteria('isactive', 1));
211  $moduleslist = $module_handler->getNameList($criteria, true);
212  $moduleslist['--'] = XoopsLocale::NONE;
213  $ele->addOptionArray($moduleslist);
214  break;
215 
216  case 'group':
217  $ele = new Xoops\Form\SelectGroup($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 1, false);
218  break;
219 
220  case 'group_multi':
221  $ele = new Xoops\Form\SelectGroup($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 5, true);
222  break;
223 
224  // RMV-NOTIFY: added 'user' and 'user_multi'
225  case 'user':
226  $ele = new Xoops\Form\SelectUser($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 1, false);
227  break;
228 
229  case 'user_multi':
230  $ele = new Xoops\Form\SelectUser($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 5, true);
231  break;
232  case 'module_cache':
233  $module_handler = $xoops->getHandlerModule();
234  $modules = $module_handler->getObjectsArray(new Criteria('hasmain', 1), true);
235  $currrent_val = $obj[$i]->getConfValueForOutput();
236  $cache_options = array(
237  '0' => XoopsLocale::NO_CACHE,
238  '30' => sprintf(XoopsLocale::F_SECONDS, 30),
239  '60' => XoopsLocale::ONE_MINUTE,
240  '300' => sprintf(XoopsLocale::F_MINUTES, 5),
241  '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
242  '3600' => XoopsLocale::ONE_HOUR,
243  '18000' => sprintf(XoopsLocale::F_HOURS, 5),
244  '86400' => XoopsLocale::ONE_DAY,
245  '259200' => sprintf(XoopsLocale::F_DAYS, 3),
246  '604800' => XoopsLocale::ONE_WEEK,
247  '2592000' => XoopsLocale::ONE_MONTH
248  );
249  if (count($modules) > 0) {
250  $ele = new Xoops\Form\ElementTray($title, '<br />');
251  foreach (array_keys($modules) as $mid) {
252  $c_val = isset($currrent_val[$mid]) ? intval($currrent_val[$mid]) : null;
253  $selform = new Xoops\Form\Select($modules[$mid]->getVar('name'), $obj[$i]->getVar('conf_name') . "[$mid]", $c_val);
254  $selform->addOptionArray($cache_options);
255  $ele->addElement($selform);
256  unset($selform);
257  }
258  } else {
260  }
261  break;
262 
263  case 'site_cache':
264  $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
265  $ele->addOptionArray(array(
266  '0' => XoopsLocale::NO_CACHE,
267  '30' => sprintf(XoopsLocale::F_SECONDS, 30),
268  '60' => XoopsLocale::ONE_MINUTE,
269  '300' => sprintf(XoopsLocale::F_MINUTES, 5),
270  '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
271  '3600' => XoopsLocale::ONE_HOUR,
272  '18000' => sprintf(XoopsLocale::F_HOURS, 5),
273  '86400' => XoopsLocale::ONE_DAY,
274  '259200' => sprintf(XoopsLocale::F_DAYS, 3),
275  '604800' => XoopsLocale::ONE_WEEK,
276  '2592000' => XoopsLocale::ONE_MONTH
277  ));
278  break;
279 
280  case 'password':
282  $ele = new Xoops\Form\Password($title, $obj[$i]->getVar('conf_name'), 5, 255, $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()));
283  break;
284 
285  case 'color':
287  $ele = new Xoops\Form\ColorPicker($title, $obj[$i]->getVar('conf_name'), $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()));
288  break;
289 
290  case 'hidden':
292  $ele = new Xoops\Form\Hidden($obj[$i]->getVar('conf_name'), $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()));
293  break;
294 
295  case 'textbox':
296  default:
298  $ele = new Xoops\Form\Text($title, $obj[$i]->getVar('conf_name'), 5, 255, $myts->htmlspecialchars($obj[$i]->getConfValueForOutput()));
299  break;
300  }
301  $hidden = new Xoops\Form\Hidden('conf_ids[]', $obj[$i]->getVar('conf_id'));
302  if (isset($ele)) {
303  $ele->setDescription($desc);
304  if ($obj[$i]->getVar('conf_formtype') != 'hidden') {
305  $name = 'default';
306  if (isset($configNames[$obj[$i]->getVar('conf_name')]['category'])) {
307  $name = $configNames[$obj[$i]->getVar('conf_name')]['category'];
308  }
309  $tabs[$name]->addElement($ele);
310  } else {
311  $this->addElement($ele);
312  }
313  $this->addElement($hidden);
314  unset($ele);
315  unset($hidden);
316  }
317  }
318  foreach (array_keys($tabs) as $name) {
319  if ($tabs[$name]->getElements()) {
320  $tabtray->addElement($tabs[$name]);
321  }
322  }
323  $this->addElement($tabtray);
324  $this->addElement(new Xoops\Form\Hidden('op', 'save'));
325  $this->addElement(new Xoops\Form\Button('', 'button', XoopsLocale::A_SUBMIT, 'submit'));
326  }
327 }
const ONE_MINUTE
Definition: en_US.php:880
$mid
Definition: index.php:39
const ONE_DAY
Definition: en_US.php:878
__construct($obj=null)
Definition: preferences.php:34
const A_SUBMIT
Definition: en_US.php:128
const OTHER_SETTINGS
Definition: en_US.php:357
$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
getInfo($name=null)
Definition: module.php:153
const ONE_MONTH
Definition: en_US.php:881
getVar($key, $format= 's')
const NO_MODULE_TO_CACHE
Definition: en_US.php:350
$xoops
Definition: admin.php:25
getForm(&$obj, XoopsModule &$mod)
Definition: preferences.php:46
const F_DAYS
Definition: en_US.php:405
if($_SERVER['REQUEST_METHOD']== 'POST') $config_handler
static get($name)
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
static translate($key, $dirname= 'xoops')
Definition: Locale.php:128
$criteria
$module_handler
Definition: main.php:55
$myts
Definition: edituser.php:38
$j
Definition: help.php:169
const F_HOURS
Definition: en_US.php:413
const NO_CACHE
Definition: en_US.php:862