BxBaseStudioPolyglotKeys.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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?' . 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. '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_numeric($mixedResult))
  105. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  106. else
  107. $aRes = array('msg' => $mixedResult);
  108. echoJson($aRes);
  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. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  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. echoJson(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?' . bx_encode_url_params($_GET, array('ids', '_r')),
  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. 'code' => 1,
  171. 'db' => array (
  172. 'pass' => 'XssHtml',
  173. ),
  174. );
  175. }
  176. $aForm['inputs'] = array_merge($aForm['inputs'], array(
  177. 'languages' => array(
  178. 'type' => 'hidden',
  179. 'name' => 'languages',
  180. 'value' => implode(',', array_keys($aLanguages)),
  181. 'db' => array (
  182. 'pass' => 'Xss',
  183. ),
  184. ),
  185. 'controls' => array(
  186. 'name' => 'controls',
  187. 'type' => 'input_set',
  188. array(
  189. 'type' => 'submit',
  190. 'name' => 'do_submit',
  191. 'value' => _t('_adm_pgt_btn_nkp_save'),
  192. ),
  193. array (
  194. 'type' => 'reset',
  195. 'name' => 'close',
  196. 'value' => _t('_adm_pgt_btn_nkp_close'),
  197. 'attrs' => array(
  198. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  199. 'class' => 'bx-def-margin-sec-left',
  200. ),
  201. )
  202. )
  203. ));
  204. $oForm = new BxTemplStudioFormView($aForm);
  205. $oForm->initChecker();
  206. if($oForm->isSubmittedAndValid()) {
  207. $mixedResult = $this->edit($oForm);
  208. if(is_int($mixedResult))
  209. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  210. else
  211. $aRes = array('msg' => $mixedResult);
  212. echoJson($aRes);
  213. }
  214. else {
  215. $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(
  216. 'form_id' => $aForm['form_attrs']['id'],
  217. 'form' => $oForm->getCode(true),
  218. 'object' => $this->_sObject,
  219. 'action' => $sAction
  220. )));
  221. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  222. }
  223. }
  224. public function performActionDelete()
  225. {
  226. $iAffected = 0;
  227. $aIds = bx_get('ids');
  228. if(!$aIds || !is_array($aIds)) {
  229. echoJson(array());
  230. exit;
  231. }
  232. $aIdsAffected = array ();
  233. foreach($aIds as $iId) {
  234. if(!BxDolStudioLanguagesUtils::getInstance()->deleteLanguageStringById($iId, 0, false))
  235. continue;
  236. $aIdsAffected[] = $iId;
  237. $iAffected++;
  238. }
  239. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_pgt_err_save')));
  240. }
  241. function getJsObject()
  242. {
  243. return 'oBxDolStudioPolyglotKeys';
  244. }
  245. function getCode($isDisplayHeader = true)
  246. {
  247. return $this->_oTemplate->parseHtmlByName('pgt_keys.html', array(
  248. 'content' => parent::getCode($isDisplayHeader),
  249. 'js_object' => $this->getJsObject(),
  250. 'grid_object' => $this->_sObject
  251. ));
  252. }
  253. protected function _addJsCss()
  254. {
  255. parent::_addJsCss();
  256. $this->_oTemplate->addJs(array('jquery.form.min.js', 'polyglot_keys.js'));
  257. $oForm = new BxTemplStudioFormView(array());
  258. $oForm->addCssJs();
  259. }
  260. protected function _getFilterControls ()
  261. {
  262. parent::_getFilterControls();
  263. $sContent = "";
  264. $oForm = new BxTemplStudioFormView(array());
  265. $aInputModules = array(
  266. 'type' => 'select',
  267. 'name' => 'module',
  268. 'attrs' => array(
  269. 'id' => 'bx-grid-module-' . $this->_sObject,
  270. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  271. ),
  272. 'values' => array(
  273. 'id-' . BX_DOL_LANGUAGE_CATEGORY_SYSTEM => '',
  274. 'id-' . BX_DOL_LANGUAGE_CATEGORY_CUSTOM => ''
  275. )
  276. );
  277. $aCategories = $aCounter = array();
  278. $this->oDb->getCategoriesBy(array('type' => 'all'), $aCategories, false);
  279. $this->oDb->getKeysBy(array('type' => 'counter_by_category'), $aCounter, false);
  280. foreach($aCategories as $aCategory)
  281. $aInputModules['values']['id-' . $aCategory['id']] = $aCategory['name'] . " (" . (isset($aCounter[$aCategory['id']]) ? $aCounter[$aCategory['id']] : "0") . ")";;
  282. $aInputModules['values'] = array_merge(array('id-0' => _t('_adm_pgt_txt_all_modules')), $aInputModules['values']);
  283. $sContent .= $oForm->genRow($aInputModules);
  284. $aInputSearch = array(
  285. 'type' => 'text',
  286. 'name' => 'keyword',
  287. 'attrs' => array(
  288. 'id' => 'bx-grid-search-' . $this->_sObject,
  289. 'onKeyup' => 'javascript:$(this).off(); ' . $this->getJsObject() . '.onChangeFilter()'
  290. )
  291. );
  292. $sContent .= $oForm->genRow($aInputSearch);
  293. return $sContent;
  294. }
  295. }
  296. /** @} */