whoisonline.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <?php // $Id: whoisonline.php 21549 2009-06-21 14:02:37Z iflorespaz $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) various contributors
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * Who is online list
  20. ==============================================================================
  21. */
  22. // name of the language file that needs to be included
  23. $language_file = array('index','registration','messages','userInfo');
  24. if (!isset($_GET['cidReq'])) {
  25. $cidReset = true;
  26. }
  27. // including necessary files
  28. require_once './main/inc/global.inc.php';
  29. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  30. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  31. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  32. // table definitions
  33. $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
  34. $htmlHeadXtra[] = '<script type="text/javascript">
  35. function show_image(image,width,height) {
  36. width = parseInt(width) + 20;
  37. height = parseInt(height) + 20;
  38. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
  39. }
  40. </script>';
  41. $htmlHeadXtra[] = '<script type="text/javascript" src="./main/inc/lib/javascript/jquery.js"></script>';
  42. $htmlHeadXtra[] = '<script type="text/javascript" src="./main/inc/lib/javascript/thickbox.js"></script>';
  43. $htmlHeadXtra[] = '<link rel="stylesheet" href="./main/inc/lib/javascript/thickbox.css" type="text/css" media="projection, screen">';
  44. $htmlHeadXtra[] = '<script type="text/javascript">
  45. $(document).ready(function (){
  46. $("input#id_btn_send_invitation").bind("click", function(){
  47. if (confirm("'.get_lang('SendMessageInvitation').'")) {
  48. $("#form_register_friend").submit();
  49. }
  50. });
  51. });
  52. function change_panel (mypanel_id,myuser_id) {
  53. $.ajax({
  54. contentType: "application/x-www-form-urlencoded",
  55. beforeSend: function(objeto) {
  56. $("#id_content_panel").html("'.get_lang('Loading').'"); },
  57. type: "POST",
  58. url: "main/messages/send_message.php",
  59. data: "panel_id="+mypanel_id+"&user_id="+myuser_id,
  60. success: function(datos) {
  61. $("div#id_content_panel_init").html(datos);
  62. $("div#display_response_id").html("");
  63. }
  64. });
  65. }
  66. function action_database_panel(option_id,myuser_id) {
  67. if (option_id==5) {
  68. my_txt_subject=$("#txt_subject_id").val();
  69. } else {
  70. my_txt_subject="clear";
  71. }
  72. my_txt_content=$("#txt_area_invite").val();
  73. if (my_txt_content.length==0 || my_txt_subject.length==0) {
  74. $("#display_response_id").html("&nbsp;&nbsp;&nbsp;'.get_lang('MessageEmptyMessageOrSubject').'");
  75. setTimeout("message_information_display()",3000);
  76. return false;
  77. }
  78. $.ajax({
  79. contentType: "application/x-www-form-urlencoded",
  80. beforeSend: function(objeto) {
  81. $("#display_response_id").html("'.get_lang('Loading').'"); },
  82. type: "POST",
  83. url: "main/messages/send_message.php",
  84. data: "panel_id="+option_id+"&user_id="+myuser_id+"&txt_subject="+my_txt_subject+"&txt_content="+my_txt_content,
  85. success: function(datos) {
  86. $("#display_response_id").html(datos);
  87. }
  88. });
  89. }
  90. function display_hide () {
  91. setTimeout("hide_display_message()",3000);
  92. }
  93. function message_information_display() {
  94. $("#display_response_id").html("");
  95. }
  96. function hide_display_message () {
  97. $("div#display_response_id").html("");
  98. try {
  99. $("#txt_subject_id").val("");
  100. $("#txt_area_invite").val("");
  101. }catch(e) {
  102. $("#txt_area_invite").val("");
  103. }
  104. }
  105. </script>';
  106. if ($_GET['chatid'] != '') {
  107. //send out call request
  108. $time = time();
  109. $time = date("Y-m-d H:i:s", $time);
  110. $chatid = addslashes($_GET['chatid']);
  111. if ($_GET['chatid']==strval(intval($_GET['chatid']))) {
  112. $sql="update $track_user_table set chatcall_user_id = '".Database::escape_string($_user['user_id'])."', chatcall_date = '".Database::escape_string($time)."', chatcall_text = '' where (user_id = ".(int)Database::escape_string($chatid).")";
  113. $result=api_sql_query($sql,__FILE__,__LINE__);
  114. //redirect caller to chat
  115. header("Location: ".$_configuration['code_append']."chat/chat.php?".api_get_cidreq()."&origin=whoisonline&target=".Security::remove_XSS($chatid));
  116. exit;
  117. }
  118. }
  119. /**
  120. * Displays a sortable table with the list of online users.
  121. * @param array $user_list
  122. */
  123. function display_user_list($user_list, $_plugins)
  124. {
  125. global $charset;
  126. if ($_GET["id"]=='') {
  127. $extra_params = array();
  128. $course_url = '';
  129. if(strlen($_GET['cidReq']) > 0) {
  130. $extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  131. $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
  132. }
  133. foreach ($user_list as $user) {
  134. $uid=$user[0];
  135. $user_info = api_get_user_info($uid);
  136. $table_row = array();
  137. $url = '?id='.$uid.$course_url;
  138. $image_array=UserManager::get_user_picture_path_by_id($uid,'web',false,true);
  139. $friends_profile = UserFriend::get_picture_user($uid, $image_array['file'], 92, 'medium_', ' width="90" height="90" ');
  140. //reduce image
  141. $table_row[] = '<center><a href="'.$url.'"><img src="'.$friends_profile['file'].'" '.$friends_profile['style'].' border="1"></a></center>';
  142. $table_row[] = '<a href="'.$url.'">'.$user_info['firstName'].' '.$user_info['lastName'].'</a>';
  143. //$table_row[] = '<a href="'.$url.'">'.$user_info['lastName'].'</a>';
  144. if (api_get_setting('show_email_addresses') == 'true') {
  145. $table_row[] = Display::encrypted_mailto_link($user_info['mail']);
  146. }
  147. $user_anonymous=api_get_anonymous_id();
  148. if (api_get_setting('allow_social_tool')=='true' && api_get_user_id()<>$user_anonymous && api_get_user_id()<>0) {
  149. if ($user_info['user_id'] != api_get_user_id() && !api_is_anonymous($user_info['user_id'])) {
  150. $user_relation=UserFriend::get_relation_between_contacts(api_get_user_id(),$user_info['user_id']);
  151. if ($user_relation==0 || $user_relation==6) {
  152. $table_row[] = '<a href="main/messages/send_message_to_userfriend.inc.php?view_panel=2&height=365&width=610&user_friend='.$user_info['user_id'].'" class="thickbox" title="'.get_lang('SocialAddToFriends').'">'.Display :: return_icon('add_multiple_users.gif', get_lang('SocialAddToFriends')).'&nbsp;'.get_lang('SocialAddToFriends').'</a><br />
  153. <a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=365&width=610&user_friend='.$user_info['user_id'].'" class="thickbox" title="'.get_lang('SendAMessage').'">'.Display :: return_icon('mail_send.png', get_lang('SendAMessage')).'&nbsp;'.get_lang('SendAMessage').'</a>';
  154. } else {
  155. $table_row[] = '<a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=365&width=610&user_friend='.$user_info['user_id'].'" class="thickbox" title="'.get_lang('SendAMessage').'">'.Display :: return_icon('mail_send.png', get_lang('SendAMessage')).'&nbsp;'.get_lang('SendAMessage').'</a>';
  156. }
  157. }
  158. }
  159. $table_data[] = $table_row;
  160. }
  161. $table_header[] = array(get_lang('UserPicture'),false,'width="90"');
  162. $table_header[] = array(get_lang('Name'),true);
  163. //$table_header[] = array(get_lang('LastName'),true);
  164. if (api_get_setting('show_email_addresses') == 'true') {
  165. $table_header[] = array(get_lang('Email'),true);
  166. }
  167. $user_anonymous=api_get_anonymous_id();
  168. if (api_get_setting('allow_social_tool')=='true' && api_get_user_id()<>$user_anonymous && api_get_user_id()<>0) {
  169. $table_header[] = array(get_lang('Friends'),false,'width="200"');
  170. }
  171. /*this feature is deprecated
  172. if ( api_get_setting('allow_message_tool')=='true' && isset($_SESSION['_user'])) {
  173. $table_header[] = array(get_lang('SendMessage'),true);
  174. }
  175. */
  176. $sorting_options['column'] = (isset ($_GET['column']) ? (int)$_GET['column'] : 2);
  177. /*if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true' ) {
  178. //send_invitation_friend_user();
  179. echo '<div align="right"><input type="button" name="id_btn_send_invitation" id="id_btn_send_invitation" value="'.get_lang('SendInviteMessage').'"/></div>';
  180. echo '<form action="whoisonline.php" name="form_register_friend" id="form_register_friend" method="post">';
  181. }*/
  182. Display::display_sortable_table($table_header,$table_data,$sorting_options,array('per_page_default'=>count($table_data)),$extra_params);
  183. /*if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true' ) {
  184. echo '</form>';
  185. }*/
  186. }
  187. }
  188. /**
  189. * Displays the information of an individual user
  190. * @param int $user_id
  191. */
  192. function display_individual_user($user_id)
  193. {
  194. global $interbreadcrumb;
  195. $safe_user_id = Database::escape_string($user_id);
  196. // to prevent a hacking attempt: http://www.dokeos.com/forum/viewtopic.php?t=5363
  197. $user_table=Database::get_main_table(TABLE_MAIN_USER);
  198. $sql = "SELECT * FROM $user_table WHERE user_id='".$safe_user_id."'";
  199. $result=api_sql_query($sql,__FILE__,__LINE__);
  200. if (Database::num_rows($result)==1) {
  201. $user_object = Database::fetch_object($result);
  202. $name = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;<b>('.get_lang('Me').')</b>' : '' );
  203. $alt = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  204. $status = ($user_object->status == COURSEMANAGER ? get_lang('Teacher') : get_lang('Student'));
  205. $interbreadcrumb[]=array("url" => "whoisonline.php","name" => get_lang('UsersOnLineList'));
  206. Display::display_header($alt);
  207. echo '<div class="actions-title">';
  208. echo $alt;
  209. echo '</div><br/>';
  210. echo '<div style="text-align: center">';
  211. if (strlen(trim($user_object->picture_uri)) > 0) {
  212. $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id,'system');
  213. $sysdir = $sysdir_array['dir'];
  214. $webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id,'web');
  215. $webdir = $webdir_array['dir'];
  216. $fullurl=$webdir.$user_object->picture_uri;
  217. $system_image_path=$sysdir.$user_object->picture_uri;
  218. list($width, $height, $type, $attr) = getimagesize($system_image_path);
  219. $resizing = (($height > 200) ? 'height="200"' : '');
  220. $height += 30;
  221. $width += 30;
  222. $window_name = 'window'.uniqid('');
  223. // get the path,width and height from original picture
  224. $big_image = $webdir.'big_'.$user_object->picture_uri;
  225. $big_image_size = @getimagesize(api_url_to_local_path($big_image));
  226. $big_image_width= $big_image_size[0];
  227. $big_image_height= $big_image_size[1];
  228. $url_big_image = $big_image.'?rnd='.time();
  229. echo '<input type="image" src="'.$fullurl.'" alt="'.$alt.'" onclick="return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/><br />';
  230. global $user_anonymous;
  231. if (api_get_setting('allow_social_tool')=='true' && api_get_user_id()<>$user_anonymous && api_get_user_id()<>0) {
  232. echo '<br />';
  233. echo '<a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$safe_user_id.'">'.get_lang('ViewSharedProfile').'</a>';
  234. echo '<br />';
  235. }
  236. } else {
  237. echo Display::return_icon('unknown.jpg',get_lang('Unknown'));
  238. echo '<br />';
  239. }
  240. if (api_get_setting("show_email_addresses") == "true")
  241. {
  242. echo Display::encrypted_mailto_link($user_object->email,$user_object->email).'<br />';
  243. }
  244. echo $status.'<br />';
  245. echo '</div>';
  246. if ($user_object->competences) {
  247. echo '<dt><div class="actions-message"><strong>'.get_lang('MyCompetences').'</strong></div></dt>';
  248. echo '<dd>'.$user_object->competences.'</dd>';
  249. }
  250. if ($user_object->diplomas) {
  251. echo '<dt><div class="actions-message"><strong>'.get_lang('MyDiplomas').'</strong></div></dt>';
  252. echo '<dd>'.$user_object->diplomas.'</dd>';
  253. }
  254. if ($user_object->teach) {
  255. echo '<dt><div class="actions-message"><strong>'.get_lang('MyTeach').'</strong></div></dt>';
  256. echo '<dd>'.$user_object->teach.'</dd>';;
  257. }
  258. display_productions($user_object->user_id);
  259. if ($user_object->openarea) {
  260. echo '<dt><div class="actions-message"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div></dt>';
  261. echo '<dd>'.$user_object->openarea.'</dd>';
  262. }
  263. }
  264. else
  265. {
  266. Display::display_header(get_lang('UsersOnLineList'));
  267. echo '<div class="actions-title">';
  268. echo get_lang('UsersOnLineList');
  269. echo '</div>';
  270. }
  271. }
  272. /**
  273. * Display productions in whoisonline
  274. * @param int $user_id User id
  275. * @todo use the correct api_get_path instead of $clarolineRepositoryWeb
  276. */
  277. function display_productions($user_id)
  278. {
  279. $sysdir_array = UserManager::get_user_picture_path_by_id($user_id,'system');
  280. $sysdir = $sysdir_array['dir'].$user_id.'/';
  281. $webdir_array = UserManager::get_user_picture_path_by_id($user_id,'web');
  282. $webdir = $webdir_array['dir'].$user_id.'/';
  283. if( !is_dir($sysdir)) {
  284. mkpath($sysdir);
  285. }
  286. $handle = opendir($sysdir);
  287. $productions = array();
  288. while ($file = readdir($handle)) {
  289. if ($file == '.' || $file == '..' || $file == '.htaccess') {
  290. continue; // Skip current and parent directories
  291. }
  292. $productions[] = $file;
  293. }
  294. if(count($productions) > 0) {
  295. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  296. echo '<dd><ul>';
  297. foreach($productions as $index => $file) {
  298. // Only display direct file links to avoid browsing an empty directory
  299. if(is_file($sysdir.$file) && $file != $webdir_array['file']){
  300. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  301. }
  302. // Real productions are under a subdirectory by the User's id
  303. if(is_dir($sysdir.$file)) {
  304. $subs = scandir($sysdir.$file);
  305. foreach($subs as $my => $sub) {
  306. if(substr($sub,0,1) != '.' && is_file($sysdir.$file.'/'.$sub))
  307. {
  308. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  309. }
  310. }
  311. }
  312. }
  313. echo '</ul></dd>';
  314. }
  315. }
  316. // This if statement prevents users accessing the who's online feature when it has been disabled.
  317. if ((api_get_setting('showonline','world') == 'true' AND !$_user['user_id']) OR ((api_get_setting('showonline','users') == 'true' OR api_get_setting('showonline','course') == 'true') AND $_user['user_id'])) {
  318. if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  319. $user_list = Who_is_online_in_this_course($_user['user_id'],api_get_setting('time_limit_whosonline'),$_GET['cidReq']);
  320. } else {
  321. $user_list = WhoIsOnline($_user['user_id'],$_configuration['statistics_database'],api_get_setting('time_limit_whosonline'));
  322. }
  323. $total=count($user_list);
  324. if (!isset($_GET['id']))
  325. {
  326. Display::display_header(get_lang('UsersOnLineList'));
  327. echo '<div class="actions-title">';
  328. echo get_lang('UsersOnLineList');
  329. echo '</div>';
  330. echo '<div class="actions-message">'.get_lang('TotalOnLine').' : '.$total.'</div>';
  331. if ($_GET['id']=='') {
  332. echo '<p><a class="refresh" href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
  333. } else {
  334. if(0) // if ($_user['user_id'] && $_GET["id"] != $_user['user_id'])
  335. {
  336. echo '<a href="'.api_get_self().'?chatid='.Security::remove_XSS($_GET['id']).'">'.get_lang('SendChatRequest').'</a>';
  337. }
  338. }
  339. }
  340. if ($user_list!=false)
  341. {
  342. if (!isset($_GET['id']))
  343. {
  344. display_user_list($user_list, $_plugins);
  345. }
  346. else //individual user information - also displays header info
  347. {
  348. display_individual_user(Security::remove_XSS($_GET['id']));
  349. }
  350. }
  351. elseif(isset($_GET['id']))
  352. {
  353. Display::display_header(get_lang('UsersOnLineList'));
  354. echo '<div class="actions-title">';
  355. echo get_lang('UsersOnLineList');
  356. echo '</div>';
  357. }
  358. }
  359. else
  360. {
  361. Display::display_header(get_lang('UsersOnLineList'));
  362. Display::display_error_message(get_lang('AccessNotAllowed'));
  363. }
  364. $referer = empty($_GET['referer'])?'index.php':api_htmlentities(strip_tags($_GET['referer']),ENT_QUOTES,$charset);
  365. if (isset($_GET['id'])) {
  366. echo '<a href="whoisonline.php" class="fake_button_back">'.get_lang('Back').'</a>';
  367. } else {
  368. echo '<a href="'.$referer.'" class="fake_button_back">'.get_lang('BackHome').'</a>';
  369. }
  370. /*
  371. ==============================================================================
  372. FOOTER
  373. ==============================================================================
  374. */
  375. /*echo '<div align="center"><a href="http://main.svndokeos.net/main/upload/users/4/4_49aeb3bb8bba5.jpg" class="thickbox">hola</a></div>';*/
  376. Display::display_footer();
  377. ?>