<?php

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

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

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `public` WHERE `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 `public` WHERE `id` ORDER BY id DESC LIMIT $start, " . $set['p_str'] . "");
    while ($post = mysql_fetch_array($q)) {
        echo "<table class='list-group-item-null'><tr><td class='icon14'>";
        $foto = mysql_fetch_array(mysql_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='/modules/public/images/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='/modules/public/index.php?id=" . $post['id'] . "'> " . $post['name'] . "</a><br />";
        $coint = mysql_result(mysql_query("SELECT COUNT(*) FROM `public_coint` WHERE `id_public` = '" . $post['id'] . "'"), 0);
        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='hr'></div>";
    }

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

    $res = mysql_query("SELECT * FROM `public` WHERE `id` ORDER BY podpis DESC LIMIT $start, " . $set['p_str'] . "");
    while ($row = mysql_fetch_array($res)) {
        echo "<div class='list-group-item-null'>";
        $coint = mysql_result(mysql_query("SELECT COUNT(*) FROM `public_coint` WHERE `id_public` = '" . $row['id'] . "'"), 0);
        echo "<small style='color: grey;float: right;'><i class='fa fa-users fa-fw'></i> $coint</small>";

        echo "<a href='/modules/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>";
    }
}


