BxDolStudioModule.php 3.3 KB

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