Файл: www/chat.php
Строк: 48
<?php
include 'inc/mysql.php';
include 'inc/check.php';
include 'inc/functions.php';
top();
include 'inc/account.php';
$titlestr='Чат';
include 'inc/interface.php';
if(isset($_SESSION['auth']) && $_SESSION['auth']==1){
if(isset($_POST['msg'])){
$_POST['msg'] = trim($_POST['msg']);
if(!empty($_POST['msg'])){
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `chat` WHERE `account`='".$account['id']."'"),0)>0 AND 5>(time()-mysql_result(mysql_query("SELECT `time` FROM `chat` WHERE `account`='".$account['id']."' ORDER BY `id` DESC LIMIT 1"),0)))$err[]='Нельзя писать так часто!';
if(strlen($_POST['msg'])>255) $err[]='Слишком длинное сообщение!';
if(strlen($_POST['msg'])<2) $err[]='Слишком короткое сообщение!';
}else{
$err[]='Пустое сообщение!';
}
if(!$err){
$msg = mysql_real_escape_string($_POST['msg']);
mysql_query("INSERT INTO `chat`(`account`,`msg`,`time`) VALUES('".$account['id']."','".mysql_real_escape_string($msg)."','".time()."')");
header("Location: chat.php"); exit;
}else{
foreach($err as $value){
echo '
<div class="help">'.$value.'</div>
';
}
}
}
echo '
<div class="title">
Общий чат
</div>
<div class="tools">
<a href="chat.php?">Обновить</a> | <a href="/smile.php">Смайлы</a>
</div>
';
echo '<div class="border-top"></div>';
if($_GET['go']=='delete' && ($account['status']=="moder" || $account['status']=="gm")){
if(isset($_GET['id'])){
$del = $_GET['id'];
}
if($del){
mysql_query("DELETE FROM `chat` WHERE `id`='".$del."'");
header ("Location: chat.php"); exit;
}else{
header ("Location: chat.php"); exit;
}}
if ($_GET['say']){
$say=mysql_result(mysql_query("SELECT `name` FROM `account` WHERE `id`='".intval($_GET['say'])."'"),0);
$say = str_replace("$say","$say, ",$say);
}else{
$say='';
}
echo '
<form method="post" action="chat.php?">
<div class="aut">
Сообщение [2-255]:
<textarea name="msg" rows="2" cols="30">'.$say.'</textarea><br>
<input type="submit" class="submit" value="Отправить">
</div>
</form>
';
$cop=10;
$ca=mysql_result(mysql_query("SELECT COUNT(*) FROM `chat`"),0);
$cp=ceil($ca/$cop);
if(isset($_GET['page']) && is_numeric($_GET['page'])){
$page = $_GET['page'];
if($_GET['page']>$cp) $page=$cp;
if($_GET['page']<1)$page=1;
}else{
$page=1;
}
$start=$page*$cop-$cop;
$dlist = 'list1';
$q=mysql_query("SELECT * FROM `chat` ORDER BY `id` DESC LIMIT $start,$cop");
while ($result=mysql_fetch_assoc($q)){
echo '<div class="'.$dlist.'">';
$_user = mysql_fetch_assoc(mysql_query("SELECT * FROM `account` WHERE `id`='".$result['account']."'"));
if ($account['status']=='moder' OR $account['status']=='gm'){
echo '<a href="?go=delete&id='.$result['id'].'">[x]</a>';
}
if($_user['status']=="moder" OR $_user['status']=="gm"){
echo '
<a href="char.php?id='.$_user['id'].'"><us>'.$_user['name'].'</us></a> '.untime($result['time']).'<hr>';
}else{
echo '
<a href="char.php?id='.$_user['id'].'">'.$_user['name'].'</a> '.untime($result['time']).'<hr>';
}
echo smiles(htmlspecialchars(stripslashes($result['msg'])));
echo '<hr>';
echo '[<a href="?say='.$_user['id'].'">Отв</a>]';
echo '</div>';
if ($dlist == 'list1'){
$dlist = 'list2';
}else{
$dlist = 'list1';
}
}
echo '
<div class="nstr">
Страницы
';
if($page-1>0){
echo '<a href="?page='.($page-1).'"><</a> ';
}
if($page-1>0){
echo '<a href="?page='.($page-1).'">'.($page-1).'</a> ';
}
echo '<b>'.$page.'</b>';
if($page+1<=$cp){
echo ' <a href="?page='.($page+1).'">'.($page+1).'</a>';
}
if($page+1<=$cp){
echo ' <a href="?page='.($page+1).'">></a>';
}
echo '</div>';
}else{
header("Location: /?"); exit;
}
down();
?>