BxBaseMenuSetAclLevel.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 TridentCore Trident Core
  7. * @{
  8. */
  9. bx_import('BxTemplMenu');
  10. /**
  11. * Menu to set acl level for profile
  12. */
  13. class BxBaseMenuSetAclLevel extends BxTemplMenu
  14. {
  15. protected $mixedProfileId;
  16. public function __construct ($aObject, $oTemplate)
  17. {
  18. parent::__construct ($aObject, $oTemplate);
  19. }
  20. public function getCode ($mixedProfileId = 0)
  21. {
  22. $this->mixedProfileId = $mixedProfileId;
  23. if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && ($mixedProfileId = bx_get('profile_id', 'post')) && ($iAclLevelId = bx_get('acl_level_id', 'post'))) {
  24. $mixedProfileId = urldecode($mixedProfileId);
  25. if(!is_numeric($mixedProfileId))
  26. $mixedProfileId = unserialize($mixedProfileId);
  27. header('Content-type: text/html; charset=utf-8');
  28. echo $this->setMembership($mixedProfileId, $iAclLevelId);
  29. exit;
  30. }
  31. return parent::getCode ();
  32. }
  33. public function getMenuItems ()
  34. {
  35. $this->loadData();
  36. return parent::getMenuItems();
  37. }
  38. protected function loadData()
  39. {
  40. $mixedProfileId = $this->mixedProfileId;
  41. if(bx_get('profile_id') !== false)
  42. $mixedProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  43. bx_import('BxDolAcl');
  44. $oAcl = BxDolAcl::getInstance();
  45. if (!$oAcl)
  46. return;
  47. $bBulk = is_array($mixedProfileId);
  48. if(!$bBulk) {
  49. $aProfileAclLevel = $oAcl->getMemberMembershipInfo($mixedProfileId);
  50. $this->setSelected('', $aProfileAclLevel['id']);
  51. }
  52. $aAclLevels = $oAcl->getMemberships(false, true);
  53. $aItems = array();
  54. foreach ($aAclLevels as $iId => $sTitle) {
  55. $aItems[] = array(
  56. 'id' => $iId,
  57. 'name' => $iId,
  58. 'class' => '',
  59. 'title' => $sTitle,
  60. 'icon' => '',
  61. 'link' => 'javascript:void(0);',
  62. 'onclick' => "bx_set_acl_level(" . (!$bBulk ? $mixedProfileId : "'" . urlencode(serialize($mixedProfileId)) . "'") . ", {$iId}, '.bx-popup-applied');"
  63. );
  64. }
  65. $this->_aObject['menu_items'] = $aItems;
  66. }
  67. protected function setMembership($mixedProfileId, $iAclLevelId)
  68. {
  69. bx_import('BxDolAcl');
  70. if(!is_array($mixedProfileId))
  71. $mixedProfileId = array($mixedProfileId);
  72. $iPerformerId = bx_get_logged_profile_id();
  73. $aCheck = checkActionModule($iPerformerId, 'set acl level', 'system', false);
  74. if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  75. return $aCheck[CHECK_ACTION_MESSAGE];
  76. $iSet = 0;
  77. $oAcl = BxDolAcl::getInstance();
  78. foreach($mixedProfileId as $iProfileId) {
  79. if(!$oAcl->setMembership($iProfileId, $iAclLevelId, 0, true))
  80. continue;
  81. $iSet += 1;
  82. checkActionModule($iPerformerId, 'set acl level', 'system', true); // perform action
  83. }
  84. return count($mixedProfileId) != $iSet ? _t('_error occured') : '';
  85. }
  86. }
  87. /** @} */