BxDolStudioDesigner.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_DSG_TYPE_GENERAL', 'general');
  10. define('BX_DOL_STUDIO_DSG_TYPE_LOGO', 'logo');
  11. define('BX_DOL_STUDIO_DSG_TYPE_ICON', 'icon');
  12. define('BX_DOL_STUDIO_DSG_TYPE_COVER', 'cover');
  13. define('BX_DOL_STUDIO_DSG_TYPE_SETTINGS', 'settings');
  14. define('BX_DOL_STUDIO_DSG_TYPE_DEFAULT', 'general');
  15. class BxDolStudioDesigner extends BxTemplStudioPage
  16. {
  17. protected $sPage;
  18. function __construct($sPage = "")
  19. {
  20. parent::__construct('designer');
  21. $this->oDb = new BxDolStudioDesignerQuery();
  22. $this->sPage = BX_DOL_STUDIO_DSG_TYPE_DEFAULT;
  23. if(is_string($sPage) && !empty($sPage))
  24. $this->sPage = $sPage;
  25. //--- Check actions ---//
  26. if(($sAction = bx_get('dsg_action')) !== false) {
  27. $sAction = bx_process_input($sAction);
  28. $aResult = array('code' => 1, 'message' => _t('_adm_dsg_err_cannot_process_action'));
  29. switch($sAction) {
  30. case 'delete_logo':
  31. $aResult = array('code' => 0, 'message' => '');
  32. if(!$this->deleteLogo())
  33. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_remove_old_logo'));
  34. break;
  35. case 'make_default':
  36. $aResult = array('code' => 0, 'message' => '');
  37. if(!$this->makeDefault())
  38. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_make_default'));
  39. break;
  40. case 'get-page-by-type':
  41. $sValue = bx_process_input(bx_get('dsg_value'));
  42. if(empty($sValue))
  43. break;
  44. $this->sPage = $sValue;
  45. $aResult = array('code' => 0, 'content' => $this->getPageCode());
  46. break;
  47. }
  48. echo json_encode($aResult);
  49. exit;
  50. }
  51. }
  52. function makeDefault()
  53. {
  54. $sValue = bx_get('dsg_value');
  55. if($sValue === false)
  56. return false;
  57. $sValue = bx_process_input($sValue);
  58. return $this->oDb->setParam('template', $sValue);
  59. }
  60. function submitLogo(&$oForm)
  61. {
  62. $iProfileId = getLoggedId();
  63. if(!empty($_FILES['image']['tmp_name'])) {
  64. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  65. if(!$this->deleteLogo())
  66. return $this->getJsResult('_adm_dsg_err_remove_old_logo');
  67. $iId = $oStorage->storeFileFromForm($_FILES['image'], false, $iProfileId);
  68. if($iId === false) {
  69. $this->oDb->setParam('sys_site_logo', 0);
  70. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  71. }
  72. $this->oDb->setParam('sys_site_logo', $iId);
  73. $oStorage->afterUploadCleanup($iId, $iProfileId);
  74. }
  75. $this->oDb->setParam('sys_site_logo_alt', $oForm->getCleanValue('alt'));
  76. $this->oDb->setParam('sys_site_logo_width', $oForm->getCleanValue('width'));
  77. $this->oDb->setParam('sys_site_logo_height', $oForm->getCleanValue('height'));
  78. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_LOGO);
  79. }
  80. function deleteLogo()
  81. {
  82. $iProfileId = getLoggedId();
  83. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  84. $iId = (int)getParam('sys_site_logo');
  85. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  86. return false;
  87. $this->oDb->setParam('sys_site_logo', 0);
  88. return true;
  89. }
  90. function submitIcon(&$oForm)
  91. {
  92. $iProfileId = getLoggedId();
  93. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  94. $iId = (int)getParam('sys_site_icon');
  95. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  96. return $this->getJsResult('_adm_dsg_err_remove_old_icon');
  97. $iId = $oStorage->storeFileFromForm($_FILES['image'], true, $iProfileId);
  98. if($iId === false) {
  99. $this->oDb->setParam('sys_site_icon', 0);
  100. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  101. }
  102. $this->oDb->setParam('sys_site_icon', $iId);
  103. $oStorage->afterUploadCleanup($iId, $iProfileId);
  104. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_ICON);
  105. }
  106. function submitCover(&$oForm)
  107. {
  108. $this->oDb->setParam('sys_site_cover_code', $oForm->getCleanValue('code'));
  109. $this->oDb->setParam('sys_site_cover_enabled', $oForm->getCleanValue('enabled') == 'on' ? 'on' : '');
  110. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_COVER);
  111. }
  112. }
  113. /** @} */