<?php
// Database connection
$conn = new mysqli('localhost', 'root', '', 'activation_system');

// Check for connection error
if ($conn->connect_error) {
    die(json_encode(['status' => 'error', 'message' => 'Database connection failed.']));
}

// Get Institution ID from the request
$institution_id = $_GET['institution_id'];

// Validate Institution ID
$sql = "SELECT * FROM licenses WHERE institution_id = '$institution_id'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    
    // Check if the license is active and not expired
    if ($row['status'] == 'active' && strtotime($row['expiry_date']) >= time()) {
        echo json_encode(['status' => 'success', 'message' => 'License is valid.']);
    } else {
        echo json_encode(['status' => 'error', 'message' => 'License expired or inactive.']);
    }
} else {
    echo json_encode(['status' => 'error', 'message' => 'Invalid Institution ID.']);
}

$conn->close();
?>
