home.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /* For licensing terms, see /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 __DIR__.'/../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->addProgress();
  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. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  57. $sql = "UPDATE $table_user
  58. SET
  59. picture_uri = '$new_picture'
  60. WHERE user_id = ".api_get_user_id();
  61. $result = Database::query($sql);
  62. }
  63. }
  64. }
  65. }
  66. //Block Menu
  67. $social_menu_block = SocialManager::show_social_menu('home');
  68. $social_search_block = Display::panel(
  69. UserManager::get_search_form(''),
  70. get_lang("SearchUsers")
  71. );
  72. $results = $userGroup->get_groups_by_age(1, false);
  73. $groups_newest = array();
  74. if (!empty($results)) {
  75. foreach ($results as $result) {
  76. $id = $result['id'];
  77. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  78. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  79. if ($result['count'] == 1) {
  80. $result['count'] = '1 '.get_lang('Member');
  81. } else {
  82. $result['count'] = $result['count'].' '.get_lang('Members');
  83. }
  84. $group_url = "group_view.php?id=$id";
  85. $link = Display::url(
  86. api_ucwords(cut($result['name'], 40, true)),
  87. $group_url
  88. );
  89. $result['name'] = '<div class="group-name">'.$link.'</div><div class="count-username">'.
  90. Display::returnFontAwesomeIcon('user').$result['count'].'</div>';
  91. $picture = $userGroup->get_picture_group(
  92. $id,
  93. $result['picture'],
  94. null,
  95. GROUP_IMAGE_SIZE_BIG
  96. );
  97. $result['picture'] = '<img class="img-responsive" src="'.$picture['file'].'" />';
  98. $group_actions = '<div class="group-more"><a class="btn btn-default" 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. null,
  134. GROUP_IMAGE_SIZE_BIG
  135. );
  136. $result['picture_uri'] = '<img class="img-responsive" src="'.$picture['file'].'" />';
  137. $group_actions = '<div class="group-more"><a class="btn btn-default" href="groups.php?#tab_browse-3">'.get_lang('SeeMore').'</a></div>';
  138. $group_info = '<div class="description"><p>'.cut($result['description'], 120, true)."</p></div>";
  139. $groups_pop[] = array(
  140. Display::url($result['picture_uri'], $group_url),
  141. $result['name'], $group_info.$group_actions
  142. );
  143. }
  144. $list = count($groups_newest);
  145. $social_group_block = null;
  146. if ($list > 0) {
  147. $social_group_block .= '<div class="list-group-newest">';
  148. $social_group_block .= '<div class="group-title">'.get_lang('Newest').'</div>';
  149. for ($i = 0; $i < $list; $i++) {
  150. $social_group_block .= '<div class="row">';
  151. $social_group_block .= '<div class="col-md-3">'.$groups_newest[$i][0].'</div>';
  152. $social_group_block .= '<div class="col-md-9">'.$groups_newest[$i][1];
  153. $social_group_block .= $groups_newest[$i][2].'</div>';
  154. $social_group_block .= "</div>";
  155. }
  156. $social_group_block .= "</div>";
  157. }
  158. $list = count($groups_pop);
  159. if ($list > 0) {
  160. $social_group_block .= '<div class="list-group-newest">';
  161. $social_group_block .= '<div class="group-title">'.get_lang('Popular').'</div>';
  162. for ($i = 0; $i < $list; $i++) {
  163. $social_group_block .= '<div class="row">';
  164. $social_group_block .= '<div class="col-md-3">'.$groups_pop[$i][0].'</div>';
  165. $social_group_block .= '<div class="col-md-9">'.$groups_pop[$i][1];
  166. $social_group_block .= $groups_pop[$i][2].'</div>';
  167. $social_group_block .= "</div>";
  168. }
  169. $social_group_block .= "</div>";
  170. }
  171. // My friends
  172. $friend_html = SocialManager::listMyFriendsBlock(
  173. $user_id,
  174. '',
  175. $show_full_profile
  176. );
  177. // Block Social Sessions
  178. $social_session_block = null;
  179. $user_info = api_get_user_info($user_id);
  180. $sessionList = SessionManager::getSessionsFollowedByUser($user_id, $user_info['status']);
  181. if (count($sessionList) > 0) {
  182. $social_session_block = $sessionList;
  183. }
  184. $social_group_block = Display::panelCollapse(
  185. get_lang('Group'),
  186. $social_group_block,
  187. 'sm-groups',
  188. null,
  189. 'grups-acordion',
  190. 'groups-collapse'
  191. );
  192. $tpl = new Template(get_lang('SocialNetwork'));
  193. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'home');
  194. $tpl->assign('social_menu_block', $social_menu_block);
  195. $tpl->assign('social_friend_block', $friend_html);
  196. $tpl->assign('session_list', $social_session_block);
  197. $tpl->assign('social_search_block', $social_search_block);
  198. $tpl->assign('social_skill_block', SocialManager::getSkillBlock($user_id));
  199. $tpl->assign('social_group_block', $social_group_block);
  200. $social_layout = $tpl->get_template('social/home.tpl');
  201. $tpl->display($social_layout);