social.lib.php 48 KB

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