<?php
//ini_set("display_errors",1);
include('../includes/site_config.php');
include('../session_handler.inc');

/*if ($Sess_UserType != "A") {
	exit;
}*/

# retrieve the template
$area = 'member';

$mode=$_POST['mode'];
if (isset($_POST['submit'])) {
	switch ($_POST['submit']) {
		case 'Edit banner':
			echo "<script>window.location='$CONST_LINK_ROOT/admin/affiliate_banners.php?id=$mode'</script>";
			//header("Location: $CONST_LINK_ROOT//affiliate_banners.php?id=$mode&PHPSESSID=".session_id());
			break;
		case 'Add Banner':
			echo "<script>window.location='$CONST_LINK_ROOT/admin/affiliate_banners.php?id=$mode'</script>";
			//header("Location: $CONST_LINK_ROOT//affiliate_banners.php?PHPSESSID=".session_id());
			break;
		case 'Delete banner':
			$query="SELECT * FROM banners WHERE ban_id = $mode";
			$retval=mysql_query($query,$link) or die(mysql_error());
			if (mysql_num_rows($retval) > 0) {
				$sql_picture=mysql_fetch_object($retval);
				@unlink("banners/$sql_picture->ban_picture");
			}
			$result=mysql_query("DELETE FROM banners WHERE ban_id=$mode",$link) or die(mysql_error());
			break;
	}
}

$result=mysql_query("SELECT * FROM banners",$link) or die(mysql_error());

//mysql_close($link);
?>
<? include("include/header.php");?>

<? include("banner_header.php");?>
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Affiliate Banner</div></div>
<div class="clear"></div>
<div class="admin-page">
<table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
  <tr>
    <td align="right">
      <?php //require_once("$CONST_INCLUDE_ROOT/user_status.inc.php");?>
    </td>
  </tr>
  <tr>
    <td class="pageheader"><?php echo AFF_BANNERS_SECTION_NAME ?></td>
  </tr>
  <tr>
    <td align="center">
	    <form action="<?php echo $CONST_LINK_ROOT?>/admin/affiliate_banlist.php?PHPSESSID=<?php echo session_id() ?>" method="post" name="frmBanners">
		<input type="hidden" name="mode" value="">
		<?php
			while($sql_banners=mysql_fetch_object($result)) {
				print("<div class='tdodd'><a href='$CONST_LINK_ROOT/' target='_blank'><img border=0 src='$CONST_LINK_ROOT/affiliates/banners/$sql_banners->ban_picture' alt='$sql_banners->ban_text'><br>$sql_banners->ban_text</a><br><br>");
				print("<input type='submit' value='Edit banner' name='submit'  onClick='document.frmBanners.mode.value=$sql_banners->ban_id'>&nbsp;<input type='submit' value='Delete banner' name='submit'  onClick='document.frmBanners.mode.value=$sql_banners->ban_id'></div><br>");
			}
		?>
		<p>
          <input type="submit" name="submit" value="Add Banner" > </form>
        </p>
     	 </td>
  </tr>

</table>
</div><div class="admin-page-bottom"></div></div>