| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup DolphinStudio Dolphin Studio
- * @{
- */
- defined('BX_DOL') or die('hack attempt');
- bx_import('BxTemplStudioPage');
- bx_import('BxDolStudioSettingsQuery');
- define('BX_DOL_STUDIO_STG_TYPE_SYSTEM', 'system');
- define('BX_DOL_STUDIO_STG_TYPE_DEFAULT', BX_DOL_STUDIO_STG_TYPE_SYSTEM);
- define('BX_DOL_STUDIO_STG_GROUP_SYSTEM', 'system');
- define('BX_DOL_STUDIO_STG_GROUP_MODULES', 'modules');
- define('BX_DOL_STUDIO_STG_GROUP_LANGUAGES', 'languages');
- define('BX_DOL_STUDIO_STG_CATEGORY_SYSTEM', 'system');
- define('BX_DOL_STUDIO_STG_CATEGORY_LANGUAGES', 'languages');
- define('BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES', 'templates');
- class BxDolStudioSettings extends BxTemplStudioPage {
- protected $sType;
- protected $sCategory;
- protected $aCategories;
- protected $aCustomCategories;
- function BxDolStudioSettings($sType = '', $sCategory = '') {
- parent::BxTemplStudioPage('settings');
- $this->oDb = new BxDolStudioSettingsQuery();
- $this->sType = BX_DOL_STUDIO_STG_TYPE_DEFAULT;
- if(is_string($sType) && !empty($sType))
- $this->sType = $sType;
- $this->sCategory = '';
- if(is_string($sCategory) && !empty($sCategory))
- $this->sCategory = $sCategory;
- //--- Check actions ---//
- if(($sAction = bx_get('stg_action')) !== false && ($sValue = bx_get('stg_value')) !== false) {
- $sAction = bx_process_input($sAction);
- $sValue = bx_process_input($sValue);
- $aResult = array('code' => 0, 'message' => '');
- if(!empty($sAction) && !empty($sValue)) {
- switch($sAction) {
- case 'get-page-by-type':
- $this->sType = $sValue;
- $aResult['content'] = $this->getPageCode();
- break;
- }
- $oJson = new Services_JSON();
- echo $oJson->encode($aResult);
- }
- exit;
- }
- }
- function saveChanges(&$oForm) {
- $aCategories = explode(',', $oForm->getCleanValue('categories'));
- foreach ($aCategories as $sCategory) {
- $aOptions = array();
- $iOptions = $this->oDb->getOptions(array('type' => 'by_category_name', 'value' => $sCategory), $aOptions);
- $aData = array();
- foreach($aOptions as $aOption) {
- $aData[$aOption['name']] = $oForm->getCleanValue($aOption['name']);
- if(!empty($aOption['check'])) {
- $oFunction = create_function('$arg0', $aOption['check']);
- if(!$oFunction($aData[$aOption['name']])) {
- $this->sCategory = $sCategory;
- return $this->getJsResult("'" . $aOption['title'] . "' " . $aOption['check_error'], false);
- }
- }
- if(isset($aData[$aOption['name']]))
- $aData[$aOption['name']] = $this->getProcessedValue($aOption, $aData[$aOption['name']]);
- else
- $aData[$aOption['name']] = $this->getEmptyValue($aOption);
- $this->oDb->setParam($aOption['name'], $aData[$aOption['name']]);
- }
- }
- return $this->getJsResult('_adm_stg_scs_save');
- }
- protected function getProcessedValue($aOption, $mixedValue) {
- if(is_array($mixedValue))
- $mixedValue = implode(',', $mixedValue);
- return $mixedValue;
- }
- protected function getEmptyValue($aOption) {
- $mixedValue = '';
- switch($aOption['type']) {
- case 'digit':
- $mixedValue = 0;
- break;
- case 'select':
- $aValues = explode(",", $aOption['extra']);
- $mixedValue = $aValues[0];
- break;
- case 'text':
- case 'checkbox':
- case 'file':
- $mixedValue = "";
- break;
- }
- return $mixedValue;
- }
- }
- /** @} */
|