<?php
require_once 'includes/db.php';

$query = "
CREATE TABLE IF NOT EXISTS `dynamic_pages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `slug` varchar(100) NOT NULL UNIQUE,
  `title` varchar(255) NOT NULL,
  `content` text,
  `pdf_file` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
";

if ($conn->query($query) === TRUE) {
    echo "Table dynamic_pages created successfully.\n";
} else {
    echo "Error creating table: " . $conn->error . "\n";
}

$pages = [
    ['trust-deed', 'Trust Deed'],
    ['niti-ayog', 'Niti Ayog'],
    ['80g', '80G Certificate'],
    ['12a', '12A Certificate'],
    ['e-anudan', 'E-anudan'],
    ['ayush-bharat', 'Ayush Bharat'],
    ['skill-india', 'Skill India']
];

foreach ($pages as $page) {
    $slug = $page[0];
    $title = $page[1];
    $check = $conn->query("SELECT id FROM dynamic_pages WHERE slug='$slug'");
    if ($check->num_rows == 0) {
        $sql = "INSERT INTO dynamic_pages (slug, title, content) VALUES ('$slug', '$title', '<p>Welcome to the $title page. Content will be updated soon.</p>')";
        if ($conn->query($sql) === TRUE) {
            echo "Inserted $title.\n";
        } else {
            echo "Error inserting $title: " . $conn->error . "\n";
        }
    } else {
        echo "Page $title already exists.\n";
    }
}
?>
