home.php 7.6 KB

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