cd /home/tanahtin/museum.pondoktingal.com

# =============================================
# COUNTRIES MODULE
# =============================================

# countries/index.php
cat > admin/countries/index.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$db = getDB();
$countries = $db->query("SELECT * FROM countries ORDER BY name");

include '../header.php';
?>

<h1>Countries</h1>
<p><a href="create.php" class="button">+ Add New Country</a></p>

<table>
    <thead>
        <tr><th>ID</th><th>Name</th><th>Actions</th></tr>
    </thead>
    <tbody>
        <?php while($row = $countries->fetch_assoc()): ?>
        <tr>
            <td><?php echo $row['id']; ?></td>
            <td><?php echo htmlspecialchars($row['name']); ?></td>
            <td>
                <a href="edit.php?id=<?php echo $row['id']; ?>">Edit</a> |
                <a href="delete.php?id=<?php echo $row['id']; ?>" onclick="return confirm('Delete this country? All districts will be deleted too.')">Delete</a>
            </td>
        </tr>
        <?php endwhile; ?>
    </tbody>
</table>

<?php include '../footer.php'; ?>
EOF

# countries/create.php
cat > admin/countries/create.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$error = '';
$success = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name']);
    
    if (empty($name)) {
        $error = 'Country name is required';
    } else {
        $db = getDB();
        $stmt = $db->prepare("INSERT INTO countries (name) VALUES (?)");
        $stmt->bind_param("s", $name);
        
        if ($stmt->execute()) {
            header('Location: index.php?success=created');
            exit();
        } else {
            $error = 'Error: ' . $db->error;
        }
    }
}

include '../header.php';
?>

<h1>Add New Country</h1>

<?php if ($error): ?>
    <div class="error"><?php echo $error; ?></div>
<?php endif; ?>

<form method="POST">
    <div class="form-group">
        <label>Country Name</label>
        <input type="text" name="name" required>
    </div>
    <button type="submit">Save Country</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# countries/edit.php
cat > admin/countries/edit.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$db = getDB();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name']);
    $stmt = $db->prepare("UPDATE countries SET name = ? WHERE id = ?");
    $stmt->bind_param("si", $name, $id);
    
    if ($stmt->execute()) {
        header('Location: index.php?success=updated');
        exit();
    }
}

$result = $db->query("SELECT * FROM countries WHERE id = $id");
$country = $result->fetch_assoc();

if (!$country) {
    header('Location: index.php');
    exit();
}

include '../header.php';
?>

<h1>Edit Country</h1>

<form method="POST">
    <div class="form-group">
        <label>Country Name</label>
        <input type="text" name="name" value="<?php echo htmlspecialchars($country['name']); ?>" required>
    </div>
    <button type="submit">Update Country</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# countries/delete.php
cat > admin/countries/delete.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$db = getDB();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $stmt = $db->prepare("DELETE FROM countries WHERE id = ?");
    $stmt->bind_param("i", $id);
    $stmt->execute();
    header('Location: index.php?success=deleted');
    exit();
}

$result = $db->query("SELECT * FROM countries WHERE id = $id");
$country = $result->fetch_assoc();

if (!$country) {
    header('Location: index.php');
    exit();
}

include '../header.php';
?>

<h1>Delete Country</h1>
<p>Are you sure you want to delete: <strong><?php echo htmlspecialchars($country['name']); ?></strong>?</p>
<p style="color: red;">Warning: All districts in this country will also be deleted!</p>

<form method="POST">
    <button type="submit" style="background: #c62828;">Yes, Delete</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# =============================================
# DISTRICTS MODULE
# =============================================

# districts/index.php
cat > admin/districts/index.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$db = getDB();
$country_filter = isset($_GET['country_id']) ? intval($_GET['country_id']) : 0;

