<?php
include 'inclydings/gzips.php';
include 'mysql.php';
Error_Reporting(E_ALL & ~E_NOTICE);
Error_Reporting (ERROR | WARNING);
include_once("inclydings/zag.php");
include 'inclydings/ini.php';
include 'inclydings/sesi.php';
if (isset($user)) {

switch($_GET[mod]){

default:
$req = mysql_query("SELECT * FROM `rega` WHERE `chat` = '1' LIMIT 1");
////////////////////////////
if (mysql_num_rows($req)==1){echo"Чат временно закрыт администрацией!";


include($path.'inclydings/down.php');
exit;}
$req = mysql_query("SELECT * FROM `out` WHERE `usr` = '$log' LIMIT 1");
////////////////////////////
$avto=mysql_num_rows($req);
if($avto==1){
header ('Location: gorod.php?');exit;
}
function smiles($string){
$dir = opendir ("pik4erspic/smiles"); 
while ($file = readdir ($dir)) {
if (ereg (".gif$", "$file")){
$file2=str_replace(".gif","",$file);
$string=str_replace(":$file2",'<img src="pik4erspic/smiles/'.$file.'" alt="">',$string);
}}
closedir ($dir);
return $string;  }
/////////////
$rand = rand(1000,9999);
///////////////////
include_once"inclydings/xtoonlinechat.php";
echo "  <br/><br/><a href=\"sm.php?$sd\">Смайлы</a> /<a href=\"chat.php?$sd&r=$rand\">Обновить</a><br/>";
echo "<form action=\"chat_torg.php?$sd&mod=writes\" method=\"POST\">";
echo "<input type=\"text\" name=\"zin\" maxlength=\"5000\"/> <input type=\"submit\" value=\"Написать\" class=\"ibutton\"><br>";
echo "<br>";

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 komentaras2 FROM table_komentarai2"));
if($viso>=100){
mysql_query("DELETE FROM `table_komentarai2` ORDER BY `id` LIMIT 50");
}
$puslap = floor($viso/5);
$times = date("H:i");
$asd = mysql_query("SELECT * FROM table_komentarai2 ORDER BY id DESC LIMIT $num,10");
echo"<div align='left'>";
while($dsa = mysql_fetch_array($asd))
{
$time_ban=time()+$_POST[time];
$nickas = strip_tags($dsa['nick']);
$koment = strip_tags($dsa['komentaras2']);
$time = strip_tags($dsa['time']);
$koment = smiles($koment);
$elita=mysql_query("SELECT * FROM `table_admin` WHERE `nick`='$log' LIMIT 1");
$pic = mysql_fetch_array($req);

if($pic['nick']==$log){$koment='<font color="lime">'.$koment.'</font>';}
if($pic['prava']==5){$koment='<font color="blue">'.$koment.'</font>';}


echo" <a href=\"chat_torg.php?$sd&nick=$nickas&amp;mod=write\">$nickas</a>";
$elita=mysql_query("SELECT * FROM `table_admin` WHERE `nick`='$log' LIMIT 1");
if(mysql_num_rows($elita)==1){
echo'<font color="lime">.GM</font>';
}
$elita=mysql_query("SELECT * FROM `table_mod666er` WHERE `nick`='$log' LIMIT 1");
if(mysql_num_rows($elita)==1){
echo'<font color="blue">.M</font>';
}

echo" <a href=\"search.php?$sd&nick=$nickas&amp;go=go\">[?]</a> : $koment  <small><font color=#999999> [$time]</font></small>";
$elita=mysql_query("SELECT * FROM `table_admin` WHERE `nick`='$log' LIMIT 1");
if(mysql_num_rows($elita)==1){
echo" [<a href=\"chat_torg.php?$sd&mod=del_post&amp;rs=$dsa[id]\">X</a>]";
}
echo'<br/>';
}
echo "</div>";
echo "<br/>";
if ($_GET[page] > 0)
{
echo "<a href=\"chat_torg.php?$sd&page=$back\">пред</a>";
}
elseif ($_GET[page] == 0)
{
echo "пред";
}
echo"|";
if($_GET[page] < $puslap || $_GET[page] == "" || $_GET[page] == 0)
{echo "<a href=\"chat_torg.php?$sd&page=$next\">cлед</a>";}
else
{echo "cлед";}
break;

case 'del_post':
$elita=mysql_query("SELECT * FROM `table_admin` WHERE `nick`='$log' LIMIT 1");
if(mysql_num_rows($elita)==1){

if(empty($_GET[rs])){
echo"Невыбран пост!<br/>";
}else{
$asd = mysql_query("SELECT * FROM table_komentarai2 WHERE id='".mysql_real_escape_string($_GET['rs'])."' LIMIT 1");
$avto=mysql_num_rows($asd);
if($avto==0){
echo'Нет такого поста!<br/>';
}else{
mysql_query("DELETE FROM `table_komentarai2` WHERE id='".mysql_real_escape_string($_GET['rs'])."' LIMIT 1");
header ('Location: chat_torg.php?'.$sd.'');
}
}
}else{
echo "Ошибка!Доступ закрыт!";
}
break;

case 'write':

echo"<b>Сообщение</b><br/>";
echo "<form action=\"chat_torg.php?$sd&mod=writes\" method=\"POST\">";
if (isset($_GET[nick]))
{
$_GET[nick] = htmlspecialchars($_GET[nick]);
echo "<input type=\"text\" name=\"zin\" maxlength=\"250\" value=\"$_GET[nick], \" size=\"10\"/><br/>";
}
else
{
echo "<input type=\"text\" name=\"zin\" maxlength=\"250\" size=\"10\"/><br/>";
}
echo "<input type=\"submit\" value=\"Ok\" class=\"ibutton\"><br/>";
break;

case 'writes':

if($udata[9]<"10"){echo"В чате нельзя писать до 10 уровня."; include_once"inclydings/down.php"; exit;}



$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 = addslashes($msg);
$msg=preg_replace ("|[\r\n]+|si","",$msg);
$a = mysql_num_rows(mysql_query("SELECT komentaras2 FROM table_komentarai2 WHERE komentaras2 = '$msg'"));
$b = mysql_fetch_array(mysql_query("SELECT kada FROM table_komentarai2 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 d.m.y");
if($data_dbr >= $data_kom && $msg != "")
{
mysql_query("INSERT INTO table_komentarai2 SET nick = '$log', komentaras2 = '$msg', kada = '$data', time = '$time'");
$rand = rand(1000,9999);
header ('Location: chat_torg.php?'.$sd.'');
}
elseif($data_dbr < $data_kom)
{
$sec = $data_kom-$data_dbr;
$rand = rand(1000,9999);
header ('Location: chat_torg.php?'.$sd.'');
}
elseif($msg == "")
{
$rand = rand(1000,9999);
header ('Location: chat_torg.php?'.$sd.'');
}
else
{
$rand = rand(1000,9999);
header ('Location: chat_torg.php?'.$sd.'');
}

break;
}

}else{echo"Пароль или ник неверен. Возможно сессия устарела. Попробуйте авторизироваться заново.";}
include 'inclydings/down.php';
?>
