online_message.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php // $Id: online_message.php 20467 2009-05-11 08:38:29Z ivantcholakov $
  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. * Allows to type the messages that will be displayed on online_chat.php
  22. *
  23. * @author Olivier Brouckaert
  24. * @package dokeos.online
  25. ==============================================================================
  26. */
  27. define('FRAME','message');
  28. // name of the language file that needs to be included
  29. $language_file='chat';
  30. include('../inc/global.inc.php');
  31. $this_section=SECTION_COURSES;
  32. /*
  33. -----------------------------------------------------------
  34. Constants and variables
  35. -----------------------------------------------------------
  36. */
  37. $sent = $_REQUEST['sent'];
  38. $question = $_REQUEST['question'];
  39. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  40. $query="SELECT username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  41. $result=Database::query($query);
  42. list($pseudoUser)=Database::fetch_row($result);
  43. $isAllowed=(empty($pseudoUser) || !$_cid)?false:true;
  44. $isMaster=$is_courseAdmin?true:false;
  45. if(!$isAllowed)
  46. {
  47. exit();
  48. }
  49. $timeNow=date('H:i');
  50. $dateNow=date('Y-m-d');
  51. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  52. $onlinePath=$documentPath.'online_files/';
  53. if(!is_dir($onlinePath))
  54. {
  55. if(is_file($onlinePath))
  56. {
  57. @unlink($onlinePath);
  58. }
  59. @mkdir($onlinePath, api_get_permissions_for_new_directories());
  60. }
  61. $chat_size=0;
  62. if($sent)
  63. {
  64. $message=trim(htmlspecialchars(stripslashes($_POST['message']),ENT_QUOTES,$charset));
  65. if(!empty($message))
  66. {
  67. $message=make_clickable($message);
  68. if($question)
  69. {
  70. $message='<span class="question"><b>'.get_lang('Question').' :</b> '.$message.'</span>';
  71. }
  72. $fp=fopen($onlinePath.'messages-'.$dateNow.'.log','a');
  73. if($isMaster)
  74. {
  75. fputs($fp,"[$timeNow] <span class=\"master\"><b>$pseudoUser</b></span> : $message\n");
  76. }
  77. else
  78. {
  79. fputs($fp,"[$timeNow] <b>$pseudoUser</b> : $message\n");
  80. }
  81. fclose($fp);
  82. $chat_size=filesize($onlinePath.'messages-'.$dateNow.'.log');
  83. }
  84. }
  85. include('header_frame.inc.php');
  86. ?>
  87. <form name="formMessage" method="post" action="<?php echo api_get_self(); ?>" onsubmit="javascript:if(document.formMessage.message.value == '') { alert('<?php echo addslashes(api_htmlentities(get_lang('TypeMessage'),ENT_QUOTES,$charset)); ?>'); document.formMessage.message.focus(); return false; }" autocomplete="off">
  88. <input type="hidden" name="sent" value="1">
  89. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  90. <tr>
  91. <td width="90%"><input type="text" name="message" size="50" value="" style="width: 100%;"></td>
  92. <td width="9%" nowrap="nowrap"><?php echo get_lang('Question'); ?>&nbsp;<input type="checkbox" name="question" value="1" style="vertical-align: middle;" onclick="javascript:if(this.checked == true && !confirm('<?php echo addslashes(api_htmlentities(get_lang('OnlyCheckForImportantQuestion'),ENT_QUOTES,$charset)); ?>')) this.checked=false; document.formMessage.message.focus();"></td>
  93. <td width="1%"><input type="submit" value="OK" style="width: 30px;"></td>
  94. </tr>
  95. </table>
  96. </form>
  97. <?php
  98. include('footer_frame.inc.php');
  99. ?>