<div class='wrap'>

<?php include(sprintf("%s/the_header.php", dirname(__FILE__))); ?>

<script type="text/javascript">
    //<![CDATA[

        function toggleAll(c) {
                var s = document.getElementsByTagName('input');
		for ( var i=0; i < s.length; i++ ) {
			if ( s[i].type == 'checkbox' && s[i].name == 'select[]') {
				s[i].checked = c;
			}
		}
        }

	function confirmDel() {
		return confirm('Are you sure?');
	}

    //]]>
</script>

<?php $results = $this->db_retrieve_ad(); ?>

<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">

	<h3><?php esc_html_e( 'Ad Overlays', 'ad-overlay-anything' );?></h3>
	<table class='form-table aoa_table'>
<?php
	$theader = "";
	$theader .= "<tr class='aoa_gray'>";
	$theader .= "<td><input type='checkbox' name='toggleAllfeeds' onchange='toggleAll(this.checked);' /></td>";
	$theader .= '<td>' . esc_html__( 'ID', 'ad-overlay-anything' ) . '</td>';
	$theader .= '<td>' . esc_html__( 'Active', 'ad-overlay-anything' ) . '</td>';
	$theader .= '<td>' . esc_html__( 'Name', 'ad-overlay-anything' ) . '</td>';
	$theader .= '<td><div class="aoa_table_content">' . esc_html__( 'Content', 'ad-overlay-anything' ) . '</div></td>';
	$theader .= '<td>' . esc_html__( 'Default Usage', 'ad-overlay-anything' ) . '</td>';
	$theader .= '<td>' . esc_html__( 'Edit', 'ad-overlay-anything' ) . '</td>';
	$theader .= '<td>' . esc_html__( 'Delete', 'ad-overlay-anything' ) . '</td>';
	$theader .= "</tr>\n";

	echo $theader;

	foreach ( $results as $ad ) {
		$str = ( $ad->status ) ? "<tr>" : "<tr class='aoa_gray'>";
		echo $str;
		echo "<td><input type='checkbox' name='select[]' value='" . $ad->id . "' /></td>";
		echo "<td>" . $ad->id . "</td>";
		$str = ( $ad->status ) ? "Yes" : "No";
		echo "<td>" . $str . "</td>";
		if ( $ad->status ) {
			echo "<td>" . $ad->name . "</td>";
			echo "<td><div class='aoa_table_content'>" . htmlentities( $ad->content ) . "</div></td>";
		}
		else {
			echo "<td><strike><i>" . $ad->name . "</i></strike></td>";
			echo "<td><strike><i>" . htmlentities( $ad->content ) . "</i></strike></td>";
		}
		echo "<td nowrap>[aoa id='" . $ad->id . "']<em>anything</em>[/aoa]</td>";

		echo "<td class='aoa_center'><a href='admin.php?page=aoa_show_ad&editID=" . $ad->id . "'><img width='16' height='16' alt='Edit' src='" . plugins_url( '../images/list_edit.png', __FILE__ ) . "'></a></td>";
		echo "<td class='aoa_center'><a onclick='return confirmDel()' href='admin.php?page=aoa_show_ads&delID=" . $ad->id . "'><img width='16' height='16' alt='Delete' src='" . plugins_url( '../images/list_remove.png', __FILE__ ) . "'></a></td>";
		echo "</tr>\n";
	}
	$total = count( $results );
	if ( ! $total ) {
		echo "<tr><td colspan='14'> <em><?php esc_html_e( 'No ads found', 'ad-overlay-anything' );?></em> </td></tr>\n";
	}
	else if ( $total > 10 ) {
		echo $theader;
	}
	?>
	</table>
	<p>
	For selected ad overlays: 
	<select name="aoa_function">
		<option value="delete">Delete</option>
		<option value="active">Set Active</option>
		<option value="inactive">Set Inactive</option>
	</select>
        <input type="submit" name="mass_submit" value="<?php esc_html_e( 'Submit', 'ad-overlay-anything' );?>" />
	</p>
	</form>
</div>
