whoisonline.php 16 KB

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