<?
require_once '../core/system.php';
echo only_reg();
echo Moder();
echo ban();
$header = 'Mod-Чат';
require_once H.'core/head.php';
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 =  'В чате можно писать только с 3 уровня!';
if(!isset($err)) {
mysql_query("INSERT INTO `modchat` SET `id_user` = '$user[id]', `msg` = '$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 `modchat`"),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='player menuList'>";
echo "<li><a href='/smiles.php'><img src='/images/icon/arrow.png'>Cписок смайлов</a></li>";
echo "<li><a href='?'><img src='/images/icon/arrow.png'>Обновить</a></li>";
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 class="text large" value="'.$ank[nick].', " type="text" name="msg" /><br />
<span class="btn"><span class="end"><input class="label" type="submit" value="Отправить">Отправить</span></span>
</form>';
}else{
echo '<form class="player" method="post" action="?act=post">
<input class="text large" type="text" name="msg" /><br />
<span class="btn"><span class="end"><input class="label" type="submit" value="Отправить">Отправить</span></span>
</form>';
}
$q = mysql_query("SELECT * FROM `modchat` ORDER BY `id` DESC LIMIT $start, $set[p_str]");
echo "<div class='dot-line'></div>";
echo "<div class='player' style = 'color: #d3e2ed;'>";
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 = 'Admin';
}
if($ank[prava] == 4 ){
$color = 'Moder';
}
if($ank[prava] == 0 ){
$color = '';
}
if ($ank['storona'] == '0') {?><img src="/images/icon/0.png" height="11" alt="a"/> <?php }
	    if ($ank['storona'] == '1') {?><img src="/images/icon/1.png" height="11" alt="d"/> <?php }
echo online($ank[id]);
echo " <a href='/user/?id=$ank[id]'><b><span style = 'color: #becdd8;'>$ank[nick]</span></b></a> <span class='yellow'>[".vremja($post[time])."]</span> <a href='?id=$ank[id]'>(»)</a>";
if ($user['prava'] >= 4){
echo " / /";
echo "<a href='?del=msg&id_msg=".$post['id']."'> Удалить</a>";}
if(htmlspecialchars($_GET['del']) == 'msg') {
                                                   $id_chmsg = intval($_GET['id_msg']);
                                                   $del_chat_msg = mysql_query("DELETE FROM `modchat` WHERE `id` = '".$id_chmsg."'");
                                                   header("Location: ?");
                                                   }
include 'bb_chat_expection.php';
}
echo "</div>";
if ($k_page>1){
echo "<div class='dot-line'></div>";
str('?',$k_page,$page); // Вывод страниц
}
echo "<div class='mini-line'></div>";
echo "<div class='player menuList'>";
echo "<li><a href='/user/moder.php'><img src='/images/icon/user.png'>Список Модераторов</a></li>";
echo "</div>";
}
require_once H.'core/foot.php';
?>