<?php

require '../system/start.php';
require '../system/functions.php';
reg();
$str['mesto'] = 'Файлы';
$str['block'] = $set['site'].' / Файлы';
include '../style/'.$style.'/head.php';
$query = mysql_fetch_assoc(mysql_query("select `id`,`login` from `users` where `id` = ".int($_GET['id'])));
if (!$query)
{
 echo '<div class="on">Пользователь не найден!</div>';
 include '../style/'.$style.'/foot.php';
 exit;
}
echo '<div class="where">


<img class="ico" src="../style/'.$style.'/ico/love.gif" alt="" />
<a href="../files/index.php?act=search">Поиск файлов</a><br/>
<img class="ico" src="../style/'.$style.'/ico/load.gif" width="12" height="12" alt="" />
<a href="../files/add.php">Добавить файл</a><br/>
</div>';
switch($act)
{
  default:
$zapros = mysql_query("select * from `files_files` where `user` = '".$query['login']."' order by `id` limit ".$page.",".$set['str']."");
$total = mysql_result(mysql_query("select count(*) from `files_files` where `user` = '".$query['login']."'"),0);
if($total == 0)
{
 echo '<div class="forum1">Файлов еще нет!</div>';
}
 
$querysel = mysql_query("select * from `files_sel`");
while ($row = mysql_fetch_assoc($querysel))
{
	$i++;
 	if($i%2)
  	{
   		echo '<div class="forum1">';
   	}
    else
    {
    	echo '<div class="forum2">';
    }
    $result = mysql_result(mysql_query("select count(*) from `files_files` where `id_sel` = ".$row['id']." AND `user` = '".$query['login']."'"),0);
    echo '<img class="ico" src="../style/'.$style.'/ico/folder.png" alt="" /> <a href="files.php?act=kat&amp;id='.$query['id'].'&amp;sid='.$row['id'].'">'.$row['title'].'</a> ('.$result.')';
    echo '</div>';
}


$r = mysql_query("SELECT * FROM `files_files` WHERE `user` = '".$query['login']."'");

$count = mysql_num_rows($r);
$size_all = 0;
if ($count > 0) {
	while ($e = mysql_fetch_assoc($r)) {
		$size_all = $size_all + $e['size'];
	}
}

echo '<div class="forum1">';
echo 'Всего файлов (' . $count . ')<br/>';
echo 'Объём файлов: ' . $size_all . ' кб.';
echo '</div>';

break;

case 'kat':
		
	$r = mysql_query("SELECT * FROM `files_usel` WHERE `id_sel` = '" . int($_GET['sid']) . "'");
	$num = mysql_num_rows($r);
	if ($num == 0) {
		echo 'Подразделы не созданы!';
		break;
	}
	
	while ($e = mysql_fetch_assoc($r)) {
		echo ($i % 2) ? '<div class="forum1">' : '<div class="forum2">';
		
		$count_file = mysql_result(mysql_query("SELECT COUNT(*) FROM `files_files` WHERE `id_usel` = ".$e['id']." AND `user` = '".$query['login']."'"), 0);
		
		echo '<img class="ico" src="../style/'.$style.'/ico/folder.png" alt="" /> 
		<a href="files.php?act=files&amp;id='.int($_GET['id']).'&amp;sid=' . $e['id'] . '">' . $e['title'] . '</a> [' . $count_file . ']';
		echo '</div>';
		$i++;
	}
break;

case 'files':

$q = mysql_fetch_assoc(mysql_query("select `id` from `files_usel` where `id` = ".int($_GET['sid'])));
$total = mysql_result(mysql_query("select count(*) from `files_files` where `id_usel` = ".$q['id']." AND `user` = '".$query['login']."'"),0);

$sort = trim($_GET['sort']);

if (!$sort)
	$sortirovka = 'title';
if ($sort == 'name')
	$sortirovka = 'title';
if ($sort == 'date')
	$sortirovka = 'time';
if ($sort == 'reit')
	$sortirovka = 'rate';
if ($sort == 'down')
	$sortirovka = 'down';

$zapros = mysql_query("SELECT * FROM `files_files` WHERE `id_usel` = ".$q['id']." AND `user` = '".$query['login']."' ORDER by `" . $sortirovka . "` LIMIT ".$page.",".$set['str']."");

if($total == 0)
{
	echo '<div class="forum1">Файлов еще нет!</div>';
}
else
{
    echo '<div class="where">Сортировка:<br/>
    <a href="files.php?act=files&amp;id='.$query['id'].'&amp;sid='.$q['id'].'&amp;sort=name">Имя</a> |
    <a href="files.php?act=files&amp;id='.$query['id'].'&amp;sid='.$q['id'].'&amp;sort=date">Дата</a> |
    <a href="files.php?act=files&amp;id='.$query['id'].'&amp;sid='.$q['id'].'&amp;sort=reit">Рейтинг</a> |
    <a href="files.php?act=files&amp;id='.$query['id'].'&amp;sid='.$q['id'].'&amp;sort=down">Скачивания</a>
    </div>';
	while($row = mysql_fetch_assoc($zapros))
	{
		$i++;
		if($i%2)
		{
			echo '<div class="forum1">';
		}
		else
		{
			echo '<div class="forum2">';
		}
		$result = mysql_result(mysql_query("select count(*) from `files_comments` where `id_file` = ".$row['id'].""),0);
		echo '<img class="ico" src="../style/'.$style.'/ico/ext/'.$row['ext'].'.png" alt="" /> <a href="../files/index.php?act=view&amp;id='.$row['id'].'">'.$row['title'].'</a> ('.$row['size'].')</div>';
	}
	echo pages($page, $total, 'files.php?act=files&amp;id=' . int($_GET['id']) . '&amp;sid=' . int($_GET['sid']) . '&amp;' . ($_GET['sort'] ? 'sort=' . $_GET['sort'] . '&amp;' : '') . '', $set['str']);
}
break;
}

include '../style/'.$style.'/foot.php';
?>