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#11284
ofaj
Angel Fernando Quiroz Campos 9 years ago
parent d4cbcec037
commit f9ffa0fccf
  1. 204
      app/Resources/public/css/chat.css
  2. 1
      index.php
  3. 112
      main/chat/chat.php
  4. 217
      main/chat/chat_chat.php
  5. 242
      main/chat/chat_functions.lib.php
  6. 130
      main/chat/chat_hidden.php
  7. 128
      main/chat/chat_message.php
  8. 162
      main/chat/chat_whoisonline.php
  9. 17
      main/chat/footer_frame.inc.php
  10. 272
      main/chat/header_frame.inc.php
  11. 12
      main/inc/ajax/chat.ajax.php
  12. 76
      main/inc/ajax/course_chat.ajax.php
  13. 1843
      main/inc/lib/CourseChatUtils.php
  14. 2
      main/inc/lib/document.lib.php
  15. 1968
      main/inc/lib/javascript/jquery-textcomplete/jquery.textcomplete.js
  16. 7
      main/inc/lib/javascript/jquery-textcomplete/jquery.textcomplete.min.js
  17. 2
      main/inc/lib/javascript/jquery-textcomplete/jquery.textcomplete.min.map
  18. 3
      main/inc/lib/online.inc.php
  19. 342
      main/template/default/chat/chat.tpl
  20. 44
      tests/main/chat/chat_functions.lib.test.php

