invitations.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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('social.allow_social_tool') != 'true') {
  11. api_not_allowed();
  12. }
  13. $this_section = SECTION_SOCIAL;
  14. $interbreadcrumb[] = array ('url' =>'profile.php','name' => get_lang('SocialNetwork'));
  15. $interbreadcrumb[] = array ('url' =>'#','name' => get_lang('Invitations'));
  16. if (is_array($_GET) && count($_GET) > 0) {
  17. foreach ($_GET as $key => $value) {
  18. switch ($key) {
  19. case 'accept':
  20. $useRole = GroupPortalManager::get_user_group_role(api_get_user_id(), $value);
  21. if (in_array(
  22. $useRole,
  23. array(
  24. GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,
  25. GROUP_USER_PERMISSION_PENDING_INVITATION
  26. )
  27. )) {
  28. GroupPortalManager::update_user_role(api_get_user_id(), $value, GROUP_USER_PERMISSION_READER);
  29. Display::addFlash(
  30. Display::return_message(get_lang('UserIsSubscribedToThisGroup'), 'success')
  31. );
  32. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php');
  33. exit;
  34. }
  35. if (in_array(
  36. $useRole,
  37. array(
  38. GROUP_USER_PERMISSION_READER,
  39. GROUP_USER_PERMISSION_ADMIN,
  40. GROUP_USER_PERMISSION_MODERATOR
  41. )
  42. )) {
  43. Display::addFlash(
  44. Display::return_message(get_lang('UserIsAlreadySubscribedToThisGroup'), 'warning')
  45. );
  46. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php');
  47. exit;
  48. }
  49. Display::addFlash(
  50. Display::return_message(get_lang('UserIsNotSubscribedToThisGroup'), 'warning')
  51. );
  52. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php');
  53. exit;
  54. break;
  55. case 'deny':
  56. GroupPortalManager::delete_user_rel_group(api_get_user_id(), $value);
  57. Display::addFlash(
  58. Display::return_message(get_lang('GroupInvitationWasDeny'))
  59. );
  60. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php');
  61. exit;
  62. }
  63. }
  64. }
  65. $userGroup = new UserGroup();
  66. $content = null;
  67. // Block Menu Social
  68. $social_menu_block = SocialManager::show_social_menu('invitations');
  69. // Block Invitations
  70. $socialInvitationsBlock = '<div id="id_response" align="center"></div>';
  71. $user_id = api_get_user_id();
  72. $list_get_invitation = SocialManager::get_list_invitation_of_friends_by_user_id($user_id);
  73. $list_get_invitation_sent = SocialManager::get_list_invitation_sent_by_user_id($user_id);
  74. $pending_invitations = $userGroup->get_groups_by_user(
  75. $user_id,
  76. GROUP_USER_PERMISSION_PENDING_INVITATION
  77. );
  78. $number_loop = count($list_get_invitation);
  79. $total_invitations = $number_loop + count($list_get_invitation_sent) + count($pending_invitations);
  80. if ($total_invitations == 0 && count($_GET) <= 0) {
  81. $socialInvitationsBlock .= '<div class="row">
  82. <div class="col-md-12">
  83. <a class="btn btn-success" href="search.php"><em class="fa fa-search"></em> '.
  84. get_lang('TryAndFindSomeFriends').'
  85. </a>
  86. </div>
  87. </div>';
  88. }
  89. if ($number_loop != 0) {
  90. $invitationHtml = '';
  91. foreach ($list_get_invitation as $invitation) {
  92. $sender_user_id = $invitation['user_sender_id'];
  93. $user_info = api_get_user_info($sender_user_id);
  94. $userPicture = $user_info['avatar'];
  95. $invitationHtml .= '<div id="id_'.$sender_user_id.'" class="panel panel-default">';
  96. $title = Security::remove_XSS($invitation['title'], STUDENT, true);
  97. $content = Security::remove_XSS($invitation['content'], STUDENT, true);
  98. $date = api_convert_and_format_date($invitation['send_date'], DATE_TIME_FORMAT_LONG);
  99. $invitationHtml .= '<div class="row">';
  100. $invitationHtml .= '<div class="col-md-2">';
  101. $invitationHtml .= '<a href="profile.php?u='.$sender_user_id.'"><img class="img-responsive" src="'.$userPicture.'"/></a>';
  102. $invitationHtml .= '</div>';
  103. $invitationHtml .= '<div class="col-md-10">';
  104. $invitationHtml .= '<h4 class="title-profile"><a href="profile.php?u='.$sender_user_id.'">
  105. '.$user_info['complete_name'].'</a>:
  106. </h4>';
  107. $invitationHtml .= '<div class="content-invitation">'.$content.'</div>';
  108. $invitationHtml .= '<div class="date-invitation">'.get_lang('DateSend').' : '.$date.'</div>';
  109. $invitationHtml .= '<div class="btn-group" role="group">';
  110. $invitationHtml .= Display::toolbarButton(
  111. get_lang('AcceptInvitation'),
  112. api_get_path(WEB_AJAX_PATH) . 'social.ajax.php?' . http_build_query([
  113. 'a' => 'add_friend',
  114. 'friend_id' => $sender_user_id,
  115. 'is_my_friend' => 'friend'
  116. ]),
  117. 'check',
  118. 'success',
  119. ['id' => 'btn-accept-' . $sender_user_id]
  120. );
  121. $invitationHtml .= Display::toolbarButton(
  122. get_lang('DenyInvitation'),
  123. api_get_path(WEB_AJAX_PATH) . 'social.ajax.php?' . http_build_query([
  124. 'a' => 'deny_friend',
  125. 'denied_friend_id' => $sender_user_id,
  126. ]),
  127. 'times',
  128. 'danger',
  129. ['id' => 'btn-deny-' . $sender_user_id]
  130. );
  131. $invitationHtml .= '</div>';
  132. $invitationHtml .= '</div>';
  133. $invitationHtml .= '</div></div>';
  134. }
  135. $socialInvitationsBlock .= Display::panel($invitationHtml, get_lang('InvitationReceived'));
  136. }
  137. if (count($list_get_invitation_sent) > 0) {
  138. $invitationSentHtml = '';
  139. foreach ($list_get_invitation_sent as $invitation) {
  140. $sender_user_id = $invitation['user_receiver_id'];
  141. $user_info = api_get_user_info($sender_user_id);
  142. $invitationSentHtml .= '<div id="id_'.$sender_user_id.'" class="well">';
  143. $title = Security::remove_XSS($invitation['title'], STUDENT, true);
  144. $content = Security::remove_XSS($invitation['content'], STUDENT, true);
  145. $date = api_convert_and_format_date($invitation['send_date'], DATE_TIME_FORMAT_LONG);
  146. $invitationSentHtml .= '<div class="row">';
  147. $invitationSentHtml .= '<div class="col-md-3">';
  148. $invitationSentHtml .= '<a href="profile.php?u='.$sender_user_id.'"><img src="'.$user_info['avatar'].'" /></a>';
  149. $invitationSentHtml .= '</div>';
  150. $invitationSentHtml .= '<div class="col-md-9">';
  151. $invitationSentHtml .= '<h4 class="title-profile"><a class="profile_link" href="profile.php?u='.$sender_user_id.'">'.$user_info['complete_name'].'</a></h4>';
  152. $invitationSentHtml .= '<div class="content-invitation">'.$title.' : '.$content.'</div>';
  153. $invitationSentHtml .= '<div class="date-invitation">'. get_lang('DateSend').' : '.$date.'</div>';
  154. $invitationSentHtml .= '</div>';
  155. $invitationSentHtml .= '</div></div>';
  156. }
  157. $socialInvitationsBlock .= Display::panel($invitationSentHtml, get_lang('InvitationSent'));
  158. }
  159. if (count($pending_invitations) > 0) {
  160. $new_invitation = array();
  161. $waitingInvitation = '';
  162. foreach ($pending_invitations as $invitation) {
  163. $picture = $userGroup->get_picture_group(
  164. $invitation['id'],
  165. $invitation['picture'],
  166. 80
  167. );
  168. $img = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  169. $invitation['picture_uri'] = '<a href="group_view.php?id='.$invitation['id'].'">'.$img.'</a>';
  170. $invitation['name'] = '<a href="group_view.php?id='.$invitation['id'].'">'.cut($invitation['name'],120,true).'</a>';
  171. $invitation['description'] = cut($invitation['description'],220,true);
  172. $new_invitation[]=$invitation;
  173. $waitingInvitation .= '<div class="well"><div class="row">';
  174. $waitingInvitation .= '<div class="col-md-3">'.$invitation['picture_uri'].'</div>';
  175. $waitingInvitation .= '<div class="col-md-9">';
  176. $waitingInvitation .= '<h4 class="tittle-profile">'.$invitation['name'].'</h4>';
  177. $waitingInvitation .= '<div class="description-group">'.$invitation['description'].'</div>';
  178. $waitingInvitation .= '<div class="btn-group" role="group">';
  179. $waitingInvitation .= Display::toolbarButton(
  180. get_lang('AcceptInvitation'),
  181. api_get_path(WEB_CODE_PATH) . 'social/invitations.php?' . http_build_query(['accept' => $invitation['id']]),
  182. 'check',
  183. 'success',
  184. ['id' => 'accept-invitation-' . $invitation['id']]
  185. );
  186. $waitingInvitation .= Display::toolbarButton(
  187. get_lang('DenyInvitation'),
  188. api_get_path(WEB_CODE_PATH) . 'social/invitations.php?' . http_build_query(['deny' => $invitation['id']]),
  189. 'times',
  190. 'danger',
  191. ['id' => 'deny-invitation-' . $invitation['id']]
  192. );
  193. $waitingInvitation .='</div>';
  194. $waitingInvitation .= '</div></div>';
  195. }
  196. $socialInvitationsBlock .= Display::panel($waitingInvitation, get_lang('GroupsWaitingApproval'));
  197. }
  198. $tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
  199. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'invitations');
  200. $tpl->addGlobal('social_menu_block', $social_menu_block);
  201. $tpl->addGlobal('social_invitations_block', $socialInvitationsBlock);
  202. $tpl->addGlobal('content', $content);
  203. echo $tpl->render('@template_style/social/invitations.html.twig');