<div class="content-wrapper">
<h4> <b>ASSIGNMENT</b> <small class="text-muted">/Assignment Information</small>
</h4>
<hr>
<div class="row">
<div class="col-md-12">
    <div class="card">
      <div class="card-body">
        <h4 class="text-heading"> List of Assignment </h4>
        <p></p>
        <hr>


          <div class="row">
            <?php 
            // cek tabel tugas
            $kelas = mysqli_query($con,"SELECT * FROM kelas_tugas WHERE id_kelas='$_SESSION[kelas]' AND id_jurusan='$_SESSION[jurusan]' ORDER BY id_tugas DESC ");
             $jumlah = mysqli_num_rows($kelas);
           
            foreach ($kelas as $d) { ?>
           <?php 
           if ($d['aktif']=='N') {
               echo '
               <div class="alert alert-danger">
               <b>There is no assignment for your class !</b>
               </div>

               ';
           }else{
            ?>
                            <?php 
							$tgls=date("Y-m-d");
                // tampilkan dat ujian
                $ujian = mysqli_query($con,"SELECT *,DATE_ADD(tanggal,INTERVAL waktu DAY)AS jatuh_tempo
 ,DATEDIFF(DATE_ADD(tanggal,INTERVAL waktu DAY),CURDATE()) AS selisih FROM tb_tugas
 INNER JOIN tb_jenistugas ON tb_tugas.id_jenistugas=tb_jenistugas.id_jenistugas
 INNER JOIN tb_guru ON tb_tugas.id_guru=tb_guru.id_guru
  INNER JOIN tb_master_mapel ON tb_tugas.id_mapel=tb_master_mapel.id_mapel
   INNER JOIN tb_master_semester ON tb_tugas.id_semester=tb_master_semester.id_semester
   WHERE tb_tugas.id_tugas='$d[id_tugas]' ORDER BY tb_tugas.id_tugas DESC ");
   foreach ($ujian as $t) { ?>
                 <div class="col-md-6 col-xs-12"> 
                  <div class="alert alert-dark alert-dismissible" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    Assignment :  <strong><?=$t['mapel'] ?> </strong>
                    <p>
                      <p>
                        Trainer : <b><?=$t['nama_guru'] ?></b>
                      </p>
					  <p>
                        Name of Assignment : <b><?=$t['judul_tugas'] ?></b>
                      </p>

                      <table class="table table-striped">
                        <tr>
                          <th>Type of Assignment</th>
                          <th>:</th>
                          <th> <?=$t['jenis_tugas'] ?></th>
                        </tr>
                        
                          <tr>
                          <th>Deadline of Assignment</th>
                          <th>:</th>
                          <th> <?= date('d-F-Y',strtotime($t['jatuh_tempo'])) ?></th>
                        </tr>
                          <tr>
                          <th>Remaining Days</th>
                          <th>:</th>
                          <th> <?=$t['selisih'] ?> Days </th>
                        </tr>
                      </table>

                     </p>
                     <hr>
                     <p>
                      <?php 
$tgldb=$t['tanggal'];
                      if ($t['selisih']<=0) {
                        ?>
                        <div class="alert alert-danger alert-dismissible" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <strong>Time's Up!</strong> You cannot complete this assignment because the maximum time has been reached. If there are any errors, please contact your trainer.
                        <!-- <strong>Waktu Habis!</strong> Anda tidak dapat menegrjakan tugas ini karena Sudah mencapai waktu maksimum ,Jika ada kesalahan,hubungi Guru Mata pelajaran -->
                        </div>
						<?php }elseif ($tgls < $tgldb) {?>
						<div class="alert alert-warning alert-dismissible" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <strong>TUGAS BELUM AKTIF!</strong> Akan Aktif Pada Tanggal <b><?= date('d-F-Y',strtotime($t['tanggal'])) ?></b>
                        </div>
                        <?php }else{
                        $cektugas = mysqli_query($con,"SELECT * FROM tugas_siswa WHERE id_tugas='$d[id_tugas]' AND id_siswa='$_SESSION[Siswa]' ");
                        $jml= mysqli_num_rows($cektugas);
                        if ($jml < 1) {
                         echo "<b class='badge badge-pill badge-danger'>The task hasn't been done yet</b>";
                            ?>
                         <p></p>
                          <a href="?page=tugas&act=upload&tugas=<?php echo $t[id_tugas];?>&id=<?php echo $t[id_jenistugas];?>&jenis=<?php echo $t[jenis_tugas];?>" class="btn btn-light"><i class="fa fa-pencil"></i> Do Assignment</a>
                       <a href="../Report/tugas/download_tugas.php?tugas=<?php echo $t[id_tugas] ?>&kelas=<?php echo $_SESSION[kelas] ?>&jurusan=<?php echo $_SESSION[jurusan] ?> " class="btn btn-light" target="_blank"><i class="fa fa-download"></i> Download</a> 
                        
                        <?php
                        }else{
                          echo "<b class='badge badge-pill badge-success'>Already Finished</b>";
                        }

                       
                      }


                       ?>


                     </p>
                  </div>
                </div> 
              <?php } ?>

                <?php

           }

            ?>           
         

            <?php } ?>
              
 


            
                   
          </div>

          <div class="row">
            
          </div>


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

