|
|
|
@ -30,7 +30,7 @@ |
|
|
|
|
function exit_of_chat ($user_id) { |
|
|
|
|
$list_course=array(); |
|
|
|
|
$list_course=CourseManager::get_courses_list_by_user_id($user_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$group_id = intval($_SESSION['id_group']); |
|
|
|
|
$session_id = intval($_SESSION['id_session']); |
|
|
|
|
$extra_condition = ''; |
|
|
|
@ -40,7 +40,7 @@ function exit_of_chat ($user_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']);; |
|
|
|
|
$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; |
|
|
|
|
Database::query($sql,__FILE__,__LINE__); |
|
|
|
|
} |
|
|
|
@ -75,9 +75,15 @@ function user_connected_in_chat ($user_id,$database_name) { |
|
|
|
|
* @param void |
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
function disconnect_user_of_chat () { |
|
|
|
|
function disconnect_user_of_chat($database_name='') { |
|
|
|
|
|
|
|
|
|
$list_info_user_in_chat = array(); |
|
|
|
|
$list_info_user_in_chat = users_list_in_chat (); |
|
|
|
|
|
|
|
|
|
if (!empty($database_name)) { |
|
|
|
|
$list_info_user_in_chat = users_list_in_chat($database_name); |
|
|
|
|
} else { |
|
|
|
|
$list_info_user_in_chat = users_list_in_chat(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$cd_date = date('Y-m-d',time()); |
|
|
|
|
$cdate_h = date('H',time()); |
|
|
|
@ -85,37 +91,44 @@ function disconnect_user_of_chat () { |
|
|
|
|
$cdate_s = date('s',time()); |
|
|
|
|
$cd_count_time_seconds=$cdate_h*3600 + $cdate_m*60 + $cdate_s; |
|
|
|
|
|
|
|
|
|
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'])); |
|
|
|
|
$date_db_m = date('i',strtotime($list_info_user['last_connection'])); |
|
|
|
|
$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)>5) { |
|
|
|
|
$tbl_chat_connected = Database::get_course_chat_connected_table(); |
|
|
|
|
$sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$list_info_user['user_id']; |
|
|
|
|
Database::query($sql,__FILE__,__LINE__); |
|
|
|
|
|
|
|
|
|
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',strtotime($list_info_user['last_connection'])); |
|
|
|
|
$date_db_h = date('H',strtotime($list_info_user['last_connection'])); |
|
|
|
|
$date_db_m = date('i',strtotime($list_info_user['last_connection'])); |
|
|
|
|
$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)>5) { |
|
|
|
|
|
|
|
|
|
$tbl_chat_connected = Database::get_course_chat_connected_table(); |
|
|
|
|
if (!empty($database_name)) { |
|
|
|
|
$tbl_chat_connected = Database::get_course_chat_connected_table($database_name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$list_info_user['user_id']; |
|
|
|
|
//return $sql; |
|
|
|
|
Database::query($sql,__FILE__,__LINE__); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param void |
|
|
|
|
* @return array user list in chat |
|
|
|
|
*/ |
|
|
|
|
function users_list_in_chat () { |
|
|
|
|
function users_list_in_chat ($database_name = '') { |
|
|
|
|
$list_users_in_chat=array(); |
|
|
|
|
$tbl_chat_connected = Database::get_course_chat_connected_table(); |
|
|
|
|
|
|
|
|
|
$tbl_chat_connected = Database::get_course_chat_connected_table($database_name); |
|
|
|
|
$group_id = intval($_SESSION['id_group']); |
|
|
|
|
$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; |
|
|
|
|
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; |
|
|
|
|