<?php if ($_GET[act]==''){ ?>
            <div class="col-xs-12">  
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title"><?php if (isset($_GET[kelas]) AND isset($_GET[tahun])){ echo "Rekap Absensi siswa"; }else{ echo "Rekap Absensi Siswa Pada Tahun ".date('Y'); } ?></h3>
                  <form style='margin-right:5px; margin-top:0px' class='pull-right' action='' method='GET'>
                    <input type="hidden" name='view' value='rekapabsensiswa'>
                   <?php
					 $tahun = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM tahun_ajaran where aktif='Y'"));
					 $ta = $tahun['idTahunAjaran'];
					?>
					
					<input type="hidden" class="form-control" name="tahun" value="<?php echo $ta ;?>">
                       
                    <select name='kelas' style='padding:4px'>
                         <?php 
                            echo "<option value=''>- Pilih Kelas -</option>";
                            $kelas = mysqli_query($conn,"SELECT * FROM kelas_siswa");
                            while ($k = mysqli_fetch_array($kelas)){
                              if ($_GET[kelas]==$k[idKelas]){
                                 echo "<option value='$k[idKelas]' selected>$k[idKelas] - $k[nmKelas]</option>";
                              }else{
                                echo "<option value='$k[idKelas]'>$k[idKelas] - $k[nmKelas]</option>";
                              }
                            }
                        ?>
                    </select>
                    <input type="submit" style='margin-top:-4px' class='btn btn-success btn-sm' value='Lihat'>
                  </form>

                </div><!-- /.box-header -->
                <div class="table-responsive">
                  <table id="example" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th style='width:20px'>No</th>
						<th>Semester</th>
                        <th>Jadwal Pelajaran</th>
                        <th>Kelas</th>
                        <th>Guru</th>
                        <th>Hari</th>
                        <th>Jam Ke</th>
                        <th>Action</th>
                      </tr>
                    </thead>
                    <tbody>
                  <?php
                    if (isset($_GET[kelas]) AND isset($_GET[tahun])){
                      $tampil = mysqli_query($conn,"SELECT a.*, e.nmKelas, b.namamatapelajaran, b.kode_pelajaran, c.nama_guru FROM rb_jadwal_pelajaran a 
                                            JOIN rb_mata_pelajaran b ON a.kode_pelajaran=b.kode_pelajaran
                                              JOIN rb_guru c ON a.nip=c.nip 
                                             
                                                  JOIN kelas_siswa e ON a.idKelas=e.idKelas 
                                                  where a.idKelas='$_GET[kelas]' 
                                                    AND a.idTahunAjaran='$_GET[tahun]' 
                                                      ORDER BY a.hari DESC");
                    
                    }
                    $no = 1;
                    while($r=mysqli_fetch_array($tampil)){
                    echo "<tr><td>$no</td>
								<td>$r[semester]</td>
                              <td>$r[namamatapelajaran]</td>
                              <td>$r[nmKelas]</td>
                              <td>$r[nama_guru]</td>
                              <td>$r[hari]</td>
                              <td>$r[jam_ke]</td>
                              ";
                              if($_SESSION[level]!='kepala'){
                        echo "<td style='width:70px !important'><center>
                                <a class='btn btn-success btn-xs' title='Tampil List Absensi' href='?view=rekapabsensiswa&act=tampilabsen&id=$r[idKelas]&kd=$r[kode_pelajaran]&jdwl=$r[kodejdwl]&tahun=$_GET[tahun]'><span class='glyphicon glyphicon-th'></span> Tampilkan</a>
                              </center></td>";
                              }
                            echo "</tr>";
                      $no++;
                      }
                  ?>
                    </tbody>
                  </table>
                </div><!-- /.box-body -->
                <?php 
                    if ($_GET[kelas] == '' AND $_GET[tahun] == ''){
                        echo "<center style='padding:60px; color:red'>Silahkan Memilih Kelas Terlebih dahulu...</center>";
                    }
                ?>
                </div>
            </div>
<?php 
}elseif($_GET[act]=='tampilabsen'){
    $d = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM kelas_siswa where idKelas='$_GET[id]'"));
    $m = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM rb_mata_pelajaran where kode_pelajaran='$_GET[kd]'"));
    $n = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM rb_jadwal_pelajaran where kodejdwl='$_GET[jdwl]'"));
    echo "<div class='col-md-12'>
              <div class='box box-info'>
                <div class='box-header with-border'>
                  <h3 class='box-title'>Rekap Data Absensi Siswa </b></h3> <a class='pull-right btn btn-success btn-sm' style='margin-right:5px' target='_blank' href='cetak_absen.php?id=$_GET[id]&kd=$_GET[kd]&jdwl=$_GET[jdwl]&tahun=$_GET[tahun]'><i class='fa fa-print'></i> Cetak Rekap Absen</a>
                </div>
              <div class='table-responsive'>

              <div class='col-md-12'>
              <table class='table table-condensed table-hover'>
                  <tbody>
                    <input type='hidden' name='id' value='$s[idKelas]'>
                   
                    <tr><th width='120px' scope='row'>Nama Kelas</th> <td>$d[nmKelas]</td></tr>
                    <tr><th scope='row'>Mata Pelajaran</th>           <td>$m[namamatapelajaran]</td></tr>
                  </tbody>
              </table>
              </div>

              <form method='POST' class='form-horizontal' action='' enctype='multipart/form-data'>
                <div class='col-md-12'>
                  <table class='table table-condensed table-bordered table-striped'>
                      <thead>
                      <tr>
                        <th>No</th>
                        <th>NIPD</th>
                        <th>Nama Siswa</th>
                        <th>Pertemuan</th>
                        <th>Hadir</th>
                        <th>Sakit</th>
                        <th>Izin</th>
                        <th>Alpa</th>
                        <th><center>% Kehadiran</center></th>
                      </tr>
                    </thead>
                    <tbody>";
                    
                    $no = 1;
                    $tampil = mysqli_query($conn,"SELECT * FROM siswa a where a.idKelas='$_GET[id]' ORDER BY a.idSiswa");
                    while($r=mysqli_fetch_array($tampil)){
                    $total = mysqli_num_rows(mysqli_query($conn,"SELECT * FROM `rb_absensi_siswa` where kodejdwl='$_GET[jdwl]' GROUP BY tanggal"));
                    $hadir = mysqli_num_rows(mysqli_query($conn,"SELECT * FROM `rb_absensi_siswa` where kodejdwl='$_GET[jdwl]' AND nisn='$r[nisnSiswa]' AND kode_kehadiran='H'"));
                    $sakit = mysqli_num_rows(mysqli_query($conn,"SELECT * FROM `rb_absensi_siswa` where kodejdwl='$_GET[jdwl]' AND nisn='$r[nisnSiswa]' AND kode_kehadiran='S'"));
                    $izin = mysqli_num_rows(mysqli_query($conn,"SELECT * FROM `rb_absensi_siswa` where kodejdwl='$_GET[jdwl]' AND nisn='$r[nisnSiswa]' AND kode_kehadiran='I'"));
                    $alpa = mysqli_num_rows(mysqli_query($conn,"SELECT * FROM `rb_absensi_siswa` where kodejdwl='$_GET[jdwl]' AND nisn='$r[nisnSiswa]' AND kode_kehadiran='A'"));
                    $persen = $hadir/($total)*100;
                    echo "<tr bgcolor=$warna>
                            <td>$no</td>
                            <td>$r[nisnSiswa]</td>
                            <td>$r[nmSiswa]</td>
                            <td align=center>$total</td>
                            <td align=center>$hadir</td>
                            <td align=center>$sakit</td>
                            <td align=center>$izin</td>
                            <td align=center>$alpa</td>
                            <td align=right>".number_format($persen, 2)." %</td>";
                    echo "</tr>";
                      $no++;
                      }

                    echo "</tbody>
                  </table>
                </div>
              </div>
            </div>";

}
?>