chat_message.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php // $Id: chat_message.php,v 1.11 2005/05/18 13:58:20 bvanderkimpen Exp $
  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 chat_chat.php
  22. *
  23. * @author Olivier Brouckaert
  24. * @package dokeos.chat
  25. ==============================================================================
  26. */
  27. /*
  28. ==============================================================================
  29. INIT SECTION
  30. ==============================================================================
  31. */
  32. define('FRAME','message');
  33. $language_file = array ('chat');
  34. require('../inc/global.inc.php');
  35. api_protect_course_script();
  36. include_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  37. include_once(api_get_path(LIBRARY_PATH).'text.lib.php');
  38. include_once (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  39. /*
  40. -----------------------------------------------------------
  41. Constants and variables
  42. -----------------------------------------------------------
  43. */
  44. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  45. $sent = $_REQUEST['sent'];
  46. /*
  47. ==============================================================================
  48. MAIN CODE
  49. ==============================================================================
  50. */
  51. $query="SELECT lastname, firstname, username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  52. $result=api_sql_query($query,__FILE__,__LINE__);
  53. list($pseudoUser)=mysql_fetch_row($result);
  54. $isAllowed=(empty($pseudoUser) || !$_cid)?false:true;
  55. $isMaster=$is_courseAdmin?true:false;
  56. $firstname=mysql_result($result,0,'firstname');
  57. $lastname=mysql_result($result,0,'lastname');
  58. $dateNow=date('Y-m-d');
  59. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  60. $chatPath=$documentPath.'chat_files/';
  61. $TABLEITEMPROPERTY= Database::get_course_table(TABLE_ITEM_PROPERTY);
  62. if(!is_dir($chatPath))
  63. {
  64. if(is_file($chatPath))
  65. {
  66. @unlink($chatPath);
  67. }
  68. $perm = api_get_setting('permissions_for_new_directories');
  69. $perm = octdec(!empty($perm)?$perm:'0770');
  70. @mkdir($chatPath,$perm);
  71. @chmod($chatPath,$perm);
  72. $doc_id=add_document($_course,'/chat_files','folder',0,'chat_files');
  73. api_sql_query("INSERT INTO ".$TABLEITEMPROPERTY . " (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$doc_id,'DocumentAdded',1,0,NULL,0)");
  74. }
  75. $chat_size=0;
  76. if($sent)
  77. {
  78. $message=trim(htmlspecialchars(stripslashes($_POST['message']),ENT_QUOTES,$charset));
  79. if(!empty($message))
  80. {
  81. $message=make_clickable($message);
  82. if(!file_exists($chatPath.'messages-'.$dateNow.'.log.html'))
  83. {
  84. $doc_id=add_document($_course,'/chat_files/messages-'.$dateNow.'.log.html','file',0,'messages-'.$dateNow.'.log.html');
  85. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id']);
  86. item_property_update_on_folder($_course,'/chat_files', $_user['user_id']);
  87. }
  88. else
  89. {
  90. $doc_id = DocumentManager::get_document_id($_course,'/chat_files/messages-'.$dateNow.'.log.html');
  91. }
  92. $fp=fopen($chatPath.'messages-'.$dateNow.'.log.html','a');
  93. if($isMaster)
  94. {
  95. fputs($fp,"<span style='color: #2754AF;'><b>$firstname $lastname</b></span> : $message<br>\n");
  96. }
  97. else
  98. {
  99. fputs($fp,"<b>$firstname $lastname</b> : $message<br>\n");
  100. }
  101. fclose($fp);
  102. $chat_size=filesize($chatPath.'messages-'.$dateNow.'.log.html');
  103. update_existing_document($_course, $doc_id,$chat_size);
  104. item_property_update_on_folder($_course,'/chat_files', $_user['user_id']);
  105. }
  106. }
  107. include('header_frame.inc.php');
  108. ?>
  109. <form name="formMessage" method="post" action="<?php echo api_get_self(); ?>" onsubmit="javascript:if(document.formMessage.message.value == '') { alert('<?php echo addslashes(htmlentities(get_lang('TypeMessage'),ENT_QUOTES,$charset)); ?>'); document.formMessage.message.focus(); return false; }" autocomplete="off">
  110. <input type="hidden" name="sent" value="1">
  111. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  112. <tr>
  113. <td width="520" valign="middle">
  114. <textarea name="message" style="width: 520px; height: 35px" onkeydown="send_message(event);"></textarea>
  115. </td>
  116. <td>
  117. <input type="submit" value="<?php echo get_lang("Send"); ?>" class="background_submit">
  118. </td>
  119. </tr>
  120. </table>
  121. </form>
  122. <?php
  123. include('footer_frame.inc.php');
  124. ?>