<?
require_once '../core/system.php';
echo only_reg();
echo ban();
require_once H.'core/head.php';
$avatar = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `ava`  = '".intval($_GET['ava'])."'"));


switch($act) {
case 'post':
if(isset($_POST['msg'])){
$msg = check($_POST['msg']);
if(strlen($msg) < 3 or strlen($msg) > 400) $err =  'Длина сообщения должна быть в пределах 3 - 400 символов';
if($user[level] < 3) $err = '';
if(!isset($err)) {
mysql_query("INSERT INTO `chat` SET `id_user` = '$user[id]', `msg` = '".mysql_real_escape_string($msg)."', `time` = '".time()."'");
header('Location: ?');
$_SESSION['message'] = 'Сообщение добавлено!';
exit();
}else{
header('Location: ?');
$_SESSION['err'] = $err;
// Вывод ошибки 
exit();
} 
}else{
header('Location: ?');
$_SESSION['err'] = 'Введите текст';
exit();
}
break;
default:
$k_post = mysql_result(mysql_query("SELECT COUNT(*)  FROM `chat`"),0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];
echo "<div class='block-panel' style='padding-bottom:0.5em;margin-bottom:0;'><div>";
echo '<form action="?smile" method="post"><input type="submit" class="button_small" value="Смайлы"></form>';
echo "</div>";
echo "<div class='mini-line'></div>";
if(isset($_GET['id'])) {
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $_GET[id] LIMIT 1"));
echo '<form class="player" method="post" action="?act=post">
<input tabindex="1" value="'. htmlspecialchars($ank[nick]).', " type="text" name="msg" /><br />
<input class="button_xl" type="submit" value="Отправить"></div>
</form>';
}else{
echo '<form class="player" method="post" action="?act=post">
<input tabindex="1" type="text" name="msg" /><br />
<input class="button_xl" type="submit" value="Отправить"></div>
</form>';
}
if($user[level] < 3){
echo '<div class="block10t"><div class="panelError">В чате можно писать с 3-го уровня.</div></div>';
}
if(isset($_GET['smile'])){include_once 'smiles.php';}
$q = mysql_query("SELECT * FROM `chat` ORDER BY `id` DESC LIMIT $start, $set[p_str]");
while($post = mysql_fetch_assoc($q)) {
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));
if($ank[prava] == 5 ){
$color = 'chatReMod';
}
if($ank[prava] == 4 ){
$color = 'chatReMod';
}
if($ank[prava] == 0 ){
$color = 'chatRe';
}
echo "<div style='padding-left:0.3em;padding-right:0.3em;'><hr style='margin-top:0.3em;margin-bottom:0.3em;'/></div>";
echo "<div style='padding-left:0.7em;margin-top:0em;'><div style='vertical-align:middle;line-height:1em;font-size:110%;'>";


echo '<img src="';

if(empty($ank['ava'])) echo '/img/noava.png'; else echo '/ava/'.$ank['ava'];
echo '" width="30" height="30"/>';

echo " <a href='?id=$ank[id]' class='".$color."'><b><span class = '".$color."'>$ank[nick]</span></b></a> <span style='font-size:70%;'>[".vremja($post[time])."]




</span><a href='/user/?id=$ank[id]' class='chatUserInfo'> [?]</a>";












if ($user['prava'] >= 4){
echo " / /";
echo "<span style='font-size:70%;text-decoration:none;'><a href='?del=msg&id_msg=".$post['id']."'><font color='red'> [X]</font></a></span>";}
if(htmlspecialchars($_GET['del']) == 'msg') {
                                                   $id_chmsg = intval($_GET['id_msg']);
                                                   $del_chat_msg = mysql_query("DELETE FROM `chat` WHERE `id` = '".$id_chmsg."'");
                                                   header("Location: ?");
                                                   }
echo ': '.smiles($post['msg']).'</div</div></div></div>';
}
echo "<div style='padding-left:0.3em;padding-right:0.3em;'><hr style='margin-top:0.3em;margin-bottom:0.3em;'/></div>";
echo '<div class="scroller"><b><span class="scrollerPageActive"><span class="scroll-current">';
if ($k_page>1){
str('?',$k_page,$page); // Вывод страниц
}
echo '</span></span></b></div>';
}
echo '<div style="margin-top:1em;">';
$q = mysql_query("SELECT * FROM `user` WHERE `prava` = '4' ORDER BY `online` DESC LIMIT $start, $set[p_str]");
echo "<div class='player'>";
if($k_post == 0)echo "<span class='grey'></span>"; 
while($post = mysql_fetch_assoc($q)) { 
echo '<div class="info-panel">Модераторы</div>';
echo '<div class="attention-panel">';
echo online($post[id]);
echo ' |<div class="green"> '.$post['nick'].'</div> <img src="/images/icon/level.png"> '.$post['level'].'<br />';
echo '</div>';
} 
echo "</div>";

require_once H.'core/foot.php';
?>