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