user_permissions.inc.php 7.3 KB

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