social.ajax.php 8.9 KB

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