implemented - The Chat tool is now private when are in sessions or groups - DT#5558

skala
Cristian Fasanando 15 years ago
parent bb3f8a437b
commit e3152401c4
  1. 44
      main/chat/chat_chat.php
  2. 35
      main/chat/chat_functions.lib.php
  3. 20
      main/chat/chat_hidden.php
  4. 25
      main/chat/chat_message.php
  5. 21
      main/chat/chat_whoisonline.php
  6. 5
      main/inc/lib/add_course.lib.inc.php
  7. 2
      main/install/migrate-db-1.8.6.1-1.8.6.2-pre.sql

@ -39,6 +39,8 @@ include (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
//$course=api_get_course_id();
$course=$_GET['cidReq'];
$session_id = intval($_SESSION['id_session']);
$group_id = intval($_SESSION['_gid']);
// if we have the session set up
if (!empty($course))
@ -77,40 +79,58 @@ if (!empty($course))
}
}
if(!file_exists($chatPath.'messages-'.$dateNow.'.log.html'))
$filename_chat = '';
if (!empty($group_id)) {
$filename_chat = 'messages-'.$dateNow.'_gid-'.$group_id.'.log.html';
} else if (!empty($session_id)) {
$filename_chat = 'messages-'.$dateNow.'_sid-'.$session_id.'.log.html';
} else {
$filename_chat = 'messages-'.$dateNow.'.log.html';
}
if(!file_exists($chatPath.$filename_chat))
{
@fclose(fopen($chatPath.'messages-'.$dateNow.'.log.html','w'));
@fclose(fopen($chatPath.$filename_chat,'w'));
if (!api_is_anonymous()) {
$doc_id=add_document($_course,'/chat_files/messages-'.$dateNow.'.log.html','file',0,'messages-'.$dateNow.'.log.html');
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id']);
$doc_id=add_document($_course,'/chat_files/'.$filename_chat,'file',0,$filename_chat);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'],$group_id,null,null,null,$session_id);
item_property_update_on_folder($_course,'/chat_files', $_user['user_id']);
}
}
$basename_chat = '';
if (!empty($group_id)) {
$basename_chat = 'messages-'.$dateNow.'_gid-'.$group_id;
} else if (!empty($session_id)) {
$basename_chat = 'messages-'.$dateNow.'_sid-'.$session_id;
} else {
$basename_chat = 'messages-'.$dateNow;
}
if($reset && $isMaster)
{
$i=1;
while(file_exists($chatPath.'messages-'.$dateNow.'-'.$i.'.log.html'))
$i=1;
while(file_exists($chatPath.$basename_chat.'-'.$i.'.log.html'))
{
$i++;
}
@rename($chatPath.'messages-'.$dateNow.'.log.html',$chatPath.'messages-'.$dateNow.'-'.$i.'.log.html');
@rename($chatPath.$basename_chat.'.log.html',$chatPath.$basename_chat.'-'.$i.'.log.html');
@fclose(fopen($chatPath.'messages-'.$dateNow.'.log.html','w'));
@fclose(fopen($chatPath.$basename_chat.'.log.html','w'));
$doc_id=add_document($_course,'/chat_files/messages-'.$dateNow.'-'.$i.'.log.html','file',filesize($chatPath.'messages-'.$dateNow.'-'.$i.'.log.html'),'messages-'.$dateNow.'-'.$i.'.log.html');
$doc_id=add_document($_course,'/chat_files/'.$basename_chat.'-'.$i.'.log.html','file',filesize($chatPath.$basename_chat.'-'.$i.'.log.html'),$basename_chat.'-'.$i.'.log.html');
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id']);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'],$group_id,null,null,null,$session_id);
item_property_update_on_folder($_course,'/chat_files', $_user['user_id']);
$doc_id = DocumentManager::get_document_id($_course,'/chat_files/messages-'.$dateNow.'.log.html');
$doc_id = DocumentManager::get_document_id($_course,'/chat_files/'.$basename_chat.'.log.html');
update_existing_document($_course, $doc_id,0);
}
$content=file($chatPath.'messages-'.$dateNow.'.log.html');
$content=file($chatPath.$basename_chat.'.log.html');
$nbr_lines=sizeof($content);
$remove=$nbr_lines-100;

