<?php
include"connect.php";
$id=1;
$hasil = mysqli_query($koneksi,"select * from tset where idset ='$id'");
$row=mysqli_fetch_array($hasil);

$idset="DIREKTUR";
	$hset=mysqli_query($koneksi,"select * from staf where jabatan='$idset'");
	$pset=mysqli_fetch_array($hset);
$nim= $_POST['nim'];
$semester= $_POST['semester'];
$ta = $_POST['ta'];
$krssql = mysqli_query($koneksi,"select * from krs where nim='$nim' AND semester='$semester' AND ta='$ta'");
$hasil=mysqli_num_rows($krssql);
if($hasil > 0 )
{
if ($semester=='1' || $semester=='2')
	$Rtingkat='I';
	else if ($semester=='3' || $semester=='4')
	$Rtingkat='II';
	else
	$Rtingkat='III';
	
if ($semester=='1')
	$Rsmt='I';
	else if ($semester=='2')
	$Rsmt='II';
	else if ($semester=='3')
	$Rsmt='III';
	else if ($semester=='4')
	$Rsmt='IV';
	else if ($semester=='5')
	$Rsmt='V';
	else
	$Rsmt='VI';
	
$sql_krs = mysqli_query($koneksi,"SELECT * FROM krs, mtk WHERE nim='$nim'
 AND krs.kd_mtk = mtk.kd_mtk AND krs.nilai != 0");
$jsks = 0;
$j = 1;
$tbot=0;
while($dkrs = mysqli_fetch_array($sql_krs)){
 $bobotnilai1 = $dkrs['jsks'] * $dkrs['nilai'];
 $jsks = $jsks + $dkrs['jsks'];
 $tbot = $tbot + $bobotnilai1;
 $j++;
}
$ipk = $tbot / $jsks;
$fipk= number_format($ipk,2,'.','');

	
$mhssql = mysqli_query($koneksi,"select * from mhs where nim='$nim'");
$hasilmhs=mysqli_fetch_row($mhssql);
if ($hasilmhs)
{

echo"<table border=0 width=700>
	<tr><td align=center><h2><u>KARTU HASIL STUDI</u></h2></td></tr></table>";
echo"<table border=0>";
echo"<tr><td>NIM</td>  <td width=400>: $nim</td> <td>Semester</> <td>: $Rsmt</td></tr>";
echo"<tr><td>Nama</td> <td width=400>: $hasilmhs[1]</td> <td>Total IPK</> <td>: $fipk</td></tr>";
echo"<tr><td>Program Studi</td> <td width=400>: $hasilmhs[12]</td> <td></td> <td><br></td</tr></table>";
}
}
?>
<table border="1" width="700" cellpadding="2" style="border-collapse:collapse;">
<tr><th>No.</th>
 <th>Kode</th>
 <th>Mata Kuliah</th>
 <th>SKS</th>
 <th>Nilai</th>
 <th>Huruf</th>
 <th>Bobot</th>
</tr>
<?php
include"connect.php";
$sqlkrs = mysqli_query($koneksi,"SELECT * FROM krs, mtk WHERE nim='$nim'
 AND krs.kd_mtk = mtk.kd_mtk
 AND krs.semester='$semester' AND krs.ta='$ta' order by mtk.kd_mtk ASC");
$jumsks = 0;
$i = 1;
$totbot=0;
while($datakrs = mysqli_fetch_array($sqlkrs)){
 echo "<tr><td align=center>$i</td>";
 echo "<td align=center>$datakrs[kd_mtk]</td>";
 echo "<td>$datakrs[nm_mtk]</td>";
 echo "<td align=center>$datakrs[jsks]</td>";
 echo "<td align=center>$datakrs[nilai]</td>";
 
 if ($datakrs['nilai']>3.50)
 $lambang="A";
 else if ($datakrs['nilai']>2.75)
 $lambang="B";
 else if ($datakrs['nilai']>1.99)
 $lambang="C";
 else if ($datakrs['nilai']>0.99)
 $lambang="D";
 else
 $lambang="E";
 
 echo "<td align=center>$lambang</td>";
 $bobotnilai = $datakrs['jsks'] * $datakrs['nilai'];
 $fbobotnilai= number_format($bobotnilai,2,'.','');
 echo "<td align=right>$fbobotnilai</td>";
 $jumsks = $jumsks + $datakrs['jsks'];
 $totbot = $totbot + $bobotnilai;
 $ftotbot= number_format($totbot,2,'.','');
 $i++;
}
echo "<tr><td colspan=6>Jumlah SKS</td><td align=right>$jumsks</td></tr>";
echo "<tr><td colspan=6>Total SKS</td><td align=right>$jsks</td></tr>";
echo "<tr><td colspan=6>Jumlah Bobot</td><td align=right>$ftotbot</td></tr>";
$ips = $totbot / $jumsks;
$fips= number_format($ips,2,'.','');
echo "<tr><td colspan=6>IPS</td><td align=right>$fips</td></tr>";
//

?>
</table>
<p>&nbsp;</p>
<table border="0" width="700">
<tr>
<td>Catatan Pembimbing :
<p>.................................................................</p>
<p>.................................................................</p>
<p>.................................................................</p>
</td>
<td></td>
<?
$namabulan = array("","Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","Nopember","Desember");
$tgl= date("j");
$bln= $namabulan[date("n")];
$thn= date("Y");
?>
<!-- <td align="center"><p>Cikarang ,<? echo " $tgl $bln $thn"; ?> <br> -->
<td align="center"><p>Cikarang ,25 Agustus 2023 <br>
  STIKes Bhakti Husada Cikarang <br>
  Ketua, </p>
  <p>&nbsp;</p>
  <p><br>
      <u><? echo " $pset[1]"; ?></u>
      <br>
    NIK.<? echo " $pset[0]"; ?></p></td></tr>
<script>
window.print();
</script>
</table>
