BxBaseStudioPolyglotKeys.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. defined('BX_DOL') or die('hack attempt');
  11. bx_import('BxDolStudioPolyglotKeys');
  12. class BxBaseStudioPolyglotKeys extends BxDolStudioPolyglotKeys {
  13. function __construct($aOptions, $oTemplate = false) {
  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. $sAction = 'add';
  20. $aLanguages = array();
  21. $iLanguages = $this->oDb->getLanguagesBy(array('type' => 'all_key_id'), $aLanguages);
  22. $aForm = array(
  23. 'form_attrs' => array(
  24. 'id' => 'adm-lang-new-key-form',
  25. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  26. 'method' => 'post'
  27. ),
  28. 'params' => array(
  29. 'db' => array(
  30. 'table' => 'sys_localization_keys',
  31. 'key' => 'ID',
  32. 'uri' => '',
  33. 'uri_title' => '',
  34. 'submit_name' => 'do_submit'
  35. ),
  36. ),
  37. 'inputs' => array(
  38. 'key' => array(
  39. 'type' => 'text',
  40. 'name' => 'key',
  41. 'caption' => _t('_adm_pgt_txt_nkp_key_name'),
  42. 'value' => '',
  43. 'db' => array (
  44. 'pass' => 'Xss',
  45. ),
  46. ),
  47. 'category_id' => array(
  48. 'type' => 'select',
  49. 'name' => 'category_id',
  50. 'caption' => _t('_adm_pgt_txt_nkp_module'),
  51. 'values' => $this->oDb->getCategories(),
  52. 'value' => '1',
  53. 'db' => array (
  54. 'pass' => 'Int',
  55. ),
  56. ),
  57. )
  58. );
  59. foreach($aLanguages as $aLanguage) {
  60. $sName = 'language_' . $aLanguage['id'];
  61. $aForm['inputs'][$sName] = array(
  62. 'type' => 'textarea',
  63. 'name' => $sName,
  64. 'caption' => $aLanguage['title'],
  65. 'value' => '',
  66. 'db' => array (
  67. 'pass' => 'XssHtml',
  68. ),
  69. );
  70. }
  71. $aForm['inputs'] = array_merge($aForm['inputs'], array(
  72. 'languages' => array(
  73. 'type' => 'hidden',
  74. 'name' => 'languages',
  75. 'value' => implode(',', array_keys($aLanguages)),
  76. 'db' => array (
  77. 'pass' => 'Xss',
  78. ),
  79. ),
  80. 'controls' => array(
  81. 'name' => 'controls',
  82. 'type' => 'input_set',
  83. array(
  84. 'type' => 'submit',
  85. 'name' => 'do_submit',
  86. 'value' => _t('_adm_pgt_btn_nkp_create'),
  87. ),
  88. array (
  89. 'type' => 'reset',
  90. 'name' => 'close',
  91. 'value' => _t('_adm_pgt_btn_nkp_close'),
  92. 'attrs' => array(
  93. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  94. 'class' => 'bx-def-margin-sec-left',
  95. ),
  96. )
  97. )
  98. ));
  99. bx_import('BxTemplStudioFormView');
  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. bx_import('BxTemplStudioFunctions');
  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. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  119. }
  120. }
  121. public function performActionEdit() {
  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. bx_import('BxTemplStudioFormView');
  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. $this->_echoResultJson($aRes, true);
  213. }
  214. else {
  215. bx_import('BxTemplStudioFunctions');
  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. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  223. }
  224. }
  225. public function performActionDelete() {
  226. $iAffected = 0;
  227. $aIds = bx_get('ids');
  228. if(!$aIds || !is_array($aIds)) {
  229. $this->_echoResultJson(array());
  230. exit;
  231. }
  232. bx_import('BxDolStudioLanguagesUtils');
  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. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_pgt_err_save')));
  241. }
  242. function getJsObject() {
  243. return 'oBxDolStudioPolyglotKeys';
  244. }
  245. function getCode($isDisplayHeader = true) {
  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. parent::_addJsCss();
  254. $this->_oTemplate->addJs(array('jquery.form.js', 'polyglot_keys.js'));
  255. bx_import('BxTemplStudioFormView');
  256. $oForm = new BxTemplStudioFormView(array());
  257. $oForm->addCssJs();
  258. }
  259. protected function _getFilterControls () {
  260. parent::_getFilterControls();
  261. $sContent = "";
  262. bx_import('BxTemplStudioFormView');
  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. /** @} */