group_waiting_list.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 __DIR__.'/../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. //todo @this validation could be in a function in group_portal_manager
  17. if (empty($group_id)) {
  18. api_not_allowed();
  19. } else {
  20. $group_info = $usergroup->get($group_id);
  21. if (empty($group_info)) {
  22. api_not_allowed();
  23. }
  24. //only admin or moderator can do that
  25. $user_role = $usergroup->get_user_group_role(api_get_user_id(), $group_id);
  26. if (!in_array($user_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) {
  27. api_not_allowed();
  28. }
  29. }
  30. $interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups'));
  31. $interbreadcrumb[] = array('url' => 'group_view.php?id='.$group_id, 'name' => $group_info['name']);
  32. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('WaitingList'));
  33. // Group information
  34. $admins = $usergroup->get_users_by_group(
  35. $group_id,
  36. true,
  37. array(GROUP_USER_PERMISSION_ADMIN),
  38. 0,
  39. 1000
  40. );
  41. $show_message = '';
  42. if (isset($_GET['action']) && $_GET['action'] == 'accept') {
  43. // we add a user only if is a open group
  44. $user_join = intval($_GET['u']);
  45. //if i'm a moderator
  46. if ($usergroup->is_group_moderator($group_id)) {
  47. $usergroup->update_user_role($user_join, $group_id);
  48. Display::addFlash(Display::return_message(get_lang('UserAdded')));
  49. }
  50. }
  51. if (isset($_GET['action']) && $_GET['action'] == 'deny') {
  52. // we add a user only if is a open group
  53. $user_join = intval($_GET['u']);
  54. //if i'm a moderator
  55. if ($usergroup->is_group_moderator($group_id)) {
  56. $usergroup->delete_user_rel_group($user_join, $group_id);
  57. Display::addFlash(Display::return_message(get_lang('UserDeleted')));
  58. }
  59. }
  60. if (isset($_GET['action']) && $_GET['action'] == 'set_moderator') {
  61. // we add a user only if is a open group
  62. $user_moderator = intval($_GET['u']);
  63. //if i'm the admin
  64. if ($usergroup->is_group_admin($group_id)) {
  65. $usergroup->update_user_role($user_moderator, $group_id, GROUP_USER_PERMISSION_MODERATOR);
  66. Display::addFlash(Display::return_message(get_lang('UserChangeToModerator')));
  67. }
  68. }
  69. $users = $usergroup->get_users_by_group(
  70. $group_id,
  71. true,
  72. array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER),
  73. 0,
  74. 1000
  75. );
  76. $new_member_list = array();
  77. $social_left_content = SocialManager::show_social_menu('waiting_list', $group_id);
  78. // Display form
  79. foreach ($users as $user) {
  80. $userId = $user['user_info']['user_id'];
  81. switch ($user['relation_type']) {
  82. case GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER:
  83. $user['link'] = '<a href="group_waiting_list.php?id='.$group_id.'&u='.$userId.'&action=accept">'.
  84. Display::return_icon('invitation_friend.png', get_lang('AddNormalUser')).'</a>';
  85. $user['link'] .= '<a href="group_waiting_list.php?id='.$group_id.'&u='.$userId.'&action=set_moderator">'.
  86. Display::return_icon('social_moderator_add.png', get_lang('AddModerator')).'</a>';
  87. $user['link'] .= '<a href="group_waiting_list.php?id='.$group_id.'&u='.$userId.'&action=deny">'.
  88. Display::return_icon('user_delete.png', get_lang('DenyEntry')).'</a>';
  89. break;
  90. }
  91. $new_member_list[] = $user;
  92. }
  93. $social_right_content = '';
  94. if (empty($new_member_list) > 0) {
  95. $social_right_content = Display :: return_message(get_lang('ThereAreNotUsersInTheWaitingList'));
  96. }
  97. $tpl = new Template(null);
  98. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'groups', $group_id);
  99. $social_menu_block = SocialManager::show_social_menu('member_list', $group_id);
  100. $tpl->assign('social_menu_block', $social_menu_block);
  101. $tpl->setHelp('Groups');
  102. $tpl->assign('members', $new_member_list);
  103. $tpl->assign('social_right_content', $social_right_content);
  104. $social_layout = $tpl->get_template('social/group_waiting_list.tpl');
  105. $tpl->display($social_layout);