<?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>';

echo '<div class="menu">';
//////////////////////////
    ////// Скриншоты /////////
    //////////////////////////
    $scr = mysql_result(mysql_query("SELECT COUNT(*) FROM `downscreen` WHERE `fileid` = '".$viewf."'"), 0);
    if ($scr)
    {
        
        $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 '<div class="sect fcols fx-row">
<div class="fleft">
					<div class="fimg img-fit"><img src="graftemp/' . $screen1[way] . ' " alt="Скриншот..."/></div></div>' ;
               
            }
} 
 } else { echo '<div class="sect fcols fx-row">
<div class="fleft">
					<div class="fimg img-fit"><img src="/images/cower.png" alt="salomlar.uz" /></div>
					<div class="ffav icon-left">
					
					</div>
				</div>'; }
echo '<div class="fmain fx-1">
					<h1 class="sect-title">' . str_replace('_', ' ', $namee[0]) . '<div></div></h1>
					<ul class="finfo">
						<li><span>	Скачано:</span>  ' . ending($file['count']) . '</li>
						<li><span>Добавлено:</span> ' . $filtime . '</li>
						<li><span>Добавил:</span> ' . $file['login'] . '</li>
<li><span>Размер: </span>' . size_convert($siz) . '</li>
						
						
					</ul>  
						<br /><center>
						<audio src="loadfile.php?down=' . $file['way'] . '" preload="auto" controls></audio>
			<br />
		
<br />
				<a href="loadfile.php?down=' . $file['way'] . '"><img src="/download.png" alt=""/> </a>
</center></div>
                 <div class="fctrl fx-row">
	
				</div>			<div class="fright fx-col fx-between">
					<div class="fcaption">На этой странице Вы можете <b>скачать песню ' . str_replace('_', ' ', $namee[0]) . '</b>!. Слушайте онлайн в хорошем качестве, 
					со своего телефона на Android, iphone или пк в любое время. </div></div></div>';
echo '</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] . ' " width=" 340" height="270" alt="Скриншот..."/></center><br/>' ;
               
            }
} 

        echo '</div>';
    } else { echo '<div class="sect fcols fx-row">
<div class="fleft">
					<div class="fimg img-fit"><img src="/images/cower.png" alt="salomlar.uz" /></div>
					<div class="ffav icon-left">
					
					</div>
				</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/>';
        }
    }



    ///////////////////////////////
    //////// Если это 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 ($dostguest == 'open')
    {

        if (!$namee[1])
        {
            $namee[1] = $lng_dl['primary_file'];
        }
        if (!isset($icon))
            $icon = 'img/save.png';
echo '<center>Ijtimoiy tarmoqlar orqali bu haqida do\'stlaringizga bu xaqida ayting!</br><center><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></center>';

        //////////////////////////
        ////// Получаем 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/>';
    }

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




?>
</div>

    
    <?php

    if ($down_setting['komm'])
    {
        $totalk = mysql_result(mysql_query("SELECT COUNT(*) FROM `downkomm` WHERE `fileid` = '" . $viewf . "';"), 0);
    }


} else
{
    echo '<div class="rmenu">'.$lng_dl['file_not_found'].'</div>';
}
if ($rights >= 9) {echo '<div class="menu">';
echo '<a href="/download/admin.php?act=edit&file='. $file['id'] . '"><i class="fa fa-circle" aria-hidden="true"></i>Taxrirlash</a> | <a href="/download/admin.php?act=delete&op=file&id='. $file['id'] . '"><i class="fa fa-circle" aria-hidden="true"></i>O\'chirish</a>';
        if ($tf == 'mp3') {
 echo ' | <a href="tageditor.php?file=files' . DIRECTORY_SEPARATOR . $file['way'] . '"><i class="fa fa-circle" aria-hidden="true"></i>Teglarni tahrirlash</a>';
} echo '</div>'; }
echo '<div class="phdr"><center>Mavzuga oid yangi fayllar</center></div>';
echo '<div class="menu">';
$nadir = $file[pathid];
    $pat = "";
