BxBaseStudioNavigationSets.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 BxBaseStudioNavigationSets extends BxDolStudioNavigationSets
  11. {
  12. protected $sUrlViewItems;
  13. function __construct($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct($aOptions, $oTemplate);
  16. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_nav_btn_sets_edit');
  17. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_nav_btn_sets_delete');
  18. $this->sUrlViewItems = BX_DOL_URL_STUDIO . 'builder_menu.php?page=items&module=%s&set=%s';
  19. }
  20. public function performActionAdd()
  21. {
  22. $sAction = 'add';
  23. bx_import('BxTemplStudioFormView');
  24. $aForm = array(
  25. 'form_attrs' => array(
  26. 'id' => 'adm-nav-set-create',
  27. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('grid.php', [
  28. 'o' => $this->_sObject,
  29. 'a' => $sAction,
  30. $this->_aOptions['filter_get'] => $this->_sFilter
  31. ]),
  32. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  33. ),
  34. 'params' => array (
  35. 'db' => array(
  36. 'table' => 'sys_menu_sets',
  37. 'key' => 'set_name',
  38. 'uri' => '',
  39. 'uri_title' => '',
  40. 'submit_name' => 'do_submit'
  41. ),
  42. ),
  43. 'inputs' => array (
  44. 'title' => array(
  45. 'type' => 'text_translatable',
  46. 'name' => 'title',
  47. 'caption' => _t('_adm_nav_txt_sets_title'),
  48. 'info' => _t('_adm_nav_dsc_sets_title'),
  49. 'value' => '_adm_nav_txt_set',
  50. 'required' => '1',
  51. 'db' => array (
  52. 'pass' => 'Xss',
  53. ),
  54. 'checker' => array (
  55. 'func' => 'LengthTranslatable',
  56. 'params' => array(3, 100, 'title'),
  57. 'error' => _t('_adm_nav_err_sets_title'),
  58. ),
  59. ),
  60. 'deletable' => array(
  61. 'type' => 'hidden',
  62. 'name' => 'deletable',
  63. 'value' => 1,
  64. 'db' => array (
  65. 'pass' => 'Int',
  66. ),
  67. ),
  68. 'controls' => array(
  69. 'name' => 'controls',
  70. 'type' => 'input_set',
  71. array(
  72. 'type' => 'submit',
  73. 'name' => 'do_submit',
  74. 'value' => _t('_adm_nav_btn_sets_add'),
  75. ),
  76. array (
  77. 'type' => 'reset',
  78. 'name' => 'close',
  79. 'value' => _t('_adm_nav_btn_sets_cancel'),
  80. 'attrs' => array(
  81. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  82. 'class' => 'bx-def-margin-sec-left',
  83. ),
  84. )
  85. )
  86. )
  87. );
  88. $oForm = new BxTemplStudioFormView($aForm);
  89. $oForm->initChecker();
  90. if($oForm->isSubmittedAndValid()) {
  91. bx_import('BxDolStudioUtils');
  92. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  93. $sName = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  94. $sName = uriGenerate($sName, 'sys_menu_sets', 'set_name', ['empty' => 'set']);
  95. if($oForm->insert(array('set_name' => $sName, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM)) !== false)
  96. $aRes = array('grid' => $this->getCode(false), 'blink' => $sName);
  97. else
  98. $aRes = array('msg' => _t('_adm_nav_err_sets_create'));
  99. echoJson($aRes);
  100. }
  101. else {
  102. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-set-create-popup', _t('_adm_nav_txt_sets_create_popup'), $this->_oTemplate->parseHtmlByName('nav_add_set.html', array(
  103. 'form_id' => $aForm['form_attrs']['id'],
  104. 'form' => $oForm->getCode(true),
  105. 'object' => $this->_sObject,
  106. 'action' => $sAction
  107. )));
  108. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  109. }
  110. }
  111. public function performActionEdit()
  112. {
  113. $sAction = 'edit';
  114. $aIds = bx_get('ids');
  115. if(!$aIds || !is_array($aIds)) {
  116. $sId = bx_get('set_name');
  117. if(!$sId) {
  118. echoJson(array());
  119. exit;
  120. }
  121. $aIds = array($sId);
  122. }
  123. $sId = bx_process_input($aIds[0]);
  124. $aSet = array();
  125. $iSet = $this->oDb->getSets(array('type' => 'by_name', 'value' => $sId), $aSet);
  126. if($iSet != 1 || empty($aSet)) {
  127. echoJson(array());
  128. exit;
  129. }
  130. bx_import('BxTemplStudioFormView');
  131. $aForm = array(
  132. 'form_attrs' => array(
  133. 'id' => 'adm-nav-set-edit',
  134. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('grid.php', [
  135. 'o' => $this->_sObject,
  136. 'a' => $sAction,
  137. $this->_aOptions['filter_get'] => $this->_sFilter
  138. ]),
  139. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  140. ),
  141. 'params' => array (
  142. 'db' => array(
  143. 'table' => 'sys_menu_sets',
  144. 'key' => 'set_name',
  145. 'uri' => '',
  146. 'uri_title' => '',
  147. 'submit_name' => 'do_submit'
  148. ),
  149. ),
  150. 'inputs' => array (
  151. 'set_name' => array(
  152. 'type' => 'hidden',
  153. 'name' => 'set_name',
  154. 'value' => $sId,
  155. 'db' => array (
  156. 'pass' => 'Xss',
  157. ),
  158. ),
  159. 'title' => array(
  160. 'type' => 'text_translatable',
  161. 'name' => 'title',
  162. 'caption' => _t('_adm_nav_txt_sets_title'),
  163. 'info' => _t('_adm_nav_dsc_sets_title'),
  164. 'value' => $aSet['title'],
  165. 'required' => '1',
  166. 'db' => array (
  167. 'pass' => 'Xss',
  168. ),
  169. 'checker' => array (
  170. 'func' => 'LengthTranslatable',
  171. 'params' => array(3, 100, 'title'),
  172. 'error' => _t('_adm_nav_err_sets_title'),
  173. ),
  174. ),
  175. 'controls' => array(
  176. 'name' => 'controls',
  177. 'type' => 'input_set',
  178. array(
  179. 'type' => 'submit',
  180. 'name' => 'do_submit',
  181. 'value' => _t('_adm_nav_btn_menus_save'),
  182. ),
  183. array (
  184. 'type' => 'reset',
  185. 'name' => 'close',
  186. 'value' => _t('_adm_nav_btn_menus_cancel'),
  187. 'attrs' => array(
  188. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  189. 'class' => 'bx-def-margin-sec-left',
  190. ),
  191. )
  192. )
  193. )
  194. );
  195. $oForm = new BxTemplStudioFormView($aForm);
  196. $oForm->initChecker();
  197. if($oForm->isSubmittedAndValid()) {
  198. if($oForm->update($sId) !== false)
  199. $aRes = array('grid' => $this->getCode(false), 'blink' => $sId);
  200. else
  201. $aRes = array('msg' => _t('_adm_nav_err_sets_edit'));
  202. echoJson($aRes);
  203. }
  204. else {
  205. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-set-edit-popup', _t('_adm_nav_txt_sets_edit_popup', _t($aSet['title'])), $this->_oTemplate->parseHtmlByName('nav_add_set.html', array(
  206. 'form_id' => $aForm['form_attrs']['id'],
  207. 'form' => $oForm->getCode(true),
  208. 'object' => $this->_sObject,
  209. 'action' => $sAction
  210. )));
  211. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  212. }
  213. }
  214. public function performActionDelete()
  215. {
  216. $iAffected = 0;
  217. $aIds = bx_get('ids');
  218. if(!$aIds || !is_array($aIds)) {
  219. echoJson(array());
  220. exit;
  221. }
  222. $oGridItems = BxDolGrid::getObjectInstance('sys_studio_nav_items');
  223. if(!$oGridItems) {
  224. echoJson(array());
  225. exit;
  226. }
  227. $aIdsAffected = array ();
  228. foreach($aIds as $sId) {
  229. $sId = bx_process_input($sId);
  230. $aSet = array();
  231. $this->oDb->getSets(array('type' => 'by_name', 'value' => $sId), $aSet, false);
  232. if(!is_array($aSet) || empty($aSet))
  233. continue;
  234. $aMenus = array();
  235. $this->oDb->getMenus(array('type' => 'by_set_name', 'value' => $sId), $aMenus, false);
  236. if(is_array($aMenus) && count($aMenus) > 0) {
  237. echoJson(array('msg' => _t('_adm_nav_err_sets_delete_used')));
  238. exit;
  239. }
  240. if((int)$this->_delete($sId) <= 0)
  241. continue;
  242. $aItems = array();
  243. $this->oDb->getItems(array('type' => 'by_set_name', 'value' => $aSet['name']), $aItems, false);
  244. if(is_array($aItems) && !empty($aItems))
  245. foreach($aItems as $aItem)
  246. $oGridItems->deleteByItem($aItem);
  247. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aSet['title']);
  248. $aIdsAffected[] = $sId;
  249. $iAffected++;
  250. }
  251. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_sets_delete')));
  252. }
  253. function getJsObject()
  254. {
  255. return 'oBxDolStudioNavigationSets';
  256. }
  257. function getCode($isDisplayHeader = true)
  258. {
  259. return $this->_oTemplate->parseHtmlByName('nav_sets.html', array(
  260. 'content' => parent::getCode($isDisplayHeader),
  261. 'js_object' => $this->getJsObject(),
  262. 'grid_object' => $this->_sObject,
  263. 'params_divider' => $this->sParamsDivider
  264. ));
  265. }
  266. protected function _addJsCss()
  267. {
  268. parent::_addJsCss();
  269. $this->_oTemplate->addJs(array('jquery.form.min.js', 'navigation_sets.js'));
  270. $oForm = new BxTemplStudioFormView(array());
  271. $oForm->addCssJs();
  272. }
  273. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  274. {
  275. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  276. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  277. }
  278. protected function _getCellItems ($mixedValue, $sKey, $aField, $aRow)
  279. {
  280. $aSets = array();
  281. $this->oDb->getSets(array('type' => 'by_name', 'value' => $aRow['set_name']), $aSets, false);
  282. $sLink = sprintf($this->sUrlViewItems, $aRow['module'], $aRow['set_name']);
  283. $mixedValue = $this->_oTemplate->parseLink($sLink, _t('_adm_nav_txt_n_items', $aSets['items_count']), array(
  284. 'title' => _t('_adm_nav_txt_manage_items')
  285. ));
  286. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  287. }
  288. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  289. {
  290. if ($sType == 'single' && (int)$aRow['deletable'] != 1)
  291. return '';
  292. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  293. }
  294. protected function _getFilterControls ()
  295. {
  296. parent::_getFilterControls();
  297. return $this->getModulesSelectAll('getSets') . $this->getSearchInput();
  298. }
  299. }
  300. /** @} */