Файл: modules/mini_chat/index.php
Строк: 117
<?php
define('R', $_SERVER['DOCUMENT_ROOT']);
define('S', R.'/system');
require_once(R.'/system/kernel.php');
$tmp->header('mini_chat');
$ms=$db->guard($_GET['ms']);
$posts=$db->fass_c("SELECT COUNT(*) as count FROM `mini_chat`");
$tmp->title('title', Language::config('mini_chat'). ' ('.$posts.')');
User::panel();
$total = intval((($posts-1)/$num)+1);
if(empty($page) or $page<0) $page=1;
if($page>$total) $page=$total;
$start=$page*$num-$num;
$ch=$db->query("select * from `mini_chat` ORDER BY time DESC LIMIT ".$start.", ".$num."");
if(isset($_GET['del'])) {
if(User::aut()){
$del = $db->guard($_GET['del']);
$c=$db->fass("SELECT * FROM `mini_chat` where `id` ='".$del."'");
if($c['kto'] == User::ID() || User::profile('level') >=3)
$db->query("DELETE FROM `mini_chat` where `id` ='".$del."'");
header('location: /mini_chat');
}
}
if(isset($_GET['otv'])){
if(User::aut()){
$o=$db->guard($_GET['otv']);
$ot=$db->fass("SELECT * FROM `mini_chat` where `id` = '".$o."'");
if($ot['kto'] != User::ID() && !empty($ot)){
if(isset($_REQUEST['submit'])) {
$message = $db->guard($_POST['messages']);
if(empty($message) || mb_strlen($_POST['messages'], 'UTF-8')<2) $error .= Language::config('no_message');
if(!isset($error)) {
$db->query("INSERT INTO `mini_chat` set `kto` = '".User::ID()."', `message` = '[rep]".nickname($ot['kto'])."[/rep] ".$message."', `time` = '".time()."' ");
$lid = $db->insert_id();
$db->query("INSERT INTO `journal` set `kto` = '".User::ID()."', `komy` = '".$ot['kto']."', `message` = 'replay_chat', `url`= '/mini_chat/".$lid."', `time` = '".time()."', `readln` = '0' ");
$db->query("UPDATE `users` set `money` = money + 5 where `id` = '".User::ID()."'");
header('location: /mini_chat');
}
}
$tmp->div('messages', '<div>'.bb(smile($ot['message'])).'</div><hr>' );
bbcode();
error($error);
$tmp->div('main', '<form method="POST" name="message" action="">'.Language::config('message').':<br/><textarea name="messages"></textarea><br /><input type="submit" name="submit" value="'.Language::config('send').'" /></form>');
$tmp->div('menu', '<hr><a href="/mini_chat">'.img('link.png').' '.Language::config('back').'</a>');
$tmp->footer();
exit();
}
} else {
header('location: /mini_chat');
}
}
if(isset($_REQUEST['submit'])) {
if(User::aut()){
$message = $db->guard($_POST['messages']);
$ant=$db->fass("SELECT * FROM `mini_chat` where `kto` = '".User::ID()."' and `message` = '".$message."' and `time` > '".(time() - 3)."' limit 1");
if ($ant) $error .= Language::config('error');
if (empty($message) || mb_strlen($_POST['messages'], 'UTF-8')<2) $error .= Language::config('no_message');
if(!isset($error)) {
$db->query("INSERT INTO `mini_chat` set `kto` = '".User::ID()."', `message` = '".$message."', `time` = '".time()."' ");
header('location: /mini_chat');
}
}
}
if(isset($_GET['ms'])) {
if(User::aut()){
$msg=$db->fass("select * from `mini_chat` where `id` = '".$ms."'");
if (!empty($msg)) {
echo '<div class="messages no_read"><div>'.nick_new($msg['kto']).'<span class="times">'. times($msg['time']).'</span>'.(($msg['kto'] != User::ID()) ? '<a class="answer" href="/mini_chat/otv'.$msg['id'].'">'.img('answer.png').'</a>' : NULL ).' <br/>'.bb(smile($msg['message'])).'</div></div><hr>';
}
}
}
if(User::aut()){
error($error);
$tmp->div('menu', '<a href="/mini_chat?'.rand(101, 999).' ">'.img('refresh.png').' '.Language::config('refresh').'</a>');
bbcode();
$tmp->div('main', '<form method="POST" name="message" action="">'.Language::config('message').':<br/><textarea name="messages"></textarea><br /><input type="submit" name="submit" value="'.Language::config('send').'" /></form>');
}
if(!$posts) {
$tmp->div('main', Language::config('no_messages'));
} else {
echo '<div class="messages">';
while($chat=$ch->fetch_assoc()) {
echo '<hr><div>'.nick_new($chat['kto']).' '.(($chat['kto'] == User::ID() || User::profile('level') >=3) ? '<a class="de" href="/mini_chat/del'.$chat['id'].'">'.img('delete.png').'</a>' : NULL).'<span class="times">'. times($chat['time']).'</span>'.(($chat['kto'] != User::ID() && User::aut()) ? '<a class="answer" href="/mini_chat/otv'.$chat['id'].'">'.img('answer.png').'</a>' : NULL ).' <br/>'.bb(smile($chat['message'])).'</div>';
}
echo '</div>';
page('?');
}
$tmp->div('menu', '<hr><a href="/">'.img('link.png').' '.Language::config('home').'</a>');
$tmp->footer();
?>