<?php
require_once 'db_connect.php';

try {
    // ১. Foreign Key চেক বন্ধ করা
    $pdo->exec("SET FOREIGN_KEY_CHECKS = 0");
    
    // ২. আগের সব কোর্স মুছে ফেলা (TRUNCATE)
    $pdo->exec("TRUNCATE TABLE courses");
    
    // ৩. নতুন ৬টি কোর্স যুক্ত করা
    $sql = "INSERT INTO courses (id, title, duration, fee, offline_fee, description, status) VALUES 
    (1, 'Islamic Studies', '6 Months', 100.00, 0.00, 'A comprehensive course covering the core principles of Islam, Fiqh, Aqeedah, and daily Islamic rulings.', 'active'),
    (2, 'Arabic Language', '6 Months', 100.00, 0.00, 'Master the Arabic language from basics to advanced grammar to understand the Quran and converse fluently.', 'active'),
    (3, 'Qur''an Memorization (Hifz)', '12 Months', 100.00, 0.00, 'A structured and guided Hifz program with one-on-one attention to help you memorize the Holy Quran effectively.', 'active'),
    (4, 'Qur''an Recitation with Tajweed', '4 Months', 100.00, 0.00, 'Learn to recite the Holy Quran beautifully and accurately with proper application of Tajweed rules.', 'active'),
    (5, 'Qur''an Qaida with Tajweed', '3 Months', 100.00, 0.00, 'Perfect for beginners. Learn the Arabic alphabet, pronunciation, and basic Tajweed rules using the Noorani Qaida.', 'active'),
    (6, 'Tajweed-ul-Qur''an', '4 Months', 100.00, 0.00, 'An advanced course focused solely on mastering the intricate rules of Tajweed and Makharij.', 'active')";
    
    $pdo->exec($sql);
    
    // ৪. Foreign Key চেক চালু করা
    $pdo->exec("SET FOREIGN_KEY_CHECKS = 1");

    echo "<div style='font-family:sans-serif; text-align:center; margin-top:100px;'>";
    echo "<h1 style='color:green;'>✅ Database Updated Successfully!</h1>";
    echo "<p style='font-size:18px;'>আগের সব কোর্স মুছে নতুন ইসলামিক কোর্সগুলো ডাটাবেসে সফলভাবে যুক্ত হয়েছে।</p>";
    echo "<a href='index.php' style='display:inline-block; padding:10px 20px; background:#064e3b; color:#fff; text-decoration:none; border-radius:5px; font-weight:bold;'>Go Back to Home Page</a>";
    echo "</div>";

} catch (PDOException $e) {
    echo "<h2 style='color:red; text-align:center;'>Error: " . $e->getMessage() . "</h2>";
}
?>