profile.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is the profile social main page
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. * @author Isaac Flores Paz <florespaz_isaac@hotmail.com>
  7. * @package chamilo.social
  8. */
  9. $language_file = array('userInfo', 'index');
  10. $cidReset = true;
  11. require_once '../inc/global.inc.php';
  12. // Include OpenGraph NOT AVAILABLE
  13. require_once api_get_path(LIBRARY_PATH).'opengraph/OpenGraph.php';
  14. if (api_get_setting('allow_social_tool') !='true') {
  15. $url = api_get_path(WEB_PATH).'whoisonline.php?id='.intval($_GET['u']);
  16. header('Location: '.$url);
  17. exit;
  18. }
  19. $user_id = api_get_user_id();
  20. $friendId = isset($_GET['u']) ? intval($_GET['u']) : api_get_user_id();
  21. $isAdmin = api_is_platform_admin($user_id);
  22. $show_full_profile = true;
  23. //social tab
  24. $this_section = SECTION_SOCIAL;
  25. //Initialize blocks
  26. $social_extra_info_block = null;
  27. $social_course_block = null;
  28. $social_group_info_block = null;
  29. $social_rss_block = null;
  30. $social_skill_block = null;
  31. $social_session_block = null;
  32. if (!empty($_POST['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp_name'])) {
  33. $messageId = 0;
  34. $idMessage = SocialManager::sendWallMessage(api_get_user_id(), $friendId, $_POST['social_wall_new_msg_main'], $messageId, MESSAGE_STATUS_WALL_POST);
  35. if (!empty($_FILES['picture']['tmp_name']) && $idMessage > 0) {
  36. $error = SocialManager::sendWallMessageAttachmentFile(api_get_user_id(), $_FILES['picture'], $idMessage, $fileComment = '');
  37. }
  38. $url = api_get_path(WEB_CODE_PATH) . 'social/profile.php';
  39. $url .= empty($_SERVER['QUERY_STRING']) ? '' : '?'.Security::remove_XSS($_SERVER['QUERY_STRING']);
  40. header('Location: ' . $url);
  41. exit;
  42. } else if (!empty($_POST['social_wall_new_msg']) && !empty($_POST['messageId'])) {
  43. $messageId = intval($_POST['messageId']);
  44. $res = SocialManager::sendWallMessage(api_get_user_id(), $friendId, $_POST['social_wall_new_msg'], $messageId , MESSAGE_STATUS_WALL);
  45. $url = api_get_path(WEB_CODE_PATH) . 'social/profile.php';
  46. $url .= empty($_SERVER['QUERY_STRING']) ? '' : '?'.Security::remove_XSS($_SERVER['QUERY_STRING']);
  47. header('Location: ' . $url);
  48. exit;
  49. } else if (isset($_GET['messageId'])) {
  50. $messageId = Security::remove_XSS($_GET['messageId']);
  51. $status = SocialManager::deleteMessage($messageId);
  52. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'social/profile.php');
  53. exit;
  54. } else if (isset($_GET['u'])) { //I'm your friend? I can see your profile?
  55. $user_id = intval($_GET['u']);
  56. if (api_is_anonymous($user_id, true)) {
  57. api_not_allowed(true);
  58. }
  59. // It's me!
  60. if (api_get_user_id() != $user_id) {
  61. $user_info = UserManager::get_user_info_by_id($user_id);
  62. $show_full_profile = false;
  63. if (!$user_info) {
  64. // user does no exist !!
  65. api_not_allowed(true);
  66. } else {
  67. //checking the relationship between me and my friend
  68. $my_status= SocialManager::get_relation_between_contacts(api_get_user_id(), $user_id);
  69. if (in_array($my_status, array(
  70. USER_RELATION_TYPE_PARENT,
  71. USER_RELATION_TYPE_FRIEND,
  72. USER_RELATION_TYPE_GOODFRIEND
  73. ))) {
  74. $show_full_profile = true;
  75. }
  76. //checking the relationship between my friend and me
  77. $my_friend_status = SocialManager::get_relation_between_contacts($user_id, api_get_user_id());
  78. if (in_array($my_friend_status, array(
  79. USER_RELATION_TYPE_PARENT,
  80. USER_RELATION_TYPE_FRIEND,
  81. USER_RELATION_TYPE_GOODFRIEND
  82. ))) {
  83. $show_full_profile = true;
  84. } else {
  85. // im probably not a good friend
  86. $show_full_profile = false;
  87. }
  88. }
  89. } else {
  90. $user_info = UserManager::get_user_info_by_id($user_id);
  91. }
  92. } else {
  93. $user_info = UserManager::get_user_info_by_id($user_id);
  94. }
  95. if ($user_info['user_id'] == api_get_user_id()) {
  96. $isSelfUser = true;
  97. } else {
  98. $isSelfUser = false;
  99. }
  100. $userIsOnline = user_is_online($user_id);
  101. $libpath = api_get_path(LIBRARY_PATH);
  102. require_once api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php';
  103. require_once $libpath.'magpierss/rss_fetch.inc';
  104. $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php';
  105. $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php';
  106. $javascriptDir = api_get_path(LIBRARY_PATH) . 'javascript/';
  107. api_block_anonymous_users();
  108. $locale = _api_get_locale_from_language();
  109. // Add Jquery scroll pagination plugin
  110. $htmlHeadXtra[] = api_get_js('jscroll/jquery.jscroll.js');
  111. // Add Jquery Time ago plugin
  112. $htmlHeadXtra[] = api_get_js('jquery-timeago/jquery.timeago.js');
  113. $timeAgoLocaleDir = $javascriptDir . 'jquery-timeago/locales/jquery.timeago.' . $locale . '.js';
  114. if (file_exists($timeAgoLocaleDir)) {
  115. $htmlHeadXtra[] = api_get_js('jquery-timeago/locales/jquery.timeago.' . $locale . '.js');
  116. }
  117. $htmlHeadXtra[] = '<script>
  118. function checkLength( o, n, min, max ) {
  119. if ( o.val().length > max || o.val().length < min ) {
  120. o.addClass( "ui-state-error" );
  121. //updateTips( "Length of " + n + " must be between " + min + " and " + max + "." );
  122. return false;
  123. } else {
  124. return true;
  125. }
  126. }
  127. function send_message_to_user(user_id) {
  128. var subject = $( "#subject_id" );
  129. var content = $( "#content_id" );
  130. $("#send_message_form").show();
  131. $("#send_message_div").dialog({
  132. modal:true,
  133. height:350,
  134. buttons: {
  135. "'. addslashes(get_lang('Send')).'": function() {
  136. var bValid = true;
  137. bValid = bValid && checkLength( subject, "subject", 1, 255 );
  138. bValid = bValid && checkLength( content, "content", 1, 255 );
  139. if ( bValid ) {
  140. var url = "'.$ajax_url.'?a=send_message&user_id="+user_id;
  141. var params = $("#send_message_form").serialize();
  142. $.ajax({
  143. url: url+"&"+params,
  144. success:function(data) {
  145. $("#message_ajax_reponse").attr("class", "");
  146. $("#message_ajax_reponse").html(data);
  147. $("#message_ajax_reponse").show();
  148. $("#send_message_div").dialog({ buttons:{}});
  149. $("#send_message_form").hide();
  150. $("#send_message_div").dialog("close");
  151. $("#subject_id").val("");
  152. $("#content_id").val("");
  153. }
  154. });
  155. }
  156. }
  157. },
  158. close: function() {
  159. }
  160. });
  161. $("#send_message_div").dialog("open");
  162. //prevent the browser to follow the link
  163. }
  164. function send_invitation_to_user(user_id) {
  165. var content = $( "#content_invitation_id" );
  166. $("#send_invitation_form").show();
  167. $("#send_invitation_div").dialog({
  168. modal:true,
  169. buttons: {
  170. "'. addslashes(get_lang('SendInvitation')).'": function() {
  171. var bValid = true;
  172. bValid = bValid && checkLength( content, "content", 1, 255 );
  173. if (bValid) {
  174. var url = "'.$ajax_url.'?a=send_invitation&user_id="+user_id;
  175. var params = $("#send_invitation_form").serialize();
  176. $.ajax({
  177. url: url+"&"+params,
  178. success:function(data) {
  179. $("#message_ajax_reponse").attr("class", "");
  180. $("#message_ajax_reponse").html(data);
  181. $("#message_ajax_reponse").show();
  182. $("#send_invitation_div").dialog({ buttons:{}});
  183. $("#send_invitation_form").hide();
  184. $("#send_invitation_div").dialog("close");
  185. $("#content_invitation_id").val("");
  186. }
  187. });
  188. }
  189. },
  190. },
  191. close: function() {
  192. }
  193. });
  194. $("#send_invitation_div").dialog("open");
  195. //prevent the browser to follow the link
  196. }
  197. function toogle_course (element_html, course_code){
  198. elem_id=$(element_html).attr("id");
  199. id_elem=elem_id.split("_");
  200. ident="div#div_group_"+id_elem[1];
  201. id_button="#btn_"+id_elem[1];
  202. elem_src=$(id_button).attr("src");
  203. image_show=elem_src.split("/");
  204. my_image=image_show[2];
  205. var content = \'social_content\' + id_elem[1];
  206. if (my_image=="nolines_plus.gif") {
  207. $(id_button).attr("src","../img/nolines_minus.gif"); var action = "load_course";
  208. $("div#"+content).show("fast");
  209. } else {
  210. $("div#"+content).hide("fast");
  211. $(id_button).attr("src","../img/nolines_plus.gif"); var action = "unload";
  212. return false;
  213. }
  214. $.ajax({
  215. contentType: "application/x-www-form-urlencoded",
  216. beforeSend: function(objeto) {
  217. $("div#"+content).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  218. type: "POST",
  219. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=toogle_course",
  220. data: "load_ajax="+id_elem+"&action="+action+"&course_code="+course_code,
  221. success: function(datos) {
  222. $("div#"+content).html(datos);
  223. }
  224. });
  225. }
  226. $(document).ready(function (){
  227. $("input#id_btn_send_invitation").bind("click", function(){
  228. if (confirm("'.get_lang('SendMessageInvitation', '').'")) {
  229. $("#form_register_friend").submit();
  230. }
  231. });
  232. $("#send_message_div").dialog({
  233. autoOpen: false,
  234. modal : false,
  235. width : 550,
  236. height : 300
  237. });
  238. $("#send_invitation_div").dialog({
  239. autoOpen: false,
  240. modal : false,
  241. width : 550,
  242. height : 300
  243. });
  244. var container = $("#wallMessages");
  245. container.jscroll({
  246. loadingHtml: "<div class=\"well_border\">' . get_lang('Loading') . ' </div>",
  247. nextSelector: "a.nextPage:last",
  248. contentSelector: "",
  249. callback: timeAgo
  250. });
  251. timeAgo()
  252. });
  253. function timeAgo() {
  254. $(".timeago").timeago();
  255. }
  256. function display_hide () {
  257. setTimeout("hide_display_message()",3000);
  258. }
  259. function hide_display_message () {
  260. $("div#display_response_id").html("");
  261. try {
  262. $("#txt_subject_id").val("");
  263. $("#txt_area_invite").val("");
  264. }catch(e) {
  265. $("#txt_area_invite").val("");
  266. }
  267. }
  268. function register_friend(element_input) {
  269. if(confirm("'.get_lang('AddToFriends').'")) {
  270. name_button=$(element_input).attr("id");
  271. name_div_id="id_"+name_button.substring(13);
  272. user_id=name_div_id.split("_");
  273. user_friend_id=user_id[1];
  274. $.ajax({
  275. contentType: "application/x-www-form-urlencoded",
  276. beforeSend: function(objeto) {
  277. $("div#dpending_"+user_friend_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />");
  278. },
  279. type: "POST",
  280. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=add_friend",
  281. data: "friend_id="+user_friend_id+"&is_my_friend="+"friend",
  282. success: function(datos) {
  283. $("#dpending_" + user_friend_id).html(datos);
  284. }
  285. });
  286. }
  287. }
  288. </script>';
  289. $nametool = get_lang('ViewMySharedProfile');
  290. if (isset($_GET['shared'])) {
  291. $my_link='../social/profile.php';
  292. $link_shared='shared='.Security::remove_XSS($_GET['shared']);
  293. } else {
  294. $my_link='../social/profile.php';
  295. $link_shared='';
  296. }
  297. $interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('SocialNetwork') );
  298. if (isset($_GET['u']) && is_numeric($_GET['u']) && $_GET['u'] != api_get_user_id()) {
  299. $info_user = api_get_user_info($_GET['u']);
  300. $interbreadcrumb[]= array (
  301. 'url' => '#',
  302. 'name' => api_get_person_name($info_user['firstName'], $info_user['lastName']));
  303. $nametool = '';
  304. }
  305. if (isset($_GET['u'])) {
  306. $param_user='u='.Security::remove_XSS($_GET['u']);
  307. }else {
  308. $info_user = api_get_user_info(api_get_user_id());
  309. $param_user = '';
  310. }
  311. $_SESSION['social_user_id'] = intval($user_id);
  312. /**
  313. * Display
  314. */
  315. //Setting some course info
  316. $my_user_id = isset($_GET['u']) ? Security::remove_XSS($_GET['u']) : api_get_user_id();
  317. $personal_course_list = UserManager::get_personal_session_course_list($my_user_id);
  318. $course_list_code = array();
  319. $i=1;
  320. if (is_array($personal_course_list)) {
  321. foreach ($personal_course_list as $my_course) {
  322. if ($i<=10) {
  323. $list[] = SocialManager::get_logged_user_course_html($my_course, $i);
  324. $course_list_code[] = array('code'=> $my_course['code']);
  325. } else {
  326. break;
  327. }
  328. $i++;
  329. }
  330. //to avoid repeted courses
  331. $course_list_code = array_unique_dimensional($course_list_code);
  332. }
  333. //Block Avatar Social
  334. $social_avatar_block = '<div class="panel panel-default social-avatar">';
  335. $social_avatar_block .= SocialManager::show_social_avatar_block('shared_profile', null, $user_id);
  336. $social_avatar_block .= '<div class="lastname">'.$user_info['lastname'].'</div>';
  337. $social_avatar_block .= '<div class="firstname">'.$user_info['firstname'].'</div>';
  338. /* $social_avatar_block .= '<div class="username">'.Display::return_icon('user.png','','',ICON_SIZE_TINY).$user_info['username'].'</div>'; */
  339. $social_avatar_block .= '<div class="email">'.Display::return_icon('instant_message.png').'&nbsp;' .$user_info['email'].'</div>';
  340. $chat_status = $user_info['extra'];
  341. if(!empty($chat_status['user_chat_status'])){
  342. $social_avatar_block.= '<div class="status">'.Display::return_icon('online.png').get_lang('Chat')." (".get_lang('Online').')</div>';
  343. }else{
  344. $social_avatar_block.= '<div class="status">'.Display::return_icon('offline.png').get_lang('Chat')." (".get_lang('Offline').')</div>';
  345. }
  346. if (api_get_user_id() === $friendId) {
  347. $editProfileUrl = Display::getProfileEditionLink(api_get_user_id());
  348. $social_avatar_block .= '<div class="edit-profile">
  349. <a class="btn" href="' . $editProfileUrl . '">' . get_lang('EditProfile') . '</a>
  350. </div>';
  351. }
  352. $social_avatar_block .= '</div>';
  353. //Social Block Menu
  354. $social_menu_block = SocialManager::show_social_menu('shared_profile', null, $user_id, $show_full_profile);
  355. //Setting some session info
  356. $user_info = api_get_user_info($my_user_id);
  357. $sessionList = SessionManager::getSessionsFollowedByUser($my_user_id, $user_info['status']);
  358. $htmlSessionList = null;
  359. foreach ($sessionList as $session) {
  360. $htmlSessionList .= '<div>';
  361. $htmlSessionList .= Display::return_icon('session.png', get_lang('Session'));
  362. $htmlSessionList .= $session['name'];
  363. $htmlSessionList .= '</div>';
  364. }
  365. // My friends
  366. $friend_html = listMyFriends($user_id, $link_shared ,$show_full_profile);
  367. $social_left_content = '<div class="well sidebar-nav">' .$friend_html . '</div>';
  368. /*
  369. $personal_info = null;
  370. if (!empty($user_info['firstname']) || !empty($user_info['lastname'])) {
  371. $personal_info .= '<div><h3>'.api_get_person_name($user_info['firstname'], $user_info['lastname']).'</h3></div>';
  372. } else {
  373. //--- Basic Information
  374. $personal_info .= '<div><h3>'.get_lang('Profile').'</h3></div>';
  375. }
  376. if ($show_full_profile) {
  377. $personal_info .= '<dl class="dl-horizontal">';
  378. if ($isAdmin || $isSelfUser) {
  379. $personal_info .= '<dt>'.get_lang('UserName').'</dt><dd>'. $user_info['username'].' </dd>';
  380. }
  381. if (!empty($user_info['firstname']) || !empty($user_info['lastname'])) {
  382. $personal_info .= '<dt>'.get_lang('Name')
  383. .'</dt><dd>'. api_get_person_name($user_info['firstname'], $user_info['lastname']).'</dd>';
  384. }
  385. if (($isAdmin || $isSelfUser) && !empty($user_info['official_code'])) {
  386. $personal_info .= '<dt>'.get_lang('OfficialCode').'</dt><dd>'.$user_info['official_code'].'</dd>';
  387. }
  388. if (!empty($user_info['email'])) {
  389. if (api_get_setting('show_email_addresses')=='true') {
  390. $personal_info .= '<dt>'.get_lang('Email').'</dt><dd>'.$user_info['email'].'</dd>';
  391. }
  392. if (!empty($user_info['phone'])) {
  393. $personal_info .= '<dt>'.get_lang('Phone').'</dt><dd>'. $user_info['phone'].'</dd>';
  394. }
  395. $personal_info .= '</dl>';
  396. }
  397. } else {
  398. $personal_info .= '<dl class="dl-horizontal">';
  399. if (!empty($user_info['username'])) {
  400. if ($isAdmin || $isSelfUser) {
  401. $personal_info .= '<dt>'.get_lang('UserName').'</dt><dd>'. $user_info['username'].'</dd>';
  402. }
  403. }
  404. $personal_info .= '</dl>';
  405. }
  406. */
  407. //Social Block Wall
  408. $wallSocialAddPost = wallSocialAddPost();
  409. $social_wall_block = $wallSocialAddPost;
  410. //Social Post Wall
  411. $post_wall = wallSocialPost($my_user_id,$friendId) ;
  412. $social_post_wall_block = '<div class="panel panel-default social-post">';
  413. $social_post_wall_block .= '<div class="panel-heading">Mis publicaciones</div>';
  414. $social_post_wall_block .='<div class="panel-body">';
  415. if(empty($post_wall)){
  416. $social_post_wall_block .= '<p>'.get_lang("NoPosts").'</p>';
  417. }else{
  418. $social_post_wall_block .= $post_wall;
  419. }
  420. $social_post_wall_block .= '</div></div>';
  421. $socialAutoExtendLink = Display::url(
  422. get_lang('SeeMore'),
  423. $socialAjaxUrl . '?u='. $my_user_id . '&a=listWallMessage&start=10&length=5',
  424. array(
  425. 'class' => 'nextPage next',
  426. )
  427. );
  428. /* $socialRightInformation = SocialManager::social_wrapper_div($personal_info, 4); */
  429. $socialRightInformation = null;
  430. //$social_right_content .= SocialManager::social_wrapper_div($wallSocial, 5);
  431. $social_right_content = null;
  432. if ($show_full_profile) {
  433. // Block Extra information
  434. $t_uf = Database :: get_main_table(TABLE_MAIN_USER_FIELD);
  435. $t_ufo = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
  436. $extra_user_data = UserManager::get_extra_user_data($user_id);
  437. $extra_information = '';
  438. if (is_array($extra_user_data) && count($extra_user_data)>0 ) {
  439. $extra_information .= '<div class="panel panel-default">';
  440. $extra_information .= '<div class="panel-heading">'.get_lang('ExtraInformation').'</div>';
  441. $extra_information .='<div class="panel-body">';
  442. $extra_information_value = '';
  443. foreach($extra_user_data as $key=>$data) {
  444. //Avoding parameters
  445. if (in_array($key, array('mail_notify_invitation','mail_notify_message', 'mail_notify_group_message' ))) {
  446. continue;
  447. }
  448. // get display text, visibility and type from user_field table
  449. $field_variable = str_replace('extra_','',$key);
  450. $sql = "SELECT field_display_text,field_visible,field_type,id "
  451. ." FROM $t_uf WHERE field_variable ='$field_variable'";
  452. $res_field = Database::query($sql);
  453. $row_field = Database::fetch_row($res_field);
  454. $field_display_text = $row_field[0];
  455. $field_visible = $row_field[1];
  456. $field_type = $row_field[2];
  457. $field_id = $row_field[3];
  458. if ($field_visible == 1) {
  459. if (is_array($data)) {
  460. $extra_information_value .= '<dt>'.ucfirst($field_display_text).'</dt>'
  461. .'<dd> '.implode(',',$data).'</dd>';
  462. } else {
  463. if ($field_type == UserManager::USER_FIELD_TYPE_DOUBLE_SELECT) {
  464. $id_options = explode(';',$data);
  465. $value_options = array();
  466. // get option display text from user_field_options table
  467. foreach ($id_options as $id_option) {
  468. $sql = "SELECT option_display_text FROM $t_ufo WHERE id = '$id_option'";
  469. $res_options = Database::query($sql);
  470. $row_options = Database::fetch_row($res_options);
  471. $value_options[] = $row_options[0];
  472. }
  473. $extra_information_value .= '<dt>'.ucfirst($field_display_text).':</dt>'
  474. .'<dd>'.implode(' ',$value_options).'</dd>';
  475. } elseif ($field_type == UserManager::USER_FIELD_TYPE_TAG ) {
  476. $user_tags = UserManager::get_user_tags($user_id, $field_id);
  477. $tag_tmp = array();
  478. foreach ($user_tags as $tags) {
  479. $tag_tmp[] = '<a class="label label_tag"'
  480. .' href="'.api_get_path(WEB_PATH).'main/social/search.php?q='.$tags['tag'].'">'
  481. .$tags['tag']
  482. .'</a>';
  483. }
  484. if (is_array($user_tags) && count($user_tags)>0) {
  485. $extra_information_value .= '<dt>'.ucfirst($field_display_text).':</dt>'
  486. .'<dd>'.implode('', $tag_tmp).'</dd>';
  487. }
  488. } elseif ($field_type == UserManager::USER_FIELD_TYPE_SOCIAL_PROFILE) {
  489. $icon_path = UserManager::get_favicon_from_url($data);
  490. $bottom = '0.2';
  491. //quick hack for hi5
  492. $domain = parse_url($icon_path, PHP_URL_HOST);
  493. if ($domain == 'www.hi5.com' or $domain == 'hi5.com') {
  494. $bottom = '-0.8';
  495. }
  496. $data = '<a href="'.$data.'">'
  497. .'<img src="'.$icon_path.'" alt="icon"'
  498. .' style="margin-right:0.5em;margin-bottom:'.$bottom.'em;" />'
  499. .$field_display_text
  500. .'</a>';
  501. $extra_information_value .= '<dd>'.$data.'</dd>';
  502. } else {
  503. if (!empty($data)) {
  504. $extra_information_value .= '<dt>'.ucfirst($field_display_text).':</dt><dd>'.$data.'</dd>';
  505. }
  506. }
  507. }
  508. }
  509. }
  510. // if there are information to show
  511. if (!empty($extra_information_value)) {
  512. $extra_information .= $extra_information_value;
  513. }
  514. $extra_information .= '</div></div>'; //social-profile-info
  515. }
  516. //If there are information to show Block Extra Information
  517. if (!empty($extra_information_value)) {
  518. $social_extra_info_block = $extra_information;
  519. }
  520. // MY GROUPS
  521. $results = GroupPortalManager::get_groups_by_user($my_user_id, 0);
  522. $grid_my_groups = array();
  523. $max_numbers_of_group = 4;
  524. if (is_array($results) && count($results) > 0) {
  525. $i = 1;
  526. foreach ($results as $result) {
  527. if ($i > $max_numbers_of_group) break;
  528. $id = $result['id'];
  529. $url_open = '<a href="groups.php?id='.$id.'">';
  530. $url_close = '</a>';
  531. $icon = '';
  532. $name = cut($result['name'],CUT_GROUP_NAME,true);
  533. if ($result['relation_type'] == GROUP_USER_PERMISSION_ADMIN) {
  534. $icon = Display::return_icon(
  535. 'social_group_admin.png',
  536. get_lang('Admin'),
  537. array('style'=>'vertical-align:middle;width:16px;height:16px;')
  538. );
  539. } elseif ($result['relation_type'] == GROUP_USER_PERMISSION_MODERATOR) {
  540. $icon = Display::return_icon(
  541. 'social_group_moderator.png',
  542. get_lang('Moderator'),
  543. array('style'=>'vertical-align:middle;width:16px;height:16px;')
  544. );
  545. }
  546. $count_users_group = count(GroupPortalManager::get_all_users_by_group($id));
  547. if ($count_users_group == 1 ) {
  548. $count_users_group = $count_users_group.' '.get_lang('Member');
  549. } else {
  550. $count_users_group = $count_users_group.' '.get_lang('Members');
  551. }
  552. //$picture = GroupPortalManager::get_picture_group($result['id'], $result['picture_uri'],80);
  553. $item_name = $url_open.$name.$icon.$url_close;
  554. if ($result['description'] != '') {
  555. //$item_description = '<div class="box_shared_profile_group_description">'
  556. //.'<p class="social-groups-text4">'.cut($result['description'],100,true).'</p></div>';
  557. } else {
  558. //$item_description = '<div class="box_shared_profile_group_description">'
  559. //.'<span class="social-groups-text2"></span><p class="social-groups-text4"></p></div>';
  560. }
  561. //$result['picture_uri'] = '<div class="box_shared_profile_group_image">'
  562. //.'<img class="social-groups-image" src="'.$picture['file'].'" hspace="4" height="50"'
  563. //.' border="2" align="left" width="50" /></div>';
  564. $item_actions = '';
  565. //if (api_get_user_id() == $user_id) {
  566. //$item_actions = '<div class="box_shared_profile_group_actions"><a href="groups.php?id='.$id.'">'
  567. //.get_lang('SeeMore').$url_close.'</div>';
  568. //}
  569. $grid_my_groups[]= array($item_name,$url_open.$result['picture_uri'].$url_close, $item_actions);
  570. $i++;
  571. }
  572. }
  573. //Block My Groups
  574. if (count($grid_my_groups) > 0) {
  575. $my_groups = '';
  576. $count_groups = 0;
  577. if (count($results) == 1 ) {
  578. $count_groups = count($results);
  579. } else {
  580. $count_groups = count($results);
  581. }
  582. $my_groups .= '<div class="panel panel-default">';
  583. $my_groups .= '<div class="panel-heading">'.get_lang('MyGroups').' ('.$count_groups.') </div>';
  584. if ($i > $max_numbers_of_group) {
  585. if (api_get_user_id() == $user_id) {
  586. $my_groups .= '<div class="box_shared_profile_group_actions">'
  587. .'<a href="groups.php?#tab_browse-1">'.get_lang('SeeAllMyGroups').'</a></div>';
  588. } else {
  589. $my_groups .= '<div class="box_shared_profile_group_actions">'
  590. .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php'
  591. .'?view=mygroups&height=390&width=610&user_id='.$user_id.'"'
  592. .' class="thickbox" title="'.get_lang('SeeAll').'" >'
  593. .get_lang('SeeAllMyGroups')
  594. .'</a></div>';
  595. }
  596. }
  597. $total = count($grid_my_groups);
  598. $i = 1;
  599. foreach($grid_my_groups as $group) {
  600. $my_groups .= '<div class="panel-body">';
  601. $my_groups .= $group[0];
  602. $my_groups .= '</div>';
  603. if ($i < $total) {
  604. $my_groups .= ', ';
  605. }
  606. $i++;
  607. }
  608. $my_groups .= '</div>';
  609. $social_group_info_block = $my_groups;
  610. }
  611. //Block Social Course
  612. $my_courses = null;
  613. // COURSES LIST
  614. if ( is_array($list) ) {
  615. $my_courses .= '<div class="panel panel-default">';
  616. $my_courses .= '<div class="panel-heading">'.api_ucfirst(get_lang('MyCourses')).'</div>';
  617. $my_courses .= '<div class="panel-body">';
  618. //Courses without sessions
  619. $i=1;
  620. foreach ($list as $key => $value) {
  621. if ( empty($value[2]) ) { //if out of any session
  622. $my_courses .= $value[1];
  623. $my_courses .= '<div id="social_content'.$i.'"'
  624. .' class="course_social_content" style="display:none" >s</div>';
  625. $i++;
  626. }
  627. }
  628. $my_courses .= '</div></div>';
  629. $social_course_block .= $my_courses;
  630. }
  631. //Block Social Sessions
  632. if (count($sessionList) > 0) {
  633. $sessions = '<div class="panel panel-default">';
  634. $sessions .= '<div class="panel-heading">'.api_ucfirst(get_lang('MySessions')).'</div>';
  635. $sessions .= '<div class="panel-body">'.$htmlSessionList.'</div>';
  636. $sessions .= '</div>';
  637. $social_session_block = $sessions;
  638. }
  639. // Block Social User Feeds
  640. $user_feeds = SocialManager::get_user_feeds($user_id);
  641. if (!empty($user_feeds)) {
  642. $rss = '<div class="panel panel-default social-rss">';
  643. $rss .= '<div class="panel-heading">'.get_lang('RSSFeeds').'</div>';
  644. $rss .= '<div class="panel-body">'.$user_feeds.'</div></div>';
  645. $social_rss_block = $rss;
  646. }
  647. //BLock Social Skill
  648. if (api_get_setting('allow_skills_tool') == 'true') {
  649. $skill = new Skill();
  650. $ranking = $skill->get_user_skill_ranking($my_user_id);
  651. $skills = $skill->get_user_skills($my_user_id, true);
  652. $social_skill_block = '<div class="panel panel-default social-skill">';
  653. $social_skill_block .= '<div class="panel-heading">' . get_lang('Skills');
  654. $social_skill_block .= '<div class="btn-group pull-right"> <a class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" href="#">
  655. <span class="caret"></span></a>
  656. <ul class="dropdown-menu">';
  657. if (api_is_student() || api_is_student_boss() || api_is_drh()) {
  658. $social_skill_block .= '<li>' . Display::url(
  659. get_lang('SkillsReport'),
  660. api_get_path(WEB_CODE_PATH) . 'social/my_skills_report.php'
  661. ) . '</li>';
  662. }
  663. $social_skill_block .= '<li>' . Display::url(
  664. get_lang('SkillsWheel'),
  665. api_get_path(WEB_CODE_PATH) . 'social/skills_wheel.php'
  666. ) . '</li>';
  667. $social_skill_block .= '<li>' . Display::url(
  668. sprintf(get_lang('YourSkillRankingX'), $ranking),
  669. api_get_path(WEB_CODE_PATH) . 'social/skills_ranking.php'
  670. ) . '</li>';
  671. $social_skill_block .= '</ul></div></div>';
  672. $lis = '';
  673. if (!empty($skills)) {
  674. foreach ($skills as $skill) {
  675. $badgeImage = null;
  676. if (!empty($skill['icon'])) {
  677. $badgeImage = Display::img(
  678. api_get_path(WEB_DATA_PATH) . $skill['icon'],
  679. $skill['name']
  680. );
  681. } else {
  682. $badgeImage = Display::return_icon(
  683. 'badges-default.png',
  684. $skill['name'],
  685. array('title' => $skill['name']),ICON_SIZE_BIG
  686. );
  687. }
  688. $lis .= Display::tag(
  689. 'li',
  690. $badgeImage .
  691. '<div class="badges-name">' . $skill['name'] . '</div>'
  692. );
  693. }
  694. $social_skill_block .= '<div class="panel-body">';
  695. $social_skill_block .= Display::tag('ul', $lis, array('class' => 'list-badges'));
  696. $social_skill_block .= '</div>';
  697. }else{
  698. $social_skill_block .= '<div class="panel-body">';
  699. $social_skill_block .= '<p>'. get_lang("WithoutAchievedSkills") . '</p>';
  700. $social_skill_block .= '<p>' . Display::url(get_lang('SkillsWheel'),api_get_path(WEB_CODE_PATH) . 'social/skills_wheel.php').'</p>';
  701. $social_skill_block .= '</div>';
  702. }
  703. $social_skill_block.='</div>';
  704. }
  705. //--Productions
  706. $production_list = UserManager::build_production_list($user_id);
  707. // Images uploaded by course
  708. $file_list = '';
  709. if (is_array($course_list_code) && count($course_list_code)>0) {
  710. foreach ($course_list_code as $course) {
  711. $file_list.= UserManager::get_user_upload_files_by_course($user_id,$course['code'],$resourcetype='images');
  712. }
  713. }
  714. $count_pending_invitations = 0;
  715. if (!isset($_GET['u']) || (isset($_GET['u']) && $_GET['u']==api_get_user_id())) {
  716. $pending_invitations = SocialManager::get_list_invitation_of_friends_by_user_id(api_get_user_id());
  717. $list_get_path_web = SocialManager::get_list_web_path_user_invitation_by_user_id(api_get_user_id());
  718. $count_pending_invitations = count($pending_invitations);
  719. }
  720. if (!empty($production_list) || !empty($file_list) || $count_pending_invitations > 0) {
  721. //Pending invitations
  722. if (!isset($_GET['u']) || (isset($_GET['u']) && $_GET['u']==api_get_user_id())) {
  723. if ($count_pending_invitations > 0) {
  724. $invitations = '<div><h3>'.get_lang('PendingInvitations').'</h3></div>';
  725. for ($i=0;$i<$count_pending_invitations;$i++) {
  726. $user_invitation_id = $pending_invitations[$i]['user_sender_id'];
  727. $invitations .= '<div id="dpending_'.$user_invitation_id.'" class="friend_invitations">';
  728. $invitations .= '<div style="float:left;width:60px;" >';
  729. $invitations .= '<img style="margin-bottom:5px;"'
  730. .' src="'.$list_get_path_web[$i]['dir'].'/'.$list_get_path_web[$i]['file'].'"'
  731. .' width="60px">';
  732. $invitations .= '</div>';
  733. $invitations .= '<div style="padding-left:70px;">';
  734. $user_invitation_info = api_get_user_info($user_invitation_id);
  735. $invitations .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php'
  736. .'?u='.$user_invitation_id.'">'
  737. .api_get_person_name(
  738. $user_invitation_info['firstname'],
  739. $user_invitation_info['lastname'])
  740. .'</a>';
  741. $invitations .= '<br />';
  742. $invitations .= Security::remove_XSS(
  743. cut($pending_invitations[$i]['content'], 50),
  744. STUDENT,
  745. true
  746. );
  747. $invitations .= '<br />';
  748. $invitations .= '<a id="btn_accepted_'.$user_invitation_id.'"'
  749. .' class="btn" onclick="register_friend(this)" href="javascript:void(0)">'
  750. .get_lang('SocialAddToFriends')
  751. .'</a>';
  752. $invitations .= '<div id="id_response"></div>';
  753. $invitations .= '</div>';
  754. $invitations .= '</div>';
  755. }
  756. $socialRightInformation .= SocialManager::social_wrapper_div($invitations, 4);
  757. }
  758. }
  759. //--Productions
  760. $production_list = UserManager::build_production_list($user_id);
  761. $product_content = '';
  762. if (!empty($production_list)) {
  763. $product_content .= '<div><h3>'.get_lang('MyProductions').'</h3></div>';
  764. $product_content .= $production_list;
  765. $socialRightInformation .= SocialManager::social_wrapper_div($product_content, 4);
  766. }
  767. $images_uploaded = null;
  768. // Images uploaded by course
  769. if (!empty($file_list)) {
  770. $images_uploaded .= '<div><h3>'.get_lang('ImagesUploaded').'</h3></div>';
  771. $images_uploaded .= '<div class="social-content-information">';
  772. $images_uploaded .= $file_list;
  773. $images_uploaded .= '</div>';
  774. $socialRightInformation .= SocialManager::social_wrapper_div($images_uploaded, 4);
  775. }
  776. }
  777. if (!empty($user_info['competences']) || !empty($user_info['diplomas'])
  778. || !empty($user_info['openarea']) || !empty($user_info['teach']) ) {
  779. $more_info .= '<div><h3>'.get_lang('MoreInformation').'</h3></div>';
  780. if (!empty($user_info['competences'])) {
  781. $more_info .= '<br />';
  782. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyCompetences').'</strong></div>';
  783. $more_info .= '<div class="social-profile-extended">'.$user_info['competences'].'</div>';
  784. $more_info .= '<br />';
  785. }
  786. if (!empty($user_info['diplomas'])) {
  787. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyDiplomas').'</strong></div>';
  788. $more_info .= '<div class="social-profile-extended">'.$user_info['diplomas'].'</div>';
  789. $more_info .= '<br />';
  790. }
  791. if (!empty($user_info['openarea'])) {
  792. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div>';
  793. $more_info .= '<div class="social-profile-extended">'.$user_info['openarea'].'</div>';
  794. $more_info .= '<br />';
  795. }
  796. if (!empty($user_info['teach'])) {
  797. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyTeach').'</strong></div>';
  798. $more_info .= '<div class="social-profile-extended">'.$user_info['teach'].'</div>';
  799. $more_info .= '<br />';
  800. }
  801. $socialRightInformation .= SocialManager::social_wrapper_div($more_info, 4);
  802. }
  803. }
  804. $social_right_content .= MessageManager::generate_message_form('send_message');
  805. $social_right_content .= MessageManager::generate_invitation_form('send_invitation');
  806. $tpl = new Template(get_lang('Social'));
  807. $tpl->assign('social_avatar_block', $social_avatar_block);
  808. $tpl->assign('social_menu_block', $social_menu_block);
  809. $tpl->assign('social_wall_block', $social_wall_block);
  810. $tpl->assign('social_post_wall_block', $social_post_wall_block);
  811. $tpl->assign('social_extra_info_block', $social_extra_info_block);
  812. $tpl->assign('social_course_block', $social_course_block);
  813. $tpl->assign('social_group_info_block', $social_group_info_block);
  814. $tpl->assign('social_rss_block', $social_rss_block);
  815. $tpl->assign('social_skill_block', $social_skill_block);
  816. $tpl->assign('social_session_block', $social_session_block);
  817. $tpl->assign('socialRightInformation', $socialRightInformation);
  818. $tpl->assign('socialAutoExtendLink', $socialAutoExtendLink);
  819. $social_layout = $tpl->get_template('social/profile.tpl');
  820. $tpl->display($social_layout);
  821. /*
  822. * function list my friends
  823. */
  824. function listMyFriends($user_id, $link_shared, $show_full_profile)
  825. {
  826. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
  827. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  828. $friendHtml = '';
  829. $number_of_images = 30;
  830. $number_friends = 0;
  831. $number_friends = count($friends);
  832. $friendHtml = '<div class="nav-list"><h3>'.get_lang('SocialFriend').'<span>(' . $number_friends . ')</span></h3></div>';
  833. if ($number_friends != 0) {
  834. if ($number_friends > $number_of_images) {
  835. if (api_get_user_id() == $user_id) {
  836. $friendHtml.= ' : <span><a href="friends.php">'.get_lang('SeeAll').'</a></span>';
  837. } else {
  838. $friendHtml.= ' : <span>'
  839. .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php'
  840. .'?view=friends&height=390&width=610&user_id='.$user_id.'"'
  841. .'class="thickbox" title="'.get_lang('SeeAll').'" >'.get_lang('SeeAll').'</a></span>';
  842. }
  843. }
  844. $friendHtml.= '<ul class="nav nav-list">';
  845. $j = 1;
  846. for ($k=0; $k < $number_friends; $k++) {
  847. if ($j > $number_of_images) break;
  848. if (isset($friends[$k])) {
  849. $friend = $friends[$k];
  850. $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
  851. $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
  852. if ($user_info_friend['user_is_online']) {
  853. $statusIcon = Display::span('', array('class' => 'online_user_in_text'));
  854. } else {
  855. $statusIcon = Display::span('', array('class' => 'offline_user_in_text'));
  856. }
  857. $friendHtml.= '<li class="">';
  858. // the height = 92 must be the sqme in the image_friend_network span style in default.css
  859. $friends_profile = SocialManager::get_picture_user($friend['friend_user_id'], $friend['image'], 20, USER_IMAGE_SIZE_SMALL);
  860. $friendHtml.= '<img src="'.$friends_profile['file'].'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'"/>';
  861. $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared;
  862. $friendHtml.= $statusIcon .'<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '">' . $name_user .'</a>';
  863. $friendHtml.= '</li>';
  864. }
  865. $j++;
  866. }
  867. $friendHtml.='</ul>';
  868. } else {
  869. $friendHtml.= '<div class="">'.get_lang('NoFriendsInYourContactList').'<br />'
  870. .'<a class="btn" href="'.api_get_path(WEB_PATH).'whoisonline.php">'. get_lang('TryAndFindSomeFriends').'</a></div>';
  871. }
  872. return $friendHtml;
  873. }
  874. function wallSocialAddPost()
  875. {
  876. $html = '<div class="panel panel-default social-wall">';
  877. $html .= '<div class="panel-heading">' . get_lang('SocialWall') . '</div>';
  878. $html .= '<div class="panel-body">';
  879. $html .=
  880. '<form name="social_wall_main" method="POST" enctype="multipart/form-data">
  881. <label for="social_wall_new_msg_main" class="hide">' . get_lang('SocialWallWhatAreYouThinkingAbout') . '</label>
  882. <textarea name="social_wall_new_msg_main" rows="2" cols="80" style="width: 98%" placeholder="'.get_lang('SocialWallWhatAreYouThinkingAbout').'"></textarea>
  883. <br />
  884. <input class="" name="picture" type="file" accept="image/*" style="width:80%;">
  885. <button type="submit" name="social_wall_new_msg_main_submit" class="pull-right btn btn-success" />
  886. <i class="fa fa-pencil"></i> '.get_lang('Post').'</button>
  887. </form>';
  888. $html.= '</div></div>';
  889. return $html;
  890. }
  891. function wallSocialPost($userId, $friendId)
  892. {
  893. $array = SocialManager::getWallMessagesPostHTML($userId, $friendId);
  894. $html = '';
  895. for($i = 0; $i < count($array); $i++) {
  896. $post = $array[$i]['html'];
  897. $comment = SocialManager::getWallMessagesHTML($userId, $friendId, $array[$i]['id']);
  898. $html .= $post.$comment;
  899. }
  900. return $html;
  901. }