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

(isset($_SESSION['id_user'])) ? $id_user = $_SESSION['id_user'] : $id_user = 0;
	($id_user==0) ? header('location:login.php'):null;
	$user = fetch($koneksi, 'users',array('id_user'=>$id_user));
$idjadwal = @$_GET['idjadwal'];

$bl = date('m');
$tahun = date('Y');
$bulane = fetch ($koneksi, 'bulan', ['bln' =>$bl]);
$agendax = fetch($koneksi, 'agenda', ['idjadwal' => $idjadwal]);
$jadwal=fetch($koneksi,'jadwal_mapel',['id_jadwal' => $idjadwal]);

$absen = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM absen_mapel WHERE tanggal='$agendax[tanggal]' 
AND idjadwal='$idjadwal'"));
$jumlah = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_kelas='$jadwal[kelas]' "));
?>

<link rel='stylesheet' href='<?= $homeurl ?>/dist/css/cetak.min.css'>
<link rel='stylesheet' href='../../dist/css/bootstrap.min.css' />
<style type="text/css">
	@font-face {
		font-family: 'tulisan_keren';
		src: url('../../dist/fonts/poppins/Poppins-Light.ttf');
	}

	body {
		font-family: 'tulisan_keren';
		line-height: 1.42857143;
		color: #000;
		width: 100%;
		height: 100%;
		margin: 0;
		padding: 0;
		background-color: #FAFAFA;
		font-size: 13px;
	}

	.footer {
		position: absolute;
		bottom: 1.5cm;
		left: 1.5cm;
		right: 1.5cm;
		width: auto;
		height: 30px
	}

	* {
		box-sizing: border-box;
		-moz-box-sizing: border-box;
	}

	@page {
		size: A4;
		margin: 10mm;
	}

	@media print {

		html,
		body {
			width: 210mm;
			height: 297mm;
		}

		.page {
			margin: 10mm;
			border: initial;
			border-radius: initial;
			width: initial;
			min-height: initial;
			box-shadow: initial;
			background: initial;
			page-break-after: always;
		}

		.footer {
			bottom: .7cm;
			left: .7cm;
			right: .7cm
		}
	}
</style>
<div style='background:#fff; width:97%; margin:0 auto; height:90%;'>
            <table width='100%'>
                <tr>
                    <td width='100'><img src='<?= $homeurl . '/' . $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>AGENNDA DAN JURNAL GURU<br>KURIKULUM : <?= strtoupper($agendax['kurikulum']); ?></h4></center>
	<br>
 
    <table width='100%'>
            <tr>
                <td width='100px'>Mapel</td>
                <td width='10px'>:</td>
                <td><?= $jadwal['kode'] ?></td>
				<td width='250px'></td>
				<td width='100px'>Semester</td>
                <td width='10px'>:</td>
                <td><?= $setting['semester'] ?></td>
            </tr>
			
                <tr>
                <td width='100px'>Kelas</td>
                <td width='10px'>:</td>
                <td><?= $jadwal['kelas'] ?></td>
				<td width='250px'></td>
				<td width='100px'>Ta Pel</td>
                <td width='10px'>:</td>
                <td><?= $setting['tp'] ?></td>
				</tr>
				
			
    </table>
	
     <br>
	
     <table class='it-grid it-cetak' width='100%'>
            
              <tr height="40px">
                    <th>No.</th>
                    <th>Tanggal</th>
                    <th>Jam Pel</th>
					<th>Ke</th>
					<?php if($agendax['kurikulum']=='K-13'){ ?>
                    <th>KI/KD</th>
					 <th>Materi</th>
					 <th>Indikator</th>
					<?php }else{ ?>
					 <th>TP</th>
					  <th>Lingkup Materi</th>
					  <th>Tujuan Pembelajaran</th>
					<?php } ?>
                   
					<th>Pencapaaian</th>
					<th>Kehadiran</th>
                </tr>
	
      
	 <?php
	  $query = mysqli_query($koneksi, "select * from agenda 
	 WHERE idjadwal='$idjadwal' AND bulan='$bl'  ORDER BY id ASC");
      $no = 0;
       while ($agenda = mysqli_fetch_array($query)) {
   $lingkup = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM lingkup WHERE lm='$agenda[lm]'"));
	$tujuan = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM tujuan WHERE tp='$agenda[tp]'"));
	  $tanggalmu=date('d-m-Y',strtotime($agenda['tanggal']));
	  $hadir = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM absen_mapel WHERE idjadwal='$agenda[idjadwal]' AND tanggal='$agenda[tanggal]' 
	AND ket='H'"));
	  $bagi=100/$jumlah;
	  $prosen=$bagi * $hadir;
       $no++;
	   
	   
	 ?>
    
	 <tr>
	 <td style="text-align: center;"><?= $no ?></td>
	 <td style="text-align: center;"><?= $tanggalmu ?></td>
	 <td style="text-align: center;"><?= $jadwal['dari'] ?> - <?= $jadwal['sampai'] ?></td>
	 <td style="text-align: center;"><?= $no ?></td>
	 <?php if($agendax['kurikulum']=='K-13'){ ?>
	 <td style="text-align: center;"><?= $agenda['kikd'] ?></td>
	 <td><?= $agenda['materi'] ?></td>
	 <td><?= $agenda['indikator'] ?></td>
	 <?php }else{ ?>
	  <td style="text-align: center;"><?= $agenda['tp'] ?></td>
	 <td><?= $lingkup['materi'] ?></td>
	 <td><?= $tujuan['tujuan'] ?></td>
	  <?php } ?>
	 <td style="text-align: center;">
	 <?php if($prosen>=50){ ?>
	 Tercapai
	 <?php } ?>
	  <?php if($prosen<50){ ?>
	 Tidak Tercapai
	 <?php } ?>
	 </td>
	 <td style="text-align: center;"><?= round($prosen,2); ?>%</td>
	 
	 </tr>
	   <?php } ?>
	 </tbody>
	</table>
   <br><br>
	<table width='100%'>
					<tr>
					<td width='50px'></td>
						<td>
							Mengetahui, <br/>
							Kepala Sekolah <br/>
							<br/>
							<br/>
							<br/>
							
							<u><?= $setting['kepsek'] ?></u><br/>
							NIP. <?= $setting['nip'] ?>
						</td>
						<td width='300px'></td>
						<td>
							<?= $setting['kecamatan'] ?>, <?php echo date("t",time());; ?> <?= $bulane['ket'] ?> <?= date('Y') ?><br/>
							Guru Mata Pelajaran<br/>
							<br/>
							<br/>
							<br/>
							
							<u><?= $user['nama'] ?></u><br/>
							NIP. <?= $user['nip'] ?>
						</td>
					</tr>
				</table>
</div>