Telegraph to chat on-login

This commit is contained in:
Igor Barkov [iwork] 2019-02-12 16:40:53 +02:00
parent 4f2bc7b130
commit 55813f6781
3 changed files with 7 additions and 5 deletions

View File

@ -14,7 +14,7 @@ include_once "config.php";
$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);
if ($msg) db::c()->query('INSERT INTO `chat` (`uid`, `msg`) VALUES (?i, "?s")', $uid, $msg);
function show_messages()
{
@ -29,8 +29,10 @@ FROM `chat` ORDER BY `id` ASC LIMIT 50');
while ($message = $chat->fetch_assoc()) {
$d = new DateTime($message['msgdate']);
$m = htmlspecialchars($message['msg']);
if ($message['type'] == 'sys') {
if ($message['type'] == 'sys') { /* Системка */
echo sprintf('<span style="color:maroon;background:#faa;">%s %s</span>', $d->format('H:i'),$m)." <br>";
} elseif ($message['type'] == 'sms') { /* Телеграмма */
echo sprintf('<span style="color:darkgreen;background:#afa;">[Телеграмма]: %s %s</span>', $d->format('H:i'),$m)." <br>";
} else echo sprintf('%s [%s]: %s', $d->format('H:i'),$message['from'],$m)." <br>";
}
}

View File

@ -46,9 +46,9 @@ if ($username && $password) {
$ip = $_SERVER['REMOTE_ADDR'];
db::c()->query('INSERT INTO `iplog` (`owner`, `ip`, `date`) VALUES (?i, "?s", ?i)', $data['id'], $ip, time());
$rs = db::c()->query('SELECT * FROM `telegraph` WHERE `receiver` = ?i', $data['id']);
while ($res = $rs->fetch_assoc()) {
addchp($res['text'], '{[]}' . $data['login'] . '{[]}');
$sms = db::c()->query('SELECT * FROM `telegraph` WHERE `receiver` = ?i', $data['id']);
while ($res = $sms->fetch_assoc()) {
db::c()->query('INSERT INTO `chat` (`uid`, `msg`, `type`) VALUES (?i, "?s", "?s")', $uid, $msg, 'sms');
}
db::c()->query('DELETE FROM `telegraph` WHERE `receiver` = ?i', $data['id']);
header("Location: fight.php");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB