friends.php 4.3 KB

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