BxDolStudioLanguage.php 4.0 KB

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