BxBaseMenuSetAclLevel.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxTemplMenu');
  10. /**
  11. * Menu to set acl level for profile
  12. */
  13. class BxBaseMenuSetAclLevel extends BxTemplMenu
  14. {
  15. public function __construct ($aObject, $oTemplate)
  16. {
  17. parent::__construct ($aObject, $oTemplate);
  18. }
  19. public function getCode ()
  20. {
  21. if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && ($iProfileId = bx_get('profile_id', 'post')) && ($iAclLevelId = bx_get('acl_level_id', 'post'))) {
  22. $sMsg = '';
  23. bx_import('BxDolAcl');
  24. $aCheck = checkActionModule($iProfileId, 'set acl level', 'system', false);
  25. if (isAdmin() || $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED) {
  26. $oAcl = BxDolAcl::getInstance();
  27. if ($oAcl->setMembership($iProfileId, $iAclLevelId, 0, true))
  28. checkActionModule($iProfileId, 'delete account', 'system', true); // perform action
  29. else
  30. $sMsg = _t('_error occured');
  31. } else {
  32. $sMsg = $aCheck[CHECK_ACTION_MESSAGE];
  33. }
  34. header('Content-type: text/html; charset=utf-8');
  35. echo $sMsg;
  36. exit;
  37. }
  38. return parent::getCode ();
  39. }
  40. public function getMenuItems ()
  41. {
  42. $this->loadData();
  43. return parent::getMenuItems();
  44. }
  45. protected function loadData()
  46. {
  47. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  48. bx_import('BxDolAcl');
  49. $oAcl = BxDolAcl::getInstance();
  50. if (!$oAcl)
  51. return;
  52. $aProfileAclLevel = $oAcl->getMemberMembershipInfo($iProfileId);
  53. $aAclLevels = $oAcl->getMemberships(false, true);
  54. $this->setSelected('', $aProfileAclLevel['id']);
  55. $aItems = array();
  56. foreach ($aAclLevels as $iId => $sTitle) {
  57. $aItems[] = array(
  58. 'id' => $iId,
  59. 'name' => $iId,
  60. 'class' => '',
  61. 'title' => $sTitle,
  62. 'icon' => '',
  63. 'link' => 'javascript:void(0);',
  64. 'onclick' => "bx_set_acl_level({$iProfileId}, {$iId}, '#bx-popup-ajax-wrapper-sys_set_acl_level');"
  65. );
  66. }
  67. $this->_aObject['menu_items'] = $aItems;
  68. }
  69. }
  70. /** @} */