invitations.php 9.2 KB

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