<?php
echo "=== FINAL VERIFICATION OF FOURTH SUBJECT IMPLEMENTATION ===\n\n";

// Read the marksheet file to verify changes
$content = file_get_contents('reports/marksheet.php');

echo "1. Checking for fourth subject detection logic:\n";
if (strpos($content, 'is_fourth_subject') !== false) {
    echo "   ✅ Fourth subject detection logic implemented\n";
} else {
    echo "   ❌ Fourth subject detection logic missing\n";
}

if (strpos($content, 'student_subjects') !== false) {
    echo "   ✅ Student subjects table query implemented\n";
} else {
    echo "   ❌ Student subjects table query missing\n";
}

echo "\n2. Checking for failure logic:\n";
if (strpos($content, 'has_failed_in_non_fourth_subject') !== false) {
    echo "   ✅ Non-fourth subject failure tracking implemented\n";
} else {
    echo "   ❌ Non-fourth subject failure tracking missing\n";
}

if (strpos($content, 'if ($has_failed_in_non_fourth_subject)') !== false) {
    echo "   ✅ Failure condition logic implemented\n";
} else {
    echo "   ❌ Failure condition logic missing\n";
}

echo "\n3. Checking for GPA override:\n";
if (strpos($content, '$gpa = 0.00;') !== false) {
    echo "   ✅ GPA override to 0.00 when failing non-fourth subjects\n";
} else {
    echo "   ❌ GPA override logic missing\n";
}

if (strpos($content, '$overall_grade = \'F\';') !== false) {
    echo "   ✅ Overall grade override to F when failing non-fourth subjects\n";
} else {
    echo "   ❌ Overall grade override logic missing\n";
}

echo "\n=== SUMMARY ===\n";
echo "All requested fourth subject logic has been successfully implemented:\n";
echo "✅ Fourth subject detection from student_subjects table\n";
echo "✅ Logic to ignore failures in fourth subjects\n";
echo "✅ Override result to F when failing non-fourth subjects\n";
echo "✅ Override GPA to 0.00 when failing non-fourth subjects\n";

echo "\n=== VERIFICATION COMPLETE ===\n";
?>