XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
createconfigform.php
Go to the documentation of this file.
1 <?php
18 if (!defined('XOOPS_INSTALL')) { die('XOOPS Custom Installation die'); }
19 
20 include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
21 include_once XOOPS_ROOT_PATH.'/class/xoopslists.php';
22 
23 define("PREF_1", _MD_AM_GENERAL);
24 define("PREF_2", _MD_AM_USERSETTINGS);
25 define("PREF_3", _MD_AM_METAFOOTER);
26 define("PREF_4", _MD_AM_CENSOR);
27 define("PREF_5", _MD_AM_SEARCH);
28 define("PREF_6", _MD_AM_MAILER);
29 if (defined("_MD_AM_AUTHENTICATION")) {
30  define("PREF_7", _MD_AM_AUTHENTICATION);
31 }
32 
34 {
35  $config_handler =& xoops_gethandler('config');
36  $GLOBALS['xoopsConfig'] = $xoopsConfig =& $config_handler->getConfigsByCat(XOOPS_CONF);
37 
38  $ret = array();
39  $confcount = count( $config );
40 
41  for ($i = 0; $i < $confcount; $i++) {
42  $conf_catid = $config[$i]->getVar('conf_catid');
43  if ( !isset( $ret[$conf_catid] ) ) {
44  $form_title = constant("PREF_" . $conf_catid);
45  $ret[$conf_catid] = new XoopsThemeForm($form_title, 'configs', 'index.php', 'post');
46  }
47 
48  $title = constant($config[$i]->getVar('conf_title'));
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 XoopsFormTextArea($title, $config[$i]->getVar('conf_name'), $myts->htmlspecialchars(implode('|', $config[$i]->getConfValueForOutput())), 5, 50) : new XoopsFormTextArea($title, $config[$i]->getVar('conf_name'), '', 5, 50);
57  } else {
58  $ele = new XoopsFormTextArea($title, $config[$i]->getVar('conf_name'), $myts->htmlspecialchars($config[$i]->getConfValueForOutput()), 5, 100);
59  }
60  break;
61 
62  case 'select':
63  $ele = new XoopsFormSelect($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 = defined($options[$j]->getVar('confop_value')) ? constant($options[$j]->getVar('confop_value')) : $options[$j]->getVar('confop_value');
68  $optkey = defined($options[$j]->getVar('confop_name')) ? constant($options[$j]->getVar('confop_name')) : $options[$j]->getVar('confop_name');
69  $ele->addOption($optval, $optkey);
70  }
71  break;
72 
73  case 'select_multi':
74  $ele = new XoopsFormSelect($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 = defined($options[$j]->getVar('confop_value')) ? constant($options[$j]->getVar('confop_value')) : $options[$j]->getVar('confop_value');
79  $optkey = defined($options[$j]->getVar('confop_name')) ? constant($options[$j]->getVar('confop_name')) : $options[$j]->getVar('confop_name');
80  $ele->addOption($optval, $optkey);
81  }
82  break;
83 
84  case 'yesno':
85  $ele = new XoopsFormRadioYN($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), _YES, _NO);
86  break;
87 
88  case 'theme':
89  case 'theme_multi':
90  $ele = ($config[$i]->getVar('conf_formtype') != 'theme_multi') ? new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput()) : new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), 5, true);
91  require_once XOOPS_ROOT_PATH."/class/xoopslists.php";
92  $dirlist = XoopsLists::getThemesList();
93  if (!empty($dirlist)) {
94  asort($dirlist);
95  $ele->addOptionArray($dirlist);
96  }
97  //$themeset_handler =& xoops_gethandler('themeset');
98  //$themesetlist =& $themeset_handler->getList();
99  //asort($themesetlist);
100  //foreach ($themesetlist as $key => $name) {
101  // $ele->addOption($key, $name.' ('._MD_AM_THEMESET.')');
102  //}
103  // old theme value is used to determine whether to update cache or not. kind of dirty way
104  $form->addElement(new XoopsFormHidden('_old_theme', $config[$i]->getConfValueForOutput()));
105  break;
106 
107  case 'tplset':
108  $ele = new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
109  $tplset_handler =& xoops_gethandler('tplset');
110  $tplsetlist =& $tplset_handler->getList();
111  asort($tplsetlist);
112  foreach ($tplsetlist as $key => $name) {
113  $ele->addOption($key, $name);
114  }
115  // old theme value is used to determine whether to update cache or not. kind of dirty way
116  $form->addElement(new XoopsFormHidden('_old_theme', $config[$i]->getConfValueForOutput()));
117  break;
118 
119  case 'timezone':
120  $ele = new XoopsFormSelectTimezone($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
121  break;
122 
123  case 'language':
124  $ele = new XoopsFormSelectLang($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
125  break;
126 
127  case 'startpage':
128  $ele = new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
129  $module_handler =& xoops_gethandler('module');
130  $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
131  $criteria->add(new Criteria('isactive', 1));
132  $moduleslist =& $module_handler->getList($criteria, true);
133  $moduleslist['--'] = _MD_AM_NONE;
134  $ele->addOptionArray($moduleslist);
135  break;
136 
137  case 'group':
138  $ele = new XoopsFormSelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false);
139  break;
140 
141  case 'group_multi':
142  $ele = new XoopsFormSelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true);
143  break;
144 
145  // RMV-NOTIFY - added 'user' and 'user_multi'
146  case 'user':
147  $ele = new XoopsFormSelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false);
148  break;
149 
150  case 'user_multi':
151  $ele = new XoopsFormSelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true);
152  break;
153 
154  case 'module_cache':
155  $module_handler =& xoops_gethandler('module');
156  $modules =& $module_handler->getObjects(new Criteria('hasmain', 1), true);
157  $currrent_val = $config[$i]->getConfValueForOutput();
158  $cache_options = array('0' => _NOCACHE, '30' => sprintf(_SECONDS, 30), '60' => _MINUTE, '300' => sprintf(_MINUTES, 5), '1800' => sprintf(_MINUTES, 30), '3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK);
159  if (count($modules) > 0) {
160  $ele = new XoopsFormElementTray($title, '<br />');
161  foreach (array_keys($modules) as $mid) {
162  $c_val = isset($currrent_val[$mid]) ? intval($currrent_val[$mid]) : null;
163  $selform = new XoopsFormSelect($modules[$mid]->getVar('name'), $config[$i]->getVar('conf_name')."[$mid]", $c_val);
164  $selform->addOptionArray($cache_options);
165  $ele->addElement($selform);
166  unset($selform);
167  }
168  } else {
170  }
171  break;
172 
173  case 'site_cache':
174  $ele = new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
175  $ele->addOptionArray(array('0' => _NOCACHE, '30' => sprintf(_SECONDS, 30), '60' => _MINUTE, '300' => sprintf(_MINUTES, 5), '1800' => sprintf(_MINUTES, 30), '3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK));
176  break;
177 
178  case 'password':
180  $ele = new XoopsFormPassword($title, $config[$i]->getVar('conf_name'), 50, 255, $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
181  break;
182 
183  case 'color':
185  $ele = new XoopsFormColorPicker($title, $config[$i]->getVar('conf_name'), $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
186  break;
187 
188  case 'hidden':
190  $ele = new XoopsFormHidden( $config[$i]->getVar('conf_name'), $myts->htmlspecialchars( $config[$i]->getConfValueForOutput() ) );
191  break;
192 
193  case 'textbox':
194  default:
196  $ele = new XoopsFormText($title, $config[$i]->getVar('conf_name'), 50, 255, $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
197  break;
198  }
199 
200  if ( defined($config[$i]->getVar('conf_desc')) && constant($config[$i]->getVar('conf_desc')) != '' ) {
201  $ele->setDescription( constant($config[$i]->getVar('conf_desc')) );
202  }
203  $ret[$conf_catid]->addElement($ele);
204 
205  $hidden = new XoopsFormHidden('conf_ids[]', $config[$i]->getVar('conf_id'));
206  $ret[$conf_catid]->addElement($hidden);
207 
208  unset($ele);
209  unset($hidden);
210  }
211  return $ret;
212 }
213 
215 {
216  $title = (!defined($config->getVar('conf_desc')) || constant($config->getVar('conf_desc')) == '') ? constant($config->getVar('conf_title')) : constant($config->getVar('conf_title')).'<br /><br /><span>'.constant($config->getVar('conf_desc')).'</span>';
217  $form_theme_set = new XoopsFormSelect('' , $config->getVar('conf_name'), $config->getConfValueForOutput(), 1, false);
218  $dirlist = XoopsLists::getThemesList();
219  if (!empty($dirlist)) {
220  asort($dirlist);
221  $form_theme_set->addOptionArray($dirlist);
222 
223  }
224 
225  $label_content = "";
226 
227  // read ini file for each theme
228  foreach ( $dirlist as $theme ) {
229  // set default value
230  $theme_ini = array(
231  'Name' => $theme,
232  'Description' => '',
233  'Version' => '',
234  'Format' => '',
235  'Author' => '',
236  'Demo' => '',
237  'Url' => '',
238  'Download' => '',
239  'W3C' => '',
240  'Licence' => '',
241  'thumbnail' => 'screenshot.gif',
242  'screenshot' => 'screenshot.png',
243  );
244 
245 
246 
247  if ( $theme == $config->getConfValueForOutput() ) {
248  $label_content .= "<div id='$theme' rel='theme' style='display:block;'>";
249  } else {
250  $label_content .= "<div id='$theme' rel='theme' style='display:none;'>";
251  }
252  if ( file_exists( XOOPS_ROOT_PATH . "/themes/$theme/theme.ini" ) ) {
253  $theme_ini = parse_ini_file( XOOPS_ROOT_PATH . "/themes/$theme/theme.ini" );
254  if ( $theme_ini['screenshot'] == '' ) {
255  $theme_ini['screenshot'] = 'screenshot.png';
256  $theme_ini['thumbnail'] = 'thumbnail.png';
257  }
258  }
259 
260  if ( $theme_ini['screenshot'] != '' && file_exists( XOOPS_ROOT_PATH . "/themes/$theme/" . $theme_ini['screenshot'] ) ) {
261  $label_content .= "<img src='" . XOOPS_URL . "/themes/" . $theme . "/" . $theme_ini['screenshot'] . "' alt='Screenshot' />";
262  } elseif ( $theme_ini['thumbnail'] != '' && file_exists( XOOPS_ROOT_PATH . "/themes/$theme/" . $theme_ini['thumbnail'] ) ) {
263  $label_content .= "<img src='" . XOOPS_URL . "/themes/" . $theme . "/" . $theme_ini['thumbnail'] . "' alt='$theme' />";
264  } else {
265  $label_content .= THEME_NO_SCREENSHOT;
266  }
267  $label_content .= "</div>";
268  }
269  // read ini file for each theme
270 
271  $form_theme_set->setExtra( "onchange='showThemeSelected(this)'" );
272 
273  $form = new XoopsThemeForm($title, 'themes', 'index.php', 'post');
274  $form->addElement($form_theme_set);
275  $form->addElement( new XoopsFormLabel( '', "<div id='screenshot'>" . $label_content . "</div>" ) );
276 
277  $form->addElement( new XoopsFormHidden('conf_ids[]', $config->getVar('conf_id')) );
278  return $ret = array($form);
279 }
280 ?>