From 9d14ff16b3c21e3a15fec7306581315d5ac3ddc7 Mon Sep 17 00:00:00 2001 From: lopar Date: Mon, 5 Nov 2018 22:54:18 +0200 Subject: [PATCH] System chat from zayavka --- chat.php | 20 +++++++++++++++----- functions.php | 13 ++++++------- zayavka.php | 6 +++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/chat.php b/chat.php index f45584b..d1f238e 100644 --- a/chat.php +++ b/chat.php @@ -18,10 +18,20 @@ if ($msg) db::c()->query('INSERT INTO `chat` (`cid`, `uid`, `msg`) VALUES (?i, ? function show_messages() { - $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'); + $chat = db::c()->query(' +SELECT +`msg`, +`msgdate`, +(SELECT `login` FROM `users` WHERE `users`.`id` = `uid`) AS `from`, +`type` +FROM `chat` ORDER BY `id` ASC LIMIT 50'); + while ($message = $chat->fetch_assoc()) { $d = new DateTime($message['msgdate']); $m = htmlspecialchars($message['msg']); + if (!empty($message['type'])) { + echo sprintf('%s %s', $d->format('H:i'),$m)."
"; + } echo sprintf('%s [%s]: %s', $d->format('H:i'),$message['from'],$m)."
"; } } @@ -42,8 +52,8 @@ show_messages(); ---> ---> ---> ---> + + + + \ No newline at end of file diff --git a/functions.php b/functions.php index d24b207..7cd611e 100644 --- a/functions.php +++ b/functions.php @@ -2512,14 +2512,13 @@ function addchp($text, $who, $room = 0) fclose($fp); //закрытие } -function AddChatSystem($text) +/** +* @param $msg +* @throws \Krugozor\Database\Mysql\Exception + * Отправка системного сообщения в чат. +*/function AddChatSystem($msg) { - $fp = fopen("tmp/chat.txt", "a"); - flock($fp, LOCK_EX); - fputs($fp, ":[" . time() . "]:[!sys2all!!]:[" . ($text) . "]:[1]\r\n"); - fflush($fp); - flock($fp, LOCK_UN); - fclose($fp); + if ($msg) db::c()->query('INSERT INTO `chat` (`cid`,`uid`,`msg`,`type`) VALUES (?i,"?s","?s","?s")', 1, 'System', $msg, 'sys'); } function err($t) diff --git a/zayavka.php b/zayavka.php index 6ae4d3e..53b67bc 100644 --- a/zayavka.php +++ b/zayavka.php @@ -625,17 +625,17 @@ if ($_REQUEST['level'] == 'begin') { } if($_POST['back2']) { $z = $zay->getlist(1,null,$user['zayavka']); - addchp ('Внимание! '.nick::id($user['id'])->short().' отозвал заявку. ','{[]}'.nick::id($res['$z[$user['zayavka']]['team1'][0]'])->short().'{[]}'); + AddChatSystem('Внимание!'.nick::id($user['id'])->short().' отозвал заявку.'); echo $zay->delteam (2,$user['id'], $user['zayavka'], 1); } if($_POST['cansel']) { $z = $zay->getlist(1,null,$user['zayavka']); echo $zay->delteam (2,$z[$user['zayavka']]['team2'][0], $user['zayavka'], 1); - addchp ('Внимание! '.nick::id($user['id'])->full(1).' отказался от поединка. ','{[]}'.nick::id($res['$z[$user['zayavka']]['team2'][0]'])->short().'{[]}'); + AddChatSystem('Внимание!'.nick::id($user['id'])->short().' отказался от поединка.'); } if($_POST['confirm2']) { $z = $zay->getlist(1,null,$_REQUEST['gocombat']); - addchp ('Внимание! '.nick::id($user['id'])->full(1).' принял заявку, нужно принять вызов или отказать. ','{[]}'.nick::id($z[$_REQUEST['gocombat']]['team1'][0])->short().'{[]}'); + AddChatSystem('Внимание!'.nick::id($user['id'])->short().' принял заявку, нужно принять вызов или отказать.'); echo $zay->addteam (2,$user['id'], $_REQUEST['gocombat'], 1); die(""); }