<?php

/**

 * Generate CSV Templates

 */



define('MIGRATION_ACCESS', true);



$type = $_GET['type'] ?? 'students';



switch ($type) {

    case 'students':

        $headers = ['student_id', 'first_name', 'last_name', 'class', 'section', 'parent_name', 'phone', 'email', 'address', 'date_of_birth', 'gender'];

        $sample = ['STU001', 'John', 'Doe', 'Class 4', 'A', 'John Doe Snr', '0244123456', 'john@email.com', 'Accra', '2015-05-10', 'Male'];

        $filename = 'students_template.csv';

        break;

        

    case 'staff':

        $headers = ['staff_id', 'full_name', 'qualification', 'class_taught', 'phone', 'email', 'salary', 'date_of_employment'];

        $sample = ['STF001', 'John Mensah', 'B.Ed Mathematics', 'Class 4', '0244123456', 'john.mensah@email.com', '2500.00', '2020-09-01'];

        $filename = 'staff_template.csv';

        break;

        

    case 'fees':

        $headers = ['class_name', 'fee_type', 'amount', 'due_date', 'academic_year'];

        $sample = ['Class 4', 'School Fee', '500.00', '2026-03-30', '2025-2026'];

        $filename = 'fees_template.csv';

        break;

        

    case 'payments':

        $headers = ['student_id', 'fee_type', 'amount_paid', 'payment_date', 'payment_method', 'transaction_id', 'notes'];

        $sample = ['STU001', 'School Fee', '500.00', '2026-03-15', 'cash', '', ''];

        $filename = 'payments_template.csv';

        break;

        

    case 'subjects':

        $headers = ['subject_name', 'subject_code', 'active', 'class_name', 'is_compulsory'];

        $sample = ['English', 'ENG', 'yes', 'Class 4', 'yes'];

        $filename = 'subjects_template.csv';

        break;

        

    default:

        die('Invalid template type');

}



header('Content-Type: text/csv');

header('Content-Disposition: attachment; filename="' . $filename . '"');



$output = fopen('php://output', 'w');

fputcsv($output, $headers);

fputcsv($output, $sample);

fclose($output);

?>