View file waplend/down/komm.php

File size: 3.68Kb
<?
include"../tools.php";
include"../head.php";
include"config.php";
include"functions.php";
$k_page=1;
if (!isset($_GET['file'])){
header ("Location: index.php?".SID."");}

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



if (isset($_GET['act']) && $_GET['act']=='add' && isset($_POST['msg']) && isset($_SESSION['login']))
{
$msg=$_POST['msg'];
$msg = iconv('utf-8', 'windows-1251', $msg);
$msg=substr($msg, 0, 512);
$msg = iconv('windows-1251', 'utf-8', $msg);
$msg=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);
}

$msg=mysql_escape_string($msg);

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

$msg_t=base64_encode($msg);
$add_nick=base64_encode($_SESSION['login']);



mysql_query("INSERT INTO `loads_komm` (file, time, msg, nick)
values('$file1', '$time', '$msg_t', '$add_nick');");

echo "<b>Комментарий успешно добавлен</b>\n<br />\n";

}




$q = mysql_query("SELECT COUNT(*) FROM `loads_komm` WHERE `file` = '$file1';");
$k_post = mysql_result($q, 0);
$file=explode("/",$file1);
$i=count($file);
$i=$i-1;
$filename=$file[$i];

$k_p_str=10;

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 `loads_komm` WHERE `file` = '$file1' ORDER BY time DESC LIMIT $i, $k_p_str;");


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

if ($k_post>0)
{

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

echo "<div class='contur'><div class='header'>";



echo " <b>".base64_decode($post['nick'])."</b>";


echo "<br />\n";
echo "[$timep]<br />";


echo "".base64_decode($post['msg'])."";
echo "</div>\n";
echo "</div>\n";
}
}
else
{
echo "Нет комментариев<br />\n";
}
echo "<hr />\n<div class=\"str\">";
echo "Стр: [";
if ($page!=1)
{
echo "<a href=\"index.php?id_r=$id_r&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=\"index.php?id_r=$id_r&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=\"index.php?id_r=$id_r&amp;page=end\">$k_page</a>";
}
elseif ($k_page>1)
{
echo " <b>$k_page</b>";
}
echo "]";
echo "</div>\n";

echo "<hr />\n";
if (isset($_SESSION['login']))
{
echo "<form method=\"post\" action=\"komm.php?act=add&amp;file=$file1&amp;page=$page\">\n";
echo "<div class=\"a1\">\n<div class=\"a2\">\n";
echo "Комментировать:</div>\n<textarea name=\"msg\" rows=\"3\"></textarea><br />\n";
echo "<input type=\"checkbox\" name=\"tr\" value=\"1\" /> Транслит<br />\n";
echo "<input value=\"Добавить\" type=\"submit\" />\n";

echo "</div>\n";
echo "</form>\n";
}




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