<?php
require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");

(isset($_GET['pg'])) ? $pg = $_GET['pg'] : $pg = '';
if ($pg == 'hapus') {
    $id = $_POST['id'];
	
    delete($koneksi, 'm_produktif', ['idt' => $id]);
	
}
if ($pg == 'setting') {
   $datax=[
	'tingkat'=>$_POST['tingkat']
	];
	$data=[
	'tgl_lulus'=>$_POST['tanggal']
	];
   $exec = update($koneksi, 'aplikasi', $data, ['id_aplikasi' => 1]);
   $exec = update($koneksi, 'skl', $datax, ['id_skl' => 1]);
	echo $exec;
}
if ($pg == 'ubahpk') {
    $idpk = $_POST['idpk'];
	$nama = $_POST['nama'];
	$study = $_POST['study'];
  $exec = mysqli_query($koneksi,"UPDATE kelas SET nama_pk='$nama',program_study='$study' WHERE idpk='$idpk'");
	
}
if ($pg == 'tambahsku') {
    $idpk = $_POST['idpk'];
	$sku = $_POST['sku'];
	$jjm = $_POST['jjm'];
	$kode = $_POST['kode'];
	$where=[
	'pk'=>$idpk,
	'kode'=>$kode
	];
	 $cek = rowcount($koneksi, 'm_produktif', $where);
            if ($cek == 0) {
         $exec = mysqli_query($koneksi,"INSERT INTO m_produktif(pk,kode,sku,jjm) VALUES('$idpk','$kode','$sku','$jjm')");    
            echo "OK";
        }else{
			echo"GAGAL";
		}
 
	
}
if ($pg == 'ambil_kelas') {
    $level = $_POST['level'];
    $sql = mysqli_query($koneksi, "SELECT * FROM siswa WHERE level='" . $level . "' GROUP BY id_kelas");
    echo "<option value=''>Pilih Kelas</option>";
   while ($data = mysqli_fetch_array($sql)) {
        echo "<option value='$data[id_kelas]'>$data[id_kelas]</option>";
    }
}
if ($pg == 'ambil_mapel') {
    $klp = $_POST['kelompok'];
    $sql = mysqli_query($koneksi, "SELECT * FROM mata_pelajaran WHERE kelompok='" . $klp . "' ");
    echo "<option value=''>--Pilih Mapel--</option>";
   while ($data = mysqli_fetch_array($sql)) {
        echo "<option value='$data[kode_mapel]'>$data[nama_mapel]</option>";
    }
}
if ($pg == 'ambil_sku') {
    $kelas = $_POST['kelas'];
    $sql = mysqli_query($koneksi, "SELECT * FROM kelas JOIN m_produktif ON m_produktif.pk=kelas.idpk WHERE id_kelas='" . $kelas . "' ");
    echo "<option value=''>--Pilih Kompetensi--</option>";
   while ($data = mysqli_fetch_array($sql)) {
        echo "<option value='$data[kode]'>$data[sku]</option>";
    }
}
if ($pg == 'kelas') {
    $tingkat = $_POST['tingkat'];
    $sql = mysqli_query($koneksi, "SELECT * FROM siswa WHERE level='" . $tingkat . "' GROUP BY id_kelas");
    echo "<option value=''>--Pilih Kelas--</option>";
   while ($data = mysqli_fetch_array($sql)) {
        echo "<option value='$data[id_kelas]'>$data[id_kelas]</option>";
    }
}