<?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'])) {
    $video['id'] = intval($_GET['id']);
}
$video = mysql_fetch_array(mysql_query("SELECT * FROM `public_video` WHERE `id` = '" . $video['id'] . ")'"));
$public = mysql_fetch_array(mysql_query("SELECT * FROM `public` WHERE `id` = '" . $video['id_public'] . ")'"));

if ($video['id'] == intval($_GET['id'])) {
    $set['title'] = $video['name'];
    require_once H . 'sys/inc/thead.php';

    if (isset($_GET['del']) && $_GET['del'] == 'delete') {
        echo "<div class='list-group-item-null list-group-item-warning'>" . lang('Подтвердите удаление') . " " . $video['name'] . "<br />";
        echo "<a class='btn btn-success btn-sm' href='video.php?id=" . $video['id'] . "&amp;del=del&amp;post=$video[id]'><i class='fa fa-trash-o fa-fw'></i> " . lang('Удалить') . "</a> ";
        echo "<a class='btn btn-secondary btn-sm' href='video.php?id=" . $video['id'] . "'>" . lang('Отмена') . "</a>";
        echo "</div>";
    }

    if (isset($_GET['like']) && $_GET['like'] == 'dislike') {
        mysql_query("DELETE FROM `like` WHERE `id_user` = '" . $user['id'] . "' AND `pub_video` = '" . $video['id'] . "'");
        mysql_query("OPTIMIZE TABLE `like`");
        msg('Лайк отменен');
        header("Location: video_file.php?id=" . $video['id'] . "");
    } elseif (isset($_GET['like']) && $_GET['like'] == 'like') {
        mysql_query("INSERT INTO `like` (`id_user`, `pub_foto`, `like`) values('" . $user['id'] . "', '" . $video['id'] . "', '+1')", $db);
        mysql_query("INSERT INTO `wall` (`id_wall`, `link`, `ras`, `name`, `id_ank`, `id_pub`, `type`, `id_file`) values('" . $user['id'] . "', '/sys/public/video/" . $video['ras'] . "/" . $video['id'] . "." . $video['ras'] . "', '" . $video['ras'] . "', '" . $video['name'] . "', '" . $user['id'] . "', '" . $public['id'] . "', 'public_video', '" . $video['id'] . "')");
        msg('Вам понравилось');
        header("Location: video_file.php?id=" . $video['id'] . "");
    }
    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 "<a href='video.php?id=$public[id]'>" . lang('Видеозаписи') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo lang('Видеозапись');
    echo "</small></div><br />";

    echo "<div class='list-group-item-null list-group-item-grey'>";
    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_file.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 toOutput($video['name']);
    echo "</div>";

    $file = H . '/sys/public/video/' . $video['ras'] . '/' . $video['id'] . '.' . $video['ras'] . '';



    echo "<center><object type=application/x-shockwave-flash data=/sys/uppod.swf width=300 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=/sys/public/video/" . $video['ras'] . "/" . $video['id'] . "." . $video['ras'] . "&amp;st=/sys/public.txt&amp;poster=/sys/public/video/screen/" . $video['id'] . ".gif />
</object></center>";

    if (is_file(H . "sys/public/video/screen/" . $video['id'] . ".gif")) {
        echo "<img src='/sys/public/video/screen/" . $video['id'] . ".gif' alt='scr...' /><br />\n";
    } elseif (class_exists('ffmpeg_movie')) {
        $media = new ffmpeg_movie($file);
        $k_frame = intval($media->getFrameCount());

        $w = $media->GetFrameWidth();
        $h = $media->GetFrameHeight();
        $ff_frame = $media->getFrame(intval($k_frame / 2));
        if ($ff_frame) {
            $gd_image = $ff_frame->toGDImage();
            if ($gd_image) {
                $des_img = imagecreatetruecolor(128, 128);
                $s_img = $gd_image;
                imagecopyresampled($des_img, $s_img, 0, 0, 0, 0, 128, 128, $w, $h);
                $des_img = img_copyright($des_img); // наложение копирайта
                imagegif($des_img, H . "sys/public/video/screen/" . $video['id'] . ".gif");
                chmod(H . "sys/public/video/screen/" . $video['id'] . ".gif", 0777);
                imagedestroy($des_img);
                imagedestroy($s_img);
                if (function_exists('iconv')) {
                    echo "<img src='" . iconv('windows-1251', 'utf-8', "/sys/public/video/screen/" . $video['id'] . ".gif") . "' alt='scr...' /><br />\n";
                } else {
                    echo "<img src='/sys/public/video/screen/" . $video['id'] . ".gif' alt='scr...' /><br />\n";
                }
            }
        }
    }


    echo "<div class='list-group-item-null'><a class='btn btn-secondary btn-sm' href='/sys/public/video/" . $video['ras'] . "/" . $video['id'] . "." . $video['ras'] . "'><i class='fa fa-save fa-fw'></i> " . lang('Cкачать') . " " . $video['ras'] . "</a></div>";
}
include_once H . 'sys/inc/tfoot.php';
?>