friends.php 4.3 KB

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