home.php 7.6 KB

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