<?php ob_start();
error_reporting(0);
require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");

session_start();
if (!isset($_SESSION['id_user'])) {
    die('Anda tidak diijinkan mengakses langsung');
}
$id_bank = $_GET['m'];	
$id_kelas = $_GET['k'];
$mapelQ = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal JOIN mata_pelajaran ON mata_pelajaran.kode_mapel=banksoal.nama where id_bank='$id_bank' "));
$menu = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM menu  WHERE id_menu='1'"));
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8'>

     <title>ANALISIS_<?= $id_kelas ?></title>
  <link rel='stylesheet' href='../../dist/css/cetak.min.css'>
<link rel='stylesheet' href='../../dist/css/bootstrap.min.css' />
</head>

<style>
@page { margin: 40px; }
body { margin: 40px; }
</style>
<body style="font-size: 12px;">
	  <table width='100%'>
                <tr>
                    <td width='100'><img src='../../<?= $setting['logo'] ?>' width='70'></td>
                    <td style="text-align:center">
                        <strong class='f12'>
                            <?= strtoupper($setting['header']) ?><br>
							  KABUPATEN / KOTA <?= strtoupper($setting['kabupaten']) ?><br>
                     <?= strtoupper($setting['sekolah']) ?><br>
					 <small>Alamat :  <?= $setting['alamat'] ?> Kec. <?= $setting['kecamatan'] ?> Kab.  <?= $setting['kabupaten'] ?> Email :  <?= $setting['email'] ?></small>
                        </strong>
                    </td>
                    
                </tr>
            </table>
			 <hr style="margin:1px">
		 <hr style="margin:2px">
   <br>       

   <center><h4><b>ANALISIS BUTIR SOAL <br><?= strtoupper($mapelQ['nama_mapel']) ?></b></h4></center>
 <br>
  
      <?php
    
    $nilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_bank='$_GET[m]'"));
	
		 $mapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal where id_bank='$id_bank' "));
	 
    ?>
   
				 <?php 
				
				 $jumlah_siswa = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_kelas='$id_kelas'"));
				 ?>
				 
				  <?php 
				
					   $jumlah_soal = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_bank='$id_bank'  "));
				  
				 ?>
           
                    <table  width="100%">
                        <tr>
                            <th>Kelas</th>
                            <td width='10'>:</td>
                            <td><?= $id_kelas ?></td>
                             <td width='50'></td>
                            <th>Jml Siswa</th>
                            <td width='10'>:</td>
                            <td><b><?= $jumlah_siswa ?></b></td>
                        </tr>
                        <tr>
                            <th>Mata Pelajaran</th>
                            <td width='10'>:</td>
                            <td><?= $mapelQ['kode_mapel'] ?></td>
                           <td width='50'></td>
                            <th>Kelompok Soal</th>
                            <td width='10'>:</td>
                            <td><?= $mapel['groupsoal'] ?></td>
                        </tr>
						 <tr>
                            <th>
							
							Jumlah Soal
							
							</th>
                            <td width='10'>:</td>
                            <td><?= $jumlah_soal ?></td>
							<td width='50'></td>
							<th>Semester / TP</th>
                            <td width='10'>:</td>
                            <td><?= $setting['semester'] ?> / <?= $setting['tp'] ?></td>
                        </tr>
						
                    </table>
					<br>
                     <h4>Soal Pilihan Ganda</h4>
                  
		 <table class='it-grid it-cetak' width='100%'>
              <tr height="40px">
                        
							<th width="5%">No Soal</th>
							<th width="5%">Kunci</th>
							<th width="5%">A</th>
							<th width="5%">B</th>
							<th width="5%">C</th>
							<th width="5%">D</th>
							<?php if($setting['jenjang']=='SMA' OR $setting['jenjang']=='SMK') { ?>
							<th width="5%">E</th>
							<?php } ?>
							<th width="5%">Jml Benar</th>
                                  <th width="5%">Jml Salah</th>
								   <th width="5%">Tidak Jawab</th>
								   <th>Daya Pembeda</th>
								   <th width="5%">Efektifitas Option</th>
								   <th>Status Soal</th>
                                </tr>
								
                           
							 	
							 <?php
							 
							
                               $queryx = mysqli_query($koneksi, "select * FROM soal WHERE id_bank='$id_bank' AND jenis='1' ");                 
							   while ($mp = mysqli_fetch_array($queryx)) {
										$jawab=$mp['jawaban'];
								
								$benar=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup
								WHERE jawaban='$jawab' AND jenis='1' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
							   $salah=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup
								WHERE jawaban<>'$jawab' AND jenis='1' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$tidakjawab=$jumlah_siswa - ($benar+$salah);
								$A=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup
								WHERE jawaban='A' AND jenis='1' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$B=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup
								WHERE jawaban='B' AND jenis='1' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$C=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup
								WHERE jawaban='C' AND jenis='1' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$D=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup
								WHERE jawaban='D' AND jenis='1' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$E=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup
								WHERE jawaban='E' AND jenis='1' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
									
                                   $rumus=($jumlah_siswa * 27) / 100;
								   $bagi=$rumus*2;
                                   $sulit=$benar / $bagi;
									if($sulit < 0.30){
									{$status="Soal Sukar";}
									}elseif($sulit >= 0.30 && $sulit <= 0.70){
									{$status="Soal Sedang";}
									}elseif($sulit >= 0.70){
									{$status="Soal Mudah";}
									}	
									if($sulit < 0.30){
									{$dp="Jelek, soal dirombak ";}
									}elseif($sulit >= 0.30 && $sulit <= 0.50){
									{$dp="Kurang baik (perlu direvisi)";}
									}elseif($sulit >= 0.51 && $sulit <= 0.69){
									{$dp="Kurang baik (perlu direvisi)";}
									}elseif($sulit >= 0.70){
									{$dp="Baik";}
									}	
									if($benar > $salah){
									{$kecoh="Efektif";}
									}elseif($benar < $salah){
									{$kecoh="Menyesatkan";}
									}elseif($benar = $salah){
									{$kecoh="Tidak efektif";}
									}		
							   ?>
								
                         
							<tr>
                                        <td><?= $mp['nomor'] ?> </td>
                                        
                                        <td> <?= $mp['jawaban'] ?> </td>
										 <td> <?= $A ?> </td>
										  <td> <?= $B ?> </td>
										   <td> <?= $C ?> </td>
										    <td> <?= $D ?> </td>
											<?php if($setting['jenjang']=='SMA' OR $setting['jenjang']=='SMK') { ?>
											 <td> <?= $E ?> </td>
											<?php } ?>
									  <td> <?= $benar ?> </td>
                                       <td> <?= $salah ?> </td>
                                       <td> <?= $tidakjawab ?> </td>
									  <td> <?= $dp ?> </td>
									 <td> <?= $kecoh ?> </td>
									 <td> <?= $status ?> </td>
									 
                                    <?php } ?>	
									</tr>	
										
                         
                        </table>
						<br>
						
						 <h4>Soal PG Komplek (Multi Coice)</h4>
                    <table class='it-grid it-cetak' width='100%'>
              <tr height="40px">
							<th width="5%">No Soal</th>
							<th width="5%">Kunci Jawaban</th>
							<th width="5%">Jml Benar</th>
                                  <th width="5%">Jml Salah</th>
								   <th width="5%">Tidak Jawab</th>
								   <th>Daya Pembeda</th>
								   <th width="5%">Efektifitas Option</th>
								   <th>Status Soal</th>
                                </tr>
                          
							 <?php
                                    $queryx = mysqli_query($koneksi, "select * FROM soal WHERE id_bank='$id_bank' AND jenis='3' ");
                                    while ($mp = mysqli_fetch_array($queryx)) {
										$jawab=$mp['jawaban'];
								$benar=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE jawabmulti='$jawab' AND jenis='3' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
							   $salah=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE jawabmulti<>'$jawab' AND jenis='3' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$tidakjawab=$jumlah_siswa - ($benar+$salah);
								
                                   $rumus=($jumlah_siswa * 27) / 100;
								   $bagi=$rumus*2;
                                   $sulit=$benar / $bagi;
								if($sulit < 0.30){
								{$status="Soal Sukar";}
								}elseif($sulit >= 0.30 && $sulit <= 0.70){
								{$status="Soal Sedang";}
								}elseif($sulit >= 0.70){
								{$status="Soal Mudah";}
								}	
								if($sulit < 0.30){
								{$dp="Jelek, soal dirombak ";}
								}elseif($sulit >= 0.30 && $sulit <= 0.50){
								{$dp="Kurang baik (perlu direvisi)";}
								}elseif($sulit >= 0.51 && $sulit <= 0.69){
								{$dp="Kurang baik (perlu direvisi)";}
								}elseif($sulit >= 0.70){
								{$dp="Baik";}
								}	
								if($benar > $salah){
								{$kecoh="Efektif";}
								}elseif($benar < $salah){
								{$kecoh="Menyesatkan";}
								}elseif($benar = $salah){
								{$kecoh="Tidak efektif";}
								}
							   ?>
								
                        
							<tr>
                                        <td><?= $mp['nomor'] ?> </td>
                                        <td> <?= $mp['jawaban'] ?> </td>
									  <td> <?= $benar ?> </td>
                                       <td> <?= $salah ?> </td>
                                       <td><?= $tidakjawab ?> </td>
									 	 <td> <?= $dp ?> </td>
									 <td> <?= $kecoh ?> </td>
									  <td> <?= $status ?> </td>
                                    <?php } ?>	
									</tr>	
						
                        </table>
						<br>
                     <h4>Soal PG Komplek (Benar Salah / Fakta Opini)</h4>
                   <table class='it-grid it-cetak' width='100%'>
              <tr height="40px">
							<th width="5%">No Soal</th>
							<th width="5%">Kunci Jawaban</th>
							
							<th width="5%">Jml Benar</th>
                                  <th width="5%">Jml Salah</th>
								   <th width="5%">Tidak Jawab</th>
								   <th>Daya Pembeda</th>
								   <th width="5%">Efektifitas Option</th>
								   <th>Status Soal</th>
                                </tr>
								
                          
							 <?php
							 
							        
                                    $queryx = mysqli_query($koneksi, "select * FROM soal WHERE id_bank='$id_bank' AND jenis='4'");
                                    while ($mp = mysqli_fetch_array($queryx)) {
										$jawab=$mp['jawaban'];
								$benar=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE jawabbs='$jawab' AND jenis='4' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
							   $salah=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE jawabbs<>'$jawab' AND jenis='4' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$tidakjawab=$jumlah_siswa - ($benar+$salah);
								$A=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE jawabbs='A' AND jenis='4' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$B=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE jawabbs='B' AND jenis='4' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								
                                   $rumus=($jumlah_siswa * 27) / 100;
								   $bagi=$rumus*2;
																   $sulit=$benar / $bagi;
								if($sulit < 0.30){
								{$status="Soal Sukar";}
								}elseif($sulit >= 0.30 && $sulit <= 0.70){
								{$status="Soal Sedang";}
								}elseif($sulit >= 0.70){
								{$status="Soal Mudah";}
								}	
								if($sulit < 0.30){
								{$dp="Jelek, soal dirombak ";}
								}elseif($sulit >= 0.30 && $sulit <= 0.50){
								{$dp="Kurang baik (perlu direvisi)";}
								}elseif($sulit >= 0.51 && $sulit <= 0.69){
								{$dp="Kurang baik (perlu direvisi)";}
								}elseif($sulit >= 0.70){
								{$dp="Baik";}
								}	
								if($benar > $salah){
								{$kecoh="Efektif";}
								}elseif($benar < $salah){
								{$kecoh="Menyesatkan";}
								}elseif($benar = $salah){
								{$kecoh="Tidak efektif";}
								}
							   ?>
								
                         
							<tr>
                                        <td><?= $mp['nomor'] ?> </td>
                                        
                                        <td> <?= $mp['jawaban'] ?> </td>
										 
									  <td> <?= $benar ?> </td>
                                       <td> <?= $salah ?> </td>
                                       <td> <?= $tidakjawab ?> </td>
									 <td> <?= $dp ?> </td>
									 <td> <?= $kecoh ?> </td>
									  <td> <?= $status ?> </td>
									 
                                    <?php } ?>	
									</tr>	
							
                        </table>
						<br>
                     <h4>Soal Mengurutkan</h4>
                   <table class='it-grid it-cetak' width='100%'>
                 <tr height="40px">
							<th width="5%">No Soal</th>
							<th width="5%">Kunci Jawaban</th>
							<th width="5%">Jml Benar</th>
                                  <th width="5%">Jml Salah</th>
								   <th width="5%">Tidak Jawab</th>
								   <th>Daya Pembeda</th>
								   <th width="5%">Efektifitas Option</th>
								   <th>Status Soal</th>
                                </tr>
                          
							 <?php
                                    $queryx = mysqli_query($koneksi, "select * FROM soal WHERE id_bank='$id_bank' AND jenis='5'");
                                    while ($mp = mysqli_fetch_array($queryx)) {
										$jawab=$mp['jawaban'];
								$benar=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE jawaburut='$jawab' AND jenis='5' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
							   $salah=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE jawaburut<>'$jawab' AND jenis='5' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$tidakjawab=$jumlah_siswa - ($benar+$salah);
								
                                   $rumus=($jumlah_siswa * 27) / 100;
								   $bagi=$rumus*2;
						$sulit=$benar / $bagi;
						if($sulit < 0.30){
						{$status="Soal Sukar";}
						}elseif($sulit >= 0.30 && $sulit <= 0.70){
						{$status="Soal Sedang";}
						}elseif($sulit >= 0.70){
						{$status="Soal Mudah";}
						}	
						if($sulit < 0.30){
						{$dp="Jelek, soal dirombak ";}
						}elseif($sulit >= 0.30 && $sulit <= 0.50){
						{$dp="Kurang baik (perlu direvisi)";}
						}elseif($sulit >= 0.51 && $sulit <= 0.69){
						{$dp="Kurang baik (perlu direvisi)";}
						}elseif($sulit >= 0.70){
						{$dp="Baik";}
						}	
						if($benar > $salah){
						{$kecoh="Efektif";}
						}elseif($benar < $salah){
						{$kecoh="Menyesatkan";}
						}elseif($benar = $salah){
						{$kecoh="Tidak efektif";}
						}
							   ?>
								
                           
							<tr>
                                        <td><?= $mp['nomor'] ?> </td>
                                        <td> <?= $mp['jawaban'] ?> </td>
									  <td> <?= $benar ?> </td>
                                       <td> <?= $salah ?> </td>
                                       <td> <?= $tidakjawab ?> </td>
									   <td> <?= $dp ?> </td>
									 <td> <?= $kecoh ?> </td>
									 <td> <?= $status ?> </td>
									
                                    <?php } ?>	
									</tr>	
                           
                        </table>
						<br>
						
							<h4>Soal Esai</h4>
                    <table class='it-grid it-cetak' width='100%'>
                 <tr height="40px">
							<th width="5%">No Soal</th>
							<th width="5%">Kunci Jawaban</th>
							<th width="5%">Jml Benar</th>
                                  <th width="5%">Jml Salah</th>
								   <th width="5%">Tidak Jawab</th>
								   <th>Daya Pembeda</th>
								  
								   <th>Status Soal</th>
                                </tr>
                           
							 <?php
                                    $queryx = mysqli_query($koneksi, "select * FROM soal WHERE id_bank='$id_bank' AND jenis='2'");
                                    while ($mp = mysqli_fetch_array($queryx)) {
										$jawab=$mp['jawaban'];
								$benar=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE esai='$jawab' AND jenis='2' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
							   $salah=mysqli_num_rows(mysqli_query($koneksi, "select * FROM jawaban_dup 
								WHERE esai<>'$jawab' AND jenis='2' AND id_bank='$mp[id_bank]' AND id_soal='$mp[id_soal]'"));
								$tidakjawab=$jumlah_siswa - ($benar+$salah);
								
                                   $rumus=($jumlah_siswa * 27) / 100;
								   $bagi=$rumus*2;
                                   $sulit=$benar / $bagi;
									if($sulit < 0.30){
									{$status="Soal Sukar";}
									}elseif($sulit >= 0.30 && $sulit <= 0.70){
									{$status="Soal Sedang";}
									}elseif($sulit >= 0.70){
									{$status="Soal Mudah";}
									}	
									if($sulit < 0.30){
									{$dp="Jelek, soal dirombak ";}
									}elseif($sulit >= 0.30 && $sulit <= 0.50){
									{$dp="Kurang baik (perlu direvisi)";}
									}elseif($sulit >= 0.51 && $sulit <= 0.69){
									{$dp="Kurang baik (perlu direvisi)";}
									}elseif($sulit >= 0.70){
									{$dp="Baik";}
									}	

							   ?>
								
                           
							<tr>
                                        <td><?= $mp['nomor'] ?> </td>
                                        <td> <?= $mp['jawaban'] ?> </td>
									  <td> <?= $benar ?> </td>
                                       <td> <?= $salah ?> </td>
                                       <td> <?= $tidakjawab ?> </td>
									   <td> <?= $dp ?> </td>
									  <td> <?= $status ?> </td>
                                    <?php } ?>	
									</tr>	
										
                        </table>
						
						</div>
					
						</body>

</html>
						<?php

$html = ob_get_clean();
require_once '../../vendors/autoload.php';

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream("Leger_KI-3.pdf", array("Attachment" => false));
exit(0);
?>