<?php

/* DCMS Special
 * Дата последнего редактирования 29.09.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'] == intval($_GET['id'])) {
    $set['title'] = lang('Видеозаписи') . " - " . $public['name'];
    require_once H . 'sys/inc/thead.php';

    if (isset($user) && $user['id'] == $public['id_user']) {
        if (isset($_GET['del']) && $_GET['del'] == 'del' && intval($_GET['post'])) {
            $pubic = $db->get_array($db->query("SELECT * FROM `public_video` WHERE `id` = '" . intval($_GET['post']) . "' LIMIT 1"));
            @unlink(H . "sys/public/video/" . $pubic['ras'] . "/" . $pubic['id'] . "." . $pubic['ras']);
            @unlink(H . "sys/public/video/screen/" . $pubic['id'] . ".gif");
            $db->query("DELETE FROM `public_video` WHERE `id` = '" . intval($_GET['post']) . "'");
            $_SESSION['message'] = lang('Видеозапись успешно удалена');
            header("Location: video.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 "<a href='index.php?id=$public[id]'>" . toOutput($public['name']) . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo lang('Видеозаписи');
    echo "</small></div><br />";

    if (isset($user) && $user['id'] == $public['id_user']) {
        if (isset($_GET['del']) && $_GET['del'] == 'delete' && intval($_GET['row'])) {
            $publ = $db->get_array($db->query("SELECT * FROM `public_video` WHERE `id` = '" . intval($_GET['row']) . "' LIMIT 1"));
            echo "<div class='list-group-item-null list-group-item-warning'>" . lang('Подтвердите удаление') . " " . $publ['name'] . "<br />";
            echo "<a class='btn btn-success btn-sm' href='video.php?id=" . $public['id'] . "&amp;del=del&amp;post=" . $publ['id'] . "'><i class='fa fa-trash-o fa-fw'></i> " . lang('Удалить') . "</a> ";
            echo "<a class='btn btn-secondary btn-sm' href='video.php?id=" . $public['id'] . "'>" . lang('Отмена') . "</a>";
            echo "</div>";
        }
    }

    $ank = $db->get_array($db->query("SELECT * FROM `public_coint` WHERE `id_public` = '" . $public['id'] . "' AND `id_user` = '" . $user['id'] . "' LIMIT 1"));
    if (isset($user) && $ank['id_user'] == $user['id']) {
        if (isset($user) && $user['id'] == $public['id_user'] || $public['v'] == '0') {
            echo "<div class='list-group-item-null'>";
            echo "<div class='btn btn-secondary btn-sm'><a href='edit.php?id=" . $public['id'] . "&amp;video=add'><i class='fa fa-youtube-play fa-fw'></i> " . lang('Добавить видеозапись') . "</a></div>";
            echo "</div>";
        }
    }

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

    echo "<div class='list-group-item-null list-group-item-grey'>";
    echo "<i class='fa fa-youtube-play fa-fw'></i> " . lang('Видеозаписи') . " <small style='color: grey;'>$vid</small>";
    echo "</div>";

    $k_post = $db->super_query("SELECT COUNT(*) as count FROM `public_video` WHERE `id_public` = '$public[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();
    }

    $q = $db->query("SELECT id,name,ras FROM `public_video` WHERE `id_public` = '" . $public['id'] . "' ORDER BY id DESC LIMIT $start, " . $set['p_str'] . "");
    while ($video = $db->get_array($q)) {
        echo "<div class='list-group-item-null'>";
        echo "<span style='float: right;'>";
        if (isset($user) && $user['id'] == $public['id_user']) {
            echo "<a href='edit.php?id=" . $public['id'] . "&amp;video=video&amp;row=" . $video['id'] . "' class='hint--left' data-hint='" . lang('Редактировать') . "'><i class='fa fa-edit fa-fw'></i></a> ";
        }
        if (isset($user) && $user['id'] == $public['id_user']) {
            echo " <a href='video.php?id=" . $public['id'] . "&amp;del=delete&amp;row=" . $video['id'] . "' class='hint--left' data-hint='" . lang('Удалить') . "'><i class='fa fa-trash-o fa-fw'></i></a>";
        }
        echo "</span>";
        echo "<a href='video_file.php?id=" . $video['id'] . "'><i class='fa fa-youtube-play fa-fw'></i> " . toOutput($video['name']) . "</a><br />";
        echo "</div>";
        echo "<div class='hr'></div>";
    }

    if ($k_page > 1) {
        str("video.php?id=" . $public['id'] . "&amp;", $k_page, $page);
    }
}
include_once H . 'sys/inc/tfoot.php';
?>