<?php
include 'includes/db.php';
include 'includes/header.php';
?>
<div id="main-content" class="container mt-5">
<div class="text-center mb-5">
<h1 class="display-4 text-warning mb-3">
<i class="fas fa-newspaper me-3"></i>أحدث الأخبار
</h1>
<p class="lead text-light">تابع آخر أخبار السيارات والعروض الحصرية</p>
</div>
<div class="row">
<?php
$result = $conn->query("SELECT * FROM news ORDER BY created_at DESC");
$news_articles = $result->fetch_all(MYSQLI_ASSOC);
if (count($news_articles) > 0):
foreach ($news_articles as $article): ?>
<div class="col-lg-4 col-md-6 col-sm-12 mb-4">
<div class="card bg-dark text-white h-100 shadow-lg">
<img src="uploads/news/<?php echo htmlspecialchars($article['image']); ?>" class="card-img-top" alt="<?php echo htmlspecialchars($article['title']); ?>" style="height: 200px; object-fit: cover;">
<div class="card-body d-flex flex-column">
<h5 class="card-title text-warning"><?php echo htmlspecialchars($article['title']); ?></h5>
<p class="card-text text-light flex-grow-1"><?php echo substr(htmlspecialchars($article['content']), 0, 100); ?>...</p>
<div class="mt-auto">
<small class="text-muted">
<i class="fas fa-calendar-alt me-1"></i>
<?php echo date('d/m/Y', strtotime($article['created_at'])); ?>
</small>
<br>
<a href="news_article.php?id=<?php echo $article['id']; ?>" class="btn btn-warning mt-2 w-100">
<i class="fas fa-eye me-1"></i>اقرأ المزيد
</a>
</div>
</div>
</div>
</div>
<?php endforeach;
else: ?>
<div class="col-12">
<div class="text-center py-5">
<i class="fas fa-newspaper fa-5x text-muted mb-4"></i>
<h3 class="text-light mb-3">لا توجد أخبار حالياً</h3>
<p class="text-muted">سيتم إضافة الأخبار قريباً، تابعونا للحصول على آخر التحديثات</p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php include 'includes/footer.php'; ?>