BxDolStudioDesigner.php 4.8 KB

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