<?php 
session_start();
require"inc/auth.php";
?>

<?php 
  include"inc/conn.php";
  include"inc/session_siswa.php";
  include"inc/style.php";

  $id = $_GET["id"];
  $qunit=mysqli_query($connect,"select * from tb_unit where id_unit='".$id."' and aktif='1'");
  $runit=mysqli_fetch_array($qunit);

  $qcek=mysqli_query($connect,"select * from tb_jawaban_pretest where id_siswa='".$rsiswa_login['id_siswa']."' AND id_unit='".$runit['id_unit']."'");
  $jumjawaban=mysqli_num_rows($qcek);
?>

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Pretest | <?php echo $runit['judul_unit'];?></title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  
  
</head>

<body>

  <?php include"inc/menu.php";?>

  
  <main id="main">
    
    <!-- ======= Breadcrumbs ======= -->
    <section class="breadcrumbs">
      <div class="container" style="color:grey;">
          <ol>
            <li><a href="index.php">Beranda</a></li>
            <li><a href="unit.php?id=<?php echo $id;?>">Unit</a></li>
            <li>Uji Konsep</li>
          </ol>
      </div>
    </section><!-- End Breadcrumbs -->
    

    <!-- ======= Blog Single Section ======= -->
    <section id="blog" class="blog" style="margin-top:30px;">
      <div class="container">

        <div class="row">

          <div class="col-lg-12 entries">

            <article class="entry entry-single" style="border-top:17px solid #c2326f;border-bottom:17px solid #c2326f;border-radius:5px;">

              <a href="unit.php?id=<?php echo $id;?>"><button class="btn btn-sm" style="background:#c2326f;color:white;"><i class="bi bi-arrow-left"></i> Kembali Ke Menu</button></a>
              <br><br> 

              <header class="section-header">
                  <h2>Pretest</h2>
				<p><?php echo $runit['judul_unit'];?></p>
			  </header>






              <?php
              if($jumjawaban<1){
              ?>






              <form action="simpanjawabanpretest" method="POST">
              <div class="entry-content">

                        
                          <div class="tab-content py-3 px-3 px-sm-0" id="nav-tabContent">
                           
                           
                            
                           

                            <?php
                            $bilangan=1;
                            $urutan=0;
                            $qessai=mysqli_query($connect,"select * from tb_pretest where id_unit='".$runit['id_unit']."'");
                            $jum2=mysqli_num_rows($qessai);
                            while($ressai=mysqli_fetch_array($qessai)){
                            
                            $urutan++;
                            ?>

                            <input type="hidden" name="id_siswa" value="<?php echo $rsiswa_login['id_siswa'];?>">
                            <input type="hidden" name="id_unit" value="<?php echo $runit['id_unit'];?>">
                            <input type="hidden" name="id_pretest[]" value="<?php echo $ressai['id_pretest'];?>">


                            <table border=0 width="100%" cellpadding="5">
                              <tr>
                                <td rowspan=6 width="3%" align="center" valign="top" rowspan=2>
                                  <?php echo $bilangan++;?>.
                                </td>
                                <td colspan="2" width="97%" style="padding-bottom:5px;">
                                  <?php echo $ressai['soal'];?>
                                </td>
                              </tr>
                              <tr>
                                <td width="2%">
                                    <input type="radio" name="jawaban<?php echo $ressai['id_pretest'];?>" value="A" required="required" style="cursor:pointer;">
                                </td>
                                <td width="98%">
                                    A. <?php echo $ressai['opsi_a'];?>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                    <input type="radio" name="jawaban<?php echo $ressai['id_pretest'];?>" value="B" required="required" style="cursor:pointer;">
                                </td>
                                <td>
                                    B. <?php echo $ressai['opsi_b'];?>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                    <input type="radio" name="jawaban<?php echo $ressai['id_pretest'];?>" value="C" required="required" style="cursor:pointer;">
                                </td>
                                <td>
                                    C. <?php echo $ressai['opsi_c'];?>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                    <input type="radio" name="jawaban<?php echo $ressai['id_pretest'];?>" value="D" required="required" style="cursor:pointer;">
                                </td>
                                <td>
                                    D. <?php echo $ressai['opsi_d'];?>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                    <input type="radio" name="jawaban<?php echo $ressai['id_pretest'];?>" value="E" required="required" style="cursor:pointer;">
                                </td>
                                <td>
                                    E. <?php echo $ressai['opsi_e'];?>
                                </td>
                              </tr>
                              
                            </table>
                            <br>
                            <?php }?>

                            <?php if($jum2<1){?>
                                  <div class="alert alert-danger text-center" role="alert">
                                    <i class="fa fa-exclamation fa-2x"></i><br><i>Tidak ditemukan data soal</i>
                                  </div>
                              <?php }?>

                                
                          </div>
              </div>




              <?php if($jum2>0){?>
              <button class="btn btn-success scrollto d-inline-flex align-items-center justify-content-center align-self-center" style="background:#c2326f;color:white;">
                  <span>Simpan Jawaban</span>
              </button>
              <?php }?>

              
            </article>
            </form>





            














































            <?php }else{?>


              <div class="entry-content">

                       
                          <div class="tab-content py-3 px-3 px-sm-0" id="nav-tabContent">
                           
                           
                            <div class="alert alert-success text-center" role="alert">
                              <?php include"inc/skorpretest.php";?>
                            </div>

                            <hr>

                            <?php
                            $bilangan=1;
                            $qessai=mysqli_query($connect,"select * from tb_pretest where id_unit='".$runit['id_unit']."'");
                            $jum2=mysqli_num_rows($qessai);
                            while($ressai=mysqli_fetch_array($qessai)){

                            $qj=mysqli_query($connect,"select * from tb_jawaban_pretest where id_siswa='".$rsiswa_login['id_siswa']."' AND id_unit='".$runit['id_unit']."' AND id_pretest='".$ressai['id_pretest']."'");
                            $rj=mysqli_fetch_array($qj);
                            ?>
                            <table width="100%" cellpadding="3">
                              <tr>
                                <td width="3%" align="center" valign="top" rowspan=10>
                                  <?php echo $bilangan++;?>.
                                </td>
                                <td colspan=3 width="97%" style="padding-bottom:5px;padding:2px;">
                                  <?php echo $ressai['soal'];?>
                                </td>
                              </tr>
                              <tr>
                                <td width="98%">
                                    A. <?php echo $ressai['opsi_a'];?>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                    B. <?php echo $ressai['opsi_b'];?>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                    C. <?php echo $ressai['opsi_c'];?>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                    D. <?php echo $ressai['opsi_d'];?>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                    E. <?php echo $ressai['opsi_e'];?>
                                </td>
                              </tr>
                              <tr><td></td></tr>
                              <tr>
                                <td style="border:1px dotted silver;padding:10px;">
                                    <b>Jawaban Anda</b> : <?php echo $rj['jawaban'];?>
                                </td>
                              </tr>
                              </tr>
                              
                            </table>
                            <br>
                            <?php }?>

                            <?php if($jum2<1){?>
                                  <div class="alert alert-danger text-center" role="alert">
                                    <i>Tidak ditemukan data soal</i>
                                  </div>
                              <?php }?>

                                
                          </div>
              </div>


            </article>

            <?php }?>























































       

              

          </div><!-- End blog entries list -->

          

        </div>

      </div>
    </section><!-- End Blog Single Section -->

    
  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <footer id="footer" class="footer">

    <?php include"inc/footer.php";?>
    
  </footer><!-- End Footer -->

  <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>

  <?php include"inc/script.php";?>

</body>

</html>