BxDolStudioSettings.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentStudio Trident Studio
  7. * @{
  8. */
  9. define('BX_DOL_STUDIO_STG_TYPE_SYSTEM', 'system');
  10. define('BX_DOL_STUDIO_STG_TYPE_DEFAULT', BX_DOL_STUDIO_STG_TYPE_SYSTEM);
  11. define('BX_DOL_STUDIO_STG_GROUP_SYSTEM', 'system');
  12. define('BX_DOL_STUDIO_STG_GROUP_MODULES', 'modules');
  13. define('BX_DOL_STUDIO_STG_GROUP_LANGUAGES', 'languages');
  14. define('BX_DOL_STUDIO_STG_GROUP_TEMPLATES', 'templates');
  15. define('BX_DOL_STUDIO_STG_CATEGORY_SYSTEM', 'system');
  16. define('BX_DOL_STUDIO_STG_CATEGORY_LANGUAGES', 'languages');
  17. define('BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES', 'templates');
  18. class BxDolStudioSettings extends BxTemplStudioPage
  19. {
  20. protected $sType;
  21. protected $sCategory;
  22. protected $aCategories;
  23. protected $aCustomCategories;
  24. function __construct($sType = '', $sCategory = '')
  25. {
  26. parent::__construct('settings');
  27. $this->oDb = new BxDolStudioSettingsQuery();
  28. $this->sType = BX_DOL_STUDIO_STG_TYPE_DEFAULT;
  29. if(is_string($sType) && !empty($sType))
  30. $this->sType = $sType;
  31. $this->sCategory = '';
  32. if(is_string($sCategory) && !empty($sCategory))
  33. $this->sCategory = $sCategory;
  34. //--- Check actions ---//
  35. if(($sAction = bx_get('stg_action')) !== false && ($sValue = bx_get('stg_value')) !== false) {
  36. $sAction = bx_process_input($sAction);
  37. $sValue = bx_process_input($sValue);
  38. $aResult = array('code' => 0, 'message' => '');
  39. if(!empty($sAction) && !empty($sValue)) {
  40. switch($sAction) {
  41. case 'get-page-by-type':
  42. $this->sType = $sValue;
  43. $aResult['content'] = $this->getPageCode();
  44. break;
  45. }
  46. echo json_encode($aResult);
  47. }
  48. exit;
  49. }
  50. }
  51. function saveChanges(&$oForm)
  52. {
  53. $aCategories = explode(',', $oForm->getCleanValue('categories'));
  54. foreach ($aCategories as $sCategory) {
  55. $aOptions = array();
  56. $iOptions = $this->oDb->getOptions(array('type' => 'by_category_name_full', 'value' => $sCategory), $aOptions);
  57. $aData = array();
  58. foreach($aOptions as $aOption) {
  59. $aData[$aOption['name']] = $oForm->getCleanValue($aOption['name']);
  60. if(!empty($aOption['check'])) {
  61. $sCheckerHelper = '';
  62. if(!empty($aOption['type_name']) && BxDolRequest::serviceExists($aOption['type_name'], 'get_settings_checker_helper'))
  63. $sCheckerHelper = BxDolService::call($aOption['type_name'], 'get_settings_checker_helper');
  64. if($sCheckerHelper == '') {
  65. bx_import('BxDolStudioForm');
  66. $sCheckerHelper = 'BxDolStudioFormCheckerHelper';
  67. }
  68. $oChecker = new $sCheckerHelper();
  69. $aCheckFunction = array($oChecker, 'check' . bx_gen_method_name($aOption['check']));
  70. $aCheckFunctionParams = array($aData[$aOption['name']]);
  71. if(!empty($aOption['check_params']))
  72. $aCheckFunctionParams = array_merge($aCheckFunctionParams, unserialize($aOption['check_params']));
  73. if(is_callable($aCheckFunction) && !call_user_func_array($aCheckFunction, $aCheckFunctionParams)) {
  74. $this->sCategory = $sCategory;
  75. return $this->getJsResult(_t('_adm_stg_err_save_error_message', _t($aOption['caption']), _t($aOption['check_error'])), false);
  76. }
  77. }
  78. if(isset($aData[$aOption['name']]))
  79. $aData[$aOption['name']] = $this->getProcessedValue($aOption, $aData[$aOption['name']]);
  80. else
  81. $aData[$aOption['name']] = $this->getEmptyValue($aOption);
  82. $this->oDb->setParam($aOption['name'], $aData[$aOption['name']]);
  83. }
  84. }
  85. return $this->getJsResult('_adm_stg_scs_save');
  86. }
  87. protected function getProcessedValue($aOption, $mixedValue)
  88. {
  89. if(is_array($mixedValue))
  90. $mixedValue = implode(',', $mixedValue);
  91. return $mixedValue;
  92. }
  93. protected function getEmptyValue($aOption)
  94. {
  95. $mixedValue = '';
  96. switch($aOption['type']) {
  97. case 'digit':
  98. $mixedValue = 0;
  99. break;
  100. case 'select':
  101. if (BxDolService::isSerializedService($aOption['extra']))
  102. $aValues = BxDolService::callSerialized($aOption['extra']);
  103. else
  104. $aValues = explode(',', $aOption['extra']);
  105. $mixedValue = $aValues[0];
  106. break;
  107. case 'text':
  108. case 'checkbox':
  109. case 'file':
  110. $mixedValue = "";
  111. break;
  112. }
  113. return $mixedValue;
  114. }
  115. }
  116. /** @} */