whoisonline.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php // $Id: whoisonline.php 17479 2008-12-29 20:24:11Z cfasanando $
  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');
  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. // table definitions
  32. $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
  33. $htmlHeadXtra[] = '<script type="text/javascript">
  34. function show_image(image,width,height) {
  35. width = parseInt(width) + 20;
  36. height = parseInt(height) + 20;
  37. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
  38. }
  39. </script>';
  40. if ($_GET['chatid'] != '')
  41. {
  42. //send out call request
  43. $time = time();
  44. $time = date("Y-m-d H:i:s", $time);
  45. $chatid = addslashes($_GET['chatid']);
  46. $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).")";
  47. $result=api_sql_query($sql,__FILE__,__LINE__);
  48. //redirect caller to chat
  49. header("Location: ".$_configuration['code_append']."chat/chat.php?".api_get_cidreq()."&origin=whoisonline&target=".Security::remove_XSS($chatid));
  50. exit();
  51. }
  52. /**
  53. * Displays a sortable table with the list of online users.
  54. * @param array $user_list
  55. */
  56. function display_user_list($user_list, $_plugins)
  57. {
  58. global $charset;
  59. if ($_GET["id"]=='')
  60. {
  61. $extra_params = array();
  62. $course_url = '';
  63. if(strlen($_GET['cidReq']) > 0)
  64. {
  65. $extra_params['cidReq'] = Database::escape_string($_GET['cidReq']);
  66. $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
  67. }
  68. foreach($user_list as $user)
  69. {
  70. $uid=$user[0];
  71. $user_info = api_get_user_info($uid);
  72. $table_row = array();
  73. $url = '?id='.$uid.$course_url;
  74. $image_array=UserManager::get_user_picture_path_by_id($uid,'web',false,true);
  75. $table_row[] = '<a href="'.$url.'"><img src="'.$image_array['dir'].$image_array['file'].'" border="1" height="100"></a>';
  76. $table_row[] = '<a href="'.$url.'">'.$user_info['firstName'].'</a>';
  77. $table_row[] = '<a href="'.$url.'">'.$user_info['lastName'].'</a>';
  78. if (api_get_setting("show_email_addresses") == "true")
  79. {
  80. $table_row[] = Display::encrypted_mailto_link($user_info['mail']);
  81. }
  82. if ( api_is_plugin_installed($_plugins, 'messages') && isset($_SESSION['_user']) )
  83. {
  84. $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>';
  85. }
  86. $table_data[] = $table_row;
  87. }
  88. $table_header[] = array(get_lang('UserPicture'),true,'width="50"');
  89. $table_header[] = array(get_lang('FirstName'),true);
  90. $table_header[] = array(get_lang('LastName'),true);
  91. if (api_get_setting("show_email_addresses") == "true")
  92. {
  93. $table_header[] = array(get_lang('Email'),true);
  94. }
  95. if ( api_is_plugin_installed($_plugins, 'messages') && isset($_SESSION['_user']))
  96. {
  97. $table_header[] = array(get_lang('SendMessage'),true);
  98. }
  99. $sorting_options['column'] = (isset ($_GET['column']) ? (int)$_GET['column'] : 2);
  100. Display::display_sortable_table($table_header,$table_data,$sorting_options,array('per_page_default'=>count($table_data)),$extra_params);
  101. }
  102. }
  103. /**
  104. * Displays the information of an individual user
  105. * @param int $user_id
  106. */
  107. function display_individual_user($user_id)
  108. {
  109. global $interbreadcrumb;
  110. $safe_user_id = Database::escape_string($user_id);
  111. // to prevent a hacking attempt: http://www.dokeos.com/forum/viewtopic.php?t=5363
  112. $user_table=Database::get_main_table(TABLE_MAIN_USER);
  113. $sql = "SELECT * FROM $user_table WHERE user_id='".$safe_user_id."'";
  114. $result=api_sql_query($sql,__FILE__,__LINE__);
  115. if (Database::num_rows($result)==1)
  116. {
  117. $user_object = Database::fetch_object($result);
  118. $name = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;<b>('.get_lang('Me').')</b>' : '' );
  119. $alt = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  120. $status = ($user_object->status == COURSEMANAGER ? get_lang('Teacher') : get_lang('Student'));
  121. $interbreadcrumb[]=array("url" => "whoisonline.php","name" => get_lang('UsersOnLineList'));
  122. Display::display_header($alt);
  123. api_display_tool_title($alt);
  124. echo '<div style="text-align: center">';
  125. if (strlen(trim($user_object->picture_uri)) > 0)
  126. {
  127. $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id,'system');
  128. $sysdir = $sysdir_array['dir'];
  129. $webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id,'web');
  130. $webdir = $webdir_array['dir'];
  131. $fullurl=$webdir.$user_object->picture_uri;
  132. $system_image_path=$sysdir.$user_object->picture_uri;
  133. list($width, $height, $type, $attr) = getimagesize($system_image_path);
  134. $resizing = (($height > 200) ? 'height="200"' : '');
  135. $height += 30;
  136. $width += 30;
  137. $window_name = 'window'.uniqid('');
  138. // get the path,width and height from original picture
  139. $big_image = $webdir.'big_'.$user_object->picture_uri;
  140. $big_image_size = @getimagesize($big_image);
  141. $big_image_width= $big_image_size[0];
  142. $big_image_height= $big_image_size[1];
  143. $url_big_image = $big_image.'?rnd='.time();
  144. echo '<input type="image" src="'.$fullurl.'" alt="'.$alt.'" onclick="return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/><br />';
  145. }
  146. if (api_get_setting("show_email_addresses") == "true")
  147. {
  148. echo Display::encrypted_mailto_link($user_object->email,$user_object->email).'<br />';
  149. }
  150. echo $status.'<br />';
  151. echo '</div>';
  152. if ($user_object->competences)
  153. {
  154. echo '<dt><strong>'.get_lang('MyCompetences').'</strong></dt>';
  155. echo '<dd>'.$user_object->competences.'</dd>';
  156. }
  157. if ($user_object->diplomas)
  158. {
  159. echo '<dt><strong>'.get_lang('MyDiplomas').'</strong></dt>';
  160. echo '<dd>'.$user_object->diplomas.'</dd>';
  161. }
  162. if ($user_object->teach) {
  163. echo '<dt><strong>'.get_lang('MyTeach').'</strong></dt>';
  164. echo '<dd>'.$user_object->teach.'</dd>';;
  165. }
  166. display_productions($user_object->user_id);
  167. if ($user_object->openarea) {
  168. echo '<dt><strong>'.get_lang('MyPersonalOpenArea').'</strong></dt>';
  169. echo '<dd>'.$user_object->openarea.'</dd>';
  170. }
  171. }
  172. else
  173. {
  174. Display::display_header(get_lang('UsersOnLineList'));
  175. api_display_tool_title(get_lang('UsersOnLineList'));
  176. }
  177. }
  178. /**
  179. * Display productions in whoisonline
  180. * @param int $user_id User id
  181. * @todo use the correct api_get_path instead of $clarolineRepositoryWeb
  182. */
  183. function display_productions($user_id)
  184. {
  185. global $clarolineRepositoryWeb, $disabled_output;
  186. $sysdir_array = UserManager::get_user_picture_path_by_id($user_id,'system');
  187. $sysdir = $sysdir_array['dir'].$user_id.'/';
  188. $webdir_array = UserManager::get_user_picture_path_by_id($user_id,'web');
  189. $webdir = $webdir_array['dir'].$user_id.'/';
  190. if( !is_dir($sysdir))
  191. {
  192. mkpath($sysdir);
  193. }
  194. $handle = opendir($sysdir);
  195. $productions = array();
  196. while ($file = readdir($handle))
  197. {
  198. if ($file == '.' || $file == '..' || $file == '.htaccess')
  199. {
  200. continue; // Skip current and parent directories
  201. }
  202. $productions[] = $file;
  203. }
  204. if(count($productions) > 0)
  205. {
  206. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  207. echo '<dd><ul>';
  208. foreach($productions as $index => $file)
  209. {
  210. // Only display direct file links to avoid browsing an empty directory
  211. if(is_file($sysdir.$file) && $file != $webdir_array['file']){
  212. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  213. }
  214. // Real productions are under a subdirectory by the User's id
  215. if(is_dir($sysdir.$file)){
  216. $subs = scandir($sysdir.$file);
  217. foreach($subs as $my => $sub)
  218. {
  219. if(substr($sub,0,1) != '.' && is_file($sysdir.$file.'/'.$sub))
  220. {
  221. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  222. }
  223. }
  224. }
  225. }
  226. echo '</ul></dd>';
  227. }
  228. }
  229. // This if statement prevents users accessing the who's online feature when it has been disabled.
  230. 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']))
  231. {
  232. if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0)
  233. {
  234. $user_list = Who_is_online_in_this_course($_user['user_id'],api_get_setting('time_limit_whosonline'),$_GET['cidReq']);
  235. }
  236. else
  237. {
  238. $user_list = WhoIsOnline($_user['user_id'],$_configuration['statistics_database'],api_get_setting('time_limit_whosonline'));
  239. }
  240. $total=count($user_list);
  241. if (!isset($_GET['id']))
  242. {
  243. Display::display_header(get_lang('UsersOnLineList'));
  244. api_display_tool_title(get_lang('UsersOnLineList'));
  245. echo '<b>'.get_lang('TotalOnLine').' : '.$total.'</b>';
  246. if ($_GET['id']=='')
  247. {
  248. echo '<p><a href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
  249. }
  250. else
  251. {
  252. if(0) // if ($_user['user_id'] && $_GET["id"] != $_user['user_id'])
  253. {
  254. echo '<a href="'.api_get_self().'?chatid='.Security::remove_XSS($_GET['id']).'">'.get_lang('SendChatRequest').'</a>';
  255. }
  256. }
  257. }
  258. if ($user_list!=false)
  259. {
  260. if (!isset($_GET['id']))
  261. {
  262. display_user_list($user_list, $_plugins);
  263. }
  264. else //individual user information - also displays header info
  265. {
  266. display_individual_user($_GET['id']);
  267. }
  268. }
  269. elseif(isset($_GET['id']))
  270. {
  271. Display::display_header(get_lang('UsersOnLineList'));
  272. api_display_tool_title(get_lang('UsersOnLineList'));
  273. }
  274. }
  275. else
  276. {
  277. Display::display_header(get_lang('UsersOnLineList'));
  278. Display::display_error_message(get_lang('AccessNotAllowed'));
  279. }
  280. $referer = empty($_GET['referer'])?'index.php':htmlentities(strip_tags($_GET['referer']),ENT_QUOTES,$charset);
  281. echo '<a href="'.(Security::remove_XSS($_GET['id'])?'javascript:window.history.back();':$referer).'">&lt; '.get_lang('Back').'</a>';
  282. /*
  283. ==============================================================================
  284. FOOTER
  285. ==============================================================================
  286. */
  287. Display::display_footer();
  288. ?>