<?php 
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
session_cache_limiter("none");
set_magic_quotes_runtime(0);

include("oldinclude/dbcommon.php");

$table = @$_GET["table"];
$id = @$_GET["id"];
if(!$table || !$id)
	return;

$tablename="";
$tables = GetTablesList();
foreach($tables as $t)
{
	if(GetTableURL($t)==$table)
	{
		$tablename=$t;
		break;
	}
}
if(!$tablename)
	return;
##if @BUILDER.bCreateLoginPage##
if(!@$_SESSION["UserID"])
{ 
	header("Location: login.php"); 
	return;
}
$strPerm = GetUserPermissions($tablename);
if(strpos($strPerm,"S")===false && strpos($strPerm,"E")===false)
{ 
	header("Location: login.php"); 
	return;
}
##endif##

$file = dirname(__FILE__)."/templates_c/".$table.$id.".pdf";
if(!file_exists($file))
	return;
$value = @file_get_contents($file);

header("Content-type: application/pdf");
header("Content-Disposition: attachment;Filename=\"".$table.".pdf\"");
header("Cache-Control: private");
header("Content-Length: ".strlen($value));
echobig($value);

?>