<?php

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

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

if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1"), 0) == 1 || isset($user) && !isset($_GET['id'])) {
    if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1"), 0) == 1) {
        $id = intval($_GET['id']);
        $ank = get_user($id);
    } else {
        $ank = get_user($user['id']);
    }
    $set['title'] = lang('Блоги') . ' ' . $ank['nick'] . '';

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

    aut();

    #Навигация
    echo "<div class='list-group-item-null list-group-item-grey'><small>";
    echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='/modules/diary/'>" . lang('Блоги') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "$ank[nick]";
    echo "</small></div><br />";

    $k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `diary` 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();
    } else {
        $q = mysql_query("SELECT * FROM `diary` WHERE `id_user`='$ank[id]' ORDER BY `time` DESC");
        while ($diary = mysql_fetch_assoc($q)) {
            $razdel = mysql_fetch_assoc(mysql_query("SELECT * FROM `diary_cat` WHERE `id` = '$diary[id_cat]' LIMIT 1"));

            echo '<div class="list-group-item-null">';
            echo "<a href='/modules/diary/$diary[name]/'><i class='fa fa-book fa-fw'></i> $diary[name]</a> <small style='color: grey;'>" . date::time($diary['time']) . "</small><br />";

            echo '<i class="fa fa-folder fa-fw"></i> Категория:  <a href="index.php?r=' . $razdel['id'] . '">' . $razdel['name'] . '</a><br/>';
            echo '<i class="fa fa-eye fa-fw"></i> Просмотров: ' . $diary['viewings'] . ' | ';
            echo '<i class="fa fa-star fa-fw"></i> Рейтинг: ' . $diary['rating'] . '<br/>';
            echo '<i class="fa fa-tags fa-fw"></i> Метки: ' . $diary['tags'] . '';

            echo '</div>';
            echo "<div class='hr'></div>";
        }
    }

    require_once H . 'sys/inc/tfoot.php';
} else {
    header("Location:index.php");
}
