<?php
//___________________________¶¶
//__¶¶¶¶¶____________________¶¶
//_¶¶____¶
//¶¶_________¶¶¶¶___¶¶¶¶¶___¶¶¶___¶¶¶¶___¶¶_¶¶
//¶¶____________¶¶__¶¶__¶¶___¶¶______¶¶__¶¶¶¶¶
//¶¶_________¶¶¶¶¶__¶¶__¶¶___¶¶___¶¶¶¶¶__¶¶
//¶¶__¶¶¶¶__¶¶__¶¶__¶¶__¶¶___¶¶__¶¶__¶¶__¶¶
//¶¶____¶¶__¶¶__¶¶__¶¶__¶¶___¶¶__¶¶__¶¶__¶¶
//_¶¶___¶¶__¶¶__¶¶__¶¶__¶¶___¶¶__¶¶__¶¶__¶¶
//__¶¶¶¶¶¶___¶¶¶¶¶__¶¶__¶¶___¶¶___¶¶¶¶¶__¶¶
//___________________________¶¶
//_________________________¶¶¶
//ICQ: 993770


define('_IN_JOHNCMS', 1);
$zc=1;
$headmod = 'load';
$textl = 'Загрузки';
require_once ("../incfiles/core.php");
require_once ("../incfiles/head.php");
$time = time();
$setting = mysql_query('SELECT * FROM `zc_setting`;');

while($set = mysql_fetch_assoc($setting)){
$setup[$set['name']] = $set['value'];
}

$hackmess = $setup['hackmess'];

require 'moduls/ini.php';
require 'moduls/fun.php';

//require 'moduls/header.php';
session_name('SID') ;

###############Сесии###############
if(session_start()){
if(!empty($_SESSION["onpage"]) AND !empty($_GET['onpage'])){
$_SESSION["onpage"]=$_GET['onpage'];
}
elseif(empty($_SESSION["onpage"]) AND !empty($_GET['onpage']))
{
 $onpage=$_GET['onpaget'];
 session_register ("onpage") ;
}

if(!empty($_SESSION["prew"]) AND !empty($_GET['prew']))
$_SESSION["prew"]=$_GET['prew'];
elseif(empty($_SESSION["prew"]) AND !empty($_GET['prew']))
{
 $prew=$_GET['prew'];
 session_register ("prew") ;
}

if(!empty($_SESSION["sort"]) AND !empty($_GET['sort']))
$_SESSION["sort"]=$_GET['sort'];
elseif(empty($_SESSION["sort"]) AND !empty($_GET['sort']))
{
 $sort=$_GET['sort'];
 session_register ("sort") ;
}
 }

###############Проверка переменных###############
$onpage = intval($_SESSION["onpage"]);
$prew = intval($_SESSION["prew"]);
$sort = get2ses('sort');
$id = intval($_GET['id']);
if (!empty ($_POST['page']))
{
$page = intval($_POST['page']);}
else {$page = intval($_GET['page']);}
$start = intval($_GET['start']);

if($onpage < 3){
$onpage = 10;
}

if($prew != 0 and $prew != 1){
$prew = $setup['preview'];
}

$valid_sort = array('name' => '','data' => '','load' => '','size' => '','eval' =>'');
if(!isset($valid_sort[$sort])){
$sort='name';
}

$MODE = '`priority` DESC,`name` ASC';
if($sort == 'data') $MODE = '`priority` DESC,`timeupload` DESC';
elseif($sort == 'size') $MODE = '`priority` DESC,`size` ASC';
elseif($sort == 'load') $MODE = '`priority` DESC,`loads` DESC';
elseif($sort == 'eval' && $setup['eval_change']) $MODE = '`priority` DESC,`yes` DESC ,`no` ASC';
###############Получаем текущий каталог#############
if(!$id){
$d['path'] = $setup['path'].'/';
}
else{
$d = mysql_fetch_assoc(mysql_query('SELECT `path` FROM `'.$setup['pref'].'files` WHERE `id` = '.$id.' LIMIT 1'));
}

