BxBaseMenuSetAclLevel.php 3.7 KB

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