<?
include_once '../sys/inc/start.php';
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';
$set['title']='Файлы'; // заголовок страницы
include_once '../sys/inc/thead.php';
title();
aut();
### Проверка существует ли папка
if (isset($_GET['id']))$id=intval($_GET['id']);else $id = $user['id'];
if (isset($_GET['dir']))$dir=intval($_GET['dir']);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user_dir` WHERE `id` = '$dir' AND `id_user` = '$id' LIMIT 1"),0)==0){header("Location: /index.php?");exit;}
### 
if($id==$user['id']){
echo'<div class="dop_menu"><img src="img/upload.png" alt=""/> <a href="upload.php?id='.$dir.'">Добавить файл</a></div>';
echo'<div class="dop_menu"><img src="img/folder_plus.png" alt=""/> <a href="/file/edit.php?id='.$dir.'&amp;act=new">Создать папку</a></div>';
}
$q=mysql_query("SELECT * FROM `user_dir` WHERE `id_user` = '$id' AND `dir` = '$dir' ORDER BY `name` ASC");
while ($post = mysql_fetch_array($q))
{
$set['p_str']=15;
$list[]=array('dir'=>1,'post'=>$post);
}
$q=mysql_query("SELECT * FROM `user_files` WHERE `dir` = '$dir' ORDER BY `time` DESC");
while ($post = mysql_fetch_array($q))
{
$set['p_str']=8;
$list[]=array('dir'=>0,'post'=>$post);
}
$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){echo "<div class='err'>Папка пуста</div>";}
for ($i=$start;$i<$k_post && $i<$set['p_str']*$page;$i++){
if ($list[$i]['dir']==1) {
$post=$list[$i]['post'];
### Счётчик
$k_f=0;
$q3=mysql_query("SELECT * FROM `user_dir` WHERE `dir` = '$post[id]'");
while ($post2 = mysql_fetch_array($q3)){
$k_f=$k_f+mysql_result(mysql_query("SELECT COUNT(*) FROM `user_files` WHERE `dir` = '$post2[id]'"),0);
}
$k_f=$k_f+mysql_result(mysql_query("SELECT COUNT(*) FROM `user_files` WHERE `dir` = '$post[id]'"),0);
###
echo'<div class="pa"><img src="img/folder_open.png" alt=""/> <a href="dir.php?id='.$id.'&amp;dir='.$post['id'].'">'.htmlentities($post['name'], ENT_QUOTES, 'UTF-8').'</a> ('.$k_f.')';
if($post['id_user']==$user['id']){
echo' [<a href="edit.php?id='.$post['id'].'&amp;act=rename"><img src="/icons/renf.png" alt="" /></a>] | [<a href="edit.php?id='.$post['id'].'&amp;act=delete"><img src="/icons/delf.png" alt="" /></a>]</div>';}
else{
echo '</div>';
}
}else{ ### Файлы
$post=$list[$i]['post'];
$ras=$post['ras'];
$name=$post['name'];
$size=$post['size'];
echo '<div class="an">';
include 'icon.php';
echo "<a href='file.php?id=".$post['id']."'>$post[name]</a> (".size_file($size).")";
if($post['id_user']==$user['id']){
echo' [<a href="edit_file.php?id='.$post['id'].'&amp;act=rename"><img src="/icons/renf.png" alt="" /></a>] | [<a href="edit_file.php?id='.$post['id'].'&amp;act=delete"><img src="/icons/delf.png" alt="" /></a>] | [<a href="edit_file.php?id='.$post['id'].'&amp;act=obmen">в <b>ЗО</b></a>]</div>';}
else{
echo '</div>';
}
}
}
if ($k_page>1)str('?',$k_page,$page); // Вывод страниц
include_once '../sys/inc/tfoot.php';
?>