<?php
session_start();
include("connection.php");
$user_profile=$_SESSION['user_name'];
// if($user_profile==true){

// }else{
//     header('location:index.php');
// }
?>
              <?php 
include("includes/header.php");
include("includes/sidebar.php");
?>  
                <div class="app-main__outer">
                    <div class="app-main__inner">
                        <div class="app-page-title">
                            <div class="page-title-wrapper">
                                <div class="page-title-heading">
                                    <div class="page-title-icon">
                                    <i class="fas fa-tachometer-alt"></i>

                                    </div>
                                    <div>Admin Dashboard
                                        
                                    </div>
                                </div>
                                <div class="page-title-actions">
                                    <button type="button" data-toggle="tooltip" title="Example Tooltip" data-placement="bottom" class="btn-shadow mr-3 btn btn-dark">
                                        <i class="fa fa-star"></i>
                                    </button>
                                    
                                </div>   
                             </div>
                         </div>
                                      
                         <div class="row">
    <div class="col-md-12">
        <div class="main-card mb-3 card">
            <div class="card-header">Home-Page
            <div class="btn-actions-pane-right">
                    <div role="group" class="btn-group-sm btn-group">
                        <a href="create_homepage.php">
                            <button class="active btn btn-focus">Add</button>
                        </a>
                    </div>
                </div>
            </div>
            <div class="table-responsive">
                <table id="main-category-table"
                    class="align-middle mb-0 table table-borderless table-striped table-hover">
                    <thead>
        <tr>
            <th class="text-center">ID</th>
            <th class="text-center">Category</th>
            <th class="text-center">Image</th>
            <th class="text-center">Title</th>
            <th class="text-center">Subtitle</th>
            <th class="text-center">Description</th>
            <th class="text-center">Actions</th>
        </tr>
    </thead>
    <tbody>
        <?php
            $i = 1;
            include("connection.php");
            $sql = "SELECT * FROM homepage";
            $result = mysqli_query($conn, $sql);
            if ($result) {
                while ($row = mysqli_fetch_assoc($result)) {
                    $id = $row['id'];
                    $category = $row['category'];
                    $image = $row['image']; 
                    $title = $row['title'];
                    $subtitle = $row['subtitle'];
                    $description = $row['description'];

                    echo '
                        <tr>
                            <td class="text-center text-muted">' . $i . '</td>
                              <td class="text-center">' . $category . '</td>
                            
                            <td class="text-center">';
                                if ($image) {
                                    echo '<img src="upload/' . $image . '" width="150px" alt="Image of ' . $title . '">';
                                } else {
                                    echo 'No Image';
                                }
                    echo '</td>
                            <td class="text-center">' . $title . '</td>
                            <td class="text-center">' . $subtitle . '</td>
                            <td class="text-center">' . $description . '</td>
                            <td class="text-center">
                                <a href="update_homepage.php?update_id=' . $id . '" class="btn btn-primary btn-sm">Update</a>
                                <a href="delete_homepage.php?delete_id=' . $id . '" class="btn btn-danger btn-sm">Delete</a>
                            </td>
                        </tr>';
                    $i++;
                }
            }
        ?>
    </tbody>
</table>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function () {
        $('#main-category-table').DataTable();
    });
</script>

                        </div>

<?php
include("includes/footer.php");
?>
