BxDolStudioModule.php 3.3 KB

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