if ($country_filter) {
    $districts = $db->query("SELECT d.*, c.name as country_name FROM districts d 
                             JOIN countries c ON d.country_id = c.id 
                             WHERE d.country_id = $country_filter 
                             ORDER BY d.name");
} else {
    $districts = $db->query("SELECT d.*, c.name as country_name FROM districts d 
                             JOIN countries c ON d.country_id = c.id 
                             ORDER BY c.name, d.name");
}

$countries = getCountries();

include '../header.php';
?>

<h1>Districts/Regions</h1>
<p><a href="create.php" class="button">+ Add New District</a></p>

<form method="GET" style="margin-bottom: 20px;">
    <label>Filter by Country:</label>
    <select name="country_id" onchange="this.form.submit()">
        <option value="0">All Countries</option>
        <?php foreach($countries as $c): ?>
        <option value="<?php echo $c['id']; ?>" <?php echo $country_filter == $c['id'] ? 'selected' : ''; ?>>
            <?php echo htmlspecialchars($c['name']); ?>
        </option>
        <?php endforeach; ?>
    </select>
</form>

<table>
    <thead>
        <tr><th>ID</th><th>Country</th><th>District</th><th>Actions</th></tr>
    </thead>
    <tbody>
        <?php while($row = $districts->fetch_assoc()): ?>
        <tr>
            <td><?php echo $row['id']; ?></td>
            <td><?php echo htmlspecialchars($row['country_name']); ?></td>
            <td><?php echo htmlspecialchars($row['name']); ?></td>
            <td>
                <a href="edit.php?id=<?php echo $row['id']; ?>">Edit</a> |
                <a href="delete.php?id=<?php echo $row['id']; ?>" onclick="return confirm('Delete this district?')">Delete</a>
            </td>
        </tr>
        <?php endwhile; ?>
    </tbody>
</table>

<?php include '../footer.php'; ?>
EOF

# districts/create.php
cat > admin/districts/create.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$error = '';
$countries = getCountries();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $country_id = intval($_POST['country_id']);
    $name = trim($_POST['name']);
    
    if (empty($name) || $country_id <= 0) {
        $error = 'All fields are required';
    } else {
        $db = getDB();
        $stmt = $db->prepare("INSERT INTO districts (country_id, name) VALUES (?, ?)");
        $stmt->bind_param("is", $country_id, $name);
        
        if ($stmt->execute()) {
            header('Location: index.php?success=created');
            exit();
        } else {
            $error = 'Error: ' . $db->error;
        }
    }
}

include '../header.php';
?>

<h1>Add New District</h1>

<?php if ($error): ?>
    <div class="error"><?php echo $error; ?></div>
<?php endif; ?>

<form method="POST">
    <div class="form-group">
        <label>Country</label>
        <select name="country_id" required>
            <option value="">Select Country</option>
            <?php foreach($countries as $c): ?>
            <option value="<?php echo $c['id']; ?>"><?php echo htmlspecialchars($c['name']); ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="form-group">
        <label>District/Region Name</label>
        <input type="text" name="name" required>
    </div>
    <button type="submit">Save District</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# districts/edit.php
cat > admin/districts/edit.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$db = getDB();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $country_id = intval($_POST['country_id']);
    $name = trim($_POST['name']);
    $stmt = $db->prepare("UPDATE districts SET country_id = ?, name = ? WHERE id = ?");
    $stmt->bind_param("isi", $country_id, $name, $id);
    
    if ($stmt->execute()) {
        header('Location: index.php?success=updated');
        exit();
    }
}

$result = $db->query("SELECT * FROM districts WHERE id = $id");
$district = $result->fetch_assoc();

if (!$district) {
    header('Location: index.php');
    exit();
}

$countries = getCountries();

include '../header.php';
?>

<h1>Edit District</h1>

<form method="POST">
    <div class="form-group">
        <label>Country</label>
        <select name="country_id" required>
            <?php foreach($countries as $c): ?>
            <option value="<?php echo $c['id']; ?>" <?php echo $district['country_id'] == $c['id'] ? 'selected' : ''; ?>>
                <?php echo htmlspecialchars($c['name']); ?>
            </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="form-group">
        <label>District/Region Name</label>
        <input type="text" name="name" value="<?php echo htmlspecialchars($district['name']); ?>" required>
    </div>
    <button type="submit">Update District</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# districts/delete.php
cat > admin/districts/delete.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$db = getDB();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $stmt = $db->prepare("DELETE FROM districts WHERE id = ?");
    $stmt->bind_param("i", $id);
    $stmt->execute();
    header('Location: index.php?success=deleted');
    exit();
}

