1
0

BxDolStudioModule.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 TridentStudio Trident Studio
  7. * @{
  8. */
  9. define('BX_DOL_STUDIO_MOD_TYPE_SETTINGS', 'settings');
  10. define('BX_DOL_STUDIO_MOD_TYPE_DEFAULT', BX_DOL_STUDIO_MOD_TYPE_SETTINGS);
  11. class BxDolStudioModule extends BxTemplStudioPage
  12. {
  13. protected $sModule;
  14. protected $aModule;
  15. protected $sPage;
  16. protected $sPageDefault = BX_DOL_STUDIO_MOD_TYPE_DEFAULT;
  17. function __construct($sModule = "", $sPage = "")
  18. {
  19. parent::__construct($sModule);
  20. $this->oDb = new BxDolStudioModulesQuery();
  21. $this->sPageRssHelpObject = 'sys_studio_module_help';
  22. $this->sModule = '';
  23. if(is_string($sModule) && !empty($sModule))
  24. $this->sModule = $sModule;
  25. $this->sPage = $this->sPageDefault;
  26. if(is_string($sPage) && !empty($sPage))
  27. $this->sPage = $sPage;
  28. }
  29. public static function getObjectInstance($sModule = "", $sPage = "", $bInit = true)
  30. {
  31. $oModuleDb = BxDolModuleQuery::getInstance();
  32. $sClass = 'BxTemplStudioModule';
  33. if($sModule != '' && $oModuleDb->isModuleByName($sModule)) {
  34. $aModule = $oModuleDb->getModuleByName($sModule);
  35. if(file_exists(BX_DIRECTORY_PATH_MODULES . $aModule['path'] . 'classes/' . $aModule['class_prefix'] . 'StudioPage.php')) {
  36. bx_import('StudioPage', $aModule);
  37. $sClass = $aModule['class_prefix'] . 'StudioPage';
  38. }
  39. }
  40. $oObject = new $sClass($sModule, $sPage);
  41. if($bInit)
  42. $oObject->init();
  43. return $oObject;
  44. }
  45. public function init()
  46. {
  47. $this->checkAction();
  48. $this->aModule = $this->oDb->getModuleByName($this->sModule);
  49. if(empty($this->aModule) || !is_array($this->aModule))
  50. BxDolStudioTemplate::getInstance()->displayPageNotFound();
  51. $this->sPageRssHelpUrl = $this->aModule['help_url'];
  52. $this->sPageRssHelpId = $this->aModule['name'];
  53. $this->addMarkers(array(
  54. 'module_name' => $this->aModule['name'],
  55. 'module_uri' => $this->aModule['uri'],
  56. 'module_title' => $this->aModule['title'],
  57. ));
  58. $this->addAction(array(
  59. 'type' => 'switcher',
  60. 'name' => 'activate',
  61. 'caption' => '_adm_txt_pca_active',
  62. 'checked' => (int)$this->aModule['enabled'] == 1,
  63. 'onchange' => "javascript:" . $this->getPageJsObject() . ".activate('" . $this->sModule . "', this)"
  64. ), false);
  65. }
  66. public function checkAction()
  67. {
  68. $sAction = bx_get('mod_action');
  69. if($sAction === false)
  70. return;
  71. $sAction = bx_process_input($sAction);
  72. $aResult = array('code' => 1, 'message' => _t('_adm_mod_err_cannot_process_action'));
  73. switch($sAction) {
  74. case 'activate':
  75. $sValue = bx_process_input(bx_get('mod_value'));
  76. if(empty($sValue))
  77. break;
  78. $aResult = $this->activate($sValue);
  79. break;
  80. }
  81. if(!empty($aResult['message']))
  82. $aResult['message'] = BxTemplStudioFunctions::getInstance()->transBox('', BxDolStudioTemplate::getInstance()->parseHtmlByName('mod_action_result.html', array(
  83. 'content' => $aResult['message'])
  84. ));
  85. echo json_encode($aResult);
  86. exit;
  87. }
  88. public function activate($sModule)
  89. {
  90. $aModule = $this->oDb->getModuleByName($sModule);
  91. if(empty($aModule) || !is_array($aModule))
  92. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  93. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], ((int)$aModule['enabled'] == 0 ? 'enable' : 'disable'), array('html_response' => true));
  94. if($aResult['code'] != 0)
  95. return $aResult;
  96. $oTemplate = BxDolStudioTemplate::getInstance();
  97. $aResult = array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  98. if((int)$aModule['enabled'] == 0) {
  99. $aResult['content'] = $oTemplate->parseHtmlByName('page_content_2_col.html', array(
  100. 'page_menu_code' => $this->getPageMenu(),
  101. 'page_main_code' => $this->getPageCode()
  102. ));
  103. } else
  104. $aResult['content'] = "";
  105. return $aResult;
  106. }
  107. }
  108. /** @} */