while ($nadir != "") {
$dnew = mysql_query("select * from `downpath` where id = '" . $nadir . "';");
$dnew1 = mysql_fetch_array($dnew);
$pat = '' . $dnew1['id'] . '
' . $pat;
        $nadir = $dnew1[refid];
$cata = mysql_query("SELECT * FROM `downpath` WHERE `id` = '" . $dnew1['id'] . "' LIMIT 1");
if(mysql_num_rows($cata)){
$cata = mysql_fetch_assoc($cata);
}else{ 
$cata = array('way' => '');
} 
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `downfiles` WHERE `type` != 1 AND `status` = 1 && `way` LIKE '" . $cata['way'] ."%'"), 0);
$zap = mysql_query("SELECT * FROM `downfiles` WHERE `type` != 1 AND `status` = 1 && `way` LIKE '" . $cata['way'] ."%' ORDER BY `time` DESC LIMIT 5");
}
while ($ok = mysql_fetch_array($zap)) { 
$i; 
$ok['name'] = str_replace('||||','',$ok['name']); 
echo "<a href='/download/" . str_replace(' ', '_', $ok['name']) . "_".$ok['id'].".html'><i class='fa fa-music' aria-hidden='true'></i> ".$ok['name']."</a> ";
echo '<hr>';
}
echo '</div>';

echo'<div class="phdr"><center>Bildirilgan izohlar</center></div>';
	if ($user_id) {
    if (isset($_POST['submit']))
    {
        
    if(empty($_POST['txt']))
    {
        echo'</div>';
    } else {
    
    mysql_query("INSERT INTO `downkomm` (`id`, `fileid`, `time`, `userid`, `text`, `plus`, `minus`, `golos`) VALUES (NULL, '".$viewf."', '".time()."', '".$user_id."', '".mysql_real_escape_string($_POST['txt'])."', '0', '0', '');");    
    $req = mysql_query("SELECT * from `users` where id = '".$user_id."';");
    $res = mysql_fetch_array($req);
    $fpst = $res['komm'] + 1;
    mysql_query("UPDATE `users` SET `komm`='" . $fpst . "' WHERE `id`='" . $user_id . "';");


        if($down_setting['priv'] > 0)
        {
            $text_mail = 'Yuklamalarda komment qoldirildi. [url='.core::$system_set['homeurl'].'/download/file_'.$viewf.'.html]Ko\'rish[/url]';
            mysql_query("INSERT INTO `cms_mail` SET
                    `user_id` = '0',
                    `from_id` = '" . $down_setting['priv_user'] . "',
                    `text` = '" . mysql_real_escape_string($text_mail) . "',
                    `time` = '" . time() . "',
                    `sys` = '1'") or die(mysql_error());
        }

    
    echo'<div class="gmenu">Komment qo\'shildi!</div>';   
    }
	}
        
    $set_download = unserialize($datauser['set_forum']);
    
    echo '<form method="post" name="komm">
    <div class="menu">';
    if(!$is_mobile)
echo bbcode::auto_bb('form', 'msg');
    echo '<textarea cols="' . $set_user['field_w'] . '" rows="' . $set_user['field_h'] . '" name="txt" placeholder="Iltimos bemani fikr bildirmang!"></textarea>
    <input type="submit" name="submit" value="Yozish"/></div>
    </form>';
	}
    $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `downkomm` WHERE `fileid` = '" . $viewf . "';"), 0);
    if ($total > 0) {
    $query = mysql_query("select * from `downkomm` where fileid='" . $viewf . "' ORDER BY `time` DESC LIMIT " . $start . "," . $kmess);
    while($arr = mysql_fetch_array($query)){
    echo ($i % 2) ? '<div class="menu">' : '<div class="menu">';
    $i++;
    $res = mysql_fetch_array(mysql_query("SELECT * from `users` where id = '".$arr['userid']."';"));      
    
    $text = functions::checkout($arr['text'], 1, 1);
    $text = functions::smileys($text);
    $vrp = $arr['time'] + $sdvig * 3600;
    $idd = explode('|',$arr['golos']);
    $vr = date("d.m.y / H:i", $vrp);
    $upr = '';
    if($rights >= 1)
    $upr .= '<a href="komm.php?act=del&amp;komid='.$arr['id'].'&amp;id='.$viewf.'">[O\'chirish]</a> ';
    $arg = array ('stshide' => 1, 'header' => '('.$vr.')',
    'body' => $text,
    'sub' => $upr,
    'iphide' => 1);
    echo functions::display_user($res, $arg) . '</div>';
    } 
    } if ($user_id) {  
echo "</div>";
 } else { 
echo "<div class='menu'><center>Izoh qoldirish uchun saytga foydalanuvchi sifatida tashrif buyuring.<br>[ <a href='" . $set['homeurl'] . "/registration.php'>Ro'yhatdan o'tish</a> | ";
echo "<a href='" . $set['homeurl'] . "/login.php'>Kirish</a> ]</center></div>";
}
    if ($total > $kmess){
   	echo '<div class="menu">' . functions::display_pagination('komm.php?id='.$id.'&amp;', $start, $total, $kmess) . '';
    }
require_once '../incfiles/end.php';
