BxBaseStudioNavigationItems.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  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. 'active_api' => array(
  743. 'type' => 'switcher',
  744. 'name' => 'active_api',
  745. 'caption' => _t('_adm_nav_txt_items_active_api'),
  746. 'info' => '',
  747. 'value' => '1',
  748. 'checked' => isset($aItem['active_api']) && (int)$aItem['active_api'] == 1,
  749. 'db' => array (
  750. 'pass' => 'Int',
  751. )
  752. ),
  753. 'controls' => array(
  754. 'name' => 'controls',
  755. 'type' => 'input_set',
  756. array(
  757. 'type' => 'submit',
  758. 'name' => 'do_submit',
  759. 'value' => _t('_adm_nav_btn_items_add'),
  760. ),
  761. array (
  762. 'type' => 'reset',
  763. 'name' => 'close',
  764. 'value' => _t('_adm_nav_btn_items_cancel'),
  765. 'attrs' => array(
  766. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  767. 'class' => 'bx-def-margin-sec-left',
  768. ),
  769. )
  770. )
  771. )
  772. );
  773. $aSetItems = array();
  774. $this->oDb->getItems(array('type' => 'by_set_name', 'value' => $this->sSet), $aSetItems, false);
  775. foreach($aSetItems as $aSetItem)
  776. $aForm['inputs']['parent_id']['values'][$aSetItem['id']] = _t(!empty($aSetItem['title_system']) ? $aSetItem['title_system'] : $aSetItem['title']);
  777. $aMenus = array();
  778. $this->oDb->getMenus(array('type' => 'all'), $aMenus, false);
  779. foreach($aMenus as $aMenu)
  780. $aForm['inputs']['submenu_object']['values'][$aMenu['object']] = _t($aMenu['title']);
  781. asort($aForm['inputs']['submenu_object']['values']);
  782. $aForm['inputs']['submenu_object']['values'] = array_merge(array('' => _t('_adm_nav_txt_items_submenu_empty')), $aForm['inputs']['submenu_object']['values']);
  783. $aPageTypes = BxDolPageQuery::getPageTypes();
  784. foreach($aPageTypes as $aPageType) {
  785. $iPageType = (int)$aPageType['id'];
  786. if($iPageType == 1)
  787. continue;
  788. $aForm['inputs']['hidden_on_pt']['values'][$iPageType - 1] = _t($aPageType['title']);
  789. }
  790. $aForm['inputs']['hidden_on_col']['values'][1] = _t('_adm_nav_txt_block_hidden_on_col_thin');
  791. $aForm['inputs']['hidden_on_col']['values'][2] = _t('_adm_nav_txt_block_hidden_on_col_half');
  792. $aForm['inputs']['hidden_on_col']['values'][3] = _t('_adm_nav_txt_block_hidden_on_col_wide');
  793. $aForm['inputs']['hidden_on_col']['values'][4] = _t('_adm_nav_txt_block_hidden_on_col_full');
  794. switch($sAction) {
  795. case 'add':
  796. unset($aForm['inputs']['id']);
  797. unset($aForm['inputs']['icon_preview']);
  798. $aForm['form_attrs']['id'] .= 'create';
  799. break;
  800. case 'edit':
  801. unset($aForm['inputs']['set_name']);
  802. $aForm['form_attrs']['id'] .= 'edit';
  803. $aForm['inputs']['icon_image']['caption'] = _t('_adm_nav_txt_items_icon_image_new');
  804. $aForm['inputs']['controls'][0]['value'] = _t('_adm_nav_btn_items_save');
  805. $bSubmenu = !empty($aItem['submenu_object']);
  806. if($bSubmenu !== true)
  807. $aForm['inputs']['submenu_popup']['tr_attrs']['style'] = 'display:none;';
  808. if(!$bSubmenu && ($aItem['onclick'] != "" || !in_array($aItem['target'], array('', '_blank')))) {
  809. $aForm['inputs']['submenu_object']['tr_attrs']['style'] = 'display:none;';
  810. $aForm['inputs']['link']['tr_attrs']['style'] = 'display:none;';
  811. $aForm['inputs']['target']['tr_attrs']['style'] = 'display:none;';
  812. }
  813. $sIconImage = $sIconFont = "";
  814. if(!empty($aItem['icon'])) {
  815. if(is_numeric($aItem['icon']) && (int)$aItem['icon'] != 0) {
  816. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  817. $sIconImage = $oStorage->getFileUrlById((int)$aItem['icon']);
  818. }
  819. else {
  820. $sIconFont = $aItem['icon'];
  821. $aForm['inputs']['icon']['value'] = $sIconFont;
  822. }
  823. }
  824. $aForm['inputs']['icon_preview']['content'] = $this->_getIconPreview($aItem['id'], $sIconImage, $sIconFont);
  825. break;
  826. }
  827. return new BxTemplStudioFormView($aForm);
  828. }
  829. protected function _getIconPreview($iId, $sIconImage = '', $sIcon = '')
  830. {
  831. $bIconImage = !empty($sIconImage);
  832. $aIcons = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIcon($sIcon);
  833. $sIconHtml = $aIcons[2] . $aIcons[3] . $aIcons[4];
  834. $bIconHtml = !empty($sIconHtml) && !$bIconImage;
  835. return $this->_oTemplate->parseHtmlByName('item_icon_preview.html', array(
  836. 'id' => $iId,
  837. 'bx_if:show_icon_empty' => array(
  838. 'condition' => !$bIconImage && !$bIconHtml,
  839. 'content' => array()
  840. ),
  841. 'bx_if:show_icon_image' => array(
  842. 'condition' => $bIconImage,
  843. 'content' => array(
  844. 'js_object' => $this->getJsObject(),
  845. 'url' => $sIconImage,
  846. 'id' => $iId
  847. )
  848. ),
  849. 'bx_if:show_icon_html' => array(
  850. 'condition' => $bIconHtml,
  851. 'content' => array(
  852. 'icon' => $sIconHtml
  853. )
  854. )
  855. ));
  856. }
  857. protected function _isEditable(&$aRow)
  858. {
  859. return (int)$aRow['editable'] != 0;
  860. }
  861. protected function _isDeletable(&$aRow)
  862. {
  863. return $aRow['module'] != BX_DOL_STUDIO_MODULE_SYSTEM;
  864. }
  865. }
  866. /** @} */