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

if ($pg == 'tambah') {
	 $mapel = $_POST['mapel'];
     $dari = $_POST['dari'];
     $sampai = $_POST['sampai'];
     $kelas = $_POST['kelas'];
	 $hari = $_POST['hari'];
	 $guru = $_POST['guru'];
     $jjm = $_POST['jjm'];
	 $jenis = $_POST['jenis'];
	 $honor = $_POST['honor'];
	 $mapel = $_POST['mapel'];
	 
    $data = [
	'kelas' => $kelas,
	'hari' => $hari,
	'dari' => $dari,
	'sampai' => $sampai,
	'mapel' =>$mapel,
	'jjm' => $jjm,
	'guru' => $guru,
	'jenis' => $jenis,
	'honor' => $honor
	];
	
	 $dataxx = [
	'kelas' => $kelas,
	'hari' => $hari,
	'dari' => $dari,
	'sampai' => $sampai,
	'mapel' =>$mapel,
	'jjm' => $jjm,
	'guru' => $guru,
	'jenis' => $jenis
	
	];
   if($jenis==0):  
 $exec = insert($koneksi, 'jadwal_mapel',$data);
    echo $exec;
	else:
	$exec = insert($koneksi, 'jadwal_mapel',$dataxx);
    echo $exec;
	endif;
		  
}
if ($pg == 'hapus') {
    $id = $_POST['id'];
    $exec = delete($koneksi, 'jadwal_mapel', ['idj' => $id]);
    echo $exec;
}
if ($pg == 'agenda') {
    $tanggal = $_POST['tanggal'];
	$kelas = $_POST['kelas'];
	$hadir = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM absensi WHERE tanggal='$tanggal' AND kelas='$kelas' AND ket='H'"));
    $siswa = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$kelas'"));
	$absen = round(($hadir/$siswa)*100);
	if($absen >=50){
		$capai='Tercapai';
	}if($absen <=49){
		$capai = 'Tidak tercapai';
	}
	 $data = [
	'tanggal' =>$tanggal,
	 'kelas' =>$kelas,
	'mapel' =>$_POST['mapel'],
	'kuri' =>$_POST['kuri'],
	'idguru' =>$_POST['guru'],
	'kikd' =>$_POST['kd'],
	'materi' =>$_POST['materi'],
	'indikator' =>$_POST['indikator'],
	'lm' =>$_POST['lm'],
	'tp' =>$_POST['tp'],
	'pencapaian' =>$capai,
	'hadir'=>$hadir,
	'absen'=>$absen
	 ];
	
	 $exec = insert($koneksi, 'agenda',$data);
    echo $exec;
}
if ($pg == 'jurnal') {
    $id = $_POST['id'];
	$data = [
	'hambatan'=>$_POST['hambatan'],
	'pemecahan'=>$_POST['pemecahan']
	];
    $exec = update($koneksi, 'agenda',$data,['id' => $id]);
    echo $exec;
}