2018-03-01 23:21:53 +00:00
< ? php
/**
* Copyright ( c ) 2018.
* Author : Igor Barkov < lopar . 4 ever @ gmail . com >
* Project name : Battles - Game
*/
session_start ();
if ( $_SESSION [ 'uid' ] == null ) {
header ( " Location: index.php " );
}
include_once " config.php " ;
include_once " functions.php " ;
2018-03-02 09:29:28 +00:00
$msg = filter_input ( INPUT_POST , 'msg' );
$uid = $_SESSION [ 'uid' ];
if ( $msg ) db :: c () -> query ( 'INSERT INTO `chat` (`cid`, `uid`, `msg`) VALUES (?i, ?i, "?s")' , 1 , $uid , $msg );
2018-03-02 20:47:04 +00:00
$chat = db :: c () -> query ( 'SELECT `msg`, `msgdate`, (SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from` FROM `chat` ORDER BY `id` ASC LIMIT 50' );
2018-03-01 23:21:53 +00:00
while ( $message = $chat -> fetch_assoc ()) {
2018-03-01 23:44:06 +00:00
$d = new DateTime ( $message [ 'msgdate' ]);
2018-03-02 09:29:28 +00:00
$m = htmlspecialchars ( $message [ 'msg' ]);
2018-03-02 20:49:03 +00:00
echo sprintf ( '%s [%s]: %s' , $d -> format ( 'H:i' ), $message [ 'from' ], $m ) . " <br> " ;
2018-03-01 23:21:53 +00:00
}
2018-03-01 23:33:18 +00:00
2018-03-01 23:21:53 +00:00
?>
<! doctype html >
< html >
< head >
< meta charset = " utf-8 " >
< link rel = " stylesheet " href = " css/main.css " >
2018-03-08 12:28:31 +00:00
< style >
form { padding : 3 px ; position : fixed ; bottom : 0 ; width : 100 % ; }
2018-03-08 12:32:55 +00:00
form input [ type = " text " ] { border : 0 ; padding : 10 px ; width : 90 % ; margin - right : . 5 % ; }
form input [ type = " submit " ] { width : 9 % ; border : none ; padding : 10 px ; }
2018-03-08 12:28:31 +00:00
</ style >
2018-03-01 23:21:53 +00:00
</ head >
< body >
< form action = " chat.php " method = " post " >
2018-03-08 12:28:31 +00:00
< input id = " msg " name = " msg " size = " 100 " placeholder = " Введите сообщение... " >
2018-03-01 23:21:53 +00:00
< input type = " submit " >
</ form >
</ body >