BxBaseStudioNavigationItems.php 32 KB

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