home.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. /**
  8. * Initialization
  9. */
  10. $language_file = array('userInfo');
  11. $cidReset = true;
  12. require_once '../inc/global.inc.php';
  13. require_once api_get_path(LIBRARY_PATH) . 'group_portal_manager.lib.php';
  14. require_once api_get_path(LIBRARY_PATH) . 'skill.lib.php';
  15. $user_id = api_get_user_id();
  16. $show_full_profile = true;
  17. //social tab
  18. $this_section = SECTION_SOCIAL;
  19. unset($_SESSION['this_section']); //for hmtl editor repository
  20. api_block_anonymous_users();
  21. if (api_get_setting('allow_social_tool') != 'true') {
  22. $url = api_get_path(WEB_CODE_PATH) . 'auth/profile.php';
  23. header('Location: ' . $url);
  24. exit;
  25. api_not_allowed();
  26. }
  27. //fast upload image
  28. if (api_get_setting('profile', 'picture') == 'true') {
  29. $form = new FormValidator('profile', 'post', 'home.php', null, array());
  30. // PICTURE
  31. $form->addElement('file', 'picture', get_lang('AddImage'));
  32. $form->add_progress_bar();
  33. if (!empty($user_data['picture_uri'])) {
  34. $form->addElement(
  35. 'checkbox',
  36. 'remove_picture',
  37. null,
  38. get_lang('DelImage')
  39. );
  40. }
  41. $allowed_picture_types = api_get_supported_image_extensions();
  42. $form->addRule(
  43. 'picture',
  44. get_lang('OnlyImagesAllowed') . ' (' . implode(
  45. ',',
  46. $allowed_picture_types
  47. ) . ')',
  48. 'filetype',
  49. $allowed_picture_types
  50. );
  51. $form->addElement(
  52. 'style_submit_button',
  53. 'apply_change',
  54. get_lang('SaveSettings'),
  55. 'class="save"'
  56. );
  57. if ($form->validate()) {
  58. $user_data = $form->getSubmitValues();
  59. // upload picture if a new one is provided
  60. if ($_FILES['picture']['size']) {
  61. if ($new_picture = UserManager::update_user_picture(
  62. api_get_user_id(),
  63. $_FILES['picture']['name'],
  64. $_FILES['picture']['tmp_name']
  65. )
  66. ) {
  67. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  68. $sql = "UPDATE $table_user
  69. SET picture_uri = '$new_picture' WHERE user_id = " . api_get_user_id();
  70. $result = Database::query($sql);
  71. }
  72. }
  73. }
  74. }
  75. $user_info = UserManager :: get_user_info_by_id(api_get_user_id());
  76. $social_avatar_block = SocialManager::show_social_avatar_block('home');
  77. $social_menu_block = SocialManager::show_social_menu('home');
  78. $socialRightContent = '<div class="span5">';
  79. $socialRightContent .= '<div class="well_border">';
  80. $socialRightContent .= '<h3>' . get_lang('ContactInformation') . '</h3>';
  81. $list = array(
  82. array(
  83. 'title' => get_lang('Name'),
  84. 'content' => api_get_person_name(
  85. $user_info['firstname'],
  86. $user_info['lastname']
  87. )
  88. ),
  89. array('title' => get_lang('Email'), 'content' => $user_info['email']),
  90. );
  91. // information current user
  92. $socialRightContent .= '<div>' . Display::description($list) . '</div>';
  93. $editProfileUrl = api_get_path(WEB_CODE_PATH) . 'auth/profile.php';
  94. if (api_get_setting('sso_authentication') === 'true') {
  95. $subSSOClass = api_get_setting('sso_authentication_subclass');
  96. $objSSO = null;
  97. if (!empty($subSSOClass)) {
  98. require_once api_get_path(SYS_CODE_PATH) . 'auth/sso/sso.' . $subSSOClass . '.class.php';
  99. $subSSOClass = 'sso' . $subSSOClass;
  100. $objSSO = new $subSSOClass();
  101. } else {
  102. $objSSO = new sso();
  103. }
  104. $editProfileUrl = $objSSO->generateProfileEditingURL();
  105. }
  106. $socialRightContent .= '
  107. <div class="form-actions">
  108. <a class="btn" href="' . $editProfileUrl . '">
  109. ' . get_lang('EditProfile') . '
  110. </a>
  111. </div></div></div>';
  112. $socialRightInformation = '<div class="span4">';
  113. if (api_get_setting('allow_skills_tool') == 'true') {
  114. $socialRightInformation .= '<div class="well_border">';
  115. $skill = new Skill();
  116. $ranking = $skill->get_user_skill_ranking(api_get_user_id());
  117. $url = api_get_path(WEB_CODE_PATH) . 'social/skills_ranking.php';
  118. $ranking_url = Display::url(
  119. sprintf(get_lang('YourSkillRankingX'), $ranking),
  120. $url,
  121. array('class' => 'btn')
  122. );
  123. $skills = $skill->get_user_skills(api_get_user_id(), true);
  124. $socialRightInformation .= '<h3>' . get_lang('Skills') . '</h3>';
  125. $lis = '';
  126. if (!empty($skills)) {
  127. foreach ($skills as $skill) {
  128. $lis .= Display::tag(
  129. 'li',
  130. Display::span(
  131. $skill['name'],
  132. array('class' => 'label_tag skill')
  133. )
  134. );
  135. }
  136. $socialRightInformation .= Display::tag('ul', $lis);
  137. }
  138. $url = api_get_path(WEB_CODE_PATH) . 'social/skills_wheel.php';
  139. $skill_wheel_url = Display::url(
  140. get_lang('ViewSkillsWheel'),
  141. $url,
  142. array('class' => 'btn')
  143. );
  144. $socialRightInformation .= '<div class="btn-group">' . $skill_wheel_url . $ranking_url . '</div>';
  145. $socialRightInformation .= '</div>';
  146. }
  147. //Search box
  148. $socialRightInformation .= '<div>';
  149. $socialRightInformation .= UserManager::get_search_form('');
  150. $socialRightInformation .= '<br /></div>';
  151. //Group box by age
  152. $results = GroupPortalManager::get_groups_by_age(1, false);
  153. $groups_newest = array();
  154. if (!empty($results)) {
  155. foreach ($results as $result) {
  156. $id = $result['id'];
  157. $result['description'] = Security::remove_XSS(
  158. $result['description'],
  159. STUDENT,
  160. true
  161. );
  162. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  163. if ($result['count'] == 1) {
  164. $result['count'] = '1 ' . get_lang('Member');
  165. } else {
  166. $result['count'] = $result['count'] . ' ' . get_lang('Members');
  167. }
  168. $group_url = "groups.php?id=$id";
  169. $result['name'] = Display::url(
  170. api_ucwords(cut($result['name'], 40, true)),
  171. $group_url
  172. ) . Display::span(
  173. '<br />' . $result['count'],
  174. array('class' => 'box_description_group_member')
  175. );
  176. $picture = GroupPortalManager::get_picture_group(
  177. $id,
  178. $result['picture_uri'],
  179. 80
  180. );
  181. $result['picture_uri'] = '<img class="social-groups-image" src="' . $picture['file'] . '" hspace="10" height="44" border="2" align="left" width="44" />';
  182. $group_actions = '<div class="box_description_group_actions"><a href="groups.php?#tab_browse-2">' . get_lang(
  183. 'SeeMore'
  184. ) . '</a></div>';
  185. $groups_newest[] = array(
  186. Display::url(
  187. $result['picture_uri'],
  188. $group_url
  189. ),
  190. $result['name'],
  191. cut($result['description'], 120, true) . $group_actions
  192. );
  193. }
  194. }
  195. $results = GroupPortalManager::get_groups_by_popularity(1, false);
  196. $groups_pop = array();
  197. foreach ($results as $result) {
  198. $result['description'] = Security::remove_XSS(
  199. $result['description'],
  200. STUDENT,
  201. true
  202. );
  203. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  204. $id = $result['id'];
  205. $group_url = "groups.php?id=$id";
  206. if ($result['count'] == 1) {
  207. $result['count'] = '1 ' . get_lang('Member');
  208. } else {
  209. $result['count'] = $result['count'] . ' ' . get_lang('Members');
  210. }
  211. $result['name'] = Display::url(
  212. api_ucwords(cut($result['name'], 40, true)),
  213. $group_url
  214. ) . Display::span(
  215. '<br />' . $result['count'],
  216. array('class' => 'box_description_group_member')
  217. );
  218. $picture = GroupPortalManager::get_picture_group(
  219. $id,
  220. $result['picture_uri'],
  221. 80
  222. );
  223. $result['picture_uri'] = '<img class="social-groups-image" src="' . $picture['file'] . '" hspace="10" height="44" border="2" align="left" width="44" />';
  224. $group_actions = '<div class="box_description_group_actions" ><a href="groups.php?#tab_browse-3">' . get_lang(
  225. 'SeeMore'
  226. ) . '</a></div>';
  227. $groups_pop[] = array(
  228. Display::url($result['picture_uri'], $group_url),
  229. $result['name'],
  230. cut($result['description'], 120, true) . $group_actions
  231. );
  232. }
  233. if (count($groups_newest) > 0) {
  234. $socialRightInformation .= '<div class="social-groups-home-title">' . get_lang(
  235. 'Newest'
  236. ) . '</div>';
  237. $socialRightInformation .= Display::return_sortable_grid(
  238. 'home_group',
  239. array(),
  240. $groups_newest,
  241. array('hide_navigation' => true, 'per_page' => 100),
  242. array(),
  243. false,
  244. array(true, true, true, false)
  245. );
  246. }
  247. if (count($groups_pop) > 0) {
  248. $socialRightInformation .= '<div class="social-groups-home-title">' . get_lang(
  249. 'Popular'
  250. ) . '</div>';
  251. $socialRightInformation .= Display::return_sortable_grid(
  252. 'home_group',
  253. array(),
  254. $groups_pop,
  255. array('hide_navigation' => true, 'per_page' => 100),
  256. array(),
  257. false,
  258. array(true, true, true, true, true)
  259. );
  260. }
  261. $socialRightInformation .= '</div>';
  262. $tpl = new Template(get_lang('SocialNetwork'));
  263. $tpl->assign('social_avatar_block', $social_avatar_block);
  264. $tpl->assign('social_menu_block', $social_menu_block);
  265. $tpl->assign('social_right_content', $socialRightContent);
  266. $tpl->assign('socialRightInformation', $socialRightInformation);
  267. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  268. $tpl->display($social_layout);