Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require ('pdf/fpdf.php');
- include 'config.php';
- $db = new PDO('mysql:host=localhost;dbname=sistem_rmt','root','');
- class myPDF extends FPDF
- {
- function header()
- {
- $kelas = '';
- if($_POST['kelas'] !="Kelas")
- {
- $kelas = $_POST['kelas'];
- }
- $this->image('logo.png',10,6);
- $this->SetFont('Arial','B',14);
- $this->Cell(200,5,'SEKOLAH KEBANGSAAN TAMAN PERLING',0,0,'C');
- $this->Ln(7);
- $this->SetFont('Arial','B',13);
- $this->Cell(200,5,'Transaksi Pengambilan Makanan',0,0,'C');
- $this->Ln(5);
- $this->SetFont('Times','',12);
- $this->Cell(100,10,'Kelas -',0,0,'R');
- $this->Cell(100,10,$kelas,0,0,'L');
- $this->Ln(7);
- $this->SetFont('Times','',12);
- $this->Cell(65,10,'Tarikh Dari -',0,0,'R');
- if($_POST['tarikhmula'])
- {
- $mula = $_POST['tarikhmula'];
- $this->Cell(65,10,date("d F Y", strtotime(strip_tags($mula))),0,0,'L');
- }
- else
- {
- $mula ="";
- $this->Cell(65,10,'',0,0,'L');
- }
- $this->Cell(1,10,'Tarikh Hingga -',0,0,'R');
- if($_POST['tarikhtamat'])
- {
- $akhir = $_POST['tarikhtamat'];
- $this->Cell(65,10,date("d F Y", strtotime(strip_tags($akhir))),0,0,'L');
- }
- else
- {
- $akhir ="";
- $this->Cell(65,10,'',0,0,'L');
- }
- $this->Ln(10);
- }
- function footer()
- {
- $this->SetY(-15);
- $this->SetFont('Arial','',8);
- $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
- }
- function headerTable(){
- $this->SetFont('Times','B',12);
- $this->Cell(15,10,'No',1,0,'C');
- $this->Cell(90,10,'Nama',1,0,'C');
- $this->Cell(30,10,'Kelas',1,0,'C');
- $this->Cell(55,10,'Timestamp',1,0,'C');
- $this->Ln();
- }
- function viewTable($db){
- $this->SetFont('Times','',12);
- $mula = $_POST['tarikhmula'];
- $akhir = $_POST['tarikhtamat'];
- $kelas = '';
- if($_POST['kelas'] !="Kelas")
- {
- $kelas = $_POST['kelas'];
- }
- if(empty($_POST["tarikhmula"]) && empty($_POST["tarikhtamat"]) && $kelas == '')
- {
- $sql = 'select id_k,nama,kelas_murid, timestamp from kehadiran a join murid b where a.murid_id=b.id';
- // $sql = "select id_k,nama,kelas_murid,timestamp from kehadiran a join murid b on a.murid_id=b.id where b.kelas_murid='".$_POST['kelas']."'";
- $stmt = $db->query($sql);
- while($data = $stmt->fetch(PDO::FETCH_OBJ))
- {
- $this->Cell(15,10,$data->id_k,1,0,'C');
- $this->Cell(90,10,$data->nama,1,0,'L');
- $this->Cell(30,10,$data->kelas_murid,1,0,'C');
- $this->Cell(55,10,date("d F Y g:i A", strtotime(strip_tags($data->timestamp))),1,0,'C');
- $this->Ln();
- }
- }
- else if(isset($_POST["tarikhmula"]) && isset($_POST["tarikhtamat"]) && $kelas =='')
- {
- $sql = "select id_k,nama,kelas_murid,timestamp from kehadiran a join murid b on a.murid_id=b.id where a.timestamp>='".$mula."' and a.timestamp<='".$akhir."'";
- $stmt = $db->query($sql);
- while($data = $stmt->fetch(PDO::FETCH_OBJ))
- {
- $this->Cell(15,10,$data->id_k,1,0,'C');
- $this->Cell(90,10,$data->nama,1,0,'L');
- $this->Cell(30,10,$data->kelas_murid,1,0,'C');
- $this->Cell(55,10,date("d F Y g:i A", strtotime(strip_tags($data->timestamp))),1,0,'C');
- $this->Ln();
- }
- }
- else if(empty($_POST["tarikhmula"]) && empty($_POST["tarikhtamat"]) && $kelas != '')
- {
- $sql = "select id_k,nama,kelas_murid,timestamp from kehadiran a join murid b on a.murid_id=b.id where b.kelas_murid='".$_POST['kelas']."'";
- $stmt = $db->query($sql);
- while($data = $stmt->fetch(PDO::FETCH_OBJ))
- {
- $this->Cell(15,10,$data->id_k,1,0,'C');
- $this->Cell(90,10,$data->nama,1,0,'L');
- $this->Cell(30,10,$data->kelas_murid,1,0,'C');
- $this->Cell(55,10,date("d F Y g:i A", strtotime(strip_tags($data->timestamp))),1,0,'C');
- $this->Ln();
- }
- }
- else
- {
- $sql = "select id_k,nama,kelas_murid,timestamp from kehadiran a join murid b ON a.murid_id=b.id where b.kelas_murid='".$_POST['kelas']."' and timestamp>='".$mula."' and timestamp<='".$akhir."'";
- $stmt = $db->query($sql);
- while($data = $stmt->fetch(PDO::FETCH_OBJ))
- {
- $this->Cell(15,10,$data->id_k,1,0,'C');
- $this->Cell(90,10,$data->nama,1,0,'L');
- $this->Cell(30,10,$data->kelas_murid,1,0,'C');
- $this->Cell(55,10,date("d F Y g:i A", strtotime(strip_tags($data->timestamp))),1,0,'C');
- $this->Ln();
- }
- }
- }
- }
- $pdf = new myPDF();
- $pdf->AliasNbPages();
- $pdf->AddPage('P','A4',0);
- $pdf->headerTable();
- $pdf->viewTable($db);
- $pdf->Output();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement