<?php
// Script to fix the English subject calculation - revert to original calculation

$file_path = 'reports/all_subjects_marksheet.php';
$content = file_get_contents($file_path);

// Fix the English subject combination logic
$pattern = '// Average the marks for proper grading\s+\$count = count\(\$english_results\);\s+if \(\$count > 0\) \{\s+\$combined\[\'cq_marks\'\] = \$combined\[\'cq_marks\'\] \/ \$count;\s+\$combined\[\'mcq_marks\'\] = \$combined\[\'mcq_marks\'\] \/ \$count;\s+\/\/ For Bangla: obtained marks = CQ average \+ MCQ average \(as per user requirement\)\s+\$combined\[\'marks_obtained\'\] = \$combined\[\'cq_marks\'\] \+ \$combined\[\'mcq_marks\'\];\s+\$combined\[\'full_marks\'\] = \$combined\[\'full_marks\'\] \/ \$count;\s+\$combined\[\'pass_marks\'\] = \$combined\[\'pass_marks\'\] \/ \$count;\s+\}';
$replacement = '// Average the marks for proper grading
    $count = count($english_results);
    if ($count > 0) {
        $combined[\'cq_marks\'] = $combined[\'cq_marks\'] / $count;
        $combined[\'mcq_marks\'] = $combined[\'mcq_marks\'] / $count;
        $combined[\'marks_obtained\'] = $combined[\'marks_obtained\'] / $count;
        $combined[\'full_marks\'] = $combined[\'full_marks\'] / $count;
        $combined[\'pass_marks\'] = $combined[\'pass_marks\'] / $count;
    }';

$content = preg_replace("/{$pattern}/s", $replacement, $content);

file_put_contents($file_path, $content);
echo "English calculation fixed successfully!\n";
?>