whoisonline.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. // name of the language file that needs to 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=api_sql_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. {
  111. global $charset;
  112. if ($_GET["id"]=='') {
  113. $extra_params = array();
  114. $course_url = '';
  115. if(strlen($_GET['cidReq']) > 0) {
  116. $extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  117. $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
  118. }
  119. foreach ($user_list as $user) {
  120. $uid=$user[0];
  121. $user_info = api_get_user_info($uid);
  122. $table_row = array();
  123. $url = '?id='.$uid.$course_url;
  124. $image_array=UserManager::get_user_picture_path_by_id($uid,'system',false,true);
  125. $friends_profile = UserFriend::get_picture_user($uid, $image_array['file'], 92, 'medium_', ' width="90" height="90" ');
  126. //reduce image
  127. $table_row[] = '<center><a href="'.$url.'"><img src="'.$friends_profile['file'].'" '.$friends_profile['style'].' border="1"></a></center>';
  128. $table_row[] = '<a href="'.$url.'">'.$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. if (api_get_setting('allow_social_tool')=='true' && api_get_user_id()<>$user_anonymous && api_get_user_id()<>0) {
  135. if ($user_info['user_id'] != api_get_user_id() && !api_is_anonymous($user_info['user_id'])) {
  136. $user_relation=UserFriend::get_relation_between_contacts(api_get_user_id(),$user_info['user_id']);
  137. if ($user_relation==0 || $user_relation==6) {
  138. $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('SocialAddToFriends').'">'.Display :: return_icon('add_multiple_users.gif', get_lang('SocialAddToFriends')).'&nbsp;'.get_lang('SocialAddToFriends').'</a><br />
  139. <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>';
  140. } else {
  141. $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>';
  142. }
  143. }
  144. }
  145. $table_data[] = $table_row;
  146. }
  147. $table_header[] = array(get_lang('UserPicture'),false,'width="90"');
  148. $table_header[] = array(get_lang('Name'),true);
  149. //$table_header[] = array(get_lang('LastName'),true);
  150. if (api_get_setting('show_email_addresses') == 'true') {
  151. $table_header[] = array(get_lang('Email'),true);
  152. }
  153. $user_anonymous=api_get_anonymous_id();
  154. if (api_get_setting('allow_social_tool')=='true' && api_get_user_id()<>$user_anonymous && api_get_user_id()<>0) {
  155. $table_header[] = array(get_lang('Friends'),false,'width="200"');
  156. }
  157. /*this feature is deprecated
  158. if ( api_get_setting('allow_message_tool')=='true' && isset($_SESSION['_user'])) {
  159. $table_header[] = array(get_lang('SendMessage'),true);
  160. }
  161. */
  162. $sorting_options['column'] = (isset ($_GET['column']) ? (int)$_GET['column'] : 2);
  163. /*if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true' ) {
  164. //send_invitation_friend_user();
  165. echo '<div align="right"><input type="button" name="id_btn_send_invitation" id="id_btn_send_invitation" value="'.get_lang('SendInviteMessage').'"/></div>';
  166. echo '<form action="whoisonline.php" name="form_register_friend" id="form_register_friend" method="post">';
  167. }*/
  168. Display::display_sortable_table($table_header,$table_data,$sorting_options,array('per_page_default'=>count($table_data)),$extra_params);
  169. /*if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true' ) {
  170. echo '</form>';
  171. }*/
  172. }
  173. }
  174. /**
  175. * Displays the information of an individual user
  176. * @param int $user_id
  177. */
  178. function display_individual_user($user_id)
  179. {
  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=api_sql_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;<b>('.get_lang('Me').')</b>' : '' );
  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 = @getimagesize(api_url_to_local_path($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="return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/><br />';
  216. global $user_anonymous;
  217. if (api_get_setting('allow_social_tool')=='true' && api_get_user_id()<>$user_anonymous && api_get_user_id()<>0) {
  218. echo '<br />';
  219. echo '<a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$safe_user_id.'">'.get_lang('ViewSharedProfile').'</a>';
  220. echo '<br />';
  221. }
  222. } else {
  223. echo Display::return_icon('unknown.jpg',get_lang('Unknown'));
  224. echo '<br />';
  225. }
  226. if (api_get_setting("show_email_addresses") == "true")
  227. {
  228. echo Display::encrypted_mailto_link($user_object->email,$user_object->email).'<br />';
  229. }
  230. echo $status.'<br />';
  231. echo '</div>';
  232. if ($user_object->competences) {
  233. echo '<dt><div class="actions-message"><strong>'.get_lang('MyCompetences').'</strong></div></dt>';
  234. echo '<dd>'.$user_object->competences.'</dd>';
  235. }
  236. if ($user_object->diplomas) {
  237. echo '<dt><div class="actions-message"><strong>'.get_lang('MyDiplomas').'</strong></div></dt>';
  238. echo '<dd>'.$user_object->diplomas.'</dd>';
  239. }
  240. if ($user_object->teach) {
  241. echo '<dt><div class="actions-message"><strong>'.get_lang('MyTeach').'</strong></div></dt>';
  242. echo '<dd>'.$user_object->teach.'</dd>';;
  243. }
  244. display_productions($user_object->user_id);
  245. if ($user_object->openarea) {
  246. echo '<dt><div class="actions-message"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div></dt>';
  247. echo '<dd>'.$user_object->openarea.'</dd>';
  248. }
  249. }
  250. else
  251. {
  252. Display::display_header(get_lang('UsersOnLineList'));
  253. echo '<div class="actions-title">';
  254. echo get_lang('UsersOnLineList');
  255. echo '</div>';
  256. }
  257. }
  258. /**
  259. * Display productions in whoisonline
  260. * @param int $user_id User id
  261. * @todo use the correct api_get_path instead of $clarolineRepositoryWeb
  262. */
  263. function display_productions($user_id)
  264. {
  265. $sysdir_array = UserManager::get_user_picture_path_by_id($user_id,'system');
  266. $sysdir = $sysdir_array['dir'].$user_id.'/';
  267. $webdir_array = UserManager::get_user_picture_path_by_id($user_id,'web');
  268. $webdir = $webdir_array['dir'].$user_id.'/';
  269. if( !is_dir($sysdir)) {
  270. mkpath($sysdir);
  271. }
  272. $handle = opendir($sysdir);
  273. $productions = array();
  274. while ($file = readdir($handle)) {
  275. if ($file == '.' || $file == '..' || $file == '.htaccess') {
  276. continue; // Skip current and parent directories
  277. }
  278. $productions[] = $file;
  279. }
  280. if(count($productions) > 0) {
  281. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  282. echo '<dd><ul>';
  283. foreach($productions as $index => $file) {
  284. // Only display direct file links to avoid browsing an empty directory
  285. if(is_file($sysdir.$file) && $file != $webdir_array['file']){
  286. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  287. }
  288. // Real productions are under a subdirectory by the User's id
  289. if(is_dir($sysdir.$file)) {
  290. $subs = scandir($sysdir.$file);
  291. foreach($subs as $my => $sub) {
  292. if(substr($sub,0,1) != '.' && is_file($sysdir.$file.'/'.$sub))
  293. {
  294. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  295. }
  296. }
  297. }
  298. }
  299. echo '</ul></dd>';
  300. }
  301. }
  302. // This if statement prevents users accessing the who's online feature when it has been disabled.
  303. 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'])) {
  304. if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  305. $user_list = Who_is_online_in_this_course($_user['user_id'],api_get_setting('time_limit_whosonline'),$_GET['cidReq']);
  306. } else {
  307. $user_list = WhoIsOnline($_user['user_id'],$_configuration['statistics_database'],api_get_setting('time_limit_whosonline'));
  308. }
  309. $total=count($user_list);
  310. if (!isset($_GET['id']))
  311. {
  312. Display::display_header(get_lang('UsersOnLineList'));
  313. echo '<div class="actions-title">';
  314. echo get_lang('UsersOnLineList');
  315. echo '</div>';
  316. echo '<div class="actions-message">'.get_lang('TotalOnLine').' : '.$total.'</div>';
  317. if ($_GET['id']=='') {
  318. echo '<p><a class="refresh" href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
  319. } else {
  320. if(0) // if ($_user['user_id'] && $_GET["id"] != $_user['user_id'])
  321. {
  322. echo '<a href="'.api_get_self().'?chatid='.Security::remove_XSS($_GET['id']).'">'.get_lang('SendChatRequest').'</a>';
  323. }
  324. }
  325. }
  326. if ($user_list!=false)
  327. {
  328. if (!isset($_GET['id']))
  329. {
  330. display_user_list($user_list, $_plugins);
  331. }
  332. else //individual user information - also displays header info
  333. {
  334. display_individual_user(Security::remove_XSS($_GET['id']));
  335. }
  336. }
  337. elseif(isset($_GET['id']))
  338. {
  339. Display::display_header(get_lang('UsersOnLineList'));
  340. echo '<div class="actions-title">';
  341. echo get_lang('UsersOnLineList');
  342. echo '</div>';
  343. }
  344. }
  345. else
  346. {
  347. Display::display_header(get_lang('UsersOnLineList'));
  348. Display::display_error_message(get_lang('AccessNotAllowed'));
  349. }
  350. $referer = empty($_GET['referer'])?'index.php':api_htmlentities(strip_tags($_GET['referer']),ENT_QUOTES,$charset);
  351. if (isset($_GET['id'])) {
  352. echo '<a href="whoisonline.php" class="fake_button_back">'.get_lang('Back').'</a>';
  353. } else {
  354. echo '<a href="'.$referer.'" class="fake_button_back">'.get_lang('BackHome').'</a>';
  355. }
  356. /*
  357. ==============================================================================
  358. FOOTER
  359. ==============================================================================
  360. */
  361. /*echo '<div align="center"><a href="http://main.svndokeos.net/main/upload/users/4/4_49aeb3bb8bba5.jpg" class="thickbox">hola</a></div>';*/
  362. Display::display_footer();
  363. ?>