Вход Регистрация
Файл: public_html/chat.php
Строк: 53
<?
include ('./dev/db.php');
include (
'./dev/functions.php');
include (
'./dev/user.php');
$title 'Чат';
include (
'./dev/head.php');
if(!
$user) {
header('location: /');
exit;
}
if(
$_GET['chat'] == restart && $user['id'] == 1) {
mysql_query("truncate table `chat`");
header('location: ?');
exit;
}
if(isset(
$_GET['new_msg'])){
if(isset(
$_POST['text'])){
$text _string($_POST['text']);
if(
strlen($text) < or strlen($text) > 1000) {
echo 
'<div class="block center">Длина сообщения 1-1000 символов!<br>Вернуться в <a href="/chat.php">Чат</a></div>';
include (
'./dev/foot.php');
exit;
}

if(
$user['level'] < 5) {
echo 
'<div class="block center">Отправлять сообщения разрешено с 5 уровня!<br>Вернуться в <a href="/chat.php">Чат</a></div>';
include (
'./dev/foot.php');
exit;
}
mysql_query("INSERT INTO `chat` SET `id_user` = '$user[id]', `time` = '".time()."', `text` = '".text($text)."'");
$_SESSION['result'] = 'Сообщение отправлено!';
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 
"<textarea name='text' style='width: 97%'>$opponent[login], </textarea>";
echo 
"<input type='submit' value='Отправить'> <a href='/smiles.php'>Смайлики</a> </form>";
}else{
echo 
"<form method='post' action='?new_msg'>";
echo 
"<textarea name='text' style='width: 97%'> </textarea>";
echo 
"<input type='submit' value='Отправить'> <a href='/smiles.php'>Смайлики</a> </form>";
}
echo 
'</div>';
$set['p_str'] = 10;
$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'];
$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 `users` WHERE `id` = $post[id_user] LIMIT 1"));
echo 
"<div class='block'><img src='/img/race/sex/$ank[race].jpg'> <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'] == 0) echo "</div>";
if(
$user['access'] == 1) echo "<span style='float: right'> <a href='?delete_post=$post[id]'><font color='red'>(x)</font></a></span></div>";
}
if(
$k_post<1) {
echo 
'<div class="block center">Сообщений нет!</div>';
}
if(
$k_post>&& $user['id']==1) {
echo 
'<a href="?chat=restart" class="link"><img src="/img/arr.png"> Очистить чат</a>';
}
if(
$k_page>1)  echo str('?',$k_page,$page);
require_once 
'./dev/foot.php';
?>
Онлайн: 1
Реклама