<?php

session_start();

include "../includes/admin_auth.php";
include "../config/database.php";

if(!isset($_GET['id'])){

    header("Location: plans.php");
    exit();

}

$id=(int)$_GET['id'];

$stmt=$pdo->prepare("SELECT status FROM plans WHERE id=?");

$stmt->execute([$id]);

$plan=$stmt->fetch(PDO::FETCH_ASSOC);

if(!$plan){

    $_SESSION['error']="Plan not found.";

    header("Location: plans.php");

    exit();

}

$newStatus = ($plan['status']=="active") ? "inactive" : "active";

$stmt=$pdo->prepare("UPDATE plans SET status=? WHERE id=?");

$stmt->execute([$newStatus,$id]);

$_SESSION['success']="Plan status updated successfully.";

header("Location: plans.php");

exit();

?>