<?php
require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");
cek_session_admin();
(isset($_GET['pg'])) ? $pg = $_GET['pg'] : $pg = '';

if ($pg == 'hapusmapel') {
  
   $id = $_POST['id'];
    delete($koneksi, 'mata_pelajaran', ['kode_mapel' => $id]);
    }
if ($pg == 'tambahmapel') {
  $kode = str_replace(' ', '', $_POST['kodemapel']);
    $nama = addslashes($_POST['namamapel']);
    $datax = [
                'kode_mapel' => $kode,
				'nama_mapel'=>$nama
    ];
    $cekmapel = rowcount($koneksi, 'mata_pelajaran', ['kode_mapel' => $kode]);
    if ($cekmapel > 1) {
        echo "mapel sudah ada";
    
        } else {
           $exec = insert($koneksi, 'mata_pelajaran', $datax);
            echo $exec;
        }
    }
if ($pg == 'reset') {
 mysqli_query($koneksi, "TRUNCATE siswa");
 mysqli_query($koneksi, "TRUNCATE kelas");
 mysqli_query($koneksi, "TRUNCATE level");
 mysqli_query($koneksi, "TRUNCATE pk");
}
if ($pg == 'hapus') {
    $id = $_POST['id'];
    delete($koneksi, 'siswa', ['id_siswa' => $id]);
}
if ($pg == 'tambahujian') {
  $kode = str_replace(' ', '', $_POST['idujian']);
    $nama = addslashes($_POST['nama']);
    $datax = [
                'id_jenis' => $kode,
				'nama'=>$nama,
				'status'=>'tidak'
    ];
    $cekujian = rowcount($koneksi, 'jenis', ['id_jenis' => $kode]);
    if ($cekujian > 1) {
        echo "ujian sudah ada";
    
        } else {
           $exec = insert($koneksi, 'jenis', $datax);
            echo $exec;
        }
    }
if ($pg == 'hapusujian') {
    $id = $_POST['id'];
    delete($koneksi, 'jenis', ['id_jenis' => $id]);
}
if ($pg == 'ubahujian') {
  $kode = $_POST['idujian'];
    $nama = $_POST['nama'];
	$status = $_POST['status'];
    $datax = [
              
				'nama'=>$nama,
				'status'=>$status
    ];
   
           $exec = update($koneksi, 'jenis', $datax,['id_jenis' => $kode]);
            echo "OK";
        
    }