social.ajax.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. $language_file = array('messages','userInfo');
  7. require_once '../global.inc.php';
  8. $action = isset($_GET['a']) ? $_GET['a'] : null;
  9. $current_user_id = api_get_user_id();
  10. switch ($action) {
  11. case 'add_friend':
  12. if (api_is_anonymous()) {
  13. echo '';
  14. break;
  15. }
  16. $my_current_friend = isset($_POST['friend_id']) ? Security::remove_XSS($_POST['friend_id']) : null;
  17. $my_denied_current_friend= isset($_POST['denied_friend_id']) ? Security::remove_XSS($_POST['denied_friend_id']) : null;
  18. $my_delete_friend = isset($_POST['delete_friend_id']) ? Security::remove_XSS($_POST['delete_friend_id']) : null;
  19. $friend_id_qualify = isset($_POST['user_id_friend_q']) ? Security::remove_XSS($_POST['user_id_friend_q']) : null;
  20. $type_friend_qualify = isset($_POST['type_friend_q']) ? Security::remove_XSS($_POST['type_friend_q']) : null; //filtered?
  21. $is_my_friend = isset($_POST['is_my_friend']) ? Security::remove_XSS($_POST['is_my_friend']) : null; //filtered?
  22. if (isset($_POST['is_my_friend'])) {
  23. $relation_type = USER_RELATION_TYPE_FRIEND; //My friend
  24. } else {
  25. $relation_type = USER_RELATION_TYPE_UNKNOW; //Unknown contact
  26. }
  27. if (isset($_POST['friend_id'])) {
  28. UserManager::relate_users($current_user_id,$my_current_friend,$relation_type);
  29. UserManager::relate_users($my_current_friend,$current_user_id,$relation_type);
  30. SocialManager::invitation_accepted($my_current_friend,$current_user_id);
  31. Display::display_normal_message(api_xml_http_response_encode(get_lang('AddedContactToList')));
  32. }
  33. break;
  34. case 'deny_friend':
  35. if (api_is_anonymous()){
  36. echo '';
  37. break;
  38. }
  39. $my_current_friend = Security::remove_XSS($_POST['friend_id']);
  40. $my_denied_current_friend= Security::remove_XSS($_POST['denied_friend_id']);
  41. $my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']);
  42. $friend_id_qualify = Security::remove_XSS($_POST['user_id_friend_q']);
  43. $type_friend_qualify = Security::remove_XSS($_POST['type_friend_q']); //filtered?
  44. $is_my_friend = Security::remove_XSS($_POST['is_my_friend']); //filtered?
  45. if (isset($_POST['is_my_friend'])) {
  46. $relation_type=USER_RELATION_TYPE_FRIEND;//my friend
  47. } else {
  48. $relation_type=USER_RELATION_TYPE_UNKNOW;//Contact unknown
  49. }
  50. if (isset($_POST['denied_friend_id'])) {
  51. SocialManager::invitation_denied($my_denied_current_friend,$current_user_id);
  52. Display::display_confirmation_message(api_xml_http_response_encode(get_lang('InvitationDenied')));
  53. }
  54. break;
  55. case 'delete_friend':
  56. if (api_is_anonymous()) {
  57. echo '';
  58. break;
  59. }
  60. $my_delete_friend = intval($_POST['delete_friend_id']);
  61. if (isset($_POST['delete_friend_id'])) {
  62. SocialManager::remove_user_rel_user($my_delete_friend);
  63. }
  64. break;
  65. case 'show_my_friends':
  66. if (api_is_anonymous()) {
  67. echo '';
  68. break;
  69. }
  70. $user_id = api_get_user_id();
  71. $name_search= Security::remove_XSS($_POST['search_name_q']);
  72. $number_friends = 0;
  73. if (isset($name_search) && $name_search != 'undefined') {
  74. $friends = SocialManager::get_friends($user_id, null, $name_search);
  75. } else {
  76. $friends = SocialManager::get_friends($user_id);
  77. }
  78. $friend_html = '';
  79. $number_of_images = 8;
  80. $number_friends = count($friends);
  81. if ($number_friends != 0) {
  82. $number_loop = ($number_friends/$number_of_images);
  83. $loop_friends = ceil($number_loop);
  84. $j=0;
  85. $friend_html.= '<ul class="thumbnails">';
  86. for ($k=0;$k<$loop_friends;$k++) {
  87. if ($j==$number_of_images) {
  88. $number_of_images=$number_of_images*2;
  89. }
  90. while ($j<$number_of_images) {
  91. if (isset($friends[$j])) {
  92. $friend_html.='<li class="span2">';
  93. $friend = $friends[$j];
  94. $user_name = api_xml_http_response_encode($friend['firstName'].' '.$friend['lastName']);
  95. $friends_profile = SocialManager::get_picture_user($friend['friend_user_id'], $friend['image'], 92);
  96. $friend_html.='<div class="thumbnail" onMouseover="show_icon_delete(this)" onMouseout="hide_icon_delete(this)" class="image-social-content" id=div_'.$friends[$j]['friend_user_id'].'>';
  97. $friend_html.='<img src="'.$friends_profile['file'].'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$user_name.'" />';
  98. $friend_html.='<div class="caption">';
  99. $friend_html.='<a href="profile.php?u='.$friend['friend_user_id'].'"><h5>'.$user_name.'</h5></a>';
  100. $friend_html.='<p><button class="btn" onclick="delete_friend(this)" id=img_'.$friend['friend_user_id'].'>'.get_lang('Delete').'</button></p>';
  101. $friend_html.='</div>';
  102. $friend_html.='</div>';
  103. $friend_html.='</li>';
  104. }
  105. $j++;
  106. }
  107. }
  108. $friend_html.='</ul>';
  109. }
  110. echo $friend_html;
  111. break;
  112. case 'toogle_course':
  113. if (api_is_anonymous()){
  114. echo '';
  115. break;
  116. }
  117. require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
  118. $user_id = intval($_SESSION['social_user_id']);
  119. if ($_POST['action']) {$action = $_POST['action'];}
  120. switch ($action) {
  121. case 'load_course' :
  122. $course_id = intval($_POST['course_code']); // the int course id
  123. $course_info = api_get_course_info_by_id($course_id);
  124. $course_code = $course_info['code'];
  125. if (api_is_user_of_course($course_info['real_id'], api_get_user_id())) {
  126. //------Forum messages
  127. $forum_result = get_all_post_from_user($user_id, $course_code);
  128. $all_result_data = 0;
  129. if ($forum_result !='') {
  130. echo '<div id="social-forum-main-title">';
  131. echo api_xml_http_response_encode(get_lang('Forum'));
  132. echo '</div>';
  133. echo '<div style="background:#FAF9F6; padding:0px;" >';
  134. echo api_xml_http_response_encode($forum_result);
  135. echo '</div>';
  136. echo '<br />';
  137. $all_result_data++;
  138. }
  139. //------Blog posts
  140. $result = get_blog_post_from_user($course_code, $user_id);
  141. if (!empty($result)) {
  142. api_display_tool_title(api_xml_http_response_encode(get_lang('Blog')));
  143. echo '<div style="background:#FAF9F6; padding:0px;">';
  144. echo api_xml_http_response_encode($result);
  145. echo '</div>';
  146. echo '<br />';
  147. $all_result_data++;
  148. }
  149. //------Blog comments
  150. $result = get_blog_comment_from_user($course_code, $user_id);
  151. if (!empty($result)) {
  152. echo '<div style="background:#FAF9F6; padding-left:10px;">';
  153. api_display_tool_title(api_xml_http_response_encode(get_lang('BlogComments')));
  154. echo api_xml_http_response_encode($result);
  155. echo '</div>';
  156. echo '<br />';
  157. $all_result_data++;
  158. }
  159. if ($all_result_data == 0) {
  160. echo api_xml_http_response_encode(get_lang('NoDataAvailable'));
  161. }
  162. } else {
  163. echo '<div class="clear"></div><br />';
  164. api_display_tool_title(api_xml_http_response_encode(get_lang('Details')));
  165. echo '<div style="background:#FAF9F6; padding:0px;">';
  166. echo api_xml_http_response_encode(get_lang('UserNonRegisteredAtTheCourse'));
  167. echo '<div class="clear"></div><br />';
  168. echo '</div>';
  169. echo '<div class="clear"></div><br />';
  170. }
  171. break;
  172. case 'unload_course' :
  173. //echo 'load2';
  174. break;
  175. default:
  176. break;
  177. }
  178. break;
  179. default:
  180. echo '';
  181. }
  182. exit;