blog_permissions.inc.php 6.8 KB

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