<?php
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();
only_reg();

$id = intval($_GET['id']);
$papka = mysql_fetch_array(mysql_query("SELECT * FROM `user_files_mod_papka` WHERE `id` = '".$id."'"));
$ank = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$papka['kto_id']."'"));
$papka_num = mysql_num_rows(mysql_query("SELECT * FROM `user_files_mod_papka`  WHERE `id` = '".$id."'"));

echo '<div class="mytitle">';
echo ''.online($ank['id']).' <a href="/info.php?id='.$ank['id'].'">'.$ank['nick'].'</a><br/>';
echo ' '.output_text($papka['name']).'<br/>';
echo '</div>';
if ($user['id']==$ank['id']){

echo '<img src="/user/files/image/inf.png" alt="."/> <a href="/user/files/dir.php?edit&id='.$papka['id'].'">Изменить папку</a> | <a href="/user/files/dir.php?del&id='.$papka['id'].'">Удалить папку</a><br/>';

}

if ($papka_num == 0){

echo '<div class="komm">';
echo 'Папка не найдена.<br/>';
echo '</div>';

}else{

if (isset($_GET['del']) && $user['id']==$ank['id']){

mysql_query("DELETE FROM `user_files_mod_papka` WHERE `id` = '".$id."' LIMIT 1");

header("Location: /user/files/?id=".$ank['id']."");

}

if (isset($_GET['edit']) && $user['id']==$ank['id']){

if (isset($_POST['submitt'])){

$name = mysql_real_escape_string($_POST['name']);

mysql_query("UPDATE `user_files_mod_papka` SET `name` = '".$name."' WHERE `id` = '".$id."' LIMIT 1");

}else{

echo '<div class="rekl_main">';
echo '<form action="/user/files/dir.php?edit&id='.$id.'" method="post">';
echo 'Название:<br/>';
echo '<input type="text" name="name" value=""/><br/>';
echo '<input type="submit" name="submitt" value="Изменить"/></form>';
echo '</div>';

}

}

if (isset($_POST['submit'])){

$_SESSION['pass_files_papka'] = mysql_real_escape_string($_POST['pass']);

header("Location: /user/files/dir.php?id=".$id."");

}

if ($papka['pass_set']==1 && $_SESSION['pass_files_papka']!==$papka['pass'] && $user['id']!==$papka['kto_id']){

echo '<div class="err">';
echo '<font color="red">Папка под паролем. Если знаете пароль, пожалуйста введите его:</font><br/>';
echo '<form action="/user/files/dir.php?id='.$id.'" method="post">';
echo '<input type="text" name="pass" value=""/><br/>';
echo '<input type="submit" name="submit" value="Попробовать"/></form>';
echo '</div>';

}else{

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `user_files_mod_files` WHERE `dir` = '".$id."'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$res = mysql_query("select * from `user_files_mod_files` WHERE `dir` = '".$id."' order by time desc LIMIT $start, $set[p_str];");

if ($k_post==0){

echo '<div class="komm">';
echo 'В папке нет файлов.<br/>';
echo '</div>';

}else{

while ($post = mysql_fetch_array($res)){

echo '<div class="str">';
echo '<img src="/user/files/image/files.png" alt="."/> <a href="/user/files/file.php?id='.$post['id'].'">'.output_text($post['name']).'</a> ['.vremja($post['time']).']';
echo '<br/>';
echo '<small>'.output_text(substr($post['opis'],0,70)).'...</small><br/>';
echo '</div>';

}

if ($k_page>1)str('?id='.$id.'&',$k_page,$page);

}

}

}


if ($papka['kto_id']==$user['id']){echo '<div class="royal"><img src="/style/img/plus.gif" alt="."/> <a href="/user/files/new_file.php">Добавить файл</a></div>';}

echo '<div class="foot">';
echo '<a href="/user/files/?id='.$ank['id'].'">К папкам</a><br/>';
echo '</div>';

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