<?php include 'header.php'; ?>

<div class="content-wrapper">

  <section class="content-header">
    <h1>
      Kelas Saya
      <!-- <small>Data Kelas Ajar Saya</small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
      <li class="active">Dashboard</li>
    </ol> -->
  </section>

  <section class="content">
    <div class="row">
      <section class="col-lg-4">

        <div class="box">
          <div class="box-body">

            <form method="get" action="">
              <div class="form-group">
                <label>Tahun Ajaran</label>
                <select class="form-control" name="ta" required="required">
                  <?php 
                  $ta = mysqli_query($koneksi,"select * from ta");
                  while($j = mysqli_fetch_array($ta)){
                    ?>
                    <option <?php if(isset($_GET['ta'])){ if($_GET['ta'] == $j['ta_id']){ echo "selected='selected'"; } } ?> value="<?php echo $j['ta_id'] ?>"><?php echo $j['ta_nama'] ?> <?php if($j['ta_status'] == "1"){ echo "(Aktif)"; } ?></option>
                    <?php 
                  }
                  ?>
                </select>
              </div>
              <input type="submit" class="btn btn-primary" value="FILTER">
            </form>

          </div>
        </div>
      </section>
      <section class="col-lg-12">
        <div class="box box-primary">

          <div class="box-header">
            <h3 class="box-title">Data Kelas Saya</h3>          
          </div>
          <div class="box-body">


            <div class="table-responsive">
              <table class="table table-bordered table-striped" id="table-datatable">
                <thead>
                  <tr>
                    <th width="1%">NO</th>
                    <th>NAMA SEKOLAH</th>
                    <th>KELAS</th>
                    <th>MATA PELAJARAN</th>
                    <th>GURU PENGAJAR</th>
                    <th>JUMLAH SISWA</th>
                    <th width="15%">OPSI</th>
                  </tr>
                </thead>
                <tbody>
                  <?php 
                  $no=1;
                  $id_guru = $_SESSION['id'];
                  if(isset($_GET['ta'])){ 
                    $id_ta = $_GET['ta'];
                    $data = mysqli_query($koneksi,"SELECT * FROM kelas, jurusan, ta, kelas_mapel, mapel, guru where km_guru=guru_id and km_kelas=kelas_id and km_mapel=mapel_id and km_guru='$id_guru' and kelas_jurusan=jurusan_id and kelas_ta=ta_id and ta_id='$id_ta' order by kelas_id desc");
                  }else{
                    $data = mysqli_query($koneksi,"SELECT * FROM kelas, jurusan, ta, kelas_mapel, mapel, guru where km_guru=guru_id and km_kelas=kelas_id and km_mapel=mapel_id and km_guru='$id_guru' and kelas_jurusan=jurusan_id and kelas_ta=ta_id and ta_status='1' order by kelas_id desc");
                  }
                  
                  while($d = mysqli_fetch_array($data)){
                    ?>
                    <tr>
                      <td><?php echo $no++; ?></td>
                      <td><?php echo $d['kelas_nama']; ?></td>
                      <td><?php echo $d['jurusan_nama']; ?></td>
                      <td><?php echo $d['mapel_nama']; ?></td>
                      <td><?php echo $d['guru_nama']; ?></td>
                      <td>
                        <?php 
                        $id_kelas = $d['kelas_id'];
                        $sis = mysqli_query($koneksi,"select * from kelas_siswa where ks_kelas='$id_kelas'");
                        echo mysqli_num_rows($sis);
                        ?>
                      </td>
                      <td>                        
                        <a class="btn btn-success btn-sm" href="kelas_absen.php?km=<?php echo $d['km_id'] ?>"><i class="fa fa-book"></i> Absen & Poin</a>                                              
                      </td>
                    </tr>
                    <?php 
                  }
                  ?>
                </tbody>
              </table>
            </div>
          </div>

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

</div>
<?php include 'footer.php'; ?>