Файл: chat.php
Строк: 145
<?php
define('PROTECTOR', 1);
$headmod = 'chat';//фикс. места
$textl='Чат';
include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
include($path.'files/core.php');
include($path.'files/head.php');
include($path.'files/zag.php');
switch($_GET[mod]){
default:
function smiles($string){
$dir = opendir ("pic/smiles");
while ($file = readdir ($dir)) {
if (ereg (".gif$", "$file")){
$file2=str_replace(".gif","",$file);
$string=str_replace(":$file2",'<img src="pic/smiles/'.$file.'" alt="">',$string);
}}
closedir ($dir);
return $string; }
/////////////
$rand = rand(1000,9999);
///////////////////
echo'<div class="hid" align="left">';
echo "<a href="smile.php?">Смайлы</a><br/>";
echo "<a href="chat.php?r=$rand">Обновить</a>";
echo "<form action="chat.php?mod=writes" method="POST">";
echo "<input type="text" name="zin" maxlength="5000"/> <input type="submit" value="Написать" class="ibutton"></div>";
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");
echo "<center>-=$times=-</center>";
$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);
echo "<b>[$time]<a href="chat.php?nick=$nickas&mod=write">$nickas</a>
<a href="search.php?nick=$nickas&go=go">[i]</a>:</b> $koment ";
if($udata[prava]>=2){
echo"[<a href="chat.php?mod=del_post&p=$dsa[id]">X</a>]";
}
echo'<br/>';
}
echo "</div>";
if($udata[prava] >= 2)
{
echo "<a href="chat.php?mod=trinti">Удалить сообщения</a><br/>";
}
if ($_GET[page] > 0)
{
echo "<a href="chat.php?page=$back">Назад</a>";
}
elseif ($_GET[page] == 0)
{
echo "Назад";
}
echo"|";
if($_GET[page] < $puslap || $_GET[page] == "" || $_GET[page] == 0)
{echo "<a href="chat.php?page=$next">Далее</a>";}
else
{echo "Далее";}
break;
case 'del_post':
if($udata[prava] >= 2)
{
if(empty($_GET[p])){
echo"Не выбран пост!<br/>";
}else{
$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");
echo'Пост успешно удалён!<br/>';
echo "<a href="chat.php?">Назад</a>";
}
}
}else{
echo "Ошибка!Доступ закрыт!";
}
break;
case 'write':
echo"<b>Сообщение</b><br/>";
echo "<form action="chat.php?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/>";
echo "<img src='img/feather.png' alt=''><a href="chat.php?">Назад</a><br>";
break;
case 'writes':
$msg=$_POST['zin'];
$msg=substr($msg, 0, 512);
$msg=stripslashes(htmlspecialchars($msg));
$msg=str_replace("rn","<br />",$msg);
$msg=str_replace("r","<br />",$msg);
$msg=str_replace("n","<br />",$msg);
$msg = addslashes($msg);
$msg=preg_replace ("|[rn]+|si","",$msg);
$a = mysql_num_rows(mysql_query("SELECT komentaras FROM komentarai WHERE komentaras = '$msg'"));
$b = mysql_fetch_array(mysql_query("SELECT kada 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 != "")
{
mysql_query("INSERT INTO komentarai SET nick = '$log', komentaras = '$msg', kada = '$data', time = '$time'");
$rand = rand(1000,9999);
//start
function smiles($string){
$dir = opendir ("pic/smiles");
while ($file = readdir ($dir)) {
if (ereg (".gif$", "$file")){
$file2=str_replace(".gif","",$file);
$string=str_replace(":$file2",'<img src="pic/smiles/'.$file.'" alt="">',$string);
}}
closedir ($dir);
return $string; }
/////////////
$rand = rand(1000,9999);
///////////////////
echo'<div class="hid" align="left">';
echo "<a href="smile.php?">Смайлы</a><br/>";
echo "<a href="chat.php?r=$rand">Обновить</a>";
echo "<form action="chat.php?mod=writes" method="POST">";
echo "<input type="text" name="zin" maxlength="5000"/> <input type="submit" value="Написать" class="ibutton"></div>";
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");
echo "<center>-=$times=-</center>";
$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);
echo "<b>[$time]<a href="chat.php?nick=$nickas&mod=write">$nickas</a>
<a href="search.php?nick=$nickas&go=go">[i]</a>:</b> $koment ";
if($udata[prava]>=2){
echo"[<a href="chat.php?mod=del_post&p=$dsa[id]">X</a>]";
}
echo'<br/>';
}
echo "</div>";
if($udata[prava] >= 2)
{
echo "<a href="chat.php?mod=trinti">Удалить сообщения</a><br/>";
}
if ($_GET[page] > 0)
{
echo "<a href="chat.php?page=$back">Назад</a>";
}
elseif ($_GET[page] == 0)
{
echo "Назад";
}
echo"|";
if($_GET[page] < $puslap || $_GET[page] == "" || $_GET[page] == 0)
{echo "<a href="chat.php?page=$next">Далее</a>";}
else
{echo "Далее";}
//end
}
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] >= 2)
{
mysql_query("DELETE FROM komentarai");
echo "Все сообщения удалены!";
echo "<br/><a href="chat.php?">Назад</a><br/></div>";
}
else
{
echo "Ошибка!Доступ закрыт!<br/></div>";
}
break;
}
include($path.'files/down.php');
?>