<?
/*
=====================================================
 Volkov NET!! - by SaNcHeS Group 
-----------------------------------------------------
 http://AllForCS.RU/
-----------------------------------------------------
 Copyright (c) 2009 SaNcHeS Group
=====================================================
 Данный код защищен авторскими правами
=====================================================
 Файл: guest.php
-----------------------------------------------------
 Назначение: Пользователи
=====================================================
*/

include("./../inc/config.php");
include("./passwd.php");
include("./auth.php");
include("./html.php");

echo $HEAD;
echo $JS_POPUP;
echo $STYLE;
echo $BODY;

print <<<vivod
<table align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="600">
<p>
vivod;

if ($_GET['del']){
$m_id=(int)$_GET['del'];
@mysql_query("DELETE FROM `m3_guest` WHERE `id` = '".$m_id."' LIMIT 1;") or die (mysql_error());
print "<meta http-equiv=\"refresh\" content=\"2;url=guest.php><br><br><br><br><center>Запись удалена!</center></body></html>";
@mysql_free_result();
@mysql_close();
exit;}


if ($_GET['edit']){
$m_id=(int)$_GET['edit'];
@$leet = @mysql_query("SELECT * FROM `m3_guest` WHERE `id` = '".$m_id."' LIMIT 1;") or die (mysql_error());
if ($leet && @mysql_num_rows($leet)>0){
while ($row = mysql_fetch_array($leet, MYSQL_ASSOC))
{
$add_nick=$row['nick'];
$add_mail=$row['mail'];
$add_icq=$row['icq'];
$add_text=$row['text'];
$add_ip=$row['ip'];

}}

echo "<form name='guest_form' action='guest.php?do=ok&event=edit' method='post'>
<p class='mb'>
<table cellpadding='0' cellspacing='0' style='mb'>
<tr>
<td nowrap width='35'>
<p align='right'>Nick:</p>
</td>
<td width='4'>
<p>&nbsp;</p>
</td>
<td nowrap>
<p><input type='text' name='g_nick' value='$add_nick' maxlength='20'></p>
</td>
<td nowrap width='10' rowspan='3'>
<p>&nbsp;</p>
</td>
<td nowrap rowspan='4'>
<p align='right'><textarea name='g_text' rows='4' cols='41'>$add_text</textarea>
<p align='right'><input type='reset' name='rezet' value='Сброс'> &nbsp;<input type='submit' name='ok' value='Изменить!'></p>

</td>
</tr>
<tr>
<td nowrap width='35'>
<p align='right'>Mail:</p>
</td>
<td width='4'>
<p>&nbsp;</p>
</td>
<td nowrap>
<p><input type='text' name='g_mail' value='$add_mail' maxlength='25'></p>
</td>
</tr>
<tr>
<td nowrap width='35'>
<p align='right'>ICQ:</p>
</td>
<td width='4'>
<p>&nbsp;</p>
</td>
<td nowrap>
<p><input type='text' name='g_icq' value='$add_icq' maxlength='9'></p>
</td>
</tr>
<tr>
<td nowrap width='35'>
<p align='right'>IP:</p><br>
</td>
<td width='4'>
<p>&nbsp;</p>
</td>
<td nowrap>
<p><input type='text' name='g_ip' value='$add_ip' maxlength='15'></p><br>
</td>
</tr>
</table>
<input type='hidden' name='g_id' value='$m_id' >
</form>";

@mysql_free_result();
@mysql_close();
exit;}

if (($_GET['do']=="ok")){

$add_nick=substr(safe_str($_POST['g_nick']),0,20);
$add_mail=substr(safe_str($_POST['g_mail']),0,25);
$add_icq=substr(safe_str($_POST['g_icq']),0,10);
$add_date=date("d.m.Y (H:i)"); 
$add_text=substr($add_text, 0, 1257);
$add_text=safe_str($_POST['g_text']);
long_detector($add_text, 35);
if (isset($_POST['g_ip'])){$add_ip=$_POST['g_ip'];}else{
$add_ip=$HTTP_SERVER_VARS["REMOTE_ADDR"];}

if ($add_nick == ""){$no=1;}
if ($add_mail != ""){if ((strrpos($add_mail,' ') > 0) || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$add_mail))){$no=1;}}
if ($show_icq != ""){if (!is_numeric($add_icq)){$no=1;}}
if ($add_text == ""){$no=1;}


if ($_GET['event'] == 'edit')
{
$add_id=(int)$_POST['g_id'];
$dobavim = "UPDATE `m3_guest` SET `nick` = '$add_nick', `mail` = '$add_mail', `icq` = '$add_icq', `text` = '$add_text', `ip` = '$add_ip' WHERE `id` = '$add_id' LIMIT 1;";
$leet = mysql_query($dobavim) or die (mysql_error());


echo "<meta http-equiv=\"refresh\" content=\"0;url=guest.php>";
exit;}

