BxDolStudioModule.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. public 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->addMarkers(array(
  51. 'module_name' => $this->aModule['name'],
  52. 'module_uri' => $this->aModule['uri'],
  53. 'module_title' => $this->aModule['title']
  54. ));
  55. $this->addAction(array(
  56. 'type' => 'switcher',
  57. 'name' => 'activate',
  58. 'caption' => '_adm_txt_pca_active',
  59. 'checked' => (int)$this->aModule['enabled'] == 1,
  60. 'onchange' => "javascript:" . $this->getPageJsObject() . ".activate('" . $this->sModule . "', this)"
  61. ), false);
  62. $this->sPageRssHelpUrl = $this->aModule['help_url'];
  63. }
  64. public function activate($sModule)
  65. {
  66. $aModule = $this->oDb->getModuleByName($sModule);
  67. if(empty($aModule) || !is_array($aModule))
  68. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  69. bx_import('BxDolStudioInstallerUtils');
  70. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  71. $aResult = (int)$aModule['enabled'] == 0 ? $oInstallerUtils->perform($aModule['path'], 'enable') : $oInstallerUtils->perform($aModule['path'], 'disable');
  72. if($aResult['code'] != 0)
  73. return $aResult;
  74. bx_import('BxDolStudioTemplate');
  75. $oTemplate = BxDolStudioTemplate::getInstance();
  76. $aResult = array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  77. if((int)$aModule['enabled'] == 0) {
  78. $aResult['content'] = $oTemplate->parseHtmlByName('page_content_2_col.html', array(
  79. 'page_menu_code' => $this->getPageMenu(),
  80. 'page_main_code' => $this->getPageCode()
  81. ));
  82. } else
  83. $aResult['content'] = "";
  84. return $aResult;
  85. }
  86. }
  87. /** @} */