Handle exceptions.

This commit is contained in:
Igor Barkov (iwork) 2020-06-23 15:22:32 +03:00
parent 50f04b3a3c
commit 9ce4a48f42

View File

@ -6,19 +6,18 @@
*/
session_start();
if ($_SESSION['uid'] == null) {
if (empty($_SESSION['uid'])) {
header("Location: index.php");
}
include_once "config.php";
require_once "config.php";
//include_once "functions.php";
$msg = filter_input(INPUT_POST,'msg');
$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 "<div class='private'>DB Error: ". $e->getMessage() . "<br> File: " . $e->getFile() . " (".$e->getLine().")</div>";
try { db::c()->query('INSERT INTO `chat` (`uid`, `msg`) VALUES (?i, "?s")', $uid, $msg); }
catch (\Krugozor\Database\Mysql\Exception $e) {
echo "<div style='background-color: #ffaaaa;'>Ошибка: " . $e->getMessage() . "<br> В файле: " . $e->getFile() . " (" . $e->getLine() . ")</div>";
}
}
@ -32,20 +31,23 @@ function show_messages()
(SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from`,
`type`
FROM `chat` ORDER BY `id` LIMIT 50');
while ($message = $chat->fetch_assoc()) {
$d = new DateTime($message['msgdate']);
$m = htmlspecialchars($message['msg']);
if ($message['type'] == 'sys') { /* Системка */
echo sprintf("<span style='color:maroon;background:#faa;'>%s %s</span>", $d->format('H:i'), $m) . PHP_EOL;
} elseif ($message['type'] == 'sms') { /* Телеграмма */
echo sprintf("<span style='color:darkgreen;background:#afa;'>[Телеграмма]: %s %s</span>", $d->format('H:i'), $m) . PHP_EOL;
} else {
echo sprintf('%s [%s]: %s', $d->format('H:i'), $message['from'], $m) . PHP_EOL;
}
}
} catch (\Krugozor\Database\Mysql\Exception $e) {
echo "<div class='private'>DB Error: ". $e->getMessage() . "<br> File: " . $e->getFile() . " (".$e->getLine().")</div>";
}
while ($message = $chat->fetch_assoc()) {
$d = new DateTime($message['msgdate']);
$m = htmlspecialchars($message['msg']);
if ($message['type'] == 'sys') { /* Системка */
echo sprintf("<span style='color:maroon;background:#faa;'>%s %s</span>", $d->format('H:i'),$m).PHP_EOL;
} elseif ($message['type'] == 'sms') { /* Телеграмма */
echo sprintf("<span style='color:darkgreen;background:#afa;'>[Телеграмма]: %s %s</span>", $d->format('H:i'),$m).PHP_EOL;
} else {echo sprintf('%s [%s]: %s', $d->format('H:i'),$message['from'],$m).PHP_EOL;}
echo "<div style='background-color: #ffaaaa;'>Ошибка: " . $e->getMessage() . "<br> В файле: " . $e->getFile() . " (" . $e->getLine() . ")</div>";
}
}
show_messages();
?>
<!--<!doctype html>-->
@ -61,7 +63,7 @@ show_messages();
<!--</head>-->
<!--<body>-->
<!--<div>-->
<?php ?>
<?php ?>
<!--</div>-->
<!--<form action="chat.php" method="post">-->
<!-- <input id="msg" name="msg" size="100" placeholder="Введите сообщение...">-->