<?php
session_start();
if (!isset($_SESSION['admin_id'])) {
    echo "<script>window.location.assign('login.php');</script>";
}
    include("header.php");
    
?>

<style>
    .page-header .left {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between !important;
    }
    a, .btn-link {
        color: #fff;
    }
    a:hover {
        color: #fff;
    }
    
    th,td{
        text-align:left !important;
    }
    
    @media screen and (max-width: 767px) {
        .page-title {
            margin-right: 0;
            font-size: 14px;
        }
    }
</style>


    <div class="page">
        <div id="page_top" class="section-body top_dark">
            <div class="container-fluid">
                <div class="page-header">
                    <div class="left">
                        <!--<a href="javascript:void(0)" class="icon menu_toggle mr-3"><i class="fa fa-align-left"></i></a>-->
                        <h1 class="page-title" style="color: #fff !important;">Admin Portal</h1>
                        <img src="myassets/images/logo1.png" width="30%" class="d-sm-none"/>
                        <a href="logout.php" class="icon menu_toggle mr-3"><i class="fa fa-sign-out"></i> Logout</a>
                    </div>
                    <!--<div class="right">-->
                    <!--    <div class="input-icon xs-hide mr-4">-->
                            <!--<input type="text" class="form-control" placeholder="Search for...">-->
                            <!--<span class="input-icon-addon"><i class="fa fa-search"></i></span>-->
                    <!--        <a href="logout.php" class="icon menu_toggle mr-3"><i class="fa fa-sign-out"></i> Logout</a>-->
                    <!--    </div>-->
                    <!--</div>-->
                </div>
            </div>
        </div>
        <div class="section-body mt-3">
            <div class="container-">
                <div class="row clearfix">
                 
                    <div class="col-12 pt-5">
                        <div class="card p-4">
                            <div class="mb-3 d-flex align-items-center justify-content-between">
                                <h3>USA Phone Finder Blogs</h3>
                                <a href="add-blog.php"><button class="btn btn-primary">Add New Blogs</button></a>
                            </div>
                            <div class="table-responsive">
                                <table id="myTable" class="table table-hover table-striped table-vcenter mb-0 text-nowrap" id="tbl_exporttable_to_xls">
                                    <thead>
                                        <tr>
                                            <th>S.NO</th>
                                            <th>Title</th>
                                            <th>Image</th>
                                            <th>Date</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $data = $obj ->View_Blog();
                                        foreach($data as $key => $value){
                                        ?>
                                           <tr>
                                               <td><?php echo $key+1;?></td>
                                               <td><?php echo $value["title"];?></td>
                                               <td><img src="upload/<?php echo $value["image"];?>" style="width:100px; height:100px; object-fit:cover;"/></td>
                                               <td><?php echo date("d-M-Y",strtotime($value["date"]));?></td>
                                               <td>
                                                   <a href="edit_blog.php?id=<?php echo $value["id"];?>"><i class="fa fa-edit fa-lg text-dark"></i></a>
                                                   <a href="?delete=<?php echo $value["id"]; ?>"><i class="fa fa-trash fa-lg px-2 text-danger"></i></a>
                                               </td>
                                               
                                           </tr>
                                           
                                        <?php
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
<?php
    include("footer.php");
    
    if (isset ($_GET["delete"])) {
      $obj->Delete_Blog($_GET["delete"]);
      echo "<script> alert('Deleted Successfully'); window.location.assign('index.php')</script>";
    }
?>

    