if(!is_dir($d['path'])) die('Folder not found.</div></body></html>');


###############Постраничная навигация###############
$all = mysql_fetch_row(mysql_query('SELECT COUNT(`id`) FROM `'.$setup['pref'].'files` WHERE `infolder` = "'.$d['path'].'"'));
$all = $all[0];
$pages = ceil($all/$onpage);
if(!$pages) $pages = 1;
if($page>$pages or $page<=0) $page=1;
if($start>$all or $start<=0) $start = 0;
if($page) $start = ($page - 1) * $onpage; else $start = 0;

$open=1; $endurl='&amp;open=1'; $endquery=' AND `open`=1'; 
###############Получаем список файлов###############
$array_id = array();
$query = mysql_query('SELECT `id` FROM `'.$setup['pref'].'files` WHERE `infolder` = "'.$d['path'].'"   AND (`open` = '.$open.' OR `size` = 0) ORDER BY '.$MODE.' LIMIT '.$start.', '.$onpage);
while($list_sw = mysql_fetch_row($query)){
$array_id[] = $list_sw[0];
}
###############Готовим заголовок###################
$ex = explode('/',$d['path']);
foreach($ex as $k=>$v)
{
if($v!='' and $v!='.' and $v!='..' and $v!=$setup['path'])
{
$s = mysql_fetch_array(mysql_query("SELECT `id`,`name` FROM `".$setup['pref']."files` WHERE `path` LIKE '%".clean($v)."/' AND `size` = '0'"));
$s['name'] = str_replace('*','',$s['name']);
if($k >= sizeof($ex)-2) $put .= $s['name'];
else $put .= '<a href="index.php?id='.$s['id'].$endurl.'">'.$s['name'].'</a>&raquo;';
}
}

##############Заголовок##########################

echo '<div class="phdr"><a href="index.php?'.$endurl.'">Зона обмена</a> | '.$put.'</div>';
###############Вывод рекламы###############
if($setup['buy_change']==1)
{
echo '<div class="list1">';
$list = explode("\n",$setup['buy']);
if($setup['randbuy']==1) echo '<li>'.bbcode($list[mt_rand(0,sizeof($list)-1)]).'</li> ';
else foreach($list as $value) echo '<li>'.bbcode($value).'</li> ';
echo'</div>';
}

############################################
echo '<div class="bmenu">';
if($setup['search_change']==1) echo '<a href="search.php?'.$endurl.'">Поиск файлов</a><br />';
if($setup['top_change']==1) echo '<a href="top.php?'.$endurl.'">ТОП '.$setup['top_num'].' файлов</a><br />';
  $new_all_files = mysql_fetch_row(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'files` WHERE `timeupload` > '.($time-(86400*$setup['day_new'])).' AND `size` > 0'.$endquery));
