BxDolStudioDesigner.php 4.7 KB

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