<?php
/*
copyright: copyright 2004 Php Image Host. All Rights Reserved. You may modify this file for use on your
					site running a licenced copy of the Php Image Host scripts.
					You must not distribute this file or derivations of it.
Nullified By CrAcKlOvE
*/

require_once(dirname(__FILE__).'/includes/config.inc.php');
require_once(dirname(__FILE__).'/../classes/adrotator.class.php');

$rotator =& new adrotator($ace);
$message = '';
$name = $content = $group = '';
$live = 0;

$aid = $ace->getint('a', $_REQUEST);
$ad = 0;
if( $aid != 0 ){
	$ad = $rotator->getad($aid);
	if( !$ad ) $aid = 0;
}

if( $ad && $ace->getstr('update', $_POST) ){
	$ad->content = $ace->getstr('content', $_POST);
	$ad->group = $ace->getstr('group', $_POST);
	$ad->live = $ace->getint('live', $_POST);
	$rotator->updatead($aid, $ad->group, $ad->content, $ad->live);
	$message = 'Ad "'.htmlspecialchars($ad->name).'" Updated.';
}

$ids = isset($_POST['ids']) ? $ace->getids($_POST['ids']) : array();

if( count($ids) > 0 ){
	if( $ace->getstr('delete', $_POST) != '' ){
		$message = $rotator->deleteads($ids).' Ads Deleted.';
	}elseif( $ace->getstr('reset', $_POST) != '' ){
		$message = $rotator->resetviews($ids).' Ads Reset To 0 Views.';
	}elseif( $ace->getstr('setlive', $_POST) != '' ){
		$message = $rotator->changestatus($ids, 1).' Ads Status Changed To "Live".';
	}elseif( $ace->getstr('notlive', $_POST) != '' ){
		$message = $rotator->changestatus($ids, 0).' Ads Status Changed To "Not Live".';
	}
}elseif( $ace->getstr('add', $_POST) != '' ){
	$name = $ace->getstr('name', $_POST);
	$content = $ace->getstr('content', $_POST);
	$group = $ace->getstr('group', $_POST);
	$live = $ace->getint('live', $_POST);
	if( $name != '' ){
		$aid = $rotator->addad($name, $group, $content, $live);
		$ad = $rotator->getad($aid);
		$message = 'Ad Added.';
	}else{
		$message = 'You must enter a name for this new ad.';
	}
}



require_once(dirname(__FILE__).'/includes/header.inc.php');

?>
<div style="text-align: center;">
<b>Manage Banners</b><br /><br />
This page lets you add, edit, view and delete the banner ads displayed at the top and bottom of your site.
Active banners are displayed in rotation at the top and bottom of each page of the site.
</div>
<br /><br />
<?php

if( $message != '' ){
?>
<div class="errors"><?php echo $message;?></div>
<?php
}

