BxBaseStudioNavigationItems.php 32 KB

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