profile.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This is the profile social main page.
  6. *
  7. * @author Julio Montoya <gugli100@gmail.com>
  8. * @author Isaac Flores Paz <florespaz_isaac@hotmail.com>
  9. *
  10. * @todo use Display::panel()
  11. *
  12. * @package chamilo.social
  13. */
  14. $cidReset = true;
  15. require_once __DIR__.'/../inc/global.inc.php';
  16. if (api_get_setting('allow_social_tool') != 'true') {
  17. $url = api_get_path(WEB_PATH).'whoisonline.php?id='.intval($_GET['u']);
  18. header('Location: '.$url);
  19. exit;
  20. }
  21. $user_id = api_get_user_id();
  22. $friendId = isset($_GET['u']) ? (int) $_GET['u'] : api_get_user_id();
  23. $show_full_profile = true;
  24. //social tab
  25. $this_section = SECTION_SOCIAL;
  26. // Initialize blocks
  27. $social_course_block = null;
  28. $social_group_info_block = null;
  29. $social_rss_block = null;
  30. $social_session_block = null;
  31. SocialManager::handlePosts(api_get_self().'?u='.$friendId);
  32. if (isset($_GET['u'])) {
  33. //I'm your friend? I can see your profile?
  34. $user_id = (int) $_GET['u'];
  35. if (api_is_anonymous($user_id, true)) {
  36. api_not_allowed(true);
  37. }
  38. // It's me!
  39. if (api_get_user_id() != $user_id) {
  40. $user_info = api_get_user_info($user_id);
  41. $show_full_profile = false;
  42. if (!$user_info) {
  43. // user does no exist !!
  44. api_not_allowed(true);
  45. } else {
  46. //checking the relationship between me and my friend
  47. $my_status = SocialManager::get_relation_between_contacts(
  48. api_get_user_id(),
  49. $user_id
  50. );
  51. if (in_array($my_status, [
  52. USER_RELATION_TYPE_PARENT,
  53. USER_RELATION_TYPE_FRIEND,
  54. USER_RELATION_TYPE_GOODFRIEND,
  55. ])
  56. ) {
  57. $show_full_profile = true;
  58. }
  59. //checking the relationship between my friend and me
  60. $my_friend_status = SocialManager::get_relation_between_contacts(
  61. $user_id,
  62. api_get_user_id()
  63. );
  64. if (in_array($my_friend_status, [
  65. USER_RELATION_TYPE_PARENT,
  66. USER_RELATION_TYPE_FRIEND,
  67. USER_RELATION_TYPE_GOODFRIEND,
  68. ])
  69. ) {
  70. $show_full_profile = true;
  71. } else {
  72. // im probably not a good friend
  73. $show_full_profile = false;
  74. }
  75. }
  76. }
  77. }
  78. api_block_anonymous_users();
  79. $countPost = SocialManager::getCountWallMessagesByUser($friendId);
  80. SocialManager::getScrollJs($countPost, $htmlHeadXtra);
  81. $link_shared = '';
  82. if (isset($_GET['shared'])) {
  83. $link_shared = 'shared='.Security::remove_XSS($_GET['shared']);
  84. }
  85. $interbreadcrumb[] = [
  86. 'url' => 'home.php',
  87. 'name' => get_lang('Social network'),
  88. ];
  89. if (isset($_GET['u']) && is_numeric($_GET['u']) && $_GET['u'] != api_get_user_id()) {
  90. $info_user = api_get_user_info($_GET['u']);
  91. $interbreadcrumb[] = [
  92. 'url' => '#',
  93. 'name' => $info_user['complete_name'],
  94. ];
  95. }
  96. Session::write('social_user_id', (int) $user_id);
  97. // Setting some course info
  98. /*$course_list_code = [];
  99. $personal_course_list = UserManager::get_personal_session_course_list($friendId, 50);
  100. $i = 1;
  101. $list = [];
  102. if (is_array($personal_course_list)) {
  103. foreach ($personal_course_list as $my_course) {
  104. if ($i <= 10) {
  105. $list[] = SocialManager::get_logged_user_course_html($my_course, $i);
  106. $course_list_code[] = ['code' => $my_course['code']];
  107. } else {
  108. break;
  109. }
  110. $i++;
  111. }
  112. //to avoid repeted courses
  113. $course_list_code = array_unique_dimensional($course_list_code);
  114. }*/
  115. // Social Block Menu
  116. $menu = SocialManager::show_social_menu(
  117. 'shared_profile',
  118. null,
  119. $user_id,
  120. $show_full_profile
  121. );
  122. //Setting some session info
  123. $user_info = api_get_user_info($friendId);
  124. //$sessionList = SessionManager::getSessionsFollowedByUser($friendId, $user_info['status']);
  125. $sessionList = [];
  126. // My friends
  127. $friend_html = SocialManager::listMyFriendsBlock($user_id, $link_shared);
  128. $addPostForm = SocialManager::getWallForm(api_get_self());
  129. $posts = SocialManager::getWallMessagesByUser($friendId);
  130. $socialAutoExtendLink = SocialManager::getAutoExtendLink($user_id, $countPost);
  131. // Added a Jquery Function to return the Preview of OpenGraph URL Content
  132. $htmlHeadXtra[] = SocialManager::getScriptToGetOpenGraph();
  133. $socialRightInformation = '';
  134. $listInvitations = '';
  135. if ($show_full_profile) {
  136. $social_group_info_block = SocialManager::getGroupBlock($friendId);
  137. /*
  138. $my_courses = null;
  139. // COURSES LIST
  140. if (is_array($list)) {
  141. $i = 1;
  142. foreach ($list as $key => $value) {
  143. if (empty($value[2])) { //if out of any session
  144. $my_courses .= $value[1];
  145. $i++;
  146. }
  147. }
  148. $social_course_block .= $my_courses;
  149. }*/
  150. // Block Social Sessions
  151. if (count($sessionList) > 0) {
  152. $social_session_block = $sessionList;
  153. }
  154. // Block Social User Feeds
  155. $user_feeds = SocialManager::getUserRssFeed($user_id);
  156. if (!empty($user_feeds)) {
  157. $social_rss_block = Display::panel($user_feeds, get_lang('RSS feed'));
  158. }
  159. // Productions
  160. $production_list = UserManager::build_production_list($user_id);
  161. // Images uploaded by course
  162. $file_list = '';
  163. /*
  164. if (is_array($course_list_code) && count($course_list_code) > 0) {
  165. foreach ($course_list_code as $course) {
  166. $file_list .= UserManager::get_user_upload_files_by_course(
  167. $user_id,
  168. $course['code'],
  169. 'images'
  170. );
  171. }
  172. }*/
  173. $count_pending_invitations = 0;
  174. if (!isset($_GET['u']) ||
  175. (isset($_GET['u']) && $_GET['u'] == api_get_user_id())
  176. ) {
  177. $pending_invitations = SocialManager::get_list_invitation_of_friends_by_user_id(api_get_user_id());
  178. $list_get_path_web = SocialManager::get_list_web_path_user_invitation_by_user_id(api_get_user_id());
  179. $count_pending_invitations = count($pending_invitations);
  180. }
  181. if (!empty($production_list) || !empty($file_list) || $count_pending_invitations > 0) {
  182. // Pending invitations
  183. if (!isset($_GET['u']) || (isset($_GET['u']) && $_GET['u'] == api_get_user_id())) {
  184. if ($count_pending_invitations > 0) {
  185. $invitations = '<ul class="list-group">';
  186. for ($i = 0; $i < $count_pending_invitations; $i++) {
  187. $user_invitation_id = $pending_invitations[$i]['user_sender_id'];
  188. $invitations .= '<li id="dpending_'.$user_invitation_id.'" class="list-group-item">';
  189. $invitations .= '<img class="img-rounded" '
  190. .' src="'.$list_get_path_web[$i]['dir'].'/'.$list_get_path_web[$i]['file'].'"'
  191. .' width="40px">';
  192. $userInfo = api_get_user_info($user_invitation_id);
  193. $invitations .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php?u='.$user_invitation_id.'">'
  194. .api_get_person_name($userInfo['firstname'], $userInfo['lastname']).'</a>';
  195. $invitations .= '<div class="pull-right">';
  196. $invitations .= Display::toolbarButton(
  197. get_lang('Add to my contacts'),
  198. api_get_path(WEB_AJAX_PATH).'social.ajax.php?'.http_build_query([
  199. 'a' => 'add_friend',
  200. 'friend_id' => $user_invitation_id,
  201. 'is_my_friend' => 'friend',
  202. ]),
  203. 'plus',
  204. 'default',
  205. ['class' => 'btn-sm'],
  206. false
  207. );
  208. $invitations .= '</div>';
  209. $invitations .= '<div id="id_response"></div>';
  210. $invitations .= '</li>';
  211. }
  212. $invitations .= '</ul>';
  213. $listInvitations = Display::panelCollapse(
  214. get_lang('Pending invitations'),
  215. $invitations,
  216. 'invitations',
  217. null,
  218. 'invitations-acordion',
  219. 'invitations-collapse'
  220. );
  221. }
  222. }
  223. // Productions
  224. $production_list = UserManager::build_production_list($user_id);
  225. $product_content = '';
  226. if (!empty($production_list)) {
  227. $product_content .= '<div><h3>'.get_lang('My productions').'</h3></div>';
  228. $product_content .= $production_list;
  229. $socialRightInformation .= SocialManager::social_wrapper_div($product_content, 4);
  230. }
  231. $images_uploaded = null;
  232. // Images uploaded by course
  233. /*if (!empty($file_list)) {
  234. $images_uploaded .= '<div><h3>'.get_lang('Uploaded images').'</h3></div>';
  235. $images_uploaded .= '<div class="social-content-information">';
  236. $images_uploaded .= $file_list;
  237. $images_uploaded .= '</div>';
  238. $socialRightInformation .= SocialManager::social_wrapper_div($images_uploaded, 4);
  239. }*/
  240. }
  241. if (!empty($user_info['competences']) || !empty($user_info['diplomas'])
  242. || !empty($user_info['openarea']) || !empty($user_info['teach'])) {
  243. $more_info .= '<div><h3>'.get_lang('More information').'</h3></div>';
  244. if (!empty($user_info['competences'])) {
  245. $more_info .= '<br />';
  246. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('My competences').'</strong></div>';
  247. $more_info .= '<div class="social-profile-extended">'.$user_info['competences'].'</div>';
  248. $more_info .= '<br />';
  249. }
  250. if (!empty($user_info['diplomas'])) {
  251. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('My diplomas').'</strong></div>';
  252. $more_info .= '<div class="social-profile-extended">'.$user_info['diplomas'].'</div>';
  253. $more_info .= '<br />';
  254. }
  255. if (!empty($user_info['openarea'])) {
  256. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('My personal open area').'</strong></div>';
  257. $more_info .= '<div class="social-profile-extended">'.$user_info['openarea'].'</div>';
  258. $more_info .= '<br />';
  259. }
  260. if (!empty($user_info['teach'])) {
  261. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('What I am able to teach').'</strong></div>';
  262. $more_info .= '<div class="social-profile-extended">'.$user_info['teach'].'</div>';
  263. $more_info .= '<br />';
  264. }
  265. $socialRightInformation .= SocialManager::social_wrapper_div($more_info, 4);
  266. }
  267. }
  268. $tpl = new Template(get_lang('Social'));
  269. // Block Avatar Social
  270. SocialManager::setSocialUserBlock(
  271. $tpl,
  272. $friendId,
  273. 'shared_profile',
  274. 0,
  275. $show_full_profile
  276. );
  277. $tpl->assign('social_friend_block', $friend_html);
  278. $tpl->assign('social_menu_block', $menu);
  279. $tpl->assign('add_post_form', $addPostForm);
  280. $tpl->assign('posts', $posts);
  281. $tpl->assign('social_course_block', $social_course_block);
  282. $tpl->assign('social_group_info_block', $social_group_info_block);
  283. $tpl->assign('social_rss_block', $social_rss_block);
  284. $tpl->assign('social_skill_block', SocialManager::getSkillBlock($friendId, 'vertical'));
  285. $tpl->assign('session_list', $social_session_block);
  286. $tpl->assign('invitations', $listInvitations);
  287. $tpl->assign('social_right_information', $socialRightInformation);
  288. $tpl->assign('social_auto_extend_link', $socialAutoExtendLink);
  289. $formModalTpl = new Template();
  290. $formModalTpl->assign('invitation_form', MessageManager::generate_invitation_form());
  291. $template = $formModalTpl->get_template('social/form_modals.tpl');
  292. $formModals = $formModalTpl->fetch($template);
  293. $tpl->assign('form_modals', $formModals);
  294. $social_layout = $tpl->get_template('social/profile.tpl');
  295. $tpl->display($social_layout);