if( $ad == 0 ){

	$ads = $rotator->getads();


?>
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
<table class="formtable" cellspacing="1" cellpadding="0" border="0" align="center">
<tr>
	<td class="formheading" colspan="2">Create A New Ad</td>
</tr>
<tr>
	<td class="formlabel">Name:</td>
	<td class="formfield"><input type="text" name="name" value="<?php echo htmlspecialchars($name);?>" />
		<br />The name of the ad is just for your reference when viewing ads on this page.
	</td>
</tr>
<!--<tr>
	<td class="formlabel">Group:</td>
	<td class="formfield"><input type="text" name="group" value="<?php echo htmlspecialchars($group);?>" />
		<br />Enter a "group name" for this ad. Use "banner" for banners displayed at the top or bottom of the page,
			"left" for ads displayed on the left of the page, and "right" for banners displayed in the right hand column.
			<br /><br />If you are customizing the site, you can use different groups as required.
	</td>
</tr>-->
<tr>
	<td class="formlabel">Ad HTML:</td>
	<td class="formfield"><textarea name="content" style="width: 400px; height: 80px;"><?php echo htmlspecialchars($content);?></textarea>
		<br />Enter all the html required to display this ad. Most affiliate companies provide you with the
			html to copy and paste here for their banners.
	</td>
</tr>
<tr>
	<td class="formlabel">Live?</td>
	<td class="formfield"><input type="checkbox" name="live" value="1" <?php if( $live == 1 ) echo ' CHECKED ';?> />
		<br />Check this box to make this ad "Live". Only "Live" ads will be displayed on the site.
	</td>
</tr>
<tr>
	<td class="formlabel">&nbsp;</td>
	<td class="formfield"><input type="submit" name="add" value="Add This Ad" />
	</td>
</tr>
</table>
</form>
<?php if( count($ads) > 0 ){ ?>
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
<table class="formtable" cellspacing="1" cellpadding="0" border="0" align="center">
<tr>
	<td colspan="2" class="formheading"><?php echo count($ads);?> Ad(s) In Database</td>
</tr>
<?php
$tr = 1;
foreach( $ads as $ad ){
$tr = 1- $tr;
?>
<tr class="tr<?php echo $tr+1;?>">
	<td><input type="checkbox" name="ids[]" value="<?php echo $ad->ad_id;?>" /></td>
	<td style="text-align: center;"><b><?php echo htmlspecialchars($ad->name);?> (<?php echo $ad->views;?> views)</b>
		[<a href="<?php echo $_SERVER['SCRIPT_NAME'];?>?a=<?php echo $ad->ad_id;?>">Edit</a>]
		<?php echo $ad->live == 1 ? 'Live' : 'Not Live';?>
		<br /><br />
		<?php echo $ad->content;?>
	</td>
</tr>
<?php
}
?>
</table>
<div style="text-align: center;">
<br /><input type="submit" name="setlive" value="Set Selected Ads To Live" /><br />
<br /><input type="submit" name="notlive" value="Set Selected Ads To Not Live" /><br />
<br /><input type="submit" name="reset" value="Reset Selected Ad Views To 0" onClick="return confirm('Are you sure you want to reset the view count for the selected ads?');" />
<br /><br /><input type="submit" name="delete" value="Delete Selected Ads" onClick="return confirm('Are you sure you want to delete the selected ads?');" />
<br />
</div>
</form>
<?php
}

}else{
?>
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
<input type="hidden" name="a" value="<?php echo $ad->ad_id;?>" />
<table class="formtable" cellspacing="1" cellpadding="0" border="0" align="center">
<tr>
	<td class="formheading" colspan="2">Edit Ad "<?php echo htmlspecialchars($ad->name);?>"</td>
</tr>
<!--
<tr>
	<td class="formlabel">Group:</td>
	<td class="formfield"><input type="text" name="group" value="<?php echo htmlspecialchars($ad->groupname);?>" />
		<br />Enter a "group name" for this ad. Use "banner" for banners displayed at the top or bottom of the page,
			"left" for ads displayed on the left of the page, and "right" for banners displayed in the right hand column.
			<br /><br />If you are customizing the site, you can use different groups as required.
	</td>
</tr>
 -->
<tr>
	<td class="formlabel">Ad HTML:</td>
	<td class="formfield"><textarea name="content" style="width: 400px; height: 80px;"><?php echo htmlspecialchars($ad->content);?></textarea>
		<br />Enter all the html required to display this ad. Most affiliate companies provide you with the
			html to copy and paste here for their banners.
	</td>
</tr>
<tr>
	<td class="formlabel">Live?</td>
	<td class="formfield"><input type="checkbox" name="live" value="1" <?php if( $ad->live == 1 ) echo ' CHECKED ';?> />
		<br />Check this box to make this ad "Live". Only "Live" ads will be displayed on the site.
	</td>
</tr>
<tr>
	<td class="formlabel">&nbsp;</td>
	<td class="formfield"><input type="submit" name="update" value="Update This Ad" />
	</td>
</tr>
</table>
</form>
<?php
}

require_once(dirname(__FILE__).'/includes/footer.inc.php');

?>