@$leet = @mysql_query("SELECT * FROM `m3_guest` ORDER BY `id` DESC LIMIT 3;") or die (mysql_error());
$ii=0;
if ($leet && @mysql_num_rows($leet)>0){
while ($row = mysql_fetch_array($leet, MYSQL_ASSOC))
{
$ii=$ii+1;
if ($ii == 1){$raz=$row['ip'];}
if ($ii == 2){$dva=$row['ip'];}
if ($ii == 3){$tri=$row['ip'];}
}}
if ($add_ip == $raz and $add_ip == $dva and $add_ip == $tri){$no=1;}
@$leet = @mysql_query("SELECT * FROM `m3_ban` WHERE `ip` = '".$add_ip."';") or die (mysql_error());
if ($leet && @mysql_num_rows($leet)>0){$no=1;}
if ($no != 1){
$dobavim = "INSERT INTO `m3_guest` (nick, mail, icq, date, text, ip) VALUES ('".$add_nick."', '".$add_mail."', '".$add_icq."', '".$add_date."', '".$add_text."', '".$add_ip."');";
$leet = mysql_query($dobavim) or die (mysql_error());
}

echo "<meta http-equiv=\"refresh\" content=\"0;url=guest.php>";
exit;}


echo "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td width=\"100%\" valign=\"top\">
<p><br>".$GUEST_BOOK_INFO."</p>
</td>
<td width=\"300\">
<form name='guest_form' action='guest.php?do=ok' method='post'>
<p class='mb'>
<table cellpadding='0' cellspacing='0' style='mb'>
<tr>
<td nowrap width='35'>
<p align='right'>Nick:</p>
</td>
<td width='4'>
<p>&nbsp;</p>
</td>
<td nowrap>
<p><input type='text' name='g_nick' value='$username' maxlength='20'></p>
</td>
<td nowrap width='10' rowspan='3'>
<p>&nbsp;</p>
</td>
<td nowrap rowspan='3'>
<p align='right'><textarea name='g_text' rows='4' cols='41'></textarea></p>
</td>
</tr>
<tr>
<td nowrap width='35'>
<p align='right'>Mail:</p>
</td>
<td width='4'>
<p>&nbsp;</p>
</td>
<td nowrap>
<p><input type='text' name='g_mail' maxlength='25'></p>
</td>
</tr>
<tr>
<td nowrap width='35'>
<p align='right'>ICQ:</p>
</td>
<td width='4'>
<p>&nbsp;</p>
</td>
<td nowrap>
<p><input type='text' name='g_icq' maxlength='9'></p>
</td>
</tr>
</table><p align='right'><input type='reset' name='rezet' value='Сброс'> &nbsp;<input type='submit' name='ok' value='Насрать!'></p>
</form>
</td>
</tr>
<tr>
<td height=\"8\" colspan=\"2\">
<p>&nbsp;</p>
</td>
</tr>
<tr>
<td colspan=\"2\">";


$sql = mysql_query("SELECT * FROM `m3_guest` ORDER BY `id` DESC;") or die (mysql_error());
if ($sql && @mysql_num_rows($sql)>0){
// Логика построения страниц
$vse=0;
$paga=$_GET['page'];
if ($_GET['page']==null or $_GET['page']==0){$paga=1;}
if (!is_numeric($paga)){exit;}
$l = $paga*$co;
$f = $l-$co;
while ($row = @mysql_fetch_array($sql, MYSQL_ASSOC)){
if ($vse >= $f and $vse < $l)
{
$m3_guest_id=$row['id'];
$m3_guest_date=safe_str($row['date']);
$m3_guest_nick=safe_str($row['nick']);
$m3_guest_icq=safe_str($row['icq']);
$m3_guest_mail=safe_str($row['mail']);
$m3_guest_text=unsafe_str($row['text']);
$m3_guest_ip=$row['ip'];




if ($m3_guest_icq != ""){$MYICQ="&nbsp;<img src=\"../m3_images/icq.gif\" align=\"middle\" width=\"12\" height=\"12\" border=0> ".$m3_guest_icq." ";}
else{$MYICQ="";}

echo "<p class=\"mb\"><b>$m3_guest_date, $m3_guest_nick";
if ($MYICQ!=""){echo ", $MYICQ";}
if ($m3_guest_mail!=""){echo ", $m3_guest_mail";}
echo ", [<a href=\"javascript:na_open_window('IP', 'ip.php?ip=$m3_guest_ip', 150, 200, 200, 25, 0, 0, 0, 0, 0)\"><font color=#FB7700>$m3_guest_ip</font></a>] [<a href='?edit=$m3_guest_id'><font color=#0F00BF>EDIT</font></a>] [<a href='?del=$m3_guest_id'><font color=#BF0000>DEL</font></a>]</b><br>$m3_guest_text</p>";

}
$vse=$vse+1;
}}else{echo "<p class=\"mb\"><b><a>".date("d.m.Y")."</a>, &nbsp;<a href=\"\"><img src=\"../m3_images/icq.gif\" align=\"middle\" width=\"12\" height=\"12\" border=0></a> <a href=\"mailto:\">Admin:</a></b><br>нет ни одного сообщения!</p>";}
$guestdata="";
@$paga=$vse/$co+1;
for ($i=1;$i<$paga;$i++){if ($i == $paga){$guestdata.=" ".$i;}else{$guestdata.=" <a href='?page=".$i."'>".$i."</a>";}}
if ($guestdata == ""){$guestdata = "1";}
echo "<p align=\"center\" class=\"mb\"><small>".$guestdata."</small></p>";
echo "</td></tr></table>";


print "</p></td></tr></table>";
echo $FOOT;
@mysql_free_result();
@mysql_close();
?>