<?php
include("connection.php");
include("header.php");
?>
<div class="main-content">
    <div class="page-content">
        <div class="container-fluid">
            <!-- start page title -->
            <div class="row">
                <div class="col-12">
                    <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                        <h4 class="mb-sm-0 font-size-18">View blog</h4>
                    </div>
                </div>
            </div>
            <!-- end page title -->

            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row mb-2">
                                <div class="col-sm-6 mt-3">
                                    <div class="search-box me-2 d-inline-block">
                                        <div class="position-relative">
                                            <input type="text" class="form-control" autocomplete="off" id="searchInput"
                                                onkeyup="searchTable()" placeholder="Search...">
                                            <i class="bx bx-search-alt search-icon"></i>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-6 mt-3">
                                    <div class="text-sm-end">
                                        <a href="addblog.php">
                                            <button type="button"
                                                class="btn btn-success btn-rounded waves-effect waves-light mb-2">
                                                <i class="mdi mdi-plus me-1"></i> New Blog
                                            </button>
                                        </a>
                                    </div>
                                </div>
                            </div>

                            <div class="table-responsive">
                                <table class="table align-middle table-nowrap table-hover dt-responsive nowrap w-100"
                                    id="userList-table">
                                    <thead class="table-light">
                                        <tr>
                                            <th>S.no</th>
                                            <th>Image</th>
                                            <th>Title</th>
                                            <th>Slug</th>
                                            <th>Writer</th>
                                            <th>Date</th>
                                            <th>Category</th>
                                            <th>Short Des</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $query = "SELECT * FROM `blog` ORDER BY id DESC";
                                        $sql = mysqli_query($con, $query);
                                        $serial = 1;
                                        while ($row = mysqli_fetch_assoc($sql)) {
                                        ?>
                                        <tr>
                                            <td><?php echo $serial++; ?></td>
                                            <td><img src="./assets/images/blog/<?php echo $row['Image'] ?>" height="80"
                                                    width="80"></td>
                                            <td><?php echo $row['title'] ?></td>
                                            <td><?php echo $row['slug'] ?></td>
                                            <td><?php echo $row['blog_writer'] ?></td>
                                            <td><?php echo $row['blog_date'] ?></td>
                                            <td><?php echo $row['category'] ?></td>
                                            <td><?php echo $row['short_des'] ?></td>


                                            <td><a href="editblog.php?id=<?php echo $row['id'] ?>"><button type="button"
                                                        value="Edit" data-bs-target="#newContactModal"
                                                        class="btn btn-primary btn-rounded waves-effect waves-light addContact-modal mb-2">
                                                        <i class="far fa-edit"></i> Edit
                                                    </button></a>
                                                <a onclick="return confirm('Are you sure you want to delete this blog?')"
                                                    href="deleteblog.php?id=<?php echo $row['id'] ?>"><button
                                                        type="button" value="delete" data-bs-target="#newContactModal"
                                                        class="btn btn-danger btn-rounded waves-effect waves-light addContact-modal mb-2">
                                                        <i class="fas fa-trash"></i> Delete
                                                    </button></a>
                                            </td>
                                        </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </div><!-- end table responsive -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php include("footer.php"); ?>
</div>