<?php
// Script to fix both combineBanglaSubjects and combineEnglishSubjects functions in bulk_print_marksheets.php
$file_path = 'reports/bulk_print_marksheets.php';
$content = file_get_contents($file_path);

// Fix 1: Comment out the averaging of full_marks and pass_marks in combineBanglaSubjects function
$pattern1 = '/(\/\/ For combined subjects, full_marks should be the sum of all individual subjects\' full marks\s*\n\s*\/\/ pass_marks should be the sum of all individual subjects\' pass marks\s*\n\s*\/\/ But we keep the current logic for backward compatibility with existing data\s*\n\s*return \$combined;)/s';

$replacement1 = '// For combined subjects, full_marks should represent the total marks for all combined subjects
        // not an average. This ensures the total marks calculation is correct.
        // But we keep the current logic for backward compatibility with existing data        
        return $combined;';

$content = preg_replace($pattern1, $replacement1, $content);

// Fix 2: Make sure the averaging of full_marks and pass_marks is commented out in combineEnglishSubjects function
$pattern2 = '/(            \/\* For combined subjects, full_marks should represent the total marks for all combined subjects\s*\n\s*\/\/ not an average\. This ensures the total marks calculation is correct\.\s*\n\s*\/\/ \$combined\[\'full_marks\'\] = \$combined\[\'full_marks\'\] \/ \$count;\s*\n\s*\/\/ \$combined\[\'pass_marks\'\] = \$combined\[\'pass_marks\'\] \/ \$count;\s*\n\s*\*\/\s*\n\s*\n\s*return \$combined;)/s';

$replacement2 = '            // For combined subjects, full_marks should represent the total marks for all combined subjects
            // not an average. This ensures the total marks calculation is correct.
            // $combined[\'full_marks\'] = $combined[\'full_marks\'] / $count;
            // $combined[\'pass_marks\'] = $combined[\'pass_marks\'] / $count;

        return $combined;';

$content = preg_replace($pattern2, $replacement2, $content);

// Write the fixed content back to the file
file_put_contents($file_path, $content);

echo "Fix v2 applied successfully!\n";
?>