user_permissions.inc.php 7.3 KB

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