BxBaseStudioNavigationItems.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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. $aField['chars_limit'] -= strlen($sPrefix);
  351. $aValue = $this->_limitMaxLength(_t($aMenu['title']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow, false);
  352. $sLink = sprintf($this->sUrlViewItems, $aMenu['module'], $aMenu['set_name']);
  353. $mixedValue = $sPrefix . ' ' . $this->_oTemplate->parseLink($sLink, $aValue[0], array(
  354. 'title' => _t('_adm_nav_txt_manage_items')
  355. )) . (isset($aValue[1]) ? $aValue[1] : '');
  356. } else if($aRow['submenu_object'] == "" && $aRow['onclick'] != "")
  357. $mixedValue = $this->_limitMaxLength(_t('_adm_nav_txt_items_gl_link_custom'), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  358. else
  359. $mixedValue = BxDolPermalinks::getInstance()->permalink($mixedValue);
  360. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  361. }
  362. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  363. {
  364. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  365. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  366. }
  367. protected function _getCellVisibleForLevels ($mixedValue, $sKey, $aField, $aRow)
  368. {
  369. if(!$this->_isEditable($aRow))
  370. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  371. $mixedValue = $this->_oTemplate->parseLink('javascript:void(0)', BxDolStudioUtils::getVisibilityTitle($aRow['visible_for_levels']), array(
  372. 'title' => _t('_adm_nav_txt_manage_visibility'),
  373. 'bx_grid_action_single' => 'show_to',
  374. 'bx_grid_action_data' => $aRow['id']
  375. ));
  376. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  377. }
  378. protected function _getActionImport ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  379. {
  380. if($this->sSet == '')
  381. $isDisabled = true;
  382. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  383. }
  384. protected function _getActionAdd ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  385. {
  386. if($this->sSet == '')
  387. $isDisabled = true;
  388. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  389. }
  390. protected function _getActionEdit ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  391. {
  392. if($sType == 'single' && !$this->_isEditable($aRow))
  393. return '';
  394. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  395. }
  396. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  397. {
  398. if ($sType == 'single' && !$this->_isDeletable($aRow))
  399. return '';
  400. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  401. }
  402. protected function _getActionShowTo ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  403. {
  404. return '';
  405. }
  406. protected function _getActionDeleteIcon ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  407. {
  408. return '';
  409. }
  410. protected function _getActionsDisabledBehavior($aRow)
  411. {
  412. return false;
  413. }
  414. protected function _getFilterControls ()
  415. {
  416. parent::_getFilterControls();
  417. $sContent = $this->getModulesSelectOne('getItems') . $this->getSetsSelector($this->sModule);
  418. $oForm = new BxTemplStudioFormView(array());
  419. $aInputSearch = array(
  420. 'type' => 'text',
  421. 'name' => 'keyword',
  422. 'attrs' => array(
  423. 'id' => 'bx-grid-search-' . $this->_sObject,
  424. ),
  425. 'tr_attrs' => array(
  426. 'style' => 'display:none;'
  427. )
  428. );
  429. $sContent .= $oForm->genRow($aInputSearch);
  430. return $sContent;
  431. }
  432. protected function _getFormObject($sAction, $aItem = array())
  433. {
  434. bx_import('BxTemplStudioFormView');
  435. $aForm = array(
  436. 'form_attrs' => array(
  437. 'id' => 'adm-nav-item-',
  438. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&set=' . $this->sSet,
  439. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT,
  440. 'enctype' => 'multipart/form-data',
  441. ),
  442. 'params' => array (
  443. 'db' => array(
  444. 'table' => 'sys_menu_items',
  445. 'key' => 'id',
  446. 'uri' => '',
  447. 'uri_title' => '',
  448. 'submit_name' => 'do_submit'
  449. ),
  450. ),
  451. 'inputs' => array (
  452. 'id' => array(
  453. 'type' => 'hidden',
  454. 'name' => 'id',
  455. 'value' => isset($aItem['id']) ? (int)$aItem['id'] : 0,
  456. 'db' => array (
  457. 'pass' => 'Int',
  458. ),
  459. ),
  460. 'set_name' => array(
  461. 'type' => 'hidden',
  462. 'name' => 'set_name',
  463. 'value' => $this->sSet,
  464. 'db' => array (
  465. 'pass' => 'Xss',
  466. ),
  467. ),
  468. 'title_system' => array(
  469. 'type' => 'text_translatable',
  470. 'name' => 'title_system',
  471. 'caption' => _t('_adm_nav_txt_items_title_system'),
  472. 'info' => _t('_adm_nav_dsc_items_title_system'),
  473. 'value' => isset($aItem['title_system']) ? $aItem['title_system'] : '_adm_nav_txt_item',
  474. 'required' => '1',
  475. 'db' => array (
  476. 'pass' => 'Xss',
  477. ),
  478. 'checker' => array (
  479. 'func' => 'LengthTranslatable',
  480. 'params' => array(3, 100, 'title_system'),
  481. 'error' => _t('_adm_nav_err_items_title_system'),
  482. ),
  483. ),
  484. 'title' => array(
  485. 'type' => 'text_translatable',
  486. 'name' => 'title',
  487. 'caption' => _t('_adm_nav_txt_items_title'),
  488. 'info' => _t('_adm_nav_dsc_items_title'),
  489. 'value' => isset($aItem['title']) ? $aItem['title'] : '_adm_nav_txt_item',
  490. 'required' => '0',
  491. 'db' => array (
  492. 'pass' => 'Xss',
  493. ),
  494. ),
  495. 'submenu_object' => array(
  496. 'type' => 'select',
  497. 'name' => 'submenu_object',
  498. 'caption' => _t('_adm_nav_txt_items_submenu'),
  499. 'info' => _t('_adm_nav_dsc_items_submenu'),
  500. 'value' => isset($aItem['submenu_object']) ? $aItem['submenu_object'] : '',
  501. 'values' => array(),
  502. 'required' => '0',
  503. 'attrs' => array(
  504. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeSubmenu(this)'
  505. ),
  506. 'db' => array (
  507. 'pass' => 'Xss',
  508. ),
  509. ),
  510. 'submenu_popup' => array(
  511. 'type' => 'switcher',
  512. 'name' => 'submenu_popup',
  513. 'caption' => _t('_adm_nav_txt_items_submenu_popup'),
  514. 'info' => '',
  515. 'value' => '1',
  516. 'checked' => isset($aItem['submenu_popup']) && $aItem['submenu_popup'] == '1',
  517. 'attrs' => array(
  518. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeSubmenu(this)'
  519. ),
  520. 'db' => array (
  521. 'pass' => 'Int',
  522. )
  523. ),
  524. 'link' => array(
  525. 'type' => 'text',
  526. 'name' => 'link',
  527. 'caption' => _t('_adm_nav_txt_items_link'),
  528. 'info' => _t('_adm_nav_dsc_items_link'),
  529. 'value' => isset($aItem['link']) ? $aItem['link'] : '',
  530. 'required' => '0',
  531. 'db' => array (
  532. 'pass' => 'Xss',
  533. ),
  534. 'checker' => array (
  535. 'func' => '',
  536. 'params' => array(),
  537. 'error' => _t('_adm_nav_err_items_link'),
  538. ),
  539. ),
  540. 'target' => array(
  541. 'type' => 'select',
  542. 'name' => 'target',
  543. 'caption' => _t('_adm_nav_txt_items_target'),
  544. 'info' => _t('_adm_nav_dsc_items_target'),
  545. 'value' => isset($aItem['target']) ? $aItem['target'] : '_self',
  546. 'values' => array(
  547. array('key' => '', 'value' => _t('_adm_nav_txt_items_target_self')),
  548. array('key' => '_blank', 'value' => _t('_adm_nav_txt_items_target_blank'))
  549. ),
  550. 'required' => '0',
  551. 'db' => array (
  552. 'pass' => 'Xss',
  553. )
  554. ),
  555. 'onclick' => array(
  556. 'type' => 'text',
  557. 'name' => 'onclick',
  558. 'caption' => _t('_adm_nav_txt_items_onclick'),
  559. 'info' => _t('_adm_nav_dsc_items_onclick'),
  560. 'value' => isset($aItem['onclick']) ? $aItem['onclick'] : '',
  561. 'required' => '0',
  562. 'db' => array (
  563. 'pass' => 'Xss',
  564. ),
  565. 'checker' => array (
  566. 'func' => '',
  567. 'params' => array(),
  568. 'error' => _t('_adm_nav_err_items_onclick'),
  569. ),
  570. ),
  571. 'hidden_on' => array(
  572. 'type' => 'select_multiple',
  573. 'name' => 'hidden_on',
  574. 'caption' => _t('_adm_nav_txt_block_hidden_on'),
  575. 'info' => '',
  576. 'value' => (int)$aItem['hidden_on'],
  577. 'values' => array(
  578. BX_DB_HIDDEN_PHONE => _t('_adm_nav_txt_block_hidden_on_phone'),
  579. BX_DB_HIDDEN_TABLET => _t('_adm_nav_txt_block_hidden_on_tablet'),
  580. BX_DB_HIDDEN_DESKTOP => _t('_adm_nav_txt_block_hidden_on_desktop')
  581. ),
  582. 'db' => array (
  583. 'pass' => 'Set',
  584. )
  585. ),
  586. 'icon' => array(
  587. 'type' => 'text',
  588. 'name' => 'icon',
  589. 'caption' => _t('_adm_nav_txt_items_icon'),
  590. 'info' => _t('_adm_nav_dsc_items_icon'),
  591. 'value' => '',
  592. 'required' => '0',
  593. 'db' => array (
  594. 'pass' => 'Xss',
  595. ),
  596. 'checker' => array (
  597. 'func' => '',
  598. 'params' => array(),
  599. 'error' => _t('_adm_nav_err_items_icon'),
  600. ),
  601. ),
  602. 'icon_image' => array(
  603. 'type' => 'file',
  604. 'name' => 'icon_image',
  605. 'caption' => _t('_adm_nav_txt_items_icon_image'),
  606. 'info' => _t('_adm_nav_dsc_items_icon_image'),
  607. 'value' => '',
  608. 'checker' => array (
  609. 'func' => '',
  610. 'params' => '',
  611. 'error' => _t('_adm_nav_err_items_icon_image'),
  612. ),
  613. ),
  614. 'icon_preview' => array(
  615. 'type' => 'custom',
  616. 'name' => 'icon_preview',
  617. 'caption' => _t('_adm_nav_txt_items_icon_image_old'),
  618. 'content' => ''
  619. ),
  620. 'controls' => array(
  621. 'name' => 'controls',
  622. 'type' => 'input_set',
  623. array(
  624. 'type' => 'submit',
  625. 'name' => 'do_submit',
  626. 'value' => _t('_adm_nav_btn_items_add'),
  627. ),
  628. array (
  629. 'type' => 'reset',
  630. 'name' => 'close',
  631. 'value' => _t('_adm_nav_btn_items_cancel'),
  632. 'attrs' => array(
  633. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  634. 'class' => 'bx-def-margin-sec-left',
  635. ),
  636. )
  637. )
  638. )
  639. );
  640. $aMenus = array();
  641. $this->oDb->getMenus(array('type' => 'all'), $aMenus, false);
  642. foreach($aMenus as $aMenu)
  643. $aForm['inputs']['submenu_object']['values'][$aMenu['object']] = _t($aMenu['title']);
  644. asort($aForm['inputs']['submenu_object']['values']);
  645. $aForm['inputs']['submenu_object']['values'] = array_merge(array('' => _t('_adm_nav_txt_items_submenu_empty')), $aForm['inputs']['submenu_object']['values']);
  646. switch($sAction) {
  647. case 'add':
  648. unset($aForm['inputs']['id']);
  649. unset($aForm['inputs']['icon_preview']);
  650. $aForm['form_attrs']['id'] .= 'create';
  651. break;
  652. case 'edit':
  653. unset($aForm['inputs']['set_name']);
  654. $aForm['form_attrs']['id'] .= 'edit';
  655. $aForm['inputs']['icon_image']['caption'] = _t('_adm_nav_txt_items_icon_image_new');
  656. $aForm['inputs']['controls'][0]['value'] = _t('_adm_nav_btn_items_save');
  657. $bSubmenu = !empty($aItem['submenu_object']);
  658. if($bSubmenu !== true)
  659. $aForm['inputs']['submenu_popup']['tr_attrs']['style'] = 'display:none;';
  660. if(!$bSubmenu && ($aItem['onclick'] != "" || !in_array($aItem['target'], array('', '_blank')))) {
  661. $aForm['inputs']['submenu_object']['tr_attrs']['style'] = 'display:none;';
  662. $aForm['inputs']['link']['tr_attrs']['style'] = 'display:none;';
  663. $aForm['inputs']['target']['tr_attrs']['style'] = 'display:none;';
  664. }
  665. $sIconImage = $sIconFont = "";
  666. if(!empty($aItem['icon'])) {
  667. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0) {
  668. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  669. $sIconImage = $oStorage->getFileUrlById((int)$aItem['icon']);
  670. }
  671. else {
  672. $sIconFont = $aItem['icon'];
  673. $aForm['inputs']['icon']['value'] = $sIconFont;
  674. }
  675. }
  676. $aForm['inputs']['icon_preview']['content'] = $this->_getIconPreview($aItem['id'], $sIconImage, $sIconFont);
  677. break;
  678. }
  679. return new BxTemplStudioFormView($aForm);
  680. }
  681. protected function _getIconPreview($iId, $sIconImage = '', $sIconFont = '')
  682. {
  683. $bIconImage = !empty($sIconImage);
  684. $bIconFont = !empty($sIconFont);
  685. return $this->_oTemplate->parseHtmlByName('nav_item_icon_preview.html', array(
  686. 'id' => $iId,
  687. 'bx_if:show_icon_empty' => array(
  688. 'condition' => !$bIconImage && !$bIconFont,
  689. 'content' => array()
  690. ),
  691. 'bx_if:show_icon_image' => array(
  692. 'condition' => $bIconImage,
  693. 'content' => array(
  694. 'js_object' => $this->getJsObject(),
  695. 'url' => $sIconImage,
  696. 'id' => $iId
  697. )
  698. ),
  699. 'bx_if:show_icon_font' => array(
  700. 'condition' => $bIconFont,
  701. 'content' => array(
  702. 'icon' => $sIconFont
  703. )
  704. )
  705. ));
  706. }
  707. protected function _isEditable(&$aRow)
  708. {
  709. return (int)$aRow['editable'] != 0;
  710. }
  711. protected function _isDeletable(&$aRow)
  712. {
  713. return $aRow['module'] != BX_DOL_STUDIO_MODULE_SYSTEM;
  714. }
  715. }
  716. /** @} */