profile_friends_and_groups.inc.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Helper file for friends and groups profiles
  5. * @package chamilo.social
  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. $views = array('friends', 'mygroups');
  15. $user_id = intval($_GET['user_id']);
  16. $userGroup = new UserGroup();
  17. if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
  18. // show all friends by user_id
  19. if ($_GET['view'] == 'friends') {
  20. echo '<div style="margin-top:20px;">';
  21. $list_path_friends = $list_path_normal_friends = $list_path_parents = array();
  22. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, SOCIALPARENT
  23. $friends = SocialManager::get_friends(
  24. $user_id,
  25. USER_RELATION_TYPE_FRIEND
  26. );
  27. $number_friends = count($friends);
  28. $friend_html = '';
  29. $friend_html .= '<div><h3>'.get_lang('SocialFriend').'</h3></div>';
  30. $friend_html .= '<div id="friend-container" class="social-friend-container">';
  31. $friend_html .= '<div id="friend-header" >';
  32. if ($number_friends == 1) {
  33. $friend_html .= '<div style="float:left;width:80%">'.$number_friends.' '.get_lang('Friend').'</div>';
  34. } else {
  35. $friend_html .= '<div style="float:left;width:80%">'.$number_friends.' '.get_lang('Friends').'</div>';
  36. }
  37. $friend_html .= '</div>'; // close div friend-header
  38. for ($k = 0; $k < $number_friends; $k++) {
  39. if (isset($friends[$k])) {
  40. $friend = $friends[$k];
  41. $name_user = api_get_person_name(
  42. $friend['firstName'],
  43. $friend['lastName']
  44. );
  45. $friend_html .= '<div id=div_'.$friend['friend_user_id'].' class="image_friend_network" ><span><center>';
  46. $userPicture = UserManager::getUserPicture($friend['friend_user_id']);
  47. $friend_html .= '<a href="profile.php?u='.$friend['friend_user_id'].'">';
  48. $friend_html .= '<img src="'.$userPicture.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" />';
  49. $friend_html .= '</center></span>';
  50. $friend_html .= '<center class="friend">'.$name_user.'</a></center>';
  51. $friend_html .= '</div>';
  52. }
  53. }
  54. echo $friend_html;
  55. echo '</div>';
  56. } else {
  57. // show all groups by user_id
  58. // MY GROUPS
  59. $results = $userGroup->get_groups_by_user($user_id, 0);
  60. $grid_my_groups = array();
  61. if (is_array($results) && count($results) > 0) {
  62. $i = 1;
  63. foreach ($results as $result) {
  64. $id = $result['id'];
  65. $url_open = '<a href="group_view.php?id='.$id.'">';
  66. $url_close = '</a>';
  67. $icon = '';
  68. $name = cut($result['name'], 20, true);
  69. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  70. $icon = Display::return_icon(
  71. 'social_group_admin.png',
  72. get_lang('Admin'),
  73. array('style' => 'vertical-align:middle;width:16px;height:16px;')
  74. );
  75. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  76. $icon = Display::return_icon(
  77. 'social_group_moderator.png',
  78. get_lang('Moderator'),
  79. array('style' => 'vertical-align:middle;width:16px;height:16px;')
  80. );
  81. }
  82. $count_users_group = count(
  83. $userGroup->get_all_users_by_group($id)
  84. );
  85. if ($count_users_group == 1) {
  86. $count_users_group = $count_users_group.' '.get_lang(
  87. 'Member'
  88. );
  89. } else {
  90. $count_users_group = $count_users_group.' '.get_lang(
  91. 'Members'
  92. );
  93. }
  94. $picture = $userGroup->get_picture_group(
  95. $result['id'],
  96. $result['picture_uri'],
  97. 80
  98. );
  99. $item_name = '<div class="box_shared_profile_group_title">'.$url_open.api_xml_http_response_encode($name).$icon.$url_close.'</div>';
  100. $item_description = '';
  101. if (!empty($result['description'])) {
  102. $item_description = '<div class="box_shared_profile_group_description">
  103. <span class="social-groups-text2">' .
  104. api_xml_http_response_encode(get_lang('Description')).'</span><p class="social-groups-text4">'.
  105. cut(api_xml_http_response_encode($result['description']), 120, true).'</p></div>';
  106. }
  107. $result['picture_uri'] = '<div class="box_shared_profile_group_image">
  108. <img class="social-groups-image" src="' . $picture['file'].'" /></div>';
  109. $item_actions = '';
  110. if (api_get_user_id() == $user_id) {
  111. $item_actions = '<div class="box_shared_profile_group_actions"><a href="group_view.php?id='.$id.'">'.
  112. get_lang('SeeMore').$url_close.'</div>';
  113. }
  114. $grid_my_groups[] = array(
  115. $item_name,
  116. $url_open.$result['picture_uri'].$url_close,
  117. $item_description.$item_actions
  118. );
  119. $i++;
  120. }
  121. }
  122. if (count($grid_my_groups) > 0) {
  123. echo '<div style="margin-top:20px">';
  124. echo '<div><h3>'.get_lang('MyGroups').'</h3></div>';
  125. $count_groups = 0;
  126. if (count($results) == 1) {
  127. $count_groups = count($results).' '.get_lang('Group');
  128. } else {
  129. $count_groups = count($results).' '.get_lang('Groups');
  130. }
  131. echo '<div>'.$count_groups.'</div>';
  132. Display::display_sortable_grid(
  133. 'shared_profile_mygroups',
  134. array(),
  135. $grid_my_groups,
  136. array('hide_navigation' => true, 'per_page' => 2),
  137. $query_vars,
  138. false,
  139. array(true, true, true, false)
  140. );
  141. echo '</div>';
  142. }
  143. }
  144. }