1
0

BxBaseStudioNavigationItems.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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 BxBaseStudioNavigationItems extends BxDolStudioNavigationItems
  11. {
  12. protected $sUrlPage;
  13. protected $sUrlViewItems;
  14. function __construct($aOptions, $oTemplate = false)
  15. {
  16. parent::__construct($aOptions, $oTemplate);
  17. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_nav_btn_items_edit');
  18. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_nav_btn_items_delete');
  19. $this->sUrlPage = BX_DOL_URL_STUDIO . 'builder_menu.php?page=items';
  20. $this->sUrlViewItems = $this->sUrlPage . '&module=%s&set=%s';
  21. }
  22. public function performActionImport()
  23. {
  24. $oGrid = BxDolGrid::getObjectInstance('sys_studio_nav_import');
  25. if(!$oGrid)
  26. return '';
  27. $sContent = BxTemplFunctions::getInstance()->popupBox('adm-nav-item-import-popup', _t('_adm_nav_txt_items_import_popup'), $this->_oTemplate->parseHtmlByName('nav_import_item.html', array(
  28. 'grid' => $oGrid->getCode()
  29. )));
  30. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  31. }
  32. public function performActionAdd()
  33. {
  34. $sAction = 'add';
  35. $oForm = $this->_getFormObject($sAction);
  36. $oForm->initChecker();
  37. if($oForm->isSubmittedAndValid()) {
  38. if(!empty($_FILES['icon_image']['tmp_name'])) {
  39. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  40. $mixedIcon = $oStorage->storeFileFromForm($_FILES['icon_image'], false, 0);
  41. if($mixedIcon === false) {
  42. echoJson(array('msg' => _t('_adm_nav_err_items_icon_image') . $oStorage->getErrorString()));
  43. return;
  44. }
  45. $oStorage->afterUploadCleanup($mixedIcon, 0);
  46. BxDolForm::setSubmittedValue('icon', $mixedIcon, $oForm->aFormAttrs['method']);
  47. }
  48. $oPermalinks = BxDolPermalinks::getInstance();
  49. $sLink = $oForm->getCleanValue('link');
  50. $sLink = $oPermalinks->unpermalink($sLink);
  51. BxDolForm::setSubmittedValue('link', $sLink, $oForm->aFormAttrs['method']);
  52. $sName = $oPermalinks->getPageNameFromLink($sLink);
  53. if($sName == '') {
  54. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  55. $sName = BxDolForm::getSubmittedValue('title_system-' . $sLanguage, $oForm->aFormAttrs['method']);
  56. $sName = uriGenerate($sName, 'sys_menu_items', 'name', 'item');
  57. }
  58. bx_import('BxDolStudioUtils');
  59. $iId = (int)$oForm->insert(array('module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'name' => $sName, 'active' => 1, 'order' => $this->oDb->getItemOrderMax($this->sSet) + 1));
  60. if($iId != 0)
  61. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  62. else
  63. $aRes = array('msg' => _t('_adm_nav_err_items_create'));
  64. echoJson($aRes);
  65. }
  66. else {
  67. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-item-create-popup', _t('_adm_nav_txt_items_create_popup'), $this->_oTemplate->parseHtmlByName('nav_add_item.html', array(
  68. 'form_id' => $oForm->aFormAttrs['id'],
  69. 'form' => $oForm->getCode(true),
  70. 'object' => $this->_sObject,
  71. 'action' => $sAction
  72. )));
  73. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  74. }
  75. }
  76. public function performActionEdit($bUpdateGrid = false)
  77. {
  78. $sAction = 'edit';
  79. $aItem = $this->_getItem('getItems');
  80. if($aItem === false) {
  81. echoJson(array());
  82. exit;
  83. }
  84. $oForm = $this->_getFormObject($sAction, $aItem);
  85. $oForm->initChecker();
  86. if($oForm->isSubmittedAndValid()) {
  87. $bIconImageCur = is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0;
  88. $bIconImageNew = !empty($_FILES['icon_image']['tmp_name']);
  89. $sIconFont = $oForm->getCleanValue('icon');
  90. $bIconFont = !empty($sIconFont);
  91. if($bIconImageCur && ($bIconImageNew || $bIconFont)) {
  92. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  93. if(!$oStorage->deleteFile((int)$aItem['icon'], 0)) {
  94. echoJson(array('msg' => _t('_adm_nav_err_items_icon_image_remove')));
  95. return;
  96. }
  97. }
  98. $sIcon = $sIconFont;
  99. if($bIconImageNew) {
  100. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  101. $sIcon = $oStorage->storeFileFromForm($_FILES['icon_image'], false, 0);
  102. if($sIcon === false) {
  103. echoJson(array('msg' => _t('_adm_nav_err_items_icon_image') . $oStorage->getErrorString()));
  104. return;
  105. }
  106. $oStorage->afterUploadCleanup($sIcon, 0);
  107. } else if($bIconImageCur && !$bIconFont)
  108. $sIcon = $aItem['icon'];
  109. BxDolForm::setSubmittedValue('icon', $sIcon, $oForm->aFormAttrs['method']);
  110. $sLink = $oForm->getCleanValue('link');
  111. $sLink = BxDolPermalinks::getInstance()->unpermalink($sLink);
  112. BxDolForm::setSubmittedValue('link', $sLink, $oForm->aFormAttrs['method']);
  113. $sSubmenu = $oForm->getCleanValue('submenu_object');
  114. if(empty($sSubmenu))
  115. BxDolForm::setSubmittedValue('submenu_popup', 0, $oForm->aFormAttrs['method']);
  116. $sTarget = $oForm->getCleanValue('target');
  117. if($sTarget === false && !in_array($aItem['target'], array('', '_blank')))
  118. unset($oForm->aInputs['target']);
  119. if($oForm->update($aItem['id']) !== false)
  120. $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
  121. else
  122. $aRes = array('msg' => _t('_adm_nav_err_items_edit'));
  123. echoJson($aRes);
  124. }
  125. else {
  126. $sTitle = _t($aItem['title']);
  127. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-item-edit-popup', _t('_adm_nav_txt_items_edit_popup', ($sTitle != "" ? '"' . $sTitle . '"' : '')), $this->_oTemplate->parseHtmlByName('nav_add_item.html', array(
  128. 'form_id' => $oForm->aFormAttrs['id'],
  129. 'form' => $oForm->getCode(true),
  130. 'object' => $this->_sObject,
  131. 'action' => $sAction
  132. )));
  133. $aRes = array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false)));
  134. if($bUpdateGrid)
  135. $aRes = array_merge($aRes, array('grid' => $this->getCode(false), 'blink' => $aItem['id']));
  136. echoJson($aRes);
  137. }
  138. }
  139. public function performActionDelete()
  140. {
  141. $iAffected = 0;
  142. $aIds = bx_get('ids');
  143. if(!$aIds || !is_array($aIds)) {
  144. echoJson(array());
  145. exit;
  146. }
  147. $aIdsAffected = array ();
  148. foreach($aIds as $iId) {
  149. if(!$this->deleteById($iId))
  150. continue;
  151. $aIdsAffected[] = $iId;
  152. $iAffected++;
  153. }
  154. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_items_delete')));
  155. }
  156. public function performActionShowTo()
  157. {
  158. $sAction = 'show_to';
  159. $aItem = $this->_getItem('getItems');
  160. if($aItem === false) {
  161. echoJson(array());
  162. exit;
  163. }
  164. bx_import('BxDolStudioUtils');
  165. $aForm = array(
  166. 'form_attrs' => array(
  167. 'id' => 'adm-nav-item-create',
  168. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&set=' . $this->sSet,
  169. 'method' => 'post'
  170. ),
  171. 'params' => array (
  172. 'db' => array(
  173. 'table' => 'sys_menu_items',
  174. 'key' => 'id',
  175. 'uri' => '',
  176. 'uri_title' => '',
  177. 'submit_name' => 'do_submit'
  178. ),
  179. ),
  180. 'inputs' => array (
  181. 'id' => array(
  182. 'type' => 'hidden',
  183. 'name' => 'id',
  184. 'value' => $aItem['id'],
  185. 'db' => array (
  186. 'pass' => 'Int',
  187. ),
  188. ),
  189. 'visible_for' => array(
  190. 'type' => 'select',
  191. 'name' => 'visible_for',
  192. 'caption' => _t('_adm_nav_txt_items_visible_for'),
  193. 'info' => '',
  194. 'value' => $aItem['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  195. 'values' => array(
  196. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_nav_txt_items_visible_for_all')),
  197. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_nav_txt_items_visible_for_selected')),
  198. ),
  199. 'required' => '0',
  200. 'attrs' => array(
  201. 'onchange' => $this->getJsObject() . '.onChangeVisibleFor(this)'
  202. ),
  203. 'db' => array (
  204. 'pass' => 'Xss',
  205. )
  206. ),
  207. 'visible_for_levels' => array(
  208. 'type' => 'checkbox_set',
  209. 'name' => 'visible_for_levels',
  210. 'caption' => _t('_adm_nav_txt_items_visible_for_levels'),
  211. 'info' => _t('_adm_nav_dsc_items_visible_for_levels'),
  212. 'value' => '',
  213. 'values' => array(),
  214. 'tr_attrs' => array(
  215. 'style' => $aItem['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
  216. ),
  217. 'db' => array (
  218. 'pass' => 'Int',
  219. ),
  220. ),
  221. 'controls' => array(
  222. 'name' => 'controls',
  223. 'type' => 'input_set',
  224. array(
  225. 'type' => 'submit',
  226. 'name' => 'do_submit',
  227. 'value' => _t('_adm_nav_btn_items_save'),
  228. ),
  229. array (
  230. 'type' => 'reset',
  231. 'name' => 'close',
  232. 'value' => _t('_adm_nav_btn_items_cancel'),
  233. 'attrs' => array(
  234. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  235. 'class' => 'bx-def-margin-sec-left',
  236. ),
  237. )
  238. )
  239. )
  240. );
  241. BxDolStudioUtils::getVisibilityValues($aItem['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  242. $oForm = new BxTemplStudioFormView($aForm);
  243. $oForm->initChecker();
  244. if($oForm->isSubmittedAndValid()) {
  245. if($oForm->updateWithVisibility($aItem['id']) !== false)
  246. $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
  247. else
  248. $aRes = array('msg' => _t('_adm_nav_err_items_show_to'));
  249. echoJson($aRes);
  250. }
  251. else {
  252. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-item-hide-from-popup', _t('_adm_nav_txt_items_show_to_popup', _t($aItem['title'])), $this->_oTemplate->parseHtmlByName('nav_add_item.html', array(
  253. 'form_id' => $aForm['form_attrs']['id'],
  254. 'form' => $oForm->getCode(true),
  255. 'object' => $this->_sObject,
  256. 'action' => $sAction
  257. )));
  258. echoJson(array('popup' => $sContent));
  259. }
  260. }
  261. public function performActionDeleteIcon()
  262. {
  263. $sAction = 'delete_icon';
  264. $aIds = bx_get('ids');
  265. if(empty($aIds[0])) {
  266. echoJson(array());
  267. exit;
  268. }
  269. $iId = (int)$aIds[0];
  270. $aItem = array();
  271. $iItem = $this->oDb->getItems(array('type' => 'by_id', 'value' => $iId), $aItem);
  272. if($iItem != 1 || empty($aItem)){
  273. echoJson(array());
  274. exit;
  275. }
  276. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0)
  277. if(!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$aItem['icon'], 0)) {
  278. echoJson(array());
  279. exit;
  280. }
  281. if($this->oDb->updateItem($aItem['id'], array('icon' => '')) !== false)
  282. echoJson(array('grid' => $this->getCode(false), 'blink' => $iId, 'preview' => $this->_getIconPreview($aItem['id']), 'eval' => $this->getJsObject() . ".onDeleteIcon(oData)"));
  283. }
  284. public function getJsObject()
  285. {
  286. return 'oBxDolStudioNavigationItems';
  287. }
  288. public function getSetsSelector($sModule = '')
  289. {
  290. $oForm = new BxTemplStudioFormView(array());
  291. $aInputSets = array(
  292. 'type' => 'select',
  293. 'name' => 'set',
  294. 'attrs' => array(
  295. 'id' => 'bx-grid-set-' . $this->_sObject,
  296. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeSet()'
  297. ),
  298. 'value' => $this->sSet,
  299. 'values' => array()
  300. );
  301. $aSets = array();
  302. if(!empty($sModule))
  303. $this->oDb->getSets(array('type' => 'by_module', 'value' => $sModule), $aSets, false);
  304. else
  305. $aInputSets['attrs']['disabled'] = 'disabled';
  306. if(!empty($aSets)) {
  307. $aCounter = array();
  308. $this->oDb->getItems(array('type' => 'counter_by_sets'), $aCounter, false);
  309. foreach($aSets as $aSet)
  310. $aInputSets['values'][$aSet['name']] = _t($aSet['title']) . " (" . (isset($aCounter[$aSet['name']]) ? $aCounter[$aSet['name']] : "0") . ")";
  311. asort($aInputSets['values']);
  312. }
  313. $aInputSets['values'] = array_merge(array('' => _t('_adm_nav_txt_select_set')), $aInputSets['values']);
  314. return $oForm->genRow($aInputSets);
  315. }
  316. public function getCode($isDisplayHeader = true)
  317. {
  318. return $this->_oTemplate->parseHtmlByName('nav_items.html', array(
  319. 'content' => parent::getCode($isDisplayHeader),
  320. 'js_object' => $this->getJsObject(),
  321. 'page_url' => $this->sUrlPage,
  322. 'grid_object' => $this->_sObject,
  323. 'params_divider' => $this->sParamsDivider
  324. ));
  325. }
  326. protected function _addJsCss()
  327. {
  328. parent::_addJsCss();
  329. $this->_oTemplate->addJs(array('jquery.form.min.js', 'navigation_items.js', 'navigation_import.js'));
  330. $oForm = new BxTemplStudioFormView(array());
  331. $oForm->addCssJs();
  332. }
  333. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  334. {
  335. if(!$this->_isEditable($aRow))
  336. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  337. return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
  338. }
  339. protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow)
  340. {
  341. $mixedValue = $this->_oTemplate->getIcon($mixedValue, array('class' => 'bx-nav-item-icon bx-def-border'));
  342. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  343. }
  344. protected function _getCellLink ($mixedValue, $sKey, $aField, $aRow)
  345. {
  346. if($aRow['submenu_object'] != "") {
  347. $aMenu = array();
  348. $this->oDb->getMenus(array('type' => 'by_object', 'value' => $aRow['submenu_object']), $aMenu, false);
  349. $sPrefix = _t('_adm_nav_txt_items_gl_link_menu');
  350. if(!empty($aMenu) && is_array($aMenu)) {
  351. $aField['chars_limit'] -= strlen($sPrefix);
  352. $aValue = $this->_limitMaxLength(_t($aMenu['title']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow, false);
  353. $sLink = sprintf($this->sUrlViewItems, $aMenu['module'], $aMenu['set_name']);
  354. $mixedValue = $sPrefix . ' ' . $this->_oTemplate->parseLink($sLink, $aValue[0], array(
  355. 'title' => _t('_adm_nav_txt_manage_items')
  356. )) . (isset($aValue[1]) ? $aValue[1] : '');
  357. }
  358. else
  359. $mixedValue = $sPrefix . ' ' . _t('_undefined');
  360. } else if($aRow['submenu_object'] == "" && $aRow['onclick'] != "")
  361. $mixedValue = $this->_limitMaxLength(_t('_adm_nav_txt_items_gl_link_custom'), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  362. else
  363. $mixedValue = BxDolPermalinks::getInstance()->permalink($mixedValue);
  364. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  365. }
  366. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  367. {
  368. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  369. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  370. }
  371. protected function _getCellVisibleForLevels ($mixedValue, $sKey, $aField, $aRow)
  372. {
  373. if(!$this->_isEditable($aRow))
  374. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  375. $mixedValue = $this->_oTemplate->parseLink('javascript:void(0)', BxDolStudioUtils::getVisibilityTitle($aRow['visible_for_levels']), array(
  376. 'title' => _t('_adm_nav_txt_manage_visibility'),
  377. 'bx_grid_action_single' => 'show_to',
  378. 'bx_grid_action_data' => $aRow['id']
  379. ));
  380. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  381. }
  382. protected function _getActionImport ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  383. {
  384. if($this->sSet == '')
  385. $isDisabled = true;
  386. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  387. }
  388. protected function _getActionAdd ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  389. {
  390. if($this->sSet == '')
  391. $isDisabled = true;
  392. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  393. }
  394. protected function _getActionEdit ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  395. {
  396. if($sType == 'single' && !$this->_isEditable($aRow))
  397. return '';
  398. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  399. }
  400. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  401. {
  402. if ($sType == 'single' && !$this->_isDeletable($aRow))
  403. return '';
  404. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  405. }
  406. protected function _getActionShowTo ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  407. {
  408. return '';
  409. }
  410. protected function _getActionDeleteIcon ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  411. {
  412. return '';
  413. }
  414. protected function _getActionsDisabledBehavior($aRow)
  415. {
  416. return false;
  417. }
  418. protected function _getFilterControls ()
  419. {
  420. parent::_getFilterControls();
  421. $sContent = $this->getModulesSelectOne('getItems') . $this->getSetsSelector($this->sModule);
  422. $oForm = new BxTemplStudioFormView(array());
  423. $aInputSearch = array(
  424. 'type' => 'text',
  425. 'name' => 'keyword',
  426. 'attrs' => array(
  427. 'id' => 'bx-grid-search-' . $this->_sObject,
  428. ),
  429. 'tr_attrs' => array(
  430. 'style' => 'display:none;'
  431. )
  432. );
  433. $sContent .= $oForm->genRow($aInputSearch);
  434. return $sContent;
  435. }
  436. protected function _getFormObject($sAction, $aItem = array())
  437. {
  438. bx_import('BxTemplStudioFormView');
  439. $aForm = array(
  440. 'form_attrs' => array(
  441. 'id' => 'adm-nav-item-',
  442. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&set=' . $this->sSet,
  443. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT,
  444. 'enctype' => 'multipart/form-data',
  445. ),
  446. 'params' => array (
  447. 'db' => array(
  448. 'table' => 'sys_menu_items',
  449. 'key' => 'id',
  450. 'uri' => '',
  451. 'uri_title' => '',
  452. 'submit_name' => 'do_submit'
  453. ),
  454. ),
  455. 'inputs' => array (
  456. 'id' => array(
  457. 'type' => 'hidden',
  458. 'name' => 'id',
  459. 'value' => isset($aItem['id']) ? (int)$aItem['id'] : 0,
  460. 'db' => array (
  461. 'pass' => 'Int',
  462. ),
  463. ),
  464. 'set_name' => array(
  465. 'type' => 'hidden',
  466. 'name' => 'set_name',
  467. 'value' => $this->sSet,
  468. 'db' => array (
  469. 'pass' => 'Xss',
  470. ),
  471. ),
  472. 'title_system' => array(
  473. 'type' => 'text_translatable',
  474. 'name' => 'title_system',
  475. 'caption' => _t('_adm_nav_txt_items_title_system'),
  476. 'info' => _t('_adm_nav_dsc_items_title_system'),
  477. 'value' => isset($aItem['title_system']) ? $aItem['title_system'] : '_adm_nav_txt_item',
  478. 'required' => '1',
  479. 'db' => array (
  480. 'pass' => 'Xss',
  481. ),
  482. 'checker' => array (
  483. 'func' => 'LengthTranslatable',
  484. 'params' => array(3, 100, 'title_system'),
  485. 'error' => _t('_adm_nav_err_items_title_system'),
  486. ),
  487. ),
  488. 'title' => array(
  489. 'type' => 'text_translatable',
  490. 'name' => 'title',
  491. 'caption' => _t('_adm_nav_txt_items_title'),
  492. 'info' => _t('_adm_nav_dsc_items_title'),
  493. 'value' => isset($aItem['title']) ? $aItem['title'] : '_adm_nav_txt_item',
  494. 'required' => '0',
  495. 'db' => array (
  496. 'pass' => 'Xss',
  497. ),
  498. ),
  499. 'submenu_object' => array(
  500. 'type' => 'select',
  501. 'name' => 'submenu_object',
  502. 'caption' => _t('_adm_nav_txt_items_submenu'),
  503. 'info' => _t('_adm_nav_dsc_items_submenu'),
  504. 'value' => isset($aItem['submenu_object']) ? $aItem['submenu_object'] : '',
  505. 'values' => array(),
  506. 'required' => '0',
  507. 'attrs' => array(
  508. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeSubmenu(this)'
  509. ),
  510. 'db' => array (
  511. 'pass' => 'Xss',
  512. ),
  513. ),
  514. 'submenu_popup' => array(
  515. 'type' => 'switcher',
  516. 'name' => 'submenu_popup',
  517. 'caption' => _t('_adm_nav_txt_items_submenu_popup'),
  518. 'info' => '',
  519. 'value' => '1',
  520. 'checked' => isset($aItem['submenu_popup']) && $aItem['submenu_popup'] == '1',
  521. 'attrs' => array(
  522. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeSubmenu(this)'
  523. ),
  524. 'db' => array (
  525. 'pass' => 'Int',
  526. )
  527. ),
  528. 'link' => array(
  529. 'type' => 'text',
  530. 'name' => 'link',
  531. 'caption' => _t('_adm_nav_txt_items_link'),
  532. 'info' => _t('_adm_nav_dsc_items_link'),
  533. 'value' => isset($aItem['link']) ? $aItem['link'] : '',
  534. 'required' => '0',
  535. 'db' => array (
  536. 'pass' => 'Xss',
  537. ),
  538. 'checker' => array (
  539. 'func' => '',
  540. 'params' => array(),
  541. 'error' => _t('_adm_nav_err_items_link'),
  542. ),
  543. ),
  544. 'target' => array(
  545. 'type' => 'select',
  546. 'name' => 'target',
  547. 'caption' => _t('_adm_nav_txt_items_target'),
  548. 'info' => _t('_adm_nav_dsc_items_target'),
  549. 'value' => isset($aItem['target']) ? $aItem['target'] : '_self',
  550. 'values' => array(
  551. array('key' => '', 'value' => _t('_adm_nav_txt_items_target_self')),
  552. array('key' => '_blank', 'value' => _t('_adm_nav_txt_items_target_blank'))
  553. ),
  554. 'required' => '0',
  555. 'db' => array (
  556. 'pass' => 'Xss',
  557. )
  558. ),
  559. 'onclick' => array(
  560. 'type' => 'text',
  561. 'name' => 'onclick',
  562. 'caption' => _t('_adm_nav_txt_items_onclick'),
  563. 'info' => _t('_adm_nav_dsc_items_onclick'),
  564. 'value' => isset($aItem['onclick']) ? $aItem['onclick'] : '',
  565. 'required' => '0',
  566. 'db' => array (
  567. 'pass' => 'Xss',
  568. ),
  569. 'checker' => array (
  570. 'func' => '',
  571. 'params' => array(),
  572. 'error' => _t('_adm_nav_err_items_onclick'),
  573. ),
  574. ),
  575. 'hidden_on' => array(
  576. 'type' => 'select_multiple',
  577. 'name' => 'hidden_on',
  578. 'caption' => _t('_adm_nav_txt_block_hidden_on'),
  579. 'info' => '',
  580. 'value' => isset($aItem['hidden_on']) ? (int)$aItem['hidden_on'] : '',
  581. 'values' => array(
  582. BX_DB_HIDDEN_PHONE => _t('_adm_nav_txt_block_hidden_on_phone'),
  583. BX_DB_HIDDEN_TABLET => _t('_adm_nav_txt_block_hidden_on_tablet'),
  584. BX_DB_HIDDEN_DESKTOP => _t('_adm_nav_txt_block_hidden_on_desktop'),
  585. BX_DB_HIDDEN_MOBILE => _t('_adm_nav_txt_block_hidden_on_mobile')
  586. ),
  587. 'db' => array (
  588. 'pass' => 'Set',
  589. )
  590. ),
  591. 'icon' => array(
  592. 'type' => 'text',
  593. 'name' => 'icon',
  594. 'caption' => _t('_adm_nav_txt_items_icon'),
  595. 'info' => _t('_adm_nav_dsc_items_icon'),
  596. 'value' => '',
  597. 'required' => '0',
  598. 'db' => array (
  599. 'pass' => 'Xss',
  600. ),
  601. 'checker' => array (
  602. 'func' => '',
  603. 'params' => array(),
  604. 'error' => _t('_adm_nav_err_items_icon'),
  605. ),
  606. ),
  607. 'icon_image' => array(
  608. 'type' => 'file',
  609. 'name' => 'icon_image',
  610. 'caption' => _t('_adm_nav_txt_items_icon_image'),
  611. 'info' => _t('_adm_nav_dsc_items_icon_image'),
  612. 'value' => '',
  613. 'checker' => array (
  614. 'func' => '',
  615. 'params' => '',
  616. 'error' => _t('_adm_nav_err_items_icon_image'),
  617. ),
  618. ),
  619. 'icon_preview' => array(
  620. 'type' => 'custom',
  621. 'name' => 'icon_preview',
  622. 'caption' => _t('_adm_nav_txt_items_icon_image_old'),
  623. 'content' => ''
  624. ),
  625. 'controls' => array(
  626. 'name' => 'controls',
  627. 'type' => 'input_set',
  628. array(
  629. 'type' => 'submit',
  630. 'name' => 'do_submit',
  631. 'value' => _t('_adm_nav_btn_items_add'),
  632. ),
  633. array (
  634. 'type' => 'reset',
  635. 'name' => 'close',
  636. 'value' => _t('_adm_nav_btn_items_cancel'),
  637. 'attrs' => array(
  638. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  639. 'class' => 'bx-def-margin-sec-left',
  640. ),
  641. )
  642. )
  643. )
  644. );
  645. $aMenus = array();
  646. $this->oDb->getMenus(array('type' => 'all'), $aMenus, false);
  647. foreach($aMenus as $aMenu)
  648. $aForm['inputs']['submenu_object']['values'][$aMenu['object']] = _t($aMenu['title']);
  649. asort($aForm['inputs']['submenu_object']['values']);
  650. $aForm['inputs']['submenu_object']['values'] = array_merge(array('' => _t('_adm_nav_txt_items_submenu_empty')), $aForm['inputs']['submenu_object']['values']);
  651. switch($sAction) {
  652. case 'add':
  653. unset($aForm['inputs']['id']);
  654. unset($aForm['inputs']['icon_preview']);
  655. $aForm['form_attrs']['id'] .= 'create';
  656. break;
  657. case 'edit':
  658. unset($aForm['inputs']['set_name']);
  659. $aForm['form_attrs']['id'] .= 'edit';
  660. $aForm['inputs']['icon_image']['caption'] = _t('_adm_nav_txt_items_icon_image_new');
  661. $aForm['inputs']['controls'][0]['value'] = _t('_adm_nav_btn_items_save');
  662. $bSubmenu = !empty($aItem['submenu_object']);
  663. if($bSubmenu !== true)
  664. $aForm['inputs']['submenu_popup']['tr_attrs']['style'] = 'display:none;';
  665. if(!$bSubmenu && ($aItem['onclick'] != "" || !in_array($aItem['target'], array('', '_blank')))) {
  666. $aForm['inputs']['submenu_object']['tr_attrs']['style'] = 'display:none;';
  667. $aForm['inputs']['link']['tr_attrs']['style'] = 'display:none;';
  668. $aForm['inputs']['target']['tr_attrs']['style'] = 'display:none;';
  669. }
  670. $sIconImage = $sIconFont = "";
  671. if(!empty($aItem['icon'])) {
  672. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0) {
  673. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  674. $sIconImage = $oStorage->getFileUrlById((int)$aItem['icon']);
  675. }
  676. else {
  677. $sIconFont = $aItem['icon'];
  678. $aForm['inputs']['icon']['value'] = $sIconFont;
  679. }
  680. }
  681. $aForm['inputs']['icon_preview']['content'] = $this->_getIconPreview($aItem['id'], $sIconImage, $sIconFont);
  682. break;
  683. }
  684. return new BxTemplStudioFormView($aForm);
  685. }
  686. protected function _getIconPreview($iId, $sIconImage = '', $sIconFont = '')
  687. {
  688. $bIconImage = !empty($sIconImage);
  689. $bIconFont = !empty($sIconFont);
  690. return $this->_oTemplate->parseHtmlByName('nav_item_icon_preview.html', array(
  691. 'id' => $iId,
  692. 'bx_if:show_icon_empty' => array(
  693. 'condition' => !$bIconImage && !$bIconFont,
  694. 'content' => array()
  695. ),
  696. 'bx_if:show_icon_image' => array(
  697. 'condition' => $bIconImage,
  698. 'content' => array(
  699. 'js_object' => $this->getJsObject(),
  700. 'url' => $sIconImage,
  701. 'id' => $iId
  702. )
  703. ),
  704. 'bx_if:show_icon_font' => array(
  705. 'condition' => $bIconFont,
  706. 'content' => array(
  707. 'icon' => $sIconFont
  708. )
  709. )
  710. ));
  711. }
  712. protected function _isEditable(&$aRow)
  713. {
  714. return (int)$aRow['editable'] != 0;
  715. }
  716. protected function _isDeletable(&$aRow)
  717. {
  718. return $aRow['module'] != BX_DOL_STUDIO_MODULE_SYSTEM;
  719. }
  720. }
  721. /** @} */