<?php
/* ЧАТ ИГРЫ "ВОЙНА БОГОВ - БЕССМЕРТНЫЕ" */
define('PROTECTOR', 1);

include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
$textl='Чат';
include($path.'files/core.php');
include($path.'files/head.php');
include($path.'files/zag.php');



echo'<div class="main"><div class="block_zero">';

$avto=mysql_num_rows(mysql_query("SELECT * FROM `ban` WHERE `usr` = '$log' LIMIT 1"));
if ($avto==1){
$vrem=$ban['ban_time']-time();
echo'<div class="main"><div class="block_zero"><span style="color: #ff3434;">Ваш персонаж забанен, доступ в чат закрыт!<br>Осталось: '.Sec2Time($vrem).'<br>Забанил: '.$ban['admin'].'</span></div></div>';
include($path.'files/down.php');exit;
}
switch($_GET['mod']){
default:

if($udata['lvl']<5){
echo'<div class="main"><div class="block_zero center">В чате можно писать с 5 уровня.</div></div>';
break;
}

function smiles($string){
$dir = opendir ("image/smiles"); 
while ($file = readdir ($dir)) {
if (ereg (".gif$", "$file")){
$file2=str_replace(".gif","",$file);
$string=str_replace(":$file2",'<img src="image/smiles/'.$file.'" alt="*">',$string);
}
}
closedir ($dir);
return $string;
}
$rand = rand(1000,9999);


echo'<form action="chat.php?mod=writes" method="POST">';
echo'<input class="text large" type="text" size="100%" name="zin" maxlength="250"><span class="btn"><span class="end"><input class="label" type="submit" value="Отправить"></span></span>';
echo'<a href="chat.php?r='.$rand.'"><span style="color: #999;"> Обновить</span></a>';
echo'</div><div class="mini-line"></div><div class="block_zero">';
//-----УСТАНОВКА НАВИГАЦИИ-----//
if ($_GET['page'] == "" || $_GET['page'] < 0 || $_GET['page'] == "0") {
$_GET['page'] = 0;
}
$next = $_GET['page'] + 1;
$back = $_GET['page'] - 1;
$num = $_GET['page'] * 10;
if($_GET['page'] == "0"){
$i = 1;
}else{$i = ($_GET['page']*10)+1;
}
$viso = mysql_num_rows(mysql_query("SELECT `komentaras` FROM `komentarai`"));
$puslap = floor($viso/10);
//-----КОНЕЦ УСТАНОВКИ НАВИГАЦИИ-----//

$times = date("H:i:d");
$asd = mysql_query("SELECT * FROM `komentarai` ORDER BY `id` DESC LIMIT $num,10");
echo"<div align='left'>";
while($dsa = mysql_fetch_array($asd)){
$nickas = strip_tags($dsa['nick']);
$koment = strip_tags($dsa['komentaras']);
$time = strip_tags($dsa['time']);
$koment = smiles($koment);
$req = mysql_query("SELECT * FROM `users` WHERE `usr` = '$nickas'");
$usdata = mysql_fetch_array($req);
if($usdata['prava']=="5"){$im='adm';$tcolor='9BC';$tcol='9BC';}
if($usdata['prava']=="2"){$im='mod';$tcolor='f96';$tcol='f96';}
if($usdata['prava']=="3"){$im='mod3';$tcolor='f96';$tcol='f96';}
if($usdata['prava']=="4"){$im='adm';$tcolor='9cc';$tcol='9cc';}
if($usdata['prava']=="0"){$tcolor='fff';$tcol='fc6';}
if($usdata['prava']=="1"){$tcolor='999';$tcol='fc6';}

$refi = mysql_fetch_assoc(mysql_query("SELECT `vip` FROM `set` WHERE `usr` = '$nickas' LIMIT 1"));

if($usdata['storona']=='white'){
$p=1;
}else{
$p=0;
}
$laikas = 300;
$dabar = time();
$timeout = $dabar - $laikas;
$asdm = mysql_num_rows(mysql_query("SELECT `laikas`, `usr` FROM `online` WHERE `laikas` > '$timeout' AND `usr` = '$nickas'"));
if($asdm==0){
$gde='off';
}else{
$gde='';
}
if($refi['vip']=='on'){
$tcol='939';
echo'<img src="image/status/vip.png" width="13 height="13" alt="*"> ';
}
elseif($usdata['prava']!=='0'){
echo'<img src="image/status/'.$usdata['pol'].''.$im.'.png" alt="*">';
}else{
echo'<img src="image/icon/'.$p.''.$gde.'.png" alt="*">';
}
echo'<a href="search.php?nick='.$nickas.'&amp;go=go"><span style="color: #'.$tcol.';"> '.$nickas.'</span></a><a href="chat.php?nick='.$nickas.'&amp;mod=write"> (»)</a> <span style="color: #999;"> <small> '.$time.'</small></span><br>';
echo'<span style="color: #'.$tcolor.';">';
$koment=html_entity_decode($koment);

if($nickas=$log){
$nick='<span style="color: #9c9;">'.$nickas.'</span>';
}
$koment=str_replace($nickas,$nick,$koment);
echo' '.$koment.'</span>';
if($udata['prava']>=2){
echo'<a href="chat.php?mod=del_post&amp;p='.$dsa['id'].'"> (X)</a>';
}
echo'</div></div><div class="dot-line"></div><div class="block_zero"><div class="main">';
}
//-----НАВИГАЦИЯ-----//
if ($_GET['page'] > 0){
echo'<a href="chat.php?page='.$back.'"><< Назад - |</a>';
}

if($_GET['page'] < $puslap || $_GET['page'] == "" || $_GET['page'] == 0)
{
echo'<a href="chat.php?page='.$next.'">| - Далее >></a>';
}
//-----КОНЕЦ НАВИГАЦИИ-----//
echo'</div></div><div class="mini-line"></div><div class="menuList">';
echo'<li><a href="smile.php?"><img src="image/icon/arrow.png" alt="*">Смайлы</a></li>';
if($udata['prava'] >= 5){
echo'<li><a href="chat.php?mod=trinti"><img src="image/icon/arrow.png" alt="*"><span style="color: #9cc;">Очистить чат</span></a></li>';
}

break;

case 'del_post':
if($udata['prava'] >= 2){
if(empty($_GET['p'])){
echo'Не выбран пост!<br>';
}else{
$_GET['p'] = htmlspecialchars(stripslashes(addslashes($_GET['p'])));
$asd = mysql_query("SELECT * FROM `komentarai` WHERE `id` = '$_GET[p]' LIMIT 1");
$avto=mysql_num_rows($asd);
if($avto==0){
echo'Нет такого поста!<br>';
}else{
mysql_query("DELETE FROM `komentarai` WHERE id='$_GET[p]' LIMIT 1");
header('Location: chat.php?');
$_SESSION['message'] = 'Сообщение удалено!';
exit();
}
}
}else{
echo'Ошибка! Доступ закрыт!';
}
break;

case 'write':
echo'<form action="chat.php?mod=writes" method="POST">';
if (isset($_GET['nick'])){
$_GET['nick'] = htmlspecialchars($_GET['nick']);
echo'<input class="text large" type="text" name="zin" maxlength="250" value="'.$_GET['nick'].', "><br>';
}else{
echo'<input class="text large" name="zin" maxlength="250"><br>';
}
echo'<span class="btn"><span class="end"><input class="label" type="submit" value="Отправить"></span></span>';
echo'<a href="chat.php?"><span style="color: #999;"> Назад</span></a>';
break;

case 'writes':
$msg=$_POST['zin'];
$msg=substr($msg, 0, 512);
$msg=stripslashes(htmlspecialchars($msg));
$msg=str_replace("\r\n","<br />",$msg);
$msg=str_replace("\r","<br />",$msg);
$msg=str_replace("\n","<br />",$msg);
$msg=eregi_replace("((https?|ftp|http)://[[:alnum:]_=/-]+(\\.[[:alnum:]_=/-]+)*(/[[:alnum:]+&._=/%]*(\\?[[:alnum:]?+&_=/%]*)?)?).(ru|org|info|org.ua|h2m.ru|wen.ru|com|game-l2.ru з|tiwar.ru|l2wap.ru з|l2full.ru з|game-l2 .ru з)", "Реклама запрещена", $msg);
$msg=eregi_replace("([[:alnum:]_=/-]+(\\.[[:alnum:]_=/-]+)*(/[[:alnum:]+&._=/%]*(\\?[[:alnum:]?+&_=/%]*)?)?).(ru|org|info|org.ua|h2m.ru|wen.ru|com|tiwar.ru|game-l2.ru з|l2wap.ru з|l2full.ru з|game-l2 .ru з)", "Реклама запрещена", $msg);
$msg = addslashes($msg);
$msg=preg_replace ("|[\r\n]+|si","",$msg);
$a = mysql_num_rows(mysql_query("SELECT `komentaras` FROM `komentarai` WHERE `komentaras` = '$msg'"));
$b = mysql_fetch_array(mysql_query("SELECT * FROM `komentarai` WHERE `nick` = '$log' ORDER BY `kada` DESC LIMIT 1"));
$data_kom = strip_tags($b['kada']);
$data = date("y/m/d H:i:s", strtotime("+20 seconds"));
$data_dbr = date("y/m/d H:i:s");
$time = date("H:i");
if($data_dbr >= $data_kom && $msg != "" && $msg!=$b['komentaras'] ){
mysql_query("INSERT INTO `komentarai` SET `nick` = '$log', `komentaras` = '$msg', `kada` = '$data', `time` = '$time'");
$rand = rand(1000,9999);

function smiles($string){
$dir = opendir ("image/smiles"); 
while ($file = readdir ($dir)) {
if (ereg (".gif$", "$file")){
$file2=str_replace(".gif","",$file);
$string=str_replace(":$file2",'<img src="image/smiles/'.$file.'" alt="">',$string);
}
}
closedir ($dir);
return $string;
}
$rand = rand(1000,9999);
echo'<form action="chat.php?mod=writes" method="POST">';
echo'<input class="text large" type="text" name="zin" maxlength="250">';
echo'<span class="btn"><span class="end"><input class="label" type="submit" value="Отправить"></span></span>';
echo'<a href="chat.php?r='.$rand.'"><span style="color: #999;"> Обновить</span></a>';
echo'</div><div class="mini-line"></div><div class="block_zero">';

if ($_GET['page'] == "" || $_GET['page'] < 0 || $_GET['page'] == "0") {
$_GET['page'] = 0;
}
$next = $_GET['page'] + 1;
$back = $_GET['page'] - 1;
$num = $_GET['page'] * 10;
if($_GET['page'] == "0")
{
$i = 1;
}
else{$i = ($_GET['page']*10)+1;
}
$viso = mysql_num_rows(mysql_query("SELECT `komentaras` FROM `komentarai`"));
$puslap = floor($viso/10);
$times = date("H:i");
$asd = mysql_query("SELECT * FROM `komentarai` ORDER BY `id` DESC LIMIT $num,10");
echo"<div align='left'>";
while($dsa = mysql_fetch_array($asd)){
$nickas = strip_tags($dsa['nick']);
$koment = strip_tags($dsa['komentaras']);
$time = strip_tags($dsa['time']);
$koment = smiles($koment);
$req = mysql_query("SELECT * FROM `users` WHERE `usr` = '$nickas'");
$usdata = mysql_fetch_array($req);
if($usdata['prava']=="5"){$im='adm';$tcolor='9BC';$tcol='9BC';}
if($usdata['prava']=="2"){$im='mod';$tcolor='f96';$tcol='f96';}
if($usdata['prava']=="3"){$im='mod3';$tcolor='f96';$tcol='f96';}
if($usdata['prava']=="4"){$im='adm';$tcolor='9cc';$tcol='9cc';}
if($usdata['prava']=="0"){$tcolor='fff';$tcol='fc6';}
if($usdata['prava']=="1"){$tcolor='999';$tcol='fc6';}

$refi = mysql_fetch_assoc(mysql_query("SELECT `vip` FROM `set` WHERE `usr` = '$nickas' LIMIT 1"));

if($usdata['storona']=='white'){
$p=1;
}else{
$p=0;
}
$laikas = 300;
$dabar = time();
$timeout = $dabar - $laikas;
$asdm = mysql_num_rows(mysql_query("SELECT `laikas`, `usr` FROM `online` WHERE `laikas` > '$timeout' AND `usr` = '$nickas'"));
if($asdm==0){
$gde='off';
}else{
$gde='';
}
if($refi['vip']=='on'){
$tcol='939';
echo'<img src="image/status/vip.png" width="13 height="13" alt="*"> ';
}
elseif($usdata['prava']!=='0'){
echo'<img src="image/status/'.$usdata['pol'].''.$im.'.png" alt="*">';
}else{
echo'<img src="image/icon/'.$p.''.$gde.'.png" alt="*">';
}
echo'<a href="search.php?nick='.$nickas.'&amp;go=go"><span style="color: #'.$tcol.';"> '.$nickas.'</span></a><a href="chat.php?nick='.$nickas.'&amp;mod=write"> (»)</a> <span style="color: #999;"> <small> '.$time.'</small></span><br>';
echo'<span style="color: #'.$tcolor.';">';
$koment=html_entity_decode($koment);
if($nickas=$log){
$nick='<span style="color: #9c9;">'.$nickas.'</span>';
}
$koment=str_replace($nickas,$nick,$koment);
echo' '.$koment.'</span>';
if($udata['prava']>=2){
echo'<a href="chat.php?mod=del_post&amp;p='.$dsa['id'].'"> (X)</a>';
}
echo'</div></div><div class="dot-line"></div><div class="block_zero"><div class="main">';
}

//-----НАВИГАЦИЯ-----//
if ($_GET['page'] > 0){
echo'<a href="chat.php?page='.$back.'"><< Назад - |</a>';
}

if($_GET['page'] < $puslap || $_GET['page'] == "" || $_GET['page'] == 0)
{
echo'<a href="chat.php?page='.$next.'">| - Далее >></a>';
}
//-----КОНЕЦ НАВИГАЦИИ-----//

echo'</div></div><div class="mini-line"></div><div class="menuList">';
echo'<li><a href="smile.php?"><img src="image/icon/arrow.png" alt="*">Смайлы</a></li>';
if($udata['prava'] >= 5){
echo'<li><a href="chat.php?mod=trinti"><img src="image/icon/arrow.png" alt="*"><span style="color: #9cc;">Очистить чат</span></a></li>';
}
}
elseif($msg==$b['komentaras']){
$rand = rand(1000,9999);
echo "Ваше сообщение повторяет предыдущее!<br/>";
echo"<a href=\"chat.php?r=$rand\">Продолжить</a>";
}
elseif($data_dbr < $data_kom){
$sec = $data_kom-$data_dbr;
$rand = rand(1000,9999);
echo "Защита от Флуда! Подождите $sec секунд<br/>";
echo"<a href=\"chat.php?r=$rand\">Продолжить</a>";
}
elseif($msg == ""){
$rand = rand(1000,9999);
echo "Вы не написали сообщение!<br/>";
echo"<a href=\"chat.php?r=$rand\">Продолжить</a>";
}else{
$rand = rand(1000,9999);
echo "Ошибка!<br/>";
echo"<a href=\"chat.php?r=$rand\">Продолжить</a>";
}
break;

case 'trinti':
if($udata['prava'] >=5){
mysql_query("DELETE FROM `komentarai`");
header('Location: chat.php?');
$_SESSION['message'] = 'Чат очищен!';
exit();
}else{
echo "Ошибка! Доступ закрыт!<br/></div>";
}
break;
}
echo'</div></div></div>';
include($path.'files/down.php');
?>