source: trunk/inc/classes/BxDolAdminSettings.php

Last change on this file was 2, checked in by george, 14 years ago
  • Přidáno: Trunk revize 13719.
File size: 15.7 KB
Line 
1<?
2/***************************************************************************
3* Dolphin Smart Community Builder
4* -------------------
5* begin : Mon Mar 23 2006
6* copyright : (C) 2007 BoonEx Group
7* website : http://www.boonex.com
8* This file is part of Dolphin - Smart Community Builder
9*
10* Dolphin is free software; you can redistribute it and/or modify it under
11* the terms of the GNU General Public License as published by the
12* Free Software Foundation; either version 2 of the
13* License, or any later version.
14*
15* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
16* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17* See the GNU General Public License for more details.
18* You should have received a copy of the GNU General Public License along with Dolphin,
19* see license.txt file; if not, write to marketing@boonex.com
20***************************************************************************/
21
22bx_import('BxDolMistake');
23bx_import('BxTemplFormView');
24
25/**
26 * Global settings visualisation in admin panel.
27 *
28 * Example of usage:
29 * 1. Add form with settings
30 *
31 * $oSettings = new BxDolAdminSettings($mixedCategory);
32 * $oSettings->getForm();
33 *
34 * 2. Save sattings on form submit
35 *
36 * if(isset($_POST['save']) && isset($_POST['cat'])) {
37 * $sResult = $oSettings->saveChanges($_POST);
38 * }
39 *
40 *
41 * Memberships/ACL:
42 * Doesn't depend on user's membership.
43 *
44 *
45 * Alerts:
46 * no alerts available
47 *
48 */
49class BxDolAdminSettings extends BxDolMistake {
50 var $_oDb;
51 var $_sActionUrl;
52 var $_mixedCategory;
53 var $_iCategoryActive;
54
55 var $_iResultTimer;
56 var $_aCustomCategories;
57
58
59 /**
60 * constructor
61 */
62 function BxDolAdminSettings($mixedCategory, $sActionUrl = '') {
63 parent::BxDolMistake();
64
65 $this->_oDb = $GLOBALS['MySQL'];
66 $this->_sActionUrl = !empty($sActionUrl) ? $sActionUrl : $_SERVER['PHP_SELF'] . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
67
68 $this->_mixedCategory = $mixedCategory;
69 $this->_iCategoryActive = 0;
70
71 $this->_iResultTimer = 3;
72 $this->_aCustomCategories = array(
73 'ap' => array(
74 'title' => '_getCatTitleAdminPassword',
75 'content' => '_getCatContentAdminPassword',
76 'save' => '_saveCatAdminPassword'
77 ),
78 16 => array(
79 'save' => '_saveCatWatermark'
80 ),
81 26 => array(
82 'on_save' => '_onSavePermalinks'
83 )
84 );
85 }
86 function saveChanges(&$aData) {
87 $aCategories = explode(',', process_db_input($aData['cat'], BX_TAGS_STRIP));
88 foreach($aCategories as $mixedCategory) {
89 if(!is_numeric($mixedCategory) || isset($this->_aCustomCategories[$mixedCategory]['save'])) {
90 $mixedResult = $this->{$this->_aCustomCategories[$mixedCategory]['save']}($aData);
91 if($mixedResult !== true)
92 return $mixedResult;
93 }
94 else if(is_numeric($mixedCategory)) {
95 $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`='" . (int)$mixedCategory . "'");
96 foreach($aItems as $aItem) {
97 if(is_array($aData[$aItem['name']]))
98 foreach($aData[$aItem['name']] as $sKey => $sValue)
99 $aData[$aItem['name']][$sKey] = process_db_input($sValue, BX_TAGS_STRIP);
100 else
101 $aData[$aItem['name']] = process_db_input($aData[$aItem['name']], BX_TAGS_STRIP);
102
103 if(!empty($aItem['check'])) {
104 $oFunction = create_function('$arg0', $aItem['check']);
105 if(!$oFunction($aData[$aItem['name']])) {
106 $this->_iCategoryActive = (int)$mixedCategory;
107 return MsgBox("'" . $aItem['title'] . "' " . $aItem['check_error'], $this->_iResultTimer);
108 }
109 }
110 $aData[$aItem['name']] = (is_array($aData[$aItem['name']])) ? implode(',', $aData[$aItem['name']]) : $aData[$aItem['name']];
111 setParam ($aItem['name'], (isset($aData[$aItem['name']]) ? $aData[$aItem['name']] : $this->_empty($aItem)));
112 }
113 }
114 if(isset($this->_aCustomCategories[$mixedCategory]['on_save']))
115 $this->{$this->_aCustomCategories[$mixedCategory]['on_save']}();
116 }
117 return MsgBox(_t('_adm_txt_settings_success'), $this->_iResultTimer);
118 }
119 function getTitle() {
120 $sResult = '';
121
122 if(!is_numeric($this->_mixedCategory) || isset($this->_aCustomCategories[$this->_mixedCategory]['title']))
123 $sResult = $this->{$this->_aCustomCategories[$this->_mixedCategory]['title']}();
124 else if(is_numeric($this->_mixedCategory))
125 $sResult = $this->_oDb->getOne("SELECT `name` AS `name` FROM `sys_options_cats` WHERE `ID`='" . $this->_mixedCategory . "' LIMIT 1");
126
127 return $sResult;
128 }
129 function getForm($aCategories = array()) {
130 if(empty($aCategories))
131 $aCategories[] = $this->_mixedCategory;
132
133 $bWrap = count($aCategories) > 1;
134
135 $aForm = array(
136 'form_attrs' => array(
137 'id' => 'adm-settings-form',
138 'name' => 'adm-settings-form',
139 'action' => $this->_sActionUrl,
140 'method' => 'post',
141 'enctype' => 'multipart/form-data'
142 ),
143 'params' => array(
144 'db' => array(
145 'table' => 'sys_options',
146 'key' => 'Name',
147 'uri' => '',
148 'uri_title' => '',
149 'submit_name' => 'save'
150 ),
151 ),
152 'inputs' => array()
153 );
154 foreach($aCategories as $mixedCategory) {
155 $aFields = array();
156
157 if(!is_numeric($mixedCategory) || isset($this->_aCustomCategories[$mixedCategory]['content']))
158 $aFields = $this->{$this->_aCustomCategories[$mixedCategory]['content']}();
159 else if(is_numeric($mixedCategory) && (int)$mixedCategory != 0) {
160 $aCategory = $this->_oDb->getRow("SELECT `ID` AS `id`, `name` AS `name` FROM `sys_options_cats` WHERE `ID`='" . (int)$mixedCategory . "'");
161 $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` FROM `sys_options` WHERE `kateg`='" . (int)$mixedCategory . "' ORDER BY `order_in_kateg`");
162
163 foreach($aItems as $aItem)
164 $aFields[] = $this->_field($aItem);
165
166 if($bWrap)
167 $aFields = $this->_wrap($aCategory, $aFields);
168 }
169
170 $aForm['inputs'] = array_merge($aForm['inputs'], $aFields);
171 }
172 $aForm['inputs'] = array_merge($aForm['inputs'], array(
173 'cat' => array(
174 'type' => 'hidden',
175 'name' => 'cat',
176 'value' => implode(',', $aCategories)
177 ),
178 'save' => array(
179 'type' => 'submit',
180 'name' => 'save',
181 'value' => _t("_adm_btn_settings_save"),
182 )
183 ));
184 $oForm = new BxTemplFormView($aForm);
185 $oForm->initChecker();
186
187 return $oForm->getCode();
188 }
189
190 function _wrap($aCategory, $aFields){
191 $aFields = array_merge(
192 array(
193 'category_' . $aCategory['id'] . '_beg' => array(
194 'type' => 'block_header',
195 'caption' => $aCategory['name'],
196 'collapsable' => true,
197 'collapsed' => $aCategory['id'] != $this->_iCategoryActive
198 )
199 ),
200 $aFields);
201 $aFields['category_' . $aCategory['id'] . '_end'] = array(
202 'type' => 'block_end'
203 );
204 return $aFields;
205 }
206 function _field($aItem) {
207 $aField = array();
208 switch($aItem['type']) {
209 case 'digit':
210 $aField = array(
211 'type' => 'text',
212 'name' => $aItem['name'],
213 'caption' => $aItem['description'],
214 'value' => $aItem['value'],
215 'db' => array (
216 'pass' => 'Xss',
217 ),
218 );
219 break;
220 case 'text':
221 $aField = array(
222 'type' => 'textarea',
223 'name' => $aItem['name'],
224 'caption' => $aItem['description'],
225 'value' => $aItem['value'],
226 'db' => array (
227 'pass' => 'XssHtml',
228 ),
229 );
230 break;
231 case 'checkbox':
232 $aField = array(
233 'type' => 'checkbox',
234 'name' => $aItem['name'],
235 'caption' => $aItem['description'],
236 'value' => 'on',
237 'checked' => $aItem['value'] == 'on',
238 'db' => array (
239 'pass' => 'Boolean',
240 ),
241 );
242 break;
243 case 'list':
244 $aField = array(
245 'type' => 'checkbox_set',
246 'name' => $aItem['name'],
247 'caption' => $aItem['description'],
248 'value' => explode(',', $aItem['value']),
249 'db' => array (
250 'pass' => 'Xss',
251 ),
252 );
253
254 if(substr($aItem['extra'], 0, 4) == 'PHP:')
255 $aField['values'] = eval(substr($aItem['extra'], 4));
256 else
257 foreach(split(',', $aItem['extra']) as $sValue)
258 $aField['values'][$sValue] = $sValue;
259
260 break;
261 case 'select':
262 $aField = array(
263 'type' => 'select',
264 'name' => $aItem['name'],
265 'caption' => $aItem['description'],
266 'value' => $aItem['value'],
267 'values' => array(),
268 'db' => array (
269 'pass' => 'Xss',
270 ),
271 );
272 if(substr($aItem['extra'], 0, 4) == 'PHP:')
273 $aField['values'] = eval(substr($aItem['extra'], 4));
274 else
275 foreach(split(',', $aItem['extra']) as $sValue)
276 $aField['values'][] = array('key' => $sValue, 'value' => $sValue);
277 break;
278 case 'file':
279 $aField = array(
280 'type' => 'file',
281 'name' => $aItem['name'],
282 'caption' => $aItem['description'],
283 'value' => $aItem['value'],
284 );
285 break;
286 }
287 return $aField;
288 }
289 function _empty($aItem) {
290 $mixedValue = '';
291 switch($aItem['type']) {
292 case 'digit':
293 $mixedValue = 0;
294 break;
295 case 'select':
296 $aValues = explode(",", $aItem['extra']);
297 $mixedValue = $aValues[0];
298 break;
299 case 'text':
300 case 'checkbox':
301 case 'file':
302 $mixedValue = "";
303 break;
304 }
305 return $mixedValue;
306 }
307
308 /**
309 *
310 * CUSTOM CATEGORIES METHODS
311 *
312 */
313 function _getCatTitleAdminPassword() {
314 return _t('_adm_box_cpt_admin_password');
315 }
316 function _getCatContentAdminPassword() {
317 return array(
318 'pwd_old' => array(
319 'type' => 'password',
320 'name' => 'pwd_old',
321 'caption' => _t('_adm_txt_settings_old_password'),
322 'value' => ''
323 ),
324 'pwd_new' => array(
325 'type' => 'password',
326 'name' => 'pwd_new',
327 'caption' => _t('_adm_txt_settings_new_password'),
328 'value' => ''
329 ),
330 'pwd_conf' => array(
331 'type' => 'password',
332 'name' => 'pwd_conf',
333 'caption' => _t('_adm_txt_settings_conf_password'),
334 'value' => ''
335 )
336 );
337 }
338 function _saveCatAdminPassword(&$aData) {
339 $iId = (int)$_COOKIE['memberID'];
340
341 $aData['pwd_old'] = process_db_input($aData['pwd_old'], BX_TAGS_STRIP);
342 $aData['pwd_new'] = process_db_input($aData['pwd_new'], BX_TAGS_STRIP);
343 $aData['pwd_conf'] = process_db_input($aData['pwd_conf'], BX_TAGS_STRIP);
344
345 $aAdmin = $this->_oDb->getRow("SELECT `Password`, `Salt` FROM `Profiles` WHERE `ID`='$iId'");
346
347 if(encryptUserPwd($aData['pwd_old'], $aAdmin['Salt']) != $aAdmin['Password'])
348 return MsgBox(_t('_adm_txt_settings_wrong_old_pasword'), $this->_iResultTimer);
349
350 $iLength = strlen($aData['pwd_new']);
351 if($iLength < 3 || $iLength > 8)
352 return MsgBox(_t('_adm_txt_settings_wrong_new_pasword'), $this->_iResultTimer);
353
354 if($aData['pwd_new'] != $aData['pwd_conf'])
355 return MsgBox(_t('_adm_txt_settings_wrong_conf_pasword'), $this->_iResultTimer);
356
357 $this->_oDb->query("UPDATE `Profiles` SET `Password`='" . encryptUserPwd($aData['pwd_new'], $aAdmin['Salt']) . "' WHERE `ID`='$iId'");
358 createUserDataFile($iId);
359
360 return true;
361 }
362
363 function _saveCatWatermark(&$aData){
364 global $dir;
365 $bResult = false;
366 $iImgWidth = (int)getParam('bx_photos_file_width');
367 if(empty($iImgWidth))
368 $iImgWidth = 100;
369 $iImgHeight = (int)getParam('bx_photos_file_height');
370 if(empty($iImgHeight))
371 $iImgHeight = 100;
372
373 if(!empty($aData['transparent1']))
374 $bResult = $GLOBALS['MySQL']->query("UPDATE `sys_options` SET `VALUE`='" . (int)$aData['transparent1'] . "' WHERE `Name`='transparent1'") !== false;
375
376 if(!empty($aData['enable_watermark']))
377 $sValue = process_db_input($aData['enable_watermark'], BX_TAGS_STRIP);
378 else
379 $sValue = '';
380 $bResult = $GLOBALS['MySQL']->query("UPDATE `sys_options` SET `VALUE`='$sValue' WHERE `Name`='enable_watermark'") !== false;
381
382 if($_FILES['Water_Mark'] && $_FILES['Water_Mark']['error'] == UPLOAD_ERR_OK) {
383 $aImage = getimagesize($_FILES['Water_Mark']['tmp_name']);
384
385 if(!empty($aImage) && in_array($aImage[2], array(1, 2, 3, 6))) {
386 $sPath = $dir['profileImage'] . $_FILES['Water_Mark']['name'];
387 if(move_uploaded_file($_FILES['Water_Mark']['tmp_name'], $sPath)) {
388 $sOldImage = getParam('Water_Mark');
389 if(!empty($sOldImage) && ($dir['profileImage'] . $sOldImage) != $sPath)
390 @unlink($dir['profileImage'] . $sOldImage);
391
392 imageResize($sPath, $sPath, $iImgWidth, $iImgHeight);
393 @chmod($sPath, 0644);
394
395 $bResult = $GLOBALS['MySQL']->query("UPDATE `sys_options` SET `VALUE` ='". addslashes($_FILES['Water_Mark']['name']) . "' WHERE `Name`='Water_Mark'") !== false;
396 }
397 }
398 }
399
400 $sCacheFile = BX_DIRECTORY_PATH_CACHE . 'sys_options.php';
401 @unlink ($sCacheFile);
402
403 return $bResult ? $bResult : MsgBox(_t('_adm_txt_settings_error'), $this->_iResultTimer);
404 }
405
406 function _onSavePermalinks() {
407 $oPermalinks = new BxDolPermalinks();
408 $oPermalinks->cache();
409
410 $oMenu = new BxDolMenu();
411 $oMenu->compile();
412
413 clearCacheFile(BX_DIRECTORY_PATH_DBCACHE . 'sys_menu_member.inc');
414 }
415}
Note: See TracBrowser for help on using the repository browser.