<?
/***************************************************************************
 *                              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);
$userdata = session_pagestart($user_ip, PAGE_OBMEN);
init_userprefs($userdata);
$sql = "SELECT * FROM `" . UPLOAD_CONFIG_TABLE . "` WHERE `id`='1'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_config information', '', __LINE__, __FILE__, $sql);
	}
		$config = $db->sql_fetchrow($result);
if($config['on_off']==1)
    {
        message_die(GENERAL_MESSAGE, 'Файлобменник отключен!');
    }
$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);
if (!file_exists('../upload/'.$last['file_url']) || $last['file_url'] != trim($_GET['file'])) {	
       message_die(GENERAL_MESSAGE, 'Файл не существует!');
}
	$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);
	}
if ( $userdata['session_logged_in'] )
	{	
$sql = "UPDATE `" . USERS_TABLE . "` SET `load_count`=`load_count`+1, `load_size`=`load_size`+".$last['file_size']." WHERE `user_id` = '".$userdata['user_id']."'";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get users information', '', __LINE__, __FILE__, $sql);
	}	
	}
    $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']));



    header('Location: ' . $server_protocol . $server_name . $server_port . $script_name . 'upload/' . $last['file_url'], true, 301);


?>