BxDolStudioModule.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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('BxDolStudioModulesQuery');
  11. define('BX_DOL_STUDIO_MOD_TYPE_SETTINGS', 'settings');
  12. define('BX_DOL_STUDIO_MOD_TYPE_DEFAULT', BX_DOL_STUDIO_MOD_TYPE_SETTINGS);
  13. class BxDolStudioModule extends BxTemplStudioPage
  14. {
  15. protected $sModule;
  16. protected $aModule;
  17. protected $sPage;
  18. protected $sPageDefault = BX_DOL_STUDIO_MOD_TYPE_DEFAULT;
  19. function __construct($sModule = "", $sPage = "")
  20. {
  21. parent::__construct($sModule);
  22. $this->oDb = new BxDolStudioModulesQuery();
  23. $this->sModule = '';
  24. if(is_string($sModule) && !empty($sModule))
  25. $this->sModule = $sModule;
  26. $this->sPage = $this->sPageDefault;
  27. if(is_string($sPage) && !empty($sPage))
  28. $this->sPage = $sPage;
  29. }
  30. function init()
  31. {
  32. //--- Check Actions ---//
  33. if(($sAction = bx_get('mod_action')) !== false) {
  34. $sAction = bx_process_input($sAction);
  35. $aResult = array('code' => 1, 'message' => _t('_adm_mod_err_cannot_process_action'));
  36. switch($sAction) {
  37. case 'activate':
  38. $sValue = bx_process_input(bx_get('mod_value'));
  39. if(empty($sValue))
  40. break;
  41. $aResult = $this->activate($sValue);
  42. break;
  43. }
  44. echo json_encode($aResult);
  45. exit;
  46. }
  47. $this->aModule = $this->oDb->getModuleByName($this->sModule);
  48. if(empty($this->aModule) || !is_array($this->aModule))
  49. BxDolStudioTemplate::getInstance()->displayPageNotFound();
  50. $this->addAction(array(
  51. 'type' => 'switcher',
  52. 'name' => 'activate',
  53. 'caption' => '_adm_txt_pca_active',
  54. 'checked' => (int)$this->aModule['enabled'] == 1,
  55. 'onchange' => "javascript:" . $this->getPageJsObject() . ".activate('" . $this->sModule . "', this)"
  56. ), false);
  57. }
  58. function activate($sModule)
  59. {
  60. $aModule = $this->oDb->getModuleByName($sModule);
  61. if(empty($aModule) || !is_array($aModule))
  62. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  63. bx_import('BxDolStudioInstallerUtils');
  64. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  65. $aResult = (int)$aModule['enabled'] == 0 ? $oInstallerUtils->perform($aModule['path'], 'enable') : $oInstallerUtils->perform($aModule['path'], 'disable');
  66. if($aResult['code'] != 0)
  67. return $aResult;
  68. bx_import('BxDolStudioTemplate');
  69. $oTemplate = BxDolStudioTemplate::getInstance();
  70. $aResult = array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  71. if((int)$aModule['enabled'] == 0) {
  72. $aResult['content'] = $oTemplate->parseHtmlByName('page_content_2_col.html', array(
  73. 'page_menu_code' => $this->getPageMenu(),
  74. 'page_main_code' => $this->getPageCode()
  75. ));
  76. } else
  77. $aResult['content'] = "";
  78. return $aResult;
  79. }
  80. }
  81. /** @} */