Файл: ajax/messages/chat/online.php
Строк: 83
<?php
/**
* who is online
*
* @package Sngine
* @author Yehia Abed
* @version 0.3
*/
// fetch kernal
$depth = '../../../';
require($depth.'kernal.php');
// check AJAX Request
if(!IsAJAX()) {
header('Location: '.SITE_URL);
}
// check user exist
if($userExist) {
// checking wheter the user is already marked as being online
$check = $db->query(sprintf("SELECT * FROM users_online WHERE UserID = %s", Secure($userArray['UserID'], 'int'))) or die(ReportError("sql error #1 @ajax/messages/chat/online"));
if($check->num_rows == 0) {
$db->query(sprintf("INSERT INTO users_online (UserID) VALUES (%s)", Secure($userArray['UserID'], 'int'))) or die(ReportError("sql error #2 @ajax/messages/chat/online"));
}else {
$db->query(sprintf("UPDATE users_online SET Time = NOW() WHERE UserID = %s", Secure($userArray['UserID'], 'int'))) or die(ReportError("sql error #3 @ajax/messages/chat/online"));
}
// removing entries not updated in the last minute
$db->query("DELETE FROM users_online WHERE Time <SUBTIME(NOW(),'0 0:1:0')") or die(ReportError("sql error #4 @ajax/messages/chat/online"));
// get online users
$getUsers = $db->query(sprintf("SELECT user.UserID, user.UserFirstName, user.UserLastName, user.UserAvatarPathSmall FROM users user INNER JOIN users_online online ON user.UserID = online.UserID WHERE online.UserID != %s AND user.Offline = 'N'", Secure($userArray['UserID'], 'int') )) or die(ReportError("sql error #5 @ajax/messages/chat/online"));
$getOnlineNum = $db->query("SELECT * FROM users_online") or die(ReportError("sql error #6 @ajax/messages/chat/online"));
if($getUsers->num_rows > 0) {
while($online = $getUsers->fetch_array(MYSQLI_ASSOC)) {
$onlines[] = $online;
}
$smarty->assign('onlines', $onlines);
}
$smarty->assign('onlineCounter', $getOnlineNum->num_rows);
}
// page footer
PageFooter("ajax.chat.online");
?>