XOOPS  2.6.0
createconfigform.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 
25 defined('XOOPS_INSTALL') or die('XOOPS Custom Installation die');
26 
33 {
35  $config_handler = $xoops->getHandlerConfig();
36  //$xoops->config = $config_handler->getConfigsByCat(XOOPS_CONF);
37  //$config =& $xoops->config;
38 
39  $ret = array();
40  $confcount = count($config);
41 
42  for ($i = 0; $i < $confcount; ++$i) {
43  $conf_catid = $config[$i]->getVar('conf_catid');
44  if (!isset($ret[$conf_catid])) {
45  $ret[$conf_catid] = new Xoops\Form\ThemeForm('', 'configs', 'index.php', 'post');
46  }
47 
48  $title = Xoops_Locale::translate($config[$i]->getVar('conf_title'), 'system');
49 
50  switch ($config[$i]->getVar('conf_formtype')) {
51 
52  case 'textarea':
54  if ($config[$i]->getVar('conf_valuetype') == 'array') {
55  // this is exceptional.. only when value type is arrayneed a smarter way for this
56  $ele = ($config[$i]->getVar('conf_value') != '') ? new Xoops\Form\TextArea($title, $config[$i]->getVar('conf_name'), $myts->htmlspecialchars(implode('|', $config[$i]->getConfValueForOutput())), 5, 50) : new Xoops\Form\TextArea($title, $config[$i]->getVar('conf_name'), '', 5, 50);
57  } else {
58  $ele = new Xoops\Form\TextArea($title, $config[$i]->getVar('conf_name'), $myts->htmlspecialchars($config[$i]->getConfValueForOutput()), 5, 100);
59  }
60  break;
61 
62  case 'select':
63  $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
64  $options =& $config_handler->getConfigOptions(new Criteria('conf_id', $config[$i]->getVar('conf_id')));
65  $opcount = count($options);
66  for ($j = 0; $j < $opcount; ++$j) {
67  $optval = Xoops_Locale::translate($options[$j]->getVar('confop_value'), 'system');
68  $optkey = Xoops_Locale::translate($options[$j]->getVar('confop_name'), 'system');
69  $ele->addOption($optval, $optkey);
70  }
71  break;
72 
73  case 'select_multi':
74  $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), 5, true);
75  $options =& $config_handler->getConfigOptions(new Criteria('conf_id', $config[$i]->getVar('conf_id')));
76  $opcount = count($options);
77  for ($j = 0; $j < $opcount; ++$j) {
78  $optval = Xoops_Locale::translate($options[$j]->getVar('confop_value'), 'system');
79  $optkey = Xoops_Locale::translate($options[$j]->getVar('confop_name'), 'system');
80  $ele->addOption($optval, $optkey);
81  }
82  break;
83 
84  case 'yesno':
85  $ele = new Xoops\Form\RadioYesNo($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), XoopsLocale::YES, XoopsLocale::NO);
86  break;
87 
88  case 'theme':
89  case 'theme_multi':
90  $ele = ($config[$i]->getVar('conf_formtype') != 'theme_multi')
91  ? new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput())
92  : new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), 5, true);
93  $dirlist = XoopsLists::getThemesList();
94  if (!empty($dirlist)) {
95  asort($dirlist);
96  $ele->addOptionArray($dirlist);
97  }
98  break;
99 
100  case 'tplset':
101  $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
102  $tplset_handler = $xoops->getHandlerTplset();
103  $tplsetlist = $tplset_handler->getNameList();
104  asort($tplsetlist);
105  foreach ($tplsetlist as $key => $name) {
106  $ele->addOption($key, $name);
107  }
108  break;
109 
110  case 'timezone':
111  $ele = new Xoops\Form\SelectTimeZone($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
112  break;
113 
114  case 'language':
115  $ele = new Xoops\Form\SelectLanguage($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
116  break;
117 
118  case 'locale':
119  $ele = new Xoops\Form\SelectLocale($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
120  break;
121 
122  case 'startpage':
123  $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
124  $module_handler = $xoops->getHandlerModule();
125  $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
126  $criteria->add(new Criteria('isactive', 1));
127  $moduleslist =& $module_handler->getNameList($criteria, true);
128  $moduleslist['--'] = XoopsLocale::NONE;
129  $ele->addOptionArray($moduleslist);
130  break;
131 
132  case 'group':
133  $ele = new Xoops\Form\SelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false);
134  break;
135 
136  case 'group_multi':
137  $ele = new Xoops\Form\SelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true);
138  break;
139 
140  // RMV-NOTIFY - added 'user' and 'user_multi'
141  case 'user':
142  $ele = new Xoops\Form\SelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false);
143  break;
144 
145  case 'user_multi':
146  $ele = new Xoops\Form\SelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true);
147  break;
148 
149  case 'module_cache':
150  $module_handler = $xoops->getHandlerModule();
151  $modules = $module_handler->getObjectsArray(new Criteria('hasmain', 1), true);
152  $currrent_val = $config[$i]->getConfValueForOutput();
153  $cache_options = array(
154  '0' => XoopsLocale::NO_CACHE,
155  '30' => sprintf(XoopsLocale::F_SECONDS, 30),
156  '60' => XoopsLocale::ONE_MINUTE,
157  '300' => sprintf(XoopsLocale::F_MINUTES, 5),
158  '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
159  '3600' => XoopsLocale::ONE_HOUR,
160  '18000' => sprintf(XoopsLocale::F_HOURS, 5),
161  '86400' => XoopsLocale::ONE_DAY,
162  '259200' => sprintf(XoopsLocale::F_DAYS, 3),
163  '604800' => XoopsLocale::ONE_WEEK,
164  '2592000' => XoopsLocale::ONE_MONTH
165  );
166  if (count($modules) > 0) {
167  $ele = new Xoops\Form\ElementTray($title, '<br />');
168  foreach (array_keys($modules) as $mid) {
169  $c_val = isset($currrent_val[$mid]) ? intval($currrent_val[$mid]) : null;
170  $selform = new Xoops\Form\Select($modules[$mid]->getVar('name'), $config[$i]->getVar('conf_name') . "[$mid]", $c_val);
171  $selform->addOptionArray($cache_options);
172  $ele->addElement($selform);
173  unset($selform);
174  }
175  } else {
177  }
178  break;
179 
180  case 'site_cache':
181  $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
182  $ele->addOptionArray(array(
183  '0' => XoopsLocale::NO_CACHE,
184  '30' => sprintf(XoopsLocale::F_SECONDS, 30),
185  '60' => XoopsLocale::ONE_MINUTE,
186  '300' => sprintf(XoopsLocale::F_MINUTES, 5),
187  '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
188  '3600' => XoopsLocale::ONE_HOUR,
189  '18000' => sprintf(XoopsLocale::F_HOURS, 5),
190  '86400' => XoopsLocale::ONE_DAY,
191  '259200' => sprintf(XoopsLocale::F_DAYS, 3),
192  '604800' => XoopsLocale::ONE_WEEK,
193  '2592000' => XoopsLocale::ONE_MONTH
194  ));
195  break;
196 
197  case 'password':
199  $ele = new Xoops\Form\Password($title, $config[$i]->getVar('conf_name'), 50, 255, $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
200  break;
201 
202  case 'color':
204  $ele = new Xoops\Form\ColorPicker($title, $config[$i]->getVar('conf_name'), $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
205  break;
206 
207  case 'hidden':
209  $ele = new Xoops\Form\Hidden($config[$i]->getVar('conf_name'), $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
210  break;
211 
212  case 'textbox':
213  default:
215  $ele = new Xoops\Form\Text($title, $config[$i]->getVar('conf_name'), 50, 255, $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
216  break;
217  }
218 
219  if ($config[$i]->getVar('conf_desc') != '') {
220  $ele->setDescription(Xoops_Locale::translate($config[$i]->getVar('conf_desc'), 'system'));
221  }
222  $ret[$conf_catid]->addElement($ele);
223 
224  $hidden = new Xoops\Form\Hidden('conf_ids[]', $config[$i]->getVar('conf_id'));
225  $ret[$conf_catid]->addElement($hidden);
226 
227  unset($ele);
228  unset($hidden);
229  }
230  return $ret;
231 }
232 
239 {
240  $title = $config->getVar('conf_desc') == '' ? Xoops_Locale::translate($config->getVar('conf_title'), 'system') : Xoops_Locale::translate($config->getVar('conf_title'), 'system') . '<br /><br /><span>' . Xoops_Locale::translate($config->getVar('conf_desc'), 'system') . '</span>';
241  $form_theme_set = new Xoops\Form\Select('', $config->getVar('conf_name'), $config->getConfValueForOutput(), 1, false);
242  $dirlist = XoopsLists::getThemesList();
243  if (!empty($dirlist)) {
244  asort($dirlist);
245  $form_theme_set->addOptionArray($dirlist);
246  }
247 
248  $label_content = "";
249 
250  // read ini file for each theme
251  foreach ($dirlist as $theme) {
252  // set default value
253  $theme_ini = array(
254  'Name' => $theme,
255  'Description' => '',
256  'Version' => '',
257  'Format' => '',
258  'Author' => '',
259  'Demo' => '',
260  'Url' => '',
261  'Download' => '',
262  'W3C' => '',
263  'Licence' => '',
264  'thumbnail' => 'screenshot.gif',
265  'screenshot' => 'screenshot.png',
266  );
267 
268  if ($theme == $config->getConfValueForOutput()) {
269  $label_content .= "<div id='$theme' rel='theme' style='display:block;'>";
270  } else {
271  $label_content .= "<div id='$theme' rel='theme' style='display:none;'>";
272  }
273  if (file_exists(XOOPS_ROOT_PATH . "/themes/$theme/theme.ini")) {
274  $theme_ini = parse_ini_file(XOOPS_ROOT_PATH . "/themes/$theme/theme.ini");
275  if ($theme_ini['screenshot'] == '') {
276  $theme_ini['screenshot'] = 'screenshot.png';
277  $theme_ini['thumbnail'] = 'thumbnail.png';
278  }
279  }
280 
281  if ($theme_ini['screenshot'] != '' && file_exists(XOOPS_ROOT_PATH . "/themes/$theme/" . $theme_ini['screenshot'])) {
282  $label_content .= "<img src='" . XOOPS_URL . "/themes/" . $theme . "/" . $theme_ini['screenshot'] . "' alt='Screenshot' />";
283  } elseif ($theme_ini['thumbnail'] != '' && file_exists(XOOPS_ROOT_PATH . "/themes/$theme/" . $theme_ini['thumbnail'])) {
284  $label_content .= "<img src='" . XOOPS_URL . "/themes/" . $theme . "/" . $theme_ini['thumbnail'] . "' alt='$theme' />";
285  } else {
286  $label_content .= THEME_NO_SCREENSHOT;
287  }
288  $label_content .= "</div>";
289  }
290  // read ini file for each theme
291 
292  $form_theme_set->setExtra("onchange='showThemeSelected(this)'");
293 
294  $form = new Xoops\Form\ThemeForm($title, 'themes', 'index.php', 'post');
295  $form->addElement($form_theme_set);
296  $form->addElement(new Xoops\Form\Label('', "<div id='screenshot'>" . $label_content . "</div>"));
297 
298  $form->addElement(new Xoops\Form\Hidden('conf_ids[]', $config->getVar('conf_id')));
299  return array($form);
300 }
const ONE_MINUTE
Definition: en_US.php:880
$mid
Definition: index.php:39
const ONE_DAY
Definition: en_US.php:878
createConfigform($config)
$i
Definition: dialog.php:68
const F_SECONDS
Definition: en_US.php:437
static getInstance()
Definition: Xoops.php:160
$options['editor']
const ONE_WEEK
Definition: en_US.php:883
$form
Definition: xoops_code.php:21
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
const F_DAYS
Definition: en_US.php:405
if($_SERVER['REQUEST_METHOD']== 'POST') $config_handler
const F_MINUTES
Definition: en_US.php:426
const ONE_HOUR
Definition: en_US.php:879
$modules
Definition: userinfo.php:185
return $config
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 THEME_NO_SCREENSHOT
Definition: install.php:207
const F_HOURS
Definition: en_US.php:413
const NO_CACHE
Definition: en_US.php:862
createThemeform(XoopsConfigItem $config)