social.ajax.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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($_GET['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($_GET['friend_id'])) {
  21. $my_current_friend = $_GET['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. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php');
  27. }
  28. break;
  29. case 'deny_friend':
  30. if (api_is_anonymous()) {
  31. echo '';
  32. break;
  33. }
  34. if (isset($_GET['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($_GET['denied_friend_id'])) {
  40. SocialManager::invitation_denied($_GET['denied_friend_id'], $current_user_id);
  41. Display::display_confirmation_message(api_xml_http_response_encode(get_lang('InvitationDenied')));
  42. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php');
  43. }
  44. break;
  45. case 'delete_friend':
  46. if (api_is_anonymous()) {
  47. echo '';
  48. break;
  49. }
  50. $my_delete_friend = intval($_POST['delete_friend_id']);
  51. if (isset($_POST['delete_friend_id'])) {
  52. SocialManager::remove_user_rel_user($my_delete_friend);
  53. }
  54. break;
  55. case 'show_my_friends':
  56. if (api_is_anonymous()) {
  57. echo '';
  58. break;
  59. }
  60. $user_id = api_get_user_id();
  61. $name_search= Security::remove_XSS($_POST['search_name_q']);
  62. $number_friends = 0;
  63. if (isset($name_search) && $name_search != 'undefined') {
  64. $friends = SocialManager::get_friends($user_id, null, $name_search);
  65. } else {
  66. $friends = SocialManager::get_friends($user_id);
  67. }
  68. $friend_html = '';
  69. $number_of_images = 8;
  70. $number_friends = count($friends);
  71. if ($number_friends != 0) {
  72. $number_loop = ($number_friends/$number_of_images);
  73. $loop_friends = ceil($number_loop);
  74. $j=0;
  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 = $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 .= '
  85. <div class="col-md-3">
  86. <div class="thumbnail text-center" id="div_' . $friends[$j]['friend_user_id'] . '">
  87. <img src="' . $userPicture . '" class="img-responsive" id="imgfriend_' . $friend['friend_user_id'] . '" title="$user_name">
  88. <div class="caption">
  89. <h3>
  90. <a href="profile.php?u=' . $friend['friend_user_id'] . '">' . $user_name . '</a>
  91. </h3>
  92. <p>
  93. <button class="btn btn-danger" onclick="delete_friend(this)" id=img_' . $friend['friend_user_id'] . '>
  94. ' . get_lang('Delete') . '
  95. </button>
  96. </p>
  97. </div>
  98. </div>
  99. </div>
  100. ';
  101. }
  102. $j++;
  103. }
  104. }
  105. }
  106. echo $friend_html;
  107. break;
  108. case 'toogle_course':
  109. if (api_is_anonymous()) {
  110. echo '';
  111. break;
  112. }
  113. require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
  114. $user_id = intval($_SESSION['social_user_id']);
  115. if ($_POST['action']) {
  116. $action = $_POST['action'];
  117. }
  118. switch ($action) {
  119. case 'load_course':
  120. $course_id = intval($_POST['course_code']); // the int course id
  121. $course_info = api_get_course_info_by_id($course_id);
  122. $course_code = $course_info['code'];
  123. if (api_is_user_of_course($course_id, api_get_user_id())) {
  124. //------Forum messages
  125. $forum_result = get_all_post_from_user($user_id, $course_code);
  126. $all_result_data = 0;
  127. if ($forum_result !='') {
  128. echo '<div id="social-forum-main-title">';
  129. echo api_xml_http_response_encode(get_lang('Forum'));
  130. echo '</div>';
  131. echo '<div style="background:#FAF9F6; padding:0px;" >';
  132. echo api_xml_http_response_encode($forum_result);
  133. echo '</div>';
  134. echo '<br />';
  135. $all_result_data++;
  136. }
  137. //------Blog posts
  138. $result = Blog::getBlogPostFromUser($course_id, $user_id, $course_code );
  139. if (!empty($result)) {
  140. api_display_tool_title(api_xml_http_response_encode(get_lang('Blog')));
  141. echo '<div style="background:#FAF9F6; padding:0px;">';
  142. echo api_xml_http_response_encode($result);
  143. echo '</div>';
  144. echo '<br />';
  145. $all_result_data++;
  146. }
  147. //------Blog comments
  148. $result = Blog::getBlogCommentsFromUser($course_id, $user_id, $course_code);
  149. if (!empty($result)) {
  150. echo '<div style="background:#FAF9F6; padding-left:10px;">';
  151. api_display_tool_title(api_xml_http_response_encode(get_lang('BlogComments')));
  152. echo api_xml_http_response_encode($result);
  153. echo '</div>';
  154. echo '<br />';
  155. $all_result_data++;
  156. }
  157. if ($all_result_data == 0) {
  158. echo api_xml_http_response_encode(get_lang('NoDataAvailable'));
  159. }
  160. } else {
  161. echo '<div class="clear"></div><br />';
  162. api_display_tool_title(api_xml_http_response_encode(get_lang('Details')));
  163. echo '<div style="background:#FAF9F6; padding:0px;">';
  164. echo api_xml_http_response_encode(get_lang('UserNonRegisteredAtTheCourse'));
  165. echo '<div class="clear"></div><br />';
  166. echo '</div>';
  167. echo '<div class="clear"></div><br />';
  168. }
  169. break;
  170. case 'unload_course':
  171. break;
  172. default:
  173. break;
  174. }
  175. break;
  176. case 'listWallMessage':
  177. $start = isset($_REQUEST['start']) ? intval($_REQUEST['start']) - 1 : 0;
  178. $length = isset($_REQUEST['length']) ? intval($_REQUEST['length']) : 10;
  179. $userId = isset($_REQUEST['u']) ? intval($_REQUEST['u']) : api_get_user_id();
  180. $friendId = $userId;
  181. $array = SocialManager::getWallMessagesPostHTML($userId, $friendId, null, $length, $start);
  182. if (!empty($array)) {
  183. ksort($array);
  184. $html = '';
  185. for($i = 0; $i < count($array); $i++) {
  186. $post = $array[$i]['html'];
  187. $comment = SocialManager::getWallMessagesHTML($userId, $friendId, $array[$i]['id']);
  188. $html .= '<div class="panel panel-info"><div class="panel-body">'.$post.$comment.'</div></div>';
  189. }
  190. $html .= Display::div(
  191. Display::url(
  192. get_lang('SeeMore'),
  193. api_get_self() . '?u=' . $userId . '&a=listWallMessage&start=' .
  194. ($start + $length + 1) . '&length=' . $length,
  195. array(
  196. 'class' => 'nextPage',
  197. )
  198. ),
  199. array(
  200. 'class' => 'next',
  201. )
  202. );
  203. echo $html;
  204. }
  205. break;
  206. // Read the Url using OpenGraph and returns the hyperlinks content
  207. case 'readUrlWithOpenGraph':
  208. $url = isset($_POST['social_wall_new_msg_main']) ? $_POST['social_wall_new_msg_main'] : '';
  209. $html = '';
  210. if (SocialManager::verifyUrl($url) == true){
  211. $html = Security::remove_XSS(
  212. SocialManager::readContentWithOpenGraph($url)
  213. );
  214. }
  215. echo utf8_decode($html);
  216. break;
  217. default:
  218. echo '';
  219. }
  220. exit;