BxBaseStudioNavigationMenus.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <?php
  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. defined('BX_DOL') or die('hack attempt');
  11. bx_import('BxDolStudioNavigationMenus');
  12. bx_import('BxTemplStudioFormView');
  13. class BxBaseStudioNavigationMenus extends BxDolStudioNavigationMenus {
  14. private $sCreateNew = 'sys_create_new';
  15. protected $sUrlViewItems;
  16. function __construct($aOptions, $oTemplate = false) {
  17. parent::__construct($aOptions, $oTemplate);
  18. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_nav_btn_menus_edit');
  19. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_nav_btn_menus_delete');
  20. $this->sUrlViewItems = BX_DOL_URL_STUDIO . 'builder_menu.php?page=items&module=%s&set=%s';
  21. }
  22. public function performActionAdd() {
  23. $sAction = 'add';
  24. $aForm = array(
  25. 'form_attrs' => array(
  26. 'id' => 'adm-nav-menu-create',
  27. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  28. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  29. ),
  30. 'params' => array (
  31. 'db' => array(
  32. 'table' => 'sys_objects_menu',
  33. 'key' => 'id',
  34. 'uri' => '',
  35. 'uri_title' => '',
  36. 'submit_name' => 'do_submit'
  37. )
  38. ),
  39. 'inputs' => array (
  40. 'title' => array(
  41. 'type' => 'text_translatable',
  42. 'name' => 'title',
  43. 'caption' => _t('_adm_nav_txt_menus_title'),
  44. 'info' => _t('_adm_nav_dsc_menus_title'),
  45. 'value' => '_adm_nav_txt_menu',
  46. 'required' => '1',
  47. 'db' => array (
  48. 'pass' => 'Xss',
  49. ),
  50. 'checker' => array (
  51. 'func' => 'LengthTranslatable',
  52. 'params' => array(3, 100, 'title'),
  53. 'error' => _t('_adm_nav_err_menus_title'),
  54. ),
  55. ),
  56. 'set_name' => array(
  57. 'type' => 'select',
  58. 'name' => 'set_name',
  59. 'caption' => _t('_adm_nav_txt_menus_set_name'),
  60. 'info' => _t('_adm_nav_dsc_menus_set_name'),
  61. 'value' => '',
  62. 'values' => array(
  63. array('key' => '', 'value' => _t('_adm_nav_txt_menus_set_name_select')),
  64. array('key' => $this->sCreateNew, 'value' => _t('_adm_nav_txt_menus_set_name_new'))
  65. ),
  66. 'required' => '1',
  67. 'attrs' => array(
  68. 'id' => 'bx-form-field-set-name',
  69. 'onchange' => $this->getJsObject() . ".onSelectSet(this)"
  70. ),
  71. 'db' => array (
  72. 'pass' => 'Xss',
  73. ),
  74. 'checker' => array (
  75. 'func' => 'avail',
  76. 'params' => array(),
  77. 'error' => _t('_adm_nav_err_menus_set_name'),
  78. ),
  79. ),
  80. 'set_title' => array(
  81. 'type' => 'text',
  82. 'name' => 'set_title',
  83. 'caption' => _t('_adm_nav_txt_menus_set_title'),
  84. 'info' => _t('_adm_nav_dsc_menus_set_title'),
  85. 'value' => '',
  86. 'required' => '1',
  87. 'tr_attrs' => array(
  88. 'style' => 'display:none'
  89. ),
  90. 'db' => array (
  91. 'pass' => 'Xss',
  92. ),
  93. 'checker' => array (
  94. 'func' => 'Avail',
  95. 'params' => array(),
  96. 'error' => _t('_adm_nav_err_menus_set_title'),
  97. ),
  98. ),
  99. 'template_id' => array(
  100. 'type' => 'select',
  101. 'name' => 'template_id',
  102. 'caption' => _t('_adm_nav_txt_menus_style'),
  103. 'info' => _t('_adm_nav_dsc_menus_style'),
  104. 'value' => '',
  105. 'values' => array(
  106. array('key' => '', 'value' => _t('_adm_nav_txt_menus_style_select'))
  107. ),
  108. 'required' => '1',
  109. 'db' => array (
  110. 'pass' => 'Xss',
  111. ),
  112. 'checker' => array (
  113. 'func' => 'avail',
  114. 'params' => array(),
  115. 'error' => _t('_adm_nav_err_menus_style'),
  116. ),
  117. ),
  118. 'controls' => array(
  119. 'name' => 'controls',
  120. 'type' => 'input_set',
  121. array(
  122. 'type' => 'submit',
  123. 'name' => 'do_submit',
  124. 'value' => _t('_adm_nav_btn_menus_add'),
  125. ),
  126. array (
  127. 'type' => 'reset',
  128. 'name' => 'close',
  129. 'value' => _t('_adm_nav_btn_menus_cancel'),
  130. 'attrs' => array(
  131. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  132. 'class' => 'bx-def-margin-sec-left',
  133. ),
  134. )
  135. )
  136. )
  137. );
  138. $aSets = array();
  139. $this->oDb->getSets(array('type' => 'all'), $aSets, false);
  140. foreach($aSets as $sSet)
  141. $aForm['inputs']['set_name']['values'][] = array('key' => $sSet['name'], 'value' => _t($sSet['title']));
  142. $aTemplates = array();
  143. $this->oDb->getTemplates(array('type' => 'all'), $aTemplates, false);
  144. foreach($aTemplates as $aTemplate)
  145. $aForm['inputs']['template_id']['values'][] = array('key' => $aTemplate['id'], 'value' => _t($aTemplate['title']));
  146. $oForm = new BxTemplStudioFormView($aForm);
  147. if($oForm->isSubmitted() && isset($oForm->aInputs['set_name']))
  148. $this->updateSetFields($oForm);
  149. $oForm->initChecker();
  150. if($oForm->isSubmittedAndValid()) {
  151. bx_import('BxDolStudioLanguagesUtils');
  152. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  153. $sLanguage = $oLanguage->getCurrentLangName(false);
  154. $sObject = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  155. $sObject = uriGenerate($sObject, 'sys_objects_menu', 'object', 'object');
  156. //--- New Set Creation
  157. if($oForm->getCleanValue('set_name') == $this->sCreateNew) {
  158. $sSetTitleValue = $oForm->getCleanValue('set_title');
  159. $sSetName = uriGenerate($sSetTitleValue, 'sys_menu_sets', 'set_name', 'set');
  160. $sSetTitleKey = '_adm_nav_txt_set_' . $sSetName;
  161. if($this->oDb->addSet(array('set_name' => $sSetName, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'title' => $sSetTitleKey, 'deletable' => 1))) {
  162. $oLanguage->addLanguageString($sSetTitleKey, $sSetTitleValue);
  163. BxDolForm::setSubmittedValue('set_name', $sSetName, $oForm->aFormAttrs['method']);
  164. }
  165. }
  166. unset($oForm->aInputs['set_title']);
  167. $iId = (int)$oForm->insert(array('object' => $sObject, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'deletable' => 1, 'active' => 1));
  168. if($iId != 0)
  169. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  170. else
  171. $aRes = array('msg' => _t('_adm_nav_err_menus_create'));
  172. $this->_echoResultJson($aRes, true);
  173. }
  174. else {
  175. bx_import('BxTemplStudioFunctions');
  176. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-menu-create-popup', _t('_adm_nav_txt_menus_create_popup'), $this->_oTemplate->parseHtmlByName('nav_add_menu.html', array(
  177. 'form_id' => $aForm['form_attrs']['id'],
  178. 'form' => $oForm->getCode(true),
  179. 'object' => $this->_sObject,
  180. 'action' => $sAction
  181. )));
  182. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  183. }
  184. }
  185. public function performActionEdit() {
  186. $sAction = 'edit';
  187. $aIds = bx_get('ids');
  188. if(!$aIds || !is_array($aIds)) {
  189. $iId = (int)bx_get('id');
  190. if(!$iId) {
  191. $this->_echoResultJson(array());
  192. exit;
  193. }
  194. $aIds = array($iId);
  195. }
  196. $iId = $aIds[0];
  197. $aMenu = array();
  198. $iMenu = $this->oDb->getMenus(array('type' => 'by_id', 'value' => $iId), $aMenu);
  199. if($iMenu != 1 || empty($aMenu)){
  200. $this->_echoResultJson(array());
  201. exit;
  202. }
  203. $aForm = array(
  204. 'form_attrs' => array(
  205. 'id' => 'adm-nav-menu-edit',
  206. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  207. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  208. ),
  209. 'params' => array (
  210. 'db' => array(
  211. 'table' => 'sys_objects_menu',
  212. 'key' => 'id',
  213. 'uri' => '',
  214. 'uri_title' => '',
  215. 'submit_name' => 'do_submit'
  216. ),
  217. ),
  218. 'inputs' => array (
  219. 'id' => array(
  220. 'type' => 'hidden',
  221. 'name' => 'id',
  222. 'value' => $iId,
  223. 'db' => array (
  224. 'pass' => 'Int',
  225. ),
  226. ),
  227. 'title' => array(
  228. 'type' => 'text_translatable',
  229. 'name' => 'title',
  230. 'caption' => _t('_adm_nav_txt_menus_title'),
  231. 'info' => _t('_adm_nav_dsc_menus_title'),
  232. 'value' => $aMenu['title'],
  233. 'required' => '1',
  234. 'db' => array (
  235. 'pass' => 'Xss',
  236. ),
  237. 'checker' => array (
  238. 'func' => 'LengthTranslatable',
  239. 'params' => array(3, 100, 'title'),
  240. 'error' => _t('_adm_nav_err_menus_title'),
  241. ),
  242. ),
  243. 'set_name' => array(
  244. 'type' => 'select',
  245. 'name' => 'set_name',
  246. 'caption' => _t('_adm_nav_txt_menus_set_name'),
  247. 'info' => _t('_adm_nav_dsc_menus_set_name'),
  248. 'value' => $aMenu['set_name'],
  249. 'values' => array(
  250. array('key' => '', 'value' => _t('_adm_nav_txt_menus_set_name_select')),
  251. array('key' => $this->sCreateNew, 'value' => _t('_adm_nav_txt_menus_set_name_new'))
  252. ),
  253. 'required' => '1',
  254. 'attrs' => array(
  255. 'id' => 'bx-form-field-set-name',
  256. 'onchange' => $this->getJsObject() . ".onSelectSet(this)"
  257. ),
  258. 'db' => array (
  259. 'pass' => 'Xss',
  260. ),
  261. 'checker' => array (
  262. 'func' => 'avail',
  263. 'params' => array(),
  264. 'error' => _t('_adm_nav_err_menus_set_name'),
  265. ),
  266. ),
  267. 'set_title' => array(
  268. 'type' => 'text',
  269. 'name' => 'set_title',
  270. 'caption' => _t('_adm_nav_txt_menus_set_title'),
  271. 'info' => _t('_adm_nav_dsc_menus_set_title'),
  272. 'value' => '',
  273. 'required' => '1',
  274. 'tr_attrs' => array(
  275. 'style' => 'display:none'
  276. ),
  277. 'db' => array (
  278. 'pass' => 'Xss',
  279. ),
  280. 'checker' => array (
  281. 'func' => 'UniqueSet',
  282. 'params' => array(),
  283. 'error' => _t('_adm_nav_err_menus_set_title'),
  284. ),
  285. ),
  286. 'template_id' => array(
  287. 'type' => 'select',
  288. 'name' => 'template_id',
  289. 'caption' => _t('_adm_nav_txt_menus_style'),
  290. 'info' => _t('_adm_nav_dsc_menus_style'),
  291. 'value' => $aMenu['template_id'],
  292. 'values' => array(
  293. array('key' => '', 'value' => _t('_adm_nav_txt_menus_style_select'))
  294. ),
  295. 'required' => '1',
  296. 'db' => array (
  297. 'pass' => 'Xss',
  298. ),
  299. 'checker' => array (
  300. 'func' => 'avail',
  301. 'params' => array(),
  302. 'error' => _t('_adm_nav_err_menus_style'),
  303. ),
  304. ),
  305. 'controls' => array(
  306. 'name' => 'controls',
  307. 'type' => 'input_set',
  308. array(
  309. 'type' => 'submit',
  310. 'name' => 'do_submit',
  311. 'value' => _t('_adm_nav_btn_menus_save'),
  312. ),
  313. array (
  314. 'type' => 'reset',
  315. 'name' => 'close',
  316. 'value' => _t('_adm_nav_btn_menus_cancel'),
  317. 'attrs' => array(
  318. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  319. 'class' => 'bx-def-margin-sec-left',
  320. ),
  321. )
  322. )
  323. )
  324. );
  325. $aSets = array();
  326. $this->oDb->getSets(array('type' => 'all'), $aSets, false);
  327. foreach($aSets as $sSet)
  328. $aForm['inputs']['set_name']['values'][] = array('key' => $sSet['name'], 'value' => _t($sSet['title']));
  329. $aTemplates = array();
  330. $this->oDb->getTemplates(array('type' => 'all'), $aTemplates, false);
  331. foreach($aTemplates as $aTemplate)
  332. $aForm['inputs']['template_id']['values'][] = array('key' => $aTemplate['id'], 'value' => _t($aTemplate['title']));
  333. $oForm = new BxTemplStudioFormView($aForm);
  334. if($oForm->isSubmitted() && isset($oForm->aInputs['set_name']))
  335. $this->updateSetFields($oForm);
  336. $oForm->initChecker();
  337. if($oForm->isSubmittedAndValid()) {
  338. //--- New Set Creation
  339. if($oForm->getCleanValue('set_name') == $this->sCreateNew) {
  340. $sSetTitleValue = $oForm->getCleanValue('set_title');
  341. $sSetName = 'custom_' . $this->getSystemName($sSetTitleValue);
  342. $sSetTitleKey = '_adm_nav_txt_set_' . $sSetName;
  343. if($this->oDb->addSet(array('set_name' => $sSetName, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'title' => $sSetTitleKey, 'deletable' => 1))) {
  344. bx_import('BxDolStudioLanguagesUtils');
  345. BxDolStudioLanguagesUtils::getInstance()->addLanguageString($sSetTitleKey, $sSetTitleValue);
  346. BxDolForm::setSubmittedValue('set_name', $sSetName, $oForm->aFormAttrs['method']);
  347. }
  348. }
  349. unset($oForm->aInputs['set_title']);
  350. if($oForm->update($iId) !== false)
  351. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  352. else
  353. $aRes = array('msg' => _t('_adm_nav_err_menus_edit'));
  354. $this->_echoResultJson($aRes, true);
  355. }
  356. else {
  357. bx_import('BxTemplStudioFunctions');
  358. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-menu-edit-popup', _t('_adm_nav_txt_menus_edit_popup', _t($aMenu['title'])), $this->_oTemplate->parseHtmlByName('nav_add_menu.html', array(
  359. 'form_id' => $aForm['form_attrs']['id'],
  360. 'form' => $oForm->getCode(true),
  361. 'object' => $this->_sObject,
  362. 'action' => $sAction
  363. )));
  364. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  365. }
  366. }
  367. public function performActionDelete() {
  368. $iAffected = 0;
  369. $aIds = bx_get('ids');
  370. if(!$aIds || !is_array($aIds)) {
  371. $this->_echoResultJson(array());
  372. exit;
  373. }
  374. $aIdsAffected = array ();
  375. foreach($aIds as $iId) {
  376. $aMenu = array();
  377. $iMenu = $this->oDb->getMenus(array('type' => 'by_id', 'value' => (int)$iId), $aMenu);
  378. if($iMenu != 1 || empty($aMenu))
  379. continue;
  380. if((int)$aMenu['deletable'] != 1)
  381. continue;
  382. if((int)$this->_delete($iId) <= 0)
  383. continue;
  384. bx_import('BxDolStudioLanguagesUtils');
  385. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aMenu['title']);
  386. $aIdsAffected[] = $iId;
  387. $iAffected++;
  388. }
  389. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_menus_delete')));
  390. }
  391. function getJsObject() {
  392. return 'oBxDolStudioNavigationMenus';
  393. }
  394. function getCode($isDisplayHeader = true) {
  395. return $this->_oTemplate->parseHtmlByName('nav_menus.html', array(
  396. 'content' => parent::getCode($isDisplayHeader),
  397. 'js_object' => $this->getJsObject(),
  398. 'grid_object' => $this->_sObject,
  399. 'params_divider' => $this->sParamsDivider
  400. ));
  401. }
  402. protected function _addJsCss() {
  403. parent::_addJsCss();
  404. $this->_oTemplate->addJs(array('jquery.form.js', 'navigation_menus.js'));
  405. bx_import('BxTemplStudioFormView');
  406. $oForm = new BxTemplStudioFormView(array());
  407. $oForm->addCssJs();
  408. }
  409. protected function _getCellTitle ($mixedValue, $sKey, $aField, $aRow) {
  410. $aValue = $this->_limitMaxLength(_t($aRow['title']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow, false);
  411. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  412. 'href' => sprintf($this->sUrlViewItems, $aRow['module'], $aRow['set_name']),
  413. 'title' => _t('_adm_nav_txt_manage_items'),
  414. 'bx_repeat:attrs' => array(),
  415. 'content' => $aValue[0]
  416. )) . (isset($aValue[1]) ? $aValue[1] : '');
  417. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  418. }
  419. protected function _getCellItems ($mixedValue, $sKey, $aField, $aRow) {
  420. if(!empty($aRow['set_name'])) {
  421. $aSets = array();
  422. $this->oDb->getSets(array('type' => 'by_name', 'value' => $aRow['set_name']), $aSets, false);
  423. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  424. 'href' => sprintf($this->sUrlViewItems, $aRow['module'], $aRow['set_name']),
  425. 'title' => _t('_adm_nav_txt_manage_items'),
  426. 'bx_repeat:attrs' => array(),
  427. 'content' => _t('_adm_nav_txt_n_items', $aSets['items_count'])
  428. ));
  429. }
  430. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  431. }
  432. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow) {
  433. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  434. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  435. }
  436. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  437. if ($sType == 'single' && (int)$aRow['deletable'] != 1)
  438. return '';
  439. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  440. }
  441. protected function _getFilterControls () {
  442. parent::_getFilterControls();
  443. return $this->getModulesSelectAll('getMenus') . $this->getSearchInput();
  444. }
  445. protected function updateSetFields(&$oForm) {
  446. if($oForm->getCleanValue('set_name') != $this->sCreateNew)
  447. unset($oForm->aInputs['set_title']['checker']);
  448. else
  449. unset($oForm->aInputs['set_title']['tr_attrs']['style']);
  450. }
  451. }
  452. /** @} */