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

<div class="content-wrapper">

  <section class="content-header">
    <h1>
      Data Siswa
      <!-- <small>Data Siswa</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-12">       
        <div class="box box-primary">

          <div class="box-header">
            <h3 class="box-title">Tentang Siswa</h3>            
          </div>
          <div class="box-body">
            <?php 
            $id = $_SESSION['id'];              
            $kelas = mysqli_query($koneksi, "select * from siswa, jurusan where siswa_jurusan=jurusan_id and siswa_id='$id'");
            $k = mysqli_fetch_assoc($kelas);
            $id_siswa = $k['siswa_id'];
            ?>

            <div class="table-responsive">
              <table class="table table-bordered">
                <tr>
                  <th width="30%">Nama Siswa</th>
                  <td><?php echo $k['siswa_nama'] ?></td>
                </tr>
                <tr>
                  <th>NIS</th>
                  <td><?php echo $k['siswa_nis'] ?></td>
                </tr>
                <tr>
                  <th>Kelas</th>
                  <td><?php echo $k['jurusan_nama'] ?></td>
                </tr>
              </table>
            </div>

          </div>

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


    <div class="row">
      <div class="col-lg-6">

        <div class="box box-success">
          <div class="box-header">
            <h3 class="box-title">Riwayat Ketertiban</h3>             
          </div>
          <div class="box-body">
            <div class="table-responsive">
              <table class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th width="1%">NO</th>
                    <th>WAKTU</th>
                    <th>KELAS</th>
                    <th>TAHUN AJARAN</th>
                    <th>KETERTIBAN</th>
                    <th>POINT</th>
                  </tr>
                </thead>
                <tbody>
                  <?php 
                  $no=1;
                  $total = 0;
                  $id = $_SESSION['id']; 
                  $data = mysqli_query($koneksi,"SELECT * FROM input_prestasi, prestasi, kelas, ta where kelas_ta=ta_id and input_prestasi.kelas=kelas_id and input_prestasi.prestasi=prestasi_id and input_prestasi.siswa='$id_siswa'");
                  while($d = mysqli_fetch_array($data)){
                    ?>
                    <tr>
                      <td><?php echo $no++; ?></td>
                      <td><?php echo date('d-m-Y H:i:s', strtotime($d['waktu'])); ?></td>
                      <td><?php echo $d['kelas_nama']; ?></td>
                      <td><?php echo $d['ta_nama']; ?></td>
                      <td><?php echo $d['prestasi_nama']; ?></td>
                      <td class="text-center"><?php echo $d['prestasi_point']; ?></td>
                    </tr>
                    <?php 
                    $total += $d['prestasi_point'];
                  }
                  ?>
                </tbody>
                <tfoot>
                  <tr>
                    <td class="text-center text-bold" colspan="5">TOTAL</td>
                    <td class="bg-green text-center text-bold"><?php echo $total ?></td>
                  </tr>
                </tfoot>
              </table>
            </div>
          </div>
        </div>


      </div>
      <div class="col-lg-6">

        <div class="box box-danger">
          <div class="box-header">
            <h3 class="box-title">Riwayat Pelanggaran</h3>             
          </div>
          <div class="box-body">
            <div class="table-responsive">
              <table class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th width="1%">NO</th>
                    <th>WAKTU</th>
                    <th>KELAS</th>
                    <th>TAHUN AJARAN</th>
                    <th>PELANGGARAN</th>
                    <th>POINT</th>
                  </tr>
                </thead>
                <tbody>
                  <?php 
                  $no=1;
                  $total = 0;
                  $id = $_SESSION['id']; 
                  $data = mysqli_query($koneksi,"SELECT * FROM input_pelanggaran, pelanggaran, kelas, ta where kelas_ta=ta_id and input_pelanggaran.kelas=kelas_id and input_pelanggaran.pelanggaran=pelanggaran_id and input_pelanggaran.siswa='$id_siswa'");
                  while($d = mysqli_fetch_array($data)){
                    ?>
                    <tr>
                      <td><?php echo $no++; ?></td>
                      <td><?php echo date('d-m-Y H:i:s', strtotime($d['waktu'])); ?></td>
                      <td><?php echo $d['kelas_nama']; ?></td>
                      <td><?php echo $d['ta_nama']; ?></td>
                      <td><?php echo $d['pelanggaran_nama']; ?></td>
                      <td class="text-center"><?php echo $d['pelanggaran_point']; ?></td>
                    </tr>
                    <?php 
                    $total += $d['pelanggaran_point'];
                  }
                  ?>
                </tbody>
                <tfoot>
                  <tr>
                    <td class="text-center text-bold" colspan="5">TOTAL</td>
                    <td class="bg-green text-center text-bold"><?php echo $total ?></td>
                  </tr>
                </tfoot>
              </table>
            </div>
          </div>
        </div>

      </div>



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

        <div class="box box-danger">
          <div class="box-header">
            <h3 class="box-title">Riwayat Point Dari Guru Mata Pelajaran</h3>             
          </div>
          <div class="box-body">
           <div class="table-responsive">
            <table class="table table-bordered table-striped" id="table-datatable">
              <thead>
                <tr>
                  <th rowspan="2" width="1">NO</th>
                  <th rowspan="2">TANGGAL</th>
                  <th rowspan="2">KELAS</th>
                  <th rowspan="2">MATA PELAJARAN</th>
                  <th rowspan="2">GURU</th>
                  <th rowspan="2">PRESTASI</th>
                  <th rowspan="2">PELANGGARAN</th>
                  <th class="text-center" colspan="2">POIN</th>           
                </tr>

                <tr>
                  <th class="text-center bg-success">Plus</th>
                  <th class="text-center bg-danger">Minus</th>
                </tr>
              </thead>
              <tbody>
                <?php 
                $no=1;
                $total_plus = 0;
                $total_minus = 0;
                $data = mysqli_query($koneksi,"select * from absen, kelas_mapel, mapel, guru, kelas where absen_siswa='$id' and km_mapel=mapel_id and absen_km=km_id and km_kelas=kelas_id and km_guru=guru_id order by date(absen_tanggal) asc");
                while($d = mysqli_fetch_array($data)){


                  ?>
                  <tr>
                    <td><?php echo $no++; ?></td>
                    <td><?php echo date('d/m/Y', strtotime($d['absen_tanggal'])); ?></td>
                    <td><?php echo $d['kelas_nama']; ?></td>
                    <td><?php echo $d['mapel_nama']; ?></td>
                    <td><?php echo $d['guru_nama']; ?></td>   
                    <td class="text-center">
                      <?php 
                      $id_prestasi = $d['absen_prestasi'];
                      $pres = mysqli_query($koneksi,"select * from prestasi where prestasi_id='$id_prestasi'");
                      $cek = mysqli_num_rows($pres);
                      if($cek > 0){
                        $p = mysqli_fetch_assoc($pres);
                        echo $p['prestasi_nama'];
                        $poin_pres = $p['prestasi_point'];
                      }else{
                        echo "-";
                        $poin_pres = 0;
                      }
                      ?>
                    </td>
                    <td class="text-center">
                      <?php 
                      $id_pelanggaran = $d['absen_pelanggaran'];
                      $pela = mysqli_query($koneksi,"select * from pelanggaran where pelanggaran_id='$id_pelanggaran'");
                      $cek = mysqli_num_rows($pela);
                      if($cek > 0){
                        $p = mysqli_fetch_assoc($pela);
                        echo $p['pelanggaran_nama'];
                        $poin_pela = $p['pelanggaran_point'];
                      }else{
                        echo "-";
                        $poin_pela = 0;
                      }
                      ?>

                    </td>
                    <td class="text-center bg-success">+<?php echo $poin_pres; ?></td>
                    <td class="text-center bg-danger">-<?php echo $poin_pela; ?></td>
                  </tr> 
                  <?php 
                  $total_plus += $poin_pres;
                  $total_minus += $poin_pela;
                }
                ?>                
                <tr>
                  <td class="text-center text-bold" colspan="7">MINUS</td>
                  <td class="text-center text-bold bg-success">+<?php echo $total_plus ?></td>
                  <td class="text-center text-bold bg-danger">-<?php echo $total_minus ?></td>
                </tr>
              </tbody>

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

      </div>



    </div>

  </section>

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