blog_permissions.inc.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /**
  3. * smartBlogs add-on: it must be possible to change rights for every single blog
  4. * in a course.
  5. *
  6. * @author Toon Keppens
  7. *
  8. * @package chamilo.permissions
  9. */
  10. /**
  11. * Init.
  12. */
  13. $rights_full = [
  14. "article_add",
  15. "article_delete",
  16. "article_edit",
  17. "article_rate",
  18. "article_comments_add",
  19. "article_comments_delete",
  20. "article_comments_rate",
  21. "task_management",
  22. "member_management",
  23. "role_management",
  24. ];
  25. $rights_limited = ["Add", "Edit", "Delete"];
  26. $rights_blog = [
  27. "article_add",
  28. "article_delete",
  29. "article_edit",
  30. "article_rate",
  31. "article_comments_add",
  32. "article_comments_delete",
  33. "article_comments_rate",
  34. "task_management",
  35. "member_management",
  36. "role_management",
  37. ];
  38. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  39. // Get all user
  40. $blog_users = Blog::getBlogUsers($_GET['blog_id']);
  41. $course_id = api_get_course_int_id();
  42. // Remove the blog creater because he has all the rights automatically
  43. // and we want to keep it that way.
  44. $tbl_course_rel_user = $table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  45. $sql = "SELECT user_id
  46. FROM $tbl_course_rel_user
  47. WHERE status = '1' AND c_id = '".api_get_course_int_id()."'";
  48. $result = Database::query($sql);
  49. while ($user = Database::fetch_assoc($result)) {
  50. unset($blog_users[$user['user_id']]);
  51. }
  52. //$user_id=$userIdViewed;
  53. if (isset($mainUserInfo) && isset($mainUserInfo['status']) && $mainUserInfo['status'] == 1) {
  54. $course_admin = 1;
  55. }
  56. include_once 'permissions_functions.inc.php';
  57. // ACTIONS
  58. if (isset($_GET['do'])) {
  59. if (isset($_GET['permission']) and isset($_GET['tool']) and ($_GET['do'] == 'grant' or $_GET['do'] == 'revoke')) {
  60. $result_message = store_one_permission(
  61. 'user',
  62. $_GET['do'],
  63. $_GET['user_id'],
  64. $_GET['tool'],
  65. $_GET['permission']
  66. );
  67. }
  68. if (isset($_GET['role']) and ($_GET['do'] == 'grant' or $_GET['do'] == 'revoke')) {
  69. $result_message = assign_role(
  70. 'user',
  71. $_GET['do'],
  72. $user_id,
  73. $_GET['role'],
  74. $_GET['scope']
  75. );
  76. }
  77. }
  78. // ------------------------------------------------------------------
  79. // RETRIEVING THE PERMISSIONS OF THE ROLES OF THE USER
  80. // ------------------------------------------------------------------
  81. if (api_get_setting('user_roles') == 'true') {
  82. // course roles that are assigned to the user
  83. $current_user_role_permissions_of_user = get_roles_permissions('user', $user_id);
  84. $inherited_permissions = permission_array_merge($inherited_permissions, $current_user_role_permissions_of_user);
  85. // NOTE: deze array moet nog gemerged worden met de $inherited_permissions array
  86. // (heet momenteel nog $current_group_permissions_of_user omdat voorlopig enkel de
  87. // groepsge�rfde permissions in beschouwing worden genomen
  88. // dit moet ook de rol permissies van rollen die toegekend worden aan een gebruiker
  89. // en de rol permissies van rollen die toegekend worden aan de groepen van een gebruiker
  90. // omvatten.
  91. // NOTE: checken als de rollen brol wel degelijk geactiveerd is voordat we dit allemaal
  92. // ophalen.
  93. // platform roles that are assigned to the user
  94. $current_user_role_permissions_of_user = get_roles_permissions('user', $user_id, 'platform');
  95. $inherited_permissions = permission_array_merge($inherited_permissions, $current_user_role_permissions_of_user);
  96. }
  97. // ------------------------------------------------------------------
  98. // RETRIEVING THE PERMISSIONS OF THE ROLES OF THE GROUPS OF THE USER
  99. // ------------------------------------------------------------------
  100. if (api_get_setting('group_roles') == 'true') {
  101. // NOTE: DIT MOET NOG VERDER UITGEWERKT WORDEN
  102. foreach ($groups_of_user as $group) {
  103. $this_current_group_role_permissions_of_user = get_roles_permissions('user', $user_id);
  104. //$inherited_permissions[$tool][]=$permission;
  105. }
  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. // the list of the roles for the user
  113. echo '<strong>'.get_lang('User roles').'</strong><br />';
  114. $current_user_course_roles = get_roles('user', $user_id);
  115. $current_user_platform_roles = get_roles('user', $user_id, 'platform');
  116. display_role_list($current_user_course_roles, $current_user_platform_roles);
  117. echo '<br />';
  118. }
  119. // ---------------------------------------------------
  120. // DISPLAYING THE MATRIX (user permissions)
  121. // ---------------------------------------------------
  122. echo "<table class=\"data_table\">\n";
  123. // the header
  124. echo "\t<tr>\n";
  125. echo "\t\t<th rowspan=\"2\">".get_lang('Module')."</th>\n";
  126. echo "\t\t<th colspan=\"4\">".get_lang('Tasks manager')."</th>\n";
  127. echo "\t\t<th colspan=\"3\">".get_lang('Comment manager')."</th>\n";
  128. echo "\t\t<th colspan=\"3\">".get_lang('Project manager')."</th>\n";
  129. echo "\t</tr>\n";
  130. // Subheader
  131. echo "\t<tr>\n";
  132. echo "\t\t<th align='center'>".get_lang('Add')."</th>\n";
  133. echo "\t\t<th align='center'>".get_lang('Delete')."</th>\n";
  134. echo "\t\t<th align='center'>".get_lang('Edit')."</th>\n";
  135. echo "\t\t<th align='center'>".get_lang('Rate')."</th>\n";
  136. echo "\t\t<th align='center'>".get_lang('Add')."</th>\n";
  137. echo "\t\t<th align='center'>".get_lang('Delete')."</th>\n";
  138. echo "\t\t<th align='center'>".get_lang('Rate')."</th>\n";
  139. echo "\t\t<th align='center'>".get_lang('Tasks')."</th>\n";
  140. echo "\t\t<th align='center'>".get_lang('Members')."</th>\n";
  141. echo "\t\t<th align='center'>".get_lang('Roles')."</th>\n";
  142. echo "\t</tr>\n";
  143. // the main area with the checkboxes or images
  144. foreach ($blog_users as $user_id => $user_name) { // $blog_users contains all the users in this blog
  145. // ---------------------------------------------------
  146. // RETRIEVING THE PERMISSIONS OF THE USER
  147. // ---------------------------------------------------
  148. $current_user_permissions = [];
  149. $current_user_permissions = get_permissions('user', $user_id);
  150. echo "\t<tr>\n";
  151. echo "\t\t<td>\n";
  152. echo $user_name;
  153. echo "\t\t</td>\n";
  154. foreach ($rights_full as $key => $value) {
  155. echo "\t\t<td align='center'>\n";
  156. if (in_array($value, $rights_blog)) {
  157. display_image_matrix_for_blogs(
  158. $current_user_permissions,
  159. $user_id,
  160. 'BLOG_'.$blog_id,
  161. $value,
  162. (isset($inherited_permissions) ? $inherited_permissions : null),
  163. (isset($course_admin) ? $course_admin : null)
  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. echo "</form><br />";
  176. // LEGEND
  177. echo '<strong>'.get_lang('Legend').'</strong><br />';
  178. echo '<img src="../img/wrong.gif" /> '.get_lang('The user hasn\'t rights').'<br />';
  179. echo '<img src="../img/checkbox_on2.gif" /> '.get_lang('The user has rights').'<br />';
  180. echo '<img src="../img/checkbox_on3.gif" /> '.get_lang('The user has rightsByRoleGroup').'<br />';