social.ajax.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once '../global.inc.php';
  7. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  8. $action = $_GET['a'];
  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 = Security::remove_XSS($_POST['friend_id']);
  17. $my_denied_current_friend= Security::remove_XSS($_POST['denied_friend_id']);
  18. $my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']);
  19. $friend_id_qualify = Security::remove_XSS($_POST['user_id_friend_q']);
  20. $type_friend_qualify = Security::remove_XSS($_POST['type_friend_q']); //filtered?
  21. $is_my_friend = Security::remove_XSS($_POST['is_my_friend']); //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. if (isset($_POST['is_my_friend'])) {
  32. echo api_xml_http_response_encode(get_lang('AddedContactToList'));
  33. } else {
  34. Display::display_normal_message(api_xml_http_response_encode(get_lang('AddedContactToList')));
  35. }
  36. }
  37. case 'deny_friend':
  38. if (api_is_anonymous()){
  39. echo '';
  40. break;
  41. }
  42. $my_current_friend = Security::remove_XSS($_POST['friend_id']);
  43. $my_denied_current_friend= Security::remove_XSS($_POST['denied_friend_id']);
  44. $my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']);
  45. $friend_id_qualify = Security::remove_XSS($_POST['user_id_friend_q']);
  46. $type_friend_qualify = Security::remove_XSS($_POST['type_friend_q']); //filtered?
  47. $is_my_friend = Security::remove_XSS($_POST['is_my_friend']); //filtered?
  48. if (isset($_POST['is_my_friend'])) {
  49. $relation_type=USER_RELATION_TYPE_FRIEND;//my friend
  50. } else {
  51. $relation_type=USER_RELATION_TYPE_UNKNOW;//Contact unknown
  52. }
  53. if (isset($_POST['denied_friend_id'])) {
  54. SocialManager::invitation_denied($my_denied_current_friend,$current_user_id);
  55. Display::display_confirmation_message(api_xml_http_response_encode(get_lang('InvitationDenied')));
  56. }
  57. break;
  58. case 'delete_friend':
  59. if (api_is_anonymous()){
  60. echo '';
  61. break;
  62. }
  63. //deprecated variables?
  64. //$my_current_friend = Security::remove_XSS($_POST['friend_id']);
  65. //$my_denied_current_friend= Security::remove_XSS($_POST['denied_friend_id']);
  66. $my_delete_friend = Security::remove_XSS($_POST['delete_friend_id']);
  67. //$friend_id_qualify = Security::remove_XSS($_POST['user_id_friend_q']);
  68. //$type_friend_qualify = Security::remove_XSS($_POST['type_friend_q']); //filtered?
  69. //$is_my_friend = Security::remove_XSS($_POST['is_my_friend']); //filtered?
  70. if (isset($_POST['delete_friend_id'])) {
  71. SocialManager::remove_user_rel_user($my_delete_friend);
  72. }
  73. /*
  74. if(isset($_POST['user_id_friend_q']) && isset($_POST['type_friend_q'])) {
  75. SocialManager::qualify_friend($friend_id_qualify,$type_friend_qualify);
  76. echo api_xml_http_response_encode(get_lang('AttachContactsToGroupSuccesfuly'));
  77. }*/
  78. break;
  79. case 'show_my_friends':
  80. if (api_is_anonymous()) {
  81. echo '';
  82. break;
  83. }
  84. $list_path_friends = array();
  85. $user_id = api_get_user_id();
  86. $name_search= Security::remove_XSS($_POST['search_name_q']);
  87. $number_friends = 0;
  88. if (isset($name_search) && $name_search!='undefined') {
  89. $friends = SocialManager::get_friends($user_id,null,$name_search);
  90. } else {
  91. $friends = SocialManager::get_friends($user_id);
  92. }
  93. $friend_html = '';
  94. $number_of_images = 8;
  95. $number_friends = count($friends);
  96. if ($number_friends != 0) {
  97. $number_loop = ($number_friends/$number_of_images);
  98. $loop_friends = ceil($number_loop);
  99. $j=0;
  100. $friend_html.= '<br /><table width="100%" border="0" cellpadding="0" cellspacing="0" >';
  101. for ($k=0;$k<$loop_friends;$k++) {
  102. $friend_html.='<tr><td valign="top">';
  103. if ($j==$number_of_images) {
  104. $number_of_images=$number_of_images*2;
  105. }
  106. while ($j<$number_of_images) {
  107. if (isset($friends[$j])) {
  108. $friend = $friends[$j];
  109. $user_name = api_xml_http_response_encode($friend['firstName'].' '.$friend['lastName']);
  110. $friends_profile = SocialManager::get_picture_user($friend['friend_user_id'], $friend['image'], 92);
  111. $friend_html.='<div onMouseover="show_icon_delete(this)" onMouseout="hide_icon_delete(this)" class="image-social-content" id=div_'.$friends[$j]['friend_user_id'].'>';
  112. $friend_html.='<span><a href="profile.php?u='.$friend['friend_user_id'].'"><center><img src="'.$friends_profile['file'].'" style="width:60px;height:60px;border:3pt solid #eee" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$user_name.'" /></center></a></span>';
  113. $friend_html.='<img onclick="delete_friend (this)" id=img_'.$friend['friend_user_id'].' src="../img/blank.gif" alt="" title="" class="image-delete" /> <center class="friend">'.$user_name.'</center></div>';
  114. }
  115. $j++;
  116. }
  117. $friend_html.='</td></tr>';
  118. }
  119. $friend_html.='<br/></table>';
  120. }
  121. echo $friend_html;
  122. break;
  123. case 'toogle_course':
  124. if (api_is_anonymous()){
  125. echo '';
  126. break;
  127. }
  128. require_once api_get_path(LIBRARY_PATH).'blog.lib.php';
  129. require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
  130. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  131. $user_id = intval($_SESSION['social_user_id']);
  132. if ($_POST['action']) {$action = $_POST['action'];}
  133. switch($action) {
  134. case 'load_course' :
  135. $course_db = $_POST['course_code'];
  136. // @todo goto the course link
  137. //echo '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.get_lang('GotoCourse').'</a>';
  138. $course_id=CourseManager::get_course_id_by_database_name($course_db);
  139. if (api_is_user_of_course($course_id,api_get_user_id())) {
  140. $table_forums = Database :: get_course_table(TABLE_FORUM,$course_db);
  141. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD,$course_db);
  142. $table_posts = Database :: get_course_table(TABLE_FORUM_POST,$course_db);
  143. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_db);
  144. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  145. //------Forum messages
  146. $forum_result = get_all_post_from_user($user_id, $course_db);
  147. $all_result_data = 0;
  148. if ($forum_result !='') {
  149. echo '<div id="social-forum-main-title">';
  150. echo api_xml_http_response_encode(get_lang('Forum'));
  151. echo '</div>';
  152. echo '<div style="background:#FAF9F6; padding:0px;" >';
  153. echo api_xml_http_response_encode($forum_result);
  154. echo '</div>';
  155. echo '<br />';
  156. $all_result_data++;
  157. }
  158. //------Blog posts
  159. $result = get_blog_post_from_user($course_db, $user_id);
  160. if (!empty($result)) {
  161. api_display_tool_title(api_xml_http_response_encode(get_lang('Blog')));
  162. echo '<div style="background:#FAF9F6; padding:0px;">';
  163. echo api_xml_http_response_encode($result);
  164. echo '</div>';
  165. echo '<br />';
  166. $all_result_data++;
  167. }
  168. //------Blog comments
  169. $result = get_blog_comment_from_user($course_db, $user_id);
  170. if (!empty($result)) {
  171. echo '<div style="background:#FAF9F6; padding-left:10px;">';
  172. api_display_tool_title(api_xml_http_response_encode(get_lang('BlogComments')));
  173. echo api_xml_http_response_encode($result);
  174. echo '</div>';
  175. echo '<br />';
  176. $all_result_data++;
  177. }
  178. if ($all_result_data == 0) {
  179. echo api_xml_http_response_encode(get_lang('NoDataAvailable'));
  180. }
  181. } else {
  182. echo '<div class="clear"></div><br />';
  183. api_display_tool_title(api_xml_http_response_encode(get_lang('Details')));
  184. echo '<div style="background:#FAF9F6; padding:0px;">';
  185. echo api_xml_http_response_encode(get_lang('UserNonRegisteredAtTheCourse'));
  186. echo '<div class="clear"></div><br />';
  187. echo '</div>';
  188. echo '<div class="clear"></div><br />';
  189. }
  190. break;
  191. case 'unload_course' :
  192. //echo 'load2';
  193. break;
  194. default:
  195. break;
  196. }
  197. break;
  198. default:
  199. echo '';
  200. }
  201. exit;