BxBaseStudioNavigationMenus.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  8. * @{
  9. */
  10. class BxBaseStudioNavigationMenus extends BxDolStudioNavigationMenus
  11. {
  12. private $sCreateNew = 'sys_create_new';
  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_menus_edit');
  18. $this->_aOptions['actions_single']['delete']['attr']['title'] = _t('_adm_nav_btn_menus_delete');
  19. $this->sUrlViewItems = BX_DOL_URL_STUDIO . 'builder_menu.php?page=items&module=%s&set=%s';
  20. }
  21. public function performActionAdd()
  22. {
  23. $sAction = 'add';
  24. $oForm = $this->_getFormObject($sAction);
  25. if($oForm->isSubmitted() && isset($oForm->aInputs['set_name']))
  26. $this->updateSetFields($oForm);
  27. $oForm->initChecker();
  28. if($oForm->isSubmittedAndValid()) {
  29. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  30. $sLanguage = $oLanguage->getCurrentLangName(false);
  31. $sObject = BxDolForm::getSubmittedValue('title-' . $sLanguage, $oForm->aFormAttrs['method']);
  32. $sObject = uriGenerate($sObject, 'sys_objects_menu', 'object', 'object');
  33. //--- New Set Creation
  34. if($oForm->getCleanValue('set_name') == $this->sCreateNew) {
  35. $sSetTitleValue = $oForm->getCleanValue('set_title');
  36. $sSetName = uriGenerate($sSetTitleValue, 'sys_menu_sets', 'set_name', 'set');
  37. $sSetTitleKey = '_adm_nav_txt_set_' . $sSetName;
  38. if($this->oDb->addSet(array('set_name' => $sSetName, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'title' => $sSetTitleKey, 'deletable' => 1))) {
  39. $oLanguage->addLanguageString($sSetTitleKey, $sSetTitleValue);
  40. BxDolForm::setSubmittedValue('set_name', $sSetName, $oForm->aFormAttrs['method']);
  41. }
  42. }
  43. unset($oForm->aInputs['set_title']);
  44. $iId = (int)$oForm->insert(array('object' => $sObject, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'deletable' => 1, 'active' => 1));
  45. if($iId != 0)
  46. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  47. else
  48. $aRes = array('msg' => _t('_adm_nav_err_menus_create'));
  49. $this->_echoResultJson($aRes, true);
  50. }
  51. else {
  52. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-menu-create-popup', _t('_adm_nav_txt_menus_create_popup'), $this->_oTemplate->parseHtmlByName('nav_add_menu.html', array(
  53. 'form_id' => $oForm->aFormAttrs['id'],
  54. 'form' => $oForm->getCode(true),
  55. 'object' => $this->_sObject,
  56. 'action' => $sAction
  57. )));
  58. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  59. }
  60. }
  61. public function performActionEdit()
  62. {
  63. $sAction = 'edit';
  64. $aMenu = $this->_getItem('getMenus');
  65. if($aMenu === false) {
  66. $this->_echoResultJson(array());
  67. exit;
  68. }
  69. $oForm = $this->_getFormObject($sAction, $aMenu);
  70. if($oForm->isSubmitted() && isset($oForm->aInputs['set_name']))
  71. $this->updateSetFields($oForm);
  72. $oForm->initChecker();
  73. if($oForm->isSubmittedAndValid()) {
  74. //--- New Set Creation
  75. if($oForm->getCleanValue('set_name') == $this->sCreateNew) {
  76. $sSetTitleValue = $oForm->getCleanValue('set_title');
  77. $sSetName = 'custom_' . $this->getSystemName($sSetTitleValue);
  78. $sSetTitleKey = '_adm_nav_txt_set_' . $sSetName;
  79. if($this->oDb->addSet(array('set_name' => $sSetName, 'module' => BX_DOL_STUDIO_MODULE_CUSTOM, 'title' => $sSetTitleKey, 'deletable' => 1))) {
  80. BxDolStudioLanguagesUtils::getInstance()->addLanguageString($sSetTitleKey, $sSetTitleValue);
  81. BxDolForm::setSubmittedValue('set_name', $sSetName, $oForm->aFormAttrs['method']);
  82. }
  83. }
  84. unset($oForm->aInputs['set_title']);
  85. if($oForm->update($aMenu['id']) !== false)
  86. $aRes = array('grid' => $this->getCode(false), 'blink' => $aMenu['id']);
  87. else
  88. $aRes = array('msg' => _t('_adm_nav_err_menus_edit'));
  89. $this->_echoResultJson($aRes, true);
  90. }
  91. else {
  92. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-nav-menu-edit-popup', _t('_adm_nav_txt_menus_edit_popup', _t($aMenu['title'])), $this->_oTemplate->parseHtmlByName('nav_add_menu.html', array(
  93. 'form_id' => $oForm->aFormAttrs['id'],
  94. 'form' => $oForm->getCode(true),
  95. 'object' => $this->_sObject,
  96. 'action' => $sAction
  97. )));
  98. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  99. }
  100. }
  101. public function performActionDelete()
  102. {
  103. $iAffected = 0;
  104. $aIds = bx_get('ids');
  105. if(!$aIds || !is_array($aIds)) {
  106. $this->_echoResultJson(array());
  107. exit;
  108. }
  109. $aIdsAffected = array ();
  110. foreach($aIds as $iId) {
  111. $aMenu = array();
  112. $iMenu = $this->oDb->getMenus(array('type' => 'by_id', 'value' => (int)$iId), $aMenu);
  113. if($iMenu != 1 || empty($aMenu))
  114. continue;
  115. if((int)$aMenu['deletable'] != 1)
  116. continue;
  117. if((int)$this->_delete($iId) <= 0)
  118. continue;
  119. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aMenu['title']);
  120. $aIdsAffected[] = $iId;
  121. $iAffected++;
  122. }
  123. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_menus_delete')));
  124. }
  125. function getJsObject()
  126. {
  127. return 'oBxDolStudioNavigationMenus';
  128. }
  129. function getCode($isDisplayHeader = true)
  130. {
  131. return $this->_oTemplate->parseHtmlByName('nav_menus.html', array(
  132. 'content' => parent::getCode($isDisplayHeader),
  133. 'js_object' => $this->getJsObject(),
  134. 'grid_object' => $this->_sObject,
  135. 'params_divider' => $this->sParamsDivider
  136. ));
  137. }
  138. protected function _addJsCss()
  139. {
  140. parent::_addJsCss();
  141. $this->_oTemplate->addJs(array('jquery.form.min.js', 'navigation_menus.js'));
  142. $oForm = new BxTemplStudioFormView(array());
  143. $oForm->addCssJs();
  144. }
  145. protected function _getCellTitle ($mixedValue, $sKey, $aField, $aRow)
  146. {
  147. $aValue = $this->_limitMaxLength(_t($aRow['title']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow, false);
  148. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  149. 'href' => sprintf($this->sUrlViewItems, $aRow['module'], $aRow['set_name']),
  150. 'title' => _t('_adm_nav_txt_manage_items'),
  151. 'bx_repeat:attrs' => array(),
  152. 'content' => $aValue[0]
  153. )) . (isset($aValue[1]) ? $aValue[1] : '');
  154. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  155. }
  156. protected function _getCellItems ($mixedValue, $sKey, $aField, $aRow)
  157. {
  158. if(!empty($aRow['set_name'])) {
  159. $aSets = array();
  160. $this->oDb->getSets(array('type' => 'by_name', 'value' => $aRow['set_name']), $aSets, false);
  161. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  162. 'href' => sprintf($this->sUrlViewItems, $aRow['module'], $aRow['set_name']),
  163. 'title' => _t('_adm_nav_txt_manage_items'),
  164. 'bx_repeat:attrs' => array(),
  165. 'content' => _t('_adm_nav_txt_n_items', $aSets['items_count'])
  166. ));
  167. }
  168. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  169. }
  170. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  171. {
  172. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  173. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  174. }
  175. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  176. {
  177. if ($sType == 'single' && (int)$aRow['deletable'] != 1)
  178. return '';
  179. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  180. }
  181. protected function _getFilterControls ()
  182. {
  183. parent::_getFilterControls();
  184. return $this->getModulesSelectAll('getMenus') . $this->getSearchInput();
  185. }
  186. protected function _getFormObject($sAction, $aMenu = array())
  187. {
  188. $aForm = array(
  189. 'form_attrs' => array(
  190. 'id' => 'adm-nav-menu-',
  191. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  192. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  193. ),
  194. 'params' => array (
  195. 'db' => array(
  196. 'table' => 'sys_objects_menu',
  197. 'key' => 'id',
  198. 'uri' => '',
  199. 'uri_title' => '',
  200. 'submit_name' => 'do_submit'
  201. ),
  202. ),
  203. 'inputs' => array (
  204. 'id' => array(
  205. 'type' => 'hidden',
  206. 'name' => 'id',
  207. 'value' => isset($aMenu['id']) ? (int)$aMenu['id'] : 0,
  208. 'db' => array (
  209. 'pass' => 'Int',
  210. ),
  211. ),
  212. 'title' => array(
  213. 'type' => 'text_translatable',
  214. 'name' => 'title',
  215. 'caption' => _t('_adm_nav_txt_menus_title'),
  216. 'info' => _t('_adm_nav_dsc_menus_title'),
  217. 'value' => isset($aMenu['title']) ? $aMenu['title'] : '_adm_nav_txt_menu',
  218. 'required' => '1',
  219. 'db' => array (
  220. 'pass' => 'Xss',
  221. ),
  222. 'checker' => array (
  223. 'func' => 'LengthTranslatable',
  224. 'params' => array(3, 100, 'title'),
  225. 'error' => _t('_adm_nav_err_menus_title'),
  226. ),
  227. ),
  228. 'set_name' => array(
  229. 'type' => 'select',
  230. 'name' => 'set_name',
  231. 'caption' => _t('_adm_nav_txt_menus_set_name'),
  232. 'info' => _t('_adm_nav_dsc_menus_set_name'),
  233. 'value' => isset($aMenu['set_name']) ? $aMenu['set_name'] : '',
  234. 'values' => array(
  235. array('key' => '', 'value' => _t('_adm_nav_txt_menus_set_name_select')),
  236. array('key' => $this->sCreateNew, 'value' => _t('_adm_nav_txt_menus_set_name_new'))
  237. ),
  238. 'required' => '1',
  239. 'attrs' => array(
  240. 'id' => 'bx-form-field-set-name',
  241. 'onchange' => $this->getJsObject() . ".onSelectSet(this)"
  242. ),
  243. 'db' => array (
  244. 'pass' => 'Xss',
  245. ),
  246. 'checker' => array (
  247. 'func' => 'avail',
  248. 'params' => array(),
  249. 'error' => _t('_adm_nav_err_menus_set_name'),
  250. ),
  251. ),
  252. 'set_title' => array(
  253. 'type' => 'text',
  254. 'name' => 'set_title',
  255. 'caption' => _t('_adm_nav_txt_menus_set_title'),
  256. 'info' => _t('_adm_nav_dsc_menus_set_title'),
  257. 'value' => '',
  258. 'required' => '1',
  259. 'tr_attrs' => array(
  260. 'style' => 'display:none'
  261. ),
  262. 'db' => array (
  263. 'pass' => 'Xss',
  264. ),
  265. 'checker' => array (
  266. 'func' => 'Avail',
  267. 'params' => array(),
  268. 'error' => _t('_adm_nav_err_menus_set_title'),
  269. ),
  270. ),
  271. 'template_id' => array(
  272. 'type' => 'select',
  273. 'name' => 'template_id',
  274. 'caption' => _t('_adm_nav_txt_menus_style'),
  275. 'info' => _t('_adm_nav_dsc_menus_style'),
  276. 'value' => isset($aMenu['template_id']) ? $aMenu['template_id'] : '',
  277. 'values' => array(
  278. array('key' => '', 'value' => _t('_adm_nav_txt_menus_style_select'))
  279. ),
  280. 'required' => '1',
  281. 'db' => array (
  282. 'pass' => 'Xss',
  283. ),
  284. 'checker' => array (
  285. 'func' => 'avail',
  286. 'params' => array(),
  287. 'error' => _t('_adm_nav_err_menus_style'),
  288. ),
  289. ),
  290. 'controls' => array(
  291. 'name' => 'controls',
  292. 'type' => 'input_set',
  293. array(
  294. 'type' => 'submit',
  295. 'name' => 'do_submit',
  296. 'value' => _t('_adm_nav_btn_menus_add'),
  297. ),
  298. array (
  299. 'type' => 'reset',
  300. 'name' => 'close',
  301. 'value' => _t('_adm_nav_btn_menus_cancel'),
  302. 'attrs' => array(
  303. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  304. 'class' => 'bx-def-margin-sec-left',
  305. ),
  306. )
  307. )
  308. )
  309. );
  310. $aSets = array();
  311. $this->oDb->getSets(array('type' => 'all'), $aSets, false);
  312. foreach($aSets as $sSet)
  313. $aForm['inputs']['set_name']['values'][] = array('key' => $sSet['name'], 'value' => _t($sSet['title']));
  314. $aTemplates = array();
  315. $this->oDb->getTemplates(array('type' => 'all'), $aTemplates, false);
  316. foreach($aTemplates as $aTemplate)
  317. $aForm['inputs']['template_id']['values'][] = array('key' => $aTemplate['id'], 'value' => _t($aTemplate['title']));
  318. switch($sAction){
  319. case 'add':
  320. unset($aForm['inputs']['id']);
  321. $aForm['form_attrs']['id'] .= 'create';
  322. break;
  323. case 'edit':
  324. $aForm['form_attrs']['id'] .= 'edit';
  325. $aForm['inputs']['set_title']['checker']['func'] = 'UniqueSet';
  326. $aForm['inputs']['controls'][0]['value'] = _t('_adm_nav_btn_menus_save');
  327. break;
  328. }
  329. return new BxTemplStudioFormView($aForm);
  330. }
  331. protected function updateSetFields(&$oForm)
  332. {
  333. if($oForm->getCleanValue('set_name') != $this->sCreateNew)
  334. unset($oForm->aInputs['set_title']['checker']);
  335. else
  336. unset($oForm->aInputs['set_title']['tr_attrs']['style']);
  337. }
  338. }
  339. /** @} */