invitations.php 9.9 KB

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