<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
echo "POST:";
$_SESSION['report']; 
/*$export_data = array(
      array(
                'Recipet Date' => '2019-05-27',
                'REg No' => 'FSFSDF',
                'chassis no' => '645654',
                'Views' => 'Success',
            ),
      array(
                'Recipet Date' => '2019-05-27',
                'REg No' => 'SFSDFSDF',
                'chassis no' => '12345',
                'Views' => 'Regjected',
            ),
      
    );*/
	
	$fileName = "rto_data_report" . rand(1,100) . ".xls";
 
if ($_SESSION['report']) {
    function filterData(&$str) {
        $str = preg_replace("/\t/", "\\t", $str);
        $str = preg_replace("/\r?\n/", "\\n", $str);
        if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
    }
 
    // headers for download
    header("Content-Disposition: attachment; filename=\"$fileName\"");
    header("Content-Type: application/vnd.ms-excel");
 
    $flag = false;
    foreach($_SESSION['report'] as $row) {
        if(!$flag) {
            // display column names as first row
            echo implode("\t", array_keys($row)) . "\n";
            $flag = true;
        }
        // filter data
        array_walk($row, 'filterData');
        echo implode("\t", array_values($row)) . "\n";
    }
    exit;
}