@ -1,13 +1,5 @@
body{
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 13px;
line-height: 18px;
color: #333333;
margin: 0;
padding: 0;
}
.page-chat{
padding: 10px;
padding: 10px 0;
background:#ffffff;
}
.message-form-chat .nav{
@ -16,48 +8,7 @@ body{
.message-form-chat .nav-tabs .active a{
background-color: #f6f6f6;
}
#clear-chat{
width:140px;
padding: 13px;
font-size: 14px;
float:right;
}
#clear-chat img{
width: 20px;
float: left;
margin-right: 5px;
}
#clear-chat a{
text-decoration: none;
}
#clear-chat a:hover{
opacity: 0.7;
}
#content-chat{
background:#ffffff;
padding: 30px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
textarea {
width: 52%;
padding: 3%;
height: 100px;
float: left;
border: 0;
background-color: #ffffff;
font-family: Helvetica, arial, sans-serif;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
border: 1px solid #EEEEEE;
color: #666;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35) inset;
}
.message-student .chat-image, .message-teacher .chat-image{
width: 80px;
height: auto;
@ -85,7 +36,7 @@ textarea {
font-size: 13px;
padding: 15px;
vertical-align: top;
width: 310px;
width: calc(100% - 100px);
}
.message-teacher .icon-message{
display: inline-block;
@ -121,7 +72,7 @@ textarea {
font-size: 13px;
padding: 15px;
vertical-align: top;
width: 360px;
width: calc(100% - 100px);
}
.message-teacher .message-date{
color: #666;
@ -138,121 +89,30 @@ textarea {
text-align: right;
margin-top: 10px;
}
.user-online .profile{
list-style: none;
padding: 0;
margin:0;
}
.chat-message-block-name {
font-style: italic;
color: #666;
}
.user-online .profile li{
margin-bottom: 5px;
}
.user-online .profile li a{
color: #0088AA;
text-decoration: none;
}
.user-online .title{
background: url(chat.png) no-repeat 0 center;
color: #0088AA;
padding-top: 5px;
padding-left: 30px;
font-weight: bold;
font-size: 16px;
margin-bottom: 15px;
width: 90%;
}
.delete-chat{
background: #F8F8F8;
padding-bottom: 15px;
}
.list-group {
margin-bottom: 20px;
padding-left: 0;
}
.list-group-item {
position: relative;
display: block;
padding-top: 5px;
padding-bottom: 10px;
padding-left: 10px;
padding-right: 10px;
margin-bottom: -1px;
background-color: #EEEEEE;
border: 1px solid #E2E2E2;
-webkit-border-radius: 10px;
.chat-user {
background-color: #EEEEEE;
border: 1px solid #E2E2E2;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
color: #666;
margin-bottom: -1px;
padding: 10px;
}
.user-connected{
border-right: 1px dashed #cccccc;
margin-right: 5px;
}
li.list-group-item:hover, li.list-group-item:focus {
text-decoration: none;
background-color: #E2E2E2;
cursor: pointer;
border: 1px solid #EEEEEE;
}
li.list-group-item:hover a{
color: #000;
}
.user-image-chat{
width: 40px;
height: auto;
max-height: 40px;
display: inline-block;
vertical-align: top;
-webkit-border-radius: 10px;
.chat-user .user-image-chat {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border: 2px solid #FFF;
border-radius: 10px;
border:2px solid #ffffff;
display: inline-block;
height: auto;
margin-right: 10px;
max-height: 40px;
float: left;
margin-right: 5px;
}
.noSelect {
user-select: none;
-o-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
}
.btn-send {
background: #87e0fd; /* Old browsers */
background: -moz-linear-gradient(top, #87e0fd 0%, #53cbf1 40%, #05abe0 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#87e0fd), color-stop(40%,#53cbf1), color-stop(100%,#05abe0)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%); /* IE10+ */
background: linear-gradient(to bottom, #87e0fd 0%,#53cbf1 40%,#05abe0 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#87e0fd', endColorstr='#05abe0',GradientType=0 ); /* IE6-9 */
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border:1px solid #53cbf1;
display:inline-block;
color:#ffffff;
font-family:Arial;
font-size:22px;
font-weight:bold;
font-style:normal;
height:80px;
line-height:80px;
width:131px;
text-decoration:none;
text-align:center;
cursor: pointer;
}
.btn-send:hover {
opacity: 0.8;
}
.btn-send:active {
position:relative;
top:1px;
width: 40px;
}
.emoticons-chat img{
width: 24px;
border: none;
@ -267,21 +127,17 @@ li.list-group-item:hover a{
}
.emoji-menu {
margin-left: 0px;
width:468px;
left: 11px !important;
margin-left: -234px;
margin-top: -224px;
width: 468px;
}
.emoji-wysiwyg-editor-preview,
.emoji-wysiwyg-editor {
width: 454px;
padding: 3%;
height: 50px;
float: left;
border: 0;
background-color: #ffffff;
font-family: Helvetica, arial, sans-serif;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
@ -289,3 +145,19 @@ li.list-group-item:hover a{
color: #666;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35) inset;
}
#chat-tabs .tab-content{
margin-top: 15px;
}
.chat-history {
height: 400px;
overflow: auto;
}
#chat-users {
margin-left: 0;
}
#chat-users div.chat-user > div {
padding: 5px;
}

@ -14,7 +14,6 @@ define('CHAMILO_LOAD_WYSIWYG', false);
$cidReset = true;
require_once 'main/inc/global.inc.php';
require_once 'main/chat/chat_functions.lib.php';
//require_once 'main/auth/external_login/facebook.inc.php';
// The section (for the tabs).

@ -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;">&nbsp;</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

@ -17,16 +17,8 @@ if (api_is_anonymous()) {
// Course Chat
if ($action == 'preview') {
require_once api_get_path(SYS_CODE_PATH).'chat/chat_functions.lib.php';
echo saveMessage(
$_REQUEST['message'],
api_get_user_id(),
api_get_course_info(),
api_get_session_id(),
api_get_group_id(),
true
);
echo CourseChatUtils::prepareMessage($_REQUEST['message']);
exit;
}
if (api_get_setting('allow_global_chat') == 'false') {

@ -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

@ -517,7 +517,7 @@ class DocumentManager
if (!empty($sessionId)) {
// Chat folder filter
if ($path == '/chat_files') {
$condition .= " AND (id_session = '$sessionId') ";
$condition .= " AND (docs.session_id = '$sessionId') ";
}
// share_folder filter
$condition .= " AND docs.path != '/shared_folder' ";

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -149,8 +149,7 @@ function online_logout($user_id = null, $logout_redirect = false)
}
}
require_once api_get_path(SYS_PATH) . 'main/chat/chat_functions.lib.php';
exit_of_chat($user_id);
CourseChatUtils::exitChat($user_id);
session_regenerate_id();
Session::destroy();
if ($logout_redirect) {

@ -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>

@ -1,5 +1,4 @@
<?php
require_once(api_get_path(SYS_CODE_PATH).'chat/chat_functions.lib.php');
require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
class TestChatFunctions extends UnitTestCase {
@ -16,25 +15,6 @@ class TestChatFunctions extends UnitTestCase {
$this->tcourse = null;
}
function testuser_connected_in_chat () {
$course_code = 'COURSETEST';
$user_id = 1;
$res = user_connected_in_chat($user_id);
$this->assertTrue(is_bool($res));
}
function testUsersListInChat () {
$course_code = 'COURSETEST';
$course_info = api_get_course_info($course_code);
$database_name = $course_info['dbName'];
$res = users_list_in_chat($database_name);
$this->assertTrue(is_array($res));
//var_dump($res);
}
function CreateChatConnection($database_name) {
$session_id = 1;
$tbl_chat_connected = Database::get_main_table(TABLE_MAIN_CHAT);
@ -51,29 +31,5 @@ class TestChatFunctions extends UnitTestCase {
}
Database::query($query);
}
function testExitOfChat () {
$course_code = 'COURSETEST';
$course_info = api_get_course_info($course_code);
$database_name = $course_info['dbName'];
$this->CreateChatConnection($database_name);
$user_id = 1;
$res = exit_of_chat($user_id);
//$resu = $this->tcourse->delete_course($course_code);
$this->assertTrue(is_null($res));
//var_dump($res);
}
function testDisconnectUserOfChat() {
$_SESSION['is_courseAdmin'] = 1;
$course_code = 'COURSETEST';
$course_info = api_get_course_info($course_code);
$database_name = $course_info['dbName'];
$this->CreateChatConnection($database_name);
$res = disconnect_user_of_chat($database_name);
$this->assertTrue(is_null($res));
}
}
?>

Loading…
Cancel
Save