BxBaseStudioNavigationItems.php 38 KB

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