BxDolStudioDesigner.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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('BxDolStudioDesignerQuery');
  12. define('BX_DOL_STUDIO_DSG_TYPE_GENERAL', 'general');
  13. define('BX_DOL_STUDIO_DSG_TYPE_LOGO', 'logo');
  14. define('BX_DOL_STUDIO_DSG_TYPE_ICON', 'icon');
  15. define('BX_DOL_STUDIO_DSG_TYPE_DEFAULT', 'general');
  16. class BxDolStudioDesigner extends BxTemplStudioPage {
  17. protected $sPage;
  18. function BxDolStudioDesigner($sPage = "") {
  19. parent::BxTemplStudioPage('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 'get-page-by-type':
  35. $sValue = bx_process_input(bx_get('dsg_value'));
  36. if(empty($sValue))
  37. break;
  38. $this->sPage = $sValue;
  39. $aResult = array('code' => 0, 'content' => $this->getPageCode());
  40. break;
  41. }
  42. $oJson = new Services_JSON();
  43. echo $oJson->encode($aResult);
  44. exit;
  45. }
  46. }
  47. function submitLogo(&$oForm) {
  48. $iProfileId = getLoggedId();
  49. if(!empty($_FILES['image']['tmp_name'])) {
  50. bx_import('BxDolStorage');
  51. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  52. if(!$this->deleteLogo())
  53. return $this->getJsResult('_adm_dsg_err_remove_old_logo');
  54. $iId = $oStorage->storeFileFromForm($_FILES['image'], false, $iProfileId);
  55. if($iId === false) {
  56. $this->oDb->setParam('sys_site_logo', 0);
  57. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  58. }
  59. $this->oDb->setParam('sys_site_logo', $iId);
  60. $oStorage->afterUploadCleanup($iId, $iProfileId);
  61. }
  62. $this->oDb->setParam('sys_site_logo_alt', $oForm->getCleanValue('alt'));
  63. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_LOGO);
  64. }
  65. function deleteLogo() {
  66. $iProfileId = getLoggedId();
  67. bx_import('BxDolStorage');
  68. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  69. $iId = (int)$this->oDb->getParam('sys_site_logo');
  70. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  71. return false;
  72. $this->oDb->setParam('sys_site_logo', 0);
  73. return true;
  74. }
  75. function submitIcon(&$oForm) {
  76. $iProfileId = getLoggedId();
  77. bx_import('BxDolStorage');
  78. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  79. $iId = (int)$this->oDb->getParam('sys_site_icon');
  80. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  81. return $this->getJsResult('_adm_dsg_err_remove_old_icon');
  82. $iId = $oStorage->storeFileFromForm($_FILES['image'], true, $iProfileId);
  83. if($iId === false) {
  84. $this->oDb->setParam('sys_site_icon', 0);
  85. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  86. }
  87. $this->oDb->setParam('sys_site_icon', $iId);
  88. $oStorage->afterUploadCleanup($iId, $iProfileId);
  89. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_ICON);
  90. }
  91. }
  92. /** @} */