if($new_all_files[0]!=0 AND $setup['new_change']==1) echo '<a href="new.php?'.$endurl.'">Новые файлы </a>[+'.$new_all_files[0].']<br />';
include 'user2.php';
if(!$id AND $setup['new_komm']==1) echo '<li><a href="allkomm.php?'.$endurl.'">Посл. '.$setup['komm_num'].' комм.</a></li>';
echo '</div>
';
###############Список фалов и папок###############
if ($all == 0) echo '<div class="list1"><strong>[Раздел пуст]</strong></div>';
foreach($array_id as $key => $value)
{
 	$file_info = mysql_fetch_array(mysql_query('SELECT * FROM `'.$setup['pref'].'files` WHERE `id` = "'.$value.'";'));

	if(is_dir($file_info['path']))
 	{
   	if(is_integer($key / 2)) $row = '<div class="list1">'; else $row = '<div class="list2">';
 	if (!empty($file_info['fastabout'])) $file_info['about'] = str_replace("\n", ' <br/>',$file_info['about']);
   		//Кол-во новых файлов в папке
   		$new_all="";
        $stime=$time-(3600*24*$setup['day_new']);
   		//NOT USE//$new_all = mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'files` WHERE `timeupload` > "'.$stime.'" AND `infolder` REGEXP "'.$file_info['path'].'*" AND `size` > "0";'));
   		if($setup['day_new']!=0) $new_all = mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'files` WHERE `timeupload` > "'.$stime.'" AND `infolder` LIKE  "'.$file_info['path'].'%" AND `size` > "0"'.$endquery.';'));
		if($new_all[0] and $setup['day_new']!=0) $new_all = '<font color="red">+'.$new_all[0].'</font>'; else $new_all="";
   		//Всего файлов в папке
   		//NOT USE//$allinfolder = mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'files` WHERE `infolder` REGEXP "'.$file_info['path'].'*" AND `size` > "0";'));
   		$allinfolder = mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'files` WHERE `infolder` LIKE  "'.$file_info['path'].'%" AND `size` > "0"'.$endquery.';'));
		$name = str_replace('*','',$file_info['name']);
		###############Cоздание РАЗДЕЛОВ
	$name32=$file_info['path'];
  	$name32=str_replace('files/','',$name32);
  		$name32=str_replace('/',';',$name32);
  			$name32=str_replace('_',' ',$name32);
		if (is_file('razdely/'.$name32.'.txt')) //если оно в файле
	{
 	$razd = file_get_contents('razdely/'.$name32.'.txt');
$razdely= '<div class="gmenu"> '.$razd.'</div>';
echo $razdely;
	}
			###############Проверка на платность раздела
//			$block=false; //обнуление
	    click_change();
/*	    
		if ($file_info['pas']==1) //если оно в файле
	{
 $block=1;
	}
		if ($file_info['pas']==2) //если оно в файле
	{
 $block=2;
	}
	*/
		//Иконка к папке
		if(!file_exists($file_info['path'].'folder.png')) $ico = '<img src="ext/dir.png" alt=""/> '; else $ico = '<img src="'.$file_info['path'].'folder.png" alt=""/>';
		//Собсвенно вывод

   		echo $row.$ico.'<a href="index.php?id='.$file_info[id].$endurl.'">'.$name.'</a> ['.$allinfolder[0].']';
   		if($new_all) echo '<a href="new.php?id1='.$file_info[id].$endurl.'">'.$new_all.'</a>';
        if(!empty($file_info['fastabout'])) echo ' <br/>'.str_replace("\n", ' <br/>',$file_info['fastabout']);
   		echo '</div>';


 	}
 	elseif(is_file($file_info['path']))
 	{
 		if(is_integer($key / 2)) $row = '<div class="list1">'; else $row = '<div class="list2">'; /////////К ДИЗАЙНУ О ВЫВЕДЕНИИ ФАЙЛОВ

  		$ex = pathinfo($file_info['path']);
 		$ext = strtolower($ex['extension']);
  		//Предосмотр
      click_change();
  		$pre = '';
  		if ($setup['prew']!=0)
  		{
   			if ($ext == 'bmp') $pre = 'Предосмотр невозможен  <br/>';
   			if ($ext == 'gif' or $ext == 'jpeg' or $ext == 'jpg' or $ext == 'png' or $ext == 'JPG' or $ext == 'GIF' or $ext == 'PNG'or $ext == 'JPEG') $pre = '<img style="margin: 1px;" src="im.php?bab=1&amp;id='.$file_info['id'].'" alt=""/>';
  		}
  		//Komments and loads
  		$all_komments = @mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'komments` WHERE file_id = "'.$file_info['id'].'"'));
  		$all_komments = $all_komments[0];
  		$all_loads = $file_info['loads'];
  		$file_time = date('d.m.y', $file_info['timeupload']);
  		if ($sort=='name'or $sort=='size') $info = '';
  		if($sort=='load') $info = '(<font color="#FFFF00">'.$all_loads.'</font>)';
  		if ($sort=='data') $info = "($file_time)";
  		if ($sort=='eval' and $setup['eval_change']==1) $info = '(<font color="#800000">'.$file_info['yes'].'</font>/<font color="#004080">'.$file_info[no].'</font>)';
  		//Новизна файла
  		$new_info='';
  		$filtime2 = $file_info['timeupload']+(3600*24*$setup['day_new']);
  		if($filtime2>=$time and $setup['day_new']!=0) $new_info = '<font color="black">NEW!</font>';
  		//Красивый размер
  		if($file_info['size'] < 1024) $file_info['size'] = '('.$file_info['size'].'b)';
  		if($file_info['size'] < 1048576 and $file_info['size'] >= 1024) $file_info['size'] = '('.round($file_info['size']/1024, 2).'Kb)';
  		if($file_info['size'] > 1048576) $file_info['size'] = '('.round($file_info['size']/1024/1024, 2).'Mb)';
  		//Иконка к файлу
  		if(!file_exists('ext/'.$ext.'.png') ) $ico = '<img src="ext/stand.png" alt=""/>';
      elseif ($ext =='jar')  $ico = ' <img src="ic.php?lf='.$file_info['path'].'&amp;id='.$file_info[id].'" alt="" width="16" height="16"/>';

       else $ico = '<img src="ext/'.$ext.'.png" alt=""/>';
  		//Показ расиширения
  		if($setup['ext']==1) $extension = "($ext)"; else $extension = '';
  		//Собственно вывод
  		echo $row;
      $size1=str_replace(')','|',$file_info['size']);
  		$size2=str_replace('(','|',$size1);
  		$info=str_replace('(','|',$info);
  		$info=str_replace(')','|',$info);
  		  		echo ''.$ico.'<a href="view.php?id='.$file_info[id].'"><strong>'.htmlspecialchars($file_info['name']).'</strong></a><div class="sub">'.$extension.$size2.$info.'|<a href="load.php?id='.$file_info[id].'"><font color="red">Скачать</font></a>|';
       if($ext =='txt')     {  echo '<a href="read.php?id='.$file_info['id'].'&amp;id2='.$id.'"><font color="red">Читать</font></a>';}
            echo $new_info.'';
  		if(!empty($file_info['fastabout'])) echo str_replace("\n", ' <br/>',$file_info['fastabout']);
  		echo '</div><div class="sub">';

  		#######Получаем имя файла и обратный каталог#####
