user_permissions.inc.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * @package chamilo.permissions
  4. */
  5. $user_id = $userIdViewed;
  6. if ($mainUserInfo['status'] == 1) {
  7. $course_admin = 1;
  8. }
  9. include_once 'permissions_functions.inc.php';
  10. include_once 'all_permissions.inc.php';
  11. include_once api_get_library_path()."/groupmanager.lib.php";
  12. include_once api_get_library_path()."/blog.lib.php";
  13. // ACTIONS
  14. if ($_POST['StoreUserPermissions'] and $setting_visualisation == 'checkbox') {
  15. $result_message = store_permissions('user', $user_id);
  16. if ($result_message) {
  17. echo Display::return_message($result_message);
  18. }
  19. }
  20. if (isset($_GET['action'])) {
  21. if (isset($_GET['permission']) and isset($_GET['tool']) and ($_GET['action'] == 'grant' or $_GET['action'] == 'revoke')) {
  22. $result_message = store_one_permission('user', $_GET['action'], $user_id, $_GET['tool'], $_GET['permission']);
  23. }
  24. if (isset($_GET['role']) and ($_GET['action'] == 'grant' or $_GET['action'] == 'revoke')) {
  25. $result_message = assign_role('user', $_GET['action'], $user_id, $_GET['role'], $_GET['scope']);
  26. }
  27. }
  28. if (isset($result_message)) {
  29. echo Display::return_message($result_message);
  30. }
  31. // ---------------------------------------------------
  32. // RETRIEVING THE PERMISSIONS OF THE USER
  33. // ---------------------------------------------------
  34. $current_user_permissions = [];
  35. $current_user_permissions = get_permissions('user', $user_id);
  36. // INHERITED PERMISSIONS (group permissions, user roles, group roles)
  37. // RETRIEVING THE PERMISSIONS OF THE GROUPS OF THE USER
  38. $groups_of_user = [];
  39. $groups_of_user = GroupManager::get_group_ids($_course['real_id'], $user_id);
  40. foreach ($groups_of_user as $group) {
  41. $this_group_permissions = get_permissions('group', $group);
  42. foreach ($this_group_permissions as $tool => $permissions) {
  43. foreach ($permissions as $permission) {
  44. $inherited_group_permissions[$tool][] = $permission;
  45. }
  46. }
  47. }
  48. $inherited_permissions = $inherited_group_permissions;
  49. // RETRIEVING THE PERMISSIONS OF THE ROLES OF THE USER
  50. if (api_get_setting('user_roles') == 'true') {
  51. // course roles that are assigned to the user
  52. $current_user_role_permissions_of_user = get_roles_permissions('user', $user_id);
  53. $inherited_permissions = permission_array_merge($inherited_permissions, $current_user_role_permissions_of_user);
  54. // NOTE: deze array moet nog gemerged worden met de $inherited_permissions array
  55. // (heet momenteel nog $current_group_permissions_of_user omdat voorlopig enkel de
  56. // groepsge�rfde permissions in beschouwing worden genomen
  57. // dit moet ook de rol permissies van rollen die toegekend worden aan een gebruiker
  58. // en de rol permissies van rollen die toegekend worden aan de groepen van een gebruiker
  59. // omvatten.
  60. // NOTE: checken als de rollen brol wel degelijk geactiveerd is voordat we dit allemaal
  61. // ophalen.
  62. // platform roles that are assigned to the user
  63. $current_user_role_permissions_of_user = get_roles_permissions('user', $user_id, 'platform');
  64. $inherited_permissions = permission_array_merge($inherited_permissions, $current_user_role_permissions_of_user);
  65. }
  66. // RETRIEVING THE PERMISSIONS OF THE ROLES OF THE GROUPS OF THE USER
  67. if (api_get_setting('group_roles') == 'true') {
  68. // NOTE: DIT MOET NOG VERDER UITGEWERKT WORDEN
  69. foreach ($groups_of_user as $group) {
  70. $this_current_group_role_permissions_of_user = get_roles_permissions('user', $user_id);
  71. //$inherited_permissions[$tool][]=$permission;
  72. }
  73. }
  74. // LIMITED OR FULL
  75. $current_user_permissions = limited_or_full($current_user_permissions);
  76. $inherited_permissions = limited_or_full($inherited_permissions);
  77. if (api_get_setting('permissions') == 'limited') {
  78. $header_array = $rights_limited;
  79. }
  80. if (api_get_setting('permissions') == 'full') {
  81. $header_array = $rights_full;
  82. }
  83. echo "<form method=\"post\" action=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."\">";
  84. // DISPLAYING THE ROLES LIST
  85. if (api_get_setting('user_roles') == 'true') {
  86. // the list of the roles for the user
  87. echo '<strong>'.get_lang('UserRoles').'</strong><br />';
  88. $current_user_course_roles = get_roles('user', $user_id);
  89. $current_user_platform_roles = get_roles('user', $user_id, 'platform');
  90. display_role_list($current_user_course_roles, $current_user_platform_roles);
  91. echo '<br />';
  92. }
  93. // ---------------------------------------------------
  94. // DISPLAYING THE MATRIX (user permissions)
  95. // ---------------------------------------------------
  96. echo '<strong>'.get_lang('UserPermissions').'</strong>';
  97. echo "<table class=\"data_table\">\n";
  98. // the header
  99. echo "\t<tr>\n";
  100. echo "\t\t<th>".get_lang('Module')."</th>\n";
  101. foreach ($header_array as $header_key => $header_value) {
  102. echo "\t\t<th>".get_lang($header_value)."</th>\n";
  103. }
  104. echo "\t</tr>\n";
  105. // the main area with the checkboxes or images
  106. // $tool_rights contains all the possible tools and their rights
  107. foreach ($tool_rights as $tool => $rights) {
  108. echo "\t<tr>\n";
  109. echo "\t\t<td>\n";
  110. if (strstr($tool, 'BLOG')) {
  111. // Not dealing with a real tool here, get name of this blog
  112. // Strip blog id
  113. $tmp = strpos($tool, '_') + 1;
  114. $blog_id = substr($tool, $tmp, strlen($tool));
  115. // Get title
  116. echo get_lang('Blog').": ".Blog::getBlogTitle($blog_id);
  117. } else {
  118. echo get_lang($tool);
  119. }
  120. echo "\t\t</td>\n";
  121. foreach ($header_array as $key => $value) {
  122. echo "\t\t<td align='center'>\n";
  123. if (in_array($value, $rights)) {
  124. if ($setting_visualisation == 'checkbox') {
  125. display_checkbox_matrix(
  126. $current_user_permissions,
  127. $tool,
  128. $value,
  129. $inherited_permissions,
  130. $course_admin
  131. );
  132. }
  133. if ($setting_visualisation == 'image') {
  134. display_image_matrix(
  135. $current_user_permissions,
  136. $tool,
  137. $value,
  138. $inherited_permissions,
  139. $course_admin
  140. );
  141. }
  142. }
  143. // note: in a later stage this part will be replaced by a function
  144. // so that we can easily switch between a checkbox approach or an image approach
  145. // where every click is in fact a change of status. In the checkbox approach you first have to
  146. // do the changes and then store them by clicking the submit button.
  147. echo "\t\t</td>\n";
  148. }
  149. echo "\t</tr>\n";
  150. }
  151. echo "</table>\n";
  152. if ($setting_visualisation == 'checkbox') {
  153. echo "<input type=\"Submit\" name=\"StoreUserPermissions\" value=\"".get_lang('StorePermissions')."\">";
  154. }
  155. echo "</form><br />";
  156. // LEGEND
  157. echo '<strong>'.get_lang('Legend').'</strong><br />';
  158. echo '<img src="../img/wrong.gif" /> '.get_lang('UserHasPermissionNot').'<br />';
  159. echo '<img src="../img/checkbox_on2.gif" /> '.get_lang('UserHasPermission').'<br />';
  160. echo '<img src="../img/checkbox_on3.gif" /> '.get_lang('UserHasPermissionByRoleGroup').'<br />';