public static function userDeleteIdle() { $users_model = new UsersModel(); $users_model->setCond('timestamp < "' . date('Y-m-d H:i:s', strtotime('-' . TIME_USER_IDLE . ' seconds')) . '"'); $users_model->setFields(array('active')); $users_model->setData(array('active' => 0)); $users = $users_model->load_all(); if (count($users)) { foreach ($users as $load) { if (isset($_SESSION['chat_login']['timestamp']) && $load['timestamp'] >= $_SESSION['chat_login']['timestamp']) { AlertModel::addExit($load['user'], $load['id'], $load['id_room']); } } } return $users_model->delete(); }
$data->timestamp = date('Y-m-d H:i:s', time()); $fields = array_keys((array) $data); $users_model = new UsersModel(); $users_model->setFields($fields); $users_model->setData($data); if ($users_model->insert()) { $id_user = $users_model->getId(); $_SESSION['chat_login']['id_user'] = $id_user; $_SESSION['chat_login']['user'] = $user; $_SESSION['chat_login']['id_room'] = $id_room; $_SESSION['chat_login']['room'] = $room['room']; $_SESSION['chat_login']['timestamp'] = $data->timestamp; $_SESSION['chat_login']['id_alert'] = array(); $_SESSION['chat_login']['last'] = time(); // Aviso da entry do user AlertModel::addEntry($user, $id_user, $id_room); } } else { $message = 'The chosen username is already in use, choose another to enter.'; } } } else { $message = 'Room capacity was exhausted! Choose another room to enter.'; } } else { $message = 'The room does not exists.'; } } else { $message = 'Error code'; } }
<?php require 'app/autoload.php'; if (isset($_SESSION['chat_login']['id_user'])) { // Avisa a exit do user AlertModel::addExit($_SESSION['chat_login']['user'], $_SESSION['chat_login']['id_user'], $_SESSION['chat_login']['id_room']); // Deleta user $users_model = new UsersModel(); $users_model->delete($_SESSION['chat_login']['id_user']); } $_SESSION['chat_login'] = array(); header('location: login.php'); exit;