BxBaseStudioPolyglotKeys.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  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?' . bx_encode_url_params($_GET, array('ids', '_r')),
  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. 'code' => 1,
  68. 'db' => array (
  69. 'pass' => 'XssHtml',
  70. ),
  71. );
  72. }
  73. $aForm['inputs'] = array_merge($aForm['inputs'], array(
  74. 'languages' => array(
  75. 'type' => 'hidden',
  76. 'name' => 'languages',
  77. 'value' => implode(',', array_keys($aLanguages)),
  78. 'db' => array (
  79. 'pass' => 'Xss',
  80. ),
  81. ),
  82. 'controls' => array(
  83. 'name' => 'controls',
  84. 'type' => 'input_set',
  85. array(
  86. 'type' => 'submit',
  87. 'name' => 'do_submit',
  88. 'value' => _t('_adm_pgt_btn_nkp_create'),
  89. ),
  90. array (
  91. 'type' => 'reset',
  92. 'name' => 'close',
  93. 'value' => _t('_adm_pgt_btn_nkp_close'),
  94. 'attrs' => array(
  95. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  96. 'class' => 'bx-def-margin-sec-left',
  97. ),
  98. )
  99. )
  100. ));
  101. $oForm = new BxTemplStudioFormView($aForm);
  102. $oForm->initChecker();
  103. if($oForm->isSubmittedAndValid()) {
  104. $mixedResult = $this->add($oForm);
  105. if(is_numeric($mixedResult))
  106. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  107. else
  108. $aRes = array('msg' => $mixedResult);
  109. echoJson($aRes);
  110. }
  111. else {
  112. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-lang-new-key-popup', _t('_adm_pgt_txt_nkp_add_popup'), $this->_oTemplate->parseHtmlByName('pgt_new_key.html', array(
  113. 'form_id' => $aForm['form_attrs']['id'],
  114. 'form' => $oForm->getCode(true),
  115. 'object' => $this->_sObject,
  116. 'action' => $sAction
  117. )));
  118. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  119. }
  120. }
  121. public function performActionEdit()
  122. {
  123. $oTemplate = BxDolStudioTemplate::getInstance();
  124. $aIds = bx_get('ids');
  125. if(!$aIds || !is_array($aIds)) {
  126. $iId = (int)bx_get('id');
  127. if(!$iId) {
  128. echoJson(array());
  129. exit;
  130. }
  131. $aIds = array($iId);
  132. }
  133. $iId = $aIds[0];
  134. $sAction = 'edit';
  135. $aLanguages = array();
  136. $iLanguages = $this->oDb->getLanguagesBy(array('type' => 'all_key_id'), $aLanguages);
  137. $aKey = $this->oDb->getKeyFullInfo($iId);
  138. $aForm = array(
  139. 'form_attrs' => array(
  140. 'id' => 'adm-lang-edit-key-form',
  141. 'action' => BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r')),
  142. 'method' => 'post'
  143. ),
  144. 'params' => array(
  145. 'db' => array(
  146. 'table' => 'sys_localization_keys',
  147. 'key' => 'ID',
  148. 'uri' => '',
  149. 'uri_title' => '',
  150. 'submit_name' => 'do_submit'
  151. ),
  152. ),
  153. 'inputs' => array(
  154. 'id' => array(
  155. 'type' => 'hidden',
  156. 'name' => 'id',
  157. 'value' => $iId,
  158. 'db' => array (
  159. 'pass' => 'Int',
  160. ),
  161. ),
  162. )
  163. );
  164. foreach($aLanguages as $aLanguage) {
  165. $sName = 'language_' . $aLanguage['id'];
  166. $aForm['inputs'][$sName] = array(
  167. 'type' => 'textarea',
  168. 'name' => $sName,
  169. 'caption' => $aLanguage['title'],
  170. 'value' => isset($aKey['strings'][$aLanguage['name']]) ? $aKey['strings'][$aLanguage['name']]['string'] : '',
  171. 'code' => 1,
  172. 'db' => array (
  173. 'pass' => 'XssHtml',
  174. ),
  175. );
  176. }
  177. $aForm['inputs'] = array_merge($aForm['inputs'], array(
  178. 'languages' => array(
  179. 'type' => 'hidden',
  180. 'name' => 'languages',
  181. 'value' => implode(',', array_keys($aLanguages)),
  182. 'db' => array (
  183. 'pass' => 'Xss',
  184. ),
  185. ),
  186. 'controls' => array(
  187. 'name' => 'controls',
  188. 'type' => 'input_set',
  189. array(
  190. 'type' => 'submit',
  191. 'name' => 'do_submit',
  192. 'value' => _t('_adm_pgt_btn_nkp_save'),
  193. ),
  194. array (
  195. 'type' => 'reset',
  196. 'name' => 'close',
  197. 'value' => _t('_adm_pgt_btn_nkp_close'),
  198. 'attrs' => array(
  199. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  200. 'class' => 'bx-def-margin-sec-left',
  201. ),
  202. )
  203. )
  204. ));
  205. $oForm = new BxTemplStudioFormView($aForm);
  206. $oForm->initChecker();
  207. if($oForm->isSubmittedAndValid()) {
  208. $mixedResult = $this->edit($oForm);
  209. if(is_int($mixedResult))
  210. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  211. else
  212. $aRes = array('msg' => $mixedResult);
  213. echoJson($aRes);
  214. }
  215. else {
  216. $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(
  217. 'form_id' => $aForm['form_attrs']['id'],
  218. 'form' => $oForm->getCode(true),
  219. 'object' => $this->_sObject,
  220. 'action' => $sAction
  221. )));
  222. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  223. }
  224. }
  225. public function performActionDelete()
  226. {
  227. $iAffected = 0;
  228. $aIds = bx_get('ids');
  229. if(!$aIds || !is_array($aIds)) {
  230. echoJson(array());
  231. exit;
  232. }
  233. $aIdsAffected = array ();
  234. foreach($aIds as $iId) {
  235. if(!BxDolStudioLanguagesUtils::getInstance()->deleteLanguageStringById($iId, 0, false))
  236. continue;
  237. $aIdsAffected[] = $iId;
  238. $iAffected++;
  239. }
  240. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_pgt_err_save')));
  241. }
  242. function getJsObject()
  243. {
  244. return 'oBxDolStudioPolyglotKeys';
  245. }
  246. function getCode($isDisplayHeader = true)
  247. {
  248. return $this->_oTemplate->parseHtmlByName('pgt_keys.html', array(
  249. 'content' => parent::getCode($isDisplayHeader),
  250. 'js_object' => $this->getJsObject(),
  251. 'grid_object' => $this->_sObject
  252. ));
  253. }
  254. protected function _addJsCss()
  255. {
  256. parent::_addJsCss();
  257. $this->_oTemplate->addJs(array('jquery.form.min.js', 'polyglot_keys.js'));
  258. $oForm = new BxTemplStudioFormView(array());
  259. $oForm->addCssJs();
  260. }
  261. protected function _getFilterControls ()
  262. {
  263. parent::_getFilterControls();
  264. $sContent = "";
  265. $oForm = new BxTemplStudioFormView(array());
  266. $aInputModules = array(
  267. 'type' => 'select',
  268. 'name' => 'module',
  269. 'attrs' => array(
  270. 'id' => 'bx-grid-module-' . $this->_sObject,
  271. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  272. ),
  273. 'values' => array(
  274. 'id-' . BX_DOL_LANGUAGE_CATEGORY_SYSTEM => '',
  275. 'id-' . BX_DOL_LANGUAGE_CATEGORY_CUSTOM => ''
  276. )
  277. );
  278. $aCategories = $aCounter = array();
  279. $this->oDb->getCategoriesBy(array('type' => 'all'), $aCategories, false);
  280. $this->oDb->getKeysBy(array('type' => 'counter_by_category'), $aCounter, false);
  281. foreach($aCategories as $aCategory)
  282. $aInputModules['values']['id-' . $aCategory['id']] = $aCategory['name'] . " (" . (isset($aCounter[$aCategory['id']]) ? $aCounter[$aCategory['id']] : "0") . ")";;
  283. $aInputModules['values'] = array_merge(array('id-0' => _t('_adm_pgt_txt_all_modules')), $aInputModules['values']);
  284. $sContent .= $oForm->genRow($aInputModules);
  285. $aInputSearch = array(
  286. 'type' => 'text',
  287. 'name' => 'keyword',
  288. 'attrs' => array(
  289. 'id' => 'bx-grid-search-' . $this->_sObject,
  290. 'onKeyup' => 'javascript:$(this).off(); ' . $this->getJsObject() . '.onChangeFilter()'
  291. )
  292. );
  293. $sContent .= $oForm->genRow($aInputSearch);
  294. return $sContent;
  295. }
  296. }
  297. /** @} */