BxBaseStudioNavigationItems.php 32 KB

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