<?php if ($_GET[act]==''){ 

$kelas = mysqli_query($conn,"SELECT * FROM kelas_siswa");

?>
            <div class="col-xs-12">  
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title">Daftar Pelanggaran Siswa  </h3>
                  <form style='margin-right:5px; margin-top:0px' class='pull-right' action='' method='GET'>
                    <input type="hidden" name='view' value='bk'>
                   
                    <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>
<!-- <a class='pull-right btn btn-primary btn-sm' style='margin-right:5px'  href='index.php?view=bk&act=tambah'><i class='fa fa-plus'></i> Tambahkan Pelanggaran</a> -->
                </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>Nama Siswa</th>
                        <th>Nama Guru BK</th>
                        <th>Hari</th>
                        <th>Tanggal</th>
                        <th>Pelanggaran</th>
						            <th>Penyelesaian</th>
                       	
                      </tr>
                    </thead>
                    <tbody>
                  <?php
                    if (isset($_GET[kelas])){
                     $ta = mysqli_query($conn,"SELECT * FROM rb_bk where kode_kelas='$_GET[kelas]'");
                    
                    }
                    $no = 1;
                    while($r=mysqli_fetch_array($ta)){
                    echo "<tr><td>$no</td>
                               <td>$r[nama_siswa]</td>
                              <td>$r[penindak]</td>
                              <td>$r[hari]</td>
                              <td>$r[tanggal]</td>
                              <td>$r[pelanggaran]</td>
                              <td>$r[penyelesaian]</td>
                             ";
                                echo "";
                            echo "</tr>";
                      $no++;
					  }
					  if (isset($_GET[hapus])){
                          mysqli_query($conn,"DELETE FROM rb_bk where id_bk='$_GET[hapus]'");
                          echo "<script>document.location='index.php?view=bk';</script>";
                      }
                  ?>
                    <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]=='tambah'){
    if (isset($_POST[tambah])){
        $d = tgl_simpan($_POST[d]);
        mysqli_query($conn,"INSERT INTO rb_bk VALUES('','$_POST[c]','$_POST[a]','$_POST[b]','$_POST[e]','$d','$_POST[f]','$_POST[g]','".date('Y-m-d H:i:s')."','$_SESSION[id]')");
        echo "<script>document.location='index.php?view=bk&kelas=$_POST[kelas]';</script>";
    }

    $e = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM kelas_siswa "));
     $s = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM rb_siswa "));
    echo "<div class='col-md-12'>
              <div class='box box-info'>
                <div class='box-header with-border'>
                  <h3 class='box-title'>Tambah Pelanggaran Siswa</h3>
                </div>
              <div class='box-body'>
              <form method='POST' class='form-horizontal' action='' enctype='multipart/form-data'>
                <div class='col-md-12'>
                  <table class='table table-condensed table-bordered'>
                  <tbody>
                 
                    <tr><th width='140px' scope='row'>Kelas</th>   <td><select class='form-control' name='a'>"; 
                                                $kelas = mysqli_query($conn,"SELECT * FROM kelas_siswa");
                                                while($a = mysqli_fetch_array($kelas)){
                                             
                                                    echo "<option value='$a[idKelas]' selected>$a[nmKelas]</option>";
                                                  }
                                                
                                                echo "</select>
                    </td></tr>
					<tr><th width='140px' scope='row'>Nama Siswa</th>   <td><select class='form-control' name='b'>"; 
                                                $kelas = mysqli_query($conn,"SELECT * FROM rb_siswa");
                                                while($a = mysqli_fetch_array($kelas)){
                                             
                                                    echo "<option value='$a[nama]' selected>$a[nama]</option>";
                                                  }
                                                
                                                echo "</select>
                    </td></tr>
					<tr><th width='140px' scope='row'>Nama Guru BK</th>   <td><select class='form-control' name='e'>"; 
                                                $kelas = mysqli_query($conn,"SELECT * FROM rb_users ");
                                                while($a = mysqli_fetch_array($kelas)){
                                             
                                                    echo "<option value='$a[nama_lengkap]' selected>$a[nama_lengkap]</option>";
                                                  }
                                                
                                                echo "</select>
                    </td></tr>
                    <tr><th scope='row'>Hari</th>  <td><input type='text' class='form-control' value='$hari_ini' name='c'></td></tr>
                    <tr><th scope='row'>Tanggal</th>  <td><input type='text' style='border-radius:0px; padding-left:12px' class='datepicker form-control' value='".date('d-m-Y')."' name='d' data-date-format='dd-mm-yyyy'></td></tr>
                    <tr><th scope='row'>Pelanggaran</th>  <td><textarea style='height:80px' class='form-control' name='f'></textarea></td></tr>
                    <tr><th scope='row'>Penyelesaian</th>  <td><textarea style='height:160px'  class='form-control' name='g'></textarea></td></tr>
                    </td></tr>
                  </tbody>
                  </table>
                </div>
              </div>
              <div class='box-footer'>
                    <button type='submit' name='tambah' class='btn btn-info'>Tambahkan</button>
                    <a href='#'><button type='button' class='btn btn-default pull-right'>Cancel</button></a>
                    
                  </div>
              </form>
            </div>";

}elseif($_GET[act]=='edit'){
    if (isset($_POST[update])){
        $d = tgl_simpan($_POST[d]);
        mysqli_query($conn,"UPDATE rb_bk SET hari = '$_POST[a]',
                                                idKelas = '$_POST[b]',
                                                nama_siswa = '$_POST[c]',
                                                penindak = '$_POST[d]',
                                                tanggal = '$_POST[e]',
												pelanggaran = '$_POST[f]',
												penyelesaian = '$_POST[g]',
                                                users = '$_SESSION[id]' where id_bk='$_POST[id]'");
        echo "<script>document.location='index.php?view=bk&kelas=$_POST[kelas]';</script>";
    }
    $edit = mysqli_query($conn,"SELECT * FROM rb_bk where id_bk='$_GET[id]'");
    $s = mysqli_fetch_array($edit);
	 $e = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM kelas_siswa "));
	 echo "<div class='col-md-12'>
              <div class='box box-info'>
                <div class='box-header with-border'>
                  <h3 class='box-title'>Edit Pelanggaran Siswa</h3>
                </div>
              <div class='box-body'>
              <form method='POST' class='form-horizontal' action='' enctype='multipart/form-data'>
                <div class='col-md-12'>
                  <table class='table table-condensed table-bordered'>
                <tbody>
                    <input type='hidden' name='id' value='$s[id_bk]'>
				
                    <tr><th width='140px' scope='row'>Hari</th> <td><input type='text' class='form-control' name='a' value='$s[hari]'> </td></tr>
					<tr><th width='140px' scope='row'>Kelas</th>   <td><select class='form-control' name='b'>"; 
                                                $kelas = mysqli_query($conn,"SELECT * FROM kelas_siswa");
                                                while($a = mysqli_fetch_array($kelas)){
                                             
                                                    echo "<option value='$a[idKelas]' selected>$a[nmKelas]</option>";
                                                  }
                                                
                                                echo "</select>
                  <tr><th width='140px' scope='row'>Nama Siswa</th>   <td><select class='form-control' name='c'>"; 
                                                $kelas = mysqli_query($conn,"SELECT * FROM rb_siswa");
                                                while($a = mysqli_fetch_array($kelas)){
                                             
                                                    echo "<option value='$a[nama]' selected>$a[nama]</option>";
                                                  }
                                                
                                                echo "</select>
                    </td></tr>
					<tr><th width='140px' scope='row'>Nama Penindak</th>   <td><select class='form-control' name='d'>"; 
                                                $kelas = mysqli_query($conn,"SELECT * FROM rb_guru");
                                                while($a = mysqli_fetch_array($kelas)){
                                             
                                                    echo "<option value='$a[nama_guru]' selected>$a[nama_guru]</option>";
                                                  }
                                                
                                                echo "</select>
                    </td></tr><tr><th scope='row'>Tanggal</th>    <td><input type='text' class='form-control' name='e' value='$s[tanggal]'></td></tr>
                    <tr><th scope='row'>Pelanggaran</th>  <td><input type='text' class='form-control' name='f' value='$s[pelanggaran]'></td></tr>
                    <tr><th scope='row'>Penyelesaian</th>            <td><input type='text' class='form-control' name='g' value='$s[penyelesaian]'></td></tr>
       
                  ";
                                                                 
                  echo "
                  </tbody>
                  </table>
                </div>
              </div>
              <div class='box-footer'>
                    <button type='submit' name='update' class='btn btn-info'>Update</button>
                    <a href='#'><button type='button' class='btn btn-default pull-right'>Cancel</button></a>
                    
                  </div>
              </form>
            </div>";
}
?>