<?php
/**
 * @package     JohnCMS
 * @link        http://johncms.com
 * @copyright   Copyright (C) 2008-2011 JohnCMS Community
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      http://johncms.com/about
 *
 * @var $lng_dl
 */

define('_IN_JOHNCMS', 1);
$headmod = 'loadview';
require_once '../incfiles/core.php';
require_once 'functions.php';
$viewf = intval($_GET['view']);
$file = mysql_query("SELECT * FROM `downfiles` WHERE `id` = '" . $viewf . "'");
if (mysql_num_rows($file))
{
    $file = mysql_fetch_array($file);
    $dopway = str_replace(basename($file['way']), '', $file['way']);
    $file22 = mysql_query("SELECT * FROM `downfiles` WHERE `pathid` = '" . $viewf . "' AND `type` = 1");
    $namee = explode('||||', $file['name']);
    $textl = str_replace('#FILE_NAME#', $namee[0], $lng_dl['file_browser_title']);
    require_once '../incfiles/head.php';
    if (!$file['size'])
    {
        $siz = filesize($loadroot . '/' . $file['way']);
        mysql_query("UPDATE `downfiles` set `size` = '" . $siz . "' WHERE `id` = '" . $viewf . "'");
    }
    else
    {
        $siz = $file['size'];
    }
    $filtime = date("d.m.Y", $file['time']);

    $nadir = $file['pathid'];
    $pat = "";
    while ($nadir != "")
    {

        $dnew = mysql_query("select * from `downpath` where id = '" . $nadir . "';");
        $dnew1 = mysql_fetch_array($dnew);
        $pat = '<a href="dir_' . $dnew1['id'] . '.html" title="' . $dnew1['name'] . '">' .
            $dnew1['name'] . '</a> &gt;  ' . $pat;

        $nadir = $dnew1[refid];
    }

    $tf = pathinfo($file['way'], PATHINFO_EXTENSION);
echo '<div class="phdr"><center>
<strong>' . str_replace('_', ' ', $namee[0]) . '</strong>
</center></div>';




    //////////////////////////
    ////// Скриншоты /////////
    //////////////////////////
    $scr = mysql_result(mysql_query("SELECT COUNT(*) FROM `downscreen` WHERE `fileid` = '".$viewf."'"), 0);
    if ($scr)
    {
        echo '<div class="menu">';
        $screen = mysql_query("SELECT * FROM `downscreen` WHERE `fileid` = '".$viewf."'");
        $i = 1;
        while ($screen1 = mysql_fetch_array($screen))
        {
            if ($i == 1)
            {
                if ($down_setting['screenshot'])
echo '<center><img src="graftemp/' . $screen1[way] . '" alt="Скриншот..."/></center><br/>';
               
            }

{
} 
} 

        echo '</div>';
    }

    /////////////////////////
    ///// Скрин к темам /////
    /////////////////////////
    echo '<div class="menu">';
    if ($down_setting['screenview'])
    {
        if ($tf == 'thm')
        {
            if (!is_file($loadroot . '/' . $file['way'] . '.GIF'))
                autoscreen_thm($loadroot . '/' . $file['way'], 128, 160, $loadroot . '/' . $file['way'] .
                    '.GIF');
            echo '<img src="' . $loadroot . '/' . $file['way'] .
                '.GIF" alt="'.$lng_dl['screen'].'"/><br/>';
        } elseif ($tf == 'nth')
        {
            if (!is_file($loadroot . '/' . $file['way'] . '.GIF'))
                autoscreen_nth($loadroot . '/' . $file['way'], 128, 160, $loadroot . '/' . $file['way'] .
                    '.GIF');
            echo '<img src="' . $loadroot . '/' . $file['way'] .
                '.GIF" alt="'.$lng_dl['screen'].'"/><br/>';
        }
    }
    /////////////////////////
    ///// Скрин к видео /////
    /////////////////////////
    //TODO:Переделать обработку видео...
    if ($tf == '3gp' or $tf == 'avi' or $tf == 'mp4')
    {
        if ($down_setting['screenvideo'])
        {
            if (!is_file($loadroot . '/' . $file['way'] . '.GIF'))
                autoscreen_video($loadroot . '/' . $file['way'], $loadroot . '/' . $file['way'] .
                    '.GIF', 132, 96);
            echo '<img src="' . $loadroot . '/' . $file['way'] .
                '.GIF" alt="'.$lng_dl['screen'].'"/><br/>';
        }
        if ($down_setting['infvideo'])
        {
            $media = new ffmpeg_movie($loadroot . '/' . $file['way']);
            echo $lng_dl['time_move'].': ' . date('m:s', $media->getDuration()) . '<br/>';
            echo $lng_dl['frame_size'].': ' . $media->getFrameHeight() . 'x' . $media->getFrameWidth() .
                '<br/>';
            echo $lng_dl['bitrate'].': ' . $media->getVideoBitRate() . 'kpbs <br/>';
        }
    }

    ////////////////////////////////////
    //////// Скрин к картинке //////////
    ////////////////////////////////////
    if ($tf == 'gif' or $tf == 'png' or $tf == 'jpg' or $tf == 'jpeg')
    {
        if (!$down_setting['screencache'])
        {
            echo '<img src="getthumb.php?file=' . $loadroot . '/' . $file['way'] .
                '&amp;size=120" alt="'.$lng_dl['screen'].'"/><br/>';
        } else
        {
            if (!is_file('graftemp/' . $file['id'] . '.big.' . $tf))
            {
                $img = new ImageEdit($loadroot . '/' . $file['way'], $down_setting['scr_size']);
                // Подаём оригинал и максимальный размер
                $img->setQuality(90);
                // Качество
                if ($down_setting['scr_copy'])
                    $img->setCopy($down_setting['scr_copy_size'], $down_setting['scr_copy_text']);
                $img->saveImage('graftemp/' . $file['id'] . '.big.' . $tf);
                // Сохраняем во временную папку
            }
            echo '<img src="graftemp/' . $file['id'] . '.big.' . $tf .
                '" alt="'.$lng_dl['screen'].'"/><br/>';
        }
    }


echo ' Fayl turi: ' . $tf . ' ';
echo '<b>|</b>Qo\'shildi: ' . $filtime . '</div>';
    if ($file['login'])
    {
echo '<div class="menu">Qo\'shdi: <a href="../users/profile.php?user=' . $file['user_id'] . '">' . $file['login'] . '  </a>';
    }
echo '<b>| 
</b>Yuklab olindi: ' . ending($file['count']) . '</div>';

    ///////////////////////////////
    //////// Если это JAR /////////
    ///////////////////////////////
    if ($tf == 'jar')
    {
        $archive2 = new JarInfo($loadroot . '/' . $file['way']);

        //$archive2->setDeleteConfirm('Скачать программу повторно можно с сайта symbos.su');
        //$archive2->saveManifest();

        if ($down_setting['jar_version'] > 0 && $archive2->getVersion())
            echo '<div class="menu"><b>'.$lng_dl['version'].':</b> ' . $archive2->getVersion() . '</div>';
        if ($down_setting['jar_name'] > 0 && $archive2->getName())
            echo '<div class="menu"><b>'.$lng_dl['name'].':</b> ' . $archive2->getName() . '</div>';
        if ($down_setting['jar_vendor'] > 0 && $archive2->getVendor())
            echo '<div class="menu"><b>'.$lng_dl['vendor'].':</b> ' . $archive2->getVendor() .
                '</div>';
        if ($down_setting['jar_profile'] > 0 && $archive2->getProfile())
            echo '<div class="menu"><b>'.$lng_dl['profile'].':</b> ' . $archive2->getProfile() . '</div>';
        if ($down_setting['jar_url'] > 0 && $archive2->getUrl())
            echo '<div class="menu"><b>Url:</b> ' . $archive2->getUrl() . '</div>';
        // Получаем иконку если её ещё нет.
        $icon = 'graftemp/' . $file['id'] . '.icon.png';
        if (!is_file('graftemp/' . $file['id'] . '.icon.png'))
        {
            if (!$archive2->getIcon('graftemp/' . $file['id'] . '.icon.png'))
                $icon = 'img/jar.png';
        }
    }
    ///////////////////////
    ////// Описание ///////
    ///////////////////////
   

    /////////////////////////
    ////// Инфа о mp3 ///////
    /////////////////////////
    if ($down_setting['mp3info'])
    {
        if ($tf == 'mp3')
        {
            echo '<div class="menu">';
// Tageditor
if ($rights >= 7) {
echo '<div><img src="img/edit.png" alt="." /> <a href="tageditor.php?file=files' . DIRECTORY_SEPARATOR . $file['way']. '">Edit tag ' . $namee[1] . '</a></div>';
} 

            require_once 'classes/classAudioFile.php';
            $f = new AudioFile;
            // добавляем аудиофайл
            $f->loadFile($loadroot . '/' . $file[way]);
            // выводим информацию
            echo functions::checkout(str_replace('&', '&amp;', $f->printSampleInfo()), 1, 1);


            echo '</div>';
        }
    }


    ///////////////////////////////////
    ////// Обсуждение на форуме ///////
    ///////////////////////////////////


    if ($dostguest == 'open')
    {

        if (!$namee[1])
        {
            $namee[1] = $lng_dl['primary_file'];
        }
        if (!isset($icon))
            $icon = 'img/save.png';

echo '<div class="menu">
<a href="loadfile.php?down=' . $file['way'] . '"><b><big><red><center><font color="red">Yuklab Olish | Скачать (' . size_convert($siz) . ') </font></center></red></big></b>
</a>';

        //////////////////////////
        ////// Получаем JAD //////
        //////////////////////////
        if ($tf == 'jar' && $down_setting['jadgen'])
        {
            $jadf = str_ireplace('.jar', '.jad', $file['way']);
            $jarurl = '' . $home . '/' . $downpat . '/' . $file['way']; //// Адрес файла записываемый в JAD
            if (!is_file($loadroot . '/' . $jadf))
                $archive2->getJad($jarurl);
            echo '&nbsp;<a href="loadfile.php?down=' . $file['way'] .
                '&amp;jad=1">[JAD]</a>';
        }

echo '</div>';
        ///////////////////////////////////////
        ///// Выбор размеров для картинок /////
        ///////////////////////////////////////
        if ($tf == 'gif' || $tf == 'jpg' || $tf == 'png')
        {
            echo "
<div class='menu'>
<form action='image.php' method='get'>
<img src=\"img/view.png\" alt='.'/> <b>".$lng_dl['download_with_size'].":</b><br/>
<select title='Выберите размер' name='size'>";
            echo '<option value="640x480">640x480</option><option value="240x320">240x320</option><option value="208x208">208x208</option><option value="176x220">176x220</option><option value="176x208">176x208</option><option value="132x176">132x176</option><option value="128x160">128x160</option></select>
<input type="hidden" name="file" value="' . $loadroot . '/' . $file['way'] . '"/>
<input type="submit" value="'.$lng_dl['download'].'"/></form></div>';
        }

        ///////////////////////////////
        ////// Просмотр архивов ///////
        ///////////////////////////////
        if ($down_setting['zipview'])
        {
            if ($tf == "zip")
            {
                echo '<div class="menu"><img src="img/rar.png" alt="."/> <a href="zipview.php?file_id=' . $viewf . '">'.$lng_dl['view_zip'].'</a></div>';
            }
        }


        ////////////////////////////////
        ///// Дополнительные файлы /////
        ////////////////////////////////
        if (mysql_num_rows($file22))
        {
            while ($file2 = mysql_fetch_array($file22))
            {
                $tf = pathinfo($file2['way'], PATHINFO_EXTENSION);
                echo '<div class="menu"><img src="img/save.png" alt="."/> <a href="loadfile.php?down=' .
                    $file2['way'] . '">'.$lng_dl['download'].' ' . $file2['name'] . '</a>';
                if ($tf == "jar" && $down_setting['jadgen'])
                {
                    $archive2 = new JarInfo($loadroot . '/' . $file2['way']);
                    $jadf = str_ireplace('.jar', '.jad', $file2['way']);
                    $jarurl = '' . $home . '/' . $downpat . '/' . $file2['way']; //// Адрес файла записываемый в JAD
                    if (!is_file($loadroot . '/' . $jadf))
                        $archive2->getJad($jarurl);
                    echo '&nbsp;<a href="loadfile.php?down=' . $file2['way'] .
                        '&amp;jad=1">[JAD]</a>';
                }
                echo '&nbsp;[' . $file2['count'] . ']<br/>'.functions::checkout($file2['desc'], 1, 1).'</div>';

                if ($tf == "zip" && $down_setting['zipview'])
                    echo '<img src="img/rar.png" alt="."/> <a href="zipview.php?file_id=' . $viewf . '">'.$lng_dl['view_zip'].'</a><br/>';
            }
        }
    }
    else
    {
        echo '<b>'.$lng_dl['download_register_only'].'</b><br/>';
    }

    //////////////////////////////////
    /////// Поделиться ссылкой ///////
    //////////////////////////////////




?>
<script src="//yastatic.net/es5-shims/0.0.2/es5-shims.min.js"></script>
<script src="//yastatic.net/share2/share.js"></script>
<div class="ya-share2" data-services="vkontakte,facebook,odnoklassniki,moimir,whatsapp,telegram"></div>
</div>

    </div>
    <?php

    if ($down_setting['komm'])
    {
        $totalk = mysql_result(mysql_query("SELECT COUNT(*) FROM `downkomm` WHERE `fileid` = '" . $viewf . "';"), 0);
echo '<div class="menu">Do\'stlaringizga bu xaqida ayting!
</div>';
    }


} else
{
    echo '<div class="rmenu">'.$lng_dl['file_not_found'].'</div>';
}

require_once '../incfiles/end.php';
