BxDolStudioLanguage.php 4.0 KB

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