<?php

/* DCMS Special
 * Дата последнего редактирования 10.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'])) {
    $public['id'] = intval($_GET['id']);
}

$public = $db->get_array($db->query("SELECT * FROM `public` WHERE `id` = '" . $public['id'] . ")'"));

if ($public['id'] == 0) {
    $set['title'] = lang('Сообщества'); // заголовок страницы
    require_once H . 'sys/inc/thead.php';

    aut();

    echo "<span class=\"list-group-item-null list-group-item-warning\">" . lang('Нет такого сообщества') . "</span><br />\n";

    header("Location: public.php" . SID);

    require_once H . 'sys/inc/tfoot.php';
    exit;
}

if ($public['id'] == intval($_GET['id'])) {
    $set['title'] = $public['name'];

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

    if (isset($user)) {

        if (isset($_GET['share']) && $_GET['share'] == 'share' && intval($_GET['row'])) {
            $q = $db->query("SELECT * FROM `friends` WHERE `user` = '" . $user['id'] . "' AND `i` = '1'");
            while ($f = $db->get_array($q)) {
                $a = get_user($f['friends']);
                $like = $db->get_array($db->query("SELECT * FROM `public_wall` WHERE `id` = '" . intval($_GET['row']) . "' LIMIT 1"));
                $db->query("INSERT INTO `public_wall` (`id_wall`, `link`, `ras`, `name`, `opis`, `id_pub`, `type`, `id_file`) values('" . $a['id'] . "', '" . $like['link'] . "', '" . $like['ras'] . "', '[url=/modules/public/index.php?id=" . $public['id'] . "] " . $like['name'] . "[/url]', '" . $like['opis'] . "', '" . $public['id'] . "', '" . $like['type'] . "', '" . $like['id_file'] . "')");
            }
            $db->query("INSERT INTO `share` (`id_user`, `id_row`, `id_public`) values ('" . $user['id'] . "', '" . intval($_GET['row']) . "', '" . $public['id'] . "')");
            msg('Успешно');
            header("Location: index.php?id=" . $public['id'] . "");
        }

        if (isset($_GET['ons']) && $_GET['ons'] == 'ons') {
            $q_q = $db->query("SELECT * FROM `friends` WHERE `user` = '" . $user['id'] . "'");
            while ($ff = $db->get_array($q_q)) {
                $a = $db->get_array($db->query("SELECT * FROM `user` WHERE `id` = '" . $ff['friends'] . "' LIMIT 1"));
                $pubb = $db->get_array($db->query("SELECT * FROM `public_coint` WHERE `id_user` = '" . $a['id'] . "' AND `id_public` = '" . $public['id'] . "' LIMIT 1"));
                $publics = $db->get_row($db->query("SELECT * FROM `public` WHERE `id` = '" . $public['id'] . "' LIMIT 1"));

                if ($pubb['id_user'] != $a['id']) {
                    $msgrat = "приглашает Вас в сообщество [url=/modules/public/index.php?id=$public[id]]$publics[name][/url] ";
                    $db->query("INSERT INTO `events` (`id_user`, `id_kont`, `id_img`, `msg`, `time`) values('$user[id]', '$a[id]', '7', '$msgrat', '$time')");
                }
            }
            $upub = $db->get_array($db->query("SELECT * FROM `public_coint` WHERE `id_user` = '" . $user['id'] . "' AND `id_public` = '" . $public['id'] . "' LIMIT 1"));
            $db->query("UPDATE `public_coint` SET `aktiv` = '" . ($upub['aktiv'] + 1) . "' WHERE `id_user` = '" . $user['id'] . "' AND `id_public` = '" . $public['id'] . "' LIMIT 1");

            $_SESSION['message'] = lang('Приглашение отправлено друзьям');
            header("Location: index.php?id=" . $public['id'] . "");
            exit();
        }

        if (isset($_GET['like']) && $_GET['like'] == 'like' && intval($_GET['row'])) {
            $db->query("INSERT INTO `public_like` (`id_user`, `public`, `like`) values('" . $user['id'] . "', '" . intval($_GET['row']) . "', '+1')", $db);
            $like = $db->get_array($db->query("SELECT * FROM `public_wall` WHERE `id_pub`='" . $public['id'] . "' LIMIT 1"));
            $db->query("INSERT INTO `public_wall` (`id_wall`, `link`, `ras`, `name`, `opis`, `id_ank`, `id_pub`, `public`, `type`, `id_file`) values('" . $user['id'] . "', '" . $like['link'] . "', '" . $like['ras'] . "', '[url=/modules/public/index.php?id=" . $public['id'] . "] " . $like['name'] . "[/url]', '" . $like['opis'] . "', '" . $like['id_ank'] . "', '" . $like['id_pub'] . "', '" . $like['public'] . "', '" . $like['type'] . "', '" . $like['id_file'] . "')");
            $upub = $db->get_array($db->query("SELECT * FROM `public_coint` WHERE `id_user` = '" . $user['id'] . "' AND `id_public` = '" . $public['id'] . "' LIMIT 1"));
            $db->query("UPDATE `public_coint` SET `aktiv` = '" . ($upub['aktiv'] + 1) . "' WHERE `id_user` = '" . $user['id'] . "' AND `id_public` = '" . $public['id'] . "' LIMIT 1");

            $_SESSION['message'] = lang('Вам понравилась запись');
            header("Location: index.php?id=$public[id]");
            exit;
        }

        if (isset($_GET['dislike']) && $_GET['dislike'] == 'dislike' && intval($_GET['row'])) {

            $db->query("DELETE FROM `public_like` WHERE `id_user` = '" . $user['id'] . "' AND `public` = '" . intval($_GET['row']) . "'");
            $db->query("OPTIMIZE TABLE `public_like`");

            //$_SESSION['message'] = lang('Вам не понравилось');
            header("Location: index.php?id=$public[id]");
            exit;
        }

        if (isset($_GET['podpis']) && $_GET['podpis'] == 'podpis') {
            $public_coint = $db->super_query("SELECT COUNT(*) as count FROM `public_coint` WHERE `id_user` = '" . $user['id'] . "' AND `id_public` = '" . $public['id'] . "'");
            if ($public_coint['count'] == 0) {
                $db->query("INSERT INTO `public_coint` (`id_public`, `id_user`) values('" . $public['id'] . "', '" . $user['id'] . "')");
                $db->query("UPDATE `public` SET `podpis` = '" . ($public['podpis'] + 1) . "' WHERE `id` = '" . $public['id'] . "' LIMIT 1");
            }

            if (isset($user) && $user['id'] != $public['id_user']) {
                $msg = "" . lang('Подписался на Ваше сообщество') . " [url=/modules/public/index.php?id=$public[id]]$public[name][/url] ";
                $db->query("INSERT INTO `events` (`id_user`, `id_kont`, `id_img`, `msg`, `time`) values('$user[id]', '$public[id_user]', '8', '$msg', '$time')");
            }

            $_SESSION['message'] = lang('Вы успешно подписались');
            header("Location: index.php?id=$public[id]");
            exit;
        }


        if (isset($_GET['del']) && $_GET['del'] == 'del' && intval($_GET['row'])) {
            if (isset($user) && $user['id'] == $public['id_user']) {
                $row = $db->get_row($db->query("SELECT * FROM `public_wall` WHERE `id` = '" . intval($_GET['row']) . "' LIMIT 1"));
                $db->query("DELETE FROM `public_wall` WHERE `id` = '" . $row['id'] . "'");
                $db->query("DELETE FROM `public_like` WHERE `public` = '" . $row['id'] . "'");
                $db->query("DELETE FROM `public_wall_komm` WHERE `id_public` = '" . $public['id'] . "'");
                $db->query("OPTIMIZE TABLE `public_wall`");
                $db->query("OPTIMIZE TABLE `public_like`");

                $_SESSION['message'] = lang('Запись успешно удалена');
                header("Location: index.php?id=$public[id]");
                exit;
            } else {
                $msg = "Совершил попытку удаления записи в сообществе $public[name]";
                $db->query("INSERT INTO `events` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '1', '" . $msg . "', '$time')");

                $_SESSION['message'] = lang('Администрация уведомлена');
                header("Location: index.php?id=$public[id]");
                exit;
            }
        }


        if (isset($_GET['del_komm']) && $_GET['del_komm'] == 'del_komm' && intval($_GET['del_k'])) {
            if (isset($user) && $user['id'] == $public['id_user']) {
                $db->query("DELETE FROM `public_wall_komm` WHERE `id` = '" . intval($_GET['del_k']) . "'");

                $_SESSION['message'] = lang('Комментарий успешно удален');
                header("Location: index.php?id=$public[id]");
                exit;
            } else {
                $msg = "Совершил попытку удаления комментария записи в сообществе [b]$public[name][/b]";
                $db->query("INSERT INTO `events` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '1', '" . $msg . "', '$time')");

                $_SESSION['message'] = lang('Администрация уведомлена');
                header("Location: index.php?id=$public[id]");
                exit;
            }
        }


        if (isset($_GET['dispodpis']) && $_GET['dispodpis'] == 'dispodpis') {
            $public_coint = $db->super_query("SELECT COUNT(*) as count FROM `public_coint` WHERE `id_user` = '" . $user['id'] . "' AND `id_public` = '" . $public['id'] . "'");
            if ($public_coint['count'] == 1) {
                $db->query("DELETE FROM `public_coint` WHERE `id_user` = '" . $user['id'] . "' AND `id_public` = '" . $public['id'] . "'");
                $db->query("UPDATE `public` SET `podpis` = '" . ($public['podpis'] - 1) . "' WHERE `id` = '" . $public['id'] . "' LIMIT 1");
                $db->query("OPTIMIZE TABLE `public_coint`");
            }
            if (isset($user) && $user['id'] != $public['id_user']) {
                $msg = "" . lang('Отписался от Вашего сообщества') . " [url=/modules/public/index.php?id=$public[id]]$public[name][/url] ";
                $db->query("INSERT INTO `events` (`id_user`, `id_kont`, `id_img`, `msg`, `time`) values('$user[id]', '$public[id_user]', '8', '$msg', '$time')");
            }
            $_SESSION['message'] = lang('Вы успешно отписались');
            header("Location: index.php?id=$public[id]");
            exit;
        }

        if (isset($_POST['msg']) && $public['id'] != 0) {
            $msg = $_POST['msg'];
            // Выгрузка файла 
            if (isset($_FILES['uploadfile']) && !isset($err)) {
                $name = $db->safesql(preg_replace('#\.[^\.]*$#', NULL, $_FILES['uploadfile']['name']));
                $ras = $db->safesql(strtolower(preg_replace('#^.*\.#', NULL, $_FILES['uploadfile']['name'])));
                $size = filesize($_FILES['uploadfile']['tmp_name']);
                $type = $_FILES['uploadfile']['type'];

                $id_msg = $db->insert_id();
                $db->query("INSERT INTO `public_wall_files` (`id_post`, `name`, `ras`, `size`, `type`) VALUES ('$id_msg', '$name', '$ras', '$size', '$type')");
                $id_file = $db->insert_id();

                if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], H . 'sys/wall/files/' . $id_file . '.' . $ras . '')) {
                    if ($imgc = @imagecreatefromstring(file_get_contents(H . 'sys/wall/files/' . $id_file . '.' . $ras . ''))) {
                        $img_x = imagesx($imgc);
                        $img_y = imagesy($imgc);

                        if ($img_x == $img_y) {
                            $dstW = 220; // ширина
                            $dstH = 220; // высота 
                        } elseif ($img_x > $img_y) {
                            $prop = $img_x / $img_y;
                            $dstW = 220;
                            $dstH = ceil($dstW / $prop);
                        } else {
                            $prop = $img_y / $img_x;
                            $dstH = 220;
                            $dstW = ceil($dstH / $prop);
                        }

                        $screen = imagecreatetruecolor($dstW, $dstH);
                        imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
                        imagedestroy($imgc);
                        //$screen=img_copyright($screen); // наложение копирайта
                        imagegif($screen, H . "sys/wall/screen/$id_file.png");
                        @chmod(H . 'sys/wall/screen/' . $id_file . '.png', 0777);
                        imagedestroy($screen);
                    }

                    @chmod(H . 'sys/wall/files/' . $id_file . '.' . $ras . '', 0777);
                } else {
                    // Если файл не был загружен, удаляем запись..
                    $db->query("DELETE FROM `public_wall_files` WHERE `id` = '" . $id_file . "'");
                }
            }
            if (!isset($err)) {
                // крепим файлы
                $id_post = $db->insert_id();
                $db->query("UPDATE `public_wall_files` SET `id_post` = '$id_post' WHERE `ras` = '" . $ras . "' AND `name` = '" . $name . "'");

                if (isset($user) && $user['id'] == $public['id_user']) {
                    $db->query("INSERT INTO `public_wall` (`id_public`, `link`, `ras`, `name`, `opis`, `id_ank`) values('" . $public['id'] . "', '/sys/wall/files/" . $id_file . "." . $ras . "', '" . $ras . "', '" . $public['name'] . "', '" . $msg . "', '" . $user['id'] . "')");
                } else {
                    $db->query("INSERT INTO `public_wall` (`id_public`, `link`, `ras`, `name`, `opis`, `id_ank`) values('" . $public['id'] . "', '/sys/wall/files/" . $id_file . "." . $ras . "', '" . $ras . "', '" . $user['nick'] . "', '" . $msg . "', '" . $user['id'] . "')");
                    $upub = $db->get_array($db->query("SELECT * FROM `public_coint` WHERE `id_user` = '" . $user['id'] . "' AND `id_public` = '" . $public['id'] . "' LIMIT 1"));
                    $db->query("UPDATE `public_coint` SET `aktiv` = '" . ($upub['aktiv'] + 1) . "' WHERE `id_user` = '" . $user['id'] . "' AND `id_public` = '" . $public['id'] . "' LIMIT 1");
                    $sss = $db->query("SELECT * FROM `public_coint` WHERE `id_public` = '" . $public['id'] . "'");
                    while ($podpiska = $db->get_array($sss)) {
                        $us_pub = $db->get_array($db->query("SELECT * FROM `user` WHERE `id` = '" . $podpiska['id_user'] . "' LIMIT 1"));
                        if ($us_pub['id'] != $public['id_user']) {
                            $db->query("INSERT INTO `public_wall` (`id_wall`, `name`, `opis`, `id_pub`) values('" . $us_pub['id'] . "', '[url=/modules/public/index.php?id=" . $public['id'] . "]" . $public['name'] . "[/url]', '" . $msg . "', '" . $public['id'] . "')");
                        }
                    }
                }

                if (!isset($_GET['ajax'])) {
                    $_SESSION['message'] = lang('Запись успешно опубликована');
                    header('Location: index.php?id=' . $public['id']);
                }
                exit;
            }
        }

        aut();
        err();

        #Навигация
        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='/public.php'>" . lang('Сообщества') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
        echo toOutput($public['name']);
        echo "</small></div><br />";

        echo "<div class='list-group-item-null list-group-item-grey'>";
        if ($public['privat'] == 1) {
            echo "<small style='float: right;color: #808080;'><i class='fa fa-lock fa-fw'></i> " . lang('Закрытая группа') . "</small>";
        } else {
            echo "<small style='float: right;color: #808080;'><i class='fa fa-unlock fa-fw'></i> " . lang('Открытая группа') . "</small>";
        }
        echo "<h4>" . toOutput($public['name']) . "</h4>";
        echo "<font color='grey'>" . toOutput($public['post']) . "</font>\n";
        echo "</div>";

        /*
          $us_pub_on = $db->get_array($db->query("SELECT * FROM `user` WHERE `id` = '" . $public['id_user'] . "' LIMIT 1"));
          echo "<span style='float: right;padding: 8px;'> ";
          echo "<br /><a href='/id" . $us_pub_on['id'] . "'>" . $us_pub_on['nick'] . "</a></span>";
         * 
         */

        echo "<div class='list-group-item-null'>";
        echo "<center>";
        $foto = $db->get_array($db->query("SELECT id,ras FROM `public_foto` WHERE `id_public` = '" . $public['id'] . "' AND `foto` = '1' LIMIT 1"));
        if (is_file(H . "sys/public/ava/" . $public['id'] . "." . $foto['ras'] . "")) {
            echo "<img src='/sys/public/ava/" . $public['id'] . "." . $foto['ras'] . "' style='width: 50%;' /><br />";
        } else {
            echo "<img src='/sys/public/ava/no_foto.jpg' style='width: 50%;' /><br />";
        }
        $pro_ons = $db->get_array($db->query("SELECT * FROM `public_coint` WHERE `id_public` = '" . $public['id'] . "' AND `id_user` = '" . $user['id'] . "'"), 0);

        if (isset($user) && $user['id'] != $public['id_user']) {
            echo "<br />";
            if ($user['id'] == $pro_ons['id_user']) {
                $doc->Link('list-group-item-null bg-info', "?id=" . $public['id'] . "&amp;dispodpis=dispodpis", 'thumbs-o-down', 'Отписаться');
            } else {
                $doc->Link('list-group-item-null bg-info', "?id=" . $public['id'] . "&amp;podpis=podpis", 'thumbs-o-up', 'Подписаться');
            }
        }

        echo "</center>";
        echo "</div>";

        if (isset($user) && $user['id'] == $public['id_user']) {
            $doc->Link('list-group-item-null list-group-item-success', "edit.php?id=" . $public['id'] . "&amp;edit=edit", 'cogs', 'Управление сообществом');
            echo "<div class='modal fade bd-example-modal-sm' id='ava' tabindex='-1' role='dialog' aria-hidden='true'>";
            echo "<div class='modal-dialog'>";
            echo "<div class='modal-content'>\n";
            echo "<div class='modal-header'>\n";
            echo "<button type='button' class='close' data-dismiss='modal' aria-label='Close'>";
            echo "<span aria-hidden='true'>&times;</span>";
            echo "<span class='sr-only'>Close</span>";
            echo "</button>";
            echo "<h5 class='modal-title'>" . lang('Аватар сообщества') . "</h5>";
            echo "</div>";

            echo "<form method='post' class='list-group-item-null' enctype='multipart/form-data' action='edit.php?id=" . $public['id'] . "&amp;foto=edit'>\n";
            echo "<input type='file' class='btn btn-secondary btn-sm' name='file' accept='image/*,image/gif,image/png,image/jpeg' /><br /><br />\n";

            $doc->Button('btn btn-success btn-sm', null, 'download', 'Загрузить аватар');
            echo '</form>';
            echo "</div>\n";
            echo "</div>\n";
            echo "</div>\n";
            echo "<a href='' class='list-group-item-null list-group-item-success' data-toggle='modal' data-target='#ava'><i class='fa fa-image fa-fw'></i> " . lang('Аватар сообщества') . "</a>";
        }

        $ps = $db->get_array($db->query("SELECT * FROM `public_coint` WHERE `id_public` = '" . $public['id'] . "' AND `id_user` = '" . $user['id'] . "'"), 0);

        if ($user['id'] == $ps['id_user']) {
            $doc->Link('list-group-item-null list-group-item-success', "?id=" . $public['id'] . "&amp;ons=ons", 'external-link-square', 'Пригласить друзей');
        }

        echo "<div class='modal fade bd-example-modal-sm' id='pod' tabindex='-1' role='dialog' aria-hidden='true'>";
        echo "<div class='modal-dialog'>";
        echo "<div class='modal-content'>\n";
        echo "<div class='modal-header'>\n";
        echo "<button type='button' class='close' data-dismiss='modal' aria-label='Close'>";
        echo "<span aria-hidden='true'>&times;</span>";
        echo "<span class='sr-only'>Close</span>";
        echo "</button>";
        echo "<h5 class='modal-title'>" . lang('Топ подписчиков') . "</h5>";
        echo "</div>";

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

        $pp = $db->query("SELECT * FROM `public_coint` WHERE `id_public` = '$public[id]'  ORDER BY `aktiv` DESC LIMIT 60");
        while ($pro = $db->get_array($pp)) {
            $uss = $db->get_array($db->query("SELECT * FROM `user` WHERE `id`='" . $pro['id_user'] . "' LIMIT 1"));
            if ($public['id_user'] != $uss['id']) {
                echo "<table class='list-group-item-null'><tr><td class='icon14'>";
                avatar($uss['id'], '48', 'border-radius: 2px;');
                echo "</td><td class='null'>";
                echo user($uss['id']);
                echo "</td></tr></table>";
                echo "<div class='hr'></div>";
            }
        }
        if ($pis == 0) {
            $doc->NoResult();
        }

        echo "</div>\n";
        echo "</div>\n";
        echo "</div>\n";

        echo "<div class='list-group-item-null list-group-item-grey'>";
        echo "<a data-toggle='modal' data-target='#pod'><i class='fa fa-users fa-fw'></i> " . lang('Подписчики') . "</a> <small style='color: grey;'>$pis</small>";
        echo "</div>";

        $pp = $db->query("SELECT * FROM `public_coint` WHERE `id_public` = '" . $public['id'] . "'  ORDER BY aktiv DESC LIMIT 10");

        if ($pis == 0) {
            echo "<div class='list-group-item-null'>";
            echo "<span style='color: grey;'>" . lang('Нет подписчиков') . "</span>";
            echo "</div>";
        } else {
            echo "<div class='list-group-item-null'>";
            while ($pro = $db->get_array($pp)) {
                $uss = $db->get_array($db->query("SELECT * FROM `user` WHERE `id`='" . $pro['id_user'] . "' LIMIT 1"));
                if ($public['id_user'] != $uss['id']) {

                    echo "<a href='/id$uss[id]' class='hint--top' data-hint='" . $uss['nick'] . "'>";
                    echo avatar($uss['id'], '48', 'border-radius: 2px;');
                    echo "</a>";
                }
            }
            echo "</div>";
        }

        $public_foto = $db->super_query("SELECT COUNT(*) as count FROM `public_foto` WHERE `id_public` = '" . $public['id'] . "' AND `foto` = '2'");
        $public_foto = $public_foto['count'];
        $no = $db->get_array($db->query("SELECT * FROM `public_coint` WHERE `id_public` = '" . $public['id'] . "' AND `id_user` = '" . $user['id'] . "'"), 0);

        if ($public_foto == 0) {

            echo "<div class='list-group-item-null list-group-item-grey'>";
            #Кнопка добавления фотографий, если разрешено
            if ($public['p'] == 0 || $user['id'] == $public['id_user']) {
                if ($user['id'] == $no['id_user']) {
                    echo "<a href='foto.php?id=" . $public['id'] . "&amp;foto=add' style='float: right;color: grey;' class='hint--left' data-hint='" . lang('Добавить фотографию') . "'><i class='fa fa-plus fa-fw'></i></a>";
                }
            }

            echo "<a href='foto.php?id=" . $public['id'] . "'><i class='fa fa-camera-retro fa-fw'></i> " . lang('Фотографии') . "</a> <small style='color: grey;'>$public_foto</small>";
            echo "</div>";

            echo "<div class='list-group-item-null' style='color: grey;'>";
            echo lang('Нет фотографий');
            echo "</div>";
        } else {
            echo "<div class='list-group-item-null list-group-item-grey'>";
            #Кнопка добавления фотографий, если разрешено
            if ($public['p'] == 0 || $user['id'] == $public['id_user']) {
                if ($user['id'] == $no['id_user']) {
                    echo "<a href='foto.php?id=" . $public['id'] . "&amp;foto=add' style='float: right;color: grey;' class='hint--left' data-hint='" . lang('Добавить фотографию') . "'><i class='fa fa-plus fa-fw'></i></a>";
                }
            }

            echo "<a href='foto.php?id=" . $public['id'] . "'><i class='fa fa-camera-retro fa-fw'></i> " . lang('Фотографии') . "</a> <small style='color: grey;'>$public_foto</small>";
            echo "</div>";
            $fotos = $db->get_array($db->query("SELECT id,ras FROM `public_foto` WHERE `id_public` = '" . $public['id'] . "' AND `foto` = '2' LIMIT 1"));
            if (is_file(H . "sys/public/foto/600/" . $fotos['id'] . ".jpg")) {

                $f = $db->query("SELECT id,ras FROM `public_foto` WHERE `id_public` = '" . $public['id'] . "' AND `foto` = '2' ORDER BY id DESC LIMIT 10");
                echo "<div class='list-group-item-null'>";
                while ($foto = $db->get_array($f)) {
                    echo "<img src='/sys/public/foto/600/" . $foto['id'] . ".jpg' width='60' height='60' />";
                }
                echo "</div>";
            }
        }

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

        if ($public_audio == 0) {
            echo "<div class='list-group-item-null list-group-item-grey'>";
            #Кнопка добавления аудиозаписей, если разрешено
            if ($public['a'] == 0 || $user['id'] == $public['id_user']) {
                if ($user['id'] == $no['id_user']) {
                    echo "<a href='audio.php?id=" . $public['id'] . "&amp;audio=add' style='float: right;color: grey;' class='hint--left' data-hint='" . lang('Добавить аудиозапись') . "'><i class='fa fa-plus fa-fw'></i></a>";
                }
            }

            echo "<a href='audio.php?id=" . $public['id'] . "'><i class='fa fa-music fa-fw'></i> " . lang('Аудиозаписи') . "</a> <small style='color: grey;'>$public_audio</small>";
            echo "</div>";

            echo "<div class='list-group-item-null' style='color: grey;'>";
            echo lang('Нет аудиозаписей');
            echo "</div>";
        } else {
            echo "<div class='list-group-item-null list-group-item-grey'>";
            #Кнопка добавления аудиозаписей, если разрешено
            if ($public['a'] == 0 || $user['id'] == $public['id_user']) {
                if ($user['id'] == $no['id_user']) {
                    echo "<a href='audio.php?id=" . $public['id'] . "&amp;audio=add' style='float: right;color: grey;' class='hint--left' data-hint='" . lang('Добавить аудиозапись') . "'><i class='fa fa-plus fa-fw'></i></a>";
                }
            }

            echo "<a href='audio.php?id=" . $public['id'] . "'><i class='fa fa-music fa-fw'></i> " . lang('Аудиозаписи') . "</a> <small style='color: grey;'>$public_audio</small>";
            echo "</div>";

            $mus = $db->query("SELECT * FROM `public_audio` WHERE `id_public` = '" . $public['id'] . "'  ORDER BY id DESC LIMIT 5");
            while ($music = $db->get_array($mus)) {
                echo "<table class='list-group-item-null'><tr><td class='icon14'>";
                echo "<object type=application/x-shockwave-flash data=/sys/uppod.swf height=26 width=32>
    <param name=wmode VALUE=transparent />
    <param name=allowFullScreen value=true />
    <param name=allowScriptAccess value=always />
    <param name=movie value=/sys/uppod.swf />
    <param name=FlashVars value=way=/sys/public/music/" . $music['id'] . ".mp3&amp;swf=/sys/uppod.swf&amp;w=32&amp;h=26&amp;autoplay=0&amp;st=/sys/public_audio.txt&amp;volume=40></object> ";
                echo "</td><td class='null'>";
                echo toOutput($music['name']);
                echo "</td></tr></table>";
            }
        }

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

        if ($public_video == 0) {
            echo "<div class='list-group-item-null list-group-item-grey'>";
            #Кнопка добавления видеозаписей, если разрешено
            if ($public['v'] == 0 || $user['id'] == $public['id_user']) {
                if ($user['id'] == $no['id_user']) {
                    echo "<a href='video.php?id=" . $public['id'] . "&amp;video=add' style='float: right;color: grey;' class='hint--left' data-hint='" . lang('Добавить видеозапись') . "'><i class='fa fa-plus fa-fw'></i></a>";
                }
            }

            echo "<a href='video.php?id=" . $public['id'] . "'><i class='fa fa-youtube-play fa-fw'></i> " . lang('Видеозаписи') . "</a> <small style='color: grey;'>$public_video</small>";
            echo "</div>";

            echo "<div class='list-group-item-null' style='color: grey;'>";
            echo lang('Нет видеозаписей');
            echo "</div>";
        } else {
            echo "<div class='list-group-item-null list-group-item-grey'>";
            #Кнопка добавления видеозаписей, если разрешено
            if ($public['v'] == 0 || $user['id'] == $public['id_user']) {
                if ($user['id'] == $no['id_user']) {
                    echo "<a href='video.php?id=" . $public['id'] . "&amp;video=add' style='float: right;color: grey;' class='hint--left' data-hint='" . lang('Добавить видеозапись') . "'><i class='fa fa-plus fa-fw'></i></a>";
                }
            }
            echo "<a href='video.php?id=" . $public['id'] . "'><i class='fa fa-youtube-play fa-fw'></i> " . lang('Видеозаписи') . "</a> <small style='color: grey;'>$public_video</small>";
            echo "</div>";

            $sss = $db->query("SELECT * FROM `public_video` WHERE `id_public` = '" . $public['id'] . "' ORDER BY id DESC LIMIT 1");
            echo "<div class='list-group-item-null'>";

            while ($video = $db->get_array($sss)) {
                if (is_file(H . "sys/public/video/screen/" . $video['id'] . ".gif")) {
                    echo "<center><a class='md-trigger' data-toggle='modal' data-target='#video'><img src='/sys/public/video/screen/" . $video['id'] . ".gif' width='180' height='120'></a></center>";
                } else {
                    echo "<center><a class='md-trigger' data-toggle='modal' data-target='#video'><i class='fa fa-youtube-play fa-5x'></i></center>";
                }
                echo "<div class='modal fade bd-example-modal-sm' id='video' tabindex='-1' role='dialog' aria-hidden='true'>";
                echo "<center>";

                echo "<object type=application/x-shockwave-flash data=/sys/uppod.swf width=600 height=410>
<param name=bgcolor value=#ffffff />
<param name=allowFullScreen value=true />
<param name=allowScriptAccess value=always />
<param name=wmode value=transparent />
<param name=movie value=/sys/uppod.swf/>
<param name=flashvars value=file=/sys/public/video/" . $video['ras'] . "/" . $video['id'] . "." . $video['ras'] . "&amp;st=/sys/public.txt&amp;poster=/sys/public/video/screen/" . $video['id'] . ".gif />
</object>";
                echo '</center>';
                echo '</div>';
            }
            echo "</div>";
        }

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

        if ($public_forum == 0) {
            echo "<div class='list-group-item-null list-group-item-grey'>";
            #Кнопка добавления обсуждений, если разрешено
            if ($public['f'] == 0 || $user['id'] == $public['id_user']) {
                if ($user['id'] == $no['id_user']) {
                    echo "<a href='forum.php?id=" . $public['id'] . "&amp;act=add' style='float: right;color: grey;' class='hint--left' data-hint='" . lang('Добавить новую тему') . "'><i class='fa fa-plus fa-fw'></i></a>";
                }
            }

            echo "<a href='forum.php?id=" . $public['id'] . "'><i class='fa fa-commenting fa-fw'></i> " . lang('Обсуждения') . "</a> <small style='color: grey;'>$public_forum</small>";
            echo "</div>";

            echo "<div class='list-group-item-null' style='color: grey;'>";
            echo lang('Нет обсуждений');
            echo "</div>";
        } else {
            echo "<div class='list-group-item-null list-group-item-grey'>";
            #Кнопка добавления обсуждений, если разрешено
            if ($public['f'] == 0 || $user['id'] == $public['id_user']) {
                if ($user['id'] == $no['id_user']) {
                    echo "<a href='forum.php?id=" . $public['id'] . "&amp;act=add' style='float: right;color: grey;' class='hint--left' data-hint='" . lang('Добавить новую тему') . "'><i class='fa fa-plus fa-fw'></i></a>";
                }
            }

            echo "<a href='forum.php?id=" . $public['id'] . "'><i class='fa fa-commenting fa-fw'></i> " . lang('Обсуждения') . "</a> <small style='color: grey;'>$public_forum</small>";
            echo "</div>";

            $res = $db->query("SELECT * FROM `public_forum` WHERE `id_public` = '" . $public['id'] . "' ORDER BY id DESC LIMIT 3");

            echo "<div class='list-group-item-null'>";
            while ($row = $db->get_array($res)) {
                $komm = $db->super_query("SELECT COUNT(*) as count FROM `public_forum` WHERE `id_them` = '" . $row['id'] . "'");
                $komm = $komm['count'];

                echo "<span style='float: right'><i class='fa fa-comment-o fa-fw'></i> $komm</span>";
                echo "<a href='them.php?id=" . $row['id'] . "'><i class='fa fa-file-text-o fa-fw'></i> <b>$row[name]</b></a><br />";
            }
            echo "</div>";
        }

        include_once H . 'modules/public/wall.php';
    } else {
        echo "<div class='list-group-item-null list-group-item-warning'>" . lang('Вы не авторизованы') . "!</div>";
    }
} else {
    require_once H . 'sys/inc/thead.php';

    aut();
    err();

    echo "<div class='list-group-item-null list-group-item-danger'>" . lang('Сообщество удалено или не найдено') . "</div>";
}
require_once H . 'sys/inc/tfoot.php';
