whoisonline.php 9.1 KB

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