<?php
// Test that payment system has been successfully removed
echo "Payment System Removal Verification Test\n";
echo "=====================================\n\n";

// Test 1: Check that payment files no longer exist
$payment_files = [
    'fees/payment_failed.php',
    'fees/select_fees.php',
    'fees/student_payment.php',
    'fees/uddoktapay_cancel.php',
    'fees/uddoktapay_payment_success.php',
    'fees/uddoktapay_success.php',
    'includes/uddoktapay.php',
    'config/uddoktapay.php',
    'admin/uddoktapay_settings.php'
];

echo "1. Checking for removed payment files:\n";
$all_removed = true;
foreach ($payment_files as $file) {
    if (file_exists($file)) {
        echo "   ✗ $file still exists\n";
        $all_removed = false;
    } else {
        echo "   ✓ $file successfully removed\n";
    }
}

echo "\n";

// Test 2: Check that sidebar no longer contains payment links
echo "2. Checking sidebar layout for payment links:\n";
$sidebar_content = file_get_contents('includes/sidebar_layout.php');
if (strpos($sidebar_content, 'student_payment') === false && 
    strpos($sidebar_content, 'select_fees') === false) {
    echo "   ✓ Payment links removed from sidebar\n";
} else {
    echo "   ✗ Payment links still found in sidebar\n";
    $all_removed = false;
}

echo "\n";

// Test 3: Check that my_fees.php no longer references payment files
echo "3. Checking my_fees.php for payment references:\n";
$my_fees_content = file_get_contents('fees/my_fees.php');
if (strpos($my_fees_content, 'student_payment.php') === false && 
    strpos($my_fees_content, 'select_fees.php') === false &&
    strpos($my_fees_content, 'uddoktapay') === false) {
    echo "   ✓ Payment references removed from my_fees.php\n";
} else {
    echo "   ✗ Payment references still found in my_fees.php\n";
    $all_removed = false;
}

echo "\n";

// Test 4: Check that database tables still exist (data preservation)
echo "4. Checking database tables for data preservation:\n";
require_once 'config/database.php';

try {
    // Check if fees table exists
    $stmt = $pdo->query("SHOW TABLES LIKE 'fees'");
    $fees_table = $stmt->fetchAll();
    
    if (count($fees_table) > 0) {
        echo "   ✓ Fees table preserved\n";
    } else {
        echo "   ✗ Fees table missing\n";
        $all_removed = false;
    }
    
    // Check if fee_payments table exists
    $stmt = $pdo->query("SHOW TABLES LIKE 'fee_payments'");
    $payments_table = $stmt->fetchAll();
    
    if (count($payments_table) > 0) {
        echo "   ✓ Fee payments table preserved\n";
    } else {
        echo "   ✗ Fee payments table missing\n";
        $all_removed = false;
    }
} catch (Exception $e) {
    echo "   ✗ Database connection error: " . $e->getMessage() . "\n";
    $all_removed = false;
}

echo "\n";

// Final result
echo "Removal Verification Results:\n";
echo "============================\n";
if ($all_removed) {
    echo "🎉 SUCCESS: All payment system files have been successfully removed!\n";
    echo "   - Payment functionality disabled\n";
    echo "   - Historical data preserved\n";
    echo "   - No broken references\n";
    echo "   - System fully functional\n";
} else {
    echo "⚠ WARNING: Some payment system components may still exist.\n";
    echo "   Please review the removal process.\n";
}

echo "\nTest completed.\n";
?>