Файл: titwar.ru/chat.php
Строк: 161
<?
include './system/common.php';
include './system/functions.php';
include './system/user.php';
if(!$user) { header('location: /'); exit; }
$title = ($_GET['clan'] == true) ? 'Clan chat':'General chat';
include './system/h.php';
echo '
<div class='line'></div>';
if($user['save'] == 0) {
echo '<div class='content'><font color='#909090'>For type in chat you have to save your character</font></div>';
}
else
{
echo '<div class='menu'>';
if($user['level'] < 3) {
echo '<li><font color='#909090'>You can type in chat if your <img src='/images/icon/level.png' alt=''/> level is 3!</font></li>';
}
else
{
$text = _string($_POST['text']);
$to = _string(_num($_GET['to']));
if($to) {
$_to = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$to.'"');
$_to = mysql_fetch_array($_to);
if(!$_to OR $_to['id'] == $user['id']) {
header('location: /chat/'.($_GET['clan'] == true ? 'clan/':''));
exit;
}
}
if($text && $user['level'] > 2) {
$antiflood = mysql_fetch_array(mysql_query('SELECT * FROM `chat` WHERE `clan` = ''.($_GET['clan'] == true ? $clan['id']:0).'' AND `user` = ''.$user['id'].'' ORDER BY `time` DESC LIMIT 1'));
if(time() - $antiflood['time'] < 5) $errors[] = 'Error, you can type one time per 5 second';
if($errors) {
echo '<div class='content' align='center'>';
foreach($errors as $error) {
echo $error.'<br/>';
}
echo '</div>
<div class='line'></div>';
}
else
{
if($_to) {
$text = str_replace($_to['login'].', ', '', $text);
}
$text = eregi_replace( "[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "error", $text);
$text = str_replace(array('сука',
'нах',
'нахуй',
'пидар',
'лох',
'нуб',
'кидало',
'я админ',
'чмо',
'урод',
'Фильтр'), 'Мат', $text);
mysql_query('INSERT INTO `chat` (`clan`,
`user`,
`to`,
`text`,
`time`) VALUES ("'.($_GET['clan'] == true ? $clan['id']:0).'",
"'.$user['id'].'",
"'.$_to['id'].'",
"'.$text.'",
"'.time().'")');
header('location: /chat/'.($_GET['clan'] == true ? 'clan/':''));
}
}
?>
<li><form action='/chat/<?=($_GET['clan'] == true ? 'clan/':'')?>?to=<?=$to?>' method='post'>
<input name='text' style='width: 100%;' value="<?=($to ? $_to['login'].', ':'')?>"/><br/>
<input type='submit' value='Send'/> <a href='/chat/<?=($_GET['clan'] == true ? 'clan/':'')?>'><font color='#909090'>Refresh</font></a>
</form></li>
<?
}
?>
<li>
<?
$max = 20;
$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `chat` WHERE `clan` = "'.($_GET['clan'] == true ? $clan['id']:0).'"'),0);
$pages = ceil($count/$max);
$page = _string(_num($_GET['page']));
if($page > $pages) {
$page = $pages;
}
if($page < 1) {
$page = 1;
}
$start = $page * $max - $max;
if($count > 0) {
$msg = _string(_num($_GET['msg']));
if($msg) {
$i_msg = mysql_query('SELECT * FROM `chat` WHERE `id` = "'.$msg.'"');
$i_msg = mysql_fetch_array($i_msg);
if(!$i_msg) {
header('location: /chat/'.($_GET['clan'] == true ? 'clan/':'').'?page='.$page);
exit;
}
if($_GET['clan'] == true && $clan_memb['rank'] == 4 OR $user['access'] > 0) {
mysql_query('DELETE FROM `chat` WHERE `clan` = "'.($_GET['clan'] == true ? $clan['id']:0).'" AND`id` = "'.$i_msg['id'].'"');
}
header('location: /chat/'.($_GET['clan'] == true ? 'clan/':'').'?page='.$page);
}
$q = mysql_query('SELECT * FROM `chat` WHERE `clan` = "'.($_GET['clan'] == true ? $clan['id']:0).'" ORDER BY `id` DESC LIMIT '.$start.', '.$max.'');
while($row = mysql_fetch_array($q)) {
if($row['to'] == $user['id'] && $row['read'] == 0) {
mysql_query('UPDATE `chat` SET `read` = "1" WHERE `id` = "'.$row['id'].'"');
}
$sender = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['user'].'"');
$sender = mysql_fetch_array($sender);
?>
<img src='/images/icon/race/<?=$sender['r'].($sender['online'] > (time() - 300) ? '':'-off')?>.png' alt='*'/>
<a href='/user/<?=$sender['id']?>/'><?=$sender['login']?></a><?
if($sender['id'] != $user['id']) {
?> <a href='/chat/<?=($_GET['clan'] == true ? 'clan/':'')?>?to=<?=$sender['id']?>'>(»)</a><?
}
?>:<?
if($row['to']) {
$__to = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['to'].'"');
$__to = mysql_fetch_array($__to);
if($__to['id'] == $user['id']) {
?>
<font color='#90c090'>
<?
}
?>
<?=$__to['login']?>,
<?
if($__to['id'] == $user['id']) {
?>
</font>
<?
}
}
if($sender['access'] == 1) {
?>
<font color='#90c0c0'>
<?
}
?>
<?
if($sender['access'] == 2) {
?>
<font color='#90c0c0'>
<?
}
?>
<?=smiles($row['text'])?>
<?
if($sender['access'] > 0) {
?>
<?
}
if($user['access'] > 0) {
?>
<a href='/chat/<?=($_GET['clan'] == true ? 'clan/':'')?>?msg=<?=$row['id']?>'>[x]</a></font>
<?
}
?>
<br/>
<?
}
}
else
{
?>
<font color='#909090'>There are no messages</font>
<?
}
?>
</li>
<?
if($clan) {
$_chat = mysql_query('SELECT COUNT(*) FROM `chat` WHERE `clan` = "0" AND `to` = "'.$user['id'].'" AND `read` = "0"');
$_chat = mysql_result($_chat,0);
$_clan_chat = mysql_query('SELECT COUNT(*) FROM `chat` WHERE `clan` = "'.$clan['id'].'" AND `to` = "'.$user['id'].'" AND `read` = "0"');
$_clan_chat = mysql_result($_clan_chat,0);
?>
<li><small><img src='/images/icon/chat.png' alt='*'/> <?=($_GET['clan'] == true ? '<a href='/chat/'>General</a>':'<font color='#606060'>General</font>')?> <?=($_chat > 0 ? '<font color='#30c030'>(+)</font>':'')?> | <?=($_GET['clan'] == true ? '<font color='#606060'>Clan</font>':'<a href='/chat/clan/'>Clan</a>')?> <?=($_clan_chat > 0 ? '<font color='#30c030'>(+)</font>':'')?></small></li>
<?
}
?>
<li>
<?=pages('/chat/'.($_GET['clan'] == true ? 'clan/':'').'?');?>
</li>
<?
if($_GET['read_all'] == true) {
mysql_query('UPDATE `chat` SET `read` = "1" WHERE '.($_GET['clan'] == true ? '`clan` = "'.$clan['id'].'" AND':'').' `to` = "'.$user['id'].'"');
header('location: /chat/'.($_GET['clan'] == true ? 'clan/':''));
}
?></div>
<div class='list'>
<li><a href='/chat/<?=($_GET['clan'] == true ? 'clan/':'')?>?read_all=true'><img src='/images/icon/arrow.png' alt='*'/> Check as was read</a></li>
<li><a href='/moderators/'><img src='/images/icon/user.png' alt='*'/> Administration</a></li>
</div>
<?
}
include './system/f.php';
?>