<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
require('../includes/cmain.inc.php');
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']!= 'true') {
header("Location: index.php");
    exit();	
	  }
	  
 // print_r(SITE_WS_PATH);exit();
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
    $id = isset($_REQUEST['id']) ? (int)$_REQUEST['id'] : 0;

    if ($id > 0) {
        $sql3 = "DELETE FROM `tbl_blog` WHERE id = $id";

        if (function_exists('db_query')) {
         $result = db_query($sql3);
if ($result === TRUE) {
    header("Location: service_list.php?msg=deleted");
    exit();
} else {
    echo "Error deleting record: " . mysqli_error($GLOBALS['conn']);
}
        } else {
            echo "Error: db_query() function not found.";
        }
    } else {
        echo "Invalid ID.";
    }

    exit(); // stop the page from rendering below
}


?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome Admin</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

body {
  font-family: Arial, Helvetica, sans-serif;
}

/* Style the header */
header {
  background-color: #888888;
  padding: 30px;
  text-align: center;
  font-size: 20px;
  color: white;
}

/* Create two columns/boxes that floats next to each other */
nav {

}

/* Style the list inside the menu */
nav ul {
  list-style-type: none;
  padding: 0;
}

article {
  float: left;
  padding: 20px;
  width: 80%;
  background-color: #f1f1f1;
  font-size:13px;
  height: 500px; /* only for demonstration, should be removed */
}

/* Clear floats after the columns */
section::after {
  content: "";
  display: table;
  clear: both;
}

/* Style the footer */
footer {
  background-color: #777;
  padding: 10px;
  text-align: center;
  color: white;
}
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
  align:center;
}

/* Responsive layout - makes the two columns/boxes stack on top of each other instead of next to each other, on small screens */
@media (max-width: 600px) {
  nav, article {
    width: 100%;
    height: auto;
  }
}
.main-header{
    display:flex;
    flex-direction:column;
}
.div-header{
    display:flex;
    background:#295D9C url(images/abstract.jpg) right no-repeat;
    justify-content:center;
    color:white;
}
.div-content{
    display:flex;
     background:#EEEEEE;
      justify-content:center;
    
}
.div-menu{
    display:flex;
    flex-direction:column;
     justify-content:left;
      border:2px solid #B1B1B1;
     width:15%;
    padding:30px;
    
}
.div-editor{
     display:flex;
    flex-direction:column;
    background:#f7f7f0;
    font-size:13px;
    border:2px solid #B1B1B1;
     justify-content:center;
     width:85%;
     padding:30px;
}
.div-footer{
      display:flex;
    flex-direction:column;
     justify-content:center;
     align-items:center;
     color:white;
     font-size:12px;
         background:#295D9C url(images/abstract.jpg) right no-repeat;

    
}
</style>
</head>
<body>
<div class="main-header">    
<div class="div-header">
     <h2>Welcome Admin</h2>
</div>
<div class="div-content">
    <div class="div-menu">  <?php include("nav.php");?></div>
     <div class="div-editor">
          <h3><a href="add_blog.php" align="left">Add New Blog</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="blog_cat.php" align="left">Blog Categories</a></h3>
            <h1>Blog List</h1>
    <table style="align:center">
	<tr>
	<th>S. No.</th>
	<th>URL</th>
	<th>Provided Category</th>
	<th>Status</th>
	<th>Edit</th>
	<th>Delete</th>
	
	</tr>
	<?php
	$count=0;
	$listQuery="SELECT * FROM tbl_blog";
	$result=db_query($listQuery);
	while($row=mysqli_fetch_array($result)){
	?>
	<tr>
	<td><?php echo $row['id'];?></td>
	<td><?php echo $row['heading'];?></td>
	<td><?php echo $row['cat_name'];?></td>
	<td><?php echo $row['status'];?></td>
	<td><a href="add_blog.php?id=<?php echo $row['id'];?>&action=edit" >Edit</a></td>
	<td><a href="service_list.php?id=<?php echo $row['id'];?>&action=delete" onclick="return stdel_confirm();" >Delete</a></td>
	</tr>
	<?php 
	$count++;
	}?>
	</table>
	<script>
function stdel_confirm(){  return confirm("Are you sure want to delete?"); }
</script>
     </div>
    
</div>
<div class="div-footer">
    <p>Copyright © 2025 All Rights Reserved.</p>
</div>
</div>

</body>
</html>

