BxDolStudioLanguage.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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('BxDolModuleQuery');
  10. bx_import('BxTemplStudioPage');
  11. bx_import('BxDolStudioLanguagesQuery');
  12. define('BX_DOL_STUDIO_LANG_DEFAULT', 'en');
  13. define('BX_DOL_STUDIO_LANG_TYPE_DEFAULT', 'general');
  14. class BxDolStudioLanguage extends BxTemplStudioPage {
  15. protected $oDb;
  16. protected $sLanguage;
  17. protected $aLanguage;
  18. function __construct($sLanguage, $sPage) {
  19. parent::__construct($sLanguage);
  20. $this->oDb = new BxDolStudioLanguagesQuery();
  21. $this->sLanguage = BX_DOL_STUDIO_LANG_DEFAULT;
  22. if(is_string($sLanguage) && !empty($sLanguage))
  23. $this->sLanguage = $sLanguage;
  24. $this->sPage = BX_DOL_STUDIO_LANG_TYPE_DEFAULT;
  25. if(is_string($sPage) && !empty($sPage))
  26. $this->sPage = $sPage;
  27. //--- Check actions ---//
  28. if(($sAction = bx_get('lang_action')) !== false) {
  29. $sAction = bx_process_input($sAction);
  30. $aResult = array('code' => 1, 'message' => _t('_adm_pgt_err_cannot_process_action'));
  31. switch($sAction) {
  32. case 'activate':
  33. $sValue = bx_process_input(bx_get('lang_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->aLanguage = BxDolModuleQuery::getInstance()->getModuleByName($this->sLanguage);
  44. if(empty($this->aLanguage) || !is_array($this->aLanguage))
  45. BxDolStudioTemplate::getInstance()->displayPageNotFound();
  46. $this->aPage['header'] = $this->aLanguage['title'];
  47. $this->aPage['caption'] = $this->aLanguage['title'];
  48. $this->addAction(array(
  49. 'type' => 'switcher',
  50. 'name' => 'activate',
  51. 'caption' => '_adm_txt_pca_active',
  52. 'checked' => (int)$this->aLanguage['enabled'] == 1,
  53. 'onchange' => "javascript:" . $this->getPageJsObject() . ".activate('" . $this->sLanguage . "', this)"
  54. ), false);
  55. }
  56. function activate($sLanguage) {
  57. $aLanguage = BxDolModuleQuery::getInstance()->getModuleByName($sLanguage);
  58. if(empty($aLanguage) || !is_array($aLanguage))
  59. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  60. $aLanguages = array();
  61. $iLanguages = $this->oDb->getLanguagesBy(array('type' => 'active'), $aLanguages);
  62. if($iLanguages == 1 && $aLanguages[0]['name'] == $sLanguage)
  63. return array('code' => 1, 'message' => _t('_adm_pgt_err_last_active'));
  64. $sLanguageDefault = getParam('lang_default');
  65. if($aLanguage['uri'] == $sLanguageDefault)
  66. return array('code' => 2, 'message' => _t('_adm_pgt_err_deactivate_default'));
  67. bx_import('BxDolStudioInstallerUtils');
  68. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  69. $aResult = (int)$aLanguage['enabled'] == 0 ? $oInstallerUtils->perform($aLanguage['path'], 'enable') : $oInstallerUtils->perform($aLanguage['path'], 'disable');
  70. if($aResult['code'] != 0)
  71. return $aResult;
  72. bx_import('BxDolStudioTemplate');
  73. $oTemplate = BxDolStudioTemplate::getInstance();
  74. $aResult = array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  75. if((int)$aLanguage['enabled'] == 0) {
  76. $aResult['content'] = $oTemplate->parseHtmlByName('page_content_2_col.html', array(
  77. 'page_menu_code' => $this->getPageMenu(),
  78. 'page_main_code' => $this->getPageCode()
  79. ));
  80. }
  81. else
  82. $aResult['content'] = "";
  83. return $aResult;
  84. }
  85. }
  86. /** @} */