BxBaseStudioPolyglotKeys.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  8. * @{
  9. */
  10. class BxBaseStudioPolyglotKeys extends BxDolStudioPolyglotKeys
  11. {
  12. function __construct($aOptions, $oTemplate = false)
  13. {
  14. parent::__construct($aOptions, $oTemplate);
  15. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_pgt_btn_edit_title');
  16. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_pgt_btn_delete_title');
  17. }
  18. public function performActionAdd()
  19. {
  20. $sAction = 'add';
  21. $aLanguages = array();
  22. $iLanguages = $this->oDb->getLanguagesBy(array('type' => 'all_key_id'), $aLanguages);
  23. $aForm = array(
  24. 'form_attrs' => array(
  25. 'id' => 'adm-lang-new-key-form',
  26. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  27. 'method' => 'post'
  28. ),
  29. 'params' => array(
  30. 'db' => array(
  31. 'table' => 'sys_localization_keys',
  32. 'key' => 'ID',
  33. 'uri' => '',
  34. 'uri_title' => '',
  35. 'submit_name' => 'do_submit'
  36. ),
  37. ),
  38. 'inputs' => array(
  39. 'key' => array(
  40. 'type' => 'text',
  41. 'name' => 'key',
  42. 'caption' => _t('_adm_pgt_txt_nkp_key_name'),
  43. 'value' => '',
  44. 'db' => array (
  45. 'pass' => 'Xss',
  46. ),
  47. ),
  48. 'category_id' => array(
  49. 'type' => 'select',
  50. 'name' => 'category_id',
  51. 'caption' => _t('_adm_pgt_txt_nkp_module'),
  52. 'values' => $this->oDb->getCategories(),
  53. 'value' => BX_DOL_STUDIO_PK_CATEGORY_CUSTOM,
  54. 'db' => array (
  55. 'pass' => 'Int',
  56. ),
  57. ),
  58. )
  59. );
  60. foreach($aLanguages as $aLanguage) {
  61. $sName = 'language_' . $aLanguage['id'];
  62. $aForm['inputs'][$sName] = array(
  63. 'type' => 'textarea',
  64. 'name' => $sName,
  65. 'caption' => $aLanguage['title'],
  66. 'value' => '',
  67. 'db' => array (
  68. 'pass' => 'XssHtml',
  69. ),
  70. );
  71. }
  72. $aForm['inputs'] = array_merge($aForm['inputs'], array(
  73. 'languages' => array(
  74. 'type' => 'hidden',
  75. 'name' => 'languages',
  76. 'value' => implode(',', array_keys($aLanguages)),
  77. 'db' => array (
  78. 'pass' => 'Xss',
  79. ),
  80. ),
  81. 'controls' => array(
  82. 'name' => 'controls',
  83. 'type' => 'input_set',
  84. array(
  85. 'type' => 'submit',
  86. 'name' => 'do_submit',
  87. 'value' => _t('_adm_pgt_btn_nkp_create'),
  88. ),
  89. array (
  90. 'type' => 'reset',
  91. 'name' => 'close',
  92. 'value' => _t('_adm_pgt_btn_nkp_close'),
  93. 'attrs' => array(
  94. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  95. 'class' => 'bx-def-margin-sec-left',
  96. ),
  97. )
  98. )
  99. ));
  100. $oForm = new BxTemplStudioFormView($aForm);
  101. $oForm->initChecker();
  102. if($oForm->isSubmittedAndValid()) {
  103. $mixedResult = $this->add($oForm);
  104. if(is_int($mixedResult))
  105. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  106. else
  107. $aRes = array('msg' => $mixedResult);
  108. $this->_echoResultJson($aRes, true);
  109. }
  110. else {
  111. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-lang-new-key-popup', _t('_adm_pgt_txt_nkp_add_popup'), $this->_oTemplate->parseHtmlByName('pgt_new_key.html', array(
  112. 'form_id' => $aForm['form_attrs']['id'],
  113. 'form' => $oForm->getCode(true),
  114. 'object' => $this->_sObject,
  115. 'action' => $sAction
  116. )));
  117. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  118. }
  119. }
  120. public function performActionEdit()
  121. {
  122. $oTemplate = BxDolStudioTemplate::getInstance();
  123. $aIds = bx_get('ids');
  124. if(!$aIds || !is_array($aIds)) {
  125. $iId = (int)bx_get('id');
  126. if(!$iId) {
  127. $this->_echoResultJson(array());
  128. exit;
  129. }
  130. $aIds = array($iId);
  131. }
  132. $iId = $aIds[0];
  133. $sAction = 'edit';
  134. $aLanguages = array();
  135. $iLanguages = $this->oDb->getLanguagesBy(array('type' => 'all_key_id'), $aLanguages);
  136. $aKey = $this->oDb->getKeyFullInfo($iId);
  137. $aForm = array(
  138. 'form_attrs' => array(
  139. 'id' => 'adm-lang-edit-key-form',
  140. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  141. 'method' => 'post'
  142. ),
  143. 'params' => array(
  144. 'db' => array(
  145. 'table' => 'sys_localization_keys',
  146. 'key' => 'ID',
  147. 'uri' => '',
  148. 'uri_title' => '',
  149. 'submit_name' => 'do_submit'
  150. ),
  151. ),
  152. 'inputs' => array(
  153. 'id' => array(
  154. 'type' => 'hidden',
  155. 'name' => 'id',
  156. 'value' => $iId,
  157. 'db' => array (
  158. 'pass' => 'Int',
  159. ),
  160. ),
  161. )
  162. );
  163. foreach($aLanguages as $aLanguage) {
  164. $sName = 'language_' . $aLanguage['id'];
  165. $aForm['inputs'][$sName] = array(
  166. 'type' => 'textarea',
  167. 'name' => $sName,
  168. 'caption' => $aLanguage['title'],
  169. 'value' => isset($aKey['strings'][$aLanguage['name']]) ? $aKey['strings'][$aLanguage['name']]['string'] : '',
  170. 'db' => array (
  171. 'pass' => 'XssHtml',
  172. ),
  173. );
  174. }
  175. $aForm['inputs'] = array_merge($aForm['inputs'], array(
  176. 'languages' => array(
  177. 'type' => 'hidden',
  178. 'name' => 'languages',
  179. 'value' => implode(',', array_keys($aLanguages)),
  180. 'db' => array (
  181. 'pass' => 'Xss',
  182. ),
  183. ),
  184. 'controls' => array(
  185. 'name' => 'controls',
  186. 'type' => 'input_set',
  187. array(
  188. 'type' => 'submit',
  189. 'name' => 'do_submit',
  190. 'value' => _t('_adm_pgt_btn_nkp_save'),
  191. ),
  192. array (
  193. 'type' => 'reset',
  194. 'name' => 'close',
  195. 'value' => _t('_adm_pgt_btn_nkp_close'),
  196. 'attrs' => array(
  197. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  198. 'class' => 'bx-def-margin-sec-left',
  199. ),
  200. )
  201. )
  202. ));
  203. $oForm = new BxTemplStudioFormView($aForm);
  204. $oForm->initChecker();
  205. if($oForm->isSubmittedAndValid()) {
  206. $mixedResult = $this->edit($oForm);
  207. if(is_int($mixedResult))
  208. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  209. else
  210. $aRes = array('msg' => $mixedResult);
  211. $this->_echoResultJson($aRes, true);
  212. }
  213. else {
  214. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-lang-edit-key-popup', _t('_adm_pgt_txt_nkp_edit_popup', $aKey['key']), $this->_oTemplate->parseHtmlByName('pgt_new_key.html', array(
  215. 'form_id' => $aForm['form_attrs']['id'],
  216. 'form' => $oForm->getCode(true),
  217. 'object' => $this->_sObject,
  218. 'action' => $sAction
  219. )));
  220. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  221. }
  222. }
  223. public function performActionDelete()
  224. {
  225. $iAffected = 0;
  226. $aIds = bx_get('ids');
  227. if(!$aIds || !is_array($aIds)) {
  228. $this->_echoResultJson(array());
  229. exit;
  230. }
  231. $aIdsAffected = array ();
  232. foreach($aIds as $iId) {
  233. if(!BxDolStudioLanguagesUtils::getInstance()->deleteLanguageStringById($iId, 0, false))
  234. continue;
  235. $aIdsAffected[] = $iId;
  236. $iAffected++;
  237. }
  238. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_pgt_err_save')));
  239. }
  240. function getJsObject()
  241. {
  242. return 'oBxDolStudioPolyglotKeys';
  243. }
  244. function getCode($isDisplayHeader = true)
  245. {
  246. return $this->_oTemplate->parseHtmlByName('pgt_keys.html', array(
  247. 'content' => parent::getCode($isDisplayHeader),
  248. 'js_object' => $this->getJsObject(),
  249. 'grid_object' => $this->_sObject
  250. ));
  251. }
  252. protected function _addJsCss()
  253. {
  254. parent::_addJsCss();
  255. $this->_oTemplate->addJs(array('jquery.form.min.js', 'polyglot_keys.js'));
  256. $oForm = new BxTemplStudioFormView(array());
  257. $oForm->addCssJs();
  258. }
  259. protected function _getFilterControls ()
  260. {
  261. parent::_getFilterControls();
  262. $sContent = "";
  263. $oForm = new BxTemplStudioFormView(array());
  264. $aInputModules = array(
  265. 'type' => 'select',
  266. 'name' => 'module',
  267. 'attrs' => array(
  268. 'id' => 'bx-grid-module-' . $this->_sObject,
  269. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  270. ),
  271. 'values' => array(
  272. 'id-' . BX_DOL_LANGUAGE_CATEGORY_SYSTEM => '',
  273. 'id-' . BX_DOL_LANGUAGE_CATEGORY_CUSTOM => ''
  274. )
  275. );
  276. $aCategories = $aCounter = array();
  277. $this->oDb->getCategoriesBy(array('type' => 'all'), $aCategories, false);
  278. $this->oDb->getKeysBy(array('type' => 'counter_by_category'), $aCounter, false);
  279. foreach($aCategories as $aCategory)
  280. $aInputModules['values']['id-' . $aCategory['id']] = $aCategory['name'] . " (" . (isset($aCounter[$aCategory['id']]) ? $aCounter[$aCategory['id']] : "0") . ")";;
  281. $aInputModules['values'] = array_merge(array('id-0' => _t('_adm_pgt_txt_all_modules')), $aInputModules['values']);
  282. $sContent .= $oForm->genRow($aInputModules);
  283. $aInputSearch = array(
  284. 'type' => 'text',
  285. 'name' => 'keyword',
  286. 'attrs' => array(
  287. 'id' => 'bx-grid-search-' . $this->_sObject,
  288. 'onKeyup' => 'javascript:$(this).off(); ' . $this->getJsObject() . '.onChangeFilter()'
  289. )
  290. );
  291. $sContent .= $oForm->genRow($aInputSearch);
  292. return $sContent;
  293. }
  294. }
  295. /** @} */