social.lib.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This class provides methods for the social network management.
  5. * Include/require it in your code to use its features.
  6. *
  7. * @package chamilo.social
  8. */
  9. /**
  10. * Code
  11. */
  12. //PLUGIN PLACES
  13. define('SOCIAL_LEFT_PLUGIN', 1);
  14. define('SOCIAL_CENTER_PLUGIN', 2);
  15. define('SOCIAL_RIGHT_PLUGIN', 3);
  16. define('CUT_GROUP_NAME', 50);
  17. /**
  18. *
  19. * @package chamilo.social
  20. */
  21. class SocialManager extends UserManager {
  22. private function __construct() {
  23. }
  24. /**
  25. * Allow to see contacts list
  26. * @author isaac flores paz
  27. * @return array
  28. */
  29. public static function show_list_type_friends () {
  30. $friend_relation_list=array();
  31. $count_list=0;
  32. $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
  33. $sql='SELECT id,title FROM '.$tbl_my_friend_relation_type.' WHERE id<>6 ORDER BY id ASC';
  34. $result=Database::query($sql);
  35. while ($row=Database::fetch_array($result,'ASSOC')) {
  36. $friend_relation_list[]=$row;
  37. }
  38. $count_list=count($friend_relation_list);
  39. if ($count_list==0) {
  40. $friend_relation_list[]=get_lang('Unknown');
  41. } else {
  42. return $friend_relation_list;
  43. }
  44. }
  45. /**
  46. * Get relation type contact by name
  47. * @param string names of the kind of relation
  48. * @return int
  49. * @author isaac flores paz
  50. */
  51. public static function get_relation_type_by_name ($relation_type_name) {
  52. $list_type_friend=array();
  53. $list_type_friend=self::show_list_type_friends();
  54. foreach ($list_type_friend as $value_type_friend) {
  55. if (strtolower($value_type_friend['title'])==$relation_type_name) {
  56. return $value_type_friend['id'];
  57. }
  58. }
  59. }
  60. /**
  61. * Get the kind of relation between contacts
  62. * @param int user id
  63. * @param int user friend id
  64. * @param string
  65. * @author isaac flores paz
  66. */
  67. public static function get_relation_between_contacts ($user_id,$user_friend) {
  68. $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
  69. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
  70. $sql= 'SELECT rt.id as id FROM '.$tbl_my_friend_relation_type.' rt ' .
  71. 'WHERE rt.id=(SELECT uf.relation_type FROM '.$tbl_my_friend.' uf WHERE user_id='.((int)$user_id).' AND friend_user_id='.((int)$user_friend).' AND uf.relation_type <> '.USER_RELATION_TYPE_RRHH.' )';
  72. $res=Database::query($sql);
  73. if (Database::num_rows($res)>0) {
  74. $row=Database::fetch_array($res,'ASSOC');
  75. return $row['id'];
  76. } else {
  77. return USER_UNKNOW;
  78. }
  79. }
  80. /**
  81. * Gets friends id list
  82. * @param int user id
  83. * @param int group id
  84. * @param string name to search
  85. * @param bool true will load firstname, lastname, and image name
  86. * @return array
  87. * @author Julio Montoya <gugli100@gmail.com> Cleaning code, function renamed, $load_extra_info option added
  88. * @author isaac flores paz
  89. */
  90. public static function get_friends($user_id, $id_group = null, $search_name = null, $load_extra_info = true) {
  91. $list_ids_friends=array();
  92. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
  93. $tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER);
  94. $sql='SELECT friend_user_id FROM '.$tbl_my_friend.' WHERE relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND friend_user_id<>'.((int)$user_id).' AND user_id='.((int)$user_id);
  95. if (isset($id_group) && $id_group>0) {
  96. $sql.=' AND relation_type='.$id_group;
  97. }
  98. if (isset($search_name)) {
  99. $search_name = trim($search_name);
  100. $search_name = str_replace(' ', '', $search_name);
  101. $sql.=' AND friend_user_id IN (SELECT user_id FROM '.$tbl_my_user.' WHERE firstName LIKE "%'.Database::escape_string($search_name).'%" OR lastName LIKE "%'.Database::escape_string($search_name).'%" OR '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' like concat("%","'.Database::escape_string($search_name).'","%") ) ';
  102. }
  103. $res = Database::query($sql);
  104. while ($row = Database::fetch_array($res, 'ASSOC')) {
  105. if ($load_extra_info) {
  106. $path = UserManager::get_user_picture_path_by_id($row['friend_user_id'],'web',false,true);
  107. $my_user_info = api_get_user_info($row['friend_user_id']);
  108. $list_ids_friends[] = array('friend_user_id'=>$row['friend_user_id'],'firstName'=>$my_user_info['firstName'] , 'lastName'=>$my_user_info['lastName'], 'username'=>$my_user_info['username'], 'image'=>$path['file']);
  109. } else {
  110. $list_ids_friends[] = $row;
  111. }
  112. }
  113. return $list_ids_friends;
  114. }
  115. /**
  116. * get list web path of contacts by user id
  117. * @param int user id
  118. * @param int group id
  119. * @param string name to search
  120. * @param array
  121. * @author isaac flores paz
  122. */
  123. public static function get_list_path_web_by_user_id ($user_id,$id_group=null,$search_name=null) {
  124. $combine_friend = array();
  125. $list_ids = self::get_friends($user_id,$id_group,$search_name);
  126. if (is_array($list_ids)) {
  127. foreach ($list_ids as $values_ids) {
  128. $list_path_image_friend[] = UserManager::get_user_picture_path_by_id($values_ids['friend_user_id'],'web',false,true);
  129. $combine_friend=array('id_friend'=>$list_ids,'path_friend'=>$list_path_image_friend);
  130. }
  131. }
  132. return $combine_friend;
  133. }
  134. /**
  135. * get web path of user invitate
  136. * @author isaac flores paz
  137. * @author Julio Montoya setting variable array
  138. * @param int user id
  139. * @return array
  140. */
  141. public static function get_list_web_path_user_invitation_by_user_id ($user_id) {
  142. $list_ids = self::get_list_invitation_of_friends_by_user_id((int)$user_id);
  143. $list_path_image_friend = array();
  144. foreach ($list_ids as $values_ids) {
  145. $list_path_image_friend[] = UserManager::get_user_picture_path_by_id($values_ids['user_sender_id'],'web',false,true);
  146. }
  147. return $list_path_image_friend;
  148. }
  149. /**
  150. * Sends an invitation to contacts
  151. * @param int user id
  152. * @param int user friend id
  153. * @param string title of the message
  154. * @param string content of the message
  155. * @return boolean
  156. * @author isaac flores paz
  157. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  158. */
  159. public static function send_invitation_friend($user_id, $friend_id, $message_title, $message_content) {
  160. $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE);
  161. $user_id = intval($user_id);
  162. $friend_id = intval($friend_id);
  163. //Just in case we replace the and \n and \n\r while saving in the DB
  164. $message_content = str_replace(array("\n", "\n\r"), '<br />', $message_content);
  165. $clean_message_title = Database::escape_string($message_title);
  166. $clean_message_content = Database::escape_string($message_content);
  167. $now = api_get_utc_datetime();
  168. $sql_exist='SELECT COUNT(*) AS count FROM '.$tbl_message.' WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status IN(5,6,7);';
  169. $res_exist = Database::query($sql_exist);
  170. $row_exist = Database::fetch_array($res_exist,'ASSOC');
  171. if ($row_exist['count']==0) {
  172. $sql=' INSERT INTO '.$tbl_message.'(user_sender_id,user_receiver_id,msg_status,send_date,title,content)
  173. VALUES('.$user_id.','.$friend_id.','.MESSAGE_STATUS_INVITATION_PENDING.',"'.$now.'","'.$clean_message_title.'","'.$clean_message_content.'") ';
  174. Database::query($sql);
  175. $sender_info = api_get_user_info($user_id);
  176. $notification = new Notification();
  177. $notification->save_notification(NOTIFICATION_TYPE_INVITATION, array($friend_id), $message_title, $message_content, $sender_info);
  178. return true;
  179. } else {
  180. //invitation already exist
  181. $sql_if_exist ='SELECT COUNT(*) AS count, id FROM '.$tbl_message.' WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7';
  182. $res_if_exist = Database::query($sql_if_exist);
  183. $row_if_exist = Database::fetch_array($res_if_exist,'ASSOC');
  184. if ($row_if_exist['count']==1) {
  185. $sql_if_exist_up='UPDATE '.$tbl_message.'SET msg_status=5, content = "'.$clean_message_content.'" WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7 ';
  186. Database::query($sql_if_exist_up);
  187. return true;
  188. } else {
  189. return false;
  190. }
  191. }
  192. }
  193. /**
  194. * Get number messages of the inbox
  195. * @author isaac flores paz
  196. * @param int user receiver id
  197. * @return int
  198. */
  199. public static function get_message_number_invitation_by_user_id ($user_receiver_id) {
  200. $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE);
  201. $sql='SELECT COUNT(*) as count_message_in_box FROM '.$tbl_message.' WHERE user_receiver_id='.intval($user_receiver_id).' AND msg_status='.MESSAGE_STATUS_INVITATION_PENDING;
  202. $res=Database::query($sql);
  203. $row=Database::fetch_array($res,'ASSOC');
  204. return $row['count_message_in_box'];
  205. }
  206. /**
  207. * Get invitation list received by user
  208. * @author isaac flores paz
  209. * @param int user id
  210. * @return array()
  211. */
  212. public static function get_list_invitation_of_friends_by_user_id ($user_id) {
  213. $list_friend_invitation=array();
  214. $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE);
  215. $sql = 'SELECT user_sender_id,send_date,title,content FROM '.$tbl_message.' WHERE user_receiver_id='.intval($user_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
  216. $res = Database::query($sql);
  217. while ($row = Database::fetch_array($res,'ASSOC')) {
  218. $list_friend_invitation[]=$row;
  219. }
  220. return $list_friend_invitation;
  221. }
  222. /**
  223. * Get invitation list sent by user
  224. * @author Julio Montoya <gugli100@gmail.com>
  225. * @param int user id
  226. * @return array()
  227. */
  228. public static function get_list_invitation_sent_by_user_id ($user_id) {
  229. $list_friend_invitation=array();
  230. $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE);
  231. $sql='SELECT user_receiver_id, send_date,title,content FROM '.$tbl_message.' WHERE user_sender_id = '.intval($user_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
  232. $res=Database::query($sql);
  233. while ($row=Database::fetch_array($res,'ASSOC')) {
  234. $list_friend_invitation[$row['user_receiver_id']]=$row;
  235. }
  236. return $list_friend_invitation;
  237. }
  238. /**
  239. * Accepts invitation
  240. * @param int user sender id
  241. * @param int user receiver id
  242. * @author isaac flores paz
  243. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  244. */
  245. public static function invitation_accepted ($user_send_id,$user_receiver_id) {
  246. $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE);
  247. $sql='UPDATE '.$tbl_message.' SET msg_status='.MESSAGE_STATUS_INVITATION_ACCEPTED.' WHERE user_sender_id='.((int)$user_send_id).' AND user_receiver_id='.((int)$user_receiver_id).';';
  248. Database::query($sql);
  249. }
  250. /**
  251. * Denies invitation
  252. * @param int user sender id
  253. * @param int user receiver id
  254. * @author isaac flores paz
  255. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  256. */
  257. public static function invitation_denied ($user_send_id,$user_receiver_id) {
  258. $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE);
  259. //$msg_status=7;
  260. //$sql='UPDATE '.$tbl_message.' SET msg_status='.$msg_status.' WHERE user_sender_id='.((int)$user_send_id).' AND user_receiver_id='.((int)$user_receiver_id).';';
  261. $sql='DELETE FROM '.$tbl_message.' WHERE user_sender_id='.((int)$user_send_id).' AND user_receiver_id='.((int)$user_receiver_id).';';
  262. Database::query($sql);
  263. }
  264. /**
  265. * allow attach to group
  266. * @author isaac flores paz
  267. * @param int user to qualify
  268. * @param int kind of rating
  269. * @return void()
  270. */
  271. public static function qualify_friend ($id_friend_qualify,$type_qualify) {
  272. $tbl_user_friend=Database::get_main_table(TABLE_MAIN_USER_REL_USER);
  273. $user_id=api_get_user_id();
  274. $sql='UPDATE '.$tbl_user_friend.' SET relation_type='.((int)$type_qualify).' WHERE user_id='.((int)$user_id).' AND friend_user_id='.((int)$id_friend_qualify).';';
  275. Database::query($sql);
  276. }
  277. /**
  278. * Sends invitations to friends
  279. * @author Isaac Flores Paz <isaac.flores.paz@gmail.com>
  280. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  281. * @param void
  282. * @return string message invitation
  283. */
  284. public static function send_invitation_friend_user($userfriend_id, $subject_message = '', $content_message = '') {
  285. global $charset;
  286. $user_info = array();
  287. $user_info = api_get_user_info($userfriend_id);
  288. $succes = get_lang('MessageSentTo');
  289. $succes.= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']);
  290. if (isset($subject_message) && isset($content_message) && isset($userfriend_id)) {
  291. $send_message = MessageManager::send_message($userfriend_id, $subject_message, $content_message);
  292. if ($send_message) {
  293. echo Display::display_confirmation_message($succes,true);
  294. } else {
  295. echo Display::display_error_message(get_lang('ErrorSendingMessage'),true);
  296. }
  297. return false;
  298. } elseif (isset($userfriend_id) && !isset($subject_message)) {
  299. $count_is_true = false;
  300. if (isset($userfriend_id) && $userfriend_id>0) {
  301. $message_title = get_lang('Invitation');
  302. $count_is_true = self::send_invitation_friend(api_get_user_id(), $userfriend_id, $message_title, $content_message);
  303. if ($count_is_true) {
  304. echo Display::display_normal_message(api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES,$charset),false);
  305. } else {
  306. echo Display::display_error_message(api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES,$charset),false);
  307. }
  308. }
  309. }
  310. }
  311. /**
  312. * Get user's feeds
  313. * @param int User ID
  314. * @param int Limit of posts per feed
  315. * @return string HTML section with all feeds included
  316. * @author Yannick Warnier
  317. * @since Dokeos 1.8.6.1
  318. */
  319. public static function get_user_feeds($user, $limit=5) {
  320. if (!function_exists('fetch_rss')) { return '';}
  321. $feeds = array();
  322. $feed = UserManager::get_extra_user_data_by_field($user,'rssfeeds');
  323. if(empty($feed)) { return ''; }
  324. $feeds = explode(';',$feed['rssfeeds']);
  325. if (count($feeds)==0) { return ''; }
  326. $res = '';
  327. foreach ($feeds as $url) {
  328. if (empty($url)) { continue; }
  329. $rss = @fetch_rss($url);
  330. $i = 1;
  331. if (!empty($rss->items)) {
  332. $icon_rss = '';
  333. if (!empty($feed)) {
  334. $icon_rss = Display::url(Display::return_icon('rss.png', '', array(), 32), Security::remove_XSS($feed['rssfeeds']), array('target'=>'_blank'));
  335. }
  336. $res .= '<h2>'.$rss->channel['title'].''.$icon_rss.'</h2>';
  337. $res .= '<div class="social-rss-channel-items">';
  338. foreach ($rss->items as $item) {
  339. if ($limit>=0 and $i>$limit) {break;}
  340. $res .= '<h3><a href="'.$item['link'].'">'.$item['title'].'</a></h3>';
  341. $res .= '<div class="social-rss-item-date">'.api_get_datetime($item['date_timestamp']).'</div>';
  342. $res .= '<div class="social-rss-item-content">'.$item['description'].'</div><br />';
  343. $i++;
  344. }
  345. $res .= '</div>';
  346. }
  347. }
  348. return $res;
  349. }
  350. /**
  351. * Helper functions definition
  352. */
  353. public static function get_logged_user_course_html($my_course, $count) {
  354. global $nosession, $nbDigestEntries, $orderKey, $digest, $thisCourseSysCode;
  355. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  356. global $now, $date_start, $date_end;
  357. }
  358. //initialise
  359. $result = '';
  360. // Table definitions
  361. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  362. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  363. $user_id = api_get_user_id();
  364. $course_system_code = $my_course['k'];
  365. $course_visual_code = $my_course['c'];
  366. $course_title = $my_course['i'];
  367. $course_directory = $my_course['d'];
  368. $course_teacher = $my_course['t'];
  369. $course_teacher_email = isset($my_course['email'])?$my_course['email']:'';
  370. $course_info = Database :: get_course_info($course_system_code);
  371. $course_id = $course_info['real_id'];
  372. $course_access_settings = CourseManager :: get_access_settings($course_system_code);
  373. $course_visibility = $course_access_settings['visibility'];
  374. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code);
  375. //function logic - act on the data
  376. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']);
  377. if ($is_virtual_course) {
  378. // If the current user is also subscribed in the real course to which this
  379. // virtual course is linked, we don't need to display the virtual course entry in
  380. // the course list - it is combined with the real course entry.
  381. $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code);
  382. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  383. if ($is_subscribed_in_target_course) {
  384. return; //do not display this course entry
  385. }
  386. }
  387. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id());
  388. if ($has_virtual_courses) {
  389. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  390. $course_display_title = $return_result['title'];
  391. $course_display_code = $return_result['code'];
  392. } else {
  393. $course_display_title = $course_title;
  394. $course_display_code = $course_visual_code;
  395. }
  396. /*
  397. $s_course_status=$my_course['s'];
  398. $s_htlm_status_icon="";
  399. if ($s_course_status==1) {
  400. $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px'));
  401. }
  402. if ($s_course_status==2) {
  403. $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('coachs.gif', get_lang('Status').': '.get_lang('GeneralCoach'),array('style'=>'width:11px; height:11px'));
  404. }
  405. if ($s_course_status==5) {
  406. $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'),array('style'=>'width:11px; height:11px'));
  407. }*/
  408. $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course'));
  409. //display course entry
  410. $result .= '<div id="div_'.$count.'">';
  411. $result .= '<h3><img src="../img/nolines_plus.gif" id="btn_'.$count.'" onclick="toogle_course(this,\''.$course_id.'\' )">';
  412. $result .= $s_htlm_status_icon;
  413. //show a hyperlink to the course, unless the course is closed and user is not course admin
  414. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
  415. $result .= '<a href="javascript:void(0)" id="ln_'.$count.'" onclick=toogle_course(this,\''.$course_id.'\');>&nbsp;'.$course_title.'</a>';
  416. } else {
  417. $result .= $course_display_title." "." ".get_lang('CourseClosed')."";
  418. }
  419. $result .= '</h3>';
  420. //$current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  421. // display the what's new icons
  422. if ($nbDigestEntries > 0) {
  423. reset($digest);
  424. $result .= '<ul>';
  425. while (list ($key2) = each($digest[$thisCourseSysCode])) {
  426. $result .= '<li>';
  427. if ($orderKey[1] == 'keyTools') {
  428. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  429. $result .= "$toolsList[$key2][\"name\"]</a>";
  430. } else {
  431. $result .= api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get());
  432. }
  433. $result .= '</li>';
  434. $result .= '<ul>';
  435. reset($digest[$thisCourseSysCode][$key2]);
  436. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
  437. $result .= '<li>';
  438. if ($orderKey[2] == 'keyTools') {
  439. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  440. $result .= "$toolsList[$key3][\"name\"]</a>";
  441. } else {
  442. $result .= api_convert_and_format_date($key3, DATE_FORMAT_LONG, date_default_timezone_get());
  443. }
  444. $result .= '<ul compact="compact">';
  445. reset($digest[$thisCourseSysCode][$key2][$key3]);
  446. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) {
  447. $result .= '<li>';
  448. $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  449. $result .= '</li>';
  450. }
  451. $result .= '</ul>';
  452. $result .= '</li>';
  453. }
  454. $result .= '</ul>';
  455. $result .= '</li>';
  456. }
  457. $result .= '</ul>';
  458. }
  459. $result .= '</li>';
  460. $result .= '</div>';
  461. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  462. $session = '';
  463. $active = false;
  464. if (!empty($my_course['session_name'])) {
  465. // Request for the name of the general coach
  466. $sql = 'SELECT lastname, firstname
  467. FROM '.$tbl_session.' ts LEFT JOIN '.$main_user_table .' tu
  468. ON ts.id_coach = tu.user_id
  469. WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1';
  470. $rs = Database::query($sql);
  471. $sessioncoach = Database::store_result($rs);
  472. $sessioncoach = $sessioncoach[0];
  473. $session = array();
  474. $session['title'] = $my_course['session_name'];
  475. if ($my_course['date_start']=='0000-00-00') {
  476. $session['dates'] = get_lang('WithoutTimeLimits');
  477. if ( api_get_setting('show_session_coach') === 'true' ) {
  478. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  479. }
  480. $active = true;
  481. } else {
  482. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  483. if ( api_get_setting('show_session_coach') === 'true' ) {
  484. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  485. }
  486. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  487. }
  488. }
  489. $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0;
  490. $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active);
  491. } else {
  492. $output = array ($my_course['user_course_cat'], $result);
  493. }
  494. //$my_course['creation_date'];
  495. return $output;
  496. }
  497. /**
  498. * Shows the right menu of the Social Network tool
  499. *
  500. * @param string highlight link possible values: group_add, home, messages, messages_inbox, messages_compose ,messages_outbox ,invitations, shared_profile, friends, groups search
  501. * @param int group id
  502. * @param int user id
  503. * @param bool show profile or not (show or hide the user image/information)
  504. *
  505. */
  506. public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false) {
  507. if (empty($user_id)) {
  508. $user_id = api_get_user_id();
  509. }
  510. $user_info = api_get_user_info($user_id, true);
  511. $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups');
  512. //$show_messages = array('messages', 'messages_inbox', 'messages_outbox', 'messages_compose');
  513. // get count unread message and total invitations
  514. $count_unread_message = MessageManager::get_number_of_messages(true);
  515. $count_unread_message = (!empty($count_unread_message)?' ('.$count_unread_message.')':'');
  516. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  517. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION,false);
  518. $group_pending_invitations = count($group_pending_invitations);
  519. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  520. $total_invitations = (!empty($total_invitations)?' ('.$total_invitations.')':'');
  521. $html = '<div class="social-menu">';
  522. $html .= '<script type="text/javascript">
  523. function show_icon_edit(element_html) {
  524. ident="#edit_image";
  525. $(ident).show();
  526. }
  527. function hide_icon_edit(element_html) {
  528. ident="#edit_image";
  529. $(ident).hide();
  530. }
  531. </script>';
  532. if (in_array($show, $show_groups) && !empty($group_id)) {
  533. //--- Group image
  534. $group_info = GroupPortalManager::get_group_data($group_id);
  535. $big = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],160,GROUP_IMAGE_SIZE_BIG);
  536. $html .= '<div class="social-content-image">';
  537. $html .= '<div class="social-background-content" onmouseout="hide_icon_edit()" onmouseover="show_icon_edit()">';
  538. $html .= Display::url('<img src='.$big['file'].' class="social-groups-image" /> </a><br /><br />', api_get_path(WEB_PATH).'main/social/groups.php?id='.$group_id);
  539. if (GroupPortalManager::is_group_admin($group_id, api_get_user_id())) {
  540. $html .= '<div id="edit_image" class="hidden_message" style="display:none"><a href="'.api_get_path(WEB_PATH).'main/social/group_edit.php?id='.$group_id.'">'.get_lang('EditGroup').'</a></div>';
  541. }
  542. $html .= '</div>';
  543. $html .= '</div>';
  544. } else {
  545. $img_array = UserManager::get_user_picture_path_by_id($user_id,'web',true,true);
  546. $big_image = UserManager::get_picture_user($user_id, $img_array['file'],'', USER_IMAGE_SIZE_BIG);
  547. $big_image = $big_image['file'].'?'.uniqid();
  548. $normal_image = $img_array['dir'].$img_array['file'].'?'.uniqid();
  549. //--- User image
  550. $html .= '<div class="social-background-content" onmouseout="hide_icon_edit()" onmouseover="show_icon_edit()">';
  551. if ($img_array['file'] != 'unknown.jpg') {
  552. $html .= '<a class="thumbnail thickbox" href="'.$big_image.'"><img src='.$normal_image.' /> </a>';
  553. } else {
  554. $html .= '<img src='.$normal_image.' width="110px" />';
  555. }
  556. if (api_get_user_id() == $user_id) {
  557. $html .= '<div id="edit_image" class="hidden_message" style="display:none">';
  558. $html .= '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php">'.get_lang('EditProfile').'</a></div>';
  559. }
  560. $html .= '</div>';
  561. }
  562. if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list','waiting_list','invite_friends'))) {
  563. $html .= '<div class="social_menu_items"><ul>';
  564. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/home.php">'.Display::return_icon('home.png',get_lang('Home'),array('hspace'=>'6')).'<span class="'.($show=='home'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('Home').'</span></a></li>';
  565. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php?f=social">'.Display::return_icon('instant_message.png',get_lang('Messages'),array('hspace'=>'6')).'<span class="'.($show=='messages'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('Messages').$count_unread_message.'</span></a></li>';
  566. //Invitations
  567. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.Display::return_icon('invitation.png',get_lang('Invitations'),array('hspace'=>'6')).'<span class="'.($show=='invitations'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('Invitations').$total_invitations.'</span></a></li>';
  568. //Shared profile and groups
  569. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.Display::return_icon('my_shared_profile.png',get_lang('ViewMySharedProfile'),array('hspace'=>'6')).'<span class="'.($show=='shared_profile'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('ViewMySharedProfile').'</span></a></li>
  570. <li><a href="'.api_get_path(WEB_PATH).'main/social/friends.php">'.Display::return_icon('friend.png',get_lang('Friends'),array('hspace'=>'6')).'<span class="'.($show=='friends'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('Friends').'</span></a></li>
  571. <li><a href="'.api_get_path(WEB_PATH).'main/social/groups.php">'.Display::return_icon('group_s.png',get_lang('SocialGroups'),array('hspace'=>'6')).'<span class="'.($show=='browse_groups'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('SocialGroups').'</span></a></li>';
  572. //Search users
  573. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/search.php">'.Display::return_icon('zoom.png',get_lang('Search'),array('hspace'=>'6')).'<span class="'.($show=='search'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('Search').'</span></a></li>';
  574. //My files
  575. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/myfiles.php">'.Display::return_icon('briefcase.png',get_lang('MyFiles'),array('hspace'=>'6'),16).'<span class="'.($show=='myfiles'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('MyFiles').'</span></a></li>';
  576. $html .='</ul>
  577. </div>';
  578. }
  579. if (in_array($show, $show_groups) && !empty($group_id)) {
  580. $html .= GroupPortalManager::show_group_column_information($group_id, api_get_user_id(), $show);
  581. }
  582. if ($show == 'shared_profile') {
  583. //echo '<div align="center" class="social-menu-title" ><span class="social-menu-text1">'.get_lang('Menu').'</span></div>';
  584. $html .= '<div class="social_menu_items">
  585. <ul>';
  586. // My own profile
  587. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  588. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/home.php">'.Display::return_icon('home.png',get_lang('Home'),array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('Home').'</span></a></li>
  589. <li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php?f=social">'.Display::return_icon('instant_message.png',get_lang('Messages'),array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('Messages').$count_unread_message.'</span></a></li>';
  590. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.Display::return_icon('invitation.png',get_lang('Invitations'),array('hspace'=>'6')).'<span class="'.($show=='invitations'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('Invitations').$total_invitations.'</span></a></li>';
  591. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.Display::return_icon('my_shared_profile.png',get_lang('ViewMySharedProfile',array('hspace'=>'6','style'=>'float:left')).'<span class="social-menu-text-active" >'.get_lang('ViewMySharedProfile').'</span></a></li>
  592. <li><a href="'.api_get_path(WEB_PATH).'main/social/friends.php">'.Display::return_icon('friend.png',get_lang('Friends'),array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('Friends').'</span></a></li>
  593. <li><a href="'.api_get_path(WEB_PATH).'main/social/groups.php">'.Display::return_icon('group_s.png'),get_lang('SocialGroups'),array('hspace'=>'6')).'<span class="social-menu-text4" >'.get_lang('SocialGroups').'</span></a></li>';
  594. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/search.php">'.Display::return_icon('zoom.png',get_lang('Search'),array('hspace'=>'6')).'<span class="'.($show=='search'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('Search').'</span></a></li>';
  595. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/myfiles.php">'.Display::return_icon('briefcase.png',get_lang('MyFiles'),array('hspace'=>'6'),16).'<span class="'.($show=='myfiles'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('MyFiles').'</span></a></li>';
  596. }
  597. // My friend profile
  598. if ($user_id != api_get_user_id()) {
  599. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/send_message_to_userfriend.inc.php?height=300&width=470&user_friend='.$user_id.'&view=profile&view_panel=1" class="ajax" title="'.get_lang('SendMessage').'">';
  600. $html .= Display::return_icon('compose_message.png',get_lang('SendMessage')).'&nbsp;&nbsp;'.get_lang('SendMessage').'</a></li>';
  601. }
  602. //check if I already sent an invitation message
  603. $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id());
  604. if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0 ) {
  605. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.Display::return_icon('invitation.png',get_lang('YouAlreadySentAnInvitation')).'&nbsp;&nbsp;'.get_lang('YouAlreadySentAnInvitation').'</a></li>';
  606. } else {
  607. if (!$show_full_profile) {
  608. $html .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/send_message_to_userfriend.inc.php?view_panel=2&height=230&width=500&user_friend='.$user_id.'" class="ajax" title="'.get_lang('SendInvitation').'">'.Display :: return_icon('invitation.png', get_lang('SocialInvitationToFriends')).'&nbsp;'.get_lang('SendInvitation').'</a></li>';
  609. }
  610. }
  611. //@todo check if user is online to show the chat link
  612. if (api_get_setting('allow_global_chat') == 'true') {
  613. if ($user_id != api_get_user_id()) {
  614. $user_name = $user_info['complete_name'];
  615. $options = array('onclick' => "javascript:chatWith('".$user_id."', '".Security::remove_XSS($user_name)."', '".$user_info['user_is_online_in_chat']."')");
  616. $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline'));
  617. $html .= Display::tag('li', Display::url($chat_icon.'&nbsp;&nbsp;'.get_lang('Chat'), 'javascript:void(0);', $options));
  618. }
  619. }
  620. $html .= '</ul></div>';
  621. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  622. $personal_course_list = UserManager::get_personal_session_course_list($user_id);
  623. $course_list_code = array();
  624. $i=1;
  625. if (is_array($personal_course_list)) {
  626. foreach ($personal_course_list as $my_course) {
  627. if ($i<=10) {
  628. //$list[] = SocialManager::get_logged_user_course_html($my_course,$i);
  629. $course_list_code[] = array('code'=>$my_course['k']);
  630. } else {
  631. break;
  632. }
  633. $i++;
  634. }
  635. //to avoid repeted courses
  636. $course_list_code = array_unique_dimensional($course_list_code);
  637. }
  638. //-----Announcements
  639. $my_announcement_by_user_id= intval($user_id);
  640. $announcements = array();
  641. foreach ($course_list_code as $course) {
  642. $course_info = api_get_course_info($course['code']);
  643. if (!empty($course_info)) {
  644. $content = AnnouncementManager::get_all_annoucement_by_user_course($course_info['code'], $my_announcement_by_user_id);
  645. if (!empty($content)) {
  646. $url = Display::url(Display::return_icon('announcement.png',get_lang('Announcements')).$course_info['name'].' ('.$content['count'].')', api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$course['code']);
  647. $announcements[] = Display::tag('li', $url);
  648. }
  649. }
  650. }
  651. if (!empty($announcements)) {
  652. //echo '<div align="center" class="social-menu-title" ><span class="social-menu-text1">'.get_lang('ToolAnnouncement').'</span></div>';
  653. $html .= '<div class="social_menu_items">';
  654. $html .= '<ul>';
  655. foreach ($announcements as $announcement) {
  656. $html .= $announcement;
  657. }
  658. $html .= '</ul>';
  659. $html .= '</div>';
  660. }
  661. }
  662. }
  663. $html .= '</div>';
  664. return $html;
  665. }
  666. /**
  667. * Displays a sortable table with the list of online users.
  668. * @param array $user_list
  669. */
  670. public static function display_user_list($user_list) {
  671. if ($_GET['id'] == '') {
  672. $column_size = '9';
  673. $add_row = false;
  674. if (api_is_anonymous()) {
  675. $column_size = '12';
  676. $add_row = true;
  677. }
  678. $extra_params = array();
  679. $course_url = '';
  680. if (strlen($_GET['cidReq']) > 0) {
  681. $extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  682. $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
  683. }
  684. if ($add_row) {
  685. $html .='<div class="row">';
  686. }
  687. $html .= '<div class="span'.$column_size.'">';
  688. $html .= '<ul id="online_grid_container" class="thumbnails">';
  689. foreach ($user_list as $user) {
  690. $uid = $user[0];
  691. $user_info = api_get_user_info($uid);
  692. //Anonymous users can't have access to the profile
  693. if (!api_is_anonymous()) {
  694. if (api_get_setting('allow_social_tool')=='true') {
  695. $url = api_get_path(WEB_PATH).'main/social/profile.php?u='.$uid.$course_url;
  696. } else {
  697. $url = '?id='.$uid.$course_url;
  698. }
  699. } else {
  700. $url = '#';
  701. }
  702. $image_array = UserManager::get_user_picture_path_by_id($uid, 'system', false, true);
  703. // reduce image
  704. $name = $user_info['complete_name'];
  705. $status_icon = Display::span('', array('class' => 'online_user_in_text'));
  706. if ($image_array['file'] == 'unknown.jpg' || !file_exists($image_array['dir'].$image_array['file'])) {
  707. $friends_profile['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_180_100.jpg';
  708. $img = '<img title = "'.$name.'" alt="'.$name.'" src="'.$friends_profile['file'].'">';
  709. } else {
  710. $friends_profile = UserManager::get_picture_user($uid, $image_array['file'], 80, USER_IMAGE_SIZE_ORIGINAL);
  711. $img = '<img title = "'.$name.'" alt="'.$name.'" src="'.$friends_profile['file'].'">';
  712. }
  713. $name = '<a href="'.$url.'">'.$status_icon.$name.'</a><br>';
  714. $html .= '<li class="span'.($column_size/3).'"><div class="thumbnail">'.$img.'<div class="caption">'.$name.'</div</div></li>';
  715. }
  716. $counter = $_SESSION['who_is_online_counter'];
  717. $html .= '</ul></div>';
  718. $html .= '<div class="span'.$column_size.'"><a class="btn btn-large" id="link_load_more_items" data_link="'.$counter.'" >'.get_lang('More').'</a></div>';
  719. if ($add_row) {
  720. $html .= '</div>';
  721. }
  722. }
  723. return $html;
  724. }
  725. /**
  726. * Displays the information of an individual user
  727. * @param int $user_id
  728. */
  729. public static function display_individual_user($user_id) {
  730. global $interbreadcrumb;
  731. $safe_user_id = intval($user_id);
  732. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  733. $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id;
  734. $result = Database::query($sql);
  735. if (Database::num_rows($result) == 1) {
  736. $user_object = Database::fetch_object($result);
  737. $alt = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  738. $status = get_status_from_code($user_object->status);
  739. $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList'));
  740. Display::display_header($alt, null, $alt);
  741. echo '<div>';
  742. echo '<div style="margin:0 auto; width:350px; border:1px;">';
  743. echo '<div id="whoisonline-user-image" style="float:left; padding:5px;">';
  744. if (strlen(trim($user_object->picture_uri)) > 0) {
  745. $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'system');
  746. $sysdir = $sysdir_array['dir'];
  747. $webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'web');
  748. $webdir = $webdir_array['dir'];
  749. $fullurl = $webdir.$user_object->picture_uri;
  750. $system_image_path = $sysdir.$user_object->picture_uri;
  751. list($width, $height, $type, $attr) = @getimagesize($system_image_path);
  752. $height += 30;
  753. $width += 30;
  754. // get the path,width and height from original picture
  755. $big_image = $webdir.'big_'.$user_object->picture_uri;
  756. $big_image_size = api_getimagesize($big_image);
  757. $big_image_width = $big_image_size['width'];
  758. $big_image_height = $big_image_size['height'];
  759. $url_big_image = $big_image.'?rnd='.time();
  760. echo '<input type="image" src="'.$fullurl.'" alt="'.$alt.'" onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/><br />';
  761. } else {
  762. echo Display::return_icon('unknown.jpg', get_lang('Unknown'));
  763. echo '<br />';
  764. }
  765. if (!empty($status)) {
  766. echo '<div style="text-align:center;padding-top:5px;">'.$status.'</div>';
  767. }
  768. echo '</div>';
  769. echo '<div id="whoisonline-user-info" style="float:left; padding-left:15px;">';
  770. global $user_anonymous;
  771. if (api_get_setting('allow_social_tool') == 'true' && api_get_user_id() <> $user_anonymous && api_get_user_id() <> 0) {
  772. echo '<p><a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$safe_user_id.'">'.Display :: return_icon('my_shared_profile.png', get_lang('SocialInvitationToFriends'),array('height'=>'18px')).get_lang('ViewSharedProfile').'</a></p>';
  773. $user_anonymous = api_get_anonymous_id();
  774. if ($safe_user_id != api_get_user_id() && !api_is_anonymous($safe_user_id)) {
  775. $user_relation = SocialManager::get_relation_between_contacts(api_get_user_id(), $safe_user_id);
  776. if ($user_relation == 0 || $user_relation == 6) {
  777. echo '<p><a href="main/messages/send_message_to_userfriend.inc.php?view_panel=2&height=300&width=610&user_friend='.$safe_user_id.'" class="ajax" title="'.get_lang('SendInvitation').'">'.Display :: return_icon('invitation.png', get_lang('SocialInvitationToFriends'),array('height'=>'18px')).'&nbsp;'.get_lang('SendInvitation').'</a></p>
  778. <p><a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=310&width=610&user_friend='.$safe_user_id.'" class="ajax" title="'.get_lang('SendAMessage').'">'.Display :: return_icon('mail_send.png', get_lang('SendAMessage'),array('height'=>'18px')).'&nbsp;'.get_lang('SendAMessage').'</a></p>';
  779. } else {
  780. echo '<p><a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=310&width=610&user_friend='.$safe_user_id.'" class="ajax" title="'.get_lang('SendAMessage').'">'.Display :: return_icon('mail_send.png', get_lang('SendAMessage'),array('height'=>'18px')).'&nbsp;'.get_lang('SendAMessage').'</a></p>';
  781. }
  782. }
  783. }
  784. if (api_get_setting('show_email_addresses') == 'true') {
  785. echo Display::encrypted_mailto_link($user_object->email,$user_object->email).'<br />';
  786. }
  787. echo '</div>';
  788. echo '</div>';
  789. echo '</div>';
  790. echo '<div class="clear"></div>';
  791. echo '<div>';
  792. if ($user_object->competences) {
  793. echo '<dt><div class="actions-message"><strong>'.get_lang('MyCompetences').'</strong></div></dt>';
  794. echo '<dd>'.$user_object->competences.'</dd>';
  795. }
  796. if ($user_object->diplomas) {
  797. echo '<dt><div class="actions-message"><strong>'.get_lang('MyDiplomas').'</strong></div></dt>';
  798. echo '<dd>'.$user_object->diplomas.'</dd>';
  799. }
  800. if ($user_object->teach) {
  801. echo '<dt><div class="actions-message"><strong>'.get_lang('MyTeach').'</strong></div></dt>';
  802. echo '<dd>'.$user_object->teach.'</dd>';;
  803. }
  804. SocialManager::display_productions($user_object->user_id);
  805. if ($user_object->openarea) {
  806. echo '<dt><div class="actions-message"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div></dt>';
  807. echo '<dd>'.$user_object->openarea.'</dd>';
  808. }
  809. echo '</div>';
  810. } else {
  811. Display::display_header(get_lang('UsersOnLineList'));
  812. echo '<div class="actions-title">';
  813. echo get_lang('UsersOnLineList');
  814. echo '</div>';
  815. }
  816. }
  817. /**
  818. * Display productions in whoisonline
  819. * @param int $user_id User id
  820. */
  821. public static function display_productions($user_id) {
  822. $sysdir_array = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
  823. $sysdir = $sysdir_array['dir'].$user_id.'/';
  824. $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true);
  825. $webdir = $webdir_array['dir'].$user_id.'/';
  826. if (!is_dir($sysdir)) {
  827. mkdir($sysdir, api_get_permissions_for_new_directories(), true);
  828. }
  829. /*
  830. $handle = opendir($sysdir);
  831. $productions = array();
  832. while ($file = readdir($handle)) {
  833. if ($file == '.' || $file == '..' || $file == '.htaccess') {
  834. continue; // Skip current and parent directories
  835. }
  836. if (preg_match('/('.$user_id.'|[0-9a-f]{13}|saved)_.+\.(png|jpg|jpeg|gif)$/i', $file)) {
  837. // User's photos should not be listed as productions.
  838. continue;
  839. }
  840. $productions[] = $file;
  841. }
  842. */
  843. $productions = UserManager::get_user_productions($user_id);
  844. if (count($productions) > 0) {
  845. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  846. echo '<dd><ul>';
  847. foreach ($productions as $file) {
  848. // Only display direct file links to avoid browsing an empty directory
  849. if (is_file($sysdir.$file) && $file != $webdir_array['file']) {
  850. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  851. }
  852. // Real productions are under a subdirectory by the User's id
  853. if (is_dir($sysdir.$file)) {
  854. $subs = scandir($sysdir.$file);
  855. foreach ($subs as $my => $sub) {
  856. if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) {
  857. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  858. }
  859. }
  860. }
  861. }
  862. echo '</ul></dd>';
  863. }
  864. }
  865. /**
  866. * Dummy function
  867. *
  868. */
  869. public static function get_plugins($place = SOCIAL_CENTER_PLUGIN) {
  870. $content = '';
  871. switch ($place) {
  872. case SOCIAL_CENTER_PLUGIN:
  873. $social_plugins = array(1, 2);
  874. if (is_array($social_plugins) && count($social_plugins)>0) {
  875. $content.= '<div id="social-plugins">';
  876. foreach($social_plugins as $plugin ) {
  877. $content.= '<div class="social-plugin-item">';
  878. $content.= $plugin;
  879. $content.= '</div>';
  880. }
  881. $content.= '</div>';
  882. }
  883. break;
  884. case SOCIAL_LEFT_PLUGIN:
  885. break;
  886. case SOCIAL_RIGHT_PLUGIN:
  887. break;
  888. }
  889. return $content;
  890. }
  891. }