<?php
require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");
cek_session_guru();
(isset($_GET['pg'])) ? $pg = $_GET['pg'] : $pg = '';
if ($pg == 'hapus') {
   $id = $_POST['id'];
    delete($koneksi, 'agenda', ['id' => $id]);
}
if ($pg == 'ambil_kelas') {
    $jadwal = $_POST['jadwal'];
    $sql = mysqli_query($koneksi, "SELECT * FROM jadwal_mapel WHERE id_jadwal='" . $jadwal . "' ");
    echo "<option value=''> Pilih Kelas</option>";
   while ($data = mysqli_fetch_array($sql)) {
        echo "<option value='$data[kelas]'>$data[kelas]</option>";
    }
}
if ($pg == 'ambil_kurikulum') {
    $kelas = $_POST['kelas'];
    $sql = mysqli_query($koneksi, "SELECT * FROM kelas WHERE id_kelas='" . $kelas . "' ");
   echo "<option value=''> Pilih Kurikulum</option>";
   while ($data = mysqli_fetch_array($sql)) {
        echo "<option value='$data[kurikulum]'>$data[kurikulum]</option>";
    }
}
if ($pg == 'tambah') {
	           
$data = [
'idjadwal' => $_POST['jadwal'],
'tanggal' => $_POST['tgl'],
'kikd' => $_POST['kd'],
'kurikulum' => $_POST['kurikulum'],
'materi' => $_POST['materi'],
'indikator' => $_POST['indikator'],
'lm' => $_POST['lingkup'],
'tp' => $_POST['tujuan'],
'bulan' => date('m'),
'tahun' => date('Y')

];
            $where = [
                'tanggal' => $_POST['tgl'],
				 'idjadwal' => $_POST['jadwal']
            ];
            $cek = rowcount($koneksi, 'agenda', $where);
            if ($cek == 0) {
      $exec=insert($koneksi,'agenda',$data);
	   echo"ok";
	    }else{
			 echo"gagal";
			}
}
if ($pg == 'tambah_jurnal') {
	            $id=$_POST['id'];
                $pecah = $_POST['pecah'];
				 $hambat = $_POST['hambat'];
				

           
           
$data = [
'hambatan' => $hambat,
'pemecahan' => $pecah

];
      $exec=update($koneksi,'agenda',$data,['id'=>$id]);
	   echo $exec;
	 
			
}
if ($pg == 'edit') {
	           $id= $_POST['id'];
                $mapel= $_POST['mapel'];
                $kelas = $_POST['kelas'];
                $tanggal = $_POST['tgl'];
				 $kikd = $_POST['kd'];
				$harix =date('D',strtotime($_POST['tgl']));
                $ke = $_POST['ke'];
                 $materi = $_POST['materi'];
                $indikator = $_POST['indikator'];
				 $bulan=date('m');
				 $tahun=date('Y');
				 $guru=$_POST['guru'];

	
$data = [
'guru' => $guru,
'mapel' => $mapel,
'kelas' => $kelas,
'harix' => $harix,
'tanggal' => $tanggal,
'ke' => $ke,
'kikd' => $kikd,
'materi' => $materi,
'indikator' => $indikator,
'bulan' => $bulan,
'tahun' => $tahun

];

update($koneksi,'agenda',$data,['id'=>$id]);
}