<?php
/**
 * Simple standalone test for S3-4 functionality
 * This will test the exact queries that should work
 */

// This simulates what the S3-4 examinations table should display
echo "<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Simple S3-4 Test</title>
    <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css' rel='stylesheet'>
    <style>
        .subject-row { border-bottom: 1px solid #eee; padding: 10px 0; }
        .compulsory { background-color: #e3f2fd; }
        .optional { background-color: #e8f5e8; }
    </style>
</head>
<body>
<div class='container mt-4'>
    <h1>S3-4 Examinations Table Test</h1>
    
    <div class='alert alert-info'>
        <h5>Test Parameters:</h5>
        <ul>
            <li><strong>Student ADM:</strong> SMK205323</li>
            <li><strong>Class ID:</strong> 61</li>
            <li><strong>Stream ID:</strong> 41</li>
            <li><strong>School ID:</strong> 2</li>
            <li><strong>Academic Year:</strong> 2025</li>
            <li><strong>Term:</strong> TERM 3</li>
        </ul>
    </div>

    <div class='alert alert-warning'>
        <h5>Expected Results:</h5>
        <p>Should display exactly <strong>9 subjects</strong> total:</p>
        <ul>
            <li><strong>7 Compulsory Subjects:</strong> Physics, Biology, Chemistry, Mathematics, History, Geography, English</li>
            <li><strong>2 Optional Subjects:</strong> Agriculture, Entrepreneurship</li>
        </ul>
    </div>

    <h3>Simulated Examinations Table Output</h3>
    
    <table class='table table-bordered'>
        <thead class='table-dark'>
            <tr>
                <th>SUBJECTS</th>
                <th>PAPER</th>
                <th>MARKS</th>
                <th>GRADE</th>
                <th>COMMENTS</th>
                <th>TEACHER</th>
            </tr>
        </thead>
        <tbody>";

# Simulate the compulsory subjects that should be fetched
$expected_compulsory = [
    ['subject_name' => 'Biology', 'subject_category' => 'Compulsory'],
    ['subject_name' => 'Chemistry', 'subject_category' => 'Compulsory'],
    ['subject_name' => 'English', 'subject_category' => 'Compulsory'],
    ['subject_name' => 'Geography', 'subject_category' => 'Compulsory'],
    ['subject_name' => 'History', 'subject_category' => 'Compulsory'],
    ['subject_name' => 'Mathematics', 'subject_category' => 'Compulsory'],
    ['subject_name' => 'Physics', 'subject_category' => 'Compulsory']
];

# Simulate the optional subjects that should be fetched
$expected_optional = [
    ['subject_name' => 'Agriculture', 'subject_category' => 'Optional'],
    ['subject_name' => 'Entrepreneurship', 'subject_category' => 'Optional']
];

$subject_count = 0;

# Display compulsory subjects
foreach ($expected_compulsory as $subject) {
    $subject_count++;
    echo "<tr class='subject-row compulsory'>";
    echo "<td><strong>" . $subject['subject_name'] . "</strong></td>";
    echo "<td style='color: #999;'>-</td>";
    echo "<td>75%</td>"; // Simulated mark
    echo "<td><span class='badge bg-primary'>B</span></td>";
    echo "<td>Good work</td>";
    echo "<td>Teacher " . $subject_count . "</td>";
    echo "</tr>";
}

# Display optional subjects
foreach ($expected_optional as $subject) {
    $subject_count++;
    echo "<tr class='subject-row optional'>";
    echo "<td><strong>" . $subject['subject_name'] . "</strong></td>";
    echo "<td style='color: #999;'>-</td>";
    echo "<td>78%</td>"; // Simulated mark
    echo "<td><span class='badge bg-success'>B+</span></td>";
    echo "<td>Good effort</td>";
    echo "<td>Teacher " . $subject_count . "</td>";
    echo "</tr>";
}

echo "        </tbody>
        <tfoot>
            <tr class='table-info'>
                <td colspan='6'><strong>Total Subjects: $subject_count</strong> (7 Compulsory + 2 Optional)</td>
            </tr>
        </tfoot>
    </table>

    <div class='alert alert-success'>
        <h5>✅ This is what the S3-4 examinations table SHOULD display</h5>
        <p><strong>If you're not seeing this in the actual report card, then:</strong></p>
        <ul>
            <li>The S3-4 parameters might not be detected correctly</li>
            <li>There could be a PHP syntax error</li>
            <li>The database queries might not be returning the expected data</li>
            <li>Browser cache might be showing old version</li>
        </ul>
    </div>

    <div class='alert alert-info'>
        <h5>Next Steps to Debug:</h5>
        <ol>
            <li><strong>Check URL:</strong> Make sure you're using the exact URL with all S3-4 parameters</li>
            <li><strong>Clear Cache:</strong> Try hard refresh (Ctrl+F5) or clear browser cache</li>
            <li><strong>Check PHP Errors:</strong> Look for any PHP error messages in the browser</li>
            <li><strong>Test Database:</strong> Verify the database contains the expected data</li>
        </ol>
    </div>

    <div class='card'>
        <div class='card-header'>
            <h5>URL to Test</h5>
        </div>
        <div class='card-body'>
            <code>admin_exam_grade_reports.php?student_adm=SMK205323&s34_class_id=61&s34_stream_id=41&s34_school_id=2&s34_academic_year=2025&s34_term=TERM%203</code>
            <br><br>
            <a href='?student_adm=SMK205323&s34_class_id=61&s34_stream_id=41&s34_school_id=2&s34_academic_year=2025&s34_term=TERM%203' class='btn btn-primary'>Test This URL</a>
        </div>
    </div>

</div>
</body>
</html>";
?>
