Файл: soo/chat.php
Строк: 58
<?
include_once '../connect.php';
if(isset($_GET['s']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `id` = '".intval($_GET['s'])."' LIMIT 1"),0)==1)
{
$s=intval($_GET['s']);
$soo=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo` WHERE `id` = '$s' LIMIT 1"));
include_once 'inc/ban.php';
$title=$title.''.$soo['name'].' - Мини-чат'; // заголовок страницы
include_once '../head.php';
require('../core/bb_code.php');
require('../core/panel.php');
if($soo['konf_soo']==0 || $u['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$u[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1)
{
$user_s = mysql_fetch_assoc(mysql_query("SELECT * FROM `soo_users` WHERE `id_soo`='$soo[id]' AND `id_user`='$u[id]' LIMIT 1"));
if($u['id'] && $user_s['level']>'0' && isset($_GET['del']))
{
if($_GET['del']=='all'){mysql_query("DELETE FROM `soo_chat` WHERE `id_soo`='$soo[id]'");
header("Location: ?s=".$soo['id']."");
}
elseif(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_chat` WHERE `id` = '".intval($_GET['del'])."' AND `id_soo`='$soo[id]' LIMIT 1"),0)==1)
{
mysql_query("DELETE FROM `soo_chat` WHERE `id`='".intval($_GET['del'])."' LIMIT 1");
header("Location: ?s=".$soo['id']."");
}
}
if (isset($_POST['msg']) && $u['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$u[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1)
{
$msg=mysql_real_escape_string(trim(htmlspecialchars($_POST['msg'])));
if ($msg>1024){$error='Сообщение слишком длинное';}
elseif ($msg<2){$error='Короткое сообщение';}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_chat` WHERE `id_soo`='$soo[id]' AND `id_user` = '$u[id]' AND `mess` = '".$msg."' LIMIT 1"),0)!=0){$error='Ваше сообщение повторяет предыдущее';}
if(!empty($error)){
mysql_query("INSERT INTO `soo_chat` (`id_soo`, `id_user`, `mess`, `time`) values('$soo[id]', '$u[id]', '".$msg."', '".time()."')");
header("Location: ?s=".$soo['id']."");
}
}
if ($u['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$u[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1)
{
echo '<div class="cred"><form method="post" name="message" action="?s='.$soo['id'].'&'.$passgen.'">';
echo 'Сообщение:<br/><textarea name="msg"></textarea><br/>';
echo '<input value="Отправить" type="submit" />';
echo '</form></div>';
}
else echo'Вы не можете писать сообщение в мини-чате данного соо<br/>';
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_chat` WHERE `id_soo`='$soo[id]'"),0);
$total = intval(($k_post - 1) / 10) + 1;
$page = intval(@$_GET['page']);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * 10 - 10;
if ($k_post==0)
{
echo 'Нет сообщений';
}
$q=mysql_query("SELECT * FROM `soo_chat` WHERE `id_soo`='$soo[id]' ORDER BY id DESC LIMIT $start, 10");
while ($post = mysql_fetch_assoc($q))
{
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '$post[id_user]' LIMIT 1"));
if($num==1){
echo "<div class='div'>";
$num=0;
}else{
echo "<div class='nav'>";
$num=1;}
echo ''.ico($ank['sex'],$ank['admin']).' <a href="info.php?s='.$soo['id'].'&id='.$ank['id'].'">'.$ank['login'].'</a>'.online($ank['id']).' ('.vremya($post['time']).')<br/>';
echo ''.smile(links(bb_code(censored($post['mess'])))).'<br/>';
if ($u['id'] && $user_s['level']>'0')
echo '[<a href="?s='.$soo['id'].'&del='.$post['id'].'">Удалить</a>]<br/>';
echo "</div>";
}
if($page>1)navigation($page, $total,'?s='.$soo['id'].'&'); // Вывод страниц
echo '<div class="zona">';
if ($u['id'] && $user_s['level']>'0')echo'<a href="?s='.$soo['id'].'&del=all">Очистить чат</a><br/>';
echo'<img src="/style/img/l.gif" alt="" class="icon"/><a href="index.php?s='.$soo['id'].'">В сообщество</a><br/></div>';
}
else
{
echo'Вам недоступен просмотр чата данного сообщества';
}
}
else
{
header("Location:index.php");
}
include_once '../foot.php';
?>