whoisonline.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php // $Id: whoisonline.php 18324 2009-02-07 16:20:34Z 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');
  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">
  43. $(document).ready(function (){
  44. $("input#id_btn_send_invitation").bind("click", function(){
  45. if (confirm("'.get_lang('SendMessageInvitation').'")) {
  46. $("#form_register_friend").submit();
  47. }
  48. });
  49. });
  50. </script>';
  51. if ($_GET['chatid'] != '')
  52. {
  53. //send out call request
  54. $time = time();
  55. $time = date("Y-m-d H:i:s", $time);
  56. $chatid = addslashes($_GET['chatid']);
  57. $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).")";
  58. $result=api_sql_query($sql,__FILE__,__LINE__);
  59. //redirect caller to chat
  60. header("Location: ".$_configuration['code_append']."chat/chat.php?".api_get_cidreq()."&origin=whoisonline&target=".Security::remove_XSS($chatid));
  61. exit();
  62. }
  63. /**
  64. * Displays a sortable table with the list of online users.
  65. * @param array $user_list
  66. */
  67. function display_user_list($user_list, $_plugins)
  68. {
  69. global $charset;
  70. if ($_GET["id"]=='')
  71. {
  72. $extra_params = array();
  73. $course_url = '';
  74. if(strlen($_GET['cidReq']) > 0)
  75. {
  76. $extra_params['cidReq'] = Database::escape_string($_GET['cidReq']);
  77. $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
  78. }
  79. foreach($user_list as $user)
  80. {
  81. $uid=$user[0];
  82. $user_info = api_get_user_info($uid);
  83. $table_row = array();
  84. $url = '?id='.$uid.$course_url;
  85. $image_array=UserManager::get_user_picture_path_by_id($uid,'web',false,true);
  86. $table_row[] = '<a href="'.$url.'"><img src="'.$image_array['dir'].$image_array['file'].'" border="1" height="100"></a>';
  87. $table_row[] = '<a href="'.$url.'">'.$user_info['firstName'].'</a>';
  88. $table_row[] = '<a href="'.$url.'">'.$user_info['lastName'].'</a>';
  89. if (api_get_setting('allow_social_tool')=='true') {
  90. if ($user_info['user_id']<>api_get_user_id()) {
  91. $table_row[] = get_lang('Invitation').' :<input type="checkbox" name="id_name_chek[]" id="id_name_chek" value="'.$user_info['user_id'].'"/>';
  92. }
  93. }
  94. if (api_get_setting("show_email_addresses") == "true")
  95. {
  96. $table_row[] = Display::encrypted_mailto_link($user_info['mail']);
  97. }
  98. if ( api_is_plugin_installed($_plugins, 'messages') && isset($_SESSION['_user']) )
  99. {
  100. $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>';
  101. }
  102. $table_data[] = $table_row;
  103. }
  104. $table_header[] = array(get_lang('UserPicture'),true,'width="50"');
  105. $table_header[] = array(get_lang('FirstName'),true);
  106. $table_header[] = array(get_lang('LastName'),true);
  107. if (api_get_setting('allow_social_tool')=='true') {
  108. $table_header[] = array(get_lang('Friends'),true,'width="100"');
  109. }
  110. if (api_get_setting("show_email_addresses") == "true")
  111. {
  112. $table_header[] = array(get_lang('Email'),true);
  113. }
  114. if ( api_is_plugin_installed($_plugins, 'messages') && isset($_SESSION['_user']))
  115. {
  116. $table_header[] = array(get_lang('SendMessage'),true);
  117. }
  118. $sorting_options['column'] = (isset ($_GET['column']) ? (int)$_GET['column'] : 2);
  119. if (api_get_setting('allow_social_tool')=='true') {
  120. send_invitation_friend_user();
  121. echo '<div align="right"><input type="button" name="id_btn_send_invitation" id="id_btn_send_invitation" value="'.get_lang('SendInvitationToFriends').'"/></div>';
  122. echo '<form action="whoisonline.php" name="form_register_friend" id="form_register_friend" method="post">';
  123. }
  124. Display::display_sortable_table($table_header,$table_data,$sorting_options,array('per_page_default'=>count($table_data)),$extra_params);
  125. if (api_get_setting('allow_social_tool')=='true') {
  126. echo '</form>';
  127. }
  128. }
  129. }
  130. /**
  131. * Displays the information of an individual user
  132. * @param int $user_id
  133. */
  134. function display_individual_user($user_id)
  135. {
  136. global $interbreadcrumb;
  137. $safe_user_id = Database::escape_string($user_id);
  138. // to prevent a hacking attempt: http://www.dokeos.com/forum/viewtopic.php?t=5363
  139. $user_table=Database::get_main_table(TABLE_MAIN_USER);
  140. $sql = "SELECT * FROM $user_table WHERE user_id='".$safe_user_id."'";
  141. $result=api_sql_query($sql,__FILE__,__LINE__);
  142. if (Database::num_rows($result)==1)
  143. {
  144. $user_object = Database::fetch_object($result);
  145. $name = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;<b>('.get_lang('Me').')</b>' : '' );
  146. $alt = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  147. $status = ($user_object->status == COURSEMANAGER ? get_lang('Teacher') : get_lang('Student'));
  148. $interbreadcrumb[]=array("url" => "whoisonline.php","name" => get_lang('UsersOnLineList'));
  149. Display::display_header($alt);
  150. api_display_tool_title($alt);
  151. echo '<div style="text-align: center">';
  152. if (strlen(trim($user_object->picture_uri)) > 0)
  153. {
  154. $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id,'system');
  155. $sysdir = $sysdir_array['dir'];
  156. $webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id,'web');
  157. $webdir = $webdir_array['dir'];
  158. $fullurl=$webdir.$user_object->picture_uri;
  159. $system_image_path=$sysdir.$user_object->picture_uri;
  160. list($width, $height, $type, $attr) = getimagesize($system_image_path);
  161. $resizing = (($height > 200) ? 'height="200"' : '');
  162. $height += 30;
  163. $width += 30;
  164. $window_name = 'window'.uniqid('');
  165. // get the path,width and height from original picture
  166. $big_image = $webdir.'big_'.$user_object->picture_uri;
  167. $big_image_size = @getimagesize($big_image);
  168. $big_image_width= $big_image_size[0];
  169. $big_image_height= $big_image_size[1];
  170. $url_big_image = $big_image.'?rnd='.time();
  171. echo '<input type="image" src="'.$fullurl.'" alt="'.$alt.'" onclick="return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/><br />';
  172. }
  173. if (api_get_setting("show_email_addresses") == "true")
  174. {
  175. echo Display::encrypted_mailto_link($user_object->email,$user_object->email).'<br />';
  176. }
  177. echo $status.'<br />';
  178. echo '</div>';
  179. if ($user_object->competences)
  180. {
  181. echo '<dt><strong>'.get_lang('MyCompetences').'</strong></dt>';
  182. echo '<dd>'.$user_object->competences.'</dd>';
  183. }
  184. if ($user_object->diplomas)
  185. {
  186. echo '<dt><strong>'.get_lang('MyDiplomas').'</strong></dt>';
  187. echo '<dd>'.$user_object->diplomas.'</dd>';
  188. }
  189. if ($user_object->teach) {
  190. echo '<dt><strong>'.get_lang('MyTeach').'</strong></dt>';
  191. echo '<dd>'.$user_object->teach.'</dd>';;
  192. }
  193. display_productions($user_object->user_id);
  194. if ($user_object->openarea) {
  195. echo '<dt><strong>'.get_lang('MyPersonalOpenArea').'</strong></dt>';
  196. echo '<dd>'.$user_object->openarea.'</dd>';
  197. }
  198. }
  199. else
  200. {
  201. Display::display_header(get_lang('UsersOnLineList'));
  202. api_display_tool_title(get_lang('UsersOnLineList'));
  203. }
  204. }
  205. /**
  206. * Display productions in whoisonline
  207. * @param int $user_id User id
  208. * @todo use the correct api_get_path instead of $clarolineRepositoryWeb
  209. */
  210. function display_productions($user_id)
  211. {
  212. global $clarolineRepositoryWeb, $disabled_output;
  213. $sysdir_array = UserManager::get_user_picture_path_by_id($user_id,'system');
  214. $sysdir = $sysdir_array['dir'].$user_id.'/';
  215. $webdir_array = UserManager::get_user_picture_path_by_id($user_id,'web');
  216. $webdir = $webdir_array['dir'].$user_id.'/';
  217. if( !is_dir($sysdir))
  218. {
  219. mkpath($sysdir);
  220. }
  221. $handle = opendir($sysdir);
  222. $productions = array();
  223. while ($file = readdir($handle))
  224. {
  225. if ($file == '.' || $file == '..' || $file == '.htaccess')
  226. {
  227. continue; // Skip current and parent directories
  228. }
  229. $productions[] = $file;
  230. }
  231. if(count($productions) > 0)
  232. {
  233. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  234. echo '<dd><ul>';
  235. foreach($productions as $index => $file)
  236. {
  237. // Only display direct file links to avoid browsing an empty directory
  238. if(is_file($sysdir.$file) && $file != $webdir_array['file']){
  239. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  240. }
  241. // Real productions are under a subdirectory by the User's id
  242. if(is_dir($sysdir.$file)){
  243. $subs = scandir($sysdir.$file);
  244. foreach($subs as $my => $sub)
  245. {
  246. if(substr($sub,0,1) != '.' && is_file($sysdir.$file.'/'.$sub))
  247. {
  248. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  249. }
  250. }
  251. }
  252. }
  253. echo '</ul></dd>';
  254. }
  255. }
  256. /**
  257. * Send invitation a your friends
  258. * @author Isaac Flores Paz <isaac.flores.paz@gmail.com>
  259. * @param void
  260. * @return string message invitation
  261. */
  262. function send_invitation_friend_user() {
  263. $id_user_friend=array();
  264. $count_is_true=false;
  265. $count_number_is_true=0;
  266. $count_number_chek=count($_POST['id_name_chek']);
  267. if ($count_number_chek>0) {
  268. $user_info=array();
  269. $user_id=api_get_user_id();
  270. $user_info=api_get_user_info($user_id);
  271. $message_title=get_lang('Invitation');
  272. $message_content=get_lang('InvitationSentBy').' : '.$user_info['firstName'].' '.$user_info['lastName'];
  273. $id_user_friend=$_POST['id_name_chek'];
  274. for ($i=0;$i<$count_number_chek;$i++) {
  275. $count_is_true=UserFriend::send_invitation_friend($user_id,$id_user_friend[$i],$message_title,$message_content);
  276. if ($count_is_true===true) {
  277. $count_number_is_true++;
  278. }
  279. }
  280. if (api_get_setting('allow_social_tool')=='true') {
  281. if ($count_number_is_true>0) {
  282. echo '<div align="center">'.Display::display_normal_message(get_lang('InvitationHasBeenSent').' : '.$count_number_is_true.' '.get_lang('Invitations')).'</div>';
  283. }else {
  284. echo '<div align="center">'.Display::display_error_message(get_lang('InvitationHasBeenNotSent')).' : '.'</div>';
  285. }
  286. }
  287. }
  288. }
  289. // This if statement prevents users accessing the who's online feature when it has been disabled.
  290. 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']))
  291. {
  292. if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0)
  293. {
  294. $user_list = Who_is_online_in_this_course($_user['user_id'],api_get_setting('time_limit_whosonline'),$_GET['cidReq']);
  295. }
  296. else
  297. {
  298. $user_list = WhoIsOnline($_user['user_id'],$_configuration['statistics_database'],api_get_setting('time_limit_whosonline'));
  299. }
  300. $total=count($user_list);
  301. if (!isset($_GET['id']))
  302. {
  303. Display::display_header(get_lang('UsersOnLineList'));
  304. api_display_tool_title(get_lang('UsersOnLineList'));
  305. echo '<b>'.get_lang('TotalOnLine').' : '.$total.'</b>';
  306. if ($_GET['id']=='')
  307. {
  308. echo '<p><a href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
  309. }
  310. else
  311. {
  312. if(0) // if ($_user['user_id'] && $_GET["id"] != $_user['user_id'])
  313. {
  314. echo '<a href="'.api_get_self().'?chatid='.Security::remove_XSS($_GET['id']).'">'.get_lang('SendChatRequest').'</a>';
  315. }
  316. }
  317. }
  318. if ($user_list!=false)
  319. {
  320. if (!isset($_GET['id']))
  321. {
  322. display_user_list($user_list, $_plugins);
  323. }
  324. else //individual user information - also displays header info
  325. {
  326. display_individual_user($_GET['id']);
  327. }
  328. }
  329. elseif(isset($_GET['id']))
  330. {
  331. Display::display_header(get_lang('UsersOnLineList'));
  332. api_display_tool_title(get_lang('UsersOnLineList'));
  333. }
  334. }
  335. else
  336. {
  337. Display::display_header(get_lang('UsersOnLineList'));
  338. Display::display_error_message(get_lang('AccessNotAllowed'));
  339. }
  340. $referer = empty($_GET['referer'])?'index.php':htmlentities(strip_tags($_GET['referer']),ENT_QUOTES,$charset);
  341. echo '<a href="'.(Security::remove_XSS($_GET['id'])?'javascript:window.history.back();':$referer).'">&lt; '.get_lang('Back').'</a>';
  342. /*
  343. ==============================================================================
  344. FOOTER
  345. ==============================================================================
  346. */
  347. Display::display_footer();
  348. ?>