<?
require_once("../config.php");
require_once("header.php");
require_once("../banner_lib.php");

if($HTTP_COOKIE_VARS["admin_log"]=="in")
{
echo "<p class=\"bodymd\">[ <a href=\"index.php\">Link Admin Home</a> | <a href=\"index.php?ax=addcat\">Add a Category</a> | <a href=\"index.php?ax=add\">Add a Link</a> | <a href=\"index.php?ax=logout\">Logout</a> | <a href=\"index.php?ax=install\">Install Links</a> ]</p>";


if(isset($_POST[s1]))
{
	//get the original file name
	$MyFile = $_FILES[BannerFile][name];

	if(empty($_POST[BannerURL]) || $_POST[BannerURL] == "http://")
	{
		echo "<center><br><font color=red size=2 face=verdana><b>All fields are required!</b></font></center>";
	}
	else
	{
		if(!empty($MyFile)) //new banner will be uploaded
		{
			//delete the old file
			unlink("../banners/".$_POST[OldFile]);

			$t = time();
			$MyFile = $t."_".$MyFile;

			copy($_FILES[BannerFile][tmp_name], "../banners/".$MyFile);
		}
		else
		{
			$MyFile = $_POST[OldFile];
		}

		$q1 = "update dd_banners set 
							BannerFile = '$MyFile',
							BannerURL = '$_POST[BannerURL]',
							AltText = '$_POST[BannerALT]',
							BannerType = '$_POST[BannerType]'
							
							where BannerID = '$_GET[BannerID]' ";
		
		mysql_query($q1) or die(mysql_error());
	}
}


//get the banner info
$q1 = "select * from dd_banners where BannerID = '$_GET[BannerID]' ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);
?>

<form method=post enctype="multipart/form-data">
<table align=center width=450>
<caption align=center><b>Edit a banner</b></caption>

<tr>
	<td>Banner type:</td>
	<td>
		<select name=BannerType>
          <option value="468x60" selected>468 x 60 (Full Banner)</option>
          <option value="150x61">150x61 (button)</option>
        </select>
	</td>
</tr>

<tr>
	<td>Link to:</td>
	<td><input type=text name=BannerURL value="<?=$a1[BannerURL]?>"></td>
</tr>

<tr>
	<td>New File:</td>
	<td><input type=file name=BannerFile></td>
</tr>

<tr>
	<td>Alt text:</td>
	<td><input type=text name=BannerALT value="<?=$a1[AltText]?>"></td>
</tr>

<tr>
	<td>&nbsp;</td>
	<td>
		
		<input type=hidden name=OldFile value="<?=$a1[BannerFile]?>">
		<input type=submit name=s1 value="Save">
	</td>
</tr>

<tr>
	<td colspan=2 align=center>
		<img src="../banners/<?=$a1[BannerFile]?>">
	</td>
</tr>

</table>
</form>

<br><br>
<?


}
else
{
	echo "<a href=index.php>Click here to login</a>";
			
			}

require_once("footer.php");
	ob_end_flush();
?>