BxBaseStudioNavigationItems.php 32 KB

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