BxBaseStudioNavigationItems.php 39 KB

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