<?
include_once "../SYSTEM/include/functions.php";
include_once "../SYSTEM/include/mp3.php";
include_once "../SYSTEM/include/mysql.php";
include_once "../SYSTEM/include/param.php";
include_once "../SYSTEM/include/ban.php";
include_once "../SYSTEM/include/sess.php";
include_once "../SYSTEM/include/ban_2.php";
include_once "../SYSTEM/include/theme.php";
$title='Комментарии';
$mesto='В загрузках';
head();
$k_page=1;
if (!isset($_GET['file'])){
header ("Location: index.php?".SID."");exit;}

if (!is_file("$folder_level$set[loaddir]$_GET[file]"))
{header ("Location: index.php?".SID."");exit;}
$file1=mysql_escape_string($_GET['file']);

if (is_file("$folder_level$set[loaddir]$_GET[file]"))
{
$file2=explode("/",$file1);
$i=count($file2);
$i=$i-1;
$filename=$file2[$i];

$filesize= filesize("$folder_level$set[loaddir]$_GET[file]");
}
else
{
header ("Location: index.php?".SID."");exit;
}



if (isset($_GET['act']) && $_GET['act']=='add' && isset($_POST['msg']) && isset ($user))
{
$msg=$_POST['msg'];
$msg = iconv('utf-8', 'windows-1251', $msg);
$msg=substr($msg, 0, 512);
$msg = iconv('windows-1251', 'utf-8', $msg);
$msg=stripcslashes(htmlspecialchars($msg));
$msg=str_replace("\r\n","<br />",$msg);
$msg=str_replace("\r","<br />",$msg);
$msg=str_replace("\n","<br />",$msg);

if (isset($_POST['tr']))
{
$msg=translit($msg);
}


if ($msg=='')
{
header("Location: index.php?".SID."&l=$file1");
exit;
}

$msg_t=base64_encode($msg);

$time_q=$time-30;
$q = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]loads_komm` WHERE `file` = '$filename' AND `time` > '$time_q' AND `msg` = '$msg_t' AND `id_us` = '$user[id]';");
$repeat=mysql_result($q, 0);
if ($repeat==0)
{


mysql_query("INSERT INTO `$mysql[pref]loads_komm` (file, time, msg, id_us, size)
values('$filename', '$time', '$msg_t', '$user[id]', '$filesize');");


ball_add();
$komm_add=1;


}
}


$q = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]loads_komm` WHERE `file` = '$filename' AND `size` = '$filesize';");
$k_post = mysql_result($q, 0);
$file=explode("/",$file1);
$i=count($file);
$i=$i-1;
$filename=$file[$i];
if (isset($user))
{
$k_p_str=$user['k_page'];
}
else
{
$k_p_str=$set['k_p_s'];
}
if ($k_post!="0")
{
$v_pages_okr=$k_post/$k_p_str%100;
$v_pages_tochn=$k_post/$k_p_str;
if ($v_pages_okr==$v_pages_tochn)
{
$k_page=$v_pages_okr;
}
else
{
$k_page=$v_pages_okr+1;
}
}
$page=1;
if (isset($_GET['page']) && $_GET['page']!='')
{
if ($_GET['page']=='end')
{
$page=$k_page;
}
else
{
$page=intval($_GET['page']);
}
}
$page=intval($page);
if ($k_page<$page){$page=$k_page;}
if (0>$page){$page=1;}
$i=$k_p_str*$page-$k_p_str;
$q2 = mysql_query("SELECT * FROM `$mysql[pref]loads_komm` WHERE `file` = '$filename' ORDER BY time DESC LIMIT $i, $k_p_str;");


echo "<div class=\"h\">$filename</div><hr />\n";

if (isset($komm_add))echo "<span style=\"color:$color[msg]\"><b>Комментарий успешно добавлен</b></span>\n<hr />\n";

if ($mail_in_new>0)echo "<div class=\"privat\"><img src=\"../SYSTEM/themes/$them/img/mail0.gif\" alt=\"\" /> <a href=\"../mail.php?act=in\">Приват</a> [$mail_in_new]</div><hr />\n";

if ($k_post>0)
{

while ($post = mysql_fetch_array($q2))
{
$timep=vremja($post['time']+$timesdvig);



echo "<div class=\"mess\">\n";

user_pic($post['id_us']);
user_nick($post['id_us'], "../info.php?id=$post[id_us]");



echo "<br />\n";
echo "<span style=\"color:$color[post_time]\">[$timep]</span>";
echo "<br />\n";

echo "<span style=\"color:$color[post]\">".bbcode(smiles(links(base64_decode($post['msg']))))."</span>";
echo "</div>\n";
echo "<br />\n";
}
}
else
{
echo "Нет комментариев<br />\n";
}
echo "<hr />\n<div class=\"str\">";
echo "Стр: [";
if ($page!=1)
{
echo "<a href=\"komm.php?act=add&amp;file=$file1&amp;size=$filesize&amp;page=1\">1</a>";
}
else
{
echo "<b>1</b>";
}
$in=-3;
$out=3;
for ($ot=$in; $ot<=$out; $ot++)
{
$t_str=$page+$ot;
if ($t_str>1 && $t_str<$k_page)
{
if ($in==$ot && $t_str>2)
{
echo " ..";
}
if ($ot!=0)
{
echo " <a href=\"komm.php?act=add&amp;file=$file1&amp;size=$filesize&amp;page=$t_str\">$t_str</a>";
}
else
{
echo " <b>$t_str</b>";
}
if ($ot==$out && $t_str<$k_page-1)
{
echo " ..";
}
}
}
if ($page!=$k_page)
{
echo " <a href=\"komm.php?act=add&amp;file=$file1&amp;size=$filesize&amp;page=end\">$k_page</a>";
}
elseif ($k_page>1)
{
echo " <b>$k_page</b>";
}
echo "]";
echo "</div>\n";

echo "<hr />\n";
if (isset($user))
{
echo "<form method=\"post\" action=\"komm.php?act=add&amp;file=$file1&amp;size=$filesize&amp;page=$page\">\n";

echo "Комментировать:<br />\n<textarea name=\"msg\" class=\"form\" rows=\"3\"></textarea><br />\n";
echo "<input type=\"checkbox\" class=\"form\" name=\"tr\" value=\"1\" /> Транслит<br />\n";
echo "<input value=\"Добавить\" class=\"form\" type=\"submit\" />\n";


echo "</form>\n";
}




echo "<a href=\"index.php?l=$file1\">К описанию</a><br />\n";
echo "<a href=\"../index.php\">&lt;&lt; На главную</a>\n";

foot();
?>
