<?
/*
=====================================================
 Volkov NET!! - by SaNcHeS Group 
-----------------------------------------------------
 http://AllForCS.RU/
-----------------------------------------------------
 Copyright (c) 2009 SaNcHeS Group
=====================================================
 Данный код защищен авторскими правами
=====================================================
 Файл: comments.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_comments` WHERE `id` = '".$m_id."' LIMIT 1;") or die (mysql_error());
print "<meta http-equiv=\"refresh\" content=\"2;url=comments.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_comments` 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='comments.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");
$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_comments` 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=comments.php>";
exit;}}


$sql = mysql_query("SELECT m3_comments.id as nomer, m3_comments.date as date1, nick, icq, mail, text, m3_mp3.id as nomer2, m3_mp3.ip, m3_mp3.track, m3_mp3.artist, m3_mp3.date as date2, count, size FROM `m3_comments` INNER JOIN `m3_mp3` ON m3_comments.id_mp3 = m3_mp3.id ORDER BY m3_comments.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['nomer'];
$m3_guest_tid=$row['nomer2'];
$m3_guest_artist=unsafe_str($row['artist']);
$m3_guest_track=unsafe_str($row['track']);
$m3_guest_size=$row['size'];
$m3_guest_count=(int)$row['count'];
$m3_guest_artist=$row['artist'];
$m3_guest_date2=$row['date2'];
$m3_guest_date=safe_str($row['date1']);
$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><a href=\"javascript:na_open_window('comments', '../comments.php?id=$m3_guest_tid', 100, 100, 500, 400, 0, 0, 0, 0, 0)\"><img src='../m3_images/arrow.gif' width='15' height='15' border=0></a>&nbsp;<a href=\"javascript:na_open_window('edit', 'music.php?event=edit&id=$m3_guest_tid', 150, 150, 300, 150, 0, 0, 0, 1, 0)\">$m3_guest_artist - $m3_guest_track</a> // размер: <font color=red>$m3_guest_size</font> загрузок: <font color=red>$m3_guest_count</font><br>$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();

?>