<?php session_start();
include_once (__DIR__ . "/../../functions/koneksi.php");
include_once (__DIR__ . "/../../functions/access.php");
include_once (__DIR__ . "/../../../functions/indonesian_date.php");

require_once(__DIR__ ."/vendor/autoload.php"); 
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
//include_once (__DIR__ . "/../../functions/php_functions.php");

$helper = new Sample();
if ($helper->isCli()) {
    $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
    return;
}
$laporan  	= (isset($_POST["laporan"]) ? $_POST["laporan"] : null);
$fileName 	= str_replace(".php", ".xlsx", date("d-M-Y_hms_").$laporan);
$sheetTitle = str_replace(".php", "", $laporan);
$date_start = (isset($_POST["data_start"]) ? $_POST["data_start"] : null);
$date_end 	= (isset($_POST["data_end"]) ? $_POST["data_end"] : null);
$remark 	= (isset($_POST["remark"]) ? $_POST["remark"] : null);
$pic 		= (isset($_POST["pic"]) ? $_POST["pic"] : null);
$_transaksi = (isset($_POST["_transaksi"]) ? $_POST["_transaksi"] : null);
$row1 		= (isset($_POST["row1"]) ? $_POST["row1"] : null);
$row2 		= (isset($_POST["row2"]) ? $_POST["row2"] : null);
$row3 		= (isset($_POST["row3"]) ? $_POST["row3"] : null);

include_once (__DIR__ . "/component.php");

$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()
	->setTitle('Trade Expo Indonesia')
	->setSubject('TEI2019')
	->setDescription('Laporan Kontak Dagang')
	->setCreator('Trade Expo Indonesia')
	->setLastModifiedBy('Trade Expo Indonesia');

// Add some data
$spreadsheet-> setActiveSheetIndex(0);
$activeSheet = $spreadsheet->getActiveSheet();

$negara_or_produk = array();
$total_transaksi  = $total_persen = 100;; 
$total_lainnya    = $counter = 0;

$function_name = "__".$sheetTitle;
$function_name ($total_transaksi, $negara_or_produk);

$function_name = "__".$sheetTitle."_listIT";
$function_name ($total_transaksi, $negara_or_produk, $row1, $row2, $row3, $jn_trans_name);

// Rename worksheet
$spreadsheet->getActiveSheet()->setTitle("$sheetTitle");

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$spreadsheet->setActiveSheetIndex(0);

/** **/
// Redirect output to a client’s web browser (Xlsx)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$fileName.'"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0

$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
exit;?>