$result = $db->query("SELECT d.*, c.name as country_name FROM districts d 
                      JOIN countries c ON d.country_id = c.id 
                      WHERE d.id = $id");
$district = $result->fetch_assoc();

if (!$district) {
    header('Location: index.php');
    exit();
}

include '../header.php';
?>

<h1>Delete District</h1>
<p>Are you sure you want to delete: <strong><?php echo htmlspecialchars($district['name']); ?></strong> (<?php echo htmlspecialchars($district['country_name']); ?>)?</p>

<form method="POST">
    <button type="submit" style="background: #c62828;">Yes, Delete</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# =============================================
# CHARACTERS MODULE
# =============================================

# characters/index.php
cat > admin/characters/index.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$db = getDB();
$characters = $db->query("SELECT * FROM characters ORDER BY name");

include '../header.php';
?>

<h1>Characters</h1>
<p><a href="create.php" class="button">+ Add New Character</a></p>

<table>
    <thead>
        <tr><th>ID</th><th>Name</th><th>Type</th><th>Description</th><th>Actions</th></tr>
    </thead>
    <tbody>
        <?php while($row = $characters->fetch_assoc()): ?>
        <tr>
            <td><?php echo $row['id']; ?></td>
            <td><strong><?php echo htmlspecialchars($row['name']); ?></strong></td>
            <td><?php echo htmlspecialchars($row['type']); ?></td>
            <td><?php echo htmlspecialchars(substr($row['description'], 0, 100)); ?></td>
            <td>
                <a href="edit.php?id=<?php echo $row['id']; ?>">Edit</a> |
                <a href="delete.php?id=<?php echo $row['id']; ?>" onclick="return confirm('Delete this character?')">Delete</a>
            </td>
        </tr>
        <?php endwhile; ?>
    </tbody>
</table>

<?php include '../footer.php'; ?>
EOF

# characters/create.php
cat > admin/characters/create.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$error = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name']);
    $type = trim($_POST['type']);
    $description = trim($_POST['description']);
    
    if (empty($name)) {
        $error = 'Character name is required';
    } else {
        $db = getDB();
        $stmt = $db->prepare("INSERT INTO characters (name, type, description) VALUES (?, ?, ?)");
        $stmt->bind_param("sss", $name, $type, $description);
        
        if ($stmt->execute()) {
            header('Location: index.php?success=created');
            exit();
        } else {
            $error = 'Error: ' . $db->error;
        }
    }
}

include '../header.php';
?>

<h1>Add New Character</h1>

<?php if ($error): ?>
    <div class="error"><?php echo $error; ?></div>
<?php endif; ?>

<form method="POST">
    <div class="form-group">
        <label>Character Name</label>
        <input type="text" name="name" required>
    </div>
    <div class="form-group">
        <label>Type (hero, demon, clown, god, etc.)</label>
        <input type="text" name="type">
    </div>
    <div class="form-group">
        <label>Description</label>
        <textarea name="description" rows="4"></textarea>
    </div>
    <button type="submit">Save Character</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# characters/edit.php
cat > admin/characters/edit.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$db = getDB();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name']);
    $type = trim($_POST['type']);
    $description = trim($_POST['description']);
    $stmt = $db->prepare("UPDATE characters SET name = ?, type = ?, description = ? WHERE id = ?");
    $stmt->bind_param("sssi", $name, $type, $description, $id);
    
    if ($stmt->execute()) {
        header('Location: index.php?success=updated');
        exit();
    }
}

$result = $db->query("SELECT * FROM characters WHERE id = $id");
$character = $result->fetch_assoc();

if (!$character) {
    header('Location: index.php');
    exit();
}

include '../header.php';
?>

<h1>Edit Character</h1>

<form method="POST">
    <div class="form-group">
        <label>Character Name</label>
        <input type="text" name="name" value="<?php echo htmlspecialchars($character['name']); ?>" required>
    </div>
    <div class="form-group">
        <label>Type</label>
        <input type="text" name="type" value="<?php echo htmlspecialchars($character['type']); ?>">
    </div>
    <div class="form-group">
        <label>Description</label>
        <textarea name="description" rows="4"><?php echo htmlspecialchars($character['description']); ?></textarea>
    </div>
    <button type="submit">Update Character</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# characters/delete.php
cat > admin/characters/delete.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$db = getDB();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $stmt = $db->prepare("DELETE FROM characters WHERE id = ?");
    $stmt->bind_param("i", $id);
    $stmt->execute();
    header('Location: index.php?success=deleted');
    exit();
}

$result = $db->query("SELECT * FROM characters WHERE id = $id");
$character = $result->fetch_assoc();

if (!$character) {
    header('Location: index.php');
    exit();
}

include '../header.php';
?>

<h1>Delete Character</h1>
<p>Are you sure you want to delete: <strong><?php echo htmlspecialchars($character['name']); ?></strong>?</p>
<p style="color: red;">Warning: Images linked to this character will lose their character association!</p>

