<?
//Автор: DjBoBaH 
//Сайт: http://my-perm.net 
include_once '../sys/inc/start.php';
if(isset($_GET['showinfo']) || !isset($_GET['f']) || isset($_GET['komm']))

include_once '../sys/inc/compress.php';
include_once '../sys/inc/downloadfile.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
include $_SERVER['DOCUMENT_ROOT']."/anti_ hacker.php"; 
$timediff=mysql_result(mysql_query("SELECT `time` FROM `user` WHERE `id` = '$user[id]' LIMIT 1",$db), 0);
if($timediff < 3600)
{
include_once '../sys/inc/thead.php';
title();
echo "<div class='rekl_main'>\n";
echo 'Извените, но на данный момент Вы не можите просматривать Обменник Сообщества !!! <br/>
Что бы просматривать Обменник Сообщества, Вам необходимо провести 1 час на нашем сайте.<br/> За это время Вы можете по ближе познакомиться с сайтом и заполнить свою анкету или же поиграть в онлайн Игры!';
echo "</div>\n";
include_once '../sys/inc/tfoot.php';
exit;
}
if(isset($_GET['s']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `id` = '".intval($_GET['s'])."' LIMIT 1"),0)==1)
{
$s=intval($_GET['s']);
$soo=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo` WHERE `id` = '$s' LIMIT 1"));
include_once 'inc/ban.php';

if($soo['konf_soo']==0 || isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1 || isset($user) && $user['id']==$soo['admid']  || isset($user) && $user['level']>0)
{

if(isset($_GET['d']) && esc($_GET['d'])!=NULL){
	$l=ereg_replace("\.{2,}",NULL,esc(urldecode($_GET['d'])));
	$l=ereg_replace("\./|/\.",NULL,$l);
	$l=ereg_replace("(/){1,}","/",$l);
	$l='/'.ereg_replace("(^(/){1,})|((/){1,}$)","",$l);
	}else{
		$l='/';
		}

if($l=='/'){
	$dir_id['upload']=0;
	$id_dir=0;
	$l='/';
	}else if(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_obmen_dir` WHERE `id_soo` = '$soo[id]' AND (`dir` = '/$l' OR `dir` = '$l/' OR `dir` = '$l') LIMIT 1"),0)!=0){
		$dir_id=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo_obmen_dir` WHERE `id_soo` = '$soo[id]' AND (`dir` = '/$l' OR `dir` = '$l/' OR `dir` = '$l') LIMIT 1"));
		$id_dir=$dir_id['id'];
		}else{
			$dir_id['upload']=0;
			$id_dir=0;
			$l='/';
			}

if(isset($_GET['f'])){
	$f=esc(urldecode($_GET['f']));
	$name=eregi_replace('\.[^\.]*$', NULL, $f);
	$ras=strtolower(eregi_replace('^.*\.', NULL, $f));
	$ras=str_replace('jad', 'jar', $ras);

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_obmen_files` WHERE `id_dir` = '".$dir_id['id']."' AND `name`='$name' AND `ras` = '$ras' AND `id_soo` = '$soo[id]' LIMIT 1"),0)!=0){
	$file_id=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo_obmen_files` WHERE `id_dir` = '".$dir_id['id']."' AND `name`='$name' AND `ras` = '$ras' AND `id_soo` = '$soo[id]' LIMIT 1"));
	$ras=$file_id['ras'];
	$file=H."sys/soo/obmen/files/$file_id[id].dat";
	$name=$file_id['name'];
	$size=$file_id['size'];

if(!isset($_GET['showinfo']) && !isset($_GET['komm']) && is_file(H.'sys/soo/obmen/files/'.$file_id['id'].'.dat')){

if($ras=='jar' && strtolower(eregi_replace('^.*\.', NULL, $f))=='jad'){
	include_once H.'sys/inc/zip.php';
	$zip=new PclZip(H.'sys/soo/obmen/files/'.$file_id['id'].'.dat');
	$content = $zip->extract(PCLZIP_OPT_BY_NAME, "META-INF/MANIFEST.MF" ,PCLZIP_OPT_EXTRACT_AS_STRING);
	$jad=eregi_replace("(MIDlet-Jar-URL:( )*[^(\n|\r)]*)", NULL, $content[0]['content']);
	$jad=eregi_replace("(MIDlet-Jar-Size:( )*[^(\n|\r)]*)(\n|\r)", NULL, $jad);
	$jad=trim($jad);
	$jad.="\r\nMIDlet-Jar-Size: ".filesize(H.'sys/soo/obmen/files/'.$file_id['id'].'.dat')."";
	$jad.="\r\nMIDlet-Jar-URL: /soo/obmen.php?s=$soo[id]&d=$dir_id[dir]&f=$file_id[name].$file_id[ras]";
	$jad=br($jad,"\r\n");
	header('Content-Type: text/vnd.sun.j2me.app-descriptor');
	header('Content-Disposition: attachment; filename="'.$file_id['name'].'.jad";');
	echo $jad;
	exit;
	}



@mysql_query("UPDATE `soo_obmen_files` SET `k_loads` = '".($file_id['k_loads']+1)."' WHERE `id` = '$file_id[id]' AND `id_soo` = '$soo[id]' LIMIT 1");
include_once '../sys/inc/downloadfile.php';
DownloadFile(H.'sys/soo/obmen/files/'.$file_id['id'].'.dat', $name.'.'.$ras, ras_to_mime($ras));


exit;
}else if(isset($_GET['komm']) && is_file(H.'sys/soo/obmen/files/'.$file_id['id'].'.dat')){
	$set['title']="".filter_var($soo['name'], FILTER_SANITIZE_SPECIAL_CHARS)." - Обменник - Комментарии - ".filter_var($file_id['name'], FILTER_SANITIZE_SPECIAL_CHARS)."";
	$_SESSION['page']=1;

include_once '../sys/inc/thead.php';
title();

if(isset($user) && $soo['admid']==$user['id'] || $user['id']==$file_id['id_user']){
	include 'inc/komm_act.php';
	}

include_once 'inc/komm.php';

echo '&#187;&nbsp;<a href="?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'&amp;f='.urlencode($file_id['name']).'.'.$file_id['ras'].'&amp;showinfo">К описанию</a><br/>';
echo '&#187;&nbsp;<a href="?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'">В папку</a><br/>';
echo '&#187;&nbsp;<a href="index.php?s='.$soo['id'].'">В сообщество</a></div>';
include_once '../sys/inc/tfoot.php';
exit;
}else{
	$set['title']="Обменник - ".filter_var($file_id['name'], FILTER_SANITIZE_SPECIAL_CHARS)."";

include_once '../sys/inc/thead.php';
title();

if(isset($user) && $soo['admid']==$user['id']){
	include 'inc/file_act.php';
	}

err();
aut();
echo '<div class="menu">';

if(is_file("inc/file/$ras.php")){
	include "inc/file/$ras.php";
	}else{
		include_once 'inc/file.php';
		}

if($file_id['ras']=='jar'){
	echo '&#187;&nbsp;<a href="?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'&amp;f='.urlencode($file_id['name']).'.jad">Скачать</a> <a href="?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'&amp;f='.urlencode($file_id['name']).'.'.$file_id['ras'].'">JAR</a> ('.$file_id['k_loads'].')<br/>';
	}else{
		echo '&#187;&nbsp;<a href="?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'&amp;f='.urlencode($file_id['name']).'.'.$file_id['ras'].'">Скачать</a> ('.$file_id['ras'].')<br/>';
		echo '<b>Скачали</b>: '.$file_id['k_loads'].' раз.<br/>';
		}

echo '<input type="text" value="http://'.$_SERVER['HTTP_HOST'].'/soo/obmen.php?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'&amp;f='.urlencode($file_id['name']).'.'.$file_id['ras'].'"/><br/>';

echo '&#187;&nbsp;<a href="?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'&amp;f='.urlencode($file_id['name']).'.'.$file_id['ras'].'&amp;komm">Комментарии</a> ('.mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_obmen_komm` WHERE `id_file` = '$file_id[id]' AND `id_soo` = '$soo[id]'"), 0).')<br/>';
echo '&#187;&nbsp;<a href="?s='.$soo['id'].'&amp;d='.$dir_id['dir'].'">В папку</a><br/>';
echo '&#187;&nbsp;<a href="index.php?s='.$soo['id'].'">В сообщество</a></div>';

if(isset($user) && $soo['admid']==$user['id']){
	include 'inc/file_form.php';
	}

echo '</div>';
include_once '../sys/inc/tfoot.php';
}
}
}else{
include_once 'inc/dir.php';
}
}
else
{
$set['title']="".filter_var($soo['name'], FILTER_SANITIZE_SPECIAL_CHARS)." - Обменник";
include_once '../sys/inc/thead.php';
title();
echo'Вам недоступен просмотр файлообменника данного сообщества';
}
}
else
{
header("Location:index.php");
}
include_once '../sys/inc/tfoot.php';
?>