diff --git a/main/chat/chat_functions.lib.php b/main/chat/chat_functions.lib.php index fc75e473cb..f824378097 100644 --- a/main/chat/chat_functions.lib.php +++ b/main/chat/chat_functions.lib.php @@ -30,18 +30,12 @@ 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.$extra_condition; + $sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$user_id; Database::query($sql,__FILE__,__LINE__); } } @@ -55,14 +49,8 @@ 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); - - $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; + + $sql='SELECT COUNT(*) AS count FROM '.$tbl_chat_connected .' c WHERE user_id='.$user_id; $result = Database::query($sql,__FILE__,__LINE__); $count = Database::fetch_array($result,'ASSOC'); if (1==$count['count']) { @@ -84,13 +72,7 @@ function disconnect_user_of_chat () { $cdate_m = date('i',time()); $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'])); @@ -98,9 +80,9 @@ function disconnect_user_of_chat () { $date_db_s = date('s',strtotime($list_info_user['last_connection'])); $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)>10) { + if (($cd_count_time_seconds - $date_count_time_seconds)>5) { $tbl_chat_connected = Database::get_course_chat_connected_table(); - $sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$list_info_user['user_id'].$extra_condition; + $sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$list_info_user['user_id']; Database::query($sql,__FILE__,__LINE__); } } @@ -116,14 +98,8 @@ function disconnect_user_of_chat () { function users_list_in_chat () { $list_users_in_chat=array(); $tbl_chat_connected = Database::get_course_chat_connected_table(); - - $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; + + $sql='SELECT user_id,last_connection FROM '.$tbl_chat_connected; $result=Database::query($sql,__FILE__,__LINE__); while ($row = Database::fetch_array($result,'ASSOC')) { $list_users_in_chat[]=$row; diff --git a/main/chat/chat_hidden.php b/main/chat/chat_hidden.php index 814a01f64b..d799741526 100755 --- a/main/chat/chat_hidden.php +++ b/main/chat/chat_hidden.php @@ -84,7 +84,7 @@ if (!empty($group_id)) { $chat_size_old=intval($_POST['chat_size_old']); $chat_size_new=filesize($chatPath.$basename_chat.'.log.html'); -$sql="SELECT user_id FROM $tbl_chat_connected WHERE user_id='".$_user['user_id']."' $extra_condition"; +$sql="SELECT user_id FROM $tbl_chat_connected WHERE user_id='".$_user['user_id']."'"; $result=Database::query($sql); //The user_id exists so we must do an UPDATE and not a INSERT