whoisonline.php 15 KB

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