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

<div class="content-wrapper">

  <section class="content-header">
    <h1>
      Data Kelas
      <!-- <small>Data Kelas</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</h3>
            <div class="btn-group pull-right">
              <a href="kelas_tambah.php" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> &nbsp Tambah Kelas</a>              
            </div>
          </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>TAHUN AJARAN</th>
                    <th>JUMLAH SISWA</th>
                    <th>JUMLAH MAPEL</th>
                    <th width="25%">OPSI</th>
                  </tr>
                </thead>
                <tbody>
                  <?php 
                  $no=1;
                 
                  if(isset($_GET['ta'])){ 
                    $id_ta = $_GET['ta'];
                    $data = mysqli_query($koneksi,"SELECT * FROM kelas, jurusan, ta where 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 where 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['ta_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>
                        <?php 
                        $sis = mysqli_query($koneksi,"select * from kelas_mapel where km_kelas='$id_kelas'");
                        echo mysqli_num_rows($sis);
                        ?>
                      </td>
                      <td>                        
                        <a class="btn btn-success btn-sm" href="kelas_mapel.php?id=<?php echo $d['kelas_id'] ?>"><i class="fa fa-book"></i> Mata Pelajaran</a>
                        <a class="btn btn-primary btn-sm" href="kelas_siswa.php?id=<?php echo $d['kelas_id'] ?>"><i class="fa fa-users"></i> Siswa</a>
                        <a class="btn btn-warning btn-sm" href="kelas_edit.php?id=<?php echo $d['kelas_id'] ?>"><i class="fa fa-cog"></i></a>
                        <a class="btn btn-danger btn-sm" href="kelas_hapus.php?id=<?php echo $d['kelas_id'] ?>"><i class="fa fa-trash"></i></a>
                      </td>
                    </tr>
                    <?php 
                  }
                  ?>
                </tbody>
              </table>
            </div>
          </div>

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

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