<?php

session_start();

require('../lib/dbclass.php');




require('../PhpXlsxGenerator.php') ;


// Filter the excel data
function filterData(&$str)
{
    $str = preg_replace("/\t/", '\\t', $str);
    $str = preg_replace("/\r?\n/", '\\n', $str);

    if (strstr($str, '"')) {
        $str = '"' . str_replace('"', '""', $str) . '"';
    }
}

// Excel file name for download
$fileName = 'User Details.xlsx';

// Column names
$excelData[] = ['Name','Mobile','Username','Password'];

if ($_SESSION['where1']) {
    $where = $_SESSION['where1'];
} else {
    $where = 'tbl_user.id>0';
}




$data = findQuery("select tbl_user.* from tbl_user 
where $where order by tbl_user.id desc ");




if ($data) {
    // Output each row of the data
    foreach ($data as $index => $row) {
        $id = $row['id'];

        $pwd = decrypt($row['password']);

        $lineData = [
                        $row['name'],
                        $row['mobile'],
                         $row['username'],
                        $pwd,
                       ];
        $excelData[] = $lineData;
    }
} else {
    $excelData .= 'No records found...' . "\n";
}

// Export data to excel and download as xlsx file
$xlsx = CodexWorld\PhpXlsxGenerator::fromArray($excelData);
$xlsx->downloadAs($fileName);

exit;
