Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. <?php
  2. require ('pdf/fpdf.php');
  3. include 'config.php';
  4. $db = new PDO('mysql:host=localhost;dbname=sistem_rmt','root','');
  5.  
  6. class myPDF extends FPDF
  7. {
  8. function header()
  9. {
  10. $kelas = '';
  11. if($_POST['kelas'] !="Kelas")
  12. {
  13. $kelas = $_POST['kelas'];
  14. }
  15.  
  16.  
  17.  
  18. $this->image('logo.png',10,6);
  19. $this->SetFont('Arial','B',14);
  20. $this->Cell(200,5,'SEKOLAH KEBANGSAAN TAMAN PERLING',0,0,'C');
  21. $this->Ln(7);
  22. $this->SetFont('Arial','B',13);
  23. $this->Cell(200,5,'Transaksi Pengambilan Makanan',0,0,'C');
  24. $this->Ln(5);
  25. $this->SetFont('Times','',12);
  26. $this->Cell(100,10,'Kelas -',0,0,'R');
  27. $this->Cell(100,10,$kelas,0,0,'L');
  28. $this->Ln(7);
  29. $this->SetFont('Times','',12);
  30. $this->Cell(65,10,'Tarikh Dari -',0,0,'R');
  31.  
  32. if($_POST['tarikhmula'])
  33. {
  34. $mula = $_POST['tarikhmula'];
  35. $this->Cell(65,10,date("d F Y", strtotime(strip_tags($mula))),0,0,'L');
  36. }
  37. else
  38. {
  39. $mula ="";
  40. $this->Cell(65,10,'',0,0,'L');
  41. }
  42.  
  43. $this->Cell(1,10,'Tarikh Hingga -',0,0,'R');
  44.  
  45. if($_POST['tarikhtamat'])
  46. {
  47. $akhir = $_POST['tarikhtamat'];
  48. $this->Cell(65,10,date("d F Y", strtotime(strip_tags($akhir))),0,0,'L');
  49. }
  50. else
  51. {
  52. $akhir ="";
  53. $this->Cell(65,10,'',0,0,'L');
  54. }
  55. $this->Ln(10);
  56. }
  57. function footer()
  58. {
  59. $this->SetY(-15);
  60. $this->SetFont('Arial','',8);
  61. $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  62. }
  63. function headerTable(){
  64. $this->SetFont('Times','B',12);
  65. $this->Cell(15,10,'No',1,0,'C');
  66. $this->Cell(90,10,'Nama',1,0,'C');
  67. $this->Cell(30,10,'Kelas',1,0,'C');
  68. $this->Cell(55,10,'Timestamp',1,0,'C');
  69. $this->Ln();
  70. }
  71. function viewTable($db){
  72. $this->SetFont('Times','',12);
  73. $mula = $_POST['tarikhmula'];
  74. $akhir = $_POST['tarikhtamat'];
  75. $kelas = '';
  76.  
  77. if($_POST['kelas'] !="Kelas")
  78. {
  79. $kelas = $_POST['kelas'];
  80. }
  81.  
  82. if(empty($_POST["tarikhmula"]) && empty($_POST["tarikhtamat"]) && $kelas == '')
  83. {
  84. $sql = 'select id_k,nama,kelas_murid, timestamp from kehadiran a join murid b where a.murid_id=b.id';
  85. // $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']."'";
  86. $stmt = $db->query($sql);
  87. while($data = $stmt->fetch(PDO::FETCH_OBJ))
  88. {
  89. $this->Cell(15,10,$data->id_k,1,0,'C');
  90. $this->Cell(90,10,$data->nama,1,0,'L');
  91. $this->Cell(30,10,$data->kelas_murid,1,0,'C');
  92. $this->Cell(55,10,date("d F Y g:i A", strtotime(strip_tags($data->timestamp))),1,0,'C');
  93. $this->Ln();
  94. }
  95. }
  96. else if(isset($_POST["tarikhmula"]) && isset($_POST["tarikhtamat"]) && $kelas =='')
  97. {
  98. $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."'";
  99. $stmt = $db->query($sql);
  100. while($data = $stmt->fetch(PDO::FETCH_OBJ))
  101. {
  102. $this->Cell(15,10,$data->id_k,1,0,'C');
  103. $this->Cell(90,10,$data->nama,1,0,'L');
  104. $this->Cell(30,10,$data->kelas_murid,1,0,'C');
  105. $this->Cell(55,10,date("d F Y g:i A", strtotime(strip_tags($data->timestamp))),1,0,'C');
  106. $this->Ln();
  107. }
  108. }
  109. else if(empty($_POST["tarikhmula"]) && empty($_POST["tarikhtamat"]) && $kelas != '')
  110. {
  111. $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']."'";
  112. $stmt = $db->query($sql);
  113. while($data = $stmt->fetch(PDO::FETCH_OBJ))
  114. {
  115. $this->Cell(15,10,$data->id_k,1,0,'C');
  116. $this->Cell(90,10,$data->nama,1,0,'L');
  117. $this->Cell(30,10,$data->kelas_murid,1,0,'C');
  118. $this->Cell(55,10,date("d F Y g:i A", strtotime(strip_tags($data->timestamp))),1,0,'C');
  119. $this->Ln();
  120. }
  121. }
  122. else
  123. {
  124. $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."'";
  125. $stmt = $db->query($sql);
  126. while($data = $stmt->fetch(PDO::FETCH_OBJ))
  127. {
  128. $this->Cell(15,10,$data->id_k,1,0,'C');
  129. $this->Cell(90,10,$data->nama,1,0,'L');
  130. $this->Cell(30,10,$data->kelas_murid,1,0,'C');
  131. $this->Cell(55,10,date("d F Y g:i A", strtotime(strip_tags($data->timestamp))),1,0,'C');
  132. $this->Ln();
  133. }
  134. }
  135. }
  136. }
  137.  
  138. $pdf = new myPDF();
  139. $pdf->AliasNbPages();
  140. $pdf->AddPage('P','A4',0);
  141. $pdf->headerTable();
  142. $pdf->viewTable($db);
  143. $pdf->Output();
  144.  
  145. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement