whoisonline.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php // $Id: whoisonline.php 13297 2007-09-27 02:20:35Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  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, 181 rue Royale, B-1000 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. // @todo: is this necessary?
  26. if(isset($_GET['cidReq']))
  27. {
  28. $course_code = $_GET['cidReq'];
  29. }
  30. else
  31. {
  32. $cidReset = true;
  33. }
  34. // name of the language file that needs to be included
  35. $language_file = array('index','registration');
  36. // including necessary files
  37. require_once('./main/inc/global.inc.php');
  38. require_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  39. // table definitions
  40. $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
  41. if ($_GET['chatid'] != '')
  42. {
  43. //send out call request
  44. $time = time();
  45. $time = date("Y-m-d H:i:s", $time);
  46. $chatid = addslashes($_GET['chatid']);
  47. $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).")";
  48. $result=api_sql_query($sql,__FILE__,__LINE__);
  49. //redirect caller to chat
  50. header("Location: ".$_configuration['code_append']."chat/chat.php?cidReq=".$_cid."&origin=whoisonline&target=$chatid");
  51. exit();
  52. }
  53. /**
  54. * Displays a sortable table with the list of online users.
  55. * @param array $user_list
  56. */
  57. function display_user_list($user_list, $_plugins)
  58. {
  59. global $charset;
  60. if ($_GET["id"]=='')
  61. {
  62. $extra_params = array();
  63. $course_url = '';
  64. if(strlen($_GET['cidReq']) > 0)
  65. {
  66. $extra_params['cidReq'] = $_GET['cidReq'];
  67. $course_url = '&amp;cidReq='.$_GET['cidReq'];
  68. }
  69. foreach($user_list as $user)
  70. {
  71. $uid=$user[0];
  72. $user_info = api_get_user_info($uid);
  73. $table_row = array();
  74. $url = '?id='.$uid.$course_url;
  75. if(strlen($user_info['picture_uri']) > 0)
  76. {
  77. $table_row[] = '<span style="display:none;">1</span><a href="'.$url.'"><img src="'.api_get_path(WEB_CODE_PATH).'upload/users/'.$user_info['picture_uri'].'" alt="'.htmlentities($user_info['firstName'],ENT_QUOTES,$charset).'" width="40" border="0"/></a>';
  78. }
  79. else
  80. {
  81. $table_row[] = '<span style="display:none;">0</span>';
  82. }
  83. $table_row[] = '<a href="'.$url.'">'.$user_info['firstName'].'</a>';
  84. $table_row[] = '<a href="'.$url.'">'.$user_info['lastName'].'</a>';
  85. if (api_get_setting("show_email_addresses") == "true")
  86. {
  87. $table_row[] = Display::encrypted_mailto_link($user_info['mail']);
  88. }
  89. if ( api_is_plugin_installed($_plugins, 'messages') && isset($_SESSION['_user']) )
  90. {
  91. $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>';
  92. }
  93. $table_data[] = $table_row;
  94. }
  95. $table_header[] = array(get_lang('UserPicture'),true,'width="50"');
  96. $table_header[] = array(get_lang('FirstName'),true);
  97. $table_header[] = array(get_lang('LastName'),true);
  98. if (api_get_setting("show_email_addresses") == "true")
  99. {
  100. $table_header[] = array(get_lang('Email'),true);
  101. }
  102. if ( api_is_plugin_installed($_plugins, 'messages') && isset($_SESSION['_user']))
  103. {
  104. $table_header[] = array(get_lang('SendMessage'),true);
  105. }
  106. $sorting_options['column'] = (isset ($_GET['column']) ? $_GET['column'] : 2);
  107. Display::display_sortable_table($table_header,$table_data,$sorting_options,array('per_page_default'=>count($table_data)),$extra_params);
  108. }
  109. }
  110. /**
  111. * Displays the information of an individual user
  112. * @param int $user_id
  113. */
  114. function display_individual_user($user_id)
  115. {
  116. global $interbreadcrumb;
  117. // to prevent a hacking attempt: http://www.dokeos.com/forum/viewtopic.php?t=5363
  118. $user_table=Database::get_main_table(TABLE_MAIN_USER);
  119. $sql = "SELECT * FROM $user_table WHERE user_id='".mysql_real_escape_string($user_id)."'";
  120. $result=api_sql_query($sql,__FILE__,__LINE__);
  121. if (mysql_num_rows($result)==1)
  122. {
  123. $user_object = mysql_fetch_object($result);
  124. $name = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;<b>('.get_lang('Me').')</b>' : '' );
  125. $alt = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  126. $status = ($user_object->status == COURSEMANAGER ? get_lang('Teacher') : get_lang('Student'));
  127. $interbreadcrumb[]=array("url" => "whoisonline.php","name" => get_lang('UsersOnLineList'));
  128. Display::display_header($alt);
  129. api_display_tool_title($alt);
  130. echo '<div style="text-align: center">';
  131. if (strlen(trim($user_object->picture_uri)) > 0)
  132. {
  133. $fullurl=api_get_path(WEB_CODE_PATH).'upload/users/'.$user_object->picture_uri;
  134. $system_image_path=api_get_path(SYS_CODE_PATH).'upload/users/'.$user_object->picture_uri;
  135. list($width, $height, $type, $attr) = getimagesize($system_image_path);
  136. $resizing = (($height > 200) ? 'height="200"' : '');
  137. $height += 30;
  138. $width += 30;
  139. $window_name = 'window'.uniqid('');
  140. $onclick = $window_name."=window.open('".$fullurl."','".$window_name."','alwaysRaised=yes, alwaysLowered=no,alwaysOnTop=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=".$width.",height=".$height.",left=200,top=20'); return false;";
  141. echo '<a href="#" onclick="'.$onclick.'" ><img src="'.$fullurl.'" '.$resizing.' alt="'.$alt.'"/></a><br />';
  142. }
  143. if (api_get_setting("show_email_addresses") == "true")
  144. {
  145. echo Display::encrypted_mailto_link($user_object->email,$user_object->email).'<br />';
  146. }
  147. echo $status.'<br />';
  148. echo '</div>';
  149. if ($user_object->competences)
  150. {
  151. echo '<dt><strong>'.get_lang('Competences').'</strong></dt>';
  152. echo '<dd>'.$user_object->competences.'</dd>';
  153. }
  154. if ($user_object->diplomas)
  155. {
  156. echo '<dt><strong>'.get_lang('Diplomas').'</strong></dt>';
  157. echo '<dd>'.$user_object->diplomas.'</dd>';
  158. }
  159. if ($user_object->teach) {
  160. echo '<dt><strong>'.get_lang('Teach').'</strong></dt>';
  161. echo '<dd>'.$user_object->teach.'</dd>';;
  162. }
  163. display_productions($user_object->user_id);
  164. if ($user_object->openarea) {
  165. echo '<dt><strong>'.get_lang('Openarea').'</strong></dt>';
  166. echo '<dd>'.$user_object->openarea.'</dd>';
  167. }
  168. }
  169. }
  170. /**
  171. * Display productions in whoisonline
  172. * @param int $user_id User id
  173. * @todo use the correct api_get_path instead of $clarolineRepositoryWeb
  174. */
  175. function display_productions($user_id)
  176. {
  177. global $clarolineRepositoryWeb, $disabled_output;
  178. $sysdir=api_get_path(SYS_CODE_PATH).'upload/users/'.$user_id;
  179. $webdir=$clarolineRepositoryWeb.'upload/users/'.$user_id;
  180. if( !is_dir($sysdir))
  181. {
  182. mkpath($sysdir);
  183. }
  184. $handle = opendir($sysdir);
  185. $productions = array();
  186. while ($file = readdir($handle))
  187. {
  188. if ($file == '.' || $file == '..' || $file == '.htaccess')
  189. {
  190. continue; // Skip current and parent directories
  191. }
  192. $productions[] = $file;
  193. }
  194. if(count($productions) > 0)
  195. {
  196. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  197. echo '<dd><ul>';
  198. foreach($productions as $index => $file)
  199. {
  200. echo '<li><a href="'.$webdir.'/'.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  201. }
  202. echo '</ul></dd>';
  203. }
  204. }
  205. // This if statement prevents users accessing the who's online feature when it has been disabled.
  206. if ((get_setting('showonline','world') == 'true' AND !$_user['user_id']) OR (get_setting('showonline','users') == 'true' AND $_user['user_id']))
  207. {
  208. if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0)
  209. {
  210. $user_list = Who_is_online_in_this_course($_user['user_id'],api_get_setting('time_limit_whosonline'),$_GET['cidReq']);
  211. }
  212. else
  213. {
  214. $user_list = WhoIsOnline($_user['user_id'],$_configuration['statistics_database'],api_get_setting('time_limit_whosonline'));
  215. }
  216. $total=count($user_list);
  217. if (!isset($_GET['id']))
  218. {
  219. Display::display_header(get_lang('UsersOnLineList'));
  220. api_display_tool_title(get_lang('UsersOnLineList'));
  221. echo '<b>'.get_lang('TotalOnLine').' : '.$total.'</b>';
  222. if ($_GET['id']=='')
  223. {
  224. echo '<p><a href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
  225. }
  226. else
  227. {
  228. if(0) // if ($_user['user_id'] && $_GET["id"] != $_user['user_id'])
  229. {
  230. echo '<a href="'.api_get_self().'?chatid='.$_GET['id'].'">'.get_lang('SendChatRequest').'</a>';
  231. }
  232. }
  233. }
  234. if ($user_list!=false)
  235. {
  236. if (!isset($_GET['id']))
  237. {
  238. display_user_list($user_list, $_plugins);
  239. }
  240. else //individual user information
  241. {
  242. display_individual_user($_GET['id']);
  243. }
  244. }
  245. }
  246. else
  247. {
  248. Display::display_header(get_lang('UsersOnLineList'));
  249. Display::display_error_message(get_lang('AccessNotAllowed'));
  250. }
  251. $referer = empty($_GET['referer'])?'index.php':htmlentities(strip_tags($_GET['referer']),ENT_QUOTES,$charset);
  252. echo '<a href="'.($_GET['id']?'javascript:window.history.back();':$referer).'">&lt; '.get_lang('Back').'</a>';
  253. /*
  254. ==============================================================================
  255. FOOTER
  256. ==============================================================================
  257. */
  258. Display::display_footer();
  259. ?>