<form method="POST">
    <button type="submit" style="background: #c62828;">Yes, Delete</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# =============================================
# COLLECTIONS MODULE
# =============================================

# collections/index.php
cat > admin/collections/index.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$db = getDB();
$collections = $db->query("SELECT c.*, co.name as country_name, d.name as district_name 
                           FROM collections c
                           LEFT JOIN countries co ON c.country_id = co.id
                           LEFT JOIN districts d ON c.district_id = d.id
                           ORDER BY c.crate_number");

include '../header.php';
?>

<h1>Collections (Crates)</h1>
<p><a href="create.php" class="button">+ Add New Crate</a></p>

<table>
    <thead>
        <tr><th>Crate #</th><th>Name</th><th>Country</th><th>District</th><th>Total Puppets</th><th>Actions</th></tr>
    </thead>
    <tbody>
        <?php while($row = $collections->fetch_assoc()): ?>
        <tr>
            <td><strong><?php echo $row['crate_number']; ?></strong></td>
            <td><?php echo htmlspecialchars($row['name']); ?></td>
            <td><?php echo htmlspecialchars($row['country_name']); ?></td>
            <td><?php echo htmlspecialchars($row['district_name']); ?></td>
            <td><?php echo $row['total_puppets']; ?></td>
            <td>
                <a href="edit.php?id=<?php echo $row['id']; ?>">Edit</a> |
                <a href="delete.php?id=<?php echo $row['id']; ?>" onclick="return confirm('Delete this crate and all its images?')">Delete</a>
            </td>
        </tr>
        <?php endwhile; ?>
    </tbody>
</table>

<?php include '../footer.php'; ?>
EOF

# collections/create.php
cat > admin/collections/create.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$error = '';
$countries = getCountries();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name']);
    $crate_number = intval($_POST['crate_number']);
    $country_id = intval($_POST['country_id']);
    $district_id = $_POST['district_id'] ? intval($_POST['district_id']) : null;
    $description = trim($_POST['description']);
    $total_puppets = intval($_POST['total_puppets']);
    
    if (empty($name) || $crate_number <= 0 || $country_id <= 0) {
        $error = 'Name, Crate Number, and Country are required';
    } else {
        $db = getDB();
        $stmt = $db->prepare("INSERT INTO collections (name, crate_number, country_id, district_id, description, total_puppets) VALUES (?, ?, ?, ?, ?, ?)");
        $stmt->bind_param("siissi", $name, $crate_number, $country_id, $district_id, $description, $total_puppets);
        
        if ($stmt->execute()) {
            header('Location: index.php?success=created');
            exit();
        } else {
            $error = 'Error: ' . $db->error;
        }
    }
}

include '../header.php';
?>

<h1>Add New Collection Crate</h1>

<?php if ($error): ?>
    <div class="error"><?php echo $error; ?></div>
<?php endif; ?>

<form method="POST">
    <div class="form-group">
        <label>Crate Name (e.g., Wayang Kedu)</label>
        <input type="text" name="name" required>
    </div>
    <div class="form-group">
        <label>Crate Number (1-15)</label>
        <input type="number" name="crate_number" min="1" max="15" required>
    </div>
    <div class="form-group">
        <label>Country</label>
        <select name="country_id" id="country_id" required>
            <option value="">Select Country</option>
            <?php foreach($countries as $c): ?>
            <option value="<?php echo $c['id']; ?>"><?php echo htmlspecialchars($c['name']); ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="form-group">
        <label>District (Optional)</label>
        <select name="district_id" id="district_id">
            <option value="">Select District</option>
        </select>
    </div>
    <div class="form-group">
        <label>Description</label>
        <textarea name="description" rows="4"></textarea>
    </div>
    <div class="form-group">
        <label>Total Puppets in Crate</label>
        <input type="number" name="total_puppets" min="0" value="0">
    </div>
    <button type="submit">Save Collection</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<script>
document.getElementById('country_id').addEventListener('change', function() {
    var countryId = this.value;
    var districtSelect = document.getElementById('district_id');
    
    if (countryId) {
        fetch('../../includes/ajax_districts.php?country_id=' + countryId)
            .then(response => response.json())
            .then(data => {
                districtSelect.innerHTML = '<option value="">Select District</option>';
                data.forEach(district => {
                    districtSelect.innerHTML += '<option value="' + district.id + '">' + district.name + '</option>';
                });
            });
    } else {
        districtSelect.innerHTML = '<option value="">Select District</option>';
    }
});
</script>

