<?php
ob_start();
include('include/connect.php');
$ids="";
if($_SERVER["REQUEST_METHOD"] == "POST")
{
if($_POST['action'] == "delete")
{ 
$ids = @implode(", ", $_POST['ids']);
$qry = "SELECT * FROM posts where id IN(".$ids.")";
$result = mysql_query($qry);
while($row = mysql_fetch_array($result))
{
	 $file='blog-pics/'.$row['image'];
	 @unlink($file);
}
$sqlAdd ="delete from posts where id IN(".$ids.")";
mysql_query($sqlAdd); 
header("Location:blog-posts.php?msg=success");
exit;
}
}
if(isset($_GET['msg']))
{
?>
<div style="color:red;padding-bottom:10px;" class="form-message" align="center"><b>Task completd successfully.</b></div>
<?php	
}
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head>
<meta charset="utf-8">
<title>Blog Posts</title>
<meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
<link rel="stylesheet" href="css/adminstyle.css" media="screen">
<link rel="stylesheet" href="css/adminstyle.responsive.css" media="all">
<style>.content .postcontent-0 .layout-item-0 { padding-right: 10px;padding-left: 10px;  }.ie7 .post .layout-cell {border:none !important; padding:0 !important; }.ie6 .post .layout-cell {border:none !important; padding:0 !important; }
</style></head>
<body>
<div id="main">
<div class="header-bg clearfix">
</div>
<div id="hmenu-bg" class="bar nav clearfix">
</div>
<div class="sheet clearfix">
<header class="header clearfix">
<div class="shapes">
<h1 class="headline" data-left="0.5%">
<a href="#" target="_blank">Blog Posts</a>
</h1>
</div>
<nav class="nav clearfix">
<div class="nav-inner">
<ul class="hmenu"><li><a href="blog-posts.php" class="active">Home</a></li></ul> 
</div>
</nav>
</header>
<div class="layout-wrapper clearfix">
<div class="content-layout">
<div class="content-layout-row">
<div class="layout-cell content clearfix"><article class="post article">
<h2 class="postheader">Add,Modify & Delete Blog Posts</h2>
<div class="postcontent postcontent-0 clearfix"><div class="content-layout">
<div class="content-layout-row">
<div class="layout-cell layout-item-0" style="width: 100%" >
<br>
<a href="blog-posts-add.php" class="submit">Add New Post</a>
<form  method="post" name="action_form" action="blog-posts.php">
<table class="table" width="100%">
<tbody>
<tr class="top nodrop nodrag">
<th>&nbsp;</th>
<th class="checkbox" style="width: 12px;"></th>
<th>Name</th>
<th>Image</th>
<th class="action">Action</th>
</tr>
<?php
$allRecords = mysql_query('select * from posts ORDER BY id DESC');
if(is_resource($allRecords))
{
while($row = mysql_fetch_assoc($allRecords))
{
    ?>
    <tr>
        <td>&nbsp;</td>
        <td class="checkbox"><input type="checkbox"  value="<?php echo $row['id'];?>" name="ids[]" class="case"></td>
        <td><?php echo $row['title']; ?></td>
        <td><?php echo $row['sdate']; ?></td>
        <td><?php echo $row['post']; ?></td>
        <td><img src="blog-pics/<?php echo $row['image']; ?>" height="30" width="30" /></td>                     
        <td class="action"><a href="blog-posts-add.php?id=<?php echo $row['id']; ?>">Edit</a></td>
    </tr>
    <?php
}
}
?>
<tr>
<td>&nbsp;</td>
<td class="checkbox"  colspan="4">
<select name="action" class="select" style="width:143px;">
<option>Choose an action</option>
<option value="delete">Delete</option>
</select>
<input type="submit" name="Go" class="submit" value="Apply action">
</td>
</tr>
</tbody>
</table>
</form></div>
</div>
</div>
</div>
</article></div>
</div>
</div>
</div>
</div>
<footer class="footer clearfix">
<div class="footer-inner">
<p></p>
<p class="page-footer">
</p>
</div>
</footer>
</div>
<link rel='Stylesheet' property='stylesheet' href='style.css' />

</body></html>