BxBaseStudioNavigationSets.php 12 KB

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