BxBaseMenuSetAclLevel.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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->getMemberships(false, true);
  51. $aItems = array();
  52. foreach ($aAclLevels as $iId => $sTitle) {
  53. $aItems[] = array(
  54. 'id' => $iId,
  55. 'name' => $iId,
  56. 'class' => '',
  57. 'title' => $sTitle,
  58. 'icon' => '',
  59. 'link' => 'javascript:void(0);',
  60. 'onclick' => "bx_set_acl_level(" . (!$bBulk ? $mixedProfileId : "'" . urlencode(serialize($mixedProfileId)) . "'") . ", {$iId}, '.bx-popup-applied');"
  61. );
  62. }
  63. $this->_aObject['menu_items'] = $aItems;
  64. }
  65. protected function setMembership($mixedProfileId, $iAclLevelId)
  66. {
  67. bx_import('BxDolAcl');
  68. if(!is_array($mixedProfileId))
  69. $mixedProfileId = array($mixedProfileId);
  70. $iPerformerId = bx_get_logged_profile_id();
  71. $aCheck = checkActionModule($iPerformerId, 'set acl level', 'system', false);
  72. if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  73. return $aCheck[CHECK_ACTION_MESSAGE];
  74. $iSet = 0;
  75. $oAcl = BxDolAcl::getInstance();
  76. foreach($mixedProfileId as $iProfileId) {
  77. if(!$oAcl->setMembership($iProfileId, $iAclLevelId, 0, true))
  78. continue;
  79. $iSet += 1;
  80. checkActionModule($iPerformerId, 'set acl level', 'system', true); // perform action
  81. }
  82. return count($mixedProfileId) != $iSet ? _t('_error occured') : '';
  83. }
  84. }
  85. /** @} */