<?php
/**************************************************************************************************
|
| iDocScript - Document Sharing Script
| http://www.idocscript.com
| webmaster@idocscript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.idocscript.com/eula.html and to be bound by it.
|
| Copyright (c) 2011 iDocScript.com. All rights reserved.
|**************************************************************************************************/
include("include/config.php");
include("include/functions/import.php");

$DID = $_REQUEST['DID'];
if (is_numeric($DID))
{
	$query="SELECT allowdownloads,doc_name FROM docs WHERE public='1' AND active='1' AND DID='".mysql_real_escape_string($DID)."' limit 1";
	$executequery = $conn->Execute($query);
	$allowdownloads = $executequery->fields['allowdownloads'];
	$doc_name = $executequery->fields['doc_name'];
}

if ($allowdownloads == "1")
{
	if ($config['who_can_download'] == "1")
	{
		if ($_SESSION['USERID'] != "" && $_SESSION['USERID'] >= 0 && is_numeric($_SESSION['USERID']))
		{
			$query="UPDATE docs SET downloadcount=downloadcount+1 WHERE DID='".mysql_real_escape_string($DID)."'";
			$conn->Execute($query);
			header("location:$config[docurl]/$doc_name");
			exit;
		}
		else
		{
			header("location:$config[baseurl]/login");
			exit;
		}
	}
	else
	{
		$query="UPDATE docs SET downloadcount=downloadcount+1 WHERE DID='".mysql_real_escape_string($DID)."'";
		$conn->Execute($query);
		header("location:$config[docurl]/$doc_name");
		exit;
	}

}
?>