invitations.php 9.9 KB

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