profile.php 36 KB

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