<?php include("header.php"); ?>
<?php include("top.php"); ?>

<div class="offcanvas-overlay"></div>

<!-- ...:::Start Cart Section:::... -->
<div class="cart-section section-gap-top-30">
    <div class="container">
     
     
     
     
     
     
     
     
     
     
     
     <?php
session_start();


// Include the database connection
require 'db_connection.php';

// Fetch articles from the database
$query = "SELECT articles.id, articles.title, articles.details, articles.url, articles.images, cateories.name AS category_name 
          FROM articles 
          JOIN cateories ON articles.category_id = cateories.id";
$result = mysqli_query($conn, $query);

?>


    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            padding: 0;
        }
        .article-container {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
        }
        .article-card {
            display: flex;
            width: 100%;
            max-width: 600px;
            border: 1px solid #ccc;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .article-card img {
            width: 150px;
            height: 150px;
            object-fit: cover;
        }
        .article-content {
            padding: 10px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }
        .article-title {
            font-size: 18px;
            font-weight: bold;
            margin: 0;
            color: #007BFF;
            text-decoration: none;
        }
        .article-title:hover {
            text-decoration: underline;
        }
        .article-category {
            font-size: 14px;
            color: #555;
            margin-top: 10px;
        }
    </style>

    <h5>Articles</h5>
    <div class="article-container">
        <?php
        if (mysqli_num_rows($result) > 0) {
            while ($article = mysqli_fetch_assoc($result)) {
                // Decode images JSON
                $images = json_decode($article['images'], true);
                $imagePath = !empty($images) ? htmlspecialchars($images[0]) : 'placeholder.jpg'; // Fallback image if none exist
                
                // Generate the article details URL
                $detailsUrl = "articledetail.php?id=" . urlencode($article['id']);
        ?>
                <div class="article-card">
                    <a href="<?= htmlspecialchars($detailsUrl); ?>">
                        <img src="adm/<?= htmlspecialchars($imagePath); ?>" alt="Article Image">
                    </a>
                    <div class="article-content">
                        <a href="<?= htmlspecialchars($detailsUrl); ?>" class="article-title">
                            <?= htmlspecialchars($article['title']); ?>
                        </a>
                        <p class="article-category"><?= htmlspecialchars($article['category_name']); ?></p>
                    </div>
                </div>
        <?php
            }
        } else {
            echo "<p>No articles found.</p>";
        }
        ?>
    </div>

     
     
     
     
     
     
     
     
    </div>
</div>
<!-- ...:::End Cart Section:::... -->

<!-- JavaScript to Delete Item from Cart -->
<script>
document.querySelectorAll('.delete-item').forEach(button => {
    button.addEventListener('click', function () {
        const productId = this.getAttribute('data-product-id');
        let cart = JSON.parse(getCookie('cart') || '{}');
        
        delete cart[productId]; // Remove item from cart

        setCookie('cart', JSON.stringify(cart), 7); // Update cookie
        location.reload(); // Refresh page to reflect changes
    });
});

function getCookie(name) {
    const cookies = document.cookie.split(';').map(cookie => cookie.trim());
    for (const cookie of cookies) {
        if (cookie.startsWith(name + '=')) {
            return decodeURIComponent(cookie.split('=')[1]);
        }
    }
    return '';
}

function setCookie(name, value, days) {
    const date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    document.cookie = `${name}=${encodeURIComponent(value)}; expires=${date.toUTCString()}; path=/`;
}
</script>















    <div class="user-event-section">
    <!-- Start User Event Area -->
    <div class="col pos-relative">
        
        
        <div class="user-event-area">
             <div class="user-event">
                <a aria-label="Consultation" href="#" class="event-btn-link ">
                    <i class="fa-solid fa-comments"></i>
                    <span class="icon-label">Consultation</span>
                </a>
            </div>
            
            <div class="user-event">
                <a aria-label="Recipe" href="view.php" class="event-btn-link">
                    <i class="fa-solid fa-book"></i>
                    <span class="icon-label">Recipe</span>
                </a>
            </div>
            <div class="user-event">
                <a aria-label="Articles" href="article.php" class="event-btn-link pin">
                    <i class="fa-solid fa-newspaper"></i>
                    <span class="icon-label">Articles</span>
                </a>
            </div>
            <div class="user-event">
                <a aria-label="Ecommerce" href="home.php" class="event-btn-link">
                    <i class="fa-solid fa-bag-shopping"></i>
                    <span class="icon-label">Ecommerce</span>
                </a>
            </div>
            
           
        </div>
    </div>
    <!-- End User Event Area -->
</div>
<style>
.user-event-section {
    padding: 20px;
    background-color: #f9f9f9;
}

.user-event-area {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 20px;
}

.user-event {
    text-align: center;
}

.event-btn-link {
    text-decoration: none;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.event-btn-link i {
    font-size: 30px;
    color: green;
    margin-bottom: 5px;
    transition: color 0.3s ease;
}

.icon-label {
    font-size: 14px;
    color: #555;
}

/* Highlight active menu item */
.event-btn-link.pin i {
    color: red; /* Active icon color */
}

.event-btn-link.pin .icon-label {
    color: #007bff; /* Active text color */
    font-weight: bold; /* Optional: make text bold */
}
</style>
 <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">















