friends.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 '../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. $("div#"+"div_"+user_id[1]).hide("slow");
  26. $("div#"+"div_"+user_id[1]).html("");
  27. clear_form ();
  28. }
  29. });
  30. }
  31. }
  32. function search_image_social() {
  33. var name_search = $("#id_search_image").val();
  34. $.ajax({
  35. contentType: "application/x-www-form-urlencoded",
  36. type: "POST",
  37. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=show_my_friends",
  38. data: "search_name_q="+name_search,
  39. success: function(data) {
  40. $("#friends").html(data);
  41. }
  42. });
  43. }
  44. function show_icon_delete(element_html) {
  45. elem_id=$(element_html).attr("id");
  46. id_elem=elem_id.split("_");
  47. ident="#img_"+id_elem[1];
  48. $(ident).attr("src","'.Display::returnIconPath('delete.png').'");
  49. $(ident).attr("alt","'.get_lang('Delete', '').'");
  50. $(ident).attr("title","'.get_lang('Delete', '').'");
  51. }
  52. function hide_icon_delete(element_html) {
  53. elem_id=$(element_html).attr("id");
  54. id_elem=elem_id.split("_");
  55. ident="#img_"+id_elem[1];
  56. $(ident).attr("src","'.Display::returnIconPath('blank.gif').'");
  57. $(ident).attr("alt","");
  58. $(ident).attr("title","");
  59. }
  60. function clear_form () {
  61. $("input[@type=radio]").attr("checked", false);
  62. $("div#div_qualify_image").html("");
  63. $("div#div_info_user").html("");
  64. }
  65. </script>';
  66. $interbreadcrumb[] = array('url' => 'profile.php', 'name' => get_lang('SocialNetwork'));
  67. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Friends'));
  68. //Block Social Menu
  69. $social_menu_block = SocialManager::show_social_menu('friends');
  70. $user_id = api_get_user_id();
  71. $name_search = isset($_POST['search_name_q']) ? $_POST['search_name_q'] : null;
  72. $number_friends = 0;
  73. if (isset($name_search) && $name_search != 'undefined') {
  74. $friends = SocialManager::get_friends($user_id, null, $name_search);
  75. } else {
  76. $friends = SocialManager::get_friends($user_id);
  77. }
  78. $social_right_content = '<div class="col-md-12">';
  79. if (count($friends) == 0) {
  80. $social_right_content .= Display::return_message(
  81. Display::tag('p', get_lang('NoFriendsInYourContactList')),
  82. 'warning',
  83. false
  84. );
  85. $social_right_content .= Display::toolbarButton(
  86. get_lang('TryAndFindSomeFriends'),
  87. 'search.php',
  88. 'search',
  89. 'success'
  90. );
  91. } else {
  92. $filterForm = new FormValidator('filter');
  93. $filterForm->addText(
  94. 'id_search_image',
  95. get_lang('Search'),
  96. false,
  97. [
  98. 'onkeyup' => 'search_image_social()',
  99. 'id' => 'id_search_image'
  100. ]
  101. );
  102. $social_right_content .= $filterForm->returnForm();
  103. $friend_html = '<div id="friends" class="row">';
  104. $number_friends = count($friends);
  105. $j = 0;
  106. for ($k = 0; $k < $number_friends; $k++) {
  107. while ($j < $number_friends) {
  108. if (isset($friends[$j])) {
  109. $friend = $friends[$j];
  110. $user_name = api_xml_http_response_encode($friend['firstName'].' '.$friend['lastName']);
  111. $userPicture = UserManager::getUserPicture($friend['friend_user_id']);
  112. $friend_html .= '
  113. <div class="col-md-3">
  114. <div class="thumbnail text-center" id="div_' . $friends[$j]['friend_user_id'] . '">
  115. <img src="' . $userPicture . '" class="img-responsive" id="imgfriend_' . $friend['friend_user_id'] . '" title="'.$user_name.'">
  116. <div class="caption">
  117. <h3>
  118. <a href="profile.php?u=' . $friend['friend_user_id'] . '">' . $user_name . '</a>
  119. </h3>
  120. <p>
  121. <button class="btn btn-danger" onclick="delete_friend(this)" id=img_' . $friend['friend_user_id'] . '>
  122. ' . get_lang('Delete') . '
  123. </button>
  124. </p>
  125. </div>
  126. </div>
  127. </div>
  128. ';
  129. }
  130. $j++;
  131. }
  132. }
  133. $friend_html .= '</div>';
  134. $social_right_content .= $friend_html;
  135. }
  136. $social_right_content .= '</div>';
  137. $tpl = new Template(get_lang('Social'));
  138. SocialManager::setSocialUserBlock($tpl, $user_id, 'friends');
  139. $tpl->assign('social_menu_block', $social_menu_block);
  140. $tpl->assign('social_right_content', $social_right_content);
  141. $social_layout = $tpl->get_template('social/friends.tpl');
  142. $tpl->display($social_layout);