1
0

BxBaseMenuSetAclLevel.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. header('Content-type: text/html; charset=utf-8');
  27. echo $this->setMembership($mixedProfileId, $iAclLevelId);
  28. exit;
  29. }
  30. return parent::getCode ();
  31. }
  32. public function getMenuItems ()
  33. {
  34. $this->loadData();
  35. return parent::getMenuItems();
  36. }
  37. protected function loadData()
  38. {
  39. $mixedProfileId = $this->mixedProfileId;
  40. if(bx_get('profile_id') !== false)
  41. $mixedProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  42. $oAcl = BxDolAcl::getInstance();
  43. if (!$oAcl)
  44. return;
  45. $bBulk = is_array($mixedProfileId);
  46. if(!$bBulk) {
  47. $aProfileAclLevel = $oAcl->getMemberMembershipInfo($mixedProfileId);
  48. $this->setSelected('', $aProfileAclLevel['id']);
  49. }
  50. $aAclLevels = $oAcl->getMembershipsBy(array('type' => 'all_active_not_automatic_pair'));
  51. foreach ($aAclLevels as $k => $s)
  52. $aAclLevels[$k] = _t($s);
  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. /** @} */