<?php
require "../../config/koneksi.php";
require "../../vendor/autoload.php";
require "../../config/function.php";

use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

 
  $level=$_GET['level'];


$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()->setCreator('Edi Sukarna')
->setLastModifiedBy('Edi Sukarna')
->setTitle('Office 2007 XLSX')
->setSubject('Office 2007 XLSX')
->setDescription('Test document for Office 2007 XLSX.')
->setKeywords('office 2007 openxml php')
->setCategory('Test result file');




$spreadsheet->setActiveSheetIndex(0)
->setCellValue('A1', "No")
->setCellValue('B1', "NAMA")
->setCellValue('C1', "NIS")
->setCellValue('D1', "NISN") 
->setCellValue('E1', "NO PESERTA")
->setCellValue('F1', "KELAS")
->setCellValue('G1', "TEMPAT LAHIR")
->setCellValue('H1', "TANGGAL LAHIR") 
->setCellValue('I1', "JENIS KELAMIN") 
->setCellValue('J1', "JURUSAN")
->setCellValue('K1', "KETERANGAN")

; 

$i=2; 
$no=1; 
$sql = mysqli_query($koneksi, "SELECT * FROM siswa WHERE level='$level'");

while($row = mysqli_fetch_array($sql)){ 
$spreadsheet->setActiveSheetIndex(0)
	->setCellValue('A'.$i, $no)
	->setCellValue('B'.$i, $row['nama'])
	->setCellValue('C'.$i, $row['nis'])
	->setCellValue('D'.$i, $row['nisn'])
	->setCellValue('E'.$i, $row['no_peserta'])
	->setCellValue('F'.$i, $row['id_kelas'])
	->setCellValue('G'.$i, $row['tempat_lahir'])
	->setCellValue('H'.$i, $row['tgl_lahir'])
	->setCellValue('I'.$i, $row['jenis_kelamin'])
	->setCellValue('J'.$i, $row['idpk'])
	->setCellValue('K'.$i, $row['keterangan'])
	;
	
	$i++; $no++;
}
$spreadsheet->setActiveSheetIndex(0)
->setCellValue('M2', "KETERANGAN DIISI DENGAN ANGKA")
->setCellValue('M3', "0 TIDAK LULUS")
->setCellValue('M4', "1 LULUS")
->setCellValue('M5', "2 LULUS BERSYARAT") 

; 
$spreadsheet->getActiveSheet()->getColumnDimension('A')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(30); 
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12); 
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(12); 
$spreadsheet->getActiveSheet()->getColumnDimension('E')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(10); 
$spreadsheet->getActiveSheet()->getColumnDimension('G')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('H')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('I')->setWidth(14); 
$spreadsheet->getActiveSheet()->getColumnDimension('J')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('K')->setWidth(12); 
$spreadsheet->getActiveSheet()->getColumnDimension('L')->setWidth(4); 

$spreadsheet->getActiveSheet()->setTitle('DATA_SISWA');

$spreadsheet->setActiveSheetIndex(0);


header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

header("Content-Disposition: attachment; filename=UPDATE SISWA SKL.xlsx");
header('Cache-Control: max-age=0');

header('Cache-Control: max-age=1');


header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 
header('Cache-Control: cache, must-revalidate'); 
header('Pragma: public');

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

?>
