<?php
echo "<h2>System Requirements Check</h2>";

// Check PHP Version
echo "PHP Version: " . phpversion() . " ... " . (version_compare(phpversion(), '7.4', '>=') ? "<span style='color:green'>OK</span>" : "<span style='color:red'>Update Required</span>") . "<br>";

// Check Libraries
$tcpdf = file_exists(__DIR__ . '/libs/tcpdf/tcpdf.php');
$qrcode = file_exists(__DIR__ . '/libs/phpqrcode/qrlib.php');

echo "TCPDF Library: " . ($tcpdf ? "<span style='color:green'>Found</span>" : "<span style='color:red'>Missing (libs/tcpdf/tcpdf.php)</span>") . "<br>";
echo "PHP QR Code Library: " . ($qrcode ? "<span style='color:green'>Found</span>" : "<span style='color:red'>Missing (libs/phpqrcode/qrlib.php)</span>") . "<br>";

// Check Directories
$dirs = [
    'uploads/templates',
    'uploads/payments'
];

foreach ($dirs as $d) {
    if (!file_exists($d)) {
        if (mkdir($d, 0777, true)) {
            echo "Directory $d: <span style='color:green'>Created</span><br>";
        } else {
            echo "Directory $d: <span style='color:red'>Failed to Create</span><br>";
        }
    } else {
        echo "Directory $d: <span style='color:green'>Exists</span><br>";
    }
}

// Check DB Connection
require_once 'config/db.php';
if (isset($pdo)) {
    echo "Database: <span style='color:green'>Connected</span><br>";
} else {
    echo "Database: <span style='color:red'>Connection Failed</span><br>";
}

echo "<br><a href='index.php'>Go to Home</a>";
?>
