home.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. * @autor Alex Aragon <alex.aragon@beeznest.com> CSS Design and Template
  7. */
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $user_id = api_get_user_id();
  11. $show_full_profile = true;
  12. // social tab
  13. $this_section = SECTION_SOCIAL;
  14. unset($_SESSION['this_section']);
  15. api_block_anonymous_users();
  16. if (api_get_setting('allow_social_tool') != 'true') {
  17. $url = api_get_path(WEB_CODE_PATH) . 'auth/profile.php';
  18. header('Location: ' . $url);
  19. exit;
  20. }
  21. $userGroup = new UserGroup();
  22. //fast upload image
  23. if (api_get_setting('profile', 'picture') == 'true') {
  24. $form = new FormValidator('profile', 'post', 'home.php', null, array());
  25. // PICTURE
  26. $form->addElement('file', 'picture', get_lang('AddImage'));
  27. $form->add_progress_bar();
  28. if (!empty($user_data['picture_uri'])) {
  29. $form->addElement(
  30. 'checkbox',
  31. 'remove_picture',
  32. null,
  33. get_lang('DelImage')
  34. );
  35. }
  36. $allowed_picture_types = api_get_supported_image_extensions();
  37. $form->addRule(
  38. 'picture',
  39. get_lang('OnlyImagesAllowed') . ' (' . implode(
  40. ',',
  41. $allowed_picture_types
  42. ) . ')',
  43. 'filetype',
  44. $allowed_picture_types
  45. );
  46. $form->addButtonSave(get_lang('SaveSettings'), 'apply_change');
  47. if ($form->validate()) {
  48. $user_data = $form->getSubmitValues();
  49. // upload picture if a new one is provided
  50. if ($_FILES['picture']['size']) {
  51. if ($new_picture = UserManager::update_user_picture(
  52. api_get_user_id(),
  53. $_FILES['picture']['name'],
  54. $_FILES['picture']['tmp_name']
  55. )
  56. ) {
  57. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  58. $sql = "UPDATE $table_user
  59. SET picture_uri = '$new_picture' WHERE user_id = " . api_get_user_id();
  60. $result = Database::query($sql);
  61. }
  62. }
  63. }
  64. }
  65. //Block Menu
  66. $social_menu_block = SocialManager::show_social_menu('home');
  67. $social_search_block = Display::panel(
  68. UserManager::get_search_form(''),
  69. get_lang("SearchUsers")
  70. );
  71. $results = $userGroup->get_groups_by_age(1, false);
  72. $groups_newest = array();
  73. if (!empty($results)) {
  74. foreach ($results as $result) {
  75. $id = $result['id'];
  76. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  77. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  78. if ($result['count'] == 1) {
  79. $result['count'] = '1 ' . get_lang('Member');
  80. } else {
  81. $result['count'] = $result['count'] . ' ' . get_lang('Members');
  82. }
  83. $group_url = "group_view.php?id=$id";
  84. $result['name'] = '<div class="group-name">'.Display::url(
  85. api_ucwords(cut($result['name'], 40, true)), $group_url)
  86. .'</div><div class="count-username">'.
  87. Display::return_icon('user.png','','',ICON_SIZE_TINY).$result['count'].'</div>';
  88. $picture = $userGroup->get_picture_group(
  89. $id,
  90. $result['picture'],
  91. 80
  92. );
  93. $result['picture'] = '<img class="group-image" src="' . $picture['file'] . '" />';
  94. $group_actions = '<div class="group-more"><a href="groups.php?#tab_browse-2">' . get_lang('SeeMore') . '</a></div>';
  95. $group_info= '<div class="description"><p>' . cut($result['description'], 120, true) . "</p></div>";
  96. $groups_newest[] = array(
  97. Display::url(
  98. $result['picture'],
  99. $group_url
  100. ),
  101. $result['name'],
  102. $group_info.$group_actions,
  103. );
  104. }
  105. }
  106. // Top popular
  107. $results = $userGroup->get_groups_by_popularity(1, false);
  108. $groups_pop = array();
  109. foreach ($results as $result) {
  110. $result['description'] = Security::remove_XSS(
  111. $result['description'],
  112. STUDENT,
  113. true
  114. );
  115. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  116. $id = $result['id'];
  117. $group_url = "group_view.php?id=$id";
  118. if ($result['count'] == 1) {
  119. $result['count'] = '1 ' . get_lang('Member');
  120. } else {
  121. $result['count'] = $result['count'] . ' ' . get_lang('Members');
  122. }
  123. $result['name'] = '<div class="group-name">'.Display::url(
  124. api_ucwords(cut($result['name'], 40, true)),$group_url)
  125. .'</div><div class="count-username">'.Display::return_icon('user.png','','',ICON_SIZE_TINY).$result['count'].'</div>';
  126. $picture = $userGroup->get_picture_group(
  127. $id,
  128. $result['picture'],
  129. 80
  130. );
  131. $result['picture_uri'] = '<img class="group-image" src="' . $picture['file'] . '" />';
  132. $group_actions = '<div class="group-more" ><a href="groups.php?#tab_browse-3">' . get_lang('SeeMore') . '</a></div>';
  133. $group_info= '<div class="description"><p>' . cut($result['description'], 120, true) . "</p></div>";
  134. $groups_pop[] = array(
  135. Display::url($result['picture_uri'], $group_url),
  136. $result['name'],$group_info. $group_actions
  137. );
  138. }
  139. $list=count($groups_newest);
  140. $social_group_block = null;
  141. if ($list > 0) {
  142. $social_group_block .= '<div class="list-group-newest">';
  143. $social_group_block .= '<div class="group-title">' . get_lang('Newest') . '</div>';
  144. for($i = 0;$i < $list; $i++){
  145. $social_group_block.='<div class="row">';
  146. $social_group_block.='<div class="col-md-2">' . $groups_newest[$i][0] . '</div>';
  147. $social_group_block.='<div class="col-md-4">' . $groups_newest[$i][1];
  148. $social_group_block.= $groups_newest[$i][2] . '</div>';
  149. $social_group_block.="</div>";
  150. }
  151. $social_group_block.= "</div>";
  152. }
  153. $list=count($groups_pop);
  154. if ($list > 0) {
  155. $social_group_block .= '<div class="list-group-newest">';
  156. $social_group_block .= '<div class="group-title">' . get_lang('Popular') . '</div>';
  157. for($i = 0;$i < $list; $i++){
  158. $social_group_block.='<div class="row">';
  159. $social_group_block.='<div class="col-md-2">' . $groups_pop[$i][0] . '</div>';
  160. $social_group_block.='<div class="col-md-4">' . $groups_pop[$i][1];
  161. $social_group_block.= $groups_pop[$i][2] . '</div>';
  162. $social_group_block.="</div>";
  163. }
  164. $social_group_block.= "</div>";
  165. }
  166. // My friends
  167. $friend_html = SocialManager::listMyFriendsBlock(
  168. $user_id,
  169. '',
  170. $show_full_profile
  171. );
  172. //Block Social Sessions
  173. $social_session_block = null;
  174. $user_info = api_get_user_info($user_id);
  175. $sessionList = SessionManager::getSessionsFollowedByUser($user_id, $user_info['status']);
  176. if (count($sessionList) > 0) {
  177. $social_session_block = $sessionList;
  178. }
  179. $social_group_block = Display::panel($social_group_block, get_lang('Group'));
  180. $tpl = new Template(get_lang('SocialNetwork'));
  181. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'home');
  182. $tpl->assign('social_menu_block', $social_menu_block);
  183. $tpl->assign('social_friend_block', $friend_html);
  184. $tpl->assign('sessionList', $social_session_block);
  185. $tpl->assign('social_search_block', $social_search_block);
  186. $tpl->assign('social_skill_block', SocialManager::getSkillBlock($user_id));
  187. $tpl->assign('social_group_block', $social_group_block);
  188. $social_layout = $tpl->get_template('social/home.tpl');
  189. $tpl->display($social_layout);