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

if ($pg == 'tambah') {
  $where = [
  'idpeg' => $_POST['id'],		
    ];
    $data = [
'idpeg' => $_POST['id'],
'nokartu' => $_POST['nokartu'],
'nama' => $_POST['nama'],
'level' =>'pegawai'
    ];
	
 $cek = rowcount($koneksi, 'datarfid', $where);
            if ($cek == 0) {
            $exec = insert($koneksi, 'datarfid', $data);
            echo $exec;
if ($exec){
mysqli_query($koneksi, "delete from tmprfid");
			}
		}

}
if ($pg == 'hapus_peg') {
    $id = $_POST['id'];
    delete($koneksi, 'datarfid', ['idpeg' => $id]);
}
if ($pg == 'hapus_siswa') {
    $id = $_POST['id'];
    delete($koneksi, 'datarfid', ['idsiswa' => $id]);
	mysqli_query($koneksi, "update siswa SET sts='0' WHERE id_siswa='$_POST[id]'");
}
if ($pg == 'tambah_siswa') {
  $where = [
  'idsiswa' => $_POST['id'],		
    ];
    $data = [
'idsiswa' => $_POST['id'],
'nokartu' => $_POST['nokartu'],
'nama' => $_POST['nama'],
'level' =>'siswa'
    ];
	
 $cek = rowcount($koneksi, 'datarfid', $where);
            if ($cek == 0) {
            $exec = insert($koneksi, 'datarfid', $data);
            echo $exec;
if ($exec){
mysqli_query($koneksi, "delete from tmprfid");
mysqli_query($koneksi, "update siswa SET sts='1' WHERE id_siswa='$_POST[id]'");
			}
		}

}