whoisonline.php 17 KB

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