BxDolStudioSettings.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  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 DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. defined('BX_DOL') or die('hack attempt');
  10. bx_import('BxTemplStudioPage');
  11. bx_import('BxDolStudioSettingsQuery');
  12. define('BX_DOL_STUDIO_STG_TYPE_SYSTEM', 'system');
  13. define('BX_DOL_STUDIO_STG_TYPE_DEFAULT', BX_DOL_STUDIO_STG_TYPE_SYSTEM);
  14. define('BX_DOL_STUDIO_STG_GROUP_SYSTEM', 'system');
  15. define('BX_DOL_STUDIO_STG_GROUP_MODULES', 'modules');
  16. define('BX_DOL_STUDIO_STG_GROUP_LANGUAGES', 'languages');
  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. protected $sType;
  22. protected $sCategory;
  23. protected $aCategories;
  24. protected $aCustomCategories;
  25. function BxDolStudioSettings($sType = '', $sCategory = '') {
  26. parent::BxTemplStudioPage('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. $oJson = new Services_JSON();
  47. echo $oJson->encode($aResult);
  48. }
  49. exit;
  50. }
  51. }
  52. function saveChanges(&$oForm) {
  53. $aCategories = explode(',', $oForm->getCleanValue('categories'));
  54. foreach ($aCategories as $sCategory) {
  55. $aOptions = array();
  56. $iOptions = $this->oDb->getOptions(array('type' => 'by_category_name', '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. $oFunction = create_function('$arg0', $aOption['check']);
  62. if(!$oFunction($aData[$aOption['name']])) {
  63. $this->sCategory = $sCategory;
  64. return $this->getJsResult("'" . $aOption['title'] . "' " . $aOption['check_error'], false);
  65. }
  66. }
  67. if(isset($aData[$aOption['name']]))
  68. $aData[$aOption['name']] = $this->getProcessedValue($aOption, $aData[$aOption['name']]);
  69. else
  70. $aData[$aOption['name']] = $this->getEmptyValue($aOption);
  71. $this->oDb->setParam($aOption['name'], $aData[$aOption['name']]);
  72. }
  73. }
  74. return $this->getJsResult('_adm_stg_scs_save');
  75. }
  76. protected function getProcessedValue($aOption, $mixedValue) {
  77. if(is_array($mixedValue))
  78. $mixedValue = implode(',', $mixedValue);
  79. return $mixedValue;
  80. }
  81. protected function getEmptyValue($aOption) {
  82. $mixedValue = '';
  83. switch($aOption['type']) {
  84. case 'digit':
  85. $mixedValue = 0;
  86. break;
  87. case 'select':
  88. if (BxDolService::isSerializedService($aOption['extra']))
  89. $aValues = BxDolService::callSerialized($aOption['extra']);
  90. else
  91. $aValues = explode(',', $aOption['extra']);
  92. $mixedValue = $aValues[0];
  93. break;
  94. case 'text':
  95. case 'checkbox':
  96. case 'file':
  97. $mixedValue = "";
  98. break;
  99. }
  100. return $mixedValue;
  101. }
  102. }
  103. /** @} */