Файл: mini_chat/index.php
Строк: 84
<?php
define('R', $_SERVER['DOCUMENT_ROOT']);
define('S', R.'/system');
require_once(R.'/system/kernel.php');
$count=$db->fass("SELECT COUNT(id) as count FROM `mini_chat`");
$posts=$count['count'];
$tmp->header('mini_chat');
$tmp->div('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']))
{
$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'])){
$o = $db->guard($_GET['otv']);
$ot=$db->fass("SELECT * FROM `mini_chat` where `id` = '".$o."'");
if($ot['kto'] != User::ID()){
if(isset($_REQUEST['submit']))
{
$message = $db->guard($_POST['message']);
if(empty($_POST['message']) )
{
$error .= Language::config('error');
}
if( mb_strlen($_POST['message'], 'UTF-8')<2)
{
$error .= Language::config('error');
}
if(!isset($error))
{
$db->query("INSERT INTO `mini_chat` set `kto` = '".User::ID()."', `message` = '[b]".notv($ot['kto'])."[/b], ".$message."', `time` = '".time()."' ");
header('location: /mini_chat');
}
}
$tmp->div('block', bb(smile($ot['message'])));
error($error);
$tmp->div('menu', '<form method="POST" action="">
'.Language::config('message').':<br/>
<textarea name="message" ></textarea><br />
<input type="submit" name="submit" value="'.Language::config('send').'" /></form>');
$tmp->div('menu', '<a href="/mini_chat">'.Language::config('back').'</a>');
$tmp->footer();
exit();
}
else{
header('location: /mini_chat');
}
}
if(isset($_REQUEST['submit']))
{
$message = $db->guard($_POST['message']);
if(empty($_POST['message']) )
{
$error .= Language::config('error');
}
if( mb_strlen($_POST['message'], 'UTF-8')<2)
{
$error .= Language::config('error');
}
if(!isset($error))
{
$db->query("INSERT INTO `mini_chat` set `kto` = '".User::ID()."', `message` = '".$message."', `time` = '".time()."' ");
header('location: /mini_chat');
}
}
error($error);
$tmp->div('menu', '<a href="/mini_chat?'.rand(101, 999).' ">'.Language::config('refresh').'!</a> ');
$tmp->div('menu', '<form method="POST" action="">
'.Language::config('message').':<br/>
<textarea name="message"></textarea><br />
<input type="submit" name="submit" value="'.Language::config('send').'" /></form>');
if($posts==0)
{
$tmp->div('error', Language::config('no_messages'));
}
else{
while($chat=$ch->fetch_assoc())
{
$tmp->div('block', nick($chat['kto'], true).' ('. times($chat['time']).') '.(($chat['kto'] == User::ID() || User::profile('level') >=3) ? '<a href="/mini_chat/del'.$chat['id'].'">['.Language::config('del').']</a>' : NULL) .' '.(($chat['kto'] != User::ID() ) ? '<a href="/mini_chat/otv'.$chat['id'].'">['.Language::config('otv').']</a>' : NULL ).'</br> '.bb(smile($chat['message'])));
}
page('?');
}
$tmp->footer();
?>