group_members.php 6.4 KB

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