blog_permissions.inc.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. * @package chamilo.permissions
  8. */
  9. /**
  10. * Init
  11. */
  12. $rights_full=array("article_add","article_delete","article_edit","article_rate","article_comments_add","article_comments_delete","article_comments_rate","task_management","member_management","role_management");
  13. $rights_limited=array("Add","Edit","Delete");
  14. $rights_blog=array("article_add","article_delete","article_edit","article_rate","article_comments_add","article_comments_delete","article_comments_rate","task_management","member_management","role_management");
  15. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  16. // Get all user
  17. $blog_users = Blog::get_blog_users($_GET['blog_id']);
  18. $course_id = api_get_course_int_id();
  19. // Remove the blog creater because he has all the rights automatically
  20. // and we want to keep it that way.
  21. $tbl_course_rel_user = $table=Database::get_main_table(TABLE_MAIN_COURSE_USER);
  22. $sql = "SELECT user_id FROM $tbl_course_rel_user WHERE status = '1' AND course_code = '".$_SESSION['_cid']."'";
  23. $result = Database::query($sql);
  24. while ($user = Database::fetch_assoc($result)) {
  25. unset($blog_users[$user['user_id']]);
  26. }
  27. //$user_id=$userIdViewed;
  28. if ($mainUserInfo['status']==1)
  29. {
  30. $course_admin=1;
  31. }
  32. include_once('permissions_functions.inc.php');
  33. // ACTIONS
  34. if (isset($_GET['do']))
  35. {
  36. if ( isset($_GET['permission']) AND isset($_GET['tool']) AND ($_GET['do']=='grant' OR $_GET['do']=='revoke'))
  37. {
  38. $result_message=store_one_permission('user', $_GET['do'], $_GET['user_id'], $_GET['tool'], $_GET['permission']);
  39. }
  40. if (isset($_GET['role']) AND ($_GET['do']=='grant' OR $_GET['do']=='revoke'))
  41. {
  42. $result_message=assign_role('user', $_GET['do'], $user_id, $_GET['role'], $_GET['scope']);
  43. }
  44. }
  45. /*
  46. if (isset($result_message))
  47. {
  48. Display::display_normal_message($result_message);
  49. }
  50. */
  51. // ------------------------------------------------------------------
  52. // RETRIEVING THE PERMISSIONS OF THE ROLES OF THE USER
  53. // ------------------------------------------------------------------
  54. if (api_get_setting('user_roles')=='true') {
  55. // course roles that are assigned to the user
  56. $current_user_role_permissions_of_user=get_roles_permissions('user',$user_id);
  57. $inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user);
  58. // NOTE: deze array moet nog gemerged worden met de $inherited_permissions array
  59. // (heet momenteel nog $current_group_permissions_of_user omdat voorlopig enkel de
  60. // groepsge�rfde permissions in beschouwing worden genomen
  61. // dit moet ook de rol permissies van rollen die toegekend worden aan een gebruiker
  62. // en de rol permissies van rollen die toegekend worden aan de groepen van een gebruiker
  63. // omvatten.
  64. // NOTE: checken als de rollen brol wel degelijk geactiveerd is voordat we dit allemaal
  65. // ophalen.
  66. // platform roles that are assigned to the user
  67. $current_user_role_permissions_of_user=get_roles_permissions('user',$user_id, 'platform');
  68. $inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user);
  69. }
  70. // ------------------------------------------------------------------
  71. // RETRIEVING THE PERMISSIONS OF THE ROLES OF THE GROUPS OF THE USER
  72. // ------------------------------------------------------------------
  73. if (api_get_setting('group_roles')=='true')
  74. {
  75. // NOTE: DIT MOET NOG VERDER UITGEWERKT WORDEN
  76. foreach ($groups_of_user as $group)
  77. {
  78. $this_current_group_role_permissions_of_user=get_roles_permissions('user',$user_id);
  79. //$inherited_permissions[$tool][]=$permission;
  80. }
  81. }
  82. echo "<form method=\"post\" action=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."\">";
  83. // ---------------------------------------------------
  84. // DISPLAYING THE ROLES LIST
  85. // ---------------------------------------------------
  86. if (api_get_setting('user_roles')=='true')
  87. {
  88. // the list of the roles for the user
  89. echo '<strong>'.get_lang('UserRoles').'</strong><br />';
  90. $current_user_course_roles=get_roles('user',$user_id);
  91. $current_user_platform_roles=get_roles('user',$user_id, 'platform');
  92. display_role_list($current_user_course_roles, $current_user_platform_roles);
  93. echo '<br />';
  94. }
  95. // ---------------------------------------------------
  96. // DISPLAYING THE MATRIX (user permissions)
  97. // ---------------------------------------------------
  98. echo "<table class=\"data_table\">\n";
  99. // the header
  100. echo "\t<tr>\n";
  101. echo "\t\t<th rowspan=\"2\">".get_lang('Module')."</th>\n";
  102. echo "\t\t<th colspan=\"4\">".get_lang('ArticleManager')."</th>\n";
  103. echo "\t\t<th colspan=\"3\">".get_lang('CommentManager')."</th>\n";
  104. echo "\t\t<th colspan=\"3\">".get_lang('BlogManager')."</th>\n";
  105. echo "\t</tr>\n";
  106. // Subheader
  107. echo "\t<tr>\n";
  108. echo "\t\t<th align='center'>".get_lang('Add')."</th>\n";
  109. echo "\t\t<th align='center'>".get_lang('Delete')."</th>\n";
  110. echo "\t\t<th align='center'>".get_lang('Edit')."</th>\n";
  111. echo "\t\t<th align='center'>".get_lang('Rate')."</th>\n";
  112. echo "\t\t<th align='center'>".get_lang('Add')."</th>\n";
  113. echo "\t\t<th align='center'>".get_lang('Delete')."</th>\n";
  114. echo "\t\t<th align='center'>".get_lang('Rate')."</th>\n";
  115. echo "\t\t<th align='center'>".get_lang('Tasks')."</th>\n";
  116. echo "\t\t<th align='center'>".get_lang('Members')."</th>\n";
  117. echo "\t\t<th align='center'>".get_lang('Roles')."</th>\n";
  118. echo "\t</tr>\n";
  119. // the main area with the checkboxes or images
  120. foreach ($blog_users as $user_id => $user_name) // $blog_users contains all the users in this blog
  121. {
  122. // ---------------------------------------------------
  123. // RETRIEVING THE PERMISSIONS OF THE USER
  124. // ---------------------------------------------------
  125. $current_user_permissions = array();
  126. $current_user_permissions = get_permissions('user', $user_id);
  127. echo "\t<tr>\n";
  128. echo "\t\t<td>\n";
  129. echo $user_name;
  130. echo "\t\t</td>\n";
  131. foreach ($rights_full as $key => $value)
  132. {
  133. echo "\t\t<td align='center'>\n";
  134. if (in_array($value,$rights_blog))
  135. {
  136. display_image_matrix_for_blogs($current_user_permissions, $user_id, 'BLOG_'.$blog_id, $value,$inherited_permissions, $course_admin);
  137. }
  138. // note: in a later stage this part will be replaced by a function
  139. // so that we can easily switch between a checkbox approach or an image approach
  140. // where every click is in fact a change of status. In the checkbox approach you first have to
  141. // do the changes and then store them by clicking the submit button.
  142. echo "\t\t</td>\n";
  143. }
  144. echo "\t</tr>\n";
  145. }
  146. echo "</table>\n";
  147. echo "</form><br />";
  148. // LEGEND
  149. echo '<strong>'.get_lang('Legend').'</strong><br />';
  150. echo '<img src="../img/wrong.gif" /> '.get_lang('UserHasPermissionNot').'<br />';
  151. echo '<img src="../img/checkbox_on2.gif" /> '.get_lang('UserHasPermission').'<br />';
  152. echo '<img src="../img/checkbox_on3.gif" /> '.get_lang('UserHasPermissionByRoleGroup').'<br />';