<?php

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

foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
    require_once H . "sys/inc/$inc.php";
}
$k_post = $db->super_query("SELECT COUNT(*) as count FROM `public` WHERE `id`");
$k_post = $k_post['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 `public` WHERE `id` ORDER BY id DESC LIMIT $start, " . $set['p_str'] . "");
    while ($post = $db->get_array($q)) {
        echo "<table class='list-group-item-null-mini list-group-item-grey dop'><tr><td class='icon14'>";
        $foto = $db->get_array($db->query("SELECT id,ras FROM `public_foto` WHERE `id_public` = '" . $post['id'] . "' AND `foto` = '1' LIMIT 1"));
        if (is_file(H . "sys/public/ava/" . $post['id'] . "." . $foto['ras'] . "")) {
            echo "<img src='/sys/public/ava/" . $post['id'] . "." . $foto['ras'] . "' width='50' />";
        } else {
            echo "<img src='/sys/public/ava/no_foto.jpg' width='50' />";
        }
        echo "</td><td class='null'>";
        if ($user['level'] > 2) {
            echo "<span style='float: right;'><a href='public.php?id=" . $post['id'] . "&amp;del=del' class='hint--left' data-hint='" . lang('Удалить сообщество') . "'><i class='fa fa-trash-o fa-fw'></i></a></span>";
        }
        echo "<a href='" . DIR_PUBLIC . "index.php?id=" . $post['id'] . "'> " . $post['name'] . "</a><br />";

        $coint = $db->super_query("SELECT COUNT(*) as count FROM `public_coint` WHERE `id_public` = '" . $post['id'] . "'");
        $coint = $coint['count'];

        echo "<small style='color: grey;'><i class='fa fa-users fa-fw'></i> " . sklon_text($coint, array('подписчик', 'подписчика', 'подписчиков')) . "</small>";

        if ($post['privat'] == 1) {
            echo "<span style='float: right;color: #808080;' class='hint--left' data-hint='" . lang('Закрытое сообщество') . "'><i class='fa fa-lock fa-fw'></i></span>";
        }
        echo "</td></tr></table>";
    }

    echo "<div class='list-group-item-null list-group-item-info'>";
    echo "<i class='fa fa-line-chart fa-fw'></i> ".lang('Популярные сообщества');
    echo "</div>";

    $res = $db->query("SELECT * FROM `public` WHERE `id` ORDER BY podpis DESC LIMIT $start, " . $set['p_str'] . "");
    while ($row = $db->get_array($res)) {
        $coint = $db->super_query("SELECT COUNT(*) as count FROM `public_coint` WHERE `id_public` = '" . $row['id'] . "'");
        $coint = $coint['count'];
        echo "<div class='list-group-item-null'>";
        echo "<small style='color: grey;float: right;'><i class='fa fa-users fa-fw'></i> $coint</small>";
        echo "<a href='" . DIR_PUBLIC . "index.php?id=$row[id]'><i class='fa fa-slack fa-fw'></i> $row[name]</a><br />";
        echo "</div>";
        echo "<div class='hr'></div>";
    }
}


