<?
if (dir_name($dir_loads)!=NULL)
$set['title']='Загрузки - '.dir_name($dir_loads);
else $set['title']='Загрузки';
include_once '../sys/inc/thead.php';
title();
include 'inc/admin_act.php';
err();
aut();


$dirlist_t=NULL;
$opendir=opendir($dir_loads);
while ($readdir=readdir($opendir)){
if (!preg_match("#^\.|\.php|\.name$|\.txt$|\.opis$|\.html?$|\.sql$|\.ini$|\.db$|\.dat$|\.jad$#i",$readdir) && !preg_match("#\.JPG$|\.PNG$|\.GIF$#",$readdir))
{
$dirlist_t[]=is_dir($dir_loads.'/'.$readdir)?array('time'=>9999999999999,'dir'=>1,'name'=>$readdir):array('time'=>filectime($dir_loads.'/'.$readdir),'dir'=>0,'name'=>$readdir);
}
}
closedir($opendir);


function cmp_time($a2, $b2)
{
return ($a2['time']<$b2['time'])?1:0;
}
function cmp_dir($a2, $b2)
{
return ($a2['dir']<$b2['dir'])?1:0;
}
if (count($dirlist_t)!=0)usort($dirlist_t, "cmp_time");
//if (count($dirlist_t)!=0)usort($dirlist_t, "cmp_dir");
//if (count($dirlist_t)!=0)usort($dirlist_t, "cmp_dir");


$k_post=count($dirlist_t);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$end=$set['p_str']*$page;
if ($l!=NULL){
echo "<div class='foot'>";
echo "<img src='/style/icons/up_dir.gif' alt='*'> <a href='?'>Загрузки</a> &gt; ".rupath($l,'../sys/loads/files')."<br />\n";
echo "</div>\n";
}
echo "<table class='post'>\n";

if ($k_post==0){
echo "<div class='mess'>\n";
echo "Папка пуста\n";
echo "   </div>\n";
}

for ($i=$start;$i<$end && $i<$k_post;$i++)
{
$dirlist[$i]=$dirlist_t[$i]['name'];
if ($dirlist_t[$i]['dir']==1) // папка
{
/*-----------зебра-----------*/ if ($num==0){echo '<div class="nav1">';$num=1;}elseif ($num==1){echo '<div class="nav2">';$num=0;}/*---------------------------*/
if ($set['set_show_icon']==2){
echo "<img src='/style/themes/$set[set_them]/loads/48/dir.png' alt='' />\n";
}
elseif ($set['set_show_icon']==1){
echo "<img src='/style/themes/$set[set_them]/loads/14/dir.png' alt='' />\n";
}

echo " <a href='?d=".urlencode("$l/$dirlist[$i]")."'>".dir_name($dir_loads.'/'.$dirlist[$i])."</a> ".k_files($l.'/'.$dirlist[$i])."\n";

echo "   </div>\n";
}
else // файл
{
/*-----------зебра-----------*/ if ($num==0){echo '<div class="nav1">';$num=1;}elseif ($num==1){echo '<div class="nav2">';$num=0;}/*---------------------------*/
$ras=strtolower(preg_replace('#^.*\.#i', NULL, $dirlist[$i]));
$name=preg_replace('#\.[^\.]*$#i', NULL, $dirlist[$i]);
if (is_file($dir_loads.'/'.$dirlist[$i].'.name'))
$name2=trim(esc(file_get_contents($dir_loads.'/'.$dirlist[$i].'.name')));
elseif (function_exists('iconv'))
$name2=iconv('windows-1251', 'utf-8', $name);
else $name2=$name;

$name2=htmlspecialchars($name2);

$size=filesize($dir_loads.'/'.$dirlist[$i]);



if ($set['set_show_icon']==2){
include 'inc/icon48.php';
}
elseif ($set['set_show_icon']==1){
include 'inc/icon14.php';
}

if ($set['echo_rassh']==1)$ras2=".$ras";else $ras2=NULL;

echo "<a href='?d=".urlencode("$l")."&amp;f=".urlencode("$dirlist[$i]")."&amp;page=$page'>$name2$ras2</a> ".file_new($dir_loads.'/'.$dirlist[$i])."\n";

include 'inc/opis.php';

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

echo "</table>\n";


if ($k_page>1)str("?d=".urlencode("$l")."&amp;",$k_page,$page); // Вывод страниц

if ($l!=NULL){
echo "<div class='foot'>";
echo "<img src='/style/icons/up_dir.gif' alt='*'> <a href='?'>Загрузки</a> &gt; ".rupath($l,'../sys/loads/files')."<br />\n";
echo "</div>\n";
}






include 'inc/admin_form.php';

if ($l==NULL){
echo "<div class='foot'>";
echo "<img src='/style/icons/str.gif' alt='*'> <a href='/loads/new_komm.php'>Новые комментарии</a> (".mysql_result(mysql_query("SELECT COUNT(*) FROM `loads_komm` LEFT JOIN `loads_list` ON `loads_komm`.`file` = `loads_list`.`name` AND `loads_komm`.`size` = `loads_list`.`size` WHERE `loads_komm`.`time` > '".($time-60*60*24)."'"), 0).")<br />\n";
echo "<img src='/style/icons/str.gif' alt='*'> <a href='/loads/search.php'>Поиск файлов</a><br />\n";
echo "</div>\n";
}
include_once '../sys/inc/tfoot.php';
?>