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

function addColumnIfNotExists($conn, $table, $column, $definition) {
    $check = $conn->query("SHOW COLUMNS FROM $table LIKE '$column'");
    if ($check->num_rows == 0) {
        $sql = "ALTER TABLE $table ADD COLUMN $column $definition";
        if ($conn->query($sql) === TRUE) {
            echo "Column '$column' added successfully.<br>";
        } else {
            echo "Error adding column '$column': " . $conn->error . "<br>";
        }
    } else {
        echo "Column '$column' already exists.<br>";
    }
}

// Add 'status' column
addColumnIfNotExists($conn, 'job_applications', 'status', "ENUM('active', 'bin') DEFAULT 'active'");

// Add 'is_favorite' column
addColumnIfNotExists($conn, 'job_applications', 'is_favorite', "TINYINT(1) DEFAULT 0");

echo "Repair complete. Please refresh your admin page.";
?>
