<?php
$nSecureMe=1;

// Secure and connect
require("../../inc/dbconnect.php");
require("../inc/secure_page.php");

// bring in other required files
require("../../inc/config.php");
require("../inc/lang.php");

// config
$nPageName = "image_unlink.php";
$nRefreshCall = "refreshImages();";

// Get passed-in vars
$nUpdateDB = (isset($_POST["nUpdateDB"]) ? $_POST["nUpdateDB"] : NULL);
$nRecID = (isset($_GET['id']) ? $_GET['id'] : NULL);

if(!$nUpdateDB){
	if($nRecID){
		// some stuff
		$nSQL = "SELECT nPath FROM nImage WHERE nID='$nRecID' LIMIT 1";
		mysql_select_db($DBName); $Result = mysql_query($nSQL,$Link);
		if($Row = mysql_fetch_array($Result)){
			$nPath = $Row["nPath"];
		}
	} else { echo "<div align=\"center\" style=\"padding:20px;\">No record available. Invalid ID.</div>"; }
} else {
	$nRecID = $_POST["nRecID"];
	if($nRecID){
		// Delete record
		$nSQL = "DELETE FROM nImage WHERE nID='$nRecID' LIMIT 1";
		mysql_select_db($DBName);
		mysql_query($nSQL, $Link);
		// Optmization
		$nSQL = "OPTIMIZE TABLE nImage";
		mysql_select_db($DBName);
		mysql_query($nSQL, $Link);
	}
	echo "<script>$.colorbox.close();</script>";
	exit();
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="dialogForm" id="dialogForm" onSubmit="return submitFormModal('dialog/<?php echo $nPageName;?>?id=<?php echo $nRecID?>','dialogForm','<?php echo $nRefreshCall;?>');return false;">
	<input type="hidden" name="nUpdateDB" value="1">
	<input type="hidden" name="nRecID" value="<?php echo $nRecID?>">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
	<td height="80" align="center" style="padding:10px;">
		
		<table border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="58" valign="top" style="padding-right:10px;"><img src="assets/images/icons/question.png" alt="" width="48" height="48" border="0"></td>
			<td class="blueBold" style="font-size:12px;padding-right:10px;"><?php echo _("Are you sure you want to unlink this image?"); ?></td>
		  </tr>
		</table>
		
	</td>
  </tr>
  <tr>
	<td style="padding:10px; text-align:center;">
	<input type="submit" name="nYes" value="Unlink" class="button black"> 
	<input type="button" name="nCancel" value="Cancel" class="button" onClick="$.colorbox.close(); return false;">
	</td>
  </tr>
</table>
</form>

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