<?php
session_start();
include '../db_config.php';
include '../functions.php';

check_login();
check_role('admin');

if (isset($_GET['id']) && isset($_GET['act'])) {
    $id = intval($_GET['id']);
    $action = $_GET['act'];
    
    // Determine new status
    $status = '';
    if ($action === 'approve') {
        $status = 'Approved';
    } elseif ($action === 'reject') {
        $status = 'Rejected';
    } else {
        // Invalid action
        header("Location: manage_employers.php?error=invalid_action");
        exit();
    }

    // Update status
    $stmt = $conn->prepare("UPDATE employer_details SET status = ? WHERE user_id = ?");
    if ($stmt) {
        $stmt->bind_param("si", $status, $id);
        if ($stmt->execute()) {
            $msg = ($status == 'Approved') ? "Employer approved successfully." : "Employer rejected.";
            header("Location: manage_employers.php?msg=" . urlencode($msg));
        } else {
             header("Location: manage_employers.php?error=update_failed");
        }
        $stmt->close();
    } else {
         header("Location: manage_employers.php?error=stmt_error");
    }
} else {
    // Missing parameters
    header("Location: manage_employers.php");
}
exit();
?>
