chat_message.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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_once '../inc/global.inc.php';
  35. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  36. $course=api_get_course_id();
  37. $session_id = intval($_SESSION['id_session']);
  38. $group_id = intval($_SESSION['_gid']);
  39. /////
  40. // Juan Carlos Raña insert smileys and self-closing window
  41. ////
  42. ?>
  43. <script language="javascript" type="text/javascript">
  44. function insert_smile(text) {
  45. if (text.createTextRange) {
  46. text.smile = document.selection.createRange().duplicate();
  47. }
  48. }
  49. function insert(text) {
  50. var chat = document.formMessage.message;
  51. if (chat.createTextRange && chat.smile) {
  52. var smile = chat.smile;
  53. smile.text = smile.text.charAt(smile.text.length - 1) == ' ' ? text + ' ' : text;
  54. }
  55. else chat.value += text;
  56. chat.focus(smile)
  57. }
  58. function close_chat_window() {
  59. var chat_window = top.window.self;
  60. chat_window.opener = top.window.self;
  61. chat_window.top.close();
  62. }
  63. </script>
  64. <?php
  65. // mode open in a new window: close the window when there isn't an user login
  66. if(empty($_user['user_id']))
  67. {
  68. echo '<script languaje="javascript"> close_chat_window() </script>';
  69. }
  70. else
  71. {
  72. api_protect_course_script();
  73. }
  74. // if we have the session set up
  75. if (!empty($course) && !empty($_user['user_id']))
  76. {
  77. include_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  78. include_once(api_get_path(LIBRARY_PATH).'text.lib.php');
  79. include_once (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  80. /*
  81. -----------------------------------------------------------
  82. Constants and variables
  83. -----------------------------------------------------------
  84. */
  85. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  86. $sent = $_REQUEST['sent'];
  87. /*
  88. ==============================================================================
  89. MAIN CODE
  90. ==============================================================================
  91. */
  92. $query="SELECT lastname, firstname, username FROM $tbl_user WHERE user_id='".$_user['user_id']."'";
  93. $result=Database::query($query,__FILE__,__LINE__);
  94. list($pseudoUser)=Database::fetch_row($result);
  95. $isAllowed=(empty($pseudoUser) || !$_cid)?false:true;
  96. $isMaster=$is_courseAdmin?true:false;
  97. $firstname=Database::result($result,0,'firstname');
  98. $lastname=Database::result($result,0,'lastname');
  99. $dateNow=date('Y-m-d');
  100. $basepath_chat = '';
  101. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  102. if (!empty($group_id)) {
  103. $group_info = GroupManager :: get_group_properties($group_id);
  104. $basepath_chat = $group_info['directory'].'/chat_files';
  105. } else {
  106. $basepath_chat = '/chat_files';
  107. }
  108. $chatPath=$documentPath.$basepath_chat.'/';
  109. $TABLEITEMPROPERTY= Database::get_course_table(TABLE_ITEM_PROPERTY);
  110. if(!is_dir($chatPath)) {
  111. if(is_file($chatPath)) {
  112. @unlink($chatPath);
  113. }
  114. if (!api_is_anonymous()) {
  115. $perm = api_get_setting('permissions_for_new_directories');
  116. $perm = octdec(!empty($perm)?$perm:'0770');
  117. @mkdir($chatPath,$perm);
  118. @chmod($chatPath,$perm);
  119. // save chat files document for group into item property
  120. if (!empty($group_id)) {
  121. $doc_id=add_document($_course,$basepath_chat,'folder',0,'chat_files');
  122. $sql = "INSERT INTO $TABLEITEMPROPERTY (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)
  123. VALUES ('document',1,NOW(),NOW(),$doc_id,'FolderCreated',1,$group_id,NULL,0)";
  124. Database::query($sql,__FILE__,__LINE__);
  125. }
  126. }
  127. }
  128. include('header_frame.inc.php');
  129. $chat_size=0;
  130. //define emoticons
  131. $emoticon_text1=':-)';
  132. $emoticon_img1= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_smile.gif" alt="'.get_lang('Smile').'" title="'.get_lang('Smile').'" />';
  133. $emoticon_text2=':-D';
  134. $emoticon_img2= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_biggrin.gif" alt="'.get_lang('BigGrin').'" title="'.get_lang('BigGrin').'" />';
  135. $emoticon_text3=';-)';
  136. $emoticon_img3= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_wink.gif" alt="'.get_lang('Wink').'" title="'.get_lang('Wink').'" />';
  137. $emoticon_text4=':-P';
  138. $emoticon_img4= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_razz.gif" alt="'.get_lang('Avid').'" title="'.get_lang('Avid').'" />';
  139. $emoticon_text5='8-)';
  140. $emoticon_img5= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_cool.gif" alt="'.get_lang('Cool').'" title="'.get_lang('Cool').'" />';
  141. $emoticon_text6=':-o)';
  142. $emoticon_img6= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_surprised.gif" alt="'.get_lang('Surprised').'" title="'.get_lang('Surprised').'" />';
  143. $emoticon_text7='=;';
  144. $emoticon_img7= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_hand.gif" alt="'.get_lang('Hand').'" title="'.get_lang('Hand').'" />';
  145. $emoticon_text8='=8-o';
  146. $emoticon_img8= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_eek.gif" alt="'.get_lang('Amazing').'" title="'.get_lang('Amazing').'" />';
  147. $emoticon_text9=':-|)';
  148. $emoticon_img9= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_neutral.gif" alt="'.get_lang('Neutral').'" title="'.get_lang('Neutral').'" />';
  149. $emoticon_text8=':-k';
  150. $emoticon_img8= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_think.gif" alt="'.get_lang('Think').'" title="'.get_lang('Think').'" />';
  151. $emoticon_text11=':-?';
  152. $emoticon_img11= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_confused.gif" alt="'.get_lang('Confused').'" title="'.get_lang('Confused').'" />';
  153. $emoticon_text12=':-8';
  154. $emoticon_img12= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_redface.gif" alt="'.get_lang('Redface').'" title="'.get_lang('Redface').'" />';
  155. $emoticon_text13=':-=';
  156. $emoticon_img13= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_shhh.gif" alt="'.get_lang('Silence').'" title="'.get_lang('Silence').'" />';
  157. $emoticon_text14=':-#)';
  158. $emoticon_img14= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_silenced.gif" alt="'.get_lang('Silenced').'" title="'.get_lang('Silenced').'" />';
  159. $emoticon_text15=':-(';
  160. $emoticon_img15= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_sad.gif" alt="'.get_lang('Sad').'" title="'.get_lang('Sad').'" />';
  161. $emoticon_text16=':-[8';
  162. $emoticon_img16= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_angry.gif" alt="'.get_lang('Angry').'" title="'.get_lang('Angry').'" />';
  163. $emoticon_text17='--)';
  164. $emoticon_img17= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_arrow.gif" alt="'.get_lang('Arrow').'" title="'.get_lang('Arrow').'" />';
  165. $emoticon_text18=':!:';
  166. $emoticon_img18= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_exclaim.gif" alt="'.get_lang('Exclamation').'" title="'.get_lang('Exclamation').'" />';
  167. $emoticon_text19=':?:';
  168. $emoticon_img19= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_question.gif" alt="'.get_lang('Question').'" title="'.get_lang('Question').'" />';
  169. $emoticon_text20='0-';
  170. $emoticon_img20= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_idea.gif" alt="'.get_lang('Idea').'" title="'.get_lang('Idea').'" />';
  171. //
  172. $emoticon_text201='*';
  173. $emoticon_img201= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/waiting.gif" alt="'.get_lang('AskPermissionSpeak').'" title="'.get_lang('AskPermissionSpeak').'" />';
  174. $emoticon_text202=':speak:';
  175. $emoticon_img202= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/flag_green_small.gif" alt="'.get_lang('GiveTheFloorTo').'" title="'.get_lang('GiveTheFloorTo').'" />';
  176. $emoticon_text203=':pause:';
  177. $emoticon_img203= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/flag_yellow_small.gif" alt="'.get_lang('Pause').'" title="'.get_lang('Pause').'" />';
  178. $emoticon_text204=':stop:';
  179. $emoticon_img204= '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/flag_red_small.gif" alt="'.get_lang('Stop').'" title="'.get_lang('Stop').'" />';
  180. if($sent)
  181. {
  182. $message=trim(htmlspecialchars(stripslashes($_POST['message']),ENT_QUOTES,$charset));
  183. $message=str_replace($emoticon_text1, $emoticon_img1, $message);
  184. $message=str_replace($emoticon_text2, $emoticon_img2, $message);
  185. $message=str_replace($emoticon_text3, $emoticon_img3, $message);
  186. $message=str_replace($emoticon_text4, $emoticon_img4, $message);
  187. $message=str_replace($emoticon_text5, $emoticon_img5, $message);
  188. $message=str_replace($emoticon_text6, $emoticon_img6, $message);
  189. $message=str_replace($emoticon_text7, $emoticon_img7, $message);
  190. $message=str_replace($emoticon_text8, $emoticon_img8, $message);
  191. $message=str_replace($emoticon_text9, $emoticon_img9, $message);
  192. $message=str_replace($emoticon_text10, $emoticon_img10, $message);
  193. $message=str_replace($emoticon_text11, $emoticon_img11, $message);
  194. $message=str_replace($emoticon_text12, $emoticon_img12, $message);
  195. $message=str_replace($emoticon_text13, $emoticon_img13, $message);
  196. $message=str_replace($emoticon_text14, $emoticon_img14, $message);
  197. $message=str_replace($emoticon_text15, $emoticon_img15, $message);
  198. $message=str_replace($emoticon_text16, $emoticon_img16, $message);
  199. $message=str_replace($emoticon_text17, $emoticon_img17, $message);
  200. $message=str_replace($emoticon_text18, $emoticon_img18, $message);
  201. $message=str_replace($emoticon_text19, $emoticon_img19, $message);
  202. $message=str_replace($emoticon_text20, $emoticon_img20, $message);
  203. //
  204. $message=str_replace($emoticon_text201, $emoticon_img201, $message);
  205. $message=str_replace($emoticon_text202, $emoticon_img202, $message);
  206. $message=str_replace($emoticon_text203, $emoticon_img203, $message);
  207. $message=str_replace($emoticon_text204, $emoticon_img204, $message);
  208. $timeNow=date('d/m/y H:i:s');
  209. $basename_chat = '';
  210. if (!empty($group_id)) {
  211. $basename_chat = 'messages-'.$dateNow.'_gid-'.$group_id;
  212. } else if (!empty($session_id)) {
  213. $basename_chat = 'messages-'.$dateNow.'_sid-'.$session_id;
  214. } else {
  215. $basename_chat = 'messages-'.$dateNow;
  216. }
  217. if (!api_is_anonymous()) {
  218. if(!empty($message))
  219. {
  220. $message=make_clickable($message);
  221. if(!file_exists($chatPath.$basename_chat.'.log.html'))
  222. {
  223. $doc_id=add_document($_course,$basepath_chat.'/'.$basename_chat.'.log.html','file',0,$basename_chat.'.log.html');
  224. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'],$group_id,null,null,null,$session_id);
  225. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'],$group_id,null,null,null,$session_id);
  226. item_property_update_on_folder($_course,$basepath_chat, $_user['user_id']);
  227. }
  228. else
  229. {
  230. $doc_id = DocumentManager::get_document_id($_course,$basepath_chat.'/'.$basename_chat.'.log.html');
  231. }
  232. $fp=fopen($chatPath.$basename_chat.'.log.html','a');
  233. if($isMaster)
  234. {
  235. $photo= '<img src="'.api_get_path(WEB_IMG_PATH).'teachers.gif" alt="'.get_lang('Teacher').'" width="11" height="11" align="top" title="'.get_lang('Teacher').'" />';
  236. fputs($fp,'<span style="color:#999; font-size: smaller;">['.$timeNow.']</span>'.$photo.' <span id="chat_login_name"><b>'.api_get_person_name($firstname, $lastname).'</b></span> : <i>'.$message.'</i><br>'."\n");
  237. }
  238. else
  239. {
  240. $photo= '<img src="'.api_get_path(WEB_IMG_PATH).'students.gif" alt="'.get_lang('Student').'" width="11" height="11" align="top" title="'.get_lang('Student').'" />';
  241. fputs($fp,'<span style="color:#999; font-size: smaller;">['.$timeNow.']</span>'.$photo.' <b>'.api_get_person_name($firstname, $lastname).'</b> : <i>'.$message.'</i><br>'."\n");
  242. }
  243. fclose($fp);
  244. $chat_size=filesize($chatPath.$basename_chat.'.log.html');
  245. update_existing_document($_course, $doc_id,$chat_size);
  246. item_property_update_on_folder($_course,$basepath_chat, $_user['user_id']);
  247. }
  248. }
  249. }
  250. ?>
  251. <form name="formMessage" method="post" action="<?php echo api_get_self().'?'.api_get_cidreq(); ?>" 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">
  252. <input type="hidden" name="sent" value="1">
  253. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  254. <tr>
  255. <td width="320" valign="middle">
  256. <textarea name="message" style="width: 320px; height: 35px" onkeydown="send_message(event);" onclick="javascript:insert_smile(this);"></textarea>
  257. </td>
  258. <td>
  259. <button type="submit" value="<?php echo get_lang("Send"); ?>" class="background_submit"><?php echo get_lang("Send"); ?></button>
  260. </td>
  261. </tr>
  262. <tr>
  263. <td>
  264. <?php
  265. echo "<a href=\"javascript:insert('".$emoticon_text1."')\">".$emoticon_img1."</a>";
  266. echo "<a href=\"javascript:insert('".$emoticon_text2."')\">".$emoticon_img2."</a>";
  267. echo "<a href=\"javascript:insert('".$emoticon_text3."')\">".$emoticon_img3."</a>";
  268. echo "<a href=\"javascript:insert('".$emoticon_text4."')\">".$emoticon_img4."</a>";
  269. echo "<a href=\"javascript:insert('".$emoticon_text5."')\">".$emoticon_img5."</a>";
  270. echo "<a href=\"javascript:insert('".$emoticon_text6."')\">".$emoticon_img6."</a>";
  271. echo "<a href=\"javascript:insert('".$emoticon_text7."')\">".$emoticon_img7."</a>";
  272. echo "<a href=\"javascript:insert('".$emoticon_text8."')\">".$emoticon_img8."</a>";
  273. echo "<a href=\"javascript:insert('".$emoticon_text9."')\">".$emoticon_img9."</a>";
  274. echo "<a href=\"javascript:insert('".$emoticon_text10."')\">".$emoticon_img10."</a>";
  275. echo "<a href=\"javascript:insert('".$emoticon_text11."')\">".$emoticon_img11."</a>";
  276. echo "<a href=\"javascript:insert('".$emoticon_text12."')\">".$emoticon_img12."</a>";
  277. echo "<a href=\"javascript:insert('".$emoticon_text13."')\">".$emoticon_img13."</a>";
  278. echo "<a href=\"javascript:insert('".$emoticon_text14."')\">".$emoticon_img14."</a>";
  279. echo "<a href=\"javascript:insert('".$emoticon_text15."')\">".$emoticon_img15."</a>";
  280. echo "<a href=\"javascript:insert('".$emoticon_text16."')\">".$emoticon_img16."</a>";
  281. echo "<a href=\"javascript:insert('".$emoticon_text17."')\">".$emoticon_img17."</a>";
  282. echo "<a href=\"javascript:insert('".$emoticon_text18."')\">".$emoticon_img18."</a>";
  283. echo "<a href=\"javascript:insert('".$emoticon_text19."')\">".$emoticon_img19."</a>";
  284. echo "<a href=\"javascript:insert('".$emoticon_text20."')\">".$emoticon_img20."</a>";
  285. ?>
  286. </td>
  287. <td>
  288. <?php
  289. echo "<a href=\"javascript:insert('".$emoticon_text201."')\">".$emoticon_img201."</a>";
  290. echo "<a href=\"javascript:insert('".$emoticon_text202."')\">".$emoticon_img202."</a>";
  291. echo "<a href=\"javascript:insert('".$emoticon_text203."')\">".$emoticon_img203."</a>";
  292. echo "<a href=\"javascript:insert('".$emoticon_text204."')\">".$emoticon_img204."</a>";
  293. ?>
  294. </td>
  295. </tr>
  296. </table>
  297. </form>
  298. <?php
  299. }
  300. include('footer_frame.inc.php');
  301. ?>