$filename = pathinfo($file_info['path']);
$filename2 = str_replace('.'.$filename['extension'],'',$filename['basename']);
$ext = $filename['extension'];
$dir = $filename['dirname'].'/';
$filename = $filename['basename'];
$back = mysql_fetch_array(mysql_query("SELECT * FROM `".$setup['pref']."files` WHERE `path` = '".clean($dir)."'"));
      #   	
##################
$bolt=0;
     if(($ext == 'avi' || $ext == '3gp' || $ext == 'mp4') && extension_loaded('ffmpeg')){
$pre = '<img style="margin: 1px;" src="ffmpeg.php?id='.$file_info['id'].'" alt=""/> <br/>';
$bolt=1;
}
elseif($ext == 'thm' || $ext == 'nth'){
$pre =  '<img style="margin: 1px;"  src="theme.php?id='.$file_info['id'].'&amp;W=40&amp;H=40" alt="prev"/>';
$bolt=1;
}
if($open!=1 AND ($ext == 'avi' || $ext == 'flv' || $ext =='swf' || $ext =='mp4') AND ( 
    	strpos($h_ua, 'windows') == false	||
	strpos($h_ua, 'linux') == false	||
	strpos($h_ua, 'bsd') == false		||
	strpos($h_ua, 'x11') == false		||
	strpos($h_ua, 'unix') == false		||
	strpos($h_ua, 'macintosh') == false	||
	strpos($h_ua, 'macos') == false))
{
$pre ='<object type="application/x-shockwave-flash" data="uflvplayer_500x375.swf" height="99" width="125">
<param name="bgcolor" value="#DFE6EF" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="movie" value="uflvplayer_500x375.swf" />
<param name="FlashVars" value="way='.htmlspecialchars($file_info['path']).'&amp;swf=uflvplayer_500x375.swf&amp;w=400&amp;h=300&amp;pic=ffmpeg.php?id='.$file_info['id'].'&amp;autoplay=0&amp;tools=1&amp;skin=white&amp;volume=70&amp;q=&amp;comment=" /></object>
';
	
}
      if($open!=1 AND ( $ext == 'mp3' or $ext == 'wav')){
echo '<div class="block">';
if ( 
    	strpos($h_ua, 'windows') == false	||
	strpos($h_ua, 'linux') == false	||
	strpos($h_ua, 'bsd') == false		||
	strpos($h_ua, 'x11') == false		||
	strpos($h_ua, 'unix') == false		||
	strpos($h_ua, 'macintosh') == false	||
	strpos($h_ua, 'macos') == false) 
    {
echo'<b>Прослушка:</b> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0 " width="96" height="20" id="own_flashplayer" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<embed src="own_flashplayer_plc.swf?file='.htmlspecialchars($file_info['path']). '&amp;sta rtplay=false" quality="high" bgcolor="#ffffff" width="96" height="20" name="own_flashplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object><br/>'; }  



echo '</div>';
}
 if ($ext == 'txt') {$rtext=file_get_contents($file_info['path']);
    $rtext = htmlspecialchars($rtext);    
    $rtext=substr($rtext,0,150);
    $rtext=iconv("windows-1251", "UTF-8", "$rtext");
    if(strlen($rtext)>15) $rtext=substr($rtext,0,strrpos($rtext, ' '));
    echo '<div class="sob">'.$rtext.'...</div>';
    $outp=1;
  }
     if($pre!=NULL) echo '<div class="block">'.$pre.'</div>';
