<?php

$no = mysql_fetch_array(mysql_query("SELECT * FROM `public_coint` WHERE `id_public` = '" . $public['id'] . "' AND `id_user` = '" . $user['id'] . "'"), 0);

if (isset($user)) {

    echo "<div id='accordion' role='tablist' aria-multiselectable='true'>";
    echo "<div role='tab' id='headingTwo'>";
    echo "<div class='list-group-item-null list-group-item-grey'>";
    if ($user['id'] == $no['id_user']) {
        echo "<a data-toggle='collapse' data-parent='#accordion' href='#wall_form' style='float: right;color: grey;' class='collapsed hint--left' data-hint='" . lang('Добавить запись') . "'><i class='fa fa-pencil fa-fw'></i></a>";
    }
    echo "<i class='fa fa-th-large fa-fw'></i> " . lang('Записи сообщества') . "";
    echo "</div>";
    //echo "<span style='float: right;'><a class='collapsed' data-toggle='collapse' data-parent='#accordion' href='#status' aria-expanded='false' aria-controls='collapseTwo'><i class='fa fa-pencil'></i></a></span>";
    echo "</div>";
    echo "<div id='wall_form' class='panel-collapse collapse' role='tabpanel' aria-labelledby='wall_form'>";

    if ($user['id'] == $no['id_user']) {
        if ($public['privat'] == 1) {
            $pro_text = mysql_fetch_array(mysql_query("SELECT * FROM `public_coint` WHERE `id_user` = '" . $user['id'] . "' AND `id_public`='" . $public['id'] . "' LIMIT 1"));
            if ($pro_text['id_user'] == $user['id']) {
                echo "<form method='post' class='list-group-item-null' name='message' enctype='multipart/form-data' action='index.php?id=" . $public['id'] . "'>\n";
                echo auto_bb("message", "msg");
                echo "<textarea class='form-control' name='msg' placeholder='" . lang('Поделиться новостью') . "...' rows='2'></textarea><br />\n";
                $doc->Button('btn btn-success btn-sm', null, null, 'Опубликовать');
                echo "<input class='btn btn-secondary btn-sm' name='uploadfile' type='file' />";
                echo "</form>";
            }
        } else {
            echo "<form method='post' class='list-group-item-null' name='message' enctype='multipart/form-data' action='index.php?id=" . $public['id'] . "'>\n";
            echo auto_bb("message", "msg");
            echo "<textarea class='form-control' name='msg' placeholder='" . lang('Поделиться новостью') . "...' rows='2'></textarea><br />\n";
            $doc->Button('btn btn-success btn-sm', null, 'pencil', 'Опубликовать');
            echo "<input class='btn btn-secondary btn-sm' name='uploadfile' type='file' />";
            echo "</form>";
        }
    }

    echo "</div>";
    echo "</div>";
}
?>
<script src="/style/js/jquery.js"></script>
<script>

    $(document).ready(function () {
        $('span#like').click(function () {
            setVote('like', $(this));
        });


    });

    function setVote(type, element) {
        var go = $('#go').val();
        var us = $('#us').val();
        var id_post = element.parent().find('#id_post').val();

        $.ajax({
            type: "POST",
            url: "/modules/public/like.php?public=public",
            data: {
                'go': go,
                'id_post': id_post,
                'us': us
            },
            dataType: "json",
            success: function (data) {
                if (data.result == 'like') {
                    var count = parseInt(element.find('b').html());
                    element.find('b').html(count + 1);
                } else {
                    var count = parseInt(element.find('b').html());
                    element.find('b').html(count - 1);
                }
            }
        });
    }

</script>

<?php

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `public_wall` WHERE `id_public` = '" . $public['id'] . "'"), 0);
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];

