 <?php 
$kt = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM bk_kategori"));
$skt = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM bk_sub"));
$jbk = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM bk_pelanggaran"));
$sp1 = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM bk_sp WHERE ket='SP1' AND tapel='$setting[tp]'"));
$sp2 = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM bk_sp WHERE ket='SP2' AND tapel='$setting[tp]'"));
$sp3 = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM bk_sp WHERE ket='SP3' AND tapel='$setting[tp]'"));

?>



                       <div class="row">
                            <div class="col-xl-4">
                                <div class="card widget widget-stats">
                                    <div class="card-body">
                                        <div class="widget-stats-container d-flex">
                                            <div class="widget-stats-icon widget-stats-icon-primary">
                                                <i class="material-icons-outlined">attach_email</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">SURAT PERINGATAN 1</span>
                                                <span class="widget-stats-amount"><?= $sp1 ?></span><p>
                                               
                                            </div>
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
							
                            <div class="col-xl-4">
                                 <div class="card widget widget-stats">
                                    <div class="card-body">
                                        <div class="widget-stats-container d-flex">
                                            <div class="widget-stats-icon widget-stats-icon-success">
                                                <i class="material-icons-outlined">attach_email</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">SURAT PERINGATAN 2</span>
                                                <span class="widget-stats-amount"><?= $sp2 ?></span><p>
                                              
                                            </div>
                                           
                                        </div>
                                    </div>
                                </div>
                            </div>
                          
                            <div class="col-xl-4">
                                <div class="card widget widget-stats">
                                    <div class="card-body">
                                        <div class="widget-stats-container d-flex">
                                            <div class="widget-stats-icon widget-stats-icon-danger">
                                                <i class="material-icons-outlined">attach_email</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">SURAT PERINGATAN 3</span>
                                                <span class="widget-stats-amount"><?= $sp3 ?></span><p>
                                               
                                            </div>
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                           <div class="col-xl-7">
                                <div class="card widget widget-payment-request">
                                    <div class="card-header">
                                        <h5 class="card-title">LOG PELANGGARAN</h5>
										<button id="btnxml" class="btn  btn-light pull-right"><i class="material-icons">storage</i>RESET</button>
                                    </div>
									 
                                    <div class="card-body">
									 <div id='log' ></div> 
									<div class="row">
									  <?php
                            $query = mysqli_query($koneksi, "select * from bk_siswa GROUP BY nis");
                            $no = 0;
                            while ($bk = mysqli_fetch_array($query)):
							$siswa=fetch($koneksi,'siswa',['nis'=>$bk['nis']]);
							$poin = mysqli_fetch_array(mysqli_query($koneksi, "SELECT nis, SUM(poin) AS jml FROM bk_siswa WHERE nis='$siswa[nis]'"));
							   $no++;
                              
                            ?>
									<div class="col-xl-6">
                                         <div class="card-body">
                                        <div class="widget-payment-request-container">
                                            <div class="widget-payment-request-author">
                                                <div class="avatar m-r-sm">
                                                    <img src="../images/user.png" alt="">
                                                </div>
                                                <div class="widget-payment-request-author-info">
                                                    <span class="widget-payment-request-author-name"><?= substr($siswa['nama'],0,12) ?></span>
                                                 <span class="badge badge-secondary">KELAS <?= $siswa['kelas'] ?></span>
														<button class="btn btn-sm btn-primary" type="button" disabled>
														<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
														<?= $poin['jml'] ?>
													</button>
												</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
								<?php endwhile; ?>
                           </div>
						</div> 
					</div>
                   </div>         

						   <div class="col-xl-5">                             				
                                <div class="card widget widget-list">
                                    <div class="card-header">
                                        <h5 class="card-title">INPUT PELANGGARAN</h5>
                                    </div>
                                    <div class="card-body">
                                   
									<form id='forminput' action='' method='post'>
									 <div class="col-md-12">
										<label class="form-label bold">Tanggal</label>
											 <input type='text' name='tanggal' class='datepicker form-control' autocomplete='off' required='true' />
											</div>
											 <div class="col-md-12">
										<label class="form-label bold">Rombel</label>
											<select name="kelas" id="kelas" class="form-select" required="true">
											<?php $k = mysqli_query($koneksi, "select * from kelas GROUP BY kelas"); ?>
											<option value=''> Pilih Rombel</option>
											<?php while ($kls = mysqli_fetch_array($k)) : ?>											
												<option value="<?= $kls['kelas'] ?>"><?= $kls['kelas'] ?></option>
												<?php endwhile; ?>
														</select>
															 </div>
												<div class="col-md-12">
										<label class="form-label bold">Nama Siswa</label>
											<select class="form-select" name="nis" id="nis" required="true">
												</select>
												</div>
												<div class="col-md-12">
												<label class="form-label bold">Kategori</label>
											<select  class='form-select' name="kategori" id="kategori" required >
											 <option value="">Pilih Kategori</option>
											   <?php $ka = mysqli_query($koneksi, "SELECT * FROM bk_kategori"); ?>
												   <?php while ($k = mysqli_fetch_array($ka)) : ?>
													  <option value="<?= $k['id'] ?>"><?= $k['kategori'] ?></option>
																<?php endwhile ?>
																	</select>   
															</div>
															<div class="col-md-12">
															<label class="form-label bold">Sub Karegori</label>
												<select  class='form-select' name="sub" id="sub" required >
							
                                                    </select>   
                                            </div>
											<div class="col-sm-12">
											<label class="form-label bold">Jenis Pelanggaran</label>
											<select  class='form-select' name="jenis" id="jenis" required >
							
                                                    </select>   
                                            </div>
											
                                            <div class="widget-payment-request-actions m-t-lg d-flex">
                                              
                                                <button type="submit" id="blockui-3" class="btn btn-primary flex-grow-1 m-l-xxs">SIMPAN</button>
                                            </div>
                                       
										</form>
										
                                    </div>
                                </div>
                            </div>
						</div>
                       </div>
	<script>
              $("#kelas").change(function() {
            var kelas = $(this).val();
            console.log(kelas);
            $.ajax({
                type: "POST",
                url: "cbtserver_bk/crud_bk.php?pg=ambil_kelas", 
                data: "kelas=" + kelas, 
                success: function(response) { 
                    $("#nis").html(response);
                    console.log(response);
                },
                error: function(xhr, status, error) {
                    console.log(error);
                }
            });
        });
		  $("#kategori").change(function() {
            var kategori = $(this).val();
            console.log(kategori);
            $.ajax({
                type: "POST",
                url: "cbtserver_bk/crud_bk.php?pg=ambil_sub", 
                data: "kategori=" + kategori, 
                success: function(response) { 
                    $("#sub").html(response);
                    console.log(response);
                },
                error: function(xhr, status, error) {
                    console.log(error);
                }
            });
        });
		 $("#sub").change(function() {
            var sub = $(this).val();
            console.log(sub);
            $.ajax({
                type: "POST",
                url: "cbtserver_bk/crud_bk.php?pg=ambil_jenis", 
                data: "sub=" + sub, 
                success: function(response) { 
                    $("#jenis").html(response);
                    console.log(response);
                },
                error: function(xhr, status, error) {
                    console.log(error);
                }
            });
        });
		</script>
		<script>
		$('#forminput').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
      
        $.ajax({
            type: 'POST',
             url: "cbtserver_bk/crud_bk.php?pg=input_bk", 
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
            
                setTimeout(function() {
                    window.location.replace('?');
                }, 2000);

            }
        });
        return false;
    });
</script>
<script>
   $("#btnxml").click(function() {
        var id = $(this).data('id');
        swal({
            title: 'Konfirmasi ',
            text: 'Yakin akan mereset data ini??',
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Ya, Reset!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: '?pg=surat&ac=reset',
                    data: "id=" + id,
                    type: "POST",
                    success: function(respon) {
                        iziToast.info(
            {
                title: 'Sukses!',
                message: 'Data berhasil direset',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'		  
                });
                        setTimeout(function() {
                            window.location.reload();
                        }, 2000);
                    }
                });
            }
            return false;
        })

    });
</script>
<script>

							var autoRefresh = setInterval(
								function() {
									
									$('#log').load('cbtserver_bk/log.php');
								
								}, 1000
							);
						</script>