<?
$cou=mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files`",$db), 0);
$list=null;
if ($l=='/')
$set['title']="Зона обмена ($cou)";
else $set['title']='Обменник - '.$dir_id['name'];
$_SESSION['page']=1;
require '../sys/inc/thead.php';
title();
require 'inc/upload_act.php';
require 'inc/admin_act.php';
err();


if ($l!='/'){
echo "<div class='fyt'>";
echo "<a href='/obmen/'>Обменник</a> &gt; ".obmen_path($l)."<br />\n";
echo "</div>\n";
}



$q=mysql_query("SELECT * FROM `obmennik_dir` WHERE `dir_osn` = '/$l' OR `dir_osn` = '$l/' OR `dir_osn` = '$l' ORDER BY `name`,`num` ASC");
while ($post = mysql_fetch_assoc($q))
{
$list[]=array('dir'=>1,'post'=>$post);
}
$q=mysql_query("SELECT * FROM `obmennik_files` WHERE `id_dir` = '$id_dir' ORDER BY `time` DESC");
while ($post = mysql_fetch_assoc($q))
{
$list[]=array('dir'=>0,'post'=>$post);
}

if ($l=='/')
{
$new=mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `time` > '".(time()-86400)."'"), 0);
?>
<div class='new_enk'><img src='/style/images/search.gif'> <a href='/obmen/search.php'>Поиск</a></div>
<div class='new_enk'><img src='/style/images/new.gif'> <a href='new.php'>Новые файлы</a> (<?echo $new;?>)</div>
<div class='new_enk'><img src='/style/images/122.gif'> <a href='rules_obmen.php'> Правила Загрузки</a></div>
<div class='new_enk'><img src='/style/images/ret.png'> <a href='top.php'>30-ка самых скачеваемых</a></div>
<?
}

$set['p_str']=30;
$k_post=sizeof($list);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

if ($k_post==0)
{
?>
<div class='noy'>Папка пуста</div>
<?
}

for ($i=$start;$i<$k_post && $i<$set['p_str']*$page;$i++)
{
if ($list[$i]['dir']==1) // папка 
{
$post=$list[$i]['post'];
if($num==1){
echo "<div class='enk_div'>\n";
$num=0;
}else{
echo "<div class='enk2_div'>\n";
$num=1;}
if ($post['icon']!=NULL)echo "<img src='/style/obmen/$post[icon]' /> \n";
else
echo "<img src='/style/themes/$set[set_them]/loads/14/dir.png' alt='' />\n";
echo "<a href='/obmen$post[dir]'>$post[name]</a> ";


$k_f=0;
$k_n=0;
$q3=mysql_query("SELECT * FROM `obmennik_dir` WHERE `dir_osn` like '$post[dir]%'");
while ($post2 = mysql_fetch_assoc($q3))
{
$k_f=$k_f+mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `id_dir` = '$post2[id]'"),0);
$k_n=$k_n+mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `id_dir` = '$post2[id]' AND `time` > '".(time()-60*60*$set['loads_new_file_hour'])."'",$db), 0);
}
$k_f=$k_f+mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `id_dir` = '$post[id]'"),0);
$k_n=$k_n+mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `id_dir` = '$post[id]' AND `time` > '".(time()-60*60*$set['loads_new_file_hour'])."'",$db), 0);

if ($k_n==0)$k_n=NULL;
else $k_n='+'.$k_n;
echo "($k_f)$k_n<br />\n";
echo "</div>\n";
}else{
$post=$list[$i]['post'];
$ras=$post['ras'];
$file=H."sys/obmen/files/$post[id].dat";
$name=$post['name'];
$size=$post['size'];
if($num==1){
echo "<div class='enk_div'>\n";
$num=0;
}else{
echo "<div class='enk2_div'>\n";
$num=1;}
include 'inc/icon14.php';
if ($set['echo_rassh']==1)$ras=".$post[ras]";else $ras=NULL;
echo "<a href='/obmen$dir_id[dir]$post[name].$post[ras]?showinfo'>$post[name]$ras</a><br />\n";
require 'inc/opis.php';
echo "</div>\n";
}
}


if ($k_page>1)str('?',$k_page,$page);

if ($l!='/'){
echo "<div class='fyt'>";
echo "<a href='/obmen/'>Обменник</a> &gt; ".obmen_path($l)."<br />\n";
echo "</div>\n";
}


require 'inc/upload_form.php';
require 'inc/admin_form.php';
if ($l=='/')
{
$k=mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `group_access` = '4'"),0);
echo "<div class='new_enk'><img src='/style/images/police.png'> <a href='adm.php'>Администрация</a> ($k)</div>\n";
}
?>