social.ajax.php 9.0 KB

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