social.lib.php 45 KB

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