Renew course chat - refs BT#11284 #tmi (#1225)
* Fix get history files from course chat - refs BT#11284 * Clean code + Create template for course chat - refs BT#11284 * Renew course chat - refs BT#11284 * Allow course chat between two users - refs BT#11284 * Improve course chat style and template - refs BT#11284 * Add event when user access to chat tool - refs BT#11284 * Show all course users instead of connected users only - refs BT#11284 * Fix course chat in basis courses - refs BT#111284 * Filter users on chat by course - refs BT#11284 * Update jquery.textcomplete.js - refs BT#11248 * Fix autocomplete for emojis in course chat - refs BT#11284 * Search url in messages for course chat - refs BT#11284 * Add ctrl + Enter event to send messages in course chat - refs BT#11284ofaj
parent
d4cbcec037
commit
f9ffa0fccf
@ -1,92 +1,58 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use ChamiloSession as Session; |
||||
|
||||
/** |
||||
* Chat tool |
||||
* @package chamilo.chat |
||||
*/ |
||||
define('CHAMILO_LOAD_WYSIWYG', false); |
||||
|
||||
require_once '../inc/global.inc.php'; |
||||
$current_course_tool = TOOL_CHAT; |
||||
$this_section = SECTION_COURSES; |
||||
$nameTools = get_lang('ToolChat'); |
||||
|
||||
$origin = isset($_GET["origin"]) ? Security::remove_XSS($_GET["origin"]) : null; |
||||
$target = isset($_GET["target"]) ? Security::remove_XSS($_GET["target"]) : null; |
||||
|
||||
if ($origin != 'whoisonline') { |
||||
api_protect_course_script(true); |
||||
} else { |
||||
$origin = Session::read('origin'); |
||||
$target = Session::read('target'); |
||||
} |
||||
|
||||
api_protect_course_group(GroupManager::GROUP_TOOL_CHAT, false); |
||||
api_protect_course_script(true); |
||||
|
||||
/* TRACKING */ |
||||
Event::event_access_tool(TOOL_CHAT); |
||||
header('Content-Type: text/html; charset=UTF-8'); |
||||
|
||||
/* |
||||
* Choose CSS style (platform's, user's, or course's) |
||||
*/ |
||||
$my_style = api_get_visual_theme(); |
||||
|
||||
$mycourseid = api_get_course_id(); |
||||
if (!empty($mycourseid) && $mycourseid != -1) { |
||||
$open_chat_window = api_get_course_setting('allow_open_chat_window'); |
||||
// View |
||||
$externalCSS = [ |
||||
'jquery-emojiarea/jquery.emojiarea.css', |
||||
'jquery-textcomplete/jquery.textcomplete.css', |
||||
'emojione/css/emojione.min.css', |
||||
'emojione/css/autocomplete.css', |
||||
'highlight/styles/github.css' |
||||
]; |
||||
|
||||
foreach ($externalCSS as $css) { |
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_JS_PATH) . $css); |
||||
} |
||||
|
||||
$courseCode = Security::remove_XSS($_GET['cidReq']); |
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_CSS_PATH) . 'chat.css'); |
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_CSS_PATH) . 'markdown.css'); |
||||
|
||||
?> |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<meta charset="UTF-8" /> |
||||
<link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CSS_PATH); ?>chat.css">
|
||||
<?php |
||||
echo'<title>'.get_lang('Chat').' - '.$mycourseid.' - '.api_get_setting('siteName').'</title>'; |
||||
$externalJS = [ |
||||
'highlight/highlight.pack.js', |
||||
'jquery-textcomplete/jquery.textcomplete.js', |
||||
'emojione/js/emojione.min.js', |
||||
'jquery-emojiarea/jquery.emojiarea.js' |
||||
]; |
||||
|
||||
$groupId = api_get_group_id(); |
||||
|
||||
// If it is a group chat then the breadcrumbs. |
||||
if (!empty($groupId)) { |
||||
$group_properties = GroupManager :: get_group_properties($groupId); |
||||
$interbreadcrumb[] = array( |
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), |
||||
'name' => get_lang('Groups') |
||||
); |
||||
$interbreadcrumb[] = array( |
||||
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), |
||||
'name' => get_lang('GroupSpace').' '.$group_properties['name'] |
||||
); |
||||
$noPHP_SELF = true; |
||||
$shortBanner = false; |
||||
$add_group_to_title = ' ('.$group_properties['name'].')'; |
||||
$groupfilter = 'group_id="'.$groupId.'"'; |
||||
} else { |
||||
$groupfilter = 'group_id=0'; |
||||
} |
||||
|
||||
if (empty($open_chat_window)) { |
||||
Display::display_header($tool_name, 'Chat'); |
||||
foreach ($externalJS as $js) { |
||||
$htmlHeadXtra[] = api_get_js($js); |
||||
} |
||||
|
||||
$url = api_get_path(WEB_CODE_PATH).'chat/'; |
||||
$params = api_get_cidreq(); |
||||
$iconList = []; |
||||
|
||||
echo '<div class="page-chat">'; |
||||
echo '<iframe src="'.$url.'chat_whoisonline.php?'.$params.'" name="chat_whoisonline" scrolling="no" style="height:550px; width:35%; border: 0px none; float:left"></iframe>'; |
||||
echo '<iframe src="'.$url.'chat_chat.php?origin='.$origin.'&target='.$target.'&'.$params.'" name="chat_chat" id="chat_chat" scrolling="auto" height="380" style="width:65%; border: 0px none; float:right"></iframe>'; |
||||
echo '<iframe src="'.$url.'chat_message.php?'.$params.'" name="chat_message" scrolling="no" height="182px" style="width:65%; border: 0px none; float:right"></iframe>'; |
||||
echo '<iframe src="'.$url.'chat_hidden.php?'.$params.'" name="chat_hidden" height="0px" style="height:0px; border: 0px none"></iframe>'; |
||||
echo '</div>'; |
||||
foreach (Emojione\Emojione::$shortcode_replace as $key => $icon) { |
||||
if (!in_array($key, CourseChatUtils::getEmojisToInclude())) { |
||||
continue; |
||||
} |
||||
|
||||
if (empty($open_chat_window)) { |
||||
Display::display_footer(); |
||||
$iconList[$key] = strtoupper($icon) . '.png'; |
||||
} |
||||
|
||||
echo '</html>'; |
||||
$view = new Template(get_lang('Chat'), false, false, false, true, false); |
||||
$view->assign('icons', $iconList); |
||||
$view->assign('emoji_strategy', CourseChatUtils::getEmojiStrategry()); |
||||
$view->assign('emoji_smile', \Emojione\Emojione::toImage(':smile:')); |
||||
|
||||
$template = $view->get_template('chat/chat.tpl'); |
||||
$content = $view->fetch($template); |
||||
|
||||
$view->assign('content', $content); |
||||
$view->display_one_col_template(); |
||||
|
@ -1,217 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Chat frame that shows the message list |
||||
* |
||||
* @author Olivier Brouckaert |
||||
* @package chamilo.chat |
||||
*/ |
||||
|
||||
define('FRAME', 'chat'); |
||||
|
||||
require_once '../inc/global.inc.php'; |
||||
|
||||
$course = $_GET['cidReq']; |
||||
$session_id = api_get_session_id(); |
||||
$group_id = api_get_group_id(); |
||||
$userId = api_get_user_id(); |
||||
$_course = api_get_course_info(); |
||||
$time = api_get_utc_datetime(); |
||||
|
||||
// if we have the session set up |
||||
if (!empty($course)) { |
||||
$reset = isset($_GET['reset']) ? (bool)$_GET['reset'] : null; |
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); |
||||
$query = "SELECT username FROM $tbl_user WHERE user_id='".$userId."'"; |
||||
$result = Database::query($query); |
||||
|
||||
list($pseudo_user) = Database::fetch_row($result); |
||||
|
||||
$isAllowed = !(empty($pseudo_user) || !$_cid); |
||||
$isMaster = (bool)api_is_course_admin(); |
||||
|
||||
$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.'/'; |
||||
$TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||||
$course_id = api_get_course_int_id(); |
||||
|
||||
if (!is_dir($chat_path)) { |
||||
if (is_file($chat_path)) { |
||||
@unlink($chat_path); |
||||
} |
||||
|
||||
if (!api_is_anonymous()) { |
||||
@mkdir($chat_path, api_get_permissions_for_new_directories()); |
||||
// Save chat files document for group into item property |
||||
if (!empty($group_id)) { |
||||
$doc_id = add_document($_course, $basepath_chat, 'folder', 0, 'chat_files'); |
||||
api_item_property_update( |
||||
$_course, |
||||
TOOL_DOCUMENT, |
||||
$doc_id, |
||||
'FolderCreated', |
||||
null, |
||||
$group_id, |
||||
null, |
||||
null, |
||||
null |
||||
); |
||||
} |
||||
} |
||||
} |
||||
|
||||
$filename_chat = ''; |
||||
if (!empty($group_id)) { |
||||
$filename_chat = 'messages-'.$date_now.'_gid-'.$group_id.'.log.html'; |
||||
} else if (!empty($session_id)) { |
||||
$filename_chat = 'messages-'.$date_now.'_sid-'.$session_id.'.log.html'; |
||||
} else { |
||||
$filename_chat = 'messages-'.$date_now.'.log.html'; |
||||
} |
||||
|
||||
if (!file_exists($chat_path.$filename_chat)) { |
||||
@fclose(fopen($chat_path.$filename_chat, 'w')); |
||||
if (!api_is_anonymous()) { |
||||
$doc_id = add_document($_course, $basepath_chat.'/'.$filename_chat, 'file', 0, $filename_chat); |
||||
api_item_property_update( |
||||
$_course, |
||||
TOOL_DOCUMENT, |
||||
$doc_id, |
||||
'DocumentAdded', |
||||
$userId, |
||||
$group_id, |
||||
null, |
||||
null, |
||||
null, |
||||
$session_id |
||||
); |
||||
api_item_property_update( |
||||
$_course, |
||||
TOOL_DOCUMENT, |
||||
$doc_id, |
||||
'invisible', |
||||
$userId, |
||||
$group_id, |
||||
null, |
||||
null, |
||||
null, |
||||
$session_id |
||||
); |
||||
item_property_update_on_folder($_course, $basepath_chat, $userId); |
||||
} |
||||
} |
||||
|
||||
$basename_chat = ''; |
||||
if (!empty($group_id)) { |
||||
$basename_chat = 'messages-'.$date_now.'_gid-'.$group_id; |
||||
} else if (!empty($session_id)) { |
||||
$basename_chat = 'messages-'.$date_now.'_sid-'.$session_id; |
||||
} else { |
||||
$basename_chat = 'messages-'.$date_now; |
||||
} |
||||
|
||||
if ($reset && $isMaster) { |
||||
|
||||
$i = 1; |
||||
while (file_exists($chat_path.$basename_chat.'-'.$i.'.log.html')) { |
||||
$i++; |
||||
} |
||||
|
||||
@rename($chat_path.$basename_chat.'.log.html', $chat_path.$basename_chat.'-'.$i.'.log.html'); |
||||
@fclose(fopen($chat_path.$basename_chat.'.log.html', 'w')); |
||||
$doc_id = add_document($_course, $basepath_chat.'/'.$basename_chat.'-'.$i.'.log.html', 'file', filesize($chat_path.$basename_chat.'-'.$i.'.log.html'), $basename_chat.'-'.$i.'.log.html'); |
||||
|
||||
api_item_property_update( |
||||
$_course, |
||||
TOOL_DOCUMENT, |
||||
$doc_id, |
||||
'DocumentAdded', |
||||
$userId, |
||||
$group_id, |
||||
null, |
||||
null, |
||||
null, |
||||
$session_id |
||||
); |
||||
api_item_property_update( |
||||
$_course, |
||||
TOOL_DOCUMENT, |
||||
$doc_id, |
||||
'invisible', |
||||
$userId, |
||||
$group_id, |
||||
null, |
||||
null, |
||||
null, |
||||
$session_id |
||||
); |
||||
item_property_update_on_folder($_course, $basepath_chat, $userId); |
||||
|
||||
$doc_id = DocumentManager::get_document_id( |
||||
$_course, |
||||
$basepath_chat.'/'.$basename_chat.'.log.html' |
||||
); |
||||
|
||||
update_existing_document($_course, $doc_id, 0); |
||||
} |
||||
|
||||
$remove = 0; |
||||
$content = array(); |
||||
if (file_exists($chat_path.$basename_chat.'.log.html')) { |
||||
$content = file($chat_path.$basename_chat.'.log.html'); |
||||
$nbr_lines = sizeof($content); |
||||
$remove = $nbr_lines - 100; |
||||
} |
||||
|
||||
if ($remove < 0) { |
||||
$remove = 0; |
||||
} |
||||
|
||||
array_splice($content, 0, $remove); |
||||
require 'header_frame.inc.php'; |
||||
|
||||
if (isset($_GET['origin']) && $_GET['origin'] == 'whoisonline') { |
||||
//the caller |
||||
$content[0] = get_lang('CallSent').'<br />'.$content[0]; |
||||
} |
||||
if (isset($_GET['origin']) && $_GET['origin'] == 'whoisonlinejoin') { |
||||
//the joiner (we have to delete the chat request to him when he joins the chat) |
||||
$track_user_table = Database::get_main_table(TABLE_MAIN_USER); |
||||
$sql = "UPDATE $track_user_table SET |
||||
chatcall_user_id = '', |
||||
chatcall_date = '', |
||||
chatcall_text='' |
||||
WHERE (user_id = ".$userId.")"; |
||||
$result = Database::query($sql); |
||||
} |
||||
|
||||
echo '<div id="content-chat"'; |
||||
foreach ($content as & $this_line) { |
||||
echo $this_line; |
||||
} |
||||
echo '</div>'; |
||||
echo '<a name="bottom" style="text-decoration:none;"> </a>'; |
||||
if ($isMaster || $is_courseCoach) { |
||||
$rand = mt_rand(1, 1000); |
||||
echo '<div id="clear-chat">'; |
||||
echo '<a class="btn btn-danger btn-small " href="'.api_get_self().'?rand='.$rand.'&reset=1&'.api_get_cidreq().'#bottom" onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmReset'), ENT_QUOTES)).'\')) return false;">'. |
||||
get_lang('ClearList'). |
||||
'</a>'; |
||||
echo '</div>'; |
||||
} |
||||
} else { |
||||
echo '</div>'; |
||||
require 'header_frame.inc.php'; |
||||
$message = get_lang('CloseOtherSession'); |
||||
Display :: display_error_message($message); |
||||
} |
||||
require 'footer_frame.inc.php'; |
@ -1,242 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* @package chamilo.chat |
||||
*/ |
||||
use Michelf\MarkdownExtra; |
||||
|
||||
/** |
||||
* @author isaac flores paz |
||||
* @param integer $user_id |
||||
* |
||||
* @return boolean |
||||
* @todo this function need more parameters seems not to be use anymore |
||||
* @deprecated fix this function or create another |
||||
*/ |
||||
function user_connected_in_chat($user_id) |
||||
{ |
||||
$tbl_chat_connected = Database::get_course_table(TABLE_CHAT_CONNECTED); |
||||
$user_id = intval($user_id); |
||||
$session_id = api_get_session_id(); |
||||
$group_id = api_get_group_id(); |
||||
$course_id = api_get_course_int_id(); |
||||
|
||||
if (!empty($group_id)) { |
||||
$extra_condition = " AND to_group_id = '$group_id'"; |
||||
} else { |
||||
$extra_condition = api_get_session_condition($session_id); |
||||
} |
||||
|
||||
$sql = 'SELECT COUNT(*) AS count |
||||
FROM '.$tbl_chat_connected .' c |
||||
WHERE |
||||
c_id = '.$course_id.' AND |
||||
user_id='.$user_id.$extra_condition; |
||||
$result = Database::query($sql); |
||||
$count = Database::fetch_array($result,'ASSOC'); |
||||
|
||||
return $count['count'] == 1; |
||||
} |
||||
|
||||
/** |
||||
* @param integer |
||||
* @return void |
||||
*/ |
||||
function exit_of_chat($user_id) |
||||
{ |
||||
$user_id = intval($user_id); |
||||
$list_course = CourseManager::get_courses_list_by_user_id($user_id); |
||||
$tbl_chat_connected = Database::get_course_table(TABLE_CHAT_CONNECTED); |
||||
|
||||
foreach ($list_course as $course) { |
||||
$response = user_connected_in_chat($user_id); |
||||
|
||||
$sql = 'DELETE FROM '.$tbl_chat_connected.' |
||||
WHERE c_id = '.$course['real_id'].' AND user_id = '.$user_id; |
||||
Database::query($sql); |
||||
|
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @return void |
||||
*/ |
||||
function disconnect_user_of_chat() |
||||
{ |
||||
$list_info_user_in_chat = users_list_in_chat(); |
||||
$course_id = api_get_course_int_id(); |
||||
$groupId = api_get_group_id(); |
||||
$now = time(); |
||||
$cd_date = date('Y-m-d', $now); |
||||
$cdate_h = date('H', $now); |
||||
$cdate_m = date('i', $now); |
||||
$cdate_s = date('s', $now); |
||||
$cd_count_time_seconds = $cdate_h*3600 + $cdate_m*60 + $cdate_s; |
||||
|
||||
if (is_array($list_info_user_in_chat) && count($list_info_user_in_chat) > 0) { |
||||
foreach ($list_info_user_in_chat as $list_info_user) { |
||||
$date_db_date = date('Y-m-d', api_strtotime($list_info_user['last_connection'], 'UTC')); |
||||
$date_db_h = date('H', api_strtotime($list_info_user['last_connection'], 'UTC')); |
||||
$date_db_m = date('i', api_strtotime($list_info_user['last_connection'], 'UTC')); |
||||
$date_db_s = date('s', api_strtotime($list_info_user['last_connection'], 'UTC')); |
||||
$date_count_time_seconds = $date_db_h * 3600 + $date_db_m * 60 + $date_db_s; |
||||
if ($cd_date == $date_db_date) { |
||||
if (($cd_count_time_seconds - $date_count_time_seconds) > 5) { |
||||
$tbl_chat_connected = Database::get_course_table(TABLE_CHAT_CONNECTED); |
||||
$sql = 'DELETE FROM '.$tbl_chat_connected.' |
||||
WHERE |
||||
c_id = '.$course_id.' AND |
||||
user_id = '.$list_info_user['user_id'].' AND |
||||
to_group_id = '.$groupId.' |
||||
'; |
||||
Database::query($sql); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @return array user list in chat |
||||
*/ |
||||
function users_list_in_chat() |
||||
{ |
||||
$list_users_in_chat = array(); |
||||
$tbl_chat_connected = Database::get_course_table(TABLE_CHAT_CONNECTED); |
||||
$course_id = api_get_course_int_id(); |
||||
|
||||
$session_id = api_get_session_id(); |
||||
$group_id = api_get_group_id(); |
||||
|
||||
if (!empty($group_id)) { |
||||
$extra_condition = " WHERE to_group_id = '$group_id'"; |
||||
} else{ |
||||
$extra_condition = api_get_session_condition($session_id, false); |
||||
} |
||||
$extra_condition.= " AND c_id = $course_id "; |
||||
$sql = 'SELECT user_id, last_connection FROM '.$tbl_chat_connected.$extra_condition; |
||||
$result = Database::query($sql); |
||||
while ($row = Database::fetch_array($result, 'ASSOC')) { |
||||
$list_users_in_chat[] = $row; |
||||
} |
||||
|
||||
return $list_users_in_chat; |
||||
} |
||||
|
||||
/** |
||||
* @param string $message |
||||
* @param array $_course |
||||
* @param int $group_id |
||||
* @param int $session_id |
||||
* @param bool $preview |
||||
*/ |
||||
function saveMessage($message, $userId, $_course, $session_id, $group_id, $preview = true) |
||||
{ |
||||
$userInfo = api_get_user_info($userId); |
||||
$fullName = $userInfo['complete_name']; |
||||
$isMaster = (bool)api_is_course_admin(); |
||||
|
||||
$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); |
||||
} |
||||
} |
||||
|
||||
$date_now = date('Y-m-d'); |
||||
$message = trim($message); |
||||
$timeNow = date('d/m/y H:i:s'); |
||||
|
||||
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)) { |
||||
Emojione\Emojione::$imagePathPNG = api_get_path(WEB_LIBRARY_PATH).'javascript/emojione/png/'; |
||||
Emojione\Emojione::$ascii = true; |
||||
|
||||
// Parsing emojis |
||||
$message = Emojione\Emojione::toImage($message); |
||||
// Parsing text to understand markdown (code highlight) |
||||
$message = MarkdownExtra::defaultTransform($message); |
||||
// Security XSS |
||||
$message = Security::remove_XSS($message); |
||||
|
||||
if ($preview == true) { |
||||
return $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', |
||||
$userId, |
||||
$group_id, |
||||
null, |
||||
null, |
||||
null, |
||||
$session_id |
||||
); |
||||
api_item_property_update( |
||||
$_course, |
||||
TOOL_DOCUMENT, |
||||
$doc_id, |
||||
'invisible', |
||||
$userId, |
||||
$group_id, |
||||
null, |
||||
null, |
||||
null, |
||||
$session_id |
||||
); |
||||
item_property_update_on_folder( |
||||
$_course, |
||||
$basepath_chat, |
||||
$userId |
||||
); |
||||
} else { |
||||
$doc_id = DocumentManager::get_document_id( |
||||
$_course, |
||||
$basepath_chat.'/'.$basename_chat.'.log.html' |
||||
); |
||||
} |
||||
|
||||
$fp = fopen($chat_path.$basename_chat.'.log.html', 'a'); |
||||
$userPhoto = UserManager::getUserPicture($userId, USER_IMAGE_SIZE_MEDIUM); |
||||
$filePhoto = '<img class="chat-image" src="'.$userPhoto.'"/>'; |
||||
if ($isMaster) { |
||||
fputs($fp, '<div class="message-teacher"><div class="content-message"><div class="chat-message-block-name">'.$fullName.'</div><div class="chat-message-block-content">'.$message.'</div><div class="message-date">'.$timeNow.'</div></div><div class="icon-message"></div>'.$filePhoto.'</div>'."\n"); |
||||
} else { |
||||
fputs($fp, '<div class="message-student">'.$filePhoto.'<div class="icon-message"></div><div class="content-message"><div class="chat-message-block-name">'.$fullName.'</div><div class="chat-message-block-content">'.$message.'</div><div class="message-date">'.$timeNow.'</div></div></div>'."\n"); |
||||
} |
||||
fclose($fp); |
||||
|
||||
$chat_size = filesize($chat_path.$basename_chat.'.log.html'); |
||||
|
||||
update_existing_document($_course, $doc_id, $chat_size); |
||||
item_property_update_on_folder($_course, $basepath_chat, $userId); |
||||
} |
||||
} |
||||
} |
@ -1,130 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Hidden frame that refreshes the visible frames when a modification occurs |
||||
* |
||||
* @author Olivier Brouckaert |
||||
* @package chamilo.chat |
||||
*/ |
||||
|
||||
define('FRAME', 'hidden'); |
||||
|
||||
require_once '../inc/global.inc.php'; |
||||
require_once 'chat_functions.lib.php'; |
||||
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); |
||||
$tbl_chat_connected = Database::get_course_table(TABLE_CHAT_CONNECTED); |
||||
$userId = api_get_user_id(); |
||||
$course_id = api_get_course_int_id(); |
||||
|
||||
$query = "SELECT username FROM $tbl_user WHERE user_id='".$userId."'"; |
||||
$result = Database::query($query); |
||||
|
||||
list($pseudo_user) = Database::fetch_row($result); |
||||
|
||||
$isAllowed = !(empty($pseudo_user) || !$_cid); |
||||
$isMaster = (bool)api_is_course_admin(); |
||||
|
||||
$date_now = date('Y-m-d'); |
||||
|
||||
$group_id = api_get_group_id(); |
||||
$session_id = api_get_session_id(); |
||||
$session_condition = api_get_session_condition($session_id); |
||||
$group_condition = " AND to_group_id = '$group_id'"; |
||||
|
||||
$extra_condition = ''; |
||||
if (!empty($group_id)) { |
||||
$extra_condition = $group_condition; |
||||
} else { |
||||
$extra_condition = $session_condition; |
||||
} |
||||
|
||||
$extra_condition.= " AND c_id = $course_id"; |
||||
|
||||
// get chat path |
||||
$chat_path = ''; |
||||
$document_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; |
||||
if (!empty($group_id)) { |
||||
$group_info = GroupManager :: get_group_properties($group_id); |
||||
$chat_path = $document_path.$group_info['directory'].'/chat_files/'; |
||||
} else { |
||||
$chat_path = $document_path.'/chat_files/'; |
||||
} |
||||
|
||||
// get chat file |
||||
$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; |
||||
} |
||||
|
||||
$chat_size_old = isset($_POST['chat_size_old']) ? intval($_POST['chat_size_old']) : null; |
||||
|
||||
$file = $chat_path.$basename_chat.'.log.html'; |
||||
$chat_size_new = 0; |
||||
if (file_exists($file)) { |
||||
$chat_size_new = filesize($file); |
||||
} |
||||
|
||||
$sql = "SELECT user_id FROM $tbl_chat_connected |
||||
WHERE user_id='".$userId."' $extra_condition"; |
||||
$result = Database::query($sql); |
||||
|
||||
// The user_id exists so we must do an UPDATE and not a INSERT |
||||
$current_time = api_get_utc_datetime(); |
||||
|
||||
if (Database::num_rows($result) == 0) { |
||||
$query = "INSERT INTO $tbl_chat_connected(c_id, user_id, last_connection,session_id,to_group_id) |
||||
VALUES($course_id, '".$userId."','$current_time','$session_id','$group_id')"; |
||||
Database::query($query); |
||||
$id = Database::insert_id(); |
||||
if ($id) { |
||||
$sql = "UPDATE $tbl_chat_connected SET id = iid WHERE iid = $id"; |
||||
Database::query($sql); |
||||
} |
||||
} else { |
||||
$query = "UPDATE $tbl_chat_connected SET |
||||
last_connection='".$current_time."' |
||||
WHERE c_id = $course_id AND user_id='".$userId."' AND session_id='$session_id' AND to_group_id='$group_id'"; |
||||
Database::query($query); |
||||
} |
||||
|
||||
$query = "SELECT COUNT(user_id) FROM $tbl_chat_connected |
||||
WHERE last_connection>'".date('Y-m-d H:i:s',time()-60*5)."' $extra_condition"; |
||||
$result = Database::query($query); |
||||
|
||||
$connected_old = isset($_POST['connected_old']) ? intval($_POST['connected_old']) : null; |
||||
list($connected_new) = Database::fetch_row($result); |
||||
|
||||
/*disconnected user of chat*/ |
||||
disconnect_user_of_chat(); |
||||
require 'header_frame.inc.php'; |
||||
?> |
||||
<form name="formHidden" method="post" action="<?php echo api_get_self().'?'.api_get_cidreq(); ?>">
|
||||
<input type="hidden" name="chat_size_old" value="<?php echo $chat_size_new; ?>">
|
||||
<input type="hidden" name="connected_old" value="<?php echo $connected_new; ?>">
|
||||
</form> |
||||
<?php |
||||
|
||||
|
||||
$origin = Session::read('origin'); |
||||
$target = Session::read('target'); |
||||
|
||||
if ($origin == 'whoisonline') { |
||||
//check if our target has denied our request or not |
||||
$talk_to = (int) $target; |
||||
$track_user_table = Database::get_main_table(TABLE_MAIN_USER); |
||||
$sql = "select chatcall_text from $track_user_table where ( user_id = $talk_to )"; |
||||
$result = Database::query($sql); |
||||
$row = Database::fetch_array($result); |
||||
if ($row['chatcall_text'] == 'DENIED') { |
||||
echo "<script language=\"javascript\" type=\"text/javascript\"> alert('".get_lang('ChatDenied')."'); </script>"; |
||||
$sql = "update $track_user_table set chatcall_user_id = '', chatcall_date = '', chatcall_text='' WHERE (user_id = $talk_to)"; |
||||
$result = Database::query($sql); |
||||
} |
||||
} |
||||
require 'footer_frame.inc.php'; |
@ -1,128 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Allows to type the messages that will be displayed on chat_chat.php |
||||
* |
||||
* @author Olivier Brouckaert |
||||
* Modified by Alex Aragón (BeezNest) |
||||
* @package chamilo.chat |
||||
*/ |
||||
define('FRAME', 'message'); |
||||
|
||||
require_once '../inc/global.inc.php'; |
||||
require_once api_get_path(SYS_CODE_PATH).'chat/chat_functions.lib.php'; |
||||
|
||||
$userId = api_get_user_id(); |
||||
$userInfo = api_get_user_info(); |
||||
$course = api_get_course_id(); |
||||
$session_id = api_get_session_id(); |
||||
$group_id = api_get_group_id(); |
||||
$_course = api_get_course_info(); |
||||
|
||||
// Juan Carlos Raña inserted smileys and self-closing window. |
||||
?> |
||||
<script> |
||||
function close_chat_window() { |
||||
var chat_window = top.window.self; |
||||
chat_window.opener = top.window.self; |
||||
chat_window.top.close(); |
||||
} |
||||
</script> |
||||
<?php |
||||
|
||||
// Mode open in a new window: close the window when there isn't an user login |
||||
if (empty($userId)) { |
||||
echo '<script languaje="javascript" type="text/javascript"> close_chat_window(); </script>'; |
||||
} else { |
||||
api_protect_course_script(); |
||||
} |
||||
|
||||
if (empty($course) || empty($userId)) { |
||||
exit; |
||||
} |
||||
|
||||
/* Constants and variables */ |
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); |
||||
$sent = isset($_REQUEST['sent']) ? $_REQUEST['sent'] : null; |
||||
|
||||
require 'header_frame.inc.php'; |
||||
$chat_size = 0; |
||||
|
||||
if ($sent) { |
||||
saveMessage( |
||||
$_POST['message'], |
||||
$userId, |
||||
$_course, |
||||
$session_id, |
||||
$group_id, |
||||
false |
||||
); |
||||
} |
||||
?> |
||||
<form |
||||
id="formMessage" |
||||
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)); ?>'); document.formMessage.message.focus(); return false; }"
|
||||
autocomplete="off" |
||||
> |
||||
<input type="hidden" name="sent" value="1"> |
||||
<div class="message-form-chat"> |
||||
<div class="tabbable"> |
||||
<ul class="nav nav-tabs"> |
||||
<li class="active"> |
||||
<a href="#tab1" data-toggle="tab"> |
||||
<?php echo get_lang('Write'); ?> |
||||
</a> |
||||
</li> |
||||
<li> |
||||
<a href="#tab2" id="preview" data-toggle="tab"> |
||||
<?php echo get_lang('Preview'); ?> |
||||
</a> |
||||
</li> |
||||
<li> |
||||
<a href="#tab3" id="emojis" data-toggle="tab"> |
||||
<?php echo Emojione\Emojione::toImage(':smile:'); ?> |
||||
</a> |
||||
</li> |
||||
</ul> |
||||
<div class="tab-content"> |
||||
<div class="tab-pane active" id="tab1"> |
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%"> |
||||
<tr> |
||||
<td width="320" valign="middle"> |
||||
<?php |
||||
$talkboxsize = (api_get_course_setting('allow_open_chat_window')) ? 'width: 350px; height: 80px' : 'width: 450px; height: 35px'; |
||||
?> |
||||
<textarea id="message" class="message-text" name="message" style=" <?php echo $talkboxsize; ?>"></textarea>
|
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> |
||||
<div class="btn-group"> |
||||
<button id="send" type="submit" value="<?php echo get_lang('Send'); ?>" class="btn btn-primary">
|
||||
<?php echo get_lang('Send'); ?> |
||||
</button> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</div> |
||||
<div class="tab-pane" id="tab2"> |
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%"> |
||||
<tr> |
||||
<td width="320" valign="middle"> |
||||
<div id="html-preview" class="emoji-wysiwyg-editor-preview"> |
||||
</div> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</form> |
||||
<?php |
||||
|
||||
require 'footer_frame.inc.php'; |
@ -1,162 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Shows the list of connected users |
||||
* |
||||
* @author Olivier Brouckaert |
||||
* @package chamilo.chat |
||||
*/ |
||||
|
||||
define('FRAME', 'online'); |
||||
|
||||
require_once '../inc/global.inc.php'; |
||||
|
||||
$course = api_get_course_id(); |
||||
$courseInfo = api_get_course_info(); |
||||
$group_id = api_get_group_id(); |
||||
$session_id = api_get_session_id(); |
||||
$user_id = api_get_user_id(); |
||||
$group_condition = " AND to_group_id = '$group_id'"; |
||||
|
||||
$extra_condition = ''; |
||||
if (!empty($group_id)) { |
||||
$extra_condition = $group_condition; |
||||
} |
||||
|
||||
if (!empty($course)) { |
||||
$showPic = isset($_GET['showPic']) ? intval($_GET['showPic']) : null; |
||||
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); |
||||
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
||||
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); |
||||
$tbl_chat_connected = Database::get_course_table(TABLE_CHAT_CONNECTED); |
||||
|
||||
$query = "SELECT username FROM $tbl_user WHERE user_id='".$user_id."'"; |
||||
$result = Database::query($query); |
||||
|
||||
list($pseudo_user) = Database::fetch_array($result); |
||||
|
||||
$isAllowed = !(empty($pseudo_user) || !$_cid); |
||||
$isMaster = api_is_course_admin(); |
||||
$date_inter = api_get_utc_datetime(time() - 120); |
||||
|
||||
$users = array(); |
||||
$course_id = api_get_course_int_id(); |
||||
|
||||
if (empty($session_id)) { |
||||
$sql = "SELECT DISTINCT |
||||
t1.user_id, |
||||
username, |
||||
firstname, |
||||
lastname, |
||||
picture_uri, |
||||
email, |
||||
t3.status |
||||
FROM $tbl_user t1, $tbl_chat_connected t2, $tbl_course_user t3 |
||||
WHERE |
||||
t2.c_id = $course_id AND |
||||
t1.user_id=t2.user_id AND |
||||
t3.user_id=t2.user_id AND |
||||
t3.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND |
||||
t3.c_id = '".$courseInfo['real_id']."' AND |
||||
t2.last_connection>'".$date_inter."' $extra_condition |
||||
ORDER BY username"; |
||||
|
||||
$result = Database::query($sql); |
||||
$users = Database::store_result($result); |
||||
} else { |
||||
$session_condition = api_get_session_condition($session_id, true, false, 't3.session_id'); |
||||
// select learners |
||||
$query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email |
||||
FROM $tbl_user t1, $tbl_chat_connected t2, $tbl_session_course_user t3 |
||||
WHERE |
||||
t2.c_id = $course_id AND |
||||
t1.user_id=t2.user_id AND t3.user_id=t2.user_id AND |
||||
t3.session_id = '".$session_id."' AND |
||||
t3.c_id = '".$courseInfo['real_id']."' AND |
||||
t2.last_connection>'".$date_inter."' $session_condition |
||||
ORDER BY username"; |
||||
$result = Database::query($query); |
||||
while ($learner = Database::fetch_array($result)) { |
||||
$users[$learner['user_id']] = $learner; |
||||
} |
||||
|
||||
// select session coach |
||||
$query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email |
||||
FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session t3 |
||||
WHERE |
||||
t2.c_id = $course_id AND |
||||
t1.user_id=t2.user_id AND |
||||
t3.id_coach=t2.user_id AND |
||||
t3.id = '".$session_id."' AND |
||||
t2.last_connection > '".$date_inter."' |
||||
$extra_condition |
||||
ORDER BY username"; |
||||
$result = Database::query($query); |
||||
if ($coach = Database::fetch_array($result)) { |
||||
$users[$coach['user_id']] = $coach; |
||||
} |
||||
|
||||
// select session course coach |
||||
$query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email |
||||
FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session_course_user t3 |
||||
WHERE |
||||
t2.c_id = $course_id AND |
||||
t1.user_id=t2.user_id |
||||
AND t3.user_id =t2.user_id AND t3.status=2 |
||||
AND t3.session_id = '".$session_id."' |
||||
AND t3.c_id = '".$course_id."' |
||||
AND t2.last_connection>'".$date_inter."' $extra_condition |
||||
ORDER BY username"; |
||||
|
||||
$result = Database::query($query); |
||||
$course_coaches = array(); |
||||
while ($coaches = Database::fetch_array($result)) { |
||||
$users[$coaches['user_id']] = $coaches; |
||||
} |
||||
} |
||||
require 'header_frame.inc.php'; |
||||
|
||||
?> |
||||
<div class="user-connected"> |
||||
<div id="user-online-scroll" class="user-online"> |
||||
<div class="title"><?php echo get_lang('Users'); ?> <?php echo get_lang('Connected'); ?></div>
|
||||
<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div> |
||||
<div class="scrollbar-inner viewport"><div id="hidden" class="overview"> |
||||
<ul class="profile list-group"> |
||||
<?php |
||||
foreach ($users as & $user) { |
||||
if (empty($session_id)) { |
||||
$status = $user['status']; |
||||
} else { |
||||
$status = CourseManager::is_course_teacher($user['user_id'], api_get_course_id()) ? 1 : 5; |
||||
} |
||||
$fileUrl = UserManager::getUserPicture($user['user_id'], USER_IMAGE_SIZE_MEDIUM); |
||||
$url_user_profile=api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user['user_id'].'&'; |
||||
?> |
||||
<li class="list-group-item"> |
||||
<img src="<?php echo $fileUrl;?>" border="0" width="50" alt="" class="user-image-chat" />
|
||||
<div class="user-name"> |
||||
<a href="<?php echo $url_user_profile; ?>" target="_blank">
|
||||
<?php echo api_get_person_name($user['firstname'], $user['lastname']); ?> |
||||
</a> |
||||
<?php |
||||
if ($status == 1) { |
||||
echo Display::return_icon('teachers.gif', get_lang('Teacher'), array('height' => '18')); |
||||
} else { |
||||
echo Display::return_icon('students.gif', get_lang('Student'), array('height' => '18')); |
||||
} |
||||
?> |
||||
</div> |
||||
<div class="user-email"><?php echo $user['username']; ?></div>
|
||||
</li> |
||||
<?php |
||||
} |
||||
unset($users); |
||||
?> |
||||
</ul> |
||||
</div></div></div></div> |
||||
<?php |
||||
} |
||||
require 'footer_frame.inc.php'; |
@ -1,17 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Footer of each frame of the Chat tool |
||||
* |
||||
* @author Olivier Brouckaert |
||||
* @package chamilo.chat |
||||
*/ |
||||
?> |
||||
<audio id="audio"> |
||||
<source src="<?php echo api_get_path(WEB_PATH);?>main/chat/sound/notification.wav" type="audio/wav"></source>
|
||||
<source src="<?php echo api_get_path(WEB_PATH);?>main/chat/sound/notification.ogg" type="audio/ogg"></source>
|
||||
<source src="<?php echo api_get_path(WEB_PATH);?>main/chat/sound/notification.mp3" type="audio/mpeg"></source>
|
||||
</audio> |
||||
</body> |
||||
</html> |
File diff suppressed because one or more lines are too long
@ -0,0 +1,76 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Responses to AJAX calls for course chat |
||||
*/ |
||||
|
||||
require_once '../global.inc.php'; |
||||
|
||||
if (!api_protect_course_script(false)) { |
||||
exit; |
||||
} |
||||
|
||||
$courseId = api_get_course_int_id(); |
||||
$userId = api_get_user_id(); |
||||
$sessionId = api_get_session_id(); |
||||
$groupId = api_get_group_id(); |
||||
$json = ['status' => false]; |
||||
|
||||
$courseChatUtils = new CourseChatUtils($courseId, $userId, $sessionId, $groupId); |
||||
|
||||
switch ($_REQUEST['action']) { |
||||
case 'track': |
||||
$courseChatUtils->keepUserAsConnected(); |
||||
$courseChatUtils->disconnectInactiveUsers(); |
||||
|
||||
$friend = isset($_REQUEST['friend']) ? intval($_REQUEST['friend']) : 0; |
||||
$filePath = $courseChatUtils->getFileName(true, $friend); |
||||
$newFileSize = file_exists($filePath) ? filesize($filePath) : 0; |
||||
$oldFileSize = isset($_GET['size']) ? intval($_GET['size']) : -1; |
||||
$newUsersOnline = $courseChatUtils->countUsersOnline(); |
||||
$oldUsersOnline = isset($_GET['users_online']) ? intval($_GET['users_online']) : 0; |
||||
|
||||
$json = [ |
||||
'status' => true, |
||||
'data' => [ |
||||
'chatIsDenied' => $courseChatUtils->isChatDenied(), |
||||
'oldFileSize' => file_exists($filePath) ? filesize($filePath) : 0, |
||||
'history' => $newFileSize !== $oldFileSize ? $courseChatUtils->readMessages(false, $friend) : null, |
||||
'usersOnline' => $newUsersOnline, |
||||
'userList' => $newUsersOnline != $oldUsersOnline ? $courseChatUtils->listUsersOnline() : null, |
||||
'currentFriend' => $friend |
||||
] |
||||
]; |
||||
|
||||
break; |
||||
case 'preview': |
||||
$json = [ |
||||
'status' => true, |
||||
'data' => [ |
||||
'message' => CourseChatUtils::prepareMessage($_REQUEST['message']) |
||||
] |
||||
]; |
||||
break; |
||||
case 'reset': |
||||
$friend = isset($_REQUEST['friend']) ? intval($_REQUEST['friend']) : 0; |
||||
|
||||
$json = [ |
||||
'status' => true, |
||||
'data' => $courseChatUtils->readMessages(true, $friend) |
||||
]; |
||||
break; |
||||
case 'write': |
||||
$friend = isset($_REQUEST['friend']) ? intval($_REQUEST['friend']) : 0; |
||||
$writed = $courseChatUtils->saveMessage($_POST['message'], $friend); |
||||
|
||||
$json = [ |
||||
'status' => $writed, |
||||
'data' => [ |
||||
'writed' => $writed |
||||
] |
||||
]; |
||||
break; |
||||
} |
||||
|
||||
header('Content-Type: application/json'); |
||||
echo json_encode($json); |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,342 @@ |
||||
<div class="page-chat"> |
||||
<div class="row"> |
||||
<div class="col-sm-4 col-md-5 col-lg-4"> |
||||
<ul class="row list-unstyled" id="chat-users"></ul> |
||||
</div> |
||||
<div class="col-sm-8 col-md-7 col-lg-8"> |
||||
<div id="chat-tabs"> |
||||
<ul class="nav nav-tabs" role="tablist"> |
||||
<li role="presentation" class="active"> |
||||
<a href="#all" aria-controls="all" role="tab" data-toggle="tab">{{ 'All'|get_lang }}</a> |
||||
</li> |
||||
</ul> |
||||
<div class="tab-content"> |
||||
<div role="tabpanel" class="tab-pane active" id="all"> |
||||
<div class="course-chat chat-history" id="chat-history"></div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="profile row"> |
||||
<div class="col-xs-12"> |
||||
<div class="message-form-chat"> |
||||
<div class="tabbable"> |
||||
<ul class="nav nav-tabs"> |
||||
<li class="active"> |
||||
<a href="#tab1" data-toggle="tab">{{ 'Write'|get_lang }}</a> |
||||
</li> |
||||
<li> |
||||
<a href="#tab2" id="preview" data-toggle="tab">{{ 'Preview'|get_lang }}</a> |
||||
</li> |
||||
<li> |
||||
<button id="emojis" class="btn btn-link" type="button"> |
||||
<span class="sr-only">{{ 'Emoji'|get_lang }}</span>{{ emoji_smile }} |
||||
</button> |
||||
</li> |
||||
</ul> |
||||
<div class="tab-content"> |
||||
<div class="tab-pane active" id="tab1"> |
||||
<div class="row"> |
||||
<div class="col-sm-9"> |
||||
<span class="sr-only">{{ 'Message'|get_lang }}</span> |
||||
<textarea id="chat-writer" name="message"></textarea> |
||||
</div> |
||||
<div class="col-sm-3"> |
||||
<button id="chat-send-message" type="button" class="btn btn-primary">{{ 'Send'|get_lang }}</button> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="tab-pane" id="tab2"> |
||||
<div id="html-preview" class="emoji-wysiwyg-editor-preview"></div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<audio id="chat-alert"> |
||||
<source src="{{ _p.web_main }}/chat/sound/notification.wav" type="audio/wav"></source> |
||||
<source src="{{ _p.web_main }}chat/sound/notification.ogg" type="audio/ogg"></source> |
||||
<source src="{{ _p.web_main }}chat/sound/notification.mp3" type="audio/mpeg"></source> |
||||
</audio> |
||||
<script> |
||||
$(document).on('ready', function () { |
||||
var ChChat = { |
||||
_ajaxUrl: '{{ _p.web_ajax }}course_chat.ajax.php?{{ _p.web_cid_query }}', |
||||
_historySize: -1, |
||||
usersOnline: 0, |
||||
currentFriend: 0, |
||||
call: false, |
||||
track: function () { |
||||
return $ |
||||
.get(ChChat._ajaxUrl, { |
||||
action: 'track', |
||||
size: ChChat._historySize, |
||||
users_online: ChChat.usersOnline, |
||||
friend: ChChat.currentFriend |
||||
}) |
||||
.done(function (response) { |
||||
if (response.data.chatIsDenied) { |
||||
alert("{{ 'ChatDenied'|get_lang }}"); |
||||
|
||||
return; |
||||
} |
||||
|
||||
if (response.data.history) { |
||||
ChChat._historySize = response.data.oldFileSize; |
||||
ChChat.setHistory(response.data.history); |
||||
} |
||||
|
||||
if (response.data.userList) { |
||||
ChChat.usersOnline = response.data.usersOnline; |
||||
ChChat.setConnectedUsers(response.data.userList); |
||||
} |
||||
}); |
||||
}, |
||||
setHistory: function (messageList) { |
||||
var chatHistoryContainer = ChChat.currentFriend ? ('#chat-history-' + ChChat.currentFriend) : '#chat-history'; |
||||
|
||||
$(chatHistoryContainer) |
||||
.html(messageList) |
||||
.prop('scrollTop', function () { |
||||
return this.scrollHeight; |
||||
}); |
||||
|
||||
$('#chat-alert').get(0).play(); |
||||
}, |
||||
setConnectedUsers: function (userList) { |
||||
var html = ''; |
||||
|
||||
userList.forEach(function (user) { |
||||
var buttonStatus = user.isConnected ? 'success' : 'muted', |
||||
buttonTitle = user.isConnected ? '{{ 'StartAChat'|get_lang }}' : '{{ 'LeaveAMessage'|get_lang }}'; |
||||
|
||||
html += '<li class="col-xs-12 chat-user">' + |
||||
' <div>' + |
||||
' <img src="'+ user.image_url + '" alt="' + user.complete_name + '" class="img-circle user-image-chat"/>' + |
||||
' <ul class="list-unstyled">' + |
||||
' <li>' + user.complete_name; |
||||
|
||||
if (user.id != {{ _u.user_id }}) { |
||||
html += ' <button type="button" class="btn btn-link btn-xs" title="' + buttonTitle + '" data-name="' + user.complete_name + '" data-user="' + user.id + '">' + |
||||
' <i class="fa fa-comments text-' + buttonStatus + '"></i><span class="sr-only">' + buttonTitle + '</span>' + |
||||
' </button>'; |
||||
} |
||||
|
||||
html += ' </li>' + |
||||
' <li><small>' + user.username + '</small></li>' + |
||||
' </ul>' + |
||||
' </div>' + |
||||
'</li>'; |
||||
}); |
||||
|
||||
$('#chat-users').html(html); |
||||
}, |
||||
onPreviewListener: function () { |
||||
$ |
||||
.post(ChChat._ajaxUrl, { |
||||
action: 'preview', |
||||
'message': $('textarea#chat-writer').val() |
||||
}) |
||||
.done(function (response) { |
||||
if (!response.status) { |
||||
return; |
||||
} |
||||
|
||||
$('#html-preview').html(response.data.message); |
||||
}); |
||||
}, |
||||
onSendMessageListener: function (e) { |
||||
e.preventDefault(); |
||||
|
||||
if (!$('textarea#chat-writer').val().trim().length) { |
||||
return; |
||||
} |
||||
|
||||
var self = this; |
||||
self.disabled = true; |
||||
|
||||
$ |
||||
.post(ChChat._ajaxUrl, { |
||||
action: 'write', |
||||
message: $('textarea#chat-writer').val(), |
||||
friend: ChChat.currentFriend |
||||
}) |
||||
.done(function (response) { |
||||
self.disabled = false; |
||||
|
||||
if (!response.status) { |
||||
return; |
||||
} |
||||
|
||||
$('textarea#chat-writer').val(''); |
||||
$(".emoji-wysiwyg-editor").html(''); |
||||
}); |
||||
}, |
||||
onResetListener: function (e) { |
||||
if (!confirm("{{ 'ConfirmReset'|get_lang }}")) { |
||||
e.preventDefault(); |
||||
|
||||
return; |
||||
} |
||||
|
||||
$ |
||||
.get(ChChat._ajaxUrl, { |
||||
action: 'reset', |
||||
friend: ChChat.currentFriend |
||||
}) |
||||
.done(function (response) { |
||||
if (!response.status) { |
||||
return; |
||||
} |
||||
|
||||
ChChat.setHistory(response.data); |
||||
}); |
||||
}, |
||||
init: function () { |
||||
ChChat.track().done(function () { |
||||
ChChat.init(); |
||||
}); |
||||
} |
||||
}; |
||||
|
||||
hljs.initHighlightingOnLoad(); |
||||
|
||||
emojione.ascii = true; |
||||
emojione.imagePathPNG = '{{ _p.web_lib }}javascript/emojione/png/'; |
||||
emojione.imagePathSVG = '{{ _p.web_lib }}javascript/emojione/svg/'; |
||||
emojione.imagePathSVGSprites = '{{ _p.web_lib }}javascript/emojione/sprites/'; |
||||
|
||||
var emojiStrategy = {{ emoji_strategy|json_encode }}; |
||||
|
||||
$.emojiarea.path = '{{ _p.web_lib }}javascript/emojione/png/'; |
||||
$.emojiarea.icons = {{ icons|json_encode }}; |
||||
|
||||
$('body').on('click', '#chat-reset', ChChat.onResetListener); |
||||
|
||||
$('#preview').on('click', ChChat.onPreviewListener); |
||||
|
||||
$('#emojis').on('click', function () { |
||||
$('[data-toggle="tab"][href="#tab1"]') |
||||
.show() |
||||
.tab('show'); |
||||
}); |
||||
|
||||
$('textarea#chat-writer').emojiarea({ |
||||
button: '#emojis' |
||||
}); |
||||
|
||||
$('body').delay(1500).find('.emoji-wysiwyg-editor').textcomplete([ |
||||
{ |
||||
match: /\B:([\-+\w]*)$/, |
||||
search: function (term, callback) { |
||||
var results = []; |
||||
var results2 = []; |
||||
var results3 = []; |
||||
$.each(emojiStrategy, function (shortname, data) { |
||||
if (shortname.indexOf(term) > -1) { |
||||
results.push(shortname); |
||||
} else { |
||||
if ((data.aliases !== null) && (data.aliases.indexOf(term) > -1)) { |
||||
results2.push(shortname); |
||||
} else if ((data.keywords !== null) && (data.keywords.indexOf(term) > -1)) { |
||||
results3.push(shortname); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
if (term.length >= 3) { |
||||
results.sort(function (a, b) { |
||||
return (a.length > b.length); |
||||
}); |
||||
results2.sort(function (a, b) { |
||||
return (a.length > b.length); |
||||
}); |
||||
results3.sort(); |
||||
} |
||||
|
||||
var newResults = results.concat(results2).concat(results3); |
||||
|
||||
callback(newResults); |
||||
}, |
||||
template: function (shortname) { |
||||
return '<img class="emojione" src="{{ _p.web_lib }}javascript/emojione/png/' |
||||
+ emojiStrategy[shortname].unicode |
||||
+ '.png"> :' + shortname + ':'; |
||||
}, |
||||
replace: function (shortname) { |
||||
return ':' + shortname + ': '; |
||||
}, |
||||
index: 1, |
||||
maxCount: 10 |
||||
} |
||||
], {}); |
||||
|
||||
$('button#chat-send-message').on('click', ChChat.onSendMessageListener); |
||||
|
||||
$('#chat-users').on('click', 'button.btn', function (e) { |
||||
e.preventDefault(); |
||||
|
||||
var jSelf = $(this), |
||||
userId = parseInt(jSelf.data('user')) || 0; |
||||
|
||||
if (!userId) { |
||||
return; |
||||
} |
||||
|
||||
var exists = false; |
||||
|
||||
$('#chat-tabs ul.nav li').each(function (i, el) { |
||||
if ($(el).data('user') == userId) { |
||||
exists = true; |
||||
} |
||||
}); |
||||
|
||||
if (exists) { |
||||
$('#chat-tab-' + userId).tab('show'); |
||||
|
||||
return; |
||||
} |
||||
|
||||
$('#chat-tabs ul.nav-tabs').append('\ |
||||
<li role="presentation" data-user="' + userId + '">\ |
||||
<a id="chat-tab-' + userId + '" href="#chat-' + userId + '" aria-controls="chat-' + userId + '" role="tab" data-toggle="tab">' + jSelf.data('name') + '</a>\ |
||||
</li>\ |
||||
'); |
||||
|
||||
$('#chat-tabs .tab-content').append('\ |
||||
<div role="tabpanel" class="tab-pane" id="chat-' + userId + '">\ |
||||
<div class="course-chat chat-history" id="chat-history-' + userId + '"></div>\ |
||||
</div>\ |
||||
'); |
||||
|
||||
$('#chat-tab-' + userId).tab('show'); |
||||
}); |
||||
|
||||
$('#chat-tabs ul.nav-tabs').on('shown.bs.tab', 'li a', function (e) { |
||||
var jSelf = $(this); |
||||
|
||||
var userId = parseInt(jSelf.parent().data('user')) || 0; |
||||
|
||||
if (!userId) { |
||||
ChChat.currentFriend = 0; |
||||
|
||||
return; |
||||
} |
||||
|
||||
ChChat.currentFriend = userId; |
||||
|
||||
$(this).tab('show'); |
||||
}); |
||||
|
||||
$('.emoji-wysiwyg-editor').on('keyup', function (e) { |
||||
if (e.ctrlKey && e.keyCode === 13) { |
||||
$('button#chat-send-message').trigger('click'); |
||||
} |
||||
}); |
||||
|
||||
ChChat.init(); |
||||
}); |
||||
</script> |
Loading…
Reference in new issue