BxDolStudioDesigner.php 4.6 KB

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