chat_chat.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php // $Id: chat_chat.php,v 1.10 2005/05/18 13:58:10 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. * Chat frame that shows the message list
  22. *
  23. * @author Olivier Brouckaert
  24. * @package dokeos.chat
  25. ==============================================================================
  26. */
  27. define('FRAME','chat');
  28. $language_file = array ('chat');
  29. require('../inc/global.inc.php');
  30. include(api_get_path(LIBRARY_PATH).'document.lib.php');
  31. include (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  32. //$course=api_get_course_id();
  33. $course=$_GET['cidReq'];
  34. // if we have the session set up
  35. if (!empty($course))
  36. {
  37. $reset=$_GET['reset']?true:false;
  38. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  39. $query="SELECT username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  40. $result=Database::query($query,__FILE__,__LINE__);
  41. list($pseudoUser)=Database::fetch_row($result);
  42. $isAllowed=(empty($pseudoUser) || !$_cid)?false:true;
  43. $isMaster=$is_courseAdmin?true:false;
  44. $dateNow=date('Y-m-d');
  45. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  46. $chatPath=$documentPath.'chat_files/';
  47. $TABLEITEMPROPERTY= Database::get_course_table(TABLE_ITEM_PROPERTY);
  48. if(!is_dir($chatPath))
  49. {
  50. if(is_file($chatPath))
  51. {
  52. @unlink($chatPath);
  53. }
  54. if (!api_is_anonymous()) {
  55. $perm = api_get_setting('permissions_for_new_directories');
  56. $perm = octdec(!empty($perm)?$perm:'0770');
  57. @mkdir($chatPath,$perm);
  58. @chmod($chatPath,$perm);
  59. $doc_id=add_document($_course,'/chat_files','folder',0,'chat_files');
  60. Database::query("INSERT INTO ".$TABLEITEMPROPERTY . " (tool,insert_user_id,insert_te,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)");
  61. }
  62. }
  63. if(!file_exists($chatPath.'messages-'.$dateNow.'.log.html'))
  64. {
  65. @fclose(fopen($chatPath.'messages-'.$dateNow.'.log.html','w'));
  66. if (!api_is_anonymous()) {
  67. $doc_id=add_document($_course,'/chat_files/messages-'.$dateNow.'.log.html','file',0,'messages-'.$dateNow.'.log.html');
  68. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id']);
  69. item_property_update_on_folder($_course,'/chat_files', $_user['user_id']);
  70. }
  71. }
  72. if($reset && $isMaster)
  73. {
  74. $i=1;
  75. while(file_exists($chatPath.'messages-'.$dateNow.'-'.$i.'.log.html'))
  76. {
  77. $i++;
  78. }
  79. @rename($chatPath.'messages-'.$dateNow.'.log.html',$chatPath.'messages-'.$dateNow.'-'.$i.'.log.html');
  80. @fclose(fopen($chatPath.'messages-'.$dateNow.'.log.html','w'));
  81. $doc_id=add_document($_course,'/chat_files/messages-'.$dateNow.'-'.$i.'.log.html','file',filesize($chatPath.'messages-'.$dateNow.'-'.$i.'.log.html'),'messages-'.$dateNow.'-'.$i.'.log.html');
  82. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id']);
  83. item_property_update_on_folder($_course,'/chat_files', $_user['user_id']);
  84. $doc_id = DocumentManager::get_document_id($_course,'/chat_files/messages-'.$dateNow.'.log.html');
  85. update_existing_document($_course, $doc_id,0);
  86. }
  87. $content=file($chatPath.'messages-'.$dateNow.'.log.html');
  88. $nbr_lines=sizeof($content);
  89. $remove=$nbr_lines-100;
  90. if($remove < 0)
  91. {
  92. $remove=0;
  93. }
  94. array_splice($content,0,$remove);
  95. include('header_frame.inc.php');
  96. if ($_GET["origin"]=='whoisonline') { //the caller
  97. $content[0]=get_lang('CallSent').'<br>'.$content[0];
  98. }
  99. if ($_GET["origin"]=='whoisonlinejoin') { //the joiner (we have to delete the chat request to him when he joins the chat)
  100. $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
  101. $sql="update $track_user_table set chatcall_user_id = '', chatcall_date = '', chatcall_text='' where (user_id = ".$_user['user_id'].")";
  102. $result=Database::query($sql,__FILE__,__LINE__);
  103. }
  104. echo '<div style="margin-left: 5px;">';
  105. foreach($content as $thisLine)
  106. {
  107. echo strip_tags(api_html_entity_decode($thisLine),'<br> <span> <b> <i> <img> <font>');
  108. }
  109. echo '</div>';
  110. ?>
  111. <a name="bottom" style="text-decoration:none;">&nbsp;</a>
  112. <?php
  113. if($isMaster || $is_courseCoach)
  114. {
  115. $rand=mt_rand(1,1000);
  116. echo '<div style="margin-left: 5px;">';
  117. echo '<a href="'.api_get_self().'?rand='.$rand.'&reset=1&cidReq='.$_GET['cidReq'].'#bottom" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmReset'),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('ClearList')).' '.get_lang('ClearList').'</a>';
  118. echo '</div>';
  119. }
  120. }
  121. else
  122. {
  123. include('header_frame.inc.php');
  124. $message=get_lang('CloseOtherSession');
  125. Display :: display_error_message($message);
  126. }
  127. include('footer_frame.inc.php');
  128. ?>