if($open!=1){
 #################	 Скиншот #############################
   
if(is_file($setup['spath'].'/'.$filename.'.gif') OR is_file($setup['spath'].'/'.$filename.'.jpg') OR is_file($setup['spath'].'/'.$filename.'.jpe') OR is_file($setup['spath'].'/'.$filename.'.jpeg') OR  is_file($setup['spath'].'/'.$filename.'.png')
OR is_file($setup['spath'].'/'.$filename2.'.gif') OR is_file($setup['spath'].'/'.$filename2.'.jpg') OR is_file($setup['spath'].'/'.$filename2.'.jpe') OR is_file($setup['spath'].'/'.$filename2.'.jpeg') OR  is_file($setup['spath'].'/'.$filename2.'.png')) 
echo '<img style="margin: 1px;" src="im.php?id='.$file_info['id'].'&amp;W=40&amp;H=47&amp;bab=2" alt="screen"/>';


if (is_file($setup['opath'].'/'.$filename.'.txt')) //если оно в файле
	{
 	$f = file_get_contents($setup['opath'].'/'.$filename.'.txt');
 	$f=substr($f,0,300);
 	$f = htmlentities($f, ENT_QUOTES, 'UTF-8');
	echo '<div class="sob">'.$f.'...</div>';
	$outp=1;
	}
	if (is_file($setup['opath'].'/'.$filename2.'.txt')) //если оно в файле
	{
 	$f = file_get_contents($setup['opath'].'/'.$filename2.'.txt');
 	$f=substr($f,0,300);
 	$f = htmlentities($f, ENT_QUOTES, 'UTF-8');
	echo '<div class="sob">'.$f.'...</div>';
	$outp=1;
	}
  }
  else 
  {
if(is_file($file_info['path'].'.gif')) 
echo '<img style="margin: 1px;" src="im.php?id='.$file_info['id'].'&amp;W=40&amp;H=47&amp;bab=2'.$endurl.'" alt="screen"/>';

 	$f= $file_info['about'];
 	$f= substr($f,0,300);
 	$f= htmlentities($f, ENT_QUOTES, 'UTF-8');
	echo '<div class="sob">'.$f.'...</div>';
	$outp=1;
	

  }
