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

(isset($_GET['pg'])) ? $pg = $_GET['pg'] : $pg = '';

if ($pg == 'resetandro') {
	$data=[
	'sts'=>1
	];
 $id = $_POST['id'];
 update($koneksi, 'reset_andro',$data, ['idsiswa' => $id]);
	
}
if ($pg == 'resetbrowser') {
	$id = $_POST['id'];
	$nil = fetch($koneksi,'nilai',['id_nilai'=>$id]);
	$ids = $nil['id_siswa'];
    $idu = $nil['id_ujian'];
	$idn = $nil['id_nilai'];
  $where=[
  'idnilai'=>$idn
  ];
    $where2 = array(
      
        'id_siswa' => $ids,
        'id_ujian' => $idu
    );
    delete($koneksi, 'nilai',$where2);
   delete($koneksi, 'reset',$where);
	
}
if ($pg == 'hapus') {
    $id = $_POST['id'];
	$nilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM  nilai WHERE id_nilai='$id'"));
	$idsiswa = $nilai['id_siswa'];
	$idujian = $nilai['id_ujian'];
	 $busek = mysqli_fetch_array(mysqli_query($koneksi, "DELETE FROM reset WHERE idsiswa='$idsiswa' AND idnilai='$id' AND idujian='$idujian'"));
    $exec = delete($koneksi, 'nilai', ['id_nilai' => $id]);
  }
  if ($pg == 'reset') {
    $id = $_POST['id'];
	$nilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM  nilai WHERE id_nilai='$id'"));
	$idbank = $nilai['id_bank'];
	$idsiswa = $nilai['id_siswa'];
	$idujian = $nilai['id_ujian'];
	$hapus = mysqli_fetch_array(mysqli_query($koneksi, "DELETE FROM jawaban WHERE id_siswa='$idsiswa' AND id_bank='$idbank' AND id_ujian='$idujian'"));
    $busek = mysqli_fetch_array(mysqli_query($koneksi, "DELETE FROM reset WHERE idsiswa='$idsiswa' AND idnilai='$id' AND idujian='$idujian'"));
    mysqli_fetch_array(mysqli_query($koneksi, "DELETE FROM jodoh WHERE id_siswa='$idsiswa' AND id_bank='$idbank' AND id_ujian='$idujian'"));
	$exec = delete($koneksi, 'nilai', ['id_nilai' => $id]);
  }
  if ($pg == 'selesai') {
    $id = $_POST['idp'];
	 $simpan = mysqli_query($koneksi,"UPDATE nilai SET ujian_selesai='$datetime', browser='1', online='0' WHERE id_nilai='$id'");
	$nilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM  nilai WHERE id_nilai='$id'"));
	$idbank = $nilai['id_bank'];
	$idsiswa = $nilai['id_siswa'];
	$idujian = $nilai['id_ujian'];
	$hapus = mysqli_fetch_array(mysqli_query($koneksi, "DELETE FROM jawaban WHERE id_siswa='$idsiswa' AND id_bank='$idbank' AND id_ujian='$idujian'"));
	 $busek = mysqli_fetch_array(mysqli_query($koneksi, "DELETE FROM reset WHERE idsiswa='$idsiswa' AND idnilai='$id' AND idujian='$idujian'"));
 mysqli_fetch_array(mysqli_query($koneksi, "DELETE FROM jodoh WHERE id_siswa='$idsiswa' AND id_bank='$idbank' AND id_ujian='$idujian'"));
  }
  if ($pg == 'hapus_nilai') {
    
	 $busek = mysqli_fetch_array(mysqli_query($koneksi, "DELETE FROM nilai WHERE status='1'"));
   
  }
?>