invitations.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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('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. $userGroup = new UserGroup();
  17. $htmlHeadXtra[] = '
  18. <script>
  19. function denied_friend(element_input) {
  20. name_button=$(element_input).attr("id");
  21. name_div_id="id_"+name_button.substring(13);
  22. user_id=name_div_id.split("_");
  23. friend_user_id=user_id[1];
  24. $.ajax({
  25. contentType: "application/x-www-form-urlencoded",
  26. beforeSend: function(objeto) {
  27. $("#id_response").html("<img src=\'../inc/lib/javascript/indicator.gif\' />");
  28. },
  29. type: "POST",
  30. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=deny_friend",
  31. data: "denied_friend_id="+friend_user_id,
  32. success: function(datos) {
  33. $("div#"+name_div_id).hide("slow");
  34. $("#id_response").html(datos);
  35. }
  36. });
  37. }
  38. function register_friend(element_input) {
  39. if(confirm("'.get_lang('AddToFriends').'")) {
  40. name_button=$(element_input).attr("id");
  41. name_div_id="id_"+name_button.substring(13);
  42. user_id=name_div_id.split("_");
  43. user_friend_id=user_id[1];
  44. $.ajax({
  45. contentType: "application/x-www-form-urlencoded",
  46. beforeSend: function(objeto) {
  47. $("div#dpending_"+user_friend_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  48. type: "POST",
  49. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=add_friend",
  50. data: "friend_id="+user_friend_id+"&is_my_friend="+"friend",
  51. success: function(data) {
  52. $("div#"+name_div_id).hide("slow");
  53. $("#id_response").html(data);
  54. }
  55. });
  56. }
  57. }
  58. </script>';
  59. $show_message = null;
  60. $content = null;
  61. // Block Menu Social
  62. $social_menu_block = SocialManager::show_social_menu('invitations');
  63. // Block Invitations
  64. $socialInvitationsBlock = '<div id="id_response" align="center"></div>';
  65. $user_id = api_get_user_id();
  66. $list_get_invitation = SocialManager::get_list_invitation_of_friends_by_user_id($user_id);
  67. $list_get_invitation_sent = SocialManager::get_list_invitation_sent_by_user_id($user_id);
  68. $pending_invitations = $userGroup->get_groups_by_user(
  69. $user_id,
  70. GROUP_USER_PERMISSION_PENDING_INVITATION
  71. );
  72. $number_loop = count($list_get_invitation);
  73. $total_invitations = $number_loop + count($list_get_invitation_sent) + count($pending_invitations);
  74. if ($total_invitations == 0 && count($_GET) <= 0) {
  75. $socialInvitationsBlock .= '<div class="row">
  76. <div class="col-md-12">
  77. <a class="btn btn-success" href="search.php"><i class="fa fa-search"></i> '.
  78. get_lang('TryAndFindSomeFriends').'
  79. </a>
  80. </div>
  81. </div>';
  82. }
  83. if ($number_loop != 0) {
  84. $invitationHtml = '';
  85. foreach ($list_get_invitation as $invitation) {
  86. $sender_user_id = $invitation['user_sender_id'];
  87. $user_info = api_get_user_info($sender_user_id);
  88. $userPicture = $user_info['avatar'];
  89. $invitationHtml .= '<div id="id_'.$sender_user_id.'" class="panel panel-default">';
  90. $title = Security::remove_XSS($invitation['title'], STUDENT, true);
  91. $content = Security::remove_XSS($invitation['content'], STUDENT, true);
  92. $date = api_convert_and_format_date($invitation['send_date'], DATE_TIME_FORMAT_LONG);
  93. $invitationHtml .= '<div class="row">';
  94. $invitationHtml .= '<div class="col-md-2">';
  95. $invitationHtml .= '<a href="profile.php?u='.$sender_user_id.'"><img class="img-responsive" src="'.$userPicture.'"/></a>';
  96. $invitationHtml .= '</div>';
  97. $invitationHtml .= '<div class="col-md-10">';
  98. $invitationHtml .= '<h4 class="title-profile"><a href="profile.php?u='.$sender_user_id.'">
  99. '.$user_info['complete_name'].'</a>:
  100. </h4>';
  101. $invitationHtml .= '<div class="content-invitation">'.$content.'</div>';
  102. $invitationHtml .= '<div class="date-invitation">'.get_lang('DateSend').' : '.$date.'</div>';
  103. $invitationHtml .= '<div class="btn-group" role="group">
  104. <button class="btn btn-success" type="submit" id="btn_accepted_'.$sender_user_id.'" onclick="javascript:register_friend(this)">
  105. <i class="fa fa-check"></i> '.get_lang('AcceptInvitation').'</button>
  106. <button class="btn btn-danger" type="submit" id="btn_deniedst_'.$sender_user_id.' " onclick="javascript:denied_friend(this)" >
  107. <i class="fa fa-times"></i> '.get_lang('DenyInvitation').'</button>
  108. ';
  109. $invitationHtml .= '</div>';
  110. $invitationHtml .= '</div>';
  111. $invitationHtml .= '</div></div>';
  112. }
  113. $socialInvitationsBlock .= Display::panel($invitationHtml, get_lang('InvitationReceived'));
  114. }
  115. if (count($list_get_invitation_sent) > 0) {
  116. $invitationSentHtml = '';
  117. foreach ($list_get_invitation_sent as $invitation) {
  118. $sender_user_id = $invitation['user_receiver_id'];
  119. $user_info = api_get_user_info($sender_user_id);
  120. $invitationSentHtml .= '<div id="id_'.$sender_user_id.'" class="well">';
  121. $title = Security::remove_XSS($invitation['title'], STUDENT, true);
  122. $content = Security::remove_XSS($invitation['content'], STUDENT, true);
  123. $date = api_convert_and_format_date($invitation['send_date'], DATE_TIME_FORMAT_LONG);
  124. $invitationSentHtml .= '<div class="row">';
  125. $invitationSentHtml .= '<div class="col-md-3">';
  126. $invitationSentHtml .= '<a href="profile.php?u='.$sender_user_id.'"><img src="'.$user_info['avatar'].'" /></a>';
  127. $invitationSentHtml .= '</div>';
  128. $invitationSentHtml .= '<div class="col-md-9">';
  129. $invitationSentHtml .= '<h4 class="title-profile"><a class="profile_link" href="profile.php?u='.$sender_user_id.'">'.$user_info['complete_name'].'</a></h4>';
  130. $invitationSentHtml .= '<div class="content-invitation">'.$title.' : '.$content.'</div>';
  131. $invitationSentHtml .= '<div class="date-invitation">'. get_lang('DateSend').' : '.$date.'</div>';
  132. $invitationSentHtml .= '</div>';
  133. $invitationSentHtml .= '</div></div>';
  134. }
  135. $socialInvitationsBlock .= Display::panel($invitationSentHtml, get_lang('InvitationSent'));
  136. }
  137. if (count($pending_invitations) > 0) {
  138. $new_invitation = array();
  139. $waitingInvitation = '';
  140. foreach ($pending_invitations as $invitation) {
  141. $picture = $userGroup->get_picture_group(
  142. $invitation['id'],
  143. $invitation['picture'],
  144. 80
  145. );
  146. $img = '<img class="social-groups-image" src="'.$picture['file'].'" />';
  147. $invitation['picture_uri'] = '<a href="group_view.php?id='.$invitation['id'].'">'.$img.'</a>';
  148. $invitation['name'] = '<a href="group_view.php?id='.$invitation['id'].'">'.cut($invitation['name'],120,true).'</a>';
  149. $invitation['description'] = cut($invitation['description'],220,true);
  150. $new_invitation[]=$invitation;
  151. $waitingInvitation .= '<div class="well"><div class="row">';
  152. $waitingInvitation .= '<div class="col-md-3">'.$invitation['picture_uri'].'</div>';
  153. $waitingInvitation .= '<div class="col-md-9">';
  154. $waitingInvitation .= '<h4 class="tittle-profile">'.$invitation['name'].'</h4>';
  155. $waitingInvitation .= '<div class="description-group">'.$invitation['description'].'</div>';
  156. $waitingInvitation .= '<div class="btn-group" role="group">';
  157. $waitingInvitation .= '<a class="btn btn-success" href="invitations.php?accept='.$invitation['id'].'"><i class="fa fa-check"></i> '.get_lang('AcceptInvitation').'</a>';
  158. $waitingInvitation .= '<a class="btn btn-danger" href="invitations.php?deny='.$invitation['id'].'"><i class="fa fa-times"></i> '.get_lang('DenyInvitation').'</a>';
  159. $waitingInvitation .='</div>';
  160. $waitingInvitation .= '</div></div>';
  161. }
  162. $socialInvitationsBlock .= Display::panel($waitingInvitation, get_lang('GroupsWaitingApproval'));
  163. }
  164. $tpl = new Template(null);
  165. SocialManager::setSocialUserBlock($tpl, $user_id, 'invitations');
  166. $tpl->assign('social_menu_block', $social_menu_block);
  167. $tpl->assign('social_invitations_block',$socialInvitationsBlock);
  168. $tpl->assign('message', $show_message);
  169. $tpl->assign('content', $content);
  170. $social_layout = $tpl->get_template('social/invitations.tpl');
  171. $tpl->display($social_layout);