friends.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. *
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') != 'true') {
  12. api_not_allowed();
  13. }
  14. $this_section = SECTION_SOCIAL;
  15. $htmlHeadXtra[] = '<script>
  16. function delete_friend (element_div) {
  17. id_image = $(element_div).attr("id");
  18. user_id = id_image.split("_");
  19. if (confirm("'.get_lang('Delete', '').'")) {
  20. $.ajax({
  21. contentType: "application/x-www-form-urlencoded",
  22. type: "POST",
  23. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=delete_friend",
  24. data: "delete_friend_id="+user_id[1],
  25. success: function(datos) {
  26. $("#user_card_"+user_id[1]).hide("slow");
  27. }
  28. });
  29. }
  30. }
  31. function search_image_social() {
  32. var name_search = $("#id_search_image").val();
  33. $.ajax({
  34. contentType: "application/x-www-form-urlencoded",
  35. type: "POST",
  36. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=show_my_friends",
  37. data: "search_name_q="+name_search,
  38. success: function(data) {
  39. $("#friends").html(data);
  40. }
  41. });
  42. }
  43. function show_icon_delete(element_html) {
  44. elem_id=$(element_html).attr("id");
  45. id_elem=elem_id.split("_");
  46. ident="#img_"+id_elem[1];
  47. $(ident).attr("src","'.Display::returnIconPath('delete.png').'");
  48. $(ident).attr("alt","'.get_lang('Delete', '').'");
  49. $(ident).attr("title","'.get_lang('Delete', '').'");
  50. }
  51. function hide_icon_delete(element_html) {
  52. elem_id=$(element_html).attr("id");
  53. id_elem=elem_id.split("_");
  54. ident="#img_"+id_elem[1];
  55. $(ident).attr("src","'.Display::returnIconPath('blank.gif').'");
  56. $(ident).attr("alt","");
  57. $(ident).attr("title","");
  58. }
  59. </script>';
  60. $interbreadcrumb[] = ['url' => 'profile.php', 'name' => get_lang('SocialNetwork')];
  61. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Friends')];
  62. //Block Social Menu
  63. $social_menu_block = SocialManager::show_social_menu('friends');
  64. $user_id = api_get_user_id();
  65. $name_search = isset($_POST['search_name_q']) ? $_POST['search_name_q'] : null;
  66. $number_friends = 0;
  67. if (isset($name_search) && $name_search != 'undefined') {
  68. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND, $name_search);
  69. } else {
  70. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  71. }
  72. $social_right_content = '<div class="col-md-12">';
  73. if (count($friends) == 0) {
  74. $social_right_content .= Display::return_message(
  75. Display::tag('p', get_lang('NoFriendsInYourContactList')),
  76. 'warning',
  77. false
  78. );
  79. $social_right_content .= Display::toolbarButton(
  80. get_lang('TryAndFindSomeFriends'),
  81. 'search.php',
  82. 'search',
  83. 'success'
  84. );
  85. } else {
  86. $filterForm = new FormValidator('filter');
  87. $filterForm->addText(
  88. 'id_search_image',
  89. get_lang('Search'),
  90. false,
  91. [
  92. 'onkeyup' => 'search_image_social()',
  93. 'id' => 'id_search_image',
  94. ]
  95. );
  96. $social_right_content .= $filterForm->returnForm();
  97. $friend_html = '<div id="whoisonline">';
  98. $friend_html .= '<div class="row">';
  99. $number_friends = count($friends);
  100. $j = 0;
  101. for ($k = 0; $k < $number_friends; $k++) {
  102. while ($j < $number_friends) {
  103. if (isset($friends[$j])) {
  104. $friend = $friends[$j];
  105. $toolBar = '<button class="btn btn-danger" onclick="delete_friend(this)" id=img_'.$friend['friend_user_id'].'>
  106. '.get_lang('Delete').'
  107. </button>';
  108. $url = api_get_path(WEB_PATH).'main/social/profile.php?u='.$friend['friend_user_id'];
  109. $friend['user_info']['complete_name'] = Display::url($friend['user_info']['complete_name'], $url);
  110. $friend_html .= Display::getUserCard($friend['user_info'], '', $toolBar);
  111. }
  112. $j++;
  113. }
  114. }
  115. $friend_html .= '</div>';
  116. $friend_html .= '</div>';
  117. $social_right_content .= $friend_html;
  118. }
  119. $social_right_content .= '</div>';
  120. $tpl = new Template(get_lang('Social'));
  121. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'friends');
  122. $tpl->assign('social_menu_block', $social_menu_block);
  123. $tpl->assign('social_right_content', $social_right_content);
  124. $social_layout = $tpl->get_template('social/friends.tpl');
  125. $tpl->display($social_layout);