profile_friends_and_groups.inc.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. /**
  9. * Initialization
  10. */
  11. $language_file = array('registration', 'admin');
  12. $cidReset = true;
  13. require_once '../inc/global.inc.php';
  14. api_block_anonymous_users();
  15. if (api_get_setting('allow_social_tool') != 'true') {
  16. api_not_allowed();
  17. }
  18. $views = array('friends', 'mygroups');
  19. $user_id = intval($_GET['user_id']);
  20. if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
  21. // show all friends by user_id
  22. if ($_GET['view'] == 'friends') {
  23. echo '<div style="margin-top:20px;">';
  24. $list_path_friends = $list_path_normal_friends = $list_path_parents = array();
  25. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, SOCIALPARENT
  26. $friends = SocialManager::get_friends(
  27. $user_id,
  28. USER_RELATION_TYPE_FRIEND
  29. );
  30. $number_friends = count($friends);
  31. $friend_html = '';
  32. $friend_html .= '<div><h3>' . get_lang('SocialFriend') . '</h3></div>';
  33. $friend_html .= '<div id="friend-container" class="social-friend-container">';
  34. $friend_html .= '<div id="friend-header" >';
  35. if ($number_friends == 1) {
  36. $friend_html .= '<div style="float:left;width:80%">' . $number_friends . ' ' . get_lang(
  37. 'Friend'
  38. ) . '</div>';
  39. } else {
  40. $friend_html .= '<div style="float:left;width:80%">' . $number_friends . ' ' . get_lang(
  41. 'Friends'
  42. ) . '</div>';
  43. }
  44. $friend_html .= '</div>'; // close div friend-header
  45. for ($k = 0; $k < $number_friends; $k++) {
  46. if (isset($friends[$k])) {
  47. $friend = $friends[$k];
  48. $name_user = api_get_person_name(
  49. $friend['firstName'],
  50. $friend['lastName']
  51. );
  52. $friend_html .= '<div id=div_' . $friend['friend_user_id'] . ' class="image_friend_network" ><span><center>';
  53. // the height = 92 must be the sqme in the image_friend_network span style in default.css
  54. $friends_profile = SocialManager::get_picture_user(
  55. $friend['friend_user_id'],
  56. $friend['image'],
  57. 92,
  58. USER_IMAGE_SIZE_MEDIUM,
  59. 'width="85" height="90" '
  60. );
  61. $friend_html .= '<a href="profile.php?u=' . $friend['friend_user_id'] . '&amp;' . $link_shared . '">';
  62. $friend_html .= '<img src="' . $friends_profile['file'] . '" ' . $friends_profile['style'] . ' id="imgfriend_' . $friend['friend_user_id'] . '" title="' . $name_user . '" />';
  63. $friend_html .= '</center></span>';
  64. $friend_html .= '<center class="friend">' . $name_user . '</a></center>';
  65. $friend_html .= '</div>';
  66. }
  67. }
  68. echo $friend_html;
  69. echo '</div>';
  70. } else {
  71. // show all groups by user_id
  72. // MY GROUPS
  73. $results = GroupPortalManager::get_groups_by_user($user_id, 0);
  74. $grid_my_groups = array();
  75. if (is_array($results) && count($results) > 0) {
  76. $i = 1;
  77. foreach ($results as $result) {
  78. $id = $result['id'];
  79. $url_open = '<a href="groups.php?id=' . $id . '">';
  80. $url_close = '</a>';
  81. $icon = '';
  82. $name = cut($result['name'], 20, true);
  83. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  84. $icon = Display::return_icon(
  85. 'social_group_admin.png',
  86. get_lang('Admin'),
  87. array('style' => 'vertical-align:middle;width:16px;height:16px;')
  88. );
  89. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  90. $icon = Display::return_icon(
  91. 'social_group_moderator.png',
  92. get_lang('Moderator'),
  93. array('style' => 'vertical-align:middle;width:16px;height:16px;')
  94. );
  95. }
  96. $count_users_group = count(
  97. GroupPortalManager::get_all_users_by_group($id)
  98. );
  99. if ($count_users_group == 1) {
  100. $count_users_group = $count_users_group . ' ' . get_lang(
  101. 'Member'
  102. );
  103. } else {
  104. $count_users_group = $count_users_group . ' ' . get_lang(
  105. 'Members'
  106. );
  107. }
  108. $picture = GroupPortalManager::get_picture_group(
  109. $result['id'],
  110. $result['picture_uri'],
  111. 80
  112. );
  113. $item_name = '<div class="box_shared_profile_group_title">' . $url_open . api_xml_http_response_encode(
  114. $name
  115. ) . $icon . $url_close . '</div>';
  116. $item_description = '';
  117. if (!empty($result['description'])) {
  118. $item_description = '<div class="box_shared_profile_group_description"><span class="social-groups-text2">' . api_xml_http_response_encode(
  119. get_lang('Description')
  120. ) . '</span><p class="social-groups-text4">' . cut(
  121. api_xml_http_response_encode(
  122. $result['description']
  123. ),
  124. 120,
  125. true
  126. ) . '</p></div>';
  127. }
  128. $result['picture_uri'] = '<div class="box_shared_profile_group_image"><img class="social-groups-image" src="' . $picture['file'] . '" hspace="4" height="50" border="2" align="left" width="50" /></div>';
  129. $item_actions = '';
  130. if (api_get_user_id() == $user_id) {
  131. $item_actions = '<div class="box_shared_profile_group_actions"><a href="groups.php?id=' . $id . '">' . get_lang(
  132. 'SeeMore'
  133. ) . $url_close . '</div>';
  134. }
  135. $grid_my_groups[] = array(
  136. $item_name,
  137. $url_open . $result['picture_uri'] . $url_close,
  138. $item_description . $item_actions
  139. );
  140. $i++;
  141. }
  142. }
  143. if (count($grid_my_groups) > 0) {
  144. echo '<div style="margin-top:20px">';
  145. echo '<div><h3>' . get_lang('MyGroups') . '</h3></div>';
  146. $count_groups = 0;
  147. if (count($results) == 1) {
  148. $count_groups = count($results) . ' ' . get_lang('Group');
  149. } else {
  150. $count_groups = count($results) . ' ' . get_lang('Groups');
  151. }
  152. echo '<div>' . $count_groups . '</div>';
  153. Display::display_sortable_grid(
  154. 'shared_profile_mygroups',
  155. array(),
  156. $grid_my_groups,
  157. array('hide_navigation' => true, 'per_page' => 2),
  158. $query_vars,
  159. false,
  160. array(true, true, true, false)
  161. );
  162. echo '</div>';
  163. }
  164. }
  165. }