BxBaseStudioPolyglotKeys.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. bx_import('BxDolStudioPolyglotKeys');
  11. class BxBaseStudioPolyglotKeys extends BxDolStudioPolyglotKeys
  12. {
  13. function __construct($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct($aOptions, $oTemplate);
  16. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_pgt_btn_edit_title');
  17. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_pgt_btn_delete_title');
  18. }
  19. public function performActionAdd()
  20. {
  21. $sAction = 'add';
  22. $aLanguages = array();
  23. $iLanguages = $this->oDb->getLanguagesBy(array('type' => 'all_key_id'), $aLanguages);
  24. $aForm = array(
  25. 'form_attrs' => array(
  26. 'id' => 'adm-lang-new-key-form',
  27. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  28. 'method' => 'post'
  29. ),
  30. 'params' => array(
  31. 'db' => array(
  32. 'table' => 'sys_localization_keys',
  33. 'key' => 'ID',
  34. 'uri' => '',
  35. 'uri_title' => '',
  36. 'submit_name' => 'do_submit'
  37. ),
  38. ),
  39. 'inputs' => array(
  40. 'key' => array(
  41. 'type' => 'text',
  42. 'name' => 'key',
  43. 'caption' => _t('_adm_pgt_txt_nkp_key_name'),
  44. 'value' => '',
  45. 'db' => array (
  46. 'pass' => 'Xss',
  47. ),
  48. ),
  49. 'category_id' => array(
  50. 'type' => 'select',
  51. 'name' => 'category_id',
  52. 'caption' => _t('_adm_pgt_txt_nkp_module'),
  53. 'values' => $this->oDb->getCategories(),
  54. 'value' => '1',
  55. 'db' => array (
  56. 'pass' => 'Int',
  57. ),
  58. ),
  59. )
  60. );
  61. foreach($aLanguages as $aLanguage) {
  62. $sName = 'language_' . $aLanguage['id'];
  63. $aForm['inputs'][$sName] = array(
  64. 'type' => 'textarea',
  65. 'name' => $sName,
  66. 'caption' => $aLanguage['title'],
  67. 'value' => '',
  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. bx_import('BxTemplStudioFormView');
  102. $oForm = new BxTemplStudioFormView($aForm);
  103. $oForm->initChecker();
  104. if($oForm->isSubmittedAndValid()) {
  105. $mixedResult = $this->add($oForm);
  106. if(is_int($mixedResult))
  107. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  108. else
  109. $aRes = array('msg' => $mixedResult);
  110. $this->_echoResultJson($aRes, true);
  111. } else {
  112. bx_import('BxTemplStudioFunctions');
  113. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-lang-new-key-popup', _t('_adm_pgt_txt_nkp_add_popup'), $this->_oTemplate->parseHtmlByName('pgt_new_key.html', array(
  114. 'form_id' => $aForm['form_attrs']['id'],
  115. 'form' => $oForm->getCode(true),
  116. 'object' => $this->_sObject,
  117. 'action' => $sAction
  118. )));
  119. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  120. }
  121. }
  122. public function performActionEdit()
  123. {
  124. $oTemplate = BxDolStudioTemplate::getInstance();
  125. $aIds = bx_get('ids');
  126. if(!$aIds || !is_array($aIds)) {
  127. $iId = (int)bx_get('id');
  128. if(!$iId) {
  129. $this->_echoResultJson(array());
  130. exit;
  131. }
  132. $aIds = array($iId);
  133. }
  134. $iId = $aIds[0];
  135. $sAction = 'edit';
  136. $aLanguages = array();
  137. $iLanguages = $this->oDb->getLanguagesBy(array('type' => 'all_key_id'), $aLanguages);
  138. $aKey = $this->oDb->getKeyFullInfo($iId);
  139. $aForm = array(
  140. 'form_attrs' => array(
  141. 'id' => 'adm-lang-edit-key-form',
  142. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  143. 'method' => 'post'
  144. ),
  145. 'params' => array(
  146. 'db' => array(
  147. 'table' => 'sys_localization_keys',
  148. 'key' => 'ID',
  149. 'uri' => '',
  150. 'uri_title' => '',
  151. 'submit_name' => 'do_submit'
  152. ),
  153. ),
  154. 'inputs' => array(
  155. 'id' => array(
  156. 'type' => 'hidden',
  157. 'name' => 'id',
  158. 'value' => $iId,
  159. 'db' => array (
  160. 'pass' => 'Int',
  161. ),
  162. ),
  163. )
  164. );
  165. foreach($aLanguages as $aLanguage) {
  166. $sName = 'language_' . $aLanguage['id'];
  167. $aForm['inputs'][$sName] = array(
  168. 'type' => 'textarea',
  169. 'name' => $sName,
  170. 'caption' => $aLanguage['title'],
  171. 'value' => isset($aKey['strings'][$aLanguage['name']]) ? $aKey['strings'][$aLanguage['name']]['string'] : '',
  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. bx_import('BxTemplStudioFormView');
  206. $oForm = new BxTemplStudioFormView($aForm);
  207. $oForm->initChecker();
  208. if($oForm->isSubmittedAndValid()) {
  209. $mixedResult = $this->edit($oForm);
  210. if(is_int($mixedResult))
  211. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  212. else
  213. $aRes = array('msg' => $mixedResult);
  214. $this->_echoResultJson($aRes, true);
  215. } else {
  216. bx_import('BxTemplStudioFunctions');
  217. $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(
  218. 'form_id' => $aForm['form_attrs']['id'],
  219. 'form' => $oForm->getCode(true),
  220. 'object' => $this->_sObject,
  221. 'action' => $sAction
  222. )));
  223. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  224. }
  225. }
  226. public function performActionDelete()
  227. {
  228. $iAffected = 0;
  229. $aIds = bx_get('ids');
  230. if(!$aIds || !is_array($aIds)) {
  231. $this->_echoResultJson(array());
  232. exit;
  233. }
  234. bx_import('BxDolStudioLanguagesUtils');
  235. $aIdsAffected = array ();
  236. foreach($aIds as $iId) {
  237. if(!BxDolStudioLanguagesUtils::getInstance()->deleteLanguageStringById($iId, 0, false))
  238. continue;
  239. $aIdsAffected[] = $iId;
  240. $iAffected++;
  241. }
  242. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_pgt_err_save')));
  243. }
  244. function getJsObject()
  245. {
  246. return 'oBxDolStudioPolyglotKeys';
  247. }
  248. function getCode($isDisplayHeader = true)
  249. {
  250. return $this->_oTemplate->parseHtmlByName('pgt_keys.html', array(
  251. 'content' => parent::getCode($isDisplayHeader),
  252. 'js_object' => $this->getJsObject(),
  253. 'grid_object' => $this->_sObject
  254. ));
  255. }
  256. protected function _addJsCss()
  257. {
  258. parent::_addJsCss();
  259. $this->_oTemplate->addJs(array('jquery.form.min.js', 'polyglot_keys.js'));
  260. bx_import('BxTemplStudioFormView');
  261. $oForm = new BxTemplStudioFormView(array());
  262. $oForm->addCssJs();
  263. }
  264. protected function _getFilterControls ()
  265. {
  266. parent::_getFilterControls();
  267. $sContent = "";
  268. bx_import('BxTemplStudioFormView');
  269. $oForm = new BxTemplStudioFormView(array());
  270. $aInputModules = array(
  271. 'type' => 'select',
  272. 'name' => 'module',
  273. 'attrs' => array(
  274. 'id' => 'bx-grid-module-' . $this->_sObject,
  275. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  276. ),
  277. 'values' => array(
  278. 'id-' . BX_DOL_LANGUAGE_CATEGORY_SYSTEM => '',
  279. 'id-' . BX_DOL_LANGUAGE_CATEGORY_CUSTOM => ''
  280. )
  281. );
  282. $aCategories = $aCounter = array();
  283. $this->oDb->getCategoriesBy(array('type' => 'all'), $aCategories, false);
  284. $this->oDb->getKeysBy(array('type' => 'counter_by_category'), $aCounter, false);
  285. foreach($aCategories as $aCategory)
  286. $aInputModules['values']['id-' . $aCategory['id']] = $aCategory['name'] . " (" . (isset($aCounter[$aCategory['id']]) ? $aCounter[$aCategory['id']] : "0") . ")";;
  287. $aInputModules['values'] = array_merge(array('id-0' => _t('_adm_pgt_txt_all_modules')), $aInputModules['values']);
  288. $sContent .= $oForm->genRow($aInputModules);
  289. $aInputSearch = array(
  290. 'type' => 'text',
  291. 'name' => 'keyword',
  292. 'attrs' => array(
  293. 'id' => 'bx-grid-search-' . $this->_sObject,
  294. 'onKeyup' => 'javascript:$(this).off(); ' . $this->getJsObject() . '.onChangeFilter()'
  295. )
  296. );
  297. $sContent .= $oForm->genRow($aInputSearch);
  298. return $sContent;
  299. }
  300. }
  301. /** @} */