<?php
// File: sitemap.php (Aids SEO by listing all major public pages)

session_start();
require_once("config/db.php"); 

// --- Fetch SEO/Settings Data ---
$meta_title = "Website Sitemap | eSarthi Education";
$meta_description = "Complete directory of all pages and resources available on the eSarthi Education website.";

// CRITICAL: INCLUDE HEADER FIRST
include("includes/header.php");

// --- Data Fetching ---
// Fetch all active courses for dynamic links
$q_courses = $conn->query("
    SELECT course_id, course_name 
    FROM courses 
    WHERE status='active' 
    ORDER BY course_name ASC
");

// Fetch the latest blog posts for dynamic links
$q_blogs = $conn->query("
    SELECT title, slug 
    FROM blogs 
    WHERE status='Published' 
    ORDER BY published_date DESC 
    LIMIT 10
");

// --- Content Data ---
$marathi_title = "वेबसाइट नकाशा (Website Sitemap)";
$marathi_main_links = "मुख्य दुवे (Main Links)";
$marathi_course_links = "कोर्सेस आणि प्रोग्राम्स";
$marathi_blog_links = "नवीनतम ब्लॉग पोस्ट्स";
$marathi_student_portal = "विद्यार्थी पोर्टल आणि कायदेशीर"; // Changed heading
?>

<div class="content-container">

    <h1 class="section-title" style="color: #0f2b46; margin-bottom: 40px;">
        <i class="fas fa-sitemap" style="color: #dc3545;"></i> <?= htmlspecialchars($marathi_title) ?>
    </h1>

    <div class="grid" style="grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-bottom: 50px;">
        
        <div class="card-placeholder" style="background: white; padding: 25px; border-left: 4px solid #ffc107;">
            <h3 style="color: #0f2b46;"><i class="fas fa-home"></i> <?= htmlspecialchars($marathi_main_links) ?></h3>
            <ul style="list-style: none; padding-left: 0; line-height: 2.0;">
                <li><a href="index.php">Home (मुख्य पृष्ठ)</a></li>
                <li><a href="about.php">About Us (आमच्याबद्दल)</a></li>
                <li><a href="courses.php">All Courses (सर्व कोर्सेस)</a></li>
                <li><a href="admission.php">Admissions (प्रवेश अर्ज)</a></li>
                <li><a href="contact.php">Contact Us (संपर्क)</a></li>
                <li><a href="gallery.php">Gallery & Events (गॅलरी)</a></li>
            </ul>
        </div>

        <div class="card-placeholder" style="background: white; padding: 25px; border-left: 4px solid #dc3545;">
            <h3 style="color: #0f2b46;"><i class="fas fa-graduation-cap"></i> <?= htmlspecialchars($marathi_course_links) ?></h3>
            <ul style="list-style: none; padding-left: 0; line-height: 2.0; font-size: 0.95em;">
                <?php if ($q_courses->num_rows > 0): ?>
                    <?php while ($course = $q_courses->fetch_assoc()): ?>
                        <li><a href="course-detail.php?id=<?= $course['course_id'] ?>"><?= htmlspecialchars($course['course_name']) ?></a></li>
                    <?php endwhile; ?>
                <?php else: ?>
                    <li>No active courses found.</li>
                <?php endif; ?>
            </ul>
        </div>
        
        <div class="card-placeholder" style="background: white; padding: 25px; border-left: 4px solid #0f2b46;">
            <h3 style="color: #0f2b46;"><i class="fas fa-newspaper"></i> <?= htmlspecialchars($marathi_blog_links) ?></h3>
            <ul style="list-style: none; padding-left: 0; line-height: 2.0; font-size: 0.95em;">
                <li><a href="blog.php">Blog Home</a></li>
                <?php if ($q_blogs->num_rows > 0): ?>
                    <?php while ($blog = $q_blogs->fetch_assoc()): ?>
                        <li><a href="blog-detail.php?slug=<?= $blog['slug'] ?>"><?= htmlspecialchars($blog['title']) ?></a></li>
                    <?php endwhile; ?>
                <?php else: ?>
                    <li>No recent posts found.</li>
                <?php endif; ?>
            </ul>
        </div>
        
        <div class="card-placeholder" style="background: white; padding: 25px; border-left: 4px solid #dc3545;">
            <h3 style="color: #0f2b46;"><i class="fas fa-lock"></i> <?= htmlspecialchars($marathi_student_portal) ?></h3>
            <ul style="list-style: none; padding-left: 0; line-height: 2.0;">
                <li><a href="student/login.php">Student Login</a></li>
                <li><a href="privacy-policy.php">Privacy Policy</a></li>
                <li><a href="terms.php">Terms & Conditions</a></li>
                <li><a href="faq.php">FAQs</a></li>
            </ul>
        </div>

    </div>

</div>

<?php
// CRITICAL: INCLUDE FOOTER LAST
include("includes/footer.php");
?>