<?php
    session_start();          
    if(empty($_SESSION['p0B_c0ff33'])) header('location:login.php?goto=index');
	include "../db_function.php";

	$table = "tbl_service_banner";

	// Handle Delete action
	if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
		$del_id = intval($_GET['id']);
		$res_old = mysql_query("SELECT image FROM tbl_service_banner WHERE id=$del_id");
		if ($res_old && $row_old = mysql_fetch_array($res_old)) {
			if (!empty($row_old['image']) && file_exists("../Site/images/ads/" . $row_old['image'])) {
				@unlink("../Site/images/ads/" . $row_old['image']);
			}
		}
		mysql_query("DELETE FROM tbl_service_banner WHERE id=$del_id");
		header("location:servicebanner.php?p=servicebanner&msg=2");
		exit();
	}

    if(empty($_GET['p'])){
        $_GET['p']="servicebanner";
    }

	include('templates/header.php'); 
	include('templates/menu.php'); 
?>

<!-- start content-outer -->
<div id="content-outer">
<!-- start content -->
<div id="content">

<div id="page-heading">
  <h1>View Service Banners</h1>
</div>

<?php
if (isset($_GET['msg']) && $_GET['msg'] == 1) {
	echo '<div id="message-green">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td class="green-left">Banner saved successfully!</td>
			<td class="green-right"><a class="close-green"><img src="images/table/icon_close_green.gif" alt="" /></a></td>
		</tr>
		</table>
	</div>';
} else if (isset($_GET['msg']) && $_GET['msg'] == 2) {
	echo '<div id="message-green">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td class="green-left">Banner deleted successfully!</td>
			<td class="green-right"><a class="close-green"><img src="images/table/icon_close_green.gif" alt="" /></a></td>
		</tr>
		</table>
	</div>';
}
?>
  
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
<tr>
	<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
	<th class="topleft"></th>
	<td id="tbl-border-top">&nbsp;</td>
	<th class="topright"></th>
	<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
</tr>
<tr>
	<td id="tbl-border-left"></td>
	<td>
		<div id="content-table-inner">

		<div style="margin-bottom:15px;">
			<a href="aservicebanner.php?p=aservicebanner" style="display:inline-block; padding:8px 18px; background:#27ae60; color:#fff; border-radius:4px; text-decoration:none; font-weight:bold;">+ Add New Service Banner</a>
		</div>

		<table border="0" width="100%" cellpadding="3" cellspacing="1" class="tb" id="product-table">
		<tr>
			<th width="5%">ID</th>
			<th width="25%">Banner Image</th>
			<th width="30%">Title / Description</th>
			<th width="25%">Link URL</th>
			<th width="15%">Options</th>
		</tr>

		<?php
		$res_banners = mysql_query("SELECT * FROM tbl_service_banner ORDER BY id DESC");
		if ($res_banners && mysql_num_rows($res_banners) > 0) {
			while ($row = mysql_fetch_array($res_banners)) {
		?>
		<tr class="tb_data">
			<td align="center"><?php echo $row['id']; ?></td>
			<td align="center">
				<img src="../Site/images/ads/<?php echo $row['image']; ?>" style="max-height:80px; max-width:220px; border:1px solid #ccc; padding:2px; border-radius:3px;" />
			</td>
			<td><strong><?php echo htmlspecialchars($row['title']); ?></strong></td>
			<td><a href="<?php echo htmlspecialchars($row['link']); ?>" target="_blank" style="color:#0033cc; word-break:break-all;"><?php echo htmlspecialchars($row['link']); ?></a></td>
			<td align="center">
				<a href="aservicebanner.php?p=aservicebanner&id=<?php echo $row['id']; ?>" class="icon-1 info-tooltip" title="Edit" style="margin-right:10px;">Edit</a>
				<a href="servicebanner.php?p=servicebanner&action=delete&id=<?php echo $row['id']; ?>" onclick="return confirm('Are you sure you want to delete this banner?');" class="icon-2 info-tooltip" title="Delete">Delete</a>
			</td>
		</tr>
		<?php
			}
		} else {
			echo '<tr><td colspan="5" align="center" style="padding:20px; color:#999;">No service banners found. Click "+ Add New Service Banner" to upload one.</td></tr>';
		}
		?>
		</table>

		<div class="clear"></div>
		</div>
	</td>
	<td id="tbl-border-right"></td>
</tr>
<tr>
	<th class="sized bottomleft"></th>
	<td id="tbl-border-bottom">&nbsp;</td>
	<th class="sized bottomright"></th>
</tr>
</table>
<div class="clear">&nbsp;</div>

</div>
<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer -->

<div class="clear">&nbsp;</div>

<?php include('templates/footer.php'); ?>
