<?php
// check_license.php
session_start();

// Database connection
$conn = new mysqli("localhost", "root", "", "school_checkin");
if ($conn->connect_error) {
    die("Database connection failed: " . $conn->connect_error);
}

// Set school code (you can also get this dynamically)
$school_code = "SDAESI"; // Palitan kung unique per school

// Check if license exists and is active
$sql = "SELECT * FROM license_keys WHERE school_code = '$school_code' AND is_active = 1 LIMIT 1";
$result = $conn->query($sql);

if (!$result || $result->num_rows == 0) {
    die("<h2 style='color:red;'>❌ License not found or not active.</h2>");
}

$license = $result->fetch_assoc();
$today = date('Y-m-d');

// Check expiration
if ($today > $license['valid_until']) {
    die("<h2 style='color:orange;'>🔒 License expired on {$license['valid_until']}. Please renew.</h2>");
}

// If valid, proceed
// Optional: Store license info in session if needed
$_SESSION['school_code'] = $school_code;
?>
