<?php 
if(!isset($pdf))
{
	ini_set("display_errors","1");
	ini_set("display_startup_errors","1");
	set_magic_quotes_runtime(0);

	include("oldinclude/dbcommon.php");
	include("oldinclude/##@TABLE.strShortTableName##_variables.php");
##if @BUILDER.bCreateLoginPage##
	if(!@$_SESSION["UserID"] || !CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Search"))
	{ 
		header("Location: login.php"); 
		return;
	}
##endif##

	$field = @$_GET["field"];
	if(!CheckFieldPermissions($field))
		return DisplayNoImage();

//	construct sql

$keys=array();
##foreach @TABLE.arrKeyFields as @k##
$keys["##@k s##"]=postvalue("key##@index##");
##endfor##
	$conn=db_connect();
}
else
{
	$field = @$params["field"];
	$keys=array();
##foreach @TABLE.arrKeyFields as @k##
	$keys["##@k s##"]=@$params["key##@index##"];
##endfor##
}

$where=KeyWhere($keys);

##if @TABLE.nSecOptions==ADVSECURITY_VIEW_OWN && @BUILDER.nLoginMethod==SECURITY_TABLE && @BUILDER.bCreateLoginPage##
$where=whereAdd($where,SecuritySQL("Search"));
//$sql = AddWhere($sql,SecuritySQL("Search"));	
##endif##

$sql = gSQLWhere($where);

$rs = db_query($sql,$conn);

if(isset($pdf))
{
	if($rs && ($data=db_fetch_array($rs)))
		$file = $data[$field];
}
else
{

if(!$rs || !($data=db_fetch_array($rs)))
  return DisplayNoImage();


$value=db_stripslashesbinary($data[$field]);
if(!$value)
{
	if(@$_GET["alt"])
	{
		$value=db_stripslashesbinary($data[$_GET["alt"]]);
		if(!$value)
			return DisplayNoImage();
	}
	else
		return DisplayNoImage();
}

$itype=SupposeImageType($value);
if($itype)
	header("Content-type: $itype");
else
	return DisplayFile();
echobig($value);
return;
}


?>
