<?php

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

$k_post = mysql_result(mysql_query('SELECT COUNT(*) FROM `diary`'), 0);
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];

$limit = $user['set_them_diary_num']; #Количество выводимых дневников.

$q = mysql_query('SELECT * FROM `diary` ORDER BY `time` DESC LIMIT ' . $limit);

if ($k_post != 0) {
    echo "<div class='list-group-item-null list-group-item-info'><span style='float: right'><i class='fa fa-book fa-lg'></i></span>" . lang('Последние блоги') . "</div>";
    while ($dnev = mysql_fetch_assoc($q)) {
        $ank = get_user($dnev['id_user']);
        echo "<div class='list-group-item-null list-group-item-grey'>";
        echo "<i class='fa fa-book fa-fw'></i> <b>$dnev[name]</b><br />";
        echo "</div>";
        echo "<div class='list-group-item-null'>";

        echo "<span style='float:right;' id='hides'>";
        echo gradient("$ank[nick]", "$ank[ncolor]", "$ank[ncolor2]");
        echo "</span>";

        if (IS_WEB) {
            echo toOutput(cutStr($dnev['msg'], 300));
        } else {
            echo toOutput(cutStr($dnev['msg'], 100));
        }
        echo "<br /><a href='/modules/diary/$dnev[name]/'><font color='grey'>" . lang('Читать далее') . " &raquo;</font></a>";

        echo "<span style='float:right;' id='hides'>";
        echo "<i class='fa fa-comments fa-fw'></i> " . mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_komm` WHERE `id_diary` = '$dnev[id]'"), 0);
        echo "</span>";

        if (mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_komm` WHERE `id_diary` = '$dnev[id]'"), 0) != 0) {
            $post = mysql_fetch_assoc(mysql_query("SELECT * FROM `diary_komm` WHERE `id_diary` = '$dnev[id]' ORDER BY `time` DESC LIMIT 1"));
        }
        echo "</div>";
    }
}