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

if ($pg == 'absen') {
   
        $data = [
            'sakit'     => $_POST['sakit'],
             'izin'     => $_POST['izin'],
			  'alpha'     => $_POST['alpha']
        ];
    
    $id = $_POST['idd'];
    $exec = update($koneksi, 'siswa', $data, ['id_siswa' => $id]);
    echo $exec;
}
if ($pg == 'tambahprestasi') {
   $nis=$_POST['nis'];
           $data = [
            
             'prestasi'     => $_POST['pres'],
			  'ket_prestasi'     => $_POST['ket']
        ];


    $exec = update($koneksi, 'siswa', $data,['nis'=>$nis]);
    echo $exec;

}
if ($pg == 'hapusprestasi') {
    $id = $_POST['id'];
    $data = [
            
             'prestasi'     => '',
			  'ket_prestasi'     => ''
        ];

    $exec = update($koneksi, 'siswa', $data,['nis'=>$id]);
    echo $exec;
}
if ($pg == 'catat') {
   
        $data = [
            'catatan'     => $_POST['catat']
          
        ];
    
    $id = $_POST['idd'];
    $exec = update($koneksi, 'siswa', $data, ['id_siswa' => $id]);
    echo $exec;
}
if ($pg == 'tambaheskul') {
	$tahun=date('Y');
    $cekdata = "SELECT * FROM eskul WHERE nis='$_POST[nis]' AND ekstra='$_POST[ekstra]' AND smt='$setting[semester]' AND tahun='$tahun' ";
$jikaada = mysqli_query($koneksi,$cekdata);
if(mysqli_num_rows($jikaada)==0){
	
        $data = [
            'nis'     => $_POST['nis'],
             'ekstra'     => $_POST['ekstra'],
			  'nilai'     => $_POST['nilai'],
			   'ket'     => $_POST['ket'],
			    'smt'     => $setting['semester'],
				 'tahun'     => date('Y')
        ];
    
    $exec = insert($koneksi, 'eskul', $data);
    echo $exec;
}else{
	
}
}
if ($pg == 'hapuseskul') {
    $id = $_POST['id'];
    delete($koneksi, 'eskul', ['id' => $id]);
}