protected static function createUser($username) { require_once "handlers/ChatHandler.php"; $conn = DbHandler::getConnection(); $query = "INSERT INTO users (username, last_activity) VALUES ( '" . $conn->escapeString($username) . "', " . $conn->escapeString(getMicrotime()) . " )"; $conn->exec($query); $user_id = $conn->lastInsertRowID(); // add user rel to public chat ChatHandler::addUserChatRel($user_id, ChatHandler::PUBLIC_CHAT_ID); return $user_id; }
SessionsHandler::redirect("login.php"); } else { if ($action == "post") { if (isset($_GET["chat_id"]) && isset($_GET["msg"])) { $chat_id = $_GET["chat_id"]; $message = $_GET["msg"]; $data = ChatHandler::insertMessage(UserHandler::getCurrentUserId(), $chat_id, $message); } } else { if ($action == "get") { if (isset($_GET["chat_id"]) && isset($_GET["reload"])) { $chat_id = $_GET["chat_id"]; $reload = $_GET["reload"]; $data = ChatHandler::getLatestMessages(UserHandler::getCurrentUserId(), $chat_id, $reload); } } else { if ($action == "change") { if (isset($_GET["partner_id"])) { $partner_id = $_GET["partner_id"]; if ($partner_id != ChatHandler::PUBLIC_CHAT_ID) { $data = ChatHandler::getPrivateChat(UserHandler::getCurrentUserId(), $partner_id); } else { $data = ChatHandler::PUBLIC_CHAT_ID; } } } } } } } echo isset($data) ? json_encode($data) : "";