<?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-edit"></i> Tugas Siswa</h5>
            </div>
            <div class='card-body'>
               <div class='row'>	
                <?php
                $siswa = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_siswa='$_SESSION[id_siswa]'"));
                $mapelQ = mysqli_query($koneksi, "SELECT * FROM tugas");

                ?>
                <?php while ($mapel = mysqli_fetch_array($mapelQ)) : ?>
                    <?php
                    if ($mapel['tgl_selesai'] > date('Y-m-d H:i:s')) {
                        $datakelas = unserialize($mapel['kelas']);
                        $guru = fetch($koneksi, 'users', ['id_user' => $mapel['id_guru']]);
                    ?>
                        <?php if (in_array($siswa['id_kelas'], $datakelas) or in_array('semua', $datakelas)) : ?>
                             	<div class="col-xl-4">
								
								 <div class="card widget widget-stats">
                                    <div class="card-body">
                                        <div class="widget-stats-container d-flex">
                                             <center style="padding: 8px">
                                            <?php if ($mapel['tgl_mulai'] > date('Y-m-d H:i:s') and $mapel['tgl_selesai'] > date('Y-m-d H:i:s')) { ?>
                                                TUGAS BELUM MULAI
                                            <?php } elseif ($mapel['tgl_mulai'] < date('Y-m-d H:i:s') and $mapel['tgl_selesai'] > date('Y-m-d H:i:s')) { ?>
                                                <a href="<?= $homeurl . '/lihattugas/' . enkripsi($mapel['id_tugas']) ?>" class="btn btn-primary">
                                                    <i class="fa fa-edit"></i> Lihat Tugas
                                                </a>
                                            <?php } ?>
                                       </center>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">
												  Guru : <?= $guru['nama'] ?>
											</span>
                                                <span class="widget-stats-amount">	  
                                                      
                                                <?php
                                                if (strlen($mapel['mapel']) > 30) {
                                                    echo substr($mapel['mapel'], 0, 30) . "...";
                                                } else {
                                                    echo $mapel['mapel'];
                                                }
                                                ?>
                                               </span>
                                                <span class="widget-stats-title">
												 <?= $mapel['judul'] ?>
												</span>
                                             </span>
                                                <span class="widget-stats-title">
												Mulai <?= $mapel['tgl_mulai'] ?>
												</span>
												  <span class="widget-stats-title">
												Selesai <?= $mapel['tgl_selesai'] ?>
												</span>
                                    </div>

                                       
											
                                            
                                        </div>
                                    </div>
                                </div>
								  </div>
                        <?php endif; ?>
                    <?php } ?>
                <?php endwhile; ?>

            </div>
        </div>
    </div>
</div>