//if ($ext != '3gp' and $ext != 'mp4' and $ext != 'jpg' and $ext != 'gif' and $ext != 'png' and $outp!=1) echo'<div class="a">описание отсуствует</div>';
echo '</div>';
echo'<div class="sub"><a href="komm.php?id='.$file_info['id'].'">Ком.: ['.$all_komments.']</a>|Рейтинг:<font color="black">'.$file_info['yes'].'</font>/<font color="red">'.$file_info['no'].'</font><font color="blue">|Скач.:</font>['.$file_info['loads'].']<br/></div></div>';





 	}
}
###############Постраничная навигация########

$asd= $page - 2;
$asd2= $page + 3; if ($pages>1){
echo '<div class="phdr">Стр.:';
if($asd<$all && $asd>0 && $page>3 )
echo ' <a class="page" href="index.php?id='.$id.'&amp;page=1'.$endurl.'">1</a> ... ';
for($i=$asd; $i<$asd2;$i++)
{
	if($i<$all && $i>0)
 	{
  		if ($i > $pages )  break;
  		if ($page==$i) echo '<span class="page"><b>'.$i.'</b></span> ';
  		else echo '<a class="page" href="index.php?id='.$id.'&amp;page='.$i.$endurl.'">'.$i.'</a> ';
 	}
}
if ($i <= $pages)
{
 	if($asd2<$all) echo ' ... <a class="page" href="index.php?id='.$id.'&amp;page='.$pages.$endurl.'">'.$pages.'</a>';
}
echo '</div>';}
###############Ручной ввод страниц###############
if ($pages>$setup['pagehand'] and $setup['pagehand_change'] == 1)
{
echo '
<form action="index.php?id='.$id.$endurl.'" method="post"><li>Стр:
<input class="enter" name="page" type="text" maxlength="4" size="2" value="'.$page.'">
&nbsp;<input class="buttom" type="submit" value="GO">
</li></form>';
}
if($setup['obm'] == 1 ) 
{
echo '<div class="bmenu"><a href="upload.php?">Загрузить файл</a><br />';
echo '</div>';
if($open!=1) 
{
$all_files = mysql_fetch_row(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'files` WHERE `size` > 0  AND `open`=1'));
$new_all_files = mysql_fetch_row(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'files` WHERE `timeupload` > '.($time-(86400*$setup['day_new'])).' AND `size` > 0 AND `open`=1'));
echo ' <li><a href="index.php?open=1">Файлообменник</a>';
if($new_all_files[0]!=0) $new_all = '<font color="red">+'.(int)$new_all_files[0].'</font>'; else $new_all="";
echo '('.(int)$all_files[0].')<a href="new.php?open=1">'.$new_all.'</a></li></div>'; 
}
//else  {
//$all_files = mysql_fetch_row(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'files` WHERE `size` > 0 AND `open`=0'));
//$new_all_files = mysql_fetch_row(mysql_query('SELECT COUNT(*) FROM `'.$setup['pref'].'files` WHERE `timeupload` > '.($time-(86400*$setup['day_new'])).' AND `size` > 0 AND `open`=0'));
//echo ' <li><a href="index.php">Загрузки</a>';    
//if($new_all_files[0]!=0) $new_all = '<font color="red">+'.(int)$new_all_files[0].'</font>'; else $new_all="";
//echo '('.(int)$all_files[0].')<a href="new.php">'.$new_all.'</a></li></div>';}
}

echo '
<div class="bmenu">
<a href="user.php?id='.$id.$endurl.'">Настройки</a><br />';
if($setup['stat_change'] == 1) echo '<a href="stat.php?'.$endurl.'">Статистика</a><br />';
if($setup['zakaz'] == 1) echo ' <li><a href="table.php?">Стол заказов</a></li>';
echo '</div>';
if($rights >= "4"){
print '<div class="phdr"><a href="apanel.php">Админка</a></div>';
}

require_once ("moduls/foot.php");

?>