BxDolStudioSettings.php 5.1 KB

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