<?php

/* DCMS Special
 * Дата последнего редактирования 04.02.2016
 * Модифицировал densnet
 */

foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
    require_once "../../sys/inc/$inc.php";
}

if (isset($user)) {
    $ank['id'] = $user['id'];
}

if (isset($_GET['id'])) {
    $ank['id'] = intval($_GET['id']);
}

$ank = get_user($ank['id']);

if ($ank['id'] == 0) {
    header("Location: /index.php?" . SID);
    exit;
}

if (isset($user) && isset($_GET['delete']) && $user['id'] == $ank['id']) {
    mysql_query("DELETE FROM `bookmark_files` WHERE `id` = '" . intval($_GET['delete']) . "' AND `id_user` = '$user[id]' LIMIT 1");

    $_SESSION['message'] = lang('Закладка удалена');
    header("Location: ?page=" . intval($_GET['page']) . "" . SID);
    exit;
}

if (!$ank) {
    header("Location: /index.php?" . SID);
    exit;
}

$set['title'] = lang('Закладки') . ' - ' . lang('Фото') . ' - ' . $ank['nick']; // заголовок страницы

require_once H . 'sys/inc/thead.php';

aut();
err();

$users = mysql_result(mysql_query("SELECT COUNT(id_user) FROM `bookmark_user` WHERE `id_user` = '" . $ank['id'] . "'"), 0);
$foto = mysql_result(mysql_query("SELECT COUNT(id_user) FROM `bookmark_foto` WHERE `id_user` = '" . $ank['id'] . "'"), 0);
$files = mysql_result(mysql_query("SELECT COUNT(id_user) FROM `bookmark_files` WHERE `id_user` = '" . $ank['id'] . "'"), 0);

#Навигация
echo "<div class='card-header'>";
echo "<a href='/' data-toggle='tooltip' data-placement='right' title='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
echo "<a href='/info.php?id=$ank[id]'>$ank[nick]</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Закладки');
echo "</div>";

echo "<div class='list-group-item'>";
echo "<ul class='nav nav-tabs' style='margin-bottom: -11px;'>";
echo "<li class='nav-item'><a class='nav-link' href='index.php?id=$ank[id]'>" . lang('Люди') . " <span class='label label-default'>$users</span></a></li>";
echo "<li class='nav-item'><a class='nav-link' href='foto.php?id=$ank[id]'>" . lang('Фото') . " <span class='label label-default'>$foto</span></a></li>";
echo "<li class='nav-item'><a class='nav-link active'>" . lang('Файлы') . " <span class='label label-default'>$files</span></a></li>";
echo "</ul>";
echo "</div>";

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `bookmark_files` WHERE `id_user` = '$ank[id]'"), 0);
$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) {
    $doc->NoResult();
}

$q = mysql_query("SELECT * FROM `bookmark_files`  WHERE `id_user` = '$ank[id]' ORDER BY id DESC LIMIT $start, $set[p_str]");

while ($post = mysql_fetch_assoc($q)) {
    $f = $post['id_file'];
    $file_id = mysql_fetch_assoc(mysql_query("SELECT id_dir,id,name,ras  FROM `obmennik_files` WHERE `id` = '" . $f . "'  LIMIT 1"));
    $dir = mysql_fetch_array(mysql_query("SELECT `dir` FROM `obmennik_dir` WHERE `id` = '$file_id[id_dir]' LIMIT 1"));

    if ($file_id['ras'] == 'zip' || $file_id['ras'] == 'rar') {
        $r = "<span class='fa fa-file-archive-o fa-fw'></span>";
    } elseif ($file_id['ras'] == 'png' || $file_id['ras'] == 'jpg' || $file_id['ras'] == 'jpeg' || $file_id['ras'] == 'gif') {
        $r = "<span class='fa fa-file-image-o fa-fw'></span>";
    } elseif ($file_id['ras'] == 'mp3') {
        $r = "<span class='fa fa-file-audio-o fa-fw'></span>";
    } elseif ($file_id['ras'] == 'txt') {
        $r = "<span class='fa fa-file-text-o fa-fw'></span>";
    } elseif ($file_id['ras'] == 'mp4' || $file_id['ras'] == 'avi' || $file_id['ras'] == '3gp') {
        $r = "<span class='fa fa-file-video-o fa-fw'></span>";
    } elseif ($file_id['ras'] == 'php') {
        $r = "<span class='fa fa-file-code-o fa-fw'></span>";
    } else {
        $r = "<span class='fa fa-file-o fa-fw'></span>";
    }

    echo "<table class='list-group-item-komm'><tr><td class='icon14'>";
    echo "$r";
    echo "</td><td class = 'null'>";
    if ($ank['id'] == $user['id']) {
        echo "<span style='float:right;'><a href='?delete=$post[id]&amp;page=$page' title='" . lang('Удалить') . "'><i class='fa fa-trash-o fa-fw'></i></a></span>";
    }
    echo "<a href='/modules/obmen$dir[dir]$file_id[id].$file_id[ras]?showinfo' title='" . lang('Перейти к файлу') . "'>" . htmlspecialchars($file_id['name']) . ".$file_id[ras]</a><br />";

    echo "<span title='" . date::time($post['time']) . "' style='color:grey;'>" . date::times($post['time']) . "</span>";
    echo "</td></tr></table>";
}

if ($k_page > 1) {
    echo "<div class='list-group-item'>";
    str('?', $k_page, $page);
    echo "</div>";
}


require_once H . 'sys/inc/tfoot.php';
