<?php
/*
 * This file is part of Web Pro Manager.
 * 
 * Web Pro Manager is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Web Pro Manager is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Web Pro Manager.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @author The Web Pro Miami, Inc. <info@thewebpro.com>
 * @copyright The Web Pro Miami, Inc. <info@thewebpro.com>, http://www.thewebpro.com/
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL
 * @package WebProManager
*/

require("manage/inc/stop_cache.php");

// security
$nImageID = preg_replace("/[[:^digit:]]/", '',$_GET["id"]);
if(!$nImageID){ exit("Invalid image ID."); }

// connect to mysql
require("inc/dbconnect.php");
require("inc/config.php");

// Process image
$nMinDisplayWidth = 200;
$nImgPath = nGetImagePathFromID($nImageID);
if(file_exists("$nImgPath")){
	$nCaption = nGetImageInfoFromID($nImageID,"nCaption");
	if($nCaption){ $nImgStyle = "padding-bottom:8px;"; } else { $nImgStyle = ""; }
	$nImgSizeARRAY = getimagesize("$nImgPath");
	$nImgW = $nImgSizeARRAY[0]; $nImgH = $nImgSizeARRAY[1];
	$nImgTag = "<img src=\"$nFullSitePath$nImgPath\" alt=\"\" width=\"$nImgW\" height=\"$nImgH\" border=\"0\">";
	// display image
	if($nMinDisplayWidth>$nImgW){ $nDisplayW = $nMinDisplayWidth; } else { $nDisplayW = $nImgW; }
	echo "<div align=\"center\" style=\"width:{$nDisplayW}px; font-size:smaller; $nImgStyle\"><div style=\"$nImgStyle\">$nImgTag</div>$nCaption</div>";
}


function nGetImagePathFromID($nImgID){
	global $DBName,$Link;
	$nSQL = "SELECT nPath FROM nImage WHERE nID='$nImgID' LIMIT 1";
	mysql_select_db($DBName); $Result = mysql_query($nSQL,$Link);
	if($Row = mysql_fetch_array($Result)){
		$nPath = $Row["nPath"];
	}
	if(!file_exists($nPath)){ $nPath = "../$nPath"; }
	if(!file_exists($nPath)){ $nPath = "../$nPath"; }
	return $nPath;
}
function nGetImageInfoFromID($nImgID,$nData="nTitle"){
	global $DBName,$Link;
	$nSQL = "SELECT $nData AS nData FROM nImage WHERE nID='$nImgID' LIMIT 1";
	mysql_select_db($DBName); $Result = mysql_query($nSQL,$Link);
	if($Row = mysql_fetch_array($Result)){
		$nData = $Row["nData"];
	}
	return $nData;
}

require("inc/db_close.php");
?>