home.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. $cidReset = true;
  11. $user_id = api_get_user_id();
  12. $show_full_profile = true;
  13. // Social tab
  14. $this_section = SECTION_SOCIAL;
  15. unset($_SESSION['this_section']);//for hmtl editor repository
  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. // 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('checkbox', 'remove_picture', null, get_lang('DelImage'));
  30. }
  31. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  32. $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  33. $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
  34. if ($form->validate()) {
  35. $user_data = $form->getSubmitValues();
  36. // upload picture if a new one is provided
  37. if ($_FILES['picture']['size']) {
  38. if ($new_picture = UserManager::update_user_picture(api_get_user_id(), $_FILES['picture']['name'], $_FILES['picture']['tmp_name'])) {
  39. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  40. $sql = "UPDATE $table_user SET picture_uri = '$new_picture' WHERE user_id = ".api_get_user_id();
  41. $result = Database::query($sql);
  42. }
  43. }
  44. }
  45. }
  46. $user_info = UserManager::get_user_info_by_id(api_get_user_id());
  47. $social_left_content = SocialManager::show_social_menu('home');
  48. $usergroup = new UserGroup();
  49. $social_right_content = '<div class="span5">';
  50. $social_right_content .= '<div class="well_border">';
  51. $social_right_content .= '<h3>'.get_lang('ContactInformation').'</h3>';
  52. $list = array(
  53. array('title' => get_lang('Name'), 'content' => api_get_person_name($user_info['firstname'], $user_info['lastname'])),
  54. array('title' => get_lang('Email'), 'content' => $user_info['email']),
  55. );
  56. // Current user information
  57. $social_right_content .= '<div>'.Display::description($list).'</div>';
  58. $social_right_content .= '
  59. <div class="form-actions">
  60. <a class="btn" href="'.api_get_path(WEB_PATH).'main/auth/profile.php">
  61. '.get_lang('EditProfile').'
  62. </a>
  63. </div>
  64. </div>';
  65. if (api_get_setting('allow_skills_tool') == 'true') {
  66. $social_right_content .= '<div class="well_border">';
  67. $skill = new Skill();
  68. $ranking = $skill->get_user_skill_ranking(api_get_user_id());
  69. $url = api_get_path(WEB_CODE_PATH).'social/skills_ranking.php';
  70. $ranking_url = Display::url(sprintf(get_lang('YourSkillRankingX'), $ranking), $url, array('class' => 'btn'));
  71. $skills = $skill->get_user_skills(api_get_user_id(), true);
  72. $social_right_content .= '<h3>'.get_lang('Skills').'</h3>';
  73. $lis = '';
  74. if (!empty($skills)) {
  75. foreach($skills as $skill) {
  76. $lis .= Display::tag('li', Display::span($skill['name'], array('class'=>'label_tag skill')));
  77. }
  78. $social_right_content .= Display::tag('ul', $lis);
  79. }
  80. $url = api_get_path(WEB_CODE_PATH).'social/skills_wheel.php';
  81. $skill_wheel_url = Display::url(get_lang('ViewSkillsWheel'), $url, array('class' => 'btn'));
  82. $social_right_content .= '<div class="btn-group">'.$skill_wheel_url.$ranking_url.'</div>';
  83. $social_right_content .= '</div>';
  84. }
  85. $social_right_content .= '</div>';
  86. // Search box
  87. $social_right_content .= '<div class="span4">';
  88. $social_right_content .= UserManager::get_search_form('');
  89. $social_right_content .= '</br>';
  90. // Group box by age
  91. $results = $usergroup->get_groups_by_age(1,false);
  92. $groups_newest = array();
  93. if (!empty($results)) {
  94. foreach ($results as $result) {
  95. $id = $result['id'];
  96. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  97. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  98. if ($result['count'] == 1 ) {
  99. $result['count'] = '1 '.get_lang('Member');
  100. } else {
  101. $result['count'] = $result['count'].' '.get_lang('Members');
  102. }
  103. $group_url = "groups.php?id=$id";
  104. $result['name'] = Display::url(api_ucwords(Text::cut($result['name'],40,true)), $group_url).Display::span('<br />'.$result['count'],array('class'=>'box_description_group_member'));
  105. $picture = $usergroup->get_picture_group($id, $result['picture'],80);
  106. $result['picture'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="10" height="44" border="2" align="left" width="44" />';
  107. $group_actions = '<div class="box_description_group_actions"><a href="groups.php?#tab_browse-2">'.get_lang('SeeMore').'</a></div>';
  108. $groups_newest[]= array(Display::url($result['picture'], $group_url), $result['name'], Text::cut($result['description'],120,true).$group_actions);
  109. }
  110. }
  111. // Group box by age
  112. $results = $usergroup->get_groups_by_age(1,false);
  113. $groups_newest = array();
  114. if (!empty($results)) {
  115. foreach ($results as $result) {
  116. $id = $result['id'];
  117. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  118. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  119. if ($result['count'] == 1 ) {
  120. $result['count'] = '1 '.get_lang('Member');
  121. } else {
  122. $result['count'] = $result['count'].' '.get_lang('Members');
  123. }
  124. $group_url = "groups.php?id=$id";
  125. $result['name'] = Display::url(api_ucwords(Text::cut($result['name'],40,true)), $group_url).Display::span('<br />'.$result['count'],array('class'=>'box_description_group_member'));
  126. $picture = $usergroup->get_picture_group($id, $result['picture'],80);
  127. $result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="10" height="44" border="2" align="left" width="44" />';
  128. $group_actions = '<div class="box_description_group_actions"><a href="groups.php?#tab_browse-2">'.get_lang('SeeMore').'</a></div>';
  129. $groups_newest[]= array(Display::url($result['picture_uri'], $group_url), $result['name'], Text::cut($result['description'],120,true).$group_actions);
  130. }
  131. }
  132. $results = $usergroup->get_groups_by_popularity(1,false);
  133. $groups_pop = array();
  134. foreach ($results as $result) {
  135. $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
  136. $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
  137. $id = $result['id'];
  138. $group_url = "groups.php?id=$id";
  139. if ($result['count'] == 1 ) {
  140. $result['count'] = '1 '.get_lang('Member');
  141. } else {
  142. $result['count'] = $result['count'].' '.get_lang('Members');
  143. }
  144. $result['name'] = Display::url(api_ucwords(Text::cut($result['name'],40,true)), $group_url).Display::span('<br />'.$result['count'],array('class'=>'box_description_group_member'));
  145. $picture = $usergroup->get_picture_group($id, $result['picture'],80);
  146. $result['picture_uri'] = '<img class="social-groups-image" src="'.$picture['file'].'" hspace="10" height="44" border="2" align="left" width="44" />';
  147. $group_actions = '<div class="box_description_group_actions" ><a href="groups.php?#tab_browse-3">'.get_lang('SeeMore').'</a></div>';
  148. $groups_pop[]= array(Display::url($result['picture_uri'], $group_url) , $result['name'], Text::cut($result['description'],120,true).$group_actions);
  149. }
  150. if (count($groups_newest) > 0) {
  151. $social_right_content .= '<div class="social-groups-home-title">'.get_lang('Newest').'</div>';
  152. $social_right_content .= Display::return_sortable_grid('home_group', array(), $groups_newest, array('hide_navigation'=>true, 'per_page' => 100), array(), false, array(true, true, true,false));
  153. }
  154. if (count($groups_pop) > 0) {
  155. $social_right_content .= '<div class="social-groups-home-title">'.get_lang('Popular').'</div>';
  156. $social_right_content .= Display::return_sortable_grid('home_group', array(), $groups_pop, array('hide_navigation'=>true, 'per_page' => 100), array(), false, array(true, true, true,true,true));
  157. }
  158. $social_right_content .= '</div>';
  159. $app['title'] = get_lang('SocialNetwork');
  160. $tpl = $app['template'];
  161. $tpl->assign('social_left_content', $social_left_content);
  162. $tpl->assign('social_right_content', $social_right_content);
  163. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  164. $tpl->display($social_layout);