Файл: public_html/moder_chat.php
Строк: 191
<?
include './system/common.php';
include './system/functions.php';
include './system/user.php';
// для лохов ↓
if(!$user OR $user['access'] < 1) {
header('location: /404.php');
exit;
}
// время в прошлом склонении
function test($time_) {
if (time()-$time_<60) {
$vremya=time()-$time_;
return ' '.$vremya.'с назад';
}
elseif (time()-$time_>60 && time()-$time_<3600) {
$sec=(time()-$time_)%60;
$min=((time()-$time_)-$sec)/60;
return ' '.$min.'м '.$sec.'с назад';
}
elseif (time()-$time_>3600 && time()-$time_<3600*24) {
$min=((time()-$time_)/60)%60;
$hour=((time()-$time_)-((time()-$time_)%3600))/3600;
return ' '.$hour.'ч '.$min.'м назад';
}
elseif (time()-$time_>3600*24 && time()-$time_<3600*24*30) {
$hour=((((time()-$time_)-((time()-$time_)%3600))/3600)-((((time()-$time_)-((time()-$time_)%3600))/3600)%24))/24;
$den=((time()-$time_)-((time()-$time_)%(3600*24)))/(3600*24);
return ' '.$den.'дн '.$hour.'ч назад';
}
else {
return date('d.m.Y H:i:s', $time_);
}
}
if(!$user) { header('location: /'); exit; }
$title ='Модер чат';
include './system/h.php';
echo '<div class="main">';
?>
<div class="pvp_fon">
<?
if($user['save'] == 0) {
echo '<div class='block_zero'><font color='#909090'>Для общения в чате вам нужно сохранить своего персонажа</font></div>';
}
else
{
echo '<div class='block_zero'>';
if($user['level'] < 20) {
echo '<font color='#909090'>Писать в чат можно с <img src='/images/icon/level.png' alt=''/> 20 уровня</font><br>';
}
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: /moder_chat/'.($_GET['clan'] == true ? 'clan/':''));
exit;
}
}
if($text) {
$antiflood = mysql_fetch_array(mysql_query('SELECT * FROM `mod_chat` WHERE `clan` = ''.($_GET['clan'] == true ? $clan['id']:0).'' AND `user` = ''.$user['id'].'' ORDER BY `time` DESC LIMIT 1'));
if(time() - $antiflood['time'] < 2) $errors[] = 'Писать можно только 1 раз в 5 секунд';
if($errors) {
echo '<div class='block' align='center'>';
foreach($errors as $error) {
echo $error.'<br/>';
}
echo '</div>
<div class='mini-line'></div>';
}
else
{
if($_to) {
$text = str_replace($_to['login'].', ', '', $text);
}
mysql_query('INSERT INTO `mod_chat` (`clan`,
`user`,
`to`,
`text`,
`time`) VALUES ("'.($_GET['clan'] == true ? $clan['id']:0).'",
"'.$user['id'].'",
"'.$_to['id'].'",
"'.$text.'",
"'.time().'")');
$_SESSION['msg'] = '<center> <font color="lime"><img src="/images/icon/ok.png"> Сообщения отправлено!</font></center>';
header('location: /moder_chat/'.($_GET['clan'] == true ? 'clan/':''));
}
}
?>
<div id="pokazat">
<a href="#" onClick="document.getElementById('pokazat').style.display='none';document.getElementById('skryt').style.display='';return false;"><img src='/images/smiles/happy.gif'></a>
<div style='float: right;'><? echo bbpanel2('form', 'text').'';?></div> </div>
<div id="skryt" style="display:none">
<a href="#" onClick="document.getElementById('skryt').style.display='none';document.getElementById('pokazat').style.display='';return false;">Скрыть</a>
<p>
<form name='form' method='post' action='/moder_chat/<?=($_GET['clan'] == true ? 'clan/':'')?>?to=<?=$to?>'><div class='fight center'><? echo bbpanel('form', 'text').'';?></div>
<form action='/chat/<?=($_GET['clan'] == true ? 'clan/':'')?>?to=<?=$to?>' method='post'>
<center>
</div> <textarea height="24" width="100%"name='text' style='width: 99%;' class='text'/><?=($to ? $_to['login'].', ':'')?></textarea>
<center><input class='btn22' style='height: 25px;' type='submit' value='Отправить'>
<?
}
?>
<a style='height: 15px;' class="btn22" href="/moder_chat/">Обновить</a><hr>
</form>
</center>
<?
if($_GET['read_all'] == true) {
mysql_query('UPDATE `mod_chat` SET `read` = "1" WHERE '.($_GET['clan'] == true ? '`clan` = "'.$clan['id'].'" AND':'').' `to` = "'.$user['id'].'"');
header('location: /moder_chat/'.($_GET['clan'] == true ? 'clan/':''));
}
$max = 10;
$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `mod_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 `mod_chat` WHERE `id` = "'.$msg.'"');
$i_msg = mysql_fetch_array($i_msg);
if(!$i_msg) {
header('location: /moder_chat/'.($_GET['clan'] == true ? 'clan/':'').'?page='.$page);
exit;
}
if($_GET['clan'] == true && $clan_memb['rank'] == 4 OR $user['access'] > 0) {
mysql_query('DELETE FROM `mod_chat` WHERE `clan` = "'.($_GET['clan'] == true ? $clan['id']:0).'" AND`id` = "'.$i_msg['id'].'"');
}
header('location: /moder_chat/'.($_GET['clan'] == true ? 'clan/':'').'?page='.$page);
}
$q = mysql_query('SELECT * FROM `mod_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 `mod_chat` SET `read` = "1" WHERE `id` = "'.$row['id'].'"');
}
$sender = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['user'].'"');
$sender = mysql_fetch_array($sender);
if($row['user'] == 2){
$sender['login'] = 'Система';
$sender['r'] = 'bot';
}
?>
<font-family: Verdana, Arial, Helvetica, sans-serif>
<div class="one_by_one"><font size=2px>
<img src='/images/icon/race/<?=$sender['r'].($sender['online'] > (time() - 300) ? '':'-off')?>.png' alt='*'/>
<a href='/user/<?=$sender['id']?>/'><?=$sender['login']?> </a>
<?
if($sender['access']==1) {
echo '<font color="lime"><u>Мд</u></font>';
}
if($sender['id']==1) {
echo '<font color="orange"><u>адм</u></font>';
}
if($sender['id']==3) {
echo '<font color="red"><u>Соз</u></font>';
}
?>
<?
if($sender['id'] != $user['id']) {
?> <a href='/moder_chat/<?=($_GET['clan'] == true ? 'clan/':'')?>?to=<?=$sender['id']?>'>(»)</a><?
}
?>:<font color='darkred'><span style="float: right;"><?=test($row['time'] )?></span></font><?
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='lime'>
<?
}
?>
<?=$__to['login']?>,
<?
if($__to['id'] == $user['id']) {
?>
</font>
<?
}
}
if($sender['access'] == 1) {
?>
<font color='#f09060'>
<?
}
if($sender['access'] == 2) {
?>
<font color='#90c0c0'>
<?
}
if($sender['sex']==0) {
?>
<font color='violet'>
<?
}
if($sender['sex']==1) {
?>
<font color='gold'>
<?
}
?>
<?=smiles($row['text'])?>
<?
if($sender['access'] > 0) {
?>
</div>
</font>
</font>
<?
}
}
}
else
{
?>
<font color='#909090'>Сообщений нет</font>
<?
}
?>
<center><div class="dot-line"></div>
<div class="block_zero"><?=pages('/moder_chat/'.($_GET['clan'] == true ? 'clan/':'').'?');?></div>
</center>
<div class="dot-line"></div>
<div class="menuList">
<li><a href='/moder_chat/?read_all=true'><img src='/images/icon/arrow.png' alt='*'/> Отметить все сообщения как прочитанные</a></li>
</div>
<?
}
?>
</div>
<?
include './system/f.php';
?>