* Project name: Battles-Game */ session_start(); if ($_SESSION['uid'] == null) { header("Location: index.php"); } include_once "config.php"; //include_once "functions.php"; $msg = filter_input(INPUT_POST,'msg'); $uid = $_SESSION['uid']; if ($msg) { try { db::c()->query('INSERT INTO `chat` (`uid`, `msg`) VALUES (?i, "?s")', $uid, $msg); } catch (\Krugozor\Database\Mysql\Exception $e) { echo "
DB Error: ". $e->getMessage() . "
File: " . $e->getFile() . " (".$e->getLine().")
"; } } function show_messages() { try { $chat = db::c()->query(' SELECT `msg`, `msgdate`, (SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from`, `type` FROM `chat` ORDER BY `id` LIMIT 50'); } catch (\Krugozor\Database\Mysql\Exception $e) { echo "
DB Error: ". $e->getMessage() . "
File: " . $e->getFile() . " (".$e->getLine().")
"; } while ($message = $chat->fetch_assoc()) { $d = new DateTime($message['msgdate']); $m = htmlspecialchars($message['msg']); if ($message['type'] == 'sys') { /* Системка */ echo sprintf("%s %s", $d->format('H:i'),$m).PHP_EOL; } elseif ($message['type'] == 'sms') { /* Телеграмма */ echo sprintf("[Телеграмма]: %s %s", $d->format('H:i'),$m).PHP_EOL; } else {echo sprintf('%s [%s]: %s', $d->format('H:i'),$message['from'],$m).PHP_EOL;} } } show_messages(); ?>