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

	$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)) {
?>
<? require_once("top_inc.php"); ?>
&nbsp;&nbsp;<span class="ctracks">IMAGE MANAGEMENT - VIEW REFERERS</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"><?= number_format($line[ctr]) ?></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">
<br>
<form name="referers" action="images.php" 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="return" value="return to image list">
</form>
<br>
<table border="0" width="75%" align="center" cellpadding="2" cellspacing="0">
	<tr bgcolor="#dcdcdc">
		<td align="left" class="cell"><strong>Date/Time Viewed</strong></td>
		<td align="left" class="cell"><strong>IP Address</strong></td>
		<td align="left" class="cell"><strong>Referer</strong></td>
	</tr>
<?
	$query2 = "SELECT unix_timestamp(timestamp) as ts, referer, ip from imagehits where filename = '$filename' order by timestamp desc limit 50";
    $result2 = mysql_query($query2) or die("Query failed.");
    while ($line2 = mysql_fetch_array($result2)) {
?>
	<tr>
		<td align="left" class="cell"><?= date("m/d/Y h:i:s A", $line2[ts]) ?>&nbsp;</td>
		<td align="left" class="cell"><?= $line2[ip] ?>&nbsp;</td>
		<td align="left" class="cell"><a href="<?= $line2[referer] ?>" target="_blank"><?= strlen($line2[referer]) > 50 ? substr($line2[referer], 0, 50) . "..." : $line2[referer] ?></a>&nbsp;</td>
	</tr>
<?
	}
?>
</table>
</div>
<?
    }
    mysql_free_result($result);
	mysql_free_result($result2);
	mysql_close($link);
?>
<br>
<? require_once("bottom_inc.php"); ?>