close_chat_window(); ';
} else {
api_protect_course_script();
}
// if we have the session set up
if (!empty($course) && !empty($_user['user_id'])) {
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
/* Constants and variables */
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$sent = isset($_REQUEST['sent']) ? $_REQUEST['sent'] : null;
/* MAIN CODE */
$query = "SELECT user_id, lastname, firstname, username, picture_uri FROM $tbl_user WHERE user_id='".intval($_user['user_id'])."'";
$result = Database::query($query);
list($pseudo_user) = Database::fetch_row($result);
$isAllowed = !(empty($pseudo_user) || !$_cid);
$isMaster = (bool)api_is_course_admin();
$user_id = Database::result($result, 0, 'user_id');
$firstname = Database::result($result, 0, 'firstname');
$lastname = Database::result($result, 0, 'lastname');
$picture = Database::result($result, 0, 'picture_uri');
$date_now = date('Y-m-d');
$basepath_chat = '';
$document_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
if (!empty($group_id)) {
$group_info = GroupManager :: get_group_properties($group_id);
$basepath_chat = $group_info['directory'].'/chat_files';
} else {
$basepath_chat = '/chat_files';
}
$chat_path = $document_path.$basepath_chat.'/';
if (!is_dir($chat_path)) {
if (is_file($chat_path)) {
@unlink($chat_path);
}
}
require 'header_frame.inc.php';
$chat_size = 0;
// Define emoticons
$emoticon_text1 = ':-)';
$emoticon_img1 = '';
$emoticon_text2 = ':-D';
$emoticon_img2 = '
';
$emoticon_text3 = ';-)';
$emoticon_img3 = '
';
$emoticon_text4 = ':-P';
$emoticon_img4 = '
';
$emoticon_text5 = '8-)';
$emoticon_img5 = '
';
$emoticon_text6 = ':-o)';
$emoticon_img6 = '
';
$emoticon_text7 = '=;';
$emoticon_img7 = '
';
$emoticon_text8 = '=8-o';
$emoticon_img8 = '
';
$emoticon_text9 = ':-|)';
$emoticon_img9 = '
';
$emoticon_text10 = ':-k';
$emoticon_img10 = '
';
$emoticon_text11 = ':-?';
$emoticon_img11 = '
';
$emoticon_text12 = ':-8';
$emoticon_img12 = '
';
$emoticon_text13 = ':-L';
$emoticon_img13 = '
';
$emoticon_text14 = ':-#)';
$emoticon_img14 = '
';
$emoticon_text15 = ':-(';
$emoticon_img15 = '
';
$emoticon_text16 = ';-(';
$emoticon_img16 = '
';
$emoticon_text17 = ':-[8';
$emoticon_img17 = '
';
$emoticon_text18 = '--)';
$emoticon_img18 = '
';
$emoticon_text19 = ':!:';
$emoticon_img19 = '
';
$emoticon_text20 = ':?:';
$emoticon_img20 = '
';
$emoticon_text21 = '0-';
$emoticon_img21 = '
';
$emoticon_text201 = '*';
$emoticon_img201 = '
';
$emoticon_text202 = ':speak:';
$emoticon_img202 = '
';
$emoticon_text203 = ':pause:';
$emoticon_img203 = '
';
$emoticon_text204 = ':stop:';
$emoticon_img204 = '
';
if ($sent) {
$message = Security::remove_XSS(trim(htmlspecialchars(stripslashes($_POST['message']), ENT_QUOTES, $charset)));
$message = str_replace($emoticon_text1, $emoticon_img1, $message);
$message = str_replace($emoticon_text2, $emoticon_img2, $message);
$message = str_replace($emoticon_text3, $emoticon_img3, $message);
$message = str_replace($emoticon_text4, $emoticon_img4, $message);
$message = str_replace($emoticon_text5, $emoticon_img5, $message);
$message = str_replace($emoticon_text6, $emoticon_img6, $message);
$message = str_replace($emoticon_text7, $emoticon_img7, $message);
$message = str_replace($emoticon_text8, $emoticon_img8, $message);
$message = str_replace($emoticon_text9, $emoticon_img9, $message);
$message = str_replace($emoticon_text10, $emoticon_img10, $message);
$message = str_replace($emoticon_text11, $emoticon_img11, $message);
$message = str_replace($emoticon_text12, $emoticon_img12, $message);
$message = str_replace($emoticon_text13, $emoticon_img13, $message);
$message = str_replace($emoticon_text14, $emoticon_img14, $message);
$message = str_replace($emoticon_text15, $emoticon_img15, $message);
$message = str_replace($emoticon_text16, $emoticon_img16, $message);
$message = str_replace($emoticon_text17, $emoticon_img17, $message);
$message = str_replace($emoticon_text18, $emoticon_img18, $message);
$message = str_replace($emoticon_text19, $emoticon_img19, $message);
$message = str_replace($emoticon_text20, $emoticon_img20, $message);
$message = str_replace($emoticon_text21, $emoticon_img21, $message);
//
$message = str_replace($emoticon_text201, $emoticon_img201, $message);
$message = str_replace($emoticon_text202, $emoticon_img202, $message);
$message = str_replace($emoticon_text203, $emoticon_img203, $message);
$message = str_replace($emoticon_text204, $emoticon_img204, $message);
$timeNow = date('d/m/y H:i:s');
$basename_chat = '';
if (!empty($group_id)) {
$basename_chat = 'messages-'.$date_now.'_gid-'.$group_id;
} elseif (!empty($session_id)) {
$basename_chat = 'messages-'.$date_now.'_sid-'.$session_id;
} else {
$basename_chat = 'messages-'.$date_now;
}
if (!api_is_anonymous()) {
if (!empty($message)) {
//$message = make_clickable($message);
if (!file_exists($chat_path.$basename_chat.'.log.html')) {
$doc_id = add_document($_course, $basepath_chat.'/'.$basename_chat.'.log.html', 'file', 0, $basename_chat.'.log.html');
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $group_id, null, null, null, $session_id);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], $group_id, null, null, null, $session_id);
item_property_update_on_folder($_course, $basepath_chat, $_user['user_id']);
} else {
$doc_id = DocumentManager::get_document_id($_course, $basepath_chat.'/'.$basename_chat.'.log.html');
}
$fp = fopen($chat_path.$basename_chat.'.log.html', 'a');
// view user picture
$userImage = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
if (substr($userImage['file'],0,7) != 'unknown') {
$userPhoto = $userImage['dir'].'medium_'.$userImage['file'];
} else {
$userPhoto = $userImage['dir'].$userImage['file'];
}
$filePhoto = '
';
if ($isMaster) {
fputs($fp, '