chat_message.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Allows to type the messages that will be displayed on chat_chat.php
  5. *
  6. * @author Olivier Brouckaert
  7. * @package chamilo.chat
  8. */
  9. /**
  10. * Code
  11. */
  12. /* INIT SECTION */
  13. define('FRAME', 'message');
  14. $language_file = array('chat');
  15. require_once '../inc/global.inc.php';
  16. $course = api_get_course_id();
  17. $session_id = api_get_session_id();
  18. $group_id = api_get_group_id();
  19. // Juan Carlos Raña inserted smileys and self-closing window.
  20. ?>
  21. <script >
  22. function insert_smile(text) {
  23. if (text.createTextRange) {
  24. text.smile = document.selection.createRange().duplicate();
  25. }
  26. }
  27. function insert(text) {
  28. var chat = document.formMessage.message;
  29. if (chat.createTextRange && chat.smile) {
  30. var smile = chat.smile;
  31. smile.text = smile.text.charAt(smile.text.length - 1) == ' ' ? text + ' ' : text;
  32. }
  33. else chat.value += text;
  34. chat.focus(smile)
  35. }
  36. function close_chat_window() {
  37. var chat_window = top.window.self;
  38. chat_window.opener = top.window.self;
  39. chat_window.top.close();
  40. }
  41. </script>
  42. <?php
  43. // Mode open in a new window: close the window when there isn't an user login
  44. if (empty($_user['user_id'])) {
  45. echo '<script languaje="javascript" type="text/javascript"> close_chat_window(); </script>';
  46. } else {
  47. api_protect_course_script();
  48. }
  49. // if we have the session set up
  50. if (!empty($course) && !empty($_user['user_id'])) {
  51. /* Constants and variables */
  52. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  53. $sent = $_REQUEST['sent'];
  54. /* MAIN CODE */
  55. $query = "SELECT lastname, firstname, username FROM $tbl_user WHERE user_id='".intval($_user['user_id'])."'";
  56. $result = Database::query($query);
  57. list($pseudo_user) = Database::fetch_row($result);
  58. $isAllowed = !(empty($pseudo_user) || !$_cid);
  59. $isMaster = (bool)api_is_course_admin();
  60. $firstname = Database::result($result, 0, 'firstname');
  61. $lastname = Database::result($result, 0, 'lastname');
  62. $date_now = date('Y-m-d');
  63. $basepath_chat = '';
  64. $document_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  65. if (!empty($group_id)) {
  66. $group_info = GroupManager :: get_group_properties($group_id);
  67. $basepath_chat = $group_info['directory'].'/chat_files';
  68. } else {
  69. $basepath_chat = '/chat_files';
  70. }
  71. $chat_path = $document_path.$basepath_chat.'/';
  72. $TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  73. $course_id = api_get_course_int_id();
  74. if (!is_dir($chat_path)) {
  75. if (is_file($chat_path)) {
  76. @unlink($chat_path);
  77. }
  78. if (!api_is_anonymous()) {
  79. @mkdir($chat_path, api_get_permissions_for_new_directories());
  80. // save chat files document for group into item property
  81. if (!empty($group_id)) {
  82. $doc_id = FileManager::add_document($_course, $basepath_chat, 'folder', 0, 'chat_files');
  83. $sql = "INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)
  84. VALUES ($course_id, 'document',1,NOW(),NOW(),$doc_id,'FolderCreated',1,$group_id,NULL,0)";
  85. Database::query($sql);
  86. }
  87. }
  88. }
  89. require 'header_frame.inc.php';
  90. $chat_size = 0;
  91. // Define emoticons
  92. $emoticon_text1 = ':-)';
  93. $emoticon_img1 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_smile.gif" alt="'.get_lang(
  94. 'Smile'
  95. ).'" title="'.get_lang('Smile').'" />';
  96. $emoticon_text2 = ':-D';
  97. $emoticon_img2 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_biggrin.gif" alt="'.get_lang(
  98. 'BigGrin'
  99. ).'" title="'.get_lang('BigGrin').'" />';
  100. $emoticon_text3 = ';-)';
  101. $emoticon_img3 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_wink.gif" alt="'.get_lang(
  102. 'Wink'
  103. ).'" title="'.get_lang('Wink').'" />';
  104. $emoticon_text4 = ':-P';
  105. $emoticon_img4 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_razz.gif" alt="'.get_lang(
  106. 'Avid'
  107. ).'" title="'.get_lang('Avid').'" />';
  108. $emoticon_text5 = '8-)';
  109. $emoticon_img5 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_cool.gif" alt="'.get_lang(
  110. 'Cool'
  111. ).'" title="'.get_lang('Cool').'" />';
  112. $emoticon_text6 = ':-o)';
  113. $emoticon_img6 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_surprised.gif" alt="'.get_lang(
  114. 'Surprised'
  115. ).'" title="'.get_lang('Surprised').'" />';
  116. $emoticon_text7 = '=;';
  117. $emoticon_img7 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_hand.gif" alt="'.get_lang(
  118. 'Hand'
  119. ).'" title="'.get_lang('Hand').'" />';
  120. $emoticon_text8 = '=8-o';
  121. $emoticon_img8 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_eek.gif" alt="'.get_lang(
  122. 'Amazing'
  123. ).'" title="'.get_lang('Amazing').'" />';
  124. $emoticon_text9 = ':-|)';
  125. $emoticon_img9 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_neutral.gif" alt="'.get_lang(
  126. 'Neutral'
  127. ).'" title="'.get_lang('Neutral').'" />';
  128. $emoticon_text8 = ':-k';
  129. $emoticon_img8 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_think.gif" alt="'.get_lang(
  130. 'Think'
  131. ).'" title="'.get_lang('Think').'" />';
  132. $emoticon_text11 = ':-?';
  133. $emoticon_img11 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_confused.gif" alt="'.get_lang(
  134. 'Confused'
  135. ).'" title="'.get_lang('Confused').'" />';
  136. $emoticon_text12 = ':-8';
  137. $emoticon_img12 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_redface.gif" alt="'.get_lang(
  138. 'Redface'
  139. ).'" title="'.get_lang('Redface').'" />';
  140. $emoticon_text13 = ':- = ';
  141. $emoticon_img13 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_shhh.gif" alt="'.get_lang(
  142. 'Silence'
  143. ).'" title="'.get_lang('Silence').'" />';
  144. $emoticon_text14 = ':-#)';
  145. $emoticon_img14 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_silenced.gif" alt="'.get_lang(
  146. 'Silenced'
  147. ).'" title="'.get_lang('Silenced').'" />';
  148. $emoticon_text15 = ':-(';
  149. $emoticon_img15 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_sad.gif" alt="'.get_lang(
  150. 'Sad'
  151. ).'" title="'.get_lang('Sad').'" />';
  152. $emoticon_text16 = ':-[8';
  153. $emoticon_img16 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_angry.gif" alt="'.get_lang(
  154. 'Angry'
  155. ).'" title="'.get_lang('Angry').'" />';
  156. $emoticon_text17 = '--)';
  157. $emoticon_img17 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_arrow.gif" alt="'.get_lang(
  158. 'Arrow'
  159. ).'" title="'.get_lang('Arrow').'" />';
  160. $emoticon_text18 = ':!:';
  161. $emoticon_img18 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_exclaim.gif" alt="'.get_lang(
  162. 'Exclamation'
  163. ).'" title="'.get_lang('Exclamation').'" />';
  164. $emoticon_text19 = ':?:';
  165. $emoticon_img19 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_question.gif" alt="'.get_lang(
  166. 'Question'
  167. ).'" title="'.get_lang('Question').'" />';
  168. $emoticon_text20 = '0-';
  169. $emoticon_img20 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/icon_idea.gif" alt="'.get_lang(
  170. 'Idea'
  171. ).'" title="'.get_lang('Idea').'" />';
  172. //
  173. $emoticon_text201 = '*';
  174. $emoticon_img201 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/waiting.gif" alt="'.get_lang(
  175. 'AskPermissionSpeak'
  176. ).'" title="'.get_lang('AskPermissionSpeak').'" />';
  177. $emoticon_text202 = ':speak:';
  178. $emoticon_img202 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/flag_green_small.gif" alt="'.get_lang(
  179. 'GiveTheFloorTo'
  180. ).'" title="'.get_lang('GiveTheFloorTo').'" />';
  181. $emoticon_text203 = ':pause:';
  182. $emoticon_img203 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/flag_yellow_small.gif" alt="'.get_lang(
  183. 'Pause'
  184. ).'" title="'.get_lang('Pause').'" />';
  185. $emoticon_text204 = ':stop:';
  186. $emoticon_img204 = '<img src="'.api_get_path(WEB_IMG_PATH).'smileys/flag_red_small.gif" alt="'.get_lang(
  187. 'Stop'
  188. ).'" title="'.get_lang('Stop').'" />';
  189. if ($sent) {
  190. $message = trim(htmlspecialchars(stripslashes($_POST['message']), ENT_QUOTES, $charset));
  191. $message = str_replace($emoticon_text1, $emoticon_img1, $message);
  192. $message = str_replace($emoticon_text2, $emoticon_img2, $message);
  193. $message = str_replace($emoticon_text3, $emoticon_img3, $message);
  194. $message = str_replace($emoticon_text4, $emoticon_img4, $message);
  195. $message = str_replace($emoticon_text5, $emoticon_img5, $message);
  196. $message = str_replace($emoticon_text6, $emoticon_img6, $message);
  197. $message = str_replace($emoticon_text7, $emoticon_img7, $message);
  198. $message = str_replace($emoticon_text8, $emoticon_img8, $message);
  199. $message = str_replace($emoticon_text9, $emoticon_img9, $message);
  200. $message = str_replace($emoticon_text10, $emoticon_img10, $message);
  201. $message = str_replace($emoticon_text11, $emoticon_img11, $message);
  202. $message = str_replace($emoticon_text12, $emoticon_img12, $message);
  203. $message = str_replace($emoticon_text13, $emoticon_img13, $message);
  204. $message = str_replace($emoticon_text14, $emoticon_img14, $message);
  205. $message = str_replace($emoticon_text15, $emoticon_img15, $message);
  206. $message = str_replace($emoticon_text16, $emoticon_img16, $message);
  207. $message = str_replace($emoticon_text17, $emoticon_img17, $message);
  208. $message = str_replace($emoticon_text18, $emoticon_img18, $message);
  209. $message = str_replace($emoticon_text19, $emoticon_img19, $message);
  210. $message = str_replace($emoticon_text20, $emoticon_img20, $message);
  211. //
  212. $message = str_replace($emoticon_text201, $emoticon_img201, $message);
  213. $message = str_replace($emoticon_text202, $emoticon_img202, $message);
  214. $message = str_replace($emoticon_text203, $emoticon_img203, $message);
  215. $message = str_replace($emoticon_text204, $emoticon_img204, $message);
  216. $timeNow = date('d/m/y H:i:s');
  217. $basename_chat = '';
  218. if (!empty($group_id)) {
  219. $basename_chat = 'messages-'.$date_now.'_gid-'.$group_id;
  220. } elseif (!empty($session_id)) {
  221. $basename_chat = 'messages-'.$date_now.'_sid-'.$session_id;
  222. } else {
  223. $basename_chat = 'messages-'.$date_now;
  224. }
  225. if (!api_is_anonymous()) {
  226. if (!empty($message)) {
  227. $message = Text::make_clickable($message);
  228. if (!file_exists($chat_path.$basename_chat.'.log.html')) {
  229. $doc_id = FileManager::add_document(
  230. $_course,
  231. $basepath_chat.'/'.$basename_chat.'.log.html',
  232. 'file',
  233. 0,
  234. $basename_chat.'.log.html'
  235. );
  236. api_item_property_update(
  237. $_course,
  238. TOOL_DOCUMENT,
  239. $doc_id,
  240. 'DocumentAdded',
  241. $_user['user_id'],
  242. $group_id,
  243. null,
  244. null,
  245. null,
  246. $session_id
  247. );
  248. api_item_property_update(
  249. $_course,
  250. TOOL_DOCUMENT,
  251. $doc_id,
  252. 'invisible',
  253. $_user['user_id'],
  254. $group_id,
  255. null,
  256. null,
  257. null,
  258. $session_id
  259. );
  260. FileManager::item_property_update_on_folder($_course, $basepath_chat, $_user['user_id']);
  261. } else {
  262. $doc_id = DocumentManager::get_document_id($_course, $basepath_chat.'/'.$basename_chat.'.log.html');
  263. }
  264. $fp = fopen($chat_path.$basename_chat.'.log.html', 'a');
  265. if ($isMaster) {
  266. $photo = '<img src="'.api_get_path(WEB_IMG_PATH).'teachers.gif" alt="'.get_lang(
  267. 'Teacher'
  268. ).'" width="11" height="11" align="top" title="'.get_lang('Teacher').'" />';
  269. fputs(
  270. $fp,
  271. '<span style="color:#999; font-size: smaller;">['.$timeNow.']</span>'.$photo.' <span id="chat_login_name"><b>'.api_get_person_name(
  272. $firstname,
  273. $lastname
  274. ).'</b></span> : <i>'.$message.'</i><br />'."\n"
  275. );
  276. } else {
  277. $photo = '<img src="'.api_get_path(WEB_IMG_PATH).'students.gif" alt="'.get_lang(
  278. 'Student'
  279. ).'" width="11" height="11" align="top" title="'.get_lang('Student').'" />';
  280. fputs(
  281. $fp,
  282. '<span style="color:#999; font-size: smaller;">['.$timeNow.']</span>'.$photo.' <b>'.api_get_person_name(
  283. $firstname,
  284. $lastname
  285. ).'</b> : <i>'.$message.'</i><br />'."\n"
  286. );
  287. }
  288. fclose($fp);
  289. $chat_size = filesize($chat_path.$basename_chat.'.log.html');
  290. FileManager::update_existing_document($_course, $doc_id, $chat_size);
  291. FileManager::item_property_update_on_folder($_course, $basepath_chat, $_user['user_id']);
  292. }
  293. }
  294. }
  295. ?>
  296. <form name="formMessage" method="post" action="<?php echo api_get_self().'?'.api_get_cidreq(); ?>"
  297. onsubmit="javascript: if(document.formMessage.message.value == '') { alert('<?php echo addslashes(
  298. api_htmlentities(get_lang('TypeMessage'), ENT_QUOTES)
  299. ); ?>'); document.formMessage.message.focus(); return false; }" autocomplete="off">
  300. <input type="hidden" name="sent" value="1">
  301. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  302. <tr>
  303. <td width="320" valign="middle">
  304. <?php $talkboxsize = (api_get_course_setting(
  305. 'allow_open_chat_window'
  306. )) ? 'width: 350px; height: 35px' : 'width: 450px; height: 35px'; ?>
  307. <textarea name="message" style=" <?php echo $talkboxsize; ?>" onkeydown="send_message(event);"
  308. onclick="javascript: insert_smile(this);"></textarea>
  309. </td>
  310. <td>
  311. <button type="submit" value="<?php echo get_lang('Send'); ?>"
  312. class="background_submit"><?php echo get_lang('Send'); ?></button>
  313. </td>
  314. </tr>
  315. <tr>
  316. <td>
  317. <?php
  318. echo "<a href=\"javascript:insert('".$emoticon_text1."')\">".$emoticon_img1."</a>";
  319. echo "<a href=\"javascript:insert('".$emoticon_text2."')\">".$emoticon_img2."</a>";
  320. echo "<a href=\"javascript:insert('".$emoticon_text3."')\">".$emoticon_img3."</a>";
  321. echo "<a href=\"javascript:insert('".$emoticon_text4."')\">".$emoticon_img4."</a>";
  322. echo "<a href=\"javascript:insert('".$emoticon_text5."')\">".$emoticon_img5."</a>";
  323. echo "<a href=\"javascript:insert('".$emoticon_text6."')\">".$emoticon_img6."</a>";
  324. echo "<a href=\"javascript:insert('".$emoticon_text7."')\">".$emoticon_img7."</a>";
  325. echo "<a href=\"javascript:insert('".$emoticon_text8."')\">".$emoticon_img8."</a>";
  326. echo "<a href=\"javascript:insert('".$emoticon_text9."')\">".$emoticon_img9."</a>";
  327. echo "<a href=\"javascript:insert('".$emoticon_text10."')\">".$emoticon_img10."</a>";
  328. echo "<a href=\"javascript:insert('".$emoticon_text11."')\">".$emoticon_img11."</a>";
  329. echo "<a href=\"javascript:insert('".$emoticon_text12."')\">".$emoticon_img12."</a>";
  330. echo "<a href=\"javascript:insert('".$emoticon_text13."')\">".$emoticon_img13."</a>";
  331. echo "<a href=\"javascript:insert('".$emoticon_text14."')\">".$emoticon_img14."</a>";
  332. echo "<a href=\"javascript:insert('".$emoticon_text15."')\">".$emoticon_img15."</a>";
  333. echo "<a href=\"javascript:insert('".$emoticon_text16."')\">".$emoticon_img16."</a>";
  334. echo "<a href=\"javascript:insert('".$emoticon_text17."')\">".$emoticon_img17."</a>";
  335. echo "<a href=\"javascript:insert('".$emoticon_text18."')\">".$emoticon_img18."</a>";
  336. echo "<a href=\"javascript:insert('".$emoticon_text19."')\">".$emoticon_img19."</a>";
  337. echo "<a href=\"javascript:insert('".$emoticon_text20."')\">".$emoticon_img20."</a>";
  338. ?>
  339. </td>
  340. <td>
  341. <?php
  342. echo "<a href=\"javascript:insert('".$emoticon_text201."')\">".$emoticon_img201."</a>";
  343. echo "<a href=\"javascript:insert('".$emoticon_text202."')\">".$emoticon_img202."</a>";
  344. echo "<a href=\"javascript:insert('".$emoticon_text203."')\">".$emoticon_img203."</a>";
  345. echo "<a href=\"javascript:insert('".$emoticon_text204."')\">".$emoticon_img204."</a>";
  346. ?>
  347. </td>
  348. </tr>
  349. </table>
  350. </form>
  351. <?php
  352. }
  353. require 'footer_frame.inc.php';