<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
   <div class='row'>
   <div class='col-md-12'>
            <div class="card">
             <div class="card-header">	
                  <h5 class='card-title'><i class="fas fa-graduation-cap"></i> Agenda Guru Mapel</h5>
                </div>
				
                <div class='card-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 12px" id='example1' class='table'>
                            <thead>
                                <tr>
                                    <th width='3px'>No</th>
									<th width='5%'>Tingkat</th>
									  <th width='5%'>Kelas</th>
                                    <th>Mapel</th>  
                                     <th>Guru Mapel</th> 	
									 <th width='10%'>Hari</th>
                                      <th width='5%'>Dari</th>
                                        <th width='5%'>Sampai</th>
                                       <th width='5%'>Total Agenda</th>											
									<th>Action</th>
                                </tr>
                            </thead>
							
							<tbody>
							
                                <?php
								$no = 0;
								 if ($user['level'] == 'admin') :
								 $query = mysqli_query($koneksi, "select * from jadwal_mapel
								 JOIN users ON users.id_user=jadwal_mapel.guru");
								  elseif ($user['level'] == 'guru') :
								   $query = mysqli_query($koneksi, "select * from jadwal_mapel
								 JOIN users ON users.id_user=jadwal_mapel.guru WHERE  jadwal_mapel.guru='$_SESSION[id_user]' ");
								   endif;
                            while ($mapel = mysqli_fetch_array($query)) {
							$hari=fetch($koneksi,'m_hari',['inggris' =>$mapel['hari']]);
							$jml = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM agenda WHERE idjadwal='$mapel[id_jadwal]'"));
                                $no++;
                            ?>
							 <tr>
                                    <td><?= $no; ?></td>
									 <td><?= $mapel['tingkat'] ?></td>
									 <td><?= $mapel['kelas'] ?></td>
							        <td><?= $mapel['kode'] ?></td>
									<td><?= $mapel['nama'] ?></td>
									<td><?= $hari['hari'] ?></td>					
									<td><?= $mapel['dari'] ?></td>
									<td><?= $mapel['sampai'] ?></td>
                                   <td style="text-align:center">
                                       <?= $jml ?>
                                   </td>
								    <td style="text-align:center">
                                    <?php if($jml<>0){ ?>  
									<button class='btn btn-sm btn-outline-danger' onclick="frames['frameresult<?= $mapel[id_jadwal] ?>'].print()"><i class='fa fa-print'></i></button>  
                                  
									<?php }else{ ?>
									<button class='btn btn-sm btn-default' disabled><i class='fa fa-lock'></i></button>  
									<?php } ?>
								 </td>
								  <iframe id='loadframe' name='frameresult<?= $mapel[id_jadwal] ?>' src="sandik_agenda/cetakagendaguru.php?idj=<?= $mapel['id_jadwal'] ?>" style='display:none'></iframe>
							       </tr>
                            <?php } ?>
                        </tbody>
                        </table>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
	