BxBaseStudioNavigationItems.php 33 KB

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