<?
include_once '../sys/inc/start.php';
if (isset($_GET['showinfo']) || !isset($_GET['f']) || isset($_GET['komm']))
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';




if (isset($_GET['d']) && esc($_GET['d'])!=NULL)
{
$l=ereg_replace("\.{2,}",NULL,esc(urldecode($_GET['d'])));
$l=ereg_replace("\./|/\.",NULL,$l);
$l=ereg_replace("(/){1,}","/",$l);
$l='/'.ereg_replace("(^(/){1,})|((/){1,}$)","",$l);
}
else
{
$l='/';
}

if ($l=='/')$id_dir=0;
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_dir` WHERE `dir` = '/$l' OR `dir` = '$l/' OR `dir` = '$l' LIMIT 1"),0)!=0)
{
$dir_id=mysql_fetch_array(mysql_query("SELECT * FROM `obmennik_dir` WHERE `dir` = '/$l' OR `dir` = '$l/' OR `dir` = '$l' LIMIT 1"));
$id_dir=$dir_id['id'];
}
else
{
$id_dir=0;
$l='/';
}


if (isset($_GET['f']))
{
$f=esc(urldecode($_GET['f']));
$name=eregi_replace('\.[^\.]*$', NULL, $f); // имя файла без расширения
$ras=strtolower(eregi_replace('^.*\.', NULL, $f));
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `id_dir` = '$id_dir' AND `name`='$name' AND `ras` = '$ras' LIMIT 1"),0)!=0)
{
$file_id=mysql_fetch_array(mysql_query("SELECT * FROM `obmennik_files` WHERE `id_dir` = '$id_dir' AND `name`='$name' AND `ras` = '$ras' LIMIT 1"));


$ras=$file_id['ras'];
$file=H."sys/obmen/files/$file_id[id].dat";
$name=$file_id['name'];
$size=$file_id['size'];

if (!isset($_GET['showinfo']) && !isset($_GET['komm']) && is_file(H.'sys/obmen/files/'.$file_id['id'].'.dat'))
{

@mysql_query("UPDATE `obmennik_files` SET `k_loads` = '".($file_id['k_loads']+1)."' WHERE `id` = '$file_id[id]' LIMIT 1");
DownloadFile(H.'sys/obmen/files/'.$file_id['id'].'.dat', $name.'.'.$ras, $file_id['type']);
/*
header("Content-type: $file_id[type]");
header("Content-Disposition: attachment; filename=$name.$ras");
header("Accept-Ranges: bytes");
header("Content-length: $file_id[size]");
echo file_get_contents(H.'sys/obmen/files/'.$file_id['id'].'.dat');
*/
exit;
}
elseif(isset($_GET['komm']) && is_file(H.'sys/obmen/files/'.$file_id['id'].'.dat'))
{
$set['title']='Обменник- Комментарии - '.$file_id['name']; // заголовок страницы
$_SESSION['page']=1;
include_once '../sys/inc/thead.php';
title();

include_once 'inc/komm_act.php'; // действия с комментариями
include_once 'inc/komm.php';
echo "<div class='foot'>";
echo "&raquo;<a href='/obmen$dir_id[dir]".urlencode($file_id['name']).".$file_id[ras]?showinfo'>К описанию</a><br />\n";
echo "&laquo;<a href='/obmen$dir_id[dir]'>В папку</a><br />\n";
echo "</div>\n";
include_once '../sys/inc/tfoot.php';
exit;
}
else
{
$set['title']='Зона обмена - '.$file_id['name']; // заголовок страницы
$_SESSION['page']=1;
include_once '../sys/inc/thead.php';
title();
echo "<div class='rodown'>\n";
if (isset($user) && ($user['level']>1 || $user['id']==$file_id['id_user']))include 'inc/file_act.php';
err();
aut(); // форма авторизации

if(is_file("inc/file/$ras.php"))include "inc/file/$ras.php";
else
include_once 'inc/file.php';

echo "</div>\n";
echo "<div class='foot'>";
echo "<img src='/obmen/dload.gif' alt='' /> <b><a href='/obmen$dir_id[dir]$file_id[name].$file_id[ras]'>Скачать</b></a><br />\n";

echo "Скачано: $file_id[k_loads] раз(а)<br/>";

echo "Прямая ссылка: ";

echo "<input type='text' value='http://$_SERVER[SERVER_NAME]/obmen$dir_id[dir]".urlencode($file_id['name']).".$file_id[ras]' /><br />\n";

echo "<img src='/obmen/wall.png' alt='ico' /> <a href='/obmen$dir_id[dir]".urlencode($file_id['name']).".$file_id[ras]?komm'> Комментарии</a> (".mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_komm` WHERE `id_file` = '$file_id[id]'"), 0).")<br />\n";


include_once 'inc/komentu.php';



echo "<br/><img src='/obmen/to33blue.png' alt='ico' /> <a href='/obmen$dir_id[dir]'> В папку</a><br />\n";
echo "<img src='/ico.png' alt='ico' /> <a href='/obmen'> В обмен</a>\n";
echo "</div>\n";

if (isset($user) && ($user['level']>1 || $user['id']==$file_id['id_user']))include 'inc/file_form.php';
include_once '../sys/inc/tfoot.php';
}
}
}





include_once 'inc/dir.php';




include_once '../sys/inc/tfoot.php';
?>