<?php
include "config.php"; 
require 'vendor/autoload.php';
 
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;


	if(isset($_GET['id'])){
	$pilihtapel = $_GET['id'];
	$aa= mysqli_query($mysqli,"SELECT * FROM tapel where Idtapel='$pilihtapel' ");
	$a1= mysqli_fetch_array($aa);
	$namatapel=$a1['nama'];
	$smt=$a1['semester'];
	$kop1="Laporan Rencana Pembelajaran Guru ".$smt;
	$kop2=" Tahun Pelajaran ".$namatapel;
	$namakop=$kop1.$kop2;
 
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

$sheet->setCellValue('A1', '$namakop'); 
$sheet->setCellValue('A3', 'No');
$sheet->setCellValue('B3', 'ID RPP');
$sheet->setCellValue('C3', 'Nama Guru');
$sheet->setCellValue('D3', 'Mata Pelajaran');
$sheet->setCellValue('E3', 'Kelas');
$sheet->setCellValue('F3', 'Tanggal Kirim');
$sheet->setCellValue('G3', 'Tanggal Verifikasi');
$sheet->setCellValue('H3', 'Catatan');
$sheet->setCellValue('I3', 'Status');
$sheet->setCellValue('J3', 'Kalender Akademik');
$sheet->setCellValue('K3', 'Rincian Pekan Efektif');
$sheet->setCellValue('L3', 'Analisis Alokasi Waktu');
$sheet->setCellValue('K3', 'Capaian Pembelajaran/Layanan');
$sheet->setCellValue('N3', 'TP & ATP');
$sheet->setCellValue('O3', 'Prota');
$sheet->setCellValue('P3', 'Promes');
$sheet->setCellValue('Q3', 'KKTP');
$sheet->setCellValue('R3', 'Modul Ajar / RPP ');

$data = mysqli_query($mysqli, "SELECT drpp.Idrpp kodeid,tapel.nama nmtapel,tapel.semester, user.madrasah, user.nama nmguru,mapel.nama nmmapel, kelas.nama nmkelas,drpp.kaldik,drpp.rpe,drpp.alokasiwaktu,drpp.cp,drpp.atp,drpp.prota,drpp.promes, drpp.kktp,drpp.modulrpp,drpp.tglkirim, drpp.tglvalidasi, drpp.catatan,drpp.validasi FROM drpp,tapel,user,mapel,kelas WHERE drpp.Iduser=user.Iduser AND drpp.Idtapel=tapel.Idtapel AND drpp.Idmapel=mapel.Idmapel AND drpp.Idkelas=kelas.Idkelas AND drpp.Idtapel='$pilihtapel' ORDER BY drpp.Idrpp ASC");
$i = 4;
$no = 1;
while($d = mysqli_fetch_array($data))
{
    $sheet->setCellValue('A'.$i, $no++);
    $sheet->setCellValue('B'.$i, $d['kodeid']);
    $sheet->setCellValue('C'.$i, $d['nmguru']);
    $sheet->setCellValue('D'.$i, $d['nmmapel']);
    $sheet->setCellValue('E'.$i, $d['nmkelas']);    
    $sheet->setCellValue('F'.$i, $d['tglkirim']);  
	$sheet->setCellValue('G'.$i, $d['tglvalidasi']);  
	$sheet->setCellValue('H'.$i, $d['catatan']);
    $sheet->setCellValue('I'.$i, $d['validasi']);
    $sheet->setCellValue('J'.$i, $d['kaldik']);
    $sheet->setCellValue('K'.$i, $d['rpe']);    
    $sheet->setCellValue('L'.$i, $d['alokasiwaktu']);  
	$sheet->setCellValue('M'.$i, $d['cp']);  
	$sheet->setCellValue('N'.$i, $d['atp']);
    $sheet->setCellValue('O'.$i, $d['prota']);
    $sheet->setCellValue('P'.$i, $d['promes']);
    $sheet->setCellValue('Q'.$i, $d['kktp']);
	$sheet->setCellValue('R'.$i, $d['modulrpp']); 
    $i++;
}
 
$writer = new Xlsx($spreadsheet);
$writer->save('Laporan RPP.xlsx');
echo "<script>window.location = 'Laporan RPP.xlsx'</script>";
} 
?>