group_members.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. *
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') != 'true') {
  12. api_not_allowed(true);
  13. }
  14. $this_section = SECTION_SOCIAL;
  15. $group_id = intval($_GET['id']);
  16. $userGroup = new UserGroup();
  17. $user_role = '';
  18. //todo @this validation could be in a function in group_portal_manager
  19. if (empty($group_id)) {
  20. api_not_allowed(true);
  21. } else {
  22. $group_info = $userGroup->get($group_id);
  23. if (empty($group_info)) {
  24. api_not_allowed(true);
  25. }
  26. $user_role = $userGroup->get_user_group_role(
  27. api_get_user_id(),
  28. $group_id
  29. );
  30. if (!in_array(
  31. $user_role,
  32. [
  33. GROUP_USER_PERMISSION_ADMIN,
  34. GROUP_USER_PERMISSION_MODERATOR,
  35. GROUP_USER_PERMISSION_READER,
  36. ]
  37. )
  38. ) {
  39. api_not_allowed(true);
  40. }
  41. }
  42. $interbreadcrumb[] = ['url' => 'home.php', 'name' => get_lang('Social')];
  43. $interbreadcrumb[] = ['url' => 'groups.php', 'name' => get_lang('Groups')];
  44. $interbreadcrumb[] = ['url' => 'group_view.php?id='.$group_id, 'name' => $group_info['name']];
  45. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('MemberList')];
  46. //if i'm a moderator
  47. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  48. // we add a user only if is a open group
  49. $user_join = intval($_GET['u']);
  50. //if i'm a moderator
  51. if ($userGroup->isGroupModerator($group_id)) {
  52. $userGroup->update_user_role($user_join, $group_id);
  53. Display::addFlash(Display::return_message(get_lang('UserAdded')));
  54. }
  55. }
  56. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  57. // we add a user only if is a open group
  58. $user_join = intval($_GET['u']);
  59. //if i'm a moderator
  60. if ($userGroup->isGroupModerator($group_id)) {
  61. $userGroup->delete_user_rel_group($user_join, $group_id);
  62. Display::addFlash(Display::return_message(get_lang('UserDeleted')));
  63. }
  64. }
  65. if (isset($_GET['action']) && $_GET['action'] == 'set_moderator') {
  66. // we add a user only if is a open group
  67. $user_moderator = intval($_GET['u']);
  68. //if i'm the admin
  69. if ($userGroup->is_group_admin($group_id)) {
  70. $userGroup->update_user_role(
  71. $user_moderator,
  72. $group_id,
  73. GROUP_USER_PERMISSION_MODERATOR
  74. );
  75. Display::addFlash(Display::return_message(get_lang('UserChangeToModerator')));
  76. }
  77. }
  78. if (isset($_GET['action']) && $_GET['action'] == 'delete_moderator') {
  79. // we add a user only if is a open group
  80. $user_moderator = intval($_GET['u']);
  81. //only group admins can do that
  82. if ($userGroup->is_group_admin($group_id)) {
  83. $userGroup->update_user_role(
  84. $user_moderator,
  85. $group_id,
  86. GROUP_USER_PERMISSION_READER
  87. );
  88. Display::addFlash(Display::return_message(get_lang('UserChangeToReader')));
  89. }
  90. }
  91. $users = $userGroup->get_users_by_group(
  92. $group_id,
  93. false,
  94. [
  95. GROUP_USER_PERMISSION_ADMIN,
  96. GROUP_USER_PERMISSION_READER,
  97. GROUP_USER_PERMISSION_MODERATOR,
  98. ],
  99. 0,
  100. 1000
  101. );
  102. $new_member_list = [];
  103. $social_avatar_block = SocialManager::show_social_avatar_block(
  104. 'member_list',
  105. $group_id
  106. );
  107. $social_menu_block = SocialManager::show_social_menu('member_list', $group_id);
  108. $social_right_content = '<h2>'.$group_info['name'].'</h2>';
  109. foreach ($users as $user) {
  110. switch ($user['relation_type']) {
  111. case GROUP_USER_PERMISSION_ADMIN:
  112. $user['link'] = Display::return_icon(
  113. 'social_group_admin.png',
  114. get_lang('Admin')
  115. );
  116. break;
  117. case GROUP_USER_PERMISSION_READER:
  118. if (in_array(
  119. $user_role,
  120. [
  121. GROUP_USER_PERMISSION_ADMIN,
  122. GROUP_USER_PERMISSION_MODERATOR,
  123. ]
  124. )
  125. ) {
  126. $user['link'] = '<a href="group_members.php?id='.$group_id.'&u='.$user['id'].'&action=delete">'.
  127. Display::return_icon(
  128. 'delete.png',
  129. get_lang('DeleteFromGroup')
  130. ).'</a>'.
  131. '<a href="group_members.php?id='.$group_id.'&u='.$user['id'].'&action=set_moderator">'.
  132. Display::return_icon(
  133. 'social_moderator_add.png',
  134. get_lang('AddModerator')
  135. ).'</a>';
  136. }
  137. break;
  138. case GROUP_USER_PERMISSION_PENDING_INVITATION:
  139. $user['link'] = '<a href="group_members.php?id='.$group_id.'&u='.$user['id'].'&action=add">'.
  140. Display::return_icon(
  141. 'pending_invitation.png',
  142. get_lang('PendingInvitation')
  143. ).'</a>';
  144. break;
  145. case GROUP_USER_PERMISSION_MODERATOR:
  146. $user['link'] = Display::return_icon(
  147. 'social_group_moderator.png',
  148. get_lang('Moderator')
  149. );
  150. //only group admin can manage moderators
  151. if ($user_role == GROUP_USER_PERMISSION_ADMIN) {
  152. $user['link'] .= '<a href="group_members.php?id='.$group_id.'&u='.$user['id'].'&action=delete_moderator">'.
  153. Display::return_icon(
  154. 'social_moderator_delete.png',
  155. get_lang('DeleteModerator')
  156. ).'</a>';
  157. }
  158. break;
  159. }
  160. $userPicture = UserManager::getUserPicture($user['id']);
  161. $user['image'] = '<img src="'.$userPicture.'" width="50px" height="50px" />';
  162. $new_member_list[] = $user;
  163. }
  164. if (count($new_member_list) > 0) {
  165. $social_right_content .= Display::return_sortable_grid(
  166. 'list_members',
  167. [],
  168. $new_member_list,
  169. ['hide_navigation' => true, 'per_page' => 100],
  170. [],
  171. false,
  172. [true, false, true, false, false, true, true]
  173. );
  174. }
  175. $tpl = new Template(null);
  176. $tpl->setHelp('Groups');
  177. $tpl->assign('social_avatar_block', $social_avatar_block);
  178. $tpl->assign('social_menu_block', $social_menu_block);
  179. $tpl->assign('social_right_content', $social_right_content);
  180. $social_layout = $tpl->get_template('social/home.tpl');
  181. $tpl->display($social_layout);