<? require_once("../ihs/config.php"); ?>
<?
	$filename = $_REQUEST['filename'];
	$delete = $_REQUEST['delete'];

	$link = mysql_connect($db_server, $db_user, $db_password) or die("Could not connect.");
	mysql_select_db($db_name) or die("Could not select database.");
	$query = "SELECT i.filename as filename, i.tn_filename as tn_filename, i.filepath as filepath, unix_timestamp(i.added) as add_dt, i.email as email, i.ip as ip, i.filesize as filesize, sum(ih.kb) as bandwidth, count( ih.filename ) as ctr from images i left outer join imagehits ih on i.filename = ih.filename where i.filename = '$filename' group by filename";
    $result = mysql_query($query) or die("Query failed.");
    while ($line = mysql_fetch_array($result)) {

		// check for delete
		if (isset($delete)) {
			if ($delete == "Yes") {
				// remove image
				unlink($_SERVER['DOCUMENT_ROOT'] . $line[filepath] . $line[filename]);
				$query2 = "delete from images where filename = '$filename'";
				mysql_query($query2) or die("Could not delete.");
				$query2 = "delete from imagehits where filename = '$filename'";
				mysql_query($query2) or die("Could not delete.");

				// remove image thumbnail
				if ($line[tn_filename] != "") {
					unlink($_SERVER['DOCUMENT_ROOT'] . $line[filepath] . $line[tn_filename]);
				}
			}
		    mysql_free_result($result);
			mysql_close($link);
			header("Location: images.php?limit=" . $_REQUEST['limit'] . "&sort=" . $_REQUEST['sort'] . "&start=" . $_REQUEST['start'] . "&tn=" . $_REQUEST['tn'] . "&details=" . $_REQUEST['details']);
			exit;
		}
?>
<? require_once("top_inc.php"); ?>
&nbsp;&nbsp;<span class="ctracks">IMAGE MANAGEMENT - VIEW IMAGE</span><br>
<br>
<hr>
<br>
<table width="60%" align="center" border="0" cellspacing="0" cellpadding="4" bgcolor="#dcdcdc">
	<tr>
		<td align="right"><strong>File Name:</strong></td>
		<td align="left"><?= $line[filename] ?></td>
		<td align="right"><strong>File Size:</strong></td>
		<td align="left"><?= number_format($line[filesize]) ?> bytes</td>
	</tr>
	<tr>
		<td align="right"><strong>Date/Time Added:</strong></td>
		<td align="left"><?= date("m/d/Y h:i:s A", $line[add_dt]) ?></td>
		<td align="right"><strong>Views:</strong></td>
		<td align="left"><a href="referers.php?limit=<?= $_REQUEST['limit'] ?>&sort=<?= $_REQUEST['sort'] ?>&start=<?= $_REQUEST['start'] ?>&tn=<?= $_REQUEST['tn'] ?>&details=<?= $_REQUEST['details'] ?>&filename=<?= $line[filename] ?>"><?= number_format($line[ctr]) ?></a></td>
	</tr>
	<tr>
		<td align="right"><strong>E-Mail:</strong></td>
		<td align="left"><?= $line[email] ?></td>
		<td align="right"><strong>Bandwidth Used:</strong></td>
		<td align="left"><?= number_format($line[bandwidth]) ?> bytes</td>
	</tr>
	<tr>
		<td align="right"><strong>IP Address:</strong></td>
		<td align="left"><?= $line[ip] ?></td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
</table>
<br>
<div align="center">
<img src="<?= $line[filepath] . $line[filename] ?>" alt="" border="0"><br>
<br>
<span style="font-size: larger; font-weight: bold;">Delete This Picture?</span>
<form name="delete" action="<?= $_SERVER['PHP_SELF'] ?>" method="post" style="margin-bottom: 0px;">
<input type="hidden" name="tn" value="<?= $_REQUEST['tn'] ?>">
<input type="hidden" name="limit" value="<?= $_REQUEST['limit'] ?>">
<input type="hidden" name="sort" value="<?= $_REQUEST['sort'] ?>">
<input type="hidden" name="start" value="<?= $_REQUEST['start'] ?>">
<input type="hidden" name="details" value="<?= $_REQUEST['details'] ?>">
<input type="hidden" name="filename" value="<?= $_REQUEST['filename'] ?>">
<input type="submit" name="delete" value="Yes" style="width: 50px;" onclick="return verifyAction('Are you sure you want to delete this image?');">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="delete" value="No" style="width: 50px;">
</form>
</div>
<?
    }
    mysql_free_result($result);
	mysql_close($link);
?>
<br>
<? require_once("bottom_inc.php"); ?>