whoisonline.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. $name = api_get_person_name($user_info['firstName'], $user_info['lastName']);
  127. $table_row[] = '<a href="'.$url.'"><img title = "'.$name.'" alt="'.$name.'" src="'.$friends_profile['file'].'" '.$friends_profile['style'].' border="1"></a>';
  128. $table_row[] = '<a href="'.$url.'" style="font-size:10px;">'.api_get_person_name($user_info['firstName'], $user_info['lastName']).'</a>';
  129. //$table_row[] = '<a href="'.$url.'">'.$user_info['lastName'].'</a>';
  130. if (api_get_setting('show_email_addresses') == 'true') {
  131. $table_row[] = Display::encrypted_mailto_link($user_info['mail']);
  132. }
  133. $user_anonymous = api_get_anonymous_id();
  134. /*
  135. if (api_get_setting('allow_social_tool') == 'true' && api_get_user_id() <> $user_anonymous && api_get_user_id() <> 0) {
  136. if ($user_info['user_id'] != api_get_user_id() && !api_is_anonymous($user_info['user_id'])) {
  137. $user_relation = UserFriend::get_relation_between_contacts(api_get_user_id(), $user_info['user_id']);
  138. // not in my contacts
  139. if ($user_relation == 0 || $user_relation == 6) {
  140. $table_row[] = '<a href="main/messages/send_message_to_userfriend.inc.php?view_panel=2&height=300&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 />
  141. <a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=310&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>';
  142. } else {
  143. $table_row[] = '<a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=310&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>';
  144. }
  145. }
  146. }
  147. */
  148. $table_data[] = $table_row;
  149. }
  150. $table_header[] = array(get_lang('UserPicture'), false, 'width="90"');
  151. $table_header[] = array(get_lang('Name'), true);
  152. //$table_header[] = array(get_lang('LastName'), true);
  153. if (api_get_setting('show_email_addresses') == 'true') {
  154. $table_header[] = array(get_lang('Email'), true);
  155. }
  156. $user_anonymous = api_get_anonymous_id();
  157. if (api_get_setting('allow_social_tool') == 'true' && api_get_user_id() <> $user_anonymous && api_get_user_id() <> 0) {
  158. $table_header[] = array(get_lang('Friends'), false, 'width="200"');
  159. }
  160. /*this feature is deprecated
  161. if (api_get_setting('allow_message_tool') == 'true' && isset($_SESSION['_user'])) {
  162. $table_header[] = array(get_lang('SendMessage'), true);
  163. }
  164. */
  165. $sorting_options['column'] = (isset($_GET['column']) ? (int)$_GET['column'] : 2);
  166. /*if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
  167. //send_invitation_friend_user();
  168. echo '<div align="right"><input type="button" name="id_btn_send_invitation" id="id_btn_send_invitation" value="'.get_lang('SendInviteMessage').'"/></div>';
  169. echo '<form action="whoisonline.php" name="form_register_friend" id="form_register_friend" method="post">';
  170. }*/
  171. Display::display_sortable_table($table_header, $table_data, $sorting_options, array('per_page' => 30), $extra_params,array(),'grid');
  172. /*if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true' ) {
  173. echo '</form>';
  174. }*/
  175. }
  176. }
  177. /**
  178. * Displays the information of an individual user
  179. * @param int $user_id
  180. */
  181. function display_individual_user($user_id) {
  182. global $interbreadcrumb;
  183. $safe_user_id = Database::escape_string($user_id);
  184. // to prevent a hacking attempt: http://www.dokeos.com/forum/viewtopic.php?t=5363
  185. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  186. $sql = "SELECT * FROM $user_table WHERE user_id='".$safe_user_id."'";
  187. $result = Database::query($sql, __FILE__, __LINE__);
  188. if (Database::num_rows($result) == 1) {
  189. $user_object = Database::fetch_object($result);
  190. $name = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;<strong>('.get_lang('Me').')</strong>' : '' );
  191. $alt = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  192. $status = ($user_object->status == COURSEMANAGER ? get_lang('Teacher') : get_lang('Student'));
  193. $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList'));
  194. Display::display_header($alt);
  195. echo '<div class="actions-title">';
  196. echo $alt;
  197. echo '</div><br />';
  198. echo '<div style="text-align: center">';
  199. if (strlen(trim($user_object->picture_uri)) > 0) {
  200. $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'system');
  201. $sysdir = $sysdir_array['dir'];
  202. $webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'web');
  203. $webdir = $webdir_array['dir'];
  204. $fullurl = $webdir.$user_object->picture_uri;
  205. $system_image_path = $sysdir.$user_object->picture_uri;
  206. list($width, $height, $type, $attr) = @getimagesize($system_image_path);
  207. $resizing = (($height > 200) ? 'height="200"' : '');
  208. $height += 30;
  209. $width += 30;
  210. $window_name = 'window'.uniqid('');
  211. // get the path,width and height from original picture
  212. $big_image = $webdir.'big_'.$user_object->picture_uri;
  213. $big_image_size = api_getimagesize($big_image);
  214. $big_image_width = $big_image_size[0];
  215. $big_image_height = $big_image_size[1];
  216. $url_big_image = $big_image.'?rnd='.time();
  217. echo '<input type="image" src="'.$fullurl.'" alt="'.$alt.'" onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/><br />';
  218. } else {
  219. echo Display::return_icon('unknown.jpg', get_lang('Unknown'));
  220. echo '<br />';
  221. }
  222. echo '<br />'.$status.'<br />';
  223. global $user_anonymous;
  224. if (api_get_setting('allow_social_tool') == 'true' && api_get_user_id() <> $user_anonymous && api_get_user_id() <> 0) {
  225. echo '<br />';
  226. echo '<a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$safe_user_id.'">'.get_lang('ViewSharedProfile').'</a>';
  227. echo '<br />';
  228. $user_anonymous = api_get_anonymous_id();
  229. if ($safe_user_id != api_get_user_id() && !api_is_anonymous($safe_user_id)) {
  230. $user_relation = UserFriend::get_relation_between_contacts(api_get_user_id(), $safe_user_id);
  231. if ($user_relation == 0 || $user_relation == 6) {
  232. echo '<a href="main/messages/send_message_to_userfriend.inc.php?view_panel=2&height=300&width=610&user_friend='.$safe_user_id.'" class="thickbox" title="'.get_lang('SendInvitation').'">'.Display :: return_icon('add_multiple_users.gif', get_lang('SocialInvitationToFriends')).'&nbsp;'.get_lang('SendInvitation').'</a><br />
  233. <a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=310&width=610&user_friend='.$safe_user_id.'" class="thickbox" title="'.get_lang('SendAMessage').'">'.Display :: return_icon('mail_send.png', get_lang('SendAMessage')).'&nbsp;'.get_lang('SendAMessage').'</a>';
  234. } else {
  235. echo '<a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=310&width=610&user_friend='.$safe_user_id.'" class="thickbox" title="'.get_lang('SendAMessage').'">'.Display :: return_icon('mail_send.png', get_lang('SendAMessage')).'&nbsp;'.get_lang('SendAMessage').'</a>';
  236. }
  237. }
  238. }
  239. if (api_get_setting('show_email_addresses') == 'true') {
  240. echo Display::encrypted_mailto_link($user_object->email,$user_object->email).'<br />';
  241. }
  242. echo '</div>';
  243. if ($user_object->competences) {
  244. echo '<dt><div class="actions-message"><strong>'.get_lang('MyCompetences').'</strong></div></dt>';
  245. echo '<dd>'.$user_object->competences.'</dd>';
  246. }
  247. if ($user_object->diplomas) {
  248. echo '<dt><div class="actions-message"><strong>'.get_lang('MyDiplomas').'</strong></div></dt>';
  249. echo '<dd>'.$user_object->diplomas.'</dd>';
  250. }
  251. if ($user_object->teach) {
  252. echo '<dt><div class="actions-message"><strong>'.get_lang('MyTeach').'</strong></div></dt>';
  253. echo '<dd>'.$user_object->teach.'</dd>';;
  254. }
  255. display_productions($user_object->user_id);
  256. if ($user_object->openarea) {
  257. echo '<dt><div class="actions-message"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div></dt>';
  258. echo '<dd>'.$user_object->openarea.'</dd>';
  259. }
  260. }
  261. else
  262. {
  263. Display::display_header(get_lang('UsersOnLineList'));
  264. echo '<div class="actions-title">';
  265. echo get_lang('UsersOnLineList');
  266. echo '</div>';
  267. }
  268. }
  269. /**
  270. * Display productions in whoisonline
  271. * @param int $user_id User id
  272. * @todo use the correct api_get_path instead of $clarolineRepositoryWeb
  273. */
  274. function display_productions($user_id) {
  275. $sysdir_array = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
  276. $sysdir = $sysdir_array['dir'].$user_id.'/';
  277. $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true);
  278. $webdir = $webdir_array['dir'].$user_id.'/';
  279. if (!is_dir($sysdir)) {
  280. mkpath($sysdir);
  281. }
  282. /*
  283. $handle = opendir($sysdir);
  284. $productions = array();
  285. while ($file = readdir($handle)) {
  286. if ($file == '.' || $file == '..' || $file == '.htaccess') {
  287. continue; // Skip current and parent directories
  288. }
  289. if (preg_match('/('.$user_id.'|[0-9a-f]{13}|saved)_.+\.(png|jpg|jpeg|gif)$/i', $file)) {
  290. // User's photos should not be listed as productions.
  291. continue;
  292. }
  293. $productions[] = $file;
  294. }
  295. */
  296. $productions = UserManager::get_user_productions($user_id);
  297. if (count($productions) > 0) {
  298. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  299. echo '<dd><ul>';
  300. foreach ($productions as $index => $file) {
  301. // Only display direct file links to avoid browsing an empty directory
  302. if (is_file($sysdir.$file) && $file != $webdir_array['file']) {
  303. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  304. }
  305. // Real productions are under a subdirectory by the User's id
  306. if (is_dir($sysdir.$file)) {
  307. $subs = scandir($sysdir.$file);
  308. foreach ($subs as $my => $sub) {
  309. if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) {
  310. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  311. }
  312. }
  313. }
  314. }
  315. echo '</ul></dd>';
  316. }
  317. }
  318. // This if statement prevents users accessing the who's online feature when it has been disabled.
  319. 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'])) {
  320. if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  321. $user_list = Who_is_online_in_this_course($_user['user_id'], api_get_setting('time_limit_whosonline'), $_GET['cidReq']);
  322. } else {
  323. $user_list = WhoIsOnline($_user['user_id'], $_configuration['statistics_database'], api_get_setting('time_limit_whosonline'));
  324. }
  325. $total = count($user_list);
  326. if (!isset($_GET['id'])) {
  327. Display::display_header(get_lang('UsersOnLineList'));
  328. echo '<div class="actions-title">';
  329. echo get_lang('UsersOnLineList');
  330. echo '</div>';
  331. echo '<div class="actions-message">'.get_lang('TotalOnLine').' : '.$total.'</div>';
  332. if ($_GET['id'] == '') {
  333. echo '<p><a class="refresh" href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
  334. } else {
  335. if (0) {
  336. // if ($_user['user_id'] && $_GET["id"] != $_user['user_id']) {
  337. echo '<a href="'.api_get_self().'?chatid='.Security::remove_XSS($_GET['id']).'">'.get_lang('SendChatRequest').'</a>';
  338. }
  339. }
  340. }
  341. if ($user_list) {
  342. if (!isset($_GET['id'])) {
  343. display_user_list($user_list, $_plugins);
  344. } else {
  345. //individual user information - also displays header info
  346. display_individual_user(Security::remove_XSS($_GET['id']));
  347. }
  348. }
  349. elseif (isset($_GET['id'])) {
  350. Display::display_header(get_lang('UsersOnLineList'));
  351. echo '<div class="actions-title">';
  352. echo get_lang('UsersOnLineList');
  353. echo '</div>';
  354. }
  355. } else {
  356. Display::display_header(get_lang('UsersOnLineList'));
  357. Display::display_error_message(get_lang('AccessNotAllowed'));
  358. }
  359. $referer = empty($_GET['referer']) ? 'index.php' : api_htmlentities(strip_tags($_GET['referer']), ENT_QUOTES);
  360. if (isset($_GET['id'])) {
  361. echo '<a href="whoisonline.php" class="fake_button_back">'.get_lang('Back').'</a>';
  362. } else {
  363. echo '<a href="'.$referer.'" class="fake_button_back">'.get_lang('BackHome').'</a>';
  364. }
  365. /*
  366. ==============================================================================
  367. FOOTER
  368. ==============================================================================
  369. */
  370. /*echo '<div align="center"><a href="http://main.svndokeos.net/main/upload/users/4/4_49aeb3bb8bba5.jpg" class="thickbox">hola</a></div>';*/
  371. Display::display_footer();