invitations.php 8.6 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. /**
  8. * Initialization
  9. */
  10. $cidReset = true;
  11. api_block_anonymous_users();
  12. if (api_get_setting('allow_social_tool') != 'true') {
  13. api_not_allowed();
  14. return;
  15. }
  16. if (api_get_setting('allow_message_tool') != 'true') {
  17. api_not_allowed(true);
  18. return;
  19. }
  20. $usergroup = new UserGroup();
  21. $this_section = SECTION_SOCIAL;
  22. $interbreadcrumb[]= array ('url' =>'profile.php','name' => get_lang('SocialNetwork'));
  23. $interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Invitations'));
  24. $htmlHeadXtra[] = '
  25. <script>
  26. function denied_friend (element_input) {
  27. name_button=$(element_input).attr("id");
  28. name_div_id="id_"+name_button.substring(13);
  29. user_id=name_div_id.split("_");
  30. friend_user_id=user_id[1];
  31. $.ajax({
  32. contentType: "application/x-www-form-urlencoded",
  33. type: "POST",
  34. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=deny_friend",
  35. data: "denied_friend_id="+friend_user_id,
  36. success: function(datos) {
  37. $("div#"+name_div_id).hide("slow");
  38. $("#id_response").html(datos);
  39. }
  40. });
  41. }
  42. function register_friend(element_input) {
  43. if(confirm("'.get_lang('AddToFriends').'")) {
  44. name_button=$(element_input).attr("id");
  45. name_div_id="id_"+name_button.substring(13);
  46. user_id=name_div_id.split("_");
  47. user_friend_id=user_id[1];
  48. $.ajax({
  49. contentType: "application/x-www-form-urlencoded",
  50. type: "POST",
  51. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=add_friend",
  52. data: "friend_id="+user_friend_id+"&is_my_friend="+"friend",
  53. success: function(data) {
  54. $("div#"+name_div_id).hide("slow");
  55. $("#id_response").html(data);
  56. }
  57. });
  58. }
  59. }
  60. </script>';
  61. $show_message = null;
  62. $content = null;
  63. // easy links
  64. if (is_array($_GET) && count($_GET)>0) {
  65. foreach ($_GET as $key => $value) {
  66. switch ($key) {
  67. case 'accept':
  68. $user_role = $usergroup->get_user_group_role(api_get_user_id(), $value);
  69. if (in_array($user_role , array(GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER,GROUP_USER_PERMISSION_PENDING_INVITATION))) {
  70. $usergroup->update_user_role(api_get_user_id(), $value, GROUP_USER_PERMISSION_READER);
  71. $show_message = Display::return_message(get_lang('UserIsSubscribedToThisGroup'), 'success');
  72. } elseif (in_array($user_role , array(GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) {
  73. $show_message = Display::return_message(get_lang('UserIsAlreadySubscribedToThisGroup'), 'warning');
  74. } else {
  75. $show_message = Display::return_message(get_lang('UserIsNotSubscribedToThisGroup'), 'warning');
  76. }
  77. break 2;
  78. case 'deny':
  79. // delete invitation
  80. $usergroup->delete_user_rel_group(api_get_user_id(), $value);
  81. $show_message = Display::return_message(get_lang('GroupInvitationWasDeny'));
  82. break 2;
  83. }
  84. }
  85. }
  86. $social_left_content = SocialManager::show_social_menu('invitations');
  87. $social_right_content = '<div id="id_response" align="center"></div>';
  88. $user_id = api_get_user_id();
  89. $list_get_invitation = SocialManager::get_list_invitation_of_friends_by_user_id($user_id);
  90. $list_get_invitation_sent = SocialManager::get_list_invitation_sent_by_user_id($user_id);
  91. $pending_invitations = $usergroup->get_groups_by_user($user_id, GROUP_USER_PERMISSION_PENDING_INVITATION);
  92. $number_loop = count($list_get_invitation);
  93. $total_invitations = $number_loop + count($list_get_invitation_sent) + count($pending_invitations);
  94. if ($total_invitations == 0 && count($_GET) <= 0) {
  95. $social_right_content .= '<div class="span8"><a class="btn" href="search.php">'.get_lang('TryAndFindSomeFriends').'</a></div>';
  96. }
  97. if ($number_loop != 0) {
  98. $social_right_content .= '<div class="span8">'.Display::page_subheader(get_lang('InvitationReceived')).'</div>';
  99. foreach ($list_get_invitation as $invitation) {
  100. $sender_user_id = $invitation['user_sender_id'];
  101. $userInfo = api_get_user_info($sender_user_id);
  102. $social_right_content .= '<div id="id_'.$sender_user_id.'" class="invitation_confirm span8">';
  103. $picture = UserManager::get_user_picture_path_by_id($sender_user_id, 'web', false, true);
  104. $friends_profile = SocialManager::get_picture_user($sender_user_id, $picture['file'], 92);
  105. $title = Security::remove_XSS($invitation['title'], STUDENT, true);
  106. $content = Security::remove_XSS($invitation['content'], STUDENT, true);
  107. $date = api_convert_and_format_date($invitation['send_date'], DATE_TIME_FORMAT_LONG);
  108. $social_right_content .= '<div class="span2">
  109. <a class="thumbnail" href="'.$userInfo['profile_url'].'">
  110. <img src="'.$friends_profile['file'].'" /></a>
  111. </div>
  112. <div class="span3">
  113. <a href="'.$userInfo['profile_url'].'">'.$userInfo['complete_name'].'</a> :
  114. '.$content.'
  115. <div>
  116. '.get_lang('DateSend').' : '.$date.'
  117. </div>
  118. <div class="buttons">
  119. <button class="btn btn-primary" name="btn_accepted" type="submit" id="btn_accepted_'.$sender_user_id.'" value="'.get_lang('Accept').' "onclick="javascript:register_friend(this)">
  120. '.get_lang('Accept').'</button>
  121. <button class="btn btn-danger" name="btn_denied" type="submit" id="btn_deniedst_'.$sender_user_id.' " value="'.get_lang('Deny').' " onclick="javascript:denied_friend(this)" >
  122. '.get_lang('Deny').'</button>
  123. </div>
  124. </div>
  125. </div>';
  126. }
  127. }
  128. if (count($list_get_invitation_sent) > 0) {
  129. $social_right_content .= '<div class="span8">'.Display::page_subheader(get_lang('InvitationSent')).'</div>';
  130. foreach ($list_get_invitation_sent as $invitation) {
  131. $sender_user_id = $invitation['user_receiver_id'];
  132. $social_right_content .= '<div id="id_'.$sender_user_id.'" class="invitation_confirm span8">';
  133. $picture = UserManager::get_user_picture_path_by_id($sender_user_id, 'web', false, true);
  134. $friends_profile = SocialManager::get_picture_user($sender_user_id, $picture['file'], 92);
  135. $userInfo = api_get_user_info($sender_user_id);
  136. $title = Security::remove_XSS($invitation['title'], STUDENT, true);
  137. $content = Security::remove_XSS($invitation['content'], STUDENT, true);
  138. $date = api_convert_and_format_date($invitation['send_date'], DATE_TIME_FORMAT_LONG);
  139. $social_right_content .= '
  140. <div class="span2">
  141. <a class="thumbnail" href="'.$userInfo['profile_url'].'">
  142. <img src="'.$friends_profile['file'].'" /></a>
  143. </div>
  144. <div class="span3">
  145. <a class="profile_link" href="'.$userInfo['profile_url'].'">'.$userInfo['complete_name'].'</a>
  146. <div>'. $title.' : '.$content.'</div>
  147. <div>'. get_lang('DateSend').' : '.$date.'</div>
  148. </div>
  149. </div>';
  150. }
  151. }
  152. if (count($pending_invitations) > 0) {
  153. $social_right_content .= Display::page_subheader(get_lang('GroupsWaitingApproval'));
  154. $new_invitation = array();
  155. foreach ($pending_invitations as $invitation) {
  156. $picture = $usergroup->get_picture_group($invitation['id'], $invitation['picture'],80);
  157. $img = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="4" height="50" border="2" align="left" width="50" />';
  158. $invitation['picture'] = '<a href="groups.php?id='.$invitation['id'].'">'.$img.'</a>';
  159. $invitation['name'] = '<a href="groups.php?id='.$invitation['id'].'">'.Text::cut($invitation['name'],120,true).'</a>';
  160. $invitation['join'] = '<a class="btn btn-primary" href="invitations.php?accept='.$invitation['id'].'">'.get_lang('AcceptInvitation').'</a>';
  161. $invitation['deny'] = '<a class="btn btn-danger" href="invitations.php?deny='.$invitation['id'].'">'.get_lang('DenyInvitation').'</a>';
  162. $invitation['description'] = Text::cut($invitation['description'],220,true);
  163. $new_invitation[] = $invitation;
  164. }
  165. $social_right_content .= Display::return_sortable_grid('waiting_user', array(), $new_invitation, array('hide_navigation'=>true, 'per_page' => 100), array(), false, array(true, true, true,false,false,true,true,true,true));
  166. }
  167. $social_right_content = Display::div($social_right_content, array('class' => 'span9'));
  168. $tpl = $app['template'];
  169. $tpl->assign('content', $social_right_content);
  170. $tpl->assign('message', $show_message);