<?php

/* DCMS Special
 * Дата последнего редактирования 09.10.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']) || isset($user) && !isset($_GET['id'])) {
    $q = $db->super_query("SELECT COUNT(*) as count FROM `user` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
    if (isset($_GET['id']) && $q['count'] == 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 />";

    $q = $db->super_query("SELECT COUNT(*) as count FROM `diary` WHERE `id_user`='$ank[id]'");
    $k_post = $q['count'];
    $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 = $db->query("SELECT * FROM `diary` WHERE `id_user`='$ank[id]' ORDER BY `time` DESC");
        while ($diary = $db->get_row($q)) {
            $razdel = $db->get_row($db->query("SELECT * FROM `diary_cat` WHERE `id` = '$diary[id_cat]' LIMIT 1"));

            echo '<div class="list-group-item-null list-group-item-grey dop">';
            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>';
        }
    }

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