1
0

BxDolStudioModule.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. //--- Check Actions ---//
  48. if(($sAction = bx_get('mod_action')) !== false) {
  49. $sAction = bx_process_input($sAction);
  50. $aResult = array('code' => 1, 'message' => _t('_adm_mod_err_cannot_process_action'));
  51. switch($sAction) {
  52. case 'activate':
  53. $sValue = bx_process_input(bx_get('mod_value'));
  54. if(empty($sValue))
  55. break;
  56. $aResult = $this->activate($sValue);
  57. break;
  58. }
  59. echo json_encode($aResult);
  60. exit;
  61. }
  62. $this->aModule = $this->oDb->getModuleByName($this->sModule);
  63. if(empty($this->aModule) || !is_array($this->aModule))
  64. BxDolStudioTemplate::getInstance()->displayPageNotFound();
  65. $this->sPageRssHelpUrl = $this->aModule['help_url'];
  66. $this->sPageRssHelpId = $this->aModule['name'];
  67. $this->addMarkers(array(
  68. 'module_name' => $this->aModule['name'],
  69. 'module_uri' => $this->aModule['uri'],
  70. 'module_title' => $this->aModule['title'],
  71. ));
  72. $this->addAction(array(
  73. 'type' => 'switcher',
  74. 'name' => 'activate',
  75. 'caption' => '_adm_txt_pca_active',
  76. 'checked' => (int)$this->aModule['enabled'] == 1,
  77. 'onchange' => "javascript:" . $this->getPageJsObject() . ".activate('" . $this->sModule . "', this)"
  78. ), false);
  79. }
  80. public function activate($sModule)
  81. {
  82. $aModule = $this->oDb->getModuleByName($sModule);
  83. if(empty($aModule) || !is_array($aModule))
  84. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  85. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], ((int)$aModule['enabled'] == 0 ? 'enable' : 'disable'), array('html_response' => true));
  86. if($aResult['code'] != 0)
  87. return $aResult;
  88. $oTemplate = BxDolStudioTemplate::getInstance();
  89. $aResult = array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  90. if((int)$aModule['enabled'] == 0) {
  91. $aResult['content'] = $oTemplate->parseHtmlByName('page_content_2_col.html', array(
  92. 'page_menu_code' => $this->getPageMenu(),
  93. 'page_main_code' => $this->getPageCode()
  94. ));
  95. } else
  96. $aResult['content'] = "";
  97. return $aResult;
  98. }
  99. }
  100. /** @} */