Файл: bdls.ru/chat.php
Строк: 52
<?
include ('./system/common.php');
include ('./system/functions.php');
include ('./system/user.php');
$title = 'Чат';
include ('./system/h.php');
if(!$user) {
header('location: /');
exit;
}
if(isset($_GET['new_msg'])){
if(isset($_POST['text'])){
$text = _string($_POST['text']);
if(strlen($text) < 1 or strlen($text) > 1000) {
echo '<div class="block center">Длина сообщения 1-1000 символов!<br>Вернуться в <a href="/chat.php">Чат</a></div>';
include ('./system/f.php');
exit;
}
if($user['level'] < 10) {
echo '<div class="block center">Отправлять сообщения разрешено с 10 уровня!<br>Вернуться в <a href="/chat.php">Чат</a></div>';
include ('./system/f.php');
exit;
}
mysql_query("INSERT INTO `chat` SET `id_user` = '$user[id]', `time` = '".time()."', `text` = '".text($text)."'");
header('Location: /chat.php');
exit();
}else{
header('Location: /chat.php');
exit();
}
}
if(isset($_GET['delete_post']) and $user['access'] == 1){
mysql_query("DELETE FROM `chat` WHERE `id` = '".$_GET['delete_post']."'");
header('Location: ?');
exit();
}
echo "<div class='block'>";
if(isset($_GET['to'])){
echo "<form method='post' action='?new_msg=$_GET[to]'>";
$opponent = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = $_GET[to] LIMIT 1"));
echo "<input type='text' name='text' value = '$opponent[login], ' style='width: 97%;'>";
echo "<input type='submit' value='Отправить'> <a href='/smiles.php'><img src='/images/smiles/mini_ulibka.gif'></a> </form>";
}else{
echo "<form method='post' action='?new_msg'>";
echo "<input type='text' name='text' style='width: 97%;'>";
echo "<input type='submit' value='Отправить'> <a href='/smiles.php'><img src='/images/smiles/mini_ulibka.gif'></a> </form>";
}
echo '</div><div class="block">';
$set['p_str'] = 20;
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `chat` where `support` = '0'"),0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];
$q = mysql_query("SELECT * FROM `chat` where `support` = '0' ORDER BY `id` DESC LIMIT $start, $set[p_str]");
while($post = mysql_fetch_assoc($q)) {
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = $post[id_user] LIMIT 1"));
echo "<p><a href='/user.php?id=$ank[id]'>$ank[login]</a>";
if($user['id'] == $ank['id'])echo ": ";
if($user['id'] != $ank['id'])echo "<a href='?to=$ank[id]'> (»)</a>: ";
$msg = str_replace(array($user[login].','), "<b>$user[login],</b> ", $post['text']);
echo " ".smiles($msg);
if($user['access'] == 1) echo " <a href='?delete_post=$post[id]'><font color='red'>(x)</font></a></p>";
}
echo '</div>';
if($k_post<1) {
echo '<div class="block center">Сообщений нет!</div>';
}
if($k_page>1) echo str('?',$k_page,$page);
if($k_post>0) {
echo '<div class="ublock" style="padding: 6px;">Пожаловаться на нарушение правил чата можно Модераторам</div>';
}
require_once './system/f.php';
?>