<?php
/***************************************************************************
 *                              obmen.php
 *                            -------------------
 *  Полнлценный модуль Файлобменника под phpBB-WAP
 *	Автор модуля: SatanHell
 *  2011 год
 ***************************************************************************/

define('IN_PHPBB', true);
$phpbb_root_path = '../';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_obmen.'.$phpEx);
$id = isset($_REQUEST['id']) ? abs(intval($_REQUEST['id'])) : false;
	$sql = "SELECT*FROM `" . UPLOAD_FILES_TABLE . "` WHERE `file_id`='".$id."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_files information', '', __LINE__, __FILE__, $sql);
	}
if(!mysql_num_rows($result))
    {
        message_die(GENERAL_MESSAGE, 'Файл не существует!');
    }
$last = $db->sql_fetchrow($result);	
$file = '../upload/'.trim($_GET['file']);

if(ext_file(trim($_GET['file']))!='jar')
{
die('файл не jar');
}

if(!file_exists($file))
{
die('Файл не найден');
}

	$sql = "UPDATE `" . UPLOAD_FILES_TABLE . "` SET `file_load`=`file_load`+1 WHERE `file_id`='".$last['file_id']."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_files information', '', __LINE__, __FILE__, $sql);
	}
$name = trim($_GET['file']).'.jad';

$jad = false;

$z = new ZipArchive();

if($z->open($file))
{
$fp = $z->getStream('META-INF/MANIFEST.MF');

if(!$fp)
{
exit('не удалось создать jad');
}

while(!feof($fp))
{
$jad.=fread($fp, 200);
}
fclose($fp);
    $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
	$server_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['server_name']));
	$server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) : '';
	$script_name = preg_replace('/^\/?(.*?)\/?$/', '/\1', trim($board_config['script_path']));

$jad.="MIDlet-Jar-Size: ".filesize($file)."\n";
$jad.="MIDlet-Jar-URL: $server_protocol$server_name$server_port$script_nameupload/loading/".$id."/".trim($_GET['file'])."\n";

header("Content-type: text/vnd.sun.j2me.app-descriptor");
header('Content-Disposition: attachment; filename="'.$name.'";');

echo $jad;
}

?>