group_waiting_list.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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();
  13. }
  14. $this_section = SECTION_SOCIAL;
  15. $group_id = intval($_GET['id']);
  16. $usergroup = new UserGroup();
  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. //only admin or moderator can do that
  26. $user_role = $usergroup->get_user_group_role(api_get_user_id(), $group_id);
  27. if (!in_array($user_role, [GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR])) {
  28. api_not_allowed();
  29. }
  30. }
  31. $interbreadcrumb[] = ['url' => 'groups.php', 'name' => get_lang('Groups')];
  32. $interbreadcrumb[] = ['url' => 'group_view.php?id='.$group_id, 'name' => $group_info['name']];
  33. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('WaitingList')];
  34. // Group information
  35. $admins = $usergroup->get_users_by_group(
  36. $group_id,
  37. true,
  38. [GROUP_USER_PERMISSION_ADMIN],
  39. 0,
  40. 1000
  41. );
  42. $show_message = '';
  43. if (isset($_GET['action']) && $_GET['action'] == 'accept') {
  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 ($usergroup->isGroupModerator($group_id)) {
  48. $usergroup->update_user_role($user_join, $group_id);
  49. Display::addFlash(Display::return_message(get_lang('UserAdded')));
  50. }
  51. }
  52. if (isset($_GET['action']) && $_GET['action'] == 'deny') {
  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 ($usergroup->isGroupModerator($group_id)) {
  57. $usergroup->delete_user_rel_group($user_join, $group_id);
  58. Display::addFlash(Display::return_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 ($usergroup->is_group_admin($group_id)) {
  66. $usergroup->update_user_role($user_moderator, $group_id, GROUP_USER_PERMISSION_MODERATOR);
  67. Display::addFlash(Display::return_message(get_lang('UserChangeToModerator')));
  68. }
  69. }
  70. $users = $usergroup->get_users_by_group(
  71. $group_id,
  72. true,
  73. [GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER],
  74. 0,
  75. 1000
  76. );
  77. $new_member_list = [];
  78. $social_left_content = SocialManager::show_social_menu('waiting_list', $group_id);
  79. // Display form
  80. foreach ($users as $user) {
  81. $userId = $user['user_info']['user_id'];
  82. switch ($user['relation_type']) {
  83. case GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER:
  84. $user['link'] = '<a href="group_waiting_list.php?id='.$group_id.'&u='.$userId.'&action=accept">'.
  85. Display::return_icon('invitation_friend.png', get_lang('AddNormalUser')).'</a>';
  86. $user['link'] .= '<a href="group_waiting_list.php?id='.$group_id.'&u='.$userId.'&action=set_moderator">'.
  87. Display::return_icon('social_moderator_add.png', get_lang('AddModerator')).'</a>';
  88. $user['link'] .= '<a href="group_waiting_list.php?id='.$group_id.'&u='.$userId.'&action=deny">'.
  89. Display::return_icon('user_delete.png', get_lang('DenyEntry')).'</a>';
  90. break;
  91. }
  92. $new_member_list[] = $user;
  93. }
  94. $social_right_content = '';
  95. if (empty($new_member_list) > 0) {
  96. $social_right_content = Display :: return_message(get_lang('ThereAreNotUsersInTheWaitingList'));
  97. }
  98. $tpl = new Template(null);
  99. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'groups', $group_id);
  100. $social_menu_block = SocialManager::show_social_menu('member_list', $group_id);
  101. $tpl->assign('social_menu_block', $social_menu_block);
  102. $tpl->setHelp('Groups');
  103. $tpl->assign('members', $new_member_list);
  104. $tpl->assign('social_right_content', $social_right_content);
  105. $social_layout = $tpl->get_template('social/group_waiting_list.tpl');
  106. $tpl->display($social_layout);