profile.php 36 KB

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