<?php include '../footer.php'; ?>
EOF

# collections/edit.php
cat > admin/collections/edit.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$db = getDB();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name']);
    $crate_number = intval($_POST['crate_number']);
    $country_id = intval($_POST['country_id']);
    $district_id = $_POST['district_id'] ? intval($_POST['district_id']) : null;
    $description = trim($_POST['description']);
    $total_puppets = intval($_POST['total_puppets']);
    
    $stmt = $db->prepare("UPDATE collections SET name = ?, crate_number = ?, country_id = ?, district_id = ?, description = ?, total_puppets = ? WHERE id = ?");
    $stmt->bind_param("siiissi", $name, $crate_number, $country_id, $district_id, $description, $total_puppets, $id);
    
    if ($stmt->execute()) {
        header('Location: index.php?success=updated');
        exit();
    }
}

$result = $db->query("SELECT * FROM collections WHERE id = $id");
$collection = $result->fetch_assoc();

if (!$collection) {
    header('Location: index.php');
    exit();
}

$countries = getCountries();
$districts = getDistricts($collection['country_id']);

include '../header.php';
?>

<h1>Edit Collection Crate</h1>

<form method="POST">
    <div class="form-group">
        <label>Crate Name</label>
        <input type="text" name="name" value="<?php echo htmlspecialchars($collection['name']); ?>" required>
    </div>
    <div class="form-group">
        <label>Crate Number</label>
        <input type="number" name="crate_number" value="<?php echo $collection['crate_number']; ?>" min="1" max="15" required>
    </div>
    <div class="form-group">
        <label>Country</label>
        <select name="country_id" id="country_id" required>
            <?php foreach($countries as $c): ?>
            <option value="<?php echo $c['id']; ?>" <?php echo $collection['country_id'] == $c['id'] ? 'selected' : ''; ?>>
                <?php echo htmlspecialchars($c['name']); ?>
            </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="form-group">
        <label>District</label>
        <select name="district_id" id="district_id">
            <option value="">None</option>
            <?php foreach($districts as $d): ?>
            <option value="<?php echo $d['id']; ?>" <?php echo $collection['district_id'] == $d['id'] ? 'selected' : ''; ?>>
                <?php echo htmlspecialchars($d['name']); ?>
            </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="form-group">
        <label>Description</label>
        <textarea name="description" rows="4"><?php echo htmlspecialchars($collection['description']); ?></textarea>
    </div>
    <div class="form-group">
        <label>Total Puppets</label>
        <input type="number" name="total_puppets" value="<?php echo $collection['total_puppets']; ?>" min="0">
    </div>
    <button type="submit">Update Collection</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# collections/delete.php
cat > admin/collections/delete.php << 'EOF'
<?php
require_once '../session_check.php';
require_once '../../includes/functions.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$db = getDB();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $stmt = $db->prepare("DELETE FROM collections WHERE id = ?");
    $stmt->bind_param("i", $id);
    $stmt->execute();
    header('Location: index.php?success=deleted');
    exit();
}

$result = $db->query("SELECT * FROM collections WHERE id = $id");
$collection = $result->fetch_assoc();

if (!$collection) {
    header('Location: index.php');
    exit();
}

include '../header.php';
?>

<h1>Delete Collection Crate</h1>
<p>Are you sure you want to delete: <strong><?php echo htmlspecialchars($collection['name']); ?></strong> (Crate #<?php echo $collection['crate_number']; ?>)?</p>
<p style="color: red;">Warning: All images in this crate will also be deleted!</p>

<form method="POST">
    <button type="submit" style="background: #c62828;">Yes, Delete</button>
    <a href="index.php" class="button">Cancel</a>
</form>

<?php include '../footer.php'; ?>
EOF

# =============================================
# AJAX helper for districts
# =============================================
cat > includes/ajax_districts.php << 'EOF'
<?php
require_once 'config.php';
require_once 'functions.php';

$country_id = isset($_GET['country_id']) ? intval($_GET['country_id']) : 0;
$districts = getDistricts($country_id);

header('Content-Type: application/json');
echo json_encode($districts);
?>
EOF

echo -e "\n${GREEN}✓ All CRUD files created successfully!${NC}"
echo -e "\n${YELLOW}Visit: https://museum.pondoktingal.com/admin/${NC}"