@ -30,11 +30,18 @@
function exit_of_chat ($user_id) {
$list_course=array();
$list_course=CourseManager::get_courses_list_by_user_id($user_id);
$group_id = intval($_SESSION['_gid']);
$session_id = intval($_SESSION['id_session']);
$extra_condition = '';
if (!empty($group_id)) $extra_condition = " AND to_group_id = '$group_id'";
else $extra_condition = api_get_session_condition($session_id);
foreach($list_course as $courses) {
$response=user_connected_in_chat($user_id,$courses['db_name']);
if ($response===true) {
$tbl_chat_connected = Database::get_course_chat_connected_table($courses['db_name']);;
$sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$user_id;
$sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$user_id.$extra_condition;
Database::query($sql,__FILE__,__LINE__);
}
}
@ -48,7 +55,14 @@ function exit_of_chat ($user_id) {
*/
function user_connected_in_chat ($user_id,$database_name) {
$tbl_chat_connected = Database::get_course_chat_connected_table($database_name);
$sql='SELECT COUNT(*) AS count FROM '.$tbl_chat_connected .' c WHERE user_id='.$user_id;
$group_id = intval($_SESSION['_gid']);
$session_id = intval($_SESSION['id_session']);
$extra_condition = '';
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 user_id='.$user_id.$extra_condition;
$result = Database::query($sql,__FILE__,__LINE__);
$count = Database::fetch_array($result,'ASSOC');
if (1==$count['count']) {
@ -71,6 +85,12 @@ function disconnect_user_of_chat () {
$cdate_s = date('s',time());
$cd_count_time_seconds=$cdate_h*3600 + $cdate_m*60 + $cdate_s;
$group_id = intval($_SESSION['_gid']);
$session_id = intval($_SESSION['id_session']);
$extra_condition = '';
if (!empty($group_id)) $extra_condition = " AND to_group_id = '$group_id'";
else $extra_condition = api_get_session_condition($session_id);
foreach ($list_info_user_in_chat as $list_info_user) {
$date_db_date = date('Y-m-d',strtotime($list_info_user['last_connection']));
$date_db_h = date('H',strtotime($list_info_user['last_connection']));
@ -80,7 +100,7 @@ function disconnect_user_of_chat () {
if ($cd_date==$date_db_date) {
if (($cd_count_time_seconds - $date_count_time_seconds)>10) {
$tbl_chat_connected = Database::get_course_chat_connected_table();
$sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$list_info_user['user_id'];
$sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$list_info_user['user_id'].$extra_condition;
Database::query($sql,__FILE__,__LINE__);
}
}
@ -96,7 +116,14 @@ function disconnect_user_of_chat () {
function users_list_in_chat () {
$list_users_in_chat=array();
$tbl_chat_connected = Database::get_course_chat_connected_table();
$sql='SELECT user_id,last_connection FROM '.$tbl_chat_connected.' ;';
$group_id = intval($_SESSION['_gid']);
$session_id = intval($_SESSION['id_session']);
$extra_condition = '';
if (!empty($group_id)) $extra_condition = " WHERE to_group_id = '$group_id'";
else $extra_condition = api_get_session_condition($session_id,false);
$sql='SELECT user_id,last_connection FROM '.$tbl_chat_connected.$extra_condition;
$result=Database::query($sql,__FILE__,__LINE__);
while ($row = Database::fetch_array($result,'ASSOC')) {
$list_users_in_chat[]=$row;

@ -57,26 +57,38 @@ $isMaster=$is_courseAdmin?true:false;
$dateNow=date('Y-m-d');
$group_id = intval($_SESSION['_gid']);
$session_id = intval($_SESSION['id_session']);
$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;
}
$documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
$chatPath=$documentPath.'chat_files/';
$chat_size_old=intval($_POST['chat_size_old']);
$chat_size_new=filesize($chatPath.'messages-'.$dateNow.'.log.html');
$sql="SELECT user_id FROM $tbl_chat_connected WHERE user_id='".$_user['user_id']."'";
$sql="SELECT user_id FROM $tbl_chat_connected WHERE user_id='".$_user['user_id']."' $extra_condition";
$result=Database::query($sql);
//The user_id exists so we must do an UPDATE and not a INSERT
$current_time=date('Y-m-d H:i:s');
if (Database::num_rows($result)==0) {
$query="INSERT INTO $tbl_chat_connected(user_id,last_connection) VALUES('".$_user['user_id']."','".$current_time."')";
$query="INSERT INTO $tbl_chat_connected(user_id,last_connection,session_id,to_group_id) VALUES('".$_user['user_id']."','$current_time','$session_id','$group_id')";
} else {
$query="UPDATE $tbl_chat_connected set last_connection='".$current_time."' WHERE user_id='".$_user['user_id']."'";
$query="UPDATE $tbl_chat_connected set last_connection='".$current_time."' WHERE user_id='".$_user['user_id']."' AND session_id='$session_id' AND to_group_id='$group_id'";
}
Database::query($query,__FILE__,__LINE__);
$query="SELECT COUNT(user_id) FROM $tbl_chat_connected WHERE last_connection>'".date('Y-m-d H:i:s',time()-60*5)."'";
$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,__FILE__,__LINE__);
$connected_old=intval($_POST['connected_old']);

@ -43,6 +43,8 @@ $language_file = array ('chat');
require('../inc/global.inc.php');
$course=api_get_course_id();
$session_id = intval($_SESSION['id_session']);
$group_id = intval($_SESSION['_gid']);
/////
// Juan Carlos Ra<EFBFBD>a insert smileys and self-closing window
@ -222,28 +224,35 @@ if (!empty($course) && !empty($_user['user_id']))
$message=str_replace($emoticon_text203, $emoticon_img203, $message);
$message=str_replace($emoticon_text204, $emoticon_img204, $message);
$timeNow=date('d/m/y H:i:s');
$basename_chat = '';
if (!empty($group_id)) {
$basename_chat = 'messages-'.$dateNow.'_gid-'.$group_id;
} else if (!empty($session_id)) {
$basename_chat = 'messages-'.$dateNow.'_sid-'.$session_id;
} else {
$basename_chat = 'messages-'.$dateNow;
}
$timeNow=date('d/m/y H:i:s');
if (!api_is_anonymous()) {
if(!empty($message))
{
$message=make_clickable($message);
if(!file_exists($chatPath.'messages-'.$dateNow.'.log.html'))
if(!file_exists($chatPath.$basename_chat.'.log.html'))
{
$doc_id=add_document($_course,'/chat_files/messages-'.$dateNow.'.log.html','file',0,'messages-'.$dateNow.'.log.html');
$doc_id=add_document($_course,'/chat_files/'.$basename_chat.'.log.html','file',0,$basename_chat.'.log.html');
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id']);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'],$group_id,null,null,null,$session_id);
item_property_update_on_folder($_course,'/chat_files', $_user['user_id']);
}
else
{
$doc_id = DocumentManager::get_document_id($_course,'/chat_files/messages-'.$dateNow.'.log.html');
$doc_id = DocumentManager::get_document_id($_course,'/chat_files/'.$basename_chat.'.log.html');
}
$fp=fopen($chatPath.'messages-'.$dateNow.'.log.html','a');
$fp=fopen($chatPath.$basename_chat.'.log.html','a');
if($isMaster)
{
@ -259,7 +268,7 @@ if (!empty($course) && !empty($_user['user_id']))
fclose($fp);
$chat_size=filesize($chatPath.'messages-'.$dateNow.'.log.html');
$chat_size=filesize($chatPath.$basename_chat.'.log.html');
update_existing_document($_course, $doc_id,$chat_size);
item_property_update_on_folder($_course,'/chat_files', $_user['user_id']);

@ -36,7 +36,18 @@ include('../inc/global.inc.php');
include('../inc/lib/course.lib.php');
include('../inc/lib/usermanager.lib.php');
$course=api_get_course_id();
$course = api_get_course_id();
$group_id = intval($_SESSION['_gid']);
$session_id = intval($_SESSION['id_session']);
$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;
}
if (!empty($course))
{
@ -62,14 +73,14 @@ if (!empty($course))
if(!isset($_SESSION['id_session']))
{
$query="SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,t3.status FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_course_user t3 WHERE t1.user_id=t2.user_id AND t3.user_id=t2.user_id AND t3.course_code = '".$_course['sysCode']."' AND t2.last_connection>'".$date_inter."' ORDER BY username";
$query="SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,t3.status FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_course_user t3 WHERE t1.user_id=t2.user_id AND t3.user_id=t2.user_id AND t3.course_code = '".$_course['sysCode']."' AND t2.last_connection>'".$date_inter."' $extra_condition ORDER BY username";
$result=Database::query($query,__FILE__,__LINE__);
$Users=Database::store_result($result);
}
else
{
// select learners
$query="SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session_course_user t3 WHERE t1.user_id=t2.user_id AND t3.id_user=t2.user_id AND t3.id_session = '".$_SESSION['id_session']."' AND t3.course_code = '".$_course['sysCode']."' AND t2.last_connection>'".$date_inter."' ORDER BY username";
$query="SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session_course_user t3 WHERE t1.user_id=t2.user_id AND t3.id_user=t2.user_id AND t3.id_session = '".$_SESSION['id_session']."' AND t3.course_code = '".$_course['sysCode']."' AND t2.last_connection>'".$date_inter."' $extra_condition ORDER BY username";
$result=Database::query($query,__FILE__,__LINE__);
while($learner = Database::fetch_array($result))
{
@ -77,7 +88,7 @@ if (!empty($course))
}
// select session coach
$query="SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session t3 WHERE t1.user_id=t2.user_id AND t3.id_coach=t2.user_id AND t3.id = '".$_SESSION['id_session']."' AND t2.last_connection>'".$date_inter."' ORDER BY username";
$query="SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session t3 WHERE t1.user_id=t2.user_id AND t3.id_coach=t2.user_id AND t3.id = '".$_SESSION['id_session']."' AND t2.last_connection>'".$date_inter."' $extra_condition ORDER BY username";
$result=Database::query($query,__FILE__,__LINE__);
if($coach = Database::fetch_array($result))
$Users[$coach['user_id']] = $coach;
@ -89,7 +100,7 @@ if (!empty($course))
AND t3.id_user=t2.user_id AND t3.status=2
AND t3.id_session = '".$_SESSION['id_session']."'
AND t3.course_code = '".$_course['sysCode']."'
AND t2.last_connection>'".$date_inter."' ORDER BY username";
AND t2.last_connection>'".$date_inter."' $extra_condition ORDER BY username";
$result=Database::query($query,__FILE__,__LINE__);
$course_coachs = array();

@ -982,10 +982,13 @@ function update_Db_course($courseDbName)
CREATE TABLE `".$TABLETOOLCHATCONNECTED . "` (
user_id int unsigned NOT NULL default '0',
last_connection datetime NOT NULL default '0000-00-00 00:00:00',
session_id smallint NOT NULL default 0,
to_group_id INT NOT NULL default 0,
PRIMARY KEY (user_id)
)";
Database::query($sql, __FILE__, __LINE__);
$sql = "ALTER TABLE `".$TABLETOOLCHATCONNECTED . "` ADD INDEX ( session_id ) ";
Database::query($sql, __FILE__, __LINE__);
/*
-----------------------------------------------------------
Groups tool

@ -62,3 +62,5 @@ ALTER TABLE group_category ADD COLUMN chat_state TINYINT DEFAULT 1, ADD INDEX (c
ALTER TABLE student_publication ADD COLUMN weight float(6,2) UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE course_description ADD COLUMN description_type TINYINT NOT NULL DEFAULT 0;
ALTER TABLE dropbox_category ADD COLUMN session_id smallint NOT NULL DEFAULT 0, ADD INDEX (session_id);
ALTER TABLE chat_connected ADD COLUMN session_id smallint NOT NULL DEFAULT 0, ADD INDEX (session_id);
ALTER TABLE chat_connected ADD COLUMN to_group_id INT NOT NULL DEFAULT 0;
Loading…
Cancel
Save