BxBaseStudioNavigationItems.php 33 KB

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