BxDolStudioDesigner.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. bx_import('BxTemplStudioPage');
  10. bx_import('BxDolStudioDesignerQuery');
  11. define('BX_DOL_STUDIO_DSG_TYPE_GENERAL', 'general');
  12. define('BX_DOL_STUDIO_DSG_TYPE_LOGO', 'logo');
  13. define('BX_DOL_STUDIO_DSG_TYPE_ICON', 'icon');
  14. define('BX_DOL_STUDIO_DSG_TYPE_SETTINGS', 'settings');
  15. define('BX_DOL_STUDIO_DSG_TYPE_DEFAULT', 'general');
  16. class BxDolStudioDesigner extends BxTemplStudioPage {
  17. protected $sPage;
  18. function __construct($sPage = "") {
  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. $oJson = new Services_JSON();
  48. echo $oJson->encode($aResult);
  49. exit;
  50. }
  51. }
  52. function makeDefault() {
  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. $iProfileId = getLoggedId();
  61. if(!empty($_FILES['image']['tmp_name'])) {
  62. bx_import('BxDolStorage');
  63. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  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. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_LOGO);
  76. }
  77. function deleteLogo() {
  78. $iProfileId = getLoggedId();
  79. bx_import('BxDolStorage');
  80. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  81. $iId = (int)getParam('sys_site_logo');
  82. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  83. return false;
  84. $this->oDb->setParam('sys_site_logo', 0);
  85. return true;
  86. }
  87. function submitIcon(&$oForm) {
  88. $iProfileId = getLoggedId();
  89. bx_import('BxDolStorage');
  90. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  91. $iId = (int)getParam('sys_site_icon');
  92. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  93. return $this->getJsResult('_adm_dsg_err_remove_old_icon');
  94. $iId = $oStorage->storeFileFromForm($_FILES['image'], true, $iProfileId);
  95. if($iId === false) {
  96. $this->oDb->setParam('sys_site_icon', 0);
  97. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  98. }
  99. $this->oDb->setParam('sys_site_icon', $iId);
  100. $oStorage->afterUploadCleanup($iId, $iProfileId);
  101. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_ICON);
  102. }
  103. }
  104. /** @} */