Cheetah
ChWsbAdminSettings.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChTemplFormView');
9 
35 {
36  var $_oDb;
40 
43 
47  function __construct($mixedCategory, $sActionUrl = '')
48  {
49  $this->_oDb = $GLOBALS['MySQL'];
50  $this->_sActionUrl = !empty($sActionUrl) ? $sActionUrl : ch_html_attribute($_SERVER['PHP_SELF']) . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
51 
52  $this->_mixedCategory = $mixedCategory;
53  $this->_iCategoryActive = 0;
54 
55  $this->_iResultTimer = 3;
56  $this->_aCustomCategories = array(
57  'ap' => array(
58  'title' => '_getCatTitleAdminPassword',
59  'content' => '_getCatContentAdminPassword',
60  'save' => '_saveCatAdminPassword'
61  ),
62  16 => array(
63  'save' => '_saveCatWatermark'
64  ),
65  26 => array(
66  'on_save' => '_onSavePermalinks'
67  )
68  );
69  }
70 
71  function setActiveCategory($mixed)
72  {
73  if (is_int($mixed))
74  $this->_iCategoryActive = $mixed;
75  else
76  $this->_iCategoryActive = (int)$this->_oDb->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name`= ?", [$mixed]);
77  }
78  function saveChanges(&$aData)
79  {
80  $aCategories = explode(',', strip_tags($aData['cat']));
81  foreach($aCategories as $mixedCategory) {
82  if(!is_numeric($mixedCategory) || isset($this->_aCustomCategories[$mixedCategory]['save'])) {
83  $mixedResult = $this->{$this->_aCustomCategories[$mixedCategory]['save']}($aData);
84  if($mixedResult !== true)
85  return $mixedResult;
86  } else if(is_numeric($mixedCategory)) {
87  $aItems = $this->_oDb->getAll("SELECT `Name` AS `name`, `desc` AS `title`, `Type` AS `type`, `AvailableValues` AS `extra`, `check` AS `check`, `err_text` AS `check_error` FROM `sys_options` WHERE `kateg`= ?", [$mixedCategory]);
88 
89  $aItemsData = array();
90  foreach($aItems as $aItem) {
91  if(is_array($aData[$aItem['name']]))
92  foreach($aData[$aItem['name']] as $sKey => $sValue)
93  $aItemsData[$aItem['name']][$sKey] = strip_tags($sValue);
94  else
95  $aItemsData[$aItem['name']] = strip_tags($aData[$aItem['name']]);
96 
97  if(!empty($aItem['check'])) {
98  $oFunction = function($arg0) use ($aItem) {
99  return eval($aItem['check']);
100  };
101 
102  if(!$oFunction($aItemsData[$aItem['name']])) {
103  $this->_iCategoryActive = (int)$mixedCategory;
104  return MsgBox("'" . $aItem['title'] . "' " . $aItem['check_error'], $this->_iResultTimer);
105  }
106  }
107 
108  $bIsset = isset($aItemsData[$aItem['name']]);
109  if($bIsset && is_array($aItemsData[$aItem['name']]))
110  $aItemsData[$aItem['name']] = implode(',', $aItemsData[$aItem['name']]);
111  else if(!$bIsset)
112  $aItemsData[$aItem['name']] = $this->_empty($aItem);
113 
114  if($aItem['name'] == 'sys_php_block_enabled') {
115  if($aItemsData[$aItem['name']] == 'on') {
116  if(getParam('sys_php_block_enabled') == '') {
117  $GLOBALS['MySQL']->query("INSERT INTO `sys_page_compose` (`Page`, `PageWidth`, `Desc`, `Caption`, `Column`, `Order`, `Func`, `Content`, `DesignBox`, `ColWidth`, `Visible`, `MinWidth`, `Cache`) VALUES ('', '1140px', 'Simple PHP Block', '_Code Block', 0, 0, 'Sample', 'Code', 11, 0, 'non,memb', 0, 0)");
118  }
119  } else {
120  $GLOBALS['MySQL']->query("DELETE FROM `sys_page_compose` WHERE `Func` = 'Sample' AND `Content` = 'Code'");
121  }
122 
123  }
124  setParam ($aItem['name'], $aItemsData[$aItem['name']]);
125  }
126  }
127  if(isset($this->_aCustomCategories[$mixedCategory]['on_save']))
128  $this->{$this->_aCustomCategories[$mixedCategory]['on_save']}();
129  }
130  return MsgBox(_t('_adm_txt_settings_success'), $this->_iResultTimer);
131  }
132  function getTitle()
133  {
134  $sResult = '';
135 
136  if(!is_numeric($this->_mixedCategory) || isset($this->_aCustomCategories[$this->_mixedCategory]['title']))
137  $sResult = $this->{$this->_aCustomCategories[$this->_mixedCategory]['title']}();
138  else if(is_numeric($this->_mixedCategory))
139  $sResult = $this->_oDb->getOne("SELECT `name` AS `name` FROM `sys_options_cats` WHERE `ID`='" . $this->_mixedCategory . "' LIMIT 1");
140 
141  return $sResult;
142  }
143  function getFormObject($aCategories = array())
144  {
145  if(empty($aCategories))
146  $aCategories[] = $this->_mixedCategory;
147 
148  $bWrap = count($aCategories) > 1;
149 
150  $aForm = array(
151  'form_attrs' => array(
152  'id' => 'adm-settings-form',
153  'name' => 'adm-settings-form',
154  'action' => $this->_sActionUrl,
155  'method' => 'post',
156  'enctype' => 'multipart/form-data'
157  ),
158  'params' => array(
159  'db' => array(
160  'table' => 'sys_options',
161  'key' => 'Name',
162  'uri' => '',
163  'uri_title' => '',
164  'submit_name' => 'save'
165  ),
166  ),
167  'inputs' => array()
168  );
169  foreach($aCategories as $mixedCategory) {
170  $aFields = array();
171 
172  if(!is_numeric($mixedCategory) || isset($this->_aCustomCategories[$mixedCategory]['content']))
173  $aFields = $this->{$this->_aCustomCategories[$mixedCategory]['content']}();
174  else if(is_numeric($mixedCategory) && (int)$mixedCategory != 0) {
175  $aCategory = $this->_oDb->getRow("SELECT `ID` AS `id`, `name` AS `name` FROM `sys_options_cats` WHERE `ID`= ?", [$mixedCategory]);
176  $aItems = $this->_oDb->getAll("SELECT `Name` AS `name`, `VALUE` AS `value`, `Type` AS `type`, `desc` AS `description`, `AvailableValues` AS `extra`, `check` AS `check`, `err_text` AS `check_error`
177  FROM `sys_options` WHERE `kateg`= ? ORDER BY `order_in_kateg`", [$mixedCategory]);
178 
179  foreach($aItems as $aItem)
180  $aFields[] = $this->_field($aItem);
181 
182  if($bWrap)
183  $aFields = $this->_wrap($aCategory, $aFields);
184  }
185 
186  $aForm['inputs'] = array_merge($aForm['inputs'], $aFields);
187  }
188  $aForm['inputs'] = array_merge($aForm['inputs'], array(
189  'cat' => array(
190  'type' => 'hidden',
191  'name' => 'cat',
192  'value' => implode(',', $aCategories)
193  ),
194  'save' => array(
195  'type' => 'submit',
196  'name' => 'save',
197  'value' => _t("_adm_btn_settings_save"),
198  )
199  ));
201  return $oForm;
202 
203  }
204  function getForm($aCategories = array())
205  {
206  $oForm = $this->getFormObject($aCategories);
207  $oForm->initChecker();
208  return $oForm->getCode();
209  }
210 
211  function _wrap($aCategory, $aFields)
212  {
213  $aFields = array_merge(
214  array(
215  'category_' . $aCategory['id'] . '_beg' => array(
216  'type' => 'block_header',
217  'caption' => $aCategory['name'],
218  'collapsable' => true,
219  'collapsed' => $aCategory['id'] != $this->_iCategoryActive
220  )
221  ),
222  $aFields);
223  $aFields['category_' . $aCategory['id'] . '_end'] = array(
224  'type' => 'block_end'
225  );
226  return $aFields;
227  }
228  function _field($aItem)
229  {
230  $aField = array();
231  switch($aItem['type']) {
232  case 'digit':
233  $aField = array(
234  'type' => 'text',
235  'name' => $aItem['name'],
236  'caption' => $aItem['description'],
237  'value' => $aItem['value'],
238  'db' => array (
239  'pass' => 'Xss',
240  ),
241  );
242  break;
243 
244  case 'text':
245  $aField = array(
246  'type' => 'textarea',
247  'name' => $aItem['name'],
248  'caption' => $aItem['description'],
249  'value' => $aItem['value'],
250  'db' => array (
251  'pass' => 'XssHtml',
252  ),
253  );
254  break;
255 
256  case 'checkbox':
257  $aField = array(
258  'type' => 'checkbox',
259  'name' => $aItem['name'],
260  'caption' => $aItem['description'],
261  'value' => 'on',
262  'checked' => $aItem['value'] == 'on',
263  'db' => array (
264  'pass' => 'Boolean',
265  ),
266  );
267  break;
268 
269  case 'list':
270  $aField = array(
271  'type' => 'checkbox_set',
272  'name' => $aItem['name'],
273  'caption' => $aItem['description'],
274  'value' => explode(',', $aItem['value']),
275  'db' => array (
276  'pass' => 'Xss',
277  ),
278  );
279 
280  if(substr($aItem['extra'], 0, 4) == 'PHP:')
281  $aField['values'] = eval(substr($aItem['extra'], 4));
282  else
283  foreach(explode(',', $aItem['extra']) as $sValue)
284  $aField['values'][$sValue] = $sValue;
285  break;
286 
287  case 'select':
288  $aField = array(
289  'type' => 'select',
290  'name' => $aItem['name'],
291  'caption' => $aItem['description'],
292  'value' => $aItem['value'],
293  'values' => array(),
294  'db' => array (
295  'pass' => 'Xss',
296  ),
297  );
298 
299  if(substr($aItem['extra'], 0, 4) == 'PHP:')
300  $aField['values'] = eval(substr($aItem['extra'], 4));
301  else
302  foreach(explode(',', $aItem['extra']) as $sValue)
303  $aField['values'][] = array('key' => $sValue, 'value' => $sValue);
304  break;
305 
306  case 'select_multiple':
307  $aField = array(
308  'type' => 'select_multiple',
309  'name' => $aItem['name'],
310  'caption' => $aItem['description'],
311  'value' => explode(',', $aItem['value']),
312  'db' => array (
313  'pass' => 'Xss',
314  ),
315  );
316 
317  if(substr($aItem['extra'], 0, 4) == 'PHP:')
318  $aField['values'] = eval(substr($aItem['extra'], 4));
319  else
320  foreach(explode(',', $aItem['extra']) as $sValue)
321  $aField['values'][$sValue] = $sValue;
322  break;
323 
324  case 'file':
325  $aField = array(
326  'type' => 'file',
327  'name' => $aItem['name'],
328  'caption' => $aItem['description'],
329  'value' => $aItem['value'],
330  );
331  break;
332  }
333  return $aField;
334  }
335  function _empty($aItem)
336  {
337  $mixedValue = '';
338  switch($aItem['type']) {
339  case 'digit':
340  $mixedValue = 0;
341  break;
342  case 'select':
343  $aValues = explode(",", $aItem['extra']);
344  $mixedValue = $aValues[0];
345  break;
346  case 'text':
347  case 'checkbox':
348  case 'file':
349  $mixedValue = "";
350  break;
351  }
352  return $mixedValue;
353  }
354 
361  {
362  return _t('_adm_box_cpt_admin_password');
363  }
365  {
366  return array(
367  'pwd_old' => array(
368  'type' => 'password',
369  'name' => 'pwd_old',
370  'caption' => _t('_adm_txt_settings_old_password'),
371  'value' => ''
372  ),
373  'pwd_new' => array(
374  'type' => 'password',
375  'name' => 'pwd_new',
376  'caption' => _t('_adm_txt_settings_new_password'),
377  'value' => ''
378  ),
379  'pwd_conf' => array(
380  'type' => 'password',
381  'name' => 'pwd_conf',
382  'caption' => _t('_adm_txt_settings_conf_password'),
383  'value' => ''
384  )
385  );
386  }
387  function _saveCatAdminPassword(&$aData)
388  {
389  $iId = (int)$_COOKIE['memberID'];
390 
391  $aAdmin = $this->_oDb->getRow("SELECT `Password`, `Salt` FROM `Profiles` WHERE `ID`= ?", [$iId]);
392 
393  if(encryptUserPwd($aData['pwd_old'], $aAdmin['Salt']) != $aAdmin['Password'])
394  return MsgBox(_t('_adm_txt_settings_wrong_old_pasword'), $this->_iResultTimer);
395 
396  $iLength = strlen($aData['pwd_new']);
397  if($iLength < 3)
398  return MsgBox(_t('_adm_txt_settings_wrong_new_pasword'), $this->_iResultTimer);
399 
400  if($aData['pwd_new'] != $aData['pwd_conf'])
401  return MsgBox(_t('_adm_txt_settings_wrong_conf_pasword'), $this->_iResultTimer);
402 
403  $this->_oDb->query("UPDATE `Profiles` SET `Password`='" . encryptUserPwd($aData['pwd_new'], $aAdmin['Salt']) . "' WHERE `ID`='$iId'");
405 
406  return true;
407  }
408 
409  function _saveCatWatermark(&$aData)
410  {
411  global $dir;
412  $bResult = false;
413  $iImgWidth = (int)getParam('ch_photos_file_width');
414  if(empty($iImgWidth))
415  $iImgWidth = 100;
416  $iImgHeight = (int)getParam('ch_photos_file_height');
417  if(empty($iImgHeight))
418  $iImgHeight = 100;
419 
420  if(!empty($aData['transparent1']))
421  $bResult = $GLOBALS['MySQL']->query("UPDATE `sys_options` SET `VALUE`='" . (int)$aData['transparent1'] . "' WHERE `Name`='transparent1'") !== false;
422 
423  if(!empty($aData['enable_watermark']))
424  $sValue = process_db_input($aData['enable_watermark'], CH_TAGS_STRIP);
425  else
426  $sValue = '';
427  $bResult = $GLOBALS['MySQL']->query("UPDATE `sys_options` SET `VALUE`='$sValue' WHERE `Name`='enable_watermark'") !== false;
428 
429  if($_FILES['Water_Mark'] && $_FILES['Water_Mark']['error'] == UPLOAD_ERR_OK) {
430  $aImage = getimagesize($_FILES['Water_Mark']['tmp_name']);
431 
432  if(!empty($aImage) && in_array($aImage[2], array(1, 2, 3, 6))) {
433  $sPath = $dir['profileImage'] . $_FILES['Water_Mark']['name'];
434  if(move_uploaded_file($_FILES['Water_Mark']['tmp_name'], $sPath)) {
435  $sOldImage = getParam('Water_Mark');
436  if(!empty($sOldImage) && ($dir['profileImage'] . $sOldImage) != $sPath)
437  @unlink($dir['profileImage'] . $sOldImage);
438 
439  imageResize($sPath, $sPath, $iImgWidth, $iImgHeight);
440  @chmod($sPath, 0644);
441 
442  $bResult = $GLOBALS['MySQL']->query("UPDATE `sys_options` SET `VALUE` ='". addslashes($_FILES['Water_Mark']['name']) . "' WHERE `Name`='Water_Mark'") !== false;
443  }
444  }
445  }
446 
447  $GLOBALS['MySQL']->oParams->clearCache();
448 
449  return $bResult ? $bResult : MsgBox(_t('_adm_txt_settings_error'), $this->_iResultTimer);
450  }
451 
452  function _onSavePermalinks()
453  {
454  $oPermalinks = new ChWsbPermalinks();
455  $oPermalinks->cache();
456 
457  $oMenu = new ChWsbMenu();
458  $oMenu->compile();
459 
460  $GLOBALS['MySQL']->cleanCache ('sys_menu_member');
461  }
462 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
ChTemplFormView
Definition: ChTemplFormView.php:11
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
ChWsbAdminSettings\_getCatTitleAdminPassword
_getCatTitleAdminPassword()
Definition: ChWsbAdminSettings.php:360
$oMenu
$oMenu
Definition: bottom_menu_compose.php:29
ChWsbAdminSettings\$_iResultTimer
$_iResultTimer
Definition: ChWsbAdminSettings.php:41
$sResult
$sResult
Definition: advanced_settings.php:26
ChWsbAdminSettings\_field
_field($aItem)
Definition: ChWsbAdminSettings.php:228
ChWsbAdminSettings\_wrap
_wrap($aCategory, $aFields)
Definition: ChWsbAdminSettings.php:211
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
ChWsbAdminSettings\getTitle
getTitle()
Definition: ChWsbAdminSettings.php:132
php
$iId
$iId
Definition: license.php:15
ChWsbAdminSettings\_onSavePermalinks
_onSavePermalinks()
Definition: ChWsbAdminSettings.php:452
ch_html_attribute
ch_html_attribute($mixedInput)
Definition: utils.inc.php:1324
$oForm
$oForm
Definition: host_tools.php:42
createUserDataFile
createUserDataFile( $userID)
Definition: profiles.inc.php:192
$aFields
$aFields
Definition: preValues.php:19
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChWsbAdminSettings\_saveCatAdminPassword
_saveCatAdminPassword(&$aData)
Definition: ChWsbAdminSettings.php:387
ChWsbAdminSettings\$_oDb
$_oDb
Definition: ChWsbAdminSettings.php:36
ChWsbAdminSettings\_empty
_empty($aItem)
Definition: ChWsbAdminSettings.php:335
ChWsbAdminSettings\_saveCatWatermark
_saveCatWatermark(&$aData)
Definition: ChWsbAdminSettings.php:409
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
$bResult
$bResult
Definition: get_file.php:11
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChWsbAdminSettings\$_mixedCategory
$_mixedCategory
Definition: ChWsbAdminSettings.php:38
ChWsbAdminSettings
Definition: ChWsbAdminSettings.php:35
ChWsbAdminSettings\$_sActionUrl
$_sActionUrl
Definition: ChWsbAdminSettings.php:37
CH_TAGS_STRIP
const CH_TAGS_STRIP
Definition: utils.inc.php:22
setParam
setParam($sParamName, $sParamValue)
Definition: db.inc.php:149
ChWsbAdminSettings\__construct
__construct($mixedCategory, $sActionUrl='')
Definition: ChWsbAdminSettings.php:47
ChWsbAdminSettings\saveChanges
saveChanges(&$aData)
Definition: ChWsbAdminSettings.php:78
$aForm
$aForm
Definition: forgot.php:43
encryptUserPwd
encryptUserPwd($sPwd, $sSalt)
Definition: utils.inc.php:1643
ChWsbAdminSettings\$_aCustomCategories
$_aCustomCategories
Definition: ChWsbAdminSettings.php:42
ChWsbAdminSettings\$_iCategoryActive
$_iCategoryActive
Definition: ChWsbAdminSettings.php:39
ChWsbAdminSettings\getForm
getForm($aCategories=array())
Definition: ChWsbAdminSettings.php:204
ChWsbAdminSettings\_getCatContentAdminPassword
_getCatContentAdminPassword()
Definition: ChWsbAdminSettings.php:364
ChWsbAdminSettings\setActiveCategory
setActiveCategory($mixed)
Definition: ChWsbAdminSettings.php:71
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
imageResize
imageResize( $srcFilename, $dstFilename, $sizeX, $sizeY, $forceJPGOutput=false, $isSquare=false)
Definition: images.inc.php:29
ChWsbAdminSettings\getFormObject
getFormObject($aCategories=array())
Definition: ChWsbAdminSettings.php:143
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
$mixedCategory
$mixedCategory
Definition: settings.php:17
ChWsbMenu
Definition: ChWsbMenu.php:14
$dir
$dir
Definition: config.php:10