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. $language_file = array('userInfo');
  9. require_once '../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, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) {
  28. api_not_allowed();
  29. }
  30. }
  31. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  32. $interbreadcrumb[] = array('url' => 'group_view.php?id='.$group_id, 'name' => $group_info['name']);
  33. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('WaitingList'));
  34. // Group information
  35. $admins = $usergroup->get_users_by_group(
  36. $group_id,
  37. true,
  38. array(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->is_group_moderator($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->is_group_moderator($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. array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER),
  74. 0,
  75. 1000
  76. );
  77. $new_member_list = array();
  78. $social_left_content = SocialManager::show_social_menu('waiting_list', $group_id);
  79. // Display form
  80. foreach($users as $user) {
  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='.$user['user_id'].'&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='.$user['user_id'].'&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='.$user['user_id'].'&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, $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);