$res = mysql_query("SELECT * FROM `public_wall` WHERE `id_public` = '" . $public['id'] . "' ORDER BY id DESC LIMIT $start, " . $set['p_str'] . "");
while ($row = mysql_fetch_array($res)) {
    if (isset($_POST['komm']) && intval($_GET['row'])) {
        $komm = $_POST['komm'];
        if (!isset($err)) {
            mysql_query("INSERT INTO `public_wall_komm` (`id_row`, `id_user`, `msg`, `time`, `id_kont`) values('" . intval($_GET['row']) . "', '" . $user['id'] . "', '" . $komm . "', '" . $time . "', '" . $ank['id'] . "')");
            if (isset($user) && $user['id'] != $ank['id']) {
                mysql_query("INSERT INTO `notification` (`id_user`, `avtor`, `type`, `id_object`, `time`) values('" . $ank['id'] . "', '" . $user['id'] . "', 'wall_komm', '" . intval($_GET['row']) . "', '$time')");
            }
            if (!isset($_GET['ajax'])) {
                $_SESSION['message'] = lang('Сообщение успешно добавлено');
                header('Location: ?id=' . $ank['id']);
            }
            exit;
        }
    }
    echo "<div class='list-group-item-null'>";

    if (isset($user) && $user['id'] == $public['id_user']) {
        echo "<span style='float: right'>";
        echo "<a href='edit.php?id=" . $public['id'] . "&amp;wall=edit&amp;row=" . $row['id'] . "' class='hint--left' data-hint='" . lang('Редактировать') . "'><i class='fa fa-edit fa-fw'></i></a>";
        echo " <a href='index.php?id=" . $public['id'] . "&amp;del=del&amp;row=" . $row['id'] . "' class='hint--left' data-hint='" . lang('Удалить запись') . "'><i class='fa fa-trash-o fa-fw'></i></a>";
        echo "</span>";
    }


    echo "<b>" . toOutput($row['name']) . "</b>";
    echo "<br />";

    echo "<center>";
    if ($row['ras'] == 'jpg') {
        echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><img src='" . $row['link'] . "' width='60%' alt='Скрин...' /></a><br />\n";

        if (IS_WEB) {
            echo "<div class='modal fade bd-example-modal-sm' id='pic$row[id]' tabindex='-1' role='dialog' aria-hidden='true'>";
            echo "<div class='modal-dialog'>";
            echo "<div class='modal-content'>\n";
            echo "<center>";
            echo "<img src='" . $row['link'] . "' width='100%' alt='Скрин...' /><br />\n";
            echo '</center>';
            echo '</div>';
            echo '</div>';
            echo '</div>';
        }
    }
    if ($row['ras'] == 'jpeg') {
        echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><img src='" . $row['link'] . "' width='60%' alt='Скрин...' /></a><br />\n";
        if (IS_WEB) {
            echo "<div class='modal fade bd-example-modal-sm' id='pic$row[id]' tabindex='-1' role='dialog' aria-hidden='true'>";
            echo "<div class='modal-dialog'>";
            echo "<div class='modal-content'>\n";
            echo "<center>";
            echo "<img src='" . $row['link'] . "' width='100%' alt='Скрин...' /><br />\n";
            echo '</center>';
            echo '</div>';
            echo '</div>';
            echo '</div>';
        }
    }
    if ($row['ras'] == 'gif') {
        echo "<a style='cursor: pointer;' style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><img src='" . $row['link'] . "' width='60%' alt='Скрин...' /></a><br />\n";
        if (IS_WEB) {
            echo "<div class='modal fade bd-example-modal-sm' id='pic$row[id]' tabindex='-1' role='dialog' aria-hidden='true'>";
            echo "<div class='modal-dialog'>";
            echo "<div class='modal-content'>\n";
            echo "<center>";
            echo "<img src='" . $row['link'] . "' width='100%' alt='Скрин...' /><br />\n";
            echo '</center>';
            echo '</div>';
            echo '</div>';
            echo '</div>';
        }
    }
    if ($row['ras'] == 'png') {
        echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><img src='" . $row['link'] . "' width='60%' alt='Скрин...' /></a><br />\n";
        if (IS_WEB) {
            echo "<div class='modal fade bd-example-modal-sm' id='pic$row[id]' tabindex='-1' role='dialog' aria-hidden='true'>";
            echo "<div class='modal-dialog'>";
            echo "<div class='modal-content'>\n";
            echo "<center>";
            echo "<img src='" . $row['link'] . "' width='100%' alt='Скрин...' /><br />\n";
            echo '</center>';
            echo '</div>';
            echo '</div>';
            echo '</div>';
        }
    }
    if ($row['ras'] == 'mp3') {
        if (IS_WEB) {
            echo '<center>
            <audio controls="controls" style="width:100%">
            <source src="' . $row['link'] . '" type="audio/ogg; codecs=vorbis">
            <source src="' . $row['link'] . '" type="audio/mpeg">
            Тег audio не поддерживается вашим браузером. 
            </audio>
            </center>';
        }
    }
    if ($row['ras'] == 'mp4') {
        if (IS_WEB) {
            if (is_file(H . "" . $row['screen'] . "")) {
                echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><img src='" . $row['screen'] . "' width='60%' alt='Скрин...' /></a><br />\n";
            } else {
                echo "<object type=application/x-shockwave-flash data=/sys/uppod.swf width=400 height=210>
            <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=" . $row['link'] . "&amp;st=/sys/public.txt&amp;poster=" . $row['screen'] . " />
            </object>";
                //echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><i class='fa fa-youtube-play fa-5x'></i></a><br />\n";
            }
            echo "<div class='modal fade bd-example-modal-sm' id='pic$row[id]' tabindex='-1' role='dialog' aria-hidden='true'>";
            echo "<center>";
            echo "<object type=application/x-shockwave-flash data=/sys/uppod.swf width=400 height=210>
            <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=" . $row['link'] . "&amp;st=/sys/public.txt&amp;poster=" . $row['screen'] . " />
            </object>";
            echo '</center>';
            echo '</div>';
        } else {
            if (IS_WEB) {
                echo "<object type=application/x-shockwave-flash data=/sys/uppod.swf width=400 height=210>
            <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=" . $row['link'] . "&amp;st=/sys/public.txt&amp;poster=" . $row['screen'] . " />
            </object>";
            } else {
                if (is_file(H . "" . $row['screen'] . "")) {
                    echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><img src='" . $row['screen'] . "' width='60%' alt='Скрин...' /></a><br />\n";
                } else {
                    echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><i class='fa fa-youtube-play fa-5x'></i></a><br />\n";
                }
            }
        }
    }

    if ($row['ras'] == 'flv') {
        if (IS_WEB) {
            if (is_file(H . "" . $row['screen'] . "")) {
                echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><img src='" . $row['screen'] . "' width='60%' alt='Скрин...' /></a><br />\n";
            } else {
                echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><i class='fa fa-youtube-play fa-5x'></i></a><br />\n";
            }
            echo "<div class='modal fade bd-example-modal-sm' id='pic$row[id]' tabindex='-1' role='dialog' aria-hidden='true'>";
            echo "<center>";
            echo "<object type=application/x-shockwave-flash data=/sys/uppod.swf width=400 height=210>
            <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=" . $row['link'] . "&amp;st=/sys/public.txt&amp;poster=" . $row['screen'] . " />
            </object>";

            echo '</center>';
            echo '</div>';
        } else {
            if (IS_WEB) {
                echo "<object type=application/x-shockwave-flash data=/sys/uppod.swf width=400 height=210>
            <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=" . $row['link'] . "&amp;st=/sys/public.txt&amp;poster=" . $row['screen'] . " />
            </object>";
            } else {
                if (is_file(H . "" . $row['screen'] . "")) {
                    echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><img src='" . $row['screen'] . "' width='60%' alt='Скрин...' /></a><br />\n";
                } else {
                    echo "<a style='cursor: pointer;' data-toggle='modal' data-target='#pic$row[id]'><i class='fa fa-youtube-play fa-5x'></i></a><br />\n";
                }
            }
        }
    }

    echo "</center>";

    echo toOutput($row['opis']);

    if (isset($user)) {

        #############################

        $us = $user['id'];
        $go = 'go';

        echo "<hr>";
        $like_f = mysql_result(mysql_query("SELECT COUNT(*) FROM `public_like` WHERE `public` = '" . $row['id'] . "'"), 0);
        if (mysql_result(mysql_query("SELECT COUNT(*) FROM `public_like` WHERE `id_user` = '" . $user['id'] . "' AND `public` = '" . $row['id'] . "'"), 0) == 0) {
            if (!IS_WEB) {
                echo "<a href='index.php?id=" . $public['id'] . "&amp;like=like&amp;row=" . $row['id'] . "'><i class='fa fa-heart-o fa-fw'></i> " . lang('Мне нравится') . " " . (($like_f > 0) ? "<b>$like_f</b>" : "<b>$like_f</b>") . "</a> &#183; ";
            } else {
                echo "<span id='like'><a class='cursor'><i class='fa fa-heart-o fa-fw'></i> " . lang('Мне нравится') . " " . (($like_f > 0) ? "<b>$like_f</b>" : "<b>$like_f</b>") . "</a></span> &#183; ";
                echo '<input type="hidden" id="id_post" value="' . $row['id'] . '" />';
                echo '<input type="hidden" id="go" value="' . $go . '" />';
                echo '<input type="hidden" id="us" value="' . $user['id'] . '" />';
            }
        } else {
            if (!IS_WEB) {
                echo "<a href='index.php?id=" . $public['id'] . "&amp;like=dislike&amp;foto=" . $foto['id'] . "'><i class='fa fa-heart fa-fw'></i> " . lang('Мне нравится') . " " . (($like_f > 0) ? "<b>$like_f</b>" : "<b>$like_f</b>") . "</a> &#183; ";
            } else {
                echo "<span id='like'><a class='cursor'><i class='fa fa-heart fa-fw'></i> " . lang('Мне нравится') . " " . (($like_f > 0) ? "<b>$like_f</b>" : "<b>$like_f</b>") . "</a></span> &#183; ";
                echo '<input type="hidden" id="id_post" value="' . $row['id'] . '" />';
                echo '<input type="hidden" id="go" value="' . $go . '" />';
                echo '<input type="hidden" id="us" value="' . $user['id'] . '" />';
            }
        }

        ####################### коментарии ###########################

        $count_komm = mysql_result(mysql_query("SELECT COUNT(*) FROM `public_wall_komm` WHERE `id_row` = '" . $row['id'] . "'"), 0);
        echo " <i class='fa fa-comments fa-fw'></i> " . lang('Комментарии') . " <b>$count_komm</b>";


        $like_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `public_like` WHERE `public` = '" . $row['id'] . "'"), 0);
        if ($like_post == 0) {
            echo "";
        } else {

            echo "<br /><small style='color: #ccc'>Понравилось  " . $like_f . "  " . ($like_f == 1 ? 'человеку' : 'людям') . "</small><br />";
            $row_like = mysql_query("SELECT * FROM `public_like` WHERE `public` = '" . $row['id'] . "' ORDER BY id DESC LIMIT 5");
            while ($res_like = mysql_fetch_array($row_like)) {
                $us = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '" . $res_like['id_user'] . ")'"));
                echo " <a href='/id$us[id]'>";
                echo avatar($us['id'], '30', 'border-radius: 2px;');
                echo "</a> ";
            }
        }


        if (isset($_POST['komm']) && $public['id'] != 0 && intval($_GET['ko'])) {
            $komm = $_POST['komm'];
            if (!isset($err)) {
                mysql_query("INSERT INTO `public_wall_komm` (`id_row`, `id_user`, `msg`, `time`, `id_kont`) values('" . intval($_GET['ko']) . "', '" . $user['id'] . "', '" . $komm . "', '" . $time . "', '" . $ank['id'] . "')");
                if (isset($user) && $user['id'] != $row['id_ank']) {
                    $msg = "$SexOst " . lang('сообщение в ') . " [url=/modules/public/otvet.php?id=" . intval($_GET['ko']) . "&komm=all]" . lang('Вашей') . "[/url] " . lang('записи на стене') . " ";
                    mysql_query("INSERT INTO `notification` (`id_user`, `id_kont`, `id_img`, `msg`, `time`) values('$user[id]', '$row[id_ank]', '3', '$msg', '$time')");
                }
                if (!isset($_GET['ajax'])) {
                    $_SESSION['message'] = lang('Сообщение успешно добавлено');
                    header('Location: index.php?id=' . $public['id']);
                }
                exit;
            }
        }
    } else {
        echo "<a href='/aut.php' class='list-group-item-null list-group-item-warning'>" . lang('Авторизуйтесь пожалуйста') . "</a>";
    }

    if (isset($user)) {
        echo "<br />";
        if ($public['privat'] == 1) {
            if ($pro_text['id_user'] == $user['id']) {
                echo "<br /><form method='post' name='message' action='index.php?id=" . $public['id'] . "&amp;ko=" . $row['id'] . "' class='list-group-item-null list-group-item-grey'>\n";
                echo "<textarea class='form-control' name='komm' required placeholder='" . lang('Ваш комментарий') . "...'></textarea><br />\n";
                $doc->Button('btn btn-primary btn-sm', null, 'pencil', 'Опубликовать');
                echo "</form><br />";
            }
        } else {
            echo "<br /><form method='post' name='message' action='index.php?id=" . $public['id'] . "&amp;ko=" . $row['id'] . "' class='list-group-item-null list-group-item-grey'>\n";
            echo "<textarea class='form-control' name='komm' required placeholder='" . lang('Ваш комментарий') . "...'></textarea><br />\n";
            $doc->Button('btn btn-primary btn-sm', null, 'pencil', 'Опубликовать');
            echo "</form><br />";
        }
    }


    $q = mysql_query("SELECT * FROM `public_wall_komm` WHERE `id_row` = '" . $row['id'] . "' ORDER BY id DESC LIMIT 3");
    while ($post = mysql_fetch_array($q)) {
        $us = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '" . $post['id_user'] . "'"));
        echo "<table width='100%'><tr><td class='icon14' valign='top'>";
        echo avatar($us['id'], '48', 'border-radius: 3px;');
        echo "</td><td class='null'>";
        echo user($us['id']);
        echo " <small style='color: grey;float: right;'>" . date::timek($post['time']) . "</small>";

        echo "<br />";
        echo toOutput($post['msg']);
        if (isset($user) && $user['id'] == $public['id_user']) {
            echo "<span style='float: right;'>";
            echo "<a href='index.php?id=" . $public['id'] . "&amp;del_komm=del_komm&amp;del_k=" . $post['id'] . "' class='hint--left' data-hint='" . lang('Удалить') . "'><i class='fa fa-trash-o fa-fw'></i></a>";
            echo "</span>";
        }

        echo "</td></tr></table>";
    }

    $ons = mysql_result(mysql_query("SELECT COUNT(*) FROM `public_wall_komm` WHERE `id_row` = '" . $row['id'] . "'"), 0);
    if ($ons >= 3) {
        echo "<center><a href='/modules/public/otvet.php?id=" . $row['id'] . "&amp;komm=all' class='hint--top' data-hint='" . lang('Открыть все комментарии') . "'><i class='fa fa-chevron-down fa-fw'></i></a></center>";
    }

    echo "</div>";
    echo "<div class='hr' style='margin-left: -10px;margin-right: -10px;'></div>";
}

if ($k_page > 1) {
    str("index.php?id=" . $public['id'] . "&amp;", $k_page, $page);
}
