BxBaseStudioNavigationSets.php 12 KB

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