BxBaseStudioNavigationItems.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. bx_import('BxDolStudioUtils');
  11. class BxBaseStudioNavigationItems extends BxDolStudioNavigationItems
  12. {
  13. protected $sUrlPage;
  14. protected $sUrlViewItems;
  15. function __construct($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct($aOptions, $oTemplate);
  18. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_nav_btn_items_edit');
  19. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_nav_btn_items_delete');
  20. $this->sUrlPage = BX_DOL_URL_STUDIO . 'builder_menu.php?page=items';
  21. $this->sUrlViewItems = $this->sUrlPage . '&module=%s&set=%s';
  22. }
  23. public function performActionImport()
  24. {
  25. $oGrid = BxDolGrid::getObjectInstance('sys_studio_nav_import');
  26. if(!$oGrid)
  27. return '';
  28. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-item-import-popup', _t('_adm_nav_txt_items_import_popup'), $this->_oTemplate->parseHtmlByName('nav_import_item.html', array(
  29. 'grid' => $oGrid->getCode()
  30. )));
  31. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  32. }
  33. public function performActionAdd()
  34. {
  35. $sAction = 'add';
  36. $oForm = $this->_getFormObject($sAction);
  37. $oForm->initChecker();
  38. if($oForm->isSubmittedAndValid()) {
  39. if(!empty($_FILES['icon_image']['tmp_name'])) {
  40. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  41. $mixedIcon = $oStorage->storeFileFromForm($_FILES['icon_image'], false, 0);
  42. if($mixedIcon === false) {
  43. echoJson(array('msg' => _t('_adm_nav_err_items_icon_image') . $oStorage->getErrorString()));
  44. return;
  45. }
  46. $oStorage->afterUploadCleanup($mixedIcon, 0);
  47. BxDolForm::setSubmittedValue('icon', $mixedIcon, $oForm->aFormAttrs['method']);
  48. }
  49. $oPermalinks = BxDolPermalinks::getInstance();
  50. $sLink = $oForm->getCleanValue('link');
  51. $sLink = $oPermalinks->unpermalink($sLink);
  52. BxDolForm::setSubmittedValue('link', $sLink, $oForm->aFormAttrs['method']);
  53. $sName = $oPermalinks->getPageNameFromLink($sLink);
  54. if($sName == '') {
  55. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  56. $sName = BxDolForm::getSubmittedValue('title-' . $sLanguage, $oForm->aFormAttrs['method']);
  57. if(empty($sName))
  58. $sName = BxDolForm::getSubmittedValue('title_system-' . $sLanguage, $oForm->aFormAttrs['method']);
  59. $sName = uriGenerate($sName, 'sys_menu_items', 'name', ['empty' => 'item']);
  60. }
  61. bx_import('BxDolStudioUtils');
  62. $iId = (int)$oForm->insert(array('module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'name' => $sName, 'active' => 1, 'order' => $this->oDb->getItemOrderMax($this->sSet) + 1));
  63. if($iId != 0)
  64. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  65. else
  66. $aRes = array('msg' => _t('_adm_nav_err_items_create'));
  67. echoJson($aRes);
  68. }
  69. else {
  70. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-item-create-popup', _t('_adm_nav_txt_items_create_popup'), $this->_oTemplate->parseHtmlByName('nav_add_item.html', array(
  71. 'form_id' => $oForm->aFormAttrs['id'],
  72. 'form' => $oForm->getCode(true),
  73. 'object' => $this->_sObject,
  74. 'action' => $sAction
  75. )));
  76. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  77. }
  78. }
  79. public function performActionEdit($bUpdateGrid = false)
  80. {
  81. $sAction = 'edit';
  82. $aItem = $this->_getItem('getItems');
  83. if($aItem === false) {
  84. echoJson(array());
  85. exit;
  86. }
  87. $oForm = $this->_getFormObject($sAction, $aItem);
  88. $oForm->initChecker();
  89. if($oForm->isSubmittedAndValid()) {
  90. $bIconImageCur = is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0;
  91. $bIconImageNew = !empty($_FILES['icon_image']['tmp_name']);
  92. $sIconFont = $oForm->getCleanValue('icon');
  93. $bIconFont = !empty($sIconFont);
  94. if($bIconImageCur && ($bIconImageNew || $bIconFont)) {
  95. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  96. if(!$oStorage->deleteFile((int)$aItem['icon'], 0)) {
  97. echoJson(array('msg' => _t('_adm_nav_err_items_icon_image_remove')));
  98. return;
  99. }
  100. }
  101. $sIcon = $sIconFont;
  102. if($bIconImageNew) {
  103. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  104. $sIcon = $oStorage->storeFileFromForm($_FILES['icon_image'], false, 0);
  105. if($sIcon === false) {
  106. echoJson(array('msg' => _t('_adm_nav_err_items_icon_image') . $oStorage->getErrorString()));
  107. return;
  108. }
  109. $oStorage->afterUploadCleanup($sIcon, 0);
  110. } else if($bIconImageCur && !$bIconFont)
  111. $sIcon = $aItem['icon'];
  112. BxDolForm::setSubmittedValue('icon', $sIcon, $oForm->aFormAttrs['method']);
  113. $sLink = $oForm->getCleanValue('link');
  114. $sLink = BxDolPermalinks::getInstance()->unpermalink($sLink);
  115. BxDolForm::setSubmittedValue('link', $sLink, $oForm->aFormAttrs['method']);
  116. $sSubmenu = $oForm->getCleanValue('submenu_object');
  117. if(empty($sSubmenu))
  118. BxDolForm::setSubmittedValue('submenu_popup', 0, $oForm->aFormAttrs['method']);
  119. $sTarget = $oForm->getCleanValue('target');
  120. if($sTarget === false && !in_array($aItem['target'], array('', '_blank')))
  121. unset($oForm->aInputs['target']);
  122. if($oForm->update($aItem['id']) !== false)
  123. $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
  124. else
  125. $aRes = array('msg' => _t('_adm_nav_err_items_edit'));
  126. echoJson($aRes);
  127. }
  128. else {
  129. $sTitle = _t($aItem['title']);
  130. $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(
  131. 'form_id' => $oForm->aFormAttrs['id'],
  132. 'form' => $oForm->getCode(true),
  133. 'object' => $this->_sObject,
  134. 'action' => $sAction
  135. )));
  136. $aRes = array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false)));
  137. if($bUpdateGrid)
  138. $aRes = array_merge($aRes, array('grid' => $this->getCode(false), 'blink' => $aItem['id']));
  139. echoJson($aRes);
  140. }
  141. }
  142. public function performActionDelete()
  143. {
  144. $iAffected = 0;
  145. $aIds = bx_get('ids');
  146. if(!$aIds || !is_array($aIds))
  147. return echoJson([]);
  148. $aIdsAffected = [];
  149. foreach($aIds as $iId) {
  150. $aItem = [];
  151. $iItem = $this->oDb->getItems(['type' => 'by_id', 'value' => $iId], $aItem);
  152. if($iItem != 1 || empty($aItem) || !$this->_isDeletable($aItem))
  153. continue;
  154. if(!$this->deleteById($iId))
  155. continue;
  156. $aIdsAffected[] = $iId;
  157. $iAffected++;
  158. }
  159. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_items_delete')));
  160. }
  161. public function performActionShowTo()
  162. {
  163. $sAction = 'show_to';
  164. $aItem = $this->_getItem('getItems');
  165. if($aItem === false) {
  166. echoJson(array());
  167. exit;
  168. }
  169. bx_import('BxDolStudioUtils');
  170. $aForm = array(
  171. 'form_attrs' => array(
  172. 'id' => 'adm-nav-item-show-to',
  173. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&set=' . $this->sSet,
  174. 'method' => 'post'
  175. ),
  176. 'params' => array (
  177. 'db' => array(
  178. 'table' => 'sys_menu_items',
  179. 'key' => 'id',
  180. 'uri' => '',
  181. 'uri_title' => '',
  182. 'submit_name' => 'do_submit'
  183. ),
  184. ),
  185. 'inputs' => array (
  186. 'id' => array(
  187. 'type' => 'hidden',
  188. 'name' => 'id',
  189. 'value' => $aItem['id'],
  190. 'db' => array (
  191. 'pass' => 'Int',
  192. ),
  193. ),
  194. 'visible_for' => array(
  195. 'type' => 'select',
  196. 'name' => 'visible_for',
  197. 'caption' => _t('_adm_nav_txt_items_visible_for'),
  198. 'info' => '',
  199. 'value' => $aItem['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  200. 'values' => array(
  201. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_nav_txt_items_visible_for_all')),
  202. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_nav_txt_items_visible_for_selected')),
  203. ),
  204. 'required' => '0',
  205. 'attrs' => array(
  206. 'onchange' => $this->getJsObject() . '.onChangeVisibleFor(this)'
  207. ),
  208. 'db' => array (
  209. 'pass' => 'Xss',
  210. )
  211. ),
  212. 'visible_for_levels' => array(
  213. 'type' => 'checkbox_set',
  214. 'name' => 'visible_for_levels',
  215. 'caption' => _t('_adm_nav_txt_items_visible_for_levels'),
  216. 'info' => _t('_adm_nav_dsc_items_visible_for_levels'),
  217. 'value' => '',
  218. 'values' => array(),
  219. 'tr_attrs' => array(
  220. 'style' => $aItem['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
  221. ),
  222. 'db' => array (
  223. 'pass' => 'Int',
  224. ),
  225. ),
  226. 'controls' => array(
  227. 'name' => 'controls',
  228. 'type' => 'input_set',
  229. array(
  230. 'type' => 'submit',
  231. 'name' => 'do_submit',
  232. 'value' => _t('_adm_nav_btn_items_save'),
  233. ),
  234. array (
  235. 'type' => 'reset',
  236. 'name' => 'close',
  237. 'value' => _t('_adm_nav_btn_items_cancel'),
  238. 'attrs' => array(
  239. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  240. 'class' => 'bx-def-margin-sec-left',
  241. ),
  242. )
  243. )
  244. )
  245. );
  246. BxDolStudioUtils::getVisibilityValues($aItem['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  247. $oForm = new BxTemplStudioFormView($aForm);
  248. $oForm->initChecker();
  249. if($oForm->isSubmittedAndValid()) {
  250. if($oForm->updateWithVisibility($aItem['id']) !== false)
  251. $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
  252. else
  253. $aRes = array('msg' => _t('_adm_nav_err_items_show_to'));
  254. echoJson($aRes);
  255. }
  256. else {
  257. $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(
  258. 'form_id' => $aForm['form_attrs']['id'],
  259. 'form' => $oForm->getCode(true),
  260. 'object' => $this->_sObject,
  261. 'action' => $sAction
  262. )));
  263. echoJson(array('popup' => $sContent));
  264. }
  265. }
  266. public function performActionDeleteIcon()
  267. {
  268. $sAction = 'delete_icon';
  269. $aIds = bx_get('ids');
  270. if(empty($aIds[0])) {
  271. echoJson(array());
  272. exit;
  273. }
  274. $iId = (int)$aIds[0];
  275. $aItem = array();
  276. $iItem = $this->oDb->getItems(array('type' => 'by_id', 'value' => $iId), $aItem);
  277. if($iItem != 1 || empty($aItem)){
  278. echoJson(array());
  279. exit;
  280. }
  281. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0)
  282. if(!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$aItem['icon'], 0)) {
  283. echoJson(array());
  284. exit;
  285. }
  286. if($this->oDb->updateItem($aItem['id'], array('icon' => '')) !== false)
  287. echoJson(array('grid' => $this->getCode(false), 'blink' => $iId, 'preview' => $this->_getIconPreview($aItem['id']), 'eval' => $this->getJsObject() . ".onDeleteIcon(oData)"));
  288. }
  289. public function getJsObject()
  290. {
  291. return 'oBxDolStudioNavigationItems';
  292. }
  293. public function getSetsSelector($sModule = '')
  294. {
  295. $oForm = new BxTemplStudioFormView(array());
  296. $aInputSets = array(
  297. 'type' => 'select',
  298. 'name' => 'set',
  299. 'attrs' => array(
  300. 'id' => 'bx-grid-set-' . $this->_sObject,
  301. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeSet()'
  302. ),
  303. 'value' => $this->sSet,
  304. 'values' => array()
  305. );
  306. $aSets = array();
  307. if(!empty($sModule))
  308. $this->oDb->getSets(array('type' => 'by_module', 'value' => $sModule), $aSets, false);
  309. else
  310. $aInputSets['attrs']['disabled'] = 'disabled';
  311. if(!empty($aSets)) {
  312. $aCounter = array();
  313. $this->oDb->getItems(array('type' => 'counter_by_sets'), $aCounter, false);
  314. foreach($aSets as $aSet)
  315. $aInputSets['values'][$aSet['name']] = _t($aSet['title']) . " (" . (isset($aCounter[$aSet['name']]) ? $aCounter[$aSet['name']] : "0") . ")";
  316. asort($aInputSets['values']);
  317. }
  318. $aInputSets['values'] = array_merge(array('' => _t('_adm_nav_txt_select_set')), $aInputSets['values']);
  319. return $oForm->genRow($aInputSets);
  320. }
  321. public function getCode($isDisplayHeader = true)
  322. {
  323. return $this->_oTemplate->parseHtmlByName('nav_items.html', array(
  324. 'content' => parent::getCode($isDisplayHeader),
  325. 'js_object' => $this->getJsObject(),
  326. 'page_url' => $this->sUrlPage,
  327. 'grid_object' => $this->_sObject,
  328. 'params_divider' => $this->sParamsDivider
  329. ));
  330. }
  331. protected function _addJsCss()
  332. {
  333. parent::_addJsCss();
  334. $this->_oTemplate->addJs(array('jquery.form.min.js', 'navigation_items.js', 'navigation_import.js'));
  335. $oForm = new BxTemplStudioFormView(array());
  336. $oForm->addCssJs();
  337. }
  338. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  339. {
  340. if(!$this->_isEditable($aRow))
  341. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  342. return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
  343. }
  344. protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow)
  345. {
  346. $mixedValue = $this->_oTemplate->getIcon($mixedValue, array('class' => 'bx-item-icon'));
  347. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  348. }
  349. protected function _getCellTitleSystem ($mixedValue, $sKey, $aField, $aRow)
  350. {
  351. if(empty($mixedValue))
  352. $mixedValue = _t($aRow['title']);
  353. if((int)$aRow['active_api'] != 0)
  354. $mixedValue .= ' ' . $this->_oTemplate->parseImage($this->_oTemplate->getIconUrl('api.svg'), [
  355. 'class' => 'bx-std-api',
  356. 'title' => bx_html_attribute(_t('_adm_txt_active_api'))
  357. ]);
  358. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  359. }
  360. protected function _getCellLink ($mixedValue, $sKey, $aField, $aRow)
  361. {
  362. $aSubitems = array();
  363. $this->oDb->getItems(array('type' => 'by_parent_id', 'value' => $aRow['id']), $aSubitems, false);
  364. if(!empty($aSubitems) && is_array($aSubitems)) {
  365. $sPrefix = _t('_adm_nav_txt_items_gl_link_subitems');
  366. $aField['chars_limit'] -= strlen($sPrefix);
  367. $aTitles = array();
  368. foreach($aSubitems as $aSubitem)
  369. $aTitles[] = _t(!empty($aSubitem['title_system']) ? $aSubitem['title_system'] : $aSubitem['title']);
  370. $aValue = $this->_limitMaxLength(implode(', ', $aTitles), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow, false);
  371. $mixedValue = $sPrefix . ' ' . $aValue[0] . (isset($aValue[1]) ? $aValue[1] : '');
  372. }
  373. else if($aRow['submenu_object'] != "") {
  374. $aMenu = array();
  375. $this->oDb->getMenus(array('type' => 'by_object', 'value' => $aRow['submenu_object']), $aMenu, false);
  376. $sPrefix = _t('_adm_nav_txt_items_gl_link_menu');
  377. if(!empty($aMenu) && is_array($aMenu)) {
  378. $aField['chars_limit'] -= strlen($sPrefix);
  379. $aValue = $this->_limitMaxLength(_t($aMenu['title']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow, false);
  380. $sLink = sprintf($this->sUrlViewItems, $aMenu['module'], $aMenu['set_name']);
  381. $mixedValue = $sPrefix . ' ' . $this->_oTemplate->parseLink($sLink, $aValue[0], array(
  382. 'title' => _t('_adm_nav_txt_manage_items')
  383. )) . (isset($aValue[1]) ? $aValue[1] : '');
  384. }
  385. else
  386. $mixedValue = $sPrefix . ' ' . _t('_undefined');
  387. }
  388. else if($aRow['submenu_object'] == "" && $aRow['onclick'] != "")
  389. $mixedValue = $this->_limitMaxLength(_t('_adm_nav_txt_items_gl_link_custom'), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  390. else
  391. $mixedValue = $this->_limitMaxLength(BxDolPermalinks::getInstance()->permalink($aRow['link']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  392. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  393. }
  394. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  395. {
  396. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  397. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  398. }
  399. protected function _getCellVisibleForLevels ($mixedValue, $sKey, $aField, $aRow)
  400. {
  401. if(!$this->_isEditable($aRow))
  402. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  403. $mixedValue = $this->_oTemplate->parseLink('javascript:void(0)', BxDolStudioUtils::getVisibilityTitle($aRow['visible_for_levels']), array(
  404. 'title' => _t('_adm_nav_txt_manage_visibility'),
  405. 'bx_grid_action_single' => 'show_to',
  406. 'bx_grid_action_data' => $aRow['id']
  407. ));
  408. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  409. }
  410. protected function _getActionImport ($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 _getActionAdd ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  417. {
  418. if($this->sSet == '')
  419. $isDisabled = true;
  420. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  421. }
  422. protected function _getActionEdit ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  423. {
  424. if($sType == 'single' && !$this->_isEditable($aRow))
  425. return '';
  426. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  427. }
  428. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  429. {
  430. if ($sType == 'single' && !$this->_isDeletable($aRow))
  431. return '';
  432. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  433. }
  434. protected function _getActionShowTo ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  435. {
  436. return '';
  437. }
  438. protected function _getActionDeleteIcon ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  439. {
  440. return '';
  441. }
  442. protected function _getActionsDisabledBehavior($aRow)
  443. {
  444. return false;
  445. }
  446. protected function _getFilterControls ()
  447. {
  448. parent::_getFilterControls();
  449. $sContent = $this->getModulesSelectOne('getItems') . $this->getSetsSelector($this->sModule);
  450. $oForm = new BxTemplStudioFormView(array());
  451. $aInputSearch = array(
  452. 'type' => 'text',
  453. 'name' => 'keyword',
  454. 'attrs' => array(
  455. 'id' => 'bx-grid-search-' . $this->_sObject,
  456. ),
  457. 'tr_attrs' => array(
  458. 'style' => 'display:none;'
  459. )
  460. );
  461. $sContent .= $oForm->genRow($aInputSearch);
  462. return $sContent;
  463. }
  464. protected function _getFormObject($sAction, $aItem = array())
  465. {
  466. bx_import('BxTemplStudioFormView');
  467. $aForm = array(
  468. 'form_attrs' => array(
  469. 'id' => 'adm-nav-item-',
  470. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&set=' . $this->sSet,
  471. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT,
  472. 'enctype' => 'multipart/form-data',
  473. ),
  474. 'params' => array (
  475. 'db' => array(
  476. 'table' => 'sys_menu_items',
  477. 'key' => 'id',
  478. 'uri' => '',
  479. 'uri_title' => '',
  480. 'submit_name' => 'do_submit'
  481. ),
  482. ),
  483. 'inputs' => array (
  484. 'id' => array(
  485. 'type' => 'hidden',
  486. 'name' => 'id',
  487. 'value' => isset($aItem['id']) ? (int)$aItem['id'] : 0,
  488. 'db' => array (
  489. 'pass' => 'Int',
  490. ),
  491. ),
  492. 'set_name' => array(
  493. 'type' => 'hidden',
  494. 'name' => 'set_name',
  495. 'value' => $this->sSet,
  496. 'db' => array (
  497. 'pass' => 'Xss',
  498. ),
  499. ),
  500. 'title_system' => array(
  501. 'type' => 'text_translatable',
  502. 'name' => 'title_system',
  503. 'caption' => _t('_adm_nav_txt_items_title_system'),
  504. 'info' => _t('_adm_nav_dsc_items_title_system'),
  505. 'value' => isset($aItem['title_system']) ? $aItem['title_system'] : '_adm_nav_txt_item',
  506. 'required' => '0',
  507. 'db' => array (
  508. 'pass' => 'Xss',
  509. ),
  510. ),
  511. 'title' => array(
  512. 'type' => 'text_translatable',
  513. 'name' => 'title',
  514. 'caption' => _t('_adm_nav_txt_items_title'),
  515. 'info' => _t('_adm_nav_dsc_items_title'),
  516. 'value' => isset($aItem['title']) ? $aItem['title'] : '_adm_nav_txt_item',
  517. 'required' => '0',
  518. 'db' => array (
  519. 'pass' => 'Xss',
  520. ),
  521. ),
  522. 'title_attr' => array(
  523. 'type' => 'text_translatable',
  524. 'name' => 'title_attr',
  525. 'caption' => _t('_adm_nav_txt_items_title_attr'),
  526. 'info' => _t('_adm_nav_dsc_items_title_attr'),
  527. 'value' => isset($aItem['title_attr']) ? $aItem['title_attr'] : '_adm_nav_txt_item',
  528. 'required' => '0',
  529. 'db' => array (
  530. 'pass' => 'Xss',
  531. ),
  532. ),
  533. 'parent_id' => array(
  534. 'type' => 'select',
  535. 'name' => 'parent_id',
  536. 'caption' => _t('_adm_nav_txt_items_parent_id'),
  537. 'info' => _t('_adm_nav_dsc_items_parent_id'),
  538. 'value' => isset($aItem['parent_id']) ? $aItem['parent_id'] : '',
  539. 'values' => array(
  540. 0 => _t('_adm_nav_txt_items_parent_id_empty')
  541. ),
  542. 'required' => '0',
  543. 'attrs' => array(),
  544. 'db' => array (
  545. 'pass' => 'Int',
  546. ),
  547. ),
  548. 'submenu_object' => array(
  549. 'type' => 'select',
  550. 'name' => 'submenu_object',
  551. 'caption' => _t('_adm_nav_txt_items_submenu'),
  552. 'info' => _t('_adm_nav_dsc_items_submenu'),
  553. 'value' => isset($aItem['submenu_object']) ? $aItem['submenu_object'] : '',
  554. 'values' => array(),
  555. 'required' => '0',
  556. 'attrs' => array(
  557. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeSubmenu(this)'
  558. ),
  559. 'db' => array (
  560. 'pass' => 'Xss',
  561. ),
  562. ),
  563. 'submenu_popup' => array(
  564. 'type' => 'switcher',
  565. 'name' => 'submenu_popup',
  566. 'caption' => _t('_adm_nav_txt_items_submenu_popup'),
  567. 'info' => '',
  568. 'value' => '1',
  569. 'checked' => isset($aItem['submenu_popup']) && $aItem['submenu_popup'] == '1',
  570. 'attrs' => array(
  571. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeSubmenu(this)'
  572. ),
  573. 'db' => array (
  574. 'pass' => 'Int',
  575. )
  576. ),
  577. 'link' => array(
  578. 'type' => 'text',
  579. 'name' => 'link',
  580. 'caption' => _t('_adm_nav_txt_items_link'),
  581. 'info' => _t('_adm_nav_dsc_items_link'),
  582. 'value' => isset($aItem['link']) ? $aItem['link'] : '',
  583. 'required' => '0',
  584. 'db' => array (
  585. 'pass' => 'Xss',
  586. ),
  587. 'checker' => array (
  588. 'func' => '',
  589. 'params' => array(),
  590. 'error' => _t('_adm_nav_err_items_link'),
  591. ),
  592. ),
  593. 'target' => array(
  594. 'type' => 'select',
  595. 'name' => 'target',
  596. 'caption' => _t('_adm_nav_txt_items_target'),
  597. 'info' => _t('_adm_nav_dsc_items_target'),
  598. 'value' => isset($aItem['target']) ? $aItem['target'] : '_self',
  599. 'values' => array(
  600. array('key' => '', 'value' => _t('_adm_nav_txt_items_target_self')),
  601. array('key' => '_blank', 'value' => _t('_adm_nav_txt_items_target_blank'))
  602. ),
  603. 'required' => '0',
  604. 'db' => array (
  605. 'pass' => 'Xss',
  606. )
  607. ),
  608. 'onclick' => array(
  609. 'type' => 'text',
  610. 'name' => 'onclick',
  611. 'caption' => _t('_adm_nav_txt_items_onclick'),
  612. 'info' => _t('_adm_nav_dsc_items_onclick'),
  613. 'value' => isset($aItem['onclick']) ? $aItem['onclick'] : '',
  614. 'required' => '0',
  615. 'db' => array (
  616. 'pass' => 'Xss',
  617. ),
  618. 'checker' => array (
  619. 'func' => '',
  620. 'params' => array(),
  621. 'error' => _t('_adm_nav_err_items_onclick'),
  622. ),
  623. ),
  624. 'area_label' => array(
  625. 'type' => 'text_translatable',
  626. 'name' => 'area_label',
  627. 'caption' => _t('_adm_nav_txt_items_area_label'),
  628. 'info' => _t('_adm_nav_dsc_items_area_label'),
  629. 'value' => isset($aItem['area_label']) ? $aItem['area_label'] : '_adm_nav_txt_item',
  630. 'required' => '0',
  631. 'db' => array (
  632. 'pass' => 'Xss',
  633. ),
  634. ),
  635. 'hidden_on' => array(
  636. 'type' => 'select_multiple',
  637. 'name' => 'hidden_on',
  638. 'caption' => _t('_adm_nav_txt_block_hidden_on'),
  639. 'info' => '',
  640. 'value' => isset($aItem['hidden_on']) ? (int)$aItem['hidden_on'] : '',
  641. 'values' => array(
  642. BX_DB_HIDDEN_PHONE => _t('_adm_nav_txt_block_hidden_on_phone'),
  643. BX_DB_HIDDEN_TABLET => _t('_adm_nav_txt_block_hidden_on_tablet'),
  644. BX_DB_HIDDEN_DESKTOP => _t('_adm_nav_txt_block_hidden_on_desktop'),
  645. BX_DB_HIDDEN_MOBILE => _t('_adm_nav_txt_block_hidden_on_mobile')
  646. ),
  647. 'db' => array (
  648. 'pass' => 'Set',
  649. )
  650. ),
  651. 'hidden_on_pt' => array(
  652. 'type' => 'select_multiple',
  653. 'name' => 'hidden_on_pt',
  654. 'caption' => _t('_adm_nav_txt_block_hidden_on_pt'),
  655. 'info' => '',
  656. 'value' => isset($aItem['hidden_on_pt']) ? (int)$aItem['hidden_on_pt'] : '',
  657. 'values' => array(),
  658. 'db' => array (
  659. 'pass' => 'Set',
  660. )
  661. ),
  662. 'hidden_on_col' => array(
  663. 'type' => 'select_multiple',
  664. 'name' => 'hidden_on_col',
  665. 'caption' => _t('_adm_nav_txt_block_hidden_on_col'),
  666. 'info' => '',
  667. 'value' => isset($aItem['hidden_on_col']) ? (int)$aItem['hidden_on_col'] : '',
  668. 'values' => array(),
  669. 'db' => array (
  670. 'pass' => 'Set',
  671. )
  672. ),
  673. 'icon' => array(
  674. 'type' => 'textarea',
  675. 'name' => 'icon',
  676. 'caption' => _t('_adm_nav_txt_items_icon'),
  677. 'info' => _t('_adm_nav_dsc_items_icon'),
  678. 'value' => '',
  679. 'code' => 1,
  680. 'required' => '0',
  681. 'db' => array (
  682. 'pass' => 'Xss',
  683. ),
  684. 'checker' => array (
  685. 'func' => '',
  686. 'params' => array(),
  687. 'error' => _t('_adm_nav_err_items_icon'),
  688. ),
  689. 'attrs' => array('class' => 'bx-form-input-textarea-small'),
  690. ),
  691. 'icon_image' => array(
  692. 'type' => 'file',
  693. 'name' => 'icon_image',
  694. 'caption' => _t('_adm_nav_txt_items_icon_image'),
  695. 'info' => _t('_adm_nav_dsc_items_icon_image'),
  696. 'value' => '',
  697. 'checker' => array (
  698. 'func' => '',
  699. 'params' => '',
  700. 'error' => _t('_adm_nav_err_items_icon_image'),
  701. ),
  702. ),
  703. 'icon_preview' => array(
  704. 'type' => 'custom',
  705. 'name' => 'icon_preview',
  706. 'caption' => _t('_adm_nav_txt_items_icon_image_old'),
  707. 'content' => ''
  708. ),
  709. 'icon_only' => array(
  710. 'type' => 'switcher',
  711. 'name' => 'icon_only',
  712. 'caption' => _t('_adm_nav_txt_items_icon_only'),
  713. 'info' => '',
  714. 'value' => '1',
  715. 'checked' => isset($aItem['icon_only']) && (int)$aItem['icon_only'] == 1,
  716. 'db' => array (
  717. 'pass' => 'Int',
  718. )
  719. ),
  720. 'primary' => array(
  721. 'type' => 'switcher',
  722. 'name' => 'primary',
  723. 'caption' => _t('_adm_nav_txt_items_primary'),
  724. 'info' => '',
  725. 'value' => '1',
  726. 'checked' => isset($aItem['primary']) && (int)$aItem['primary'] == 1,
  727. 'db' => array (
  728. 'pass' => 'Int',
  729. )
  730. ),
  731. 'collapsed' => array(
  732. 'type' => 'switcher',
  733. 'name' => 'collapsed',
  734. 'caption' => _t('_adm_nav_txt_items_collapsed'),
  735. 'info' => '',
  736. 'value' => '1',
  737. 'checked' => isset($aItem['collapsed']) && (int)$aItem['collapsed'] == 1,
  738. 'db' => array (
  739. 'pass' => 'Int',
  740. )
  741. ),
  742. 'persistent' => array(
  743. 'type' => 'switcher',
  744. 'name' => 'persistent',
  745. 'caption' => _t('_adm_nav_txt_items_persistent'),
  746. 'info' => '',
  747. 'value' => '1',
  748. 'checked' => isset($aItem['persistent']) && (int)$aItem['persistent'] == 1,
  749. 'db' => array (
  750. 'pass' => 'Int',
  751. )
  752. ),
  753. 'active_api' => array(
  754. 'type' => 'switcher',
  755. 'name' => 'active_api',
  756. 'caption' => _t('_adm_nav_txt_items_active_api'),
  757. 'info' => '',
  758. 'value' => '1',
  759. 'checked' => isset($aItem['active_api']) && (int)$aItem['active_api'] == 1,
  760. 'db' => array (
  761. 'pass' => 'Int',
  762. )
  763. ),
  764. 'controls' => array(
  765. 'name' => 'controls',
  766. 'type' => 'input_set',
  767. array(
  768. 'type' => 'submit',
  769. 'name' => 'do_submit',
  770. 'value' => _t('_adm_nav_btn_items_add'),
  771. ),
  772. array (
  773. 'type' => 'reset',
  774. 'name' => 'close',
  775. 'value' => _t('_adm_nav_btn_items_cancel'),
  776. 'attrs' => array(
  777. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  778. 'class' => 'bx-def-margin-sec-left',
  779. ),
  780. )
  781. )
  782. )
  783. );
  784. $aSetItems = array();
  785. $this->oDb->getItems(array('type' => 'by_set_name', 'value' => $this->sSet), $aSetItems, false);
  786. foreach($aSetItems as $aSetItem)
  787. $aForm['inputs']['parent_id']['values'][$aSetItem['id']] = _t(!empty($aSetItem['title_system']) ? $aSetItem['title_system'] : $aSetItem['title']);
  788. $aMenus = array();
  789. $this->oDb->getMenus(array('type' => 'all'), $aMenus, false);
  790. foreach($aMenus as $aMenu)
  791. $aForm['inputs']['submenu_object']['values'][$aMenu['object']] = _t($aMenu['title']);
  792. asort($aForm['inputs']['submenu_object']['values']);
  793. $aForm['inputs']['submenu_object']['values'] = array_merge(array('' => _t('_adm_nav_txt_items_submenu_empty')), $aForm['inputs']['submenu_object']['values']);
  794. $aPageTypes = BxDolPageQuery::getPageTypes();
  795. foreach($aPageTypes as $aPageType) {
  796. $iPageType = (int)$aPageType['id'];
  797. if($iPageType == 1)
  798. continue;
  799. $aForm['inputs']['hidden_on_pt']['values'][$iPageType - 1] = _t($aPageType['title']);
  800. }
  801. $aForm['inputs']['hidden_on_col']['values'][1] = _t('_adm_nav_txt_block_hidden_on_col_thin');
  802. $aForm['inputs']['hidden_on_col']['values'][2] = _t('_adm_nav_txt_block_hidden_on_col_half');
  803. $aForm['inputs']['hidden_on_col']['values'][3] = _t('_adm_nav_txt_block_hidden_on_col_wide');
  804. $aForm['inputs']['hidden_on_col']['values'][4] = _t('_adm_nav_txt_block_hidden_on_col_full');
  805. switch($sAction) {
  806. case 'add':
  807. unset($aForm['inputs']['id']);
  808. unset($aForm['inputs']['icon_preview']);
  809. $aForm['form_attrs']['id'] .= 'create';
  810. break;
  811. case 'edit':
  812. unset($aForm['inputs']['set_name']);
  813. $aForm['form_attrs']['id'] .= 'edit';
  814. $aForm['inputs']['icon_image']['caption'] = _t('_adm_nav_txt_items_icon_image_new');
  815. $aForm['inputs']['controls'][0]['value'] = _t('_adm_nav_btn_items_save');
  816. $bSubmenu = !empty($aItem['submenu_object']);
  817. if($bSubmenu !== true)
  818. $aForm['inputs']['submenu_popup']['tr_attrs']['style'] = 'display:none;';
  819. if(!$bSubmenu && ($aItem['onclick'] != "" || !in_array($aItem['target'], array('', '_blank')))) {
  820. $aForm['inputs']['submenu_object']['tr_attrs']['style'] = 'display:none;';
  821. $aForm['inputs']['link']['tr_attrs']['style'] = 'display:none;';
  822. $aForm['inputs']['target']['tr_attrs']['style'] = 'display:none;';
  823. }
  824. $sIconImage = $sIconFont = "";
  825. if(!empty($aItem['icon'])) {
  826. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0) {
  827. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  828. $sIconImage = $oStorage->getFileUrlById((int)$aItem['icon']);
  829. }
  830. else {
  831. $sIconFont = $aItem['icon'];
  832. $aForm['inputs']['icon']['value'] = $sIconFont;
  833. }
  834. }
  835. $aForm['inputs']['icon_preview']['content'] = $this->_getIconPreview($aItem['id'], $sIconImage, $sIconFont);
  836. break;
  837. }
  838. return new BxTemplStudioFormView($aForm);
  839. }
  840. protected function _getIconPreview($iId, $sIconImage = '', $sIcon = '')
  841. {
  842. $bIconImage = !empty($sIconImage);
  843. $aIcons = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIcon($sIcon);
  844. $sIconHtml = $aIcons[2] . $aIcons[3] . $aIcons[4];
  845. $bIconHtml = !empty($sIconHtml) && !$bIconImage;
  846. return $this->_oTemplate->parseHtmlByName('item_icon_preview.html', array(
  847. 'id' => $iId,
  848. 'bx_if:show_icon_empty' => array(
  849. 'condition' => !$bIconImage && !$bIconHtml,
  850. 'content' => array()
  851. ),
  852. 'bx_if:show_icon_image' => array(
  853. 'condition' => $bIconImage,
  854. 'content' => array(
  855. 'js_object' => $this->getJsObject(),
  856. 'url' => $sIconImage,
  857. 'id' => $iId
  858. )
  859. ),
  860. 'bx_if:show_icon_html' => array(
  861. 'condition' => $bIconHtml,
  862. 'content' => array(
  863. 'icon' => $sIconHtml
  864. )
  865. )
  866. ));
  867. }
  868. protected function _isEditable(&$aRow)
  869. {
  870. return (int)$aRow['editable'] != 0;
  871. }
  872. protected function _isDeletable(&$aRow)
  873. {
  874. return $aRow['module'] != BX_DOL_STUDIO_MODULE_SYSTEM;
  875. }
  876. }
  877. /** @} */