group_members.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. /**
  8. * Initialization
  9. */
  10. $language_file = array('userInfo');
  11. $cidReset = true;
  12. require_once '../inc/global.inc.php';
  13. api_block_anonymous_users();
  14. if (api_get_setting('allow_social_tool') !='true') {
  15. api_not_allowed();
  16. }
  17. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  18. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  19. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  20. $this_section = SECTION_SOCIAL;
  21. $interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('Social'));
  22. $interbreadcrumb[] = array('url' => 'groups.php','name' => get_lang('Groups'));
  23. $interbreadcrumb[] = array('url' => '#','name' => get_lang('MemberList'));
  24. $group_id = intval($_GET['id']);
  25. //todo @this validation could be in a function in group_portal_manager
  26. if (empty($group_id)) {
  27. api_not_allowed();
  28. } else {
  29. $group_info = GroupPortalManager::get_group_data($group_id);
  30. if (empty($group_info)) {
  31. api_not_allowed();
  32. }
  33. $user_role = GroupPortalManager::get_user_group_role(api_get_user_id(), $group_id);
  34. if (!in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR, GROUP_USER_PERMISSION_READER))) {
  35. api_not_allowed();
  36. }
  37. }
  38. Display :: display_header($tool_name, 'Groups');
  39. $user_online_list = who_is_online(api_get_setting('time_limit_whosonline'), true);
  40. $user_online_count = count($user_online_list);
  41. $show_message = '';
  42. //if i'm a moderator
  43. if (isset($_GET['action']) && $_GET['action']=='add') {
  44. // we add a user only if is a open group
  45. $user_join = intval($_GET['u']);
  46. //if i'm a moderator
  47. if (GroupPortalManager::is_group_moderator($group_id)) {
  48. GroupPortalManager::update_user_role($user_join, $group_id);
  49. $show_message = get_lang('UserAdded');
  50. }
  51. }
  52. if (isset($_GET['action']) && $_GET['action']=='delete') {
  53. // we add a user only if is a open group
  54. $user_join = intval($_GET['u']);
  55. //if i'm a moderator
  56. if (GroupPortalManager::is_group_moderator($group_id)) {
  57. GroupPortalManager::delete_user_rel_group($user_join, $group_id);
  58. $show_message = get_lang('UserDeleted');
  59. }
  60. }
  61. if (isset($_GET['action']) && $_GET['action']=='set_moderator') {
  62. // we add a user only if is a open group
  63. $user_moderator= intval($_GET['u']);
  64. //if i'm the admin
  65. if (GroupPortalManager::is_group_admin($group_id)) {
  66. GroupPortalManager::update_user_role($user_moderator, $group_id, GROUP_USER_PERMISSION_MODERATOR);
  67. $show_message = get_lang('UserChangeToModerator');
  68. }
  69. }
  70. if (isset($_GET['action']) && $_GET['action']=='delete_moderator') {
  71. // we add a user only if is a open group
  72. $user_moderator= intval($_GET['u']);
  73. //only group admins can do that
  74. if (GroupPortalManager::is_group_admin($group_id)) {
  75. GroupPortalManager::update_user_role($user_moderator, $group_id, GROUP_USER_PERMISSION_READER);
  76. $show_message = get_lang('UserChangeToReader');
  77. }
  78. }
  79. $users = GroupPortalManager::get_users_by_group($group_id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000);
  80. $new_member_list = array();
  81. echo '<div id="social-content">';
  82. echo '<div id="social-content-left">';
  83. //this include the social menu div
  84. SocialManager::show_social_menu('member_list',$group_id);
  85. echo '</div>';
  86. echo '<div id="social-content-right">';
  87. echo '<h1><a href="groups.php?id='.$group_id.'">'.$group_info['name'].'</a></h1>';
  88. echo '<div class="rounded_div" style="width:90%">';
  89. if (! empty($show_message)){
  90. Display :: display_confirmation_message($show_message);
  91. }
  92. foreach($users as $user) {
  93. switch ($user['relation_type']) {
  94. case GROUP_USER_PERMISSION_ADMIN:
  95. $user['link'] = Display::return_icon('social_group_admin.png', get_lang('Admin'));
  96. break;
  97. case GROUP_USER_PERMISSION_READER:
  98. if (in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) {
  99. $user['link'] = '<a href="group_members.php?id='.$group_id.'&u='.$user['user_id'].'&action=delete">'.Display::return_icon('delete.png', get_lang('DeleteFromGroup')).'</a>'.
  100. '<a href="group_members.php?id='.$group_id.'&u='.$user['user_id'].'&action=set_moderator">'.Display::return_icon('social_moderator_add.png', get_lang('AddModerator')).'</a>';
  101. }
  102. break;
  103. case GROUP_USER_PERMISSION_PENDING_INVITATION:
  104. $user['link'] = '<a href="group_members.php?id='.$group_id.'&u='.$user['user_id'].'&action=add">'.Display::return_icon('pending_invitation.png', get_lang('PendingInvitation')).'</a>';
  105. break;
  106. case GROUP_USER_PERMISSION_MODERATOR:
  107. $user['link'] = Display::return_icon('social_group_moderator.png', get_lang('Moderator'));
  108. //only group admin can manage moderators
  109. if ($user_role == GROUP_USER_PERMISSION_ADMIN) {
  110. $user['link'] .='<a href="group_members.php?id='.$group_id.'&u='.$user['user_id'].'&action=delete_moderator">'.Display::return_icon('social_moderator_delete.png', get_lang('DeleteModerator')).'</a>';
  111. }
  112. break;
  113. }
  114. $image_path = UserManager::get_user_picture_path_by_id($user['user_id'], 'web', false, true);
  115. $picture = UserManager::get_picture_user($user['user_id'], $image_path['file'],80);
  116. $user['image'] = '<img src="'.$picture['file'].'" width="50px" height="50px" />';
  117. $new_member_list[] = $user;
  118. }
  119. if (count($new_member_list) > 0) {
  120. Display::display_sortable_grid('list_members', array(), $new_member_list, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, false, true,true,false,true,true));
  121. }
  122. echo '</div>';
  123. echo '</div>';
  124. echo '</div>';
  125. Display :: display_footer();