online_chat.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Olivier Brouckaert
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * Chat frame that shows the message list
  22. *
  23. * @author Olivier Brouckaert
  24. * @package dokeos.online
  25. ==============================================================================
  26. */
  27. define('FRAME','chat');
  28. // name of the language file that needs to be included
  29. $language_file='chat';
  30. include('../inc/global.inc.php');
  31. $reset=$_GET['reset']?true:false;
  32. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  33. $query="SELECT username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  34. $result=api_sql_query($query,__FILE__,__LINE__);
  35. list($pseudoUser)=mysql_fetch_row($result);
  36. $isAllowed=(empty($pseudoUser) || !$_cid)?false:true;
  37. $isMaster=$is_courseAdmin?true:false;
  38. if(!$isAllowed)
  39. {
  40. exit();
  41. }
  42. $dateNow=date('Y-m-d');
  43. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  44. $onlinePath=$documentPath.'online_files/';
  45. if(!file_exists($onlinePath.'messages-'.$dateNow.'.log'))
  46. {
  47. fclose(fopen($onlinePath.'messages-'.$dateNow.'.log','w'));
  48. }
  49. if($reset && $isMaster)
  50. {
  51. $i=1;
  52. while(file_exists($onlinePath.'messages-'.$dateNow.'-'.$i.'.log'))
  53. {
  54. $i++;
  55. }
  56. rename($onlinePath.'messages-'.$dateNow.'.log',$onlinePath.'messages-'.$dateNow.'-'.$i.'.log');
  57. fclose(fopen($onlinePath.'messages-'.$dateNow.'.log','w'));
  58. }
  59. $content=file($onlinePath.'messages-'.$dateNow.'.log');
  60. $nbr_lines=sizeof($content);
  61. $remove=$nbr_lines-100;
  62. if($remove < 0)
  63. {
  64. $remove=0;
  65. }
  66. array_splice($content,0,$remove);
  67. include('header_frame.inc.php');
  68. foreach($content as $thisLine)
  69. {
  70. echo "$thisLine<br>";
  71. }
  72. ?>
  73. <a name="bottom" style="text-decoration:none;">&nbsp;</a>
  74. <?php
  75. if($isMaster)
  76. {
  77. $rand=mt_rand(1,1000);
  78. ?>
  79. <br>
  80. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  81. <tr>
  82. <td width="1%" valign="middle"><a href="<?php echo api_get_self(); ?>?rand=<?php echo $rand; ?>&reset=1#bottom" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmReset'),ENT_QUOTES,$charset)); ?>')) return false;"><img src="../img/delete.gif" border="0" alt="" title="<?php echo htmlentities(get_lang('ClearList'),ENT_QUOTES,$charset); ?>"></a></td>
  83. <td width="99%">&nbsp;<a href="<?php echo api_get_self(); ?>?rand=<?php echo $rand; ?>&reset=1#bottom" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmReset'),ENT_QUOTES,$charset)); ?>')) return false;"><?php echo get_lang('ClearList'); ?></a></td>
  84. </tr>
  85. </table>
  86. <?php
  87. }
  88. include('footer_frame.inc.php');
  89. ?>