profile_friends_and_groups.inc.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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','messages','userInfo','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($user_id, USER_RELATION_TYPE_FRIEND);
  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($friend['firstName'], $friend['lastName']);
  42. $friend_html.='<div id=div_'.$friend['friend_user_id'].' class="image_friend_network" ><span><center>';
  43. // the height = 92 must be the sqme in the image_friend_network span style in default.css
  44. $friends_profile = SocialManager::get_picture_user($friend['friend_user_id'], $friend['image'], 92, USER_IMAGE_SIZE_MEDIUM , 'width="85" height="90" ');
  45. $friend_html.='<a href="profile.php?u='.$friend['friend_user_id'].'&amp;'.$link_shared.'">';
  46. $friend_html.='<img src="'.$friends_profile['file'].'" '.$friends_profile['style'].' id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" />';
  47. $friend_html.= '</center></span>';
  48. $friend_html.= '<center class="friend">'.$name_user.'</a></center>';
  49. $friend_html.= '</div>';
  50. }
  51. }
  52. echo $friend_html;
  53. echo '</div>';
  54. } else {
  55. $usergroup = new UserGroup();
  56. // show all groups by user_id
  57. // MY GROUPS
  58. $results = $usergroup->get_groups_by_user($user_id, 0);
  59. $grid_my_groups = array();
  60. if (is_array($results) && count($results) > 0) {
  61. $i = 1;
  62. foreach ($results as $result) {
  63. $id = $result['id'];
  64. $url_open = '<a href="groups.php?id='.$id.'">';
  65. $url_close = '</a>';
  66. $icon = '';
  67. $name = Text::cut($result['name'],20,true);
  68. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  69. $icon = Display::return_icon('social_group_admin.png', get_lang('Admin'), array('style'=>'vertical-align:middle;width:16px;height:16px;'));
  70. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  71. $icon = Display::return_icon('social_group_moderator.png', get_lang('Moderator'), array('style'=>'vertical-align:middle;width:16px;height:16px;'));
  72. }
  73. $count_users_group = count($usergroup->get_all_users_by_group($id));
  74. if ($count_users_group == 1 ) {
  75. $count_users_group = $count_users_group.' '.get_lang('Member');
  76. } else {
  77. $count_users_group = $count_users_group.' '.get_lang('Members');
  78. }
  79. $picture = $usergroup->get_picture_group($result['id'], $result['picture'],80);
  80. $item_name = '<div class="box_shared_profile_group_title">'.$url_open.api_xml_http_response_encode($name). $icon.$url_close.'</div>';
  81. $item_description = '';
  82. if (!empty($result['description'])) {
  83. $item_description = '<div class="box_shared_profile_group_description"><span class="social-groups-text2">'.api_xml_http_response_encode(get_lang('Description')).'</span><p class="social-groups-text4">'.Text::cut(api_xml_http_response_encode($result['description']),120,true).'</p></div>';
  84. }
  85. $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>';
  86. $item_actions = '';
  87. if (api_get_user_id() == $user_id) {
  88. $item_actions = '<div class="box_shared_profile_group_actions"><a href="groups.php?id='.$id.'">'.get_lang('SeeMore').$url_close.'</div>';
  89. }
  90. $grid_my_groups[]= array($item_name,$url_open.$result['picture_uri'].$url_close, $item_description.$item_actions);
  91. $i++;
  92. }
  93. }
  94. if (count($grid_my_groups) > 0) {
  95. echo '<div style="margin-top:20px">';
  96. echo '<div><h3>'.get_lang('MyGroups').'</h3></div>';
  97. $count_groups = 0;
  98. if (count($results) == 1 ) {
  99. $count_groups = count($results).' '.get_lang('Group');
  100. } else {
  101. $count_groups = count($results).' '.get_lang('Groups');
  102. }
  103. echo '<div>'.$count_groups.'</div>';
  104. Display::display_sortable_grid('shared_profile_mygroups', array(), $grid_my_groups, array('hide_navigation'=>true, 'per_page' => 2), $query_vars, false, array(true, true, true,false));
  105. echo '</div>';
  106. }
  107. }
  108. }