<?php
//koneksi ke database
//mysql_connect("localhost","root","");
//mysql_select_db("db_cake");
 
  $conn = mysqli_connect("localhost", "u8329117", 'abcd1234', "u8329117_spbc");
	
session_start();
if(!isset($_SESSION["login"]) ) {
	header("Location: login.php");
	exit;
}	




$kanwil=$_SESSION["kanwil"]; 


//mengambil data dari tabel
	if($kanwil=="KP")
				{
				    
	 $sql=mysqli_query($conn,"SELECT * FROM spbc order by kanwil,kcu");
     
				}
				else{
	 $sql=mysqli_query($conn,"SELECT * FROM spbc where kanwil='$kanwil' order by kanwil,kcu");	
      			}







//$conn = mysqli_connect("localhost", "root", "", "spbc");

 
 
//mengambil data dari tabel
//$sql=mysqli_query($conn,"SELECT * FROM spbc");

$data = array();
while ($row = mysqli_fetch_assoc($sql)) {
    array_push($data, $row);
}
 
//mengisi judul dan header tabel
$judul = "Data Permohonan TKAD Admin SPBC";
$header = array(
array("label"=>"ID", "length"=>10, "align"=>"L"),
array("label"=>"Nip", "length"=>20, "align"=>"L"),
array("label"=>"Nama", "length"=>30, "align"=>"L"),
array("label"=>"Email", "length"=>30, "align"=>"L"),
array("label"=>"W", "length"=>5, "align"=>"L"),
array("label"=>"Ajukan", "length"=>12, "align"=>"L"),
array("label"=>"Tgl-Aju", "length"=>20, "align"=>"L"),
array("label"=>"Fl", "length"=>5, "align"=>"L"),
array("label"=>"Ok", "length"=>12, "align"=>"L"),
array("label"=>"Tgl-Ok", "length"=>20, "align"=>"L"),
array("label"=>"Alasan", "length"=>18, "align"=>"L"),
array("label"=>"Bgt", "length"=>15, "align"=>"L"),


);
 
//memanggil fpdf
require_once ("fpdf/fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
 
//tampilan Judul Laporan
$pdf->SetFont('Arial','B','16'); //Font Arial, Tebal/Bold, ukuran font 16
$pdf->Cell(0,20, $judul, '0', 1, 'C');
 
//Header Table
$pdf->SetFont('Arial','','10');
$pdf->SetFillColor(139, 69, 19); //warna dalam kolom header
$pdf->SetTextColor(255); //warna tulisan putih
$pdf->SetDrawColor(222, 184, 135); //warna border
foreach ($header as $kolom) {
    $pdf->Cell($kolom['length'], 5, $kolom['label'], 1, '0', $kolom['align'], true);
}
$pdf->Ln();
 
//menampilkan data table
$pdf->SetFillColor(245, 222, 179); //warna dalam kolom data
$pdf->SetTextColor(0); //warna tulisan hitam
$pdf->SetFont('');
$fill=false;
foreach ($data as $baris) {
$i = 0;
foreach ($baris as $cell) {
$pdf->Cell($header[$i]['length'], 5, $cell, 1, '0', $kolom['align'], $fill);
$i++;
}
$fill = !$fill;
$pdf->Ln();
}
 
//output file pdf
$pdf->Output();
?>