<?php
//session_start();
include("../library/inc.connection.php");
include_once "library/inc.library.php";
include_once "library/inc.sesadmin.php";
include_once "library/inc.dataadmin.php";			
//$semester_id = $_SESSION['SES_SEMESTER']; 

$txtsemester = $_POST['txtsemester'];
$txtMapel = $_POST['txtMapel'];
$txtKelas = $_POST['txtKelas'];
$txtptkterdaftar = $_POST['txtptkterdaftar'];

  $sqlShow = pg_query("SELECT nm_mapel FROM tabel_mapel 
  WHERE mata_pelajaran_id='$txtMapel' AND kelompok='S'");
  $dataShow = pg_fetch_array($sqlShow);
  $namamapel =  $dataShow['nm_mapel'];
  
  
  
	#INSERT TABEL KKM
$qcek = pg_query("SELECT * FROM tabel_pembelajaran WHERE rombongan_belajar_id='$txtKelas'
                      AND semester_id = '$txtsemester'
					  AND mata_pelajaran_id = '$txtMapel' ");
if ($cek = pg_fetch_array($qcek)){
	echo "<script>alert('data Pembelajaran sudah ada');
	location.replace('?page=Data-Pembelajaran-Suplemen');</script>";
	
}else{
  

  $sqlSave2="INSERT INTO tabel_pembelajaran VALUES ( 
    	uuid_generate_v4(), '$txtKelas','$txtMapel','$txtsemester','$txtptkterdaftar','0','$namamapel')";
		$simpandata=pg_query($sqlSave2);
		if($simpandata){
	  echo "<script>alert('data pembelajaran suplemen erapor berhasil ditambah')
	       location.replace('?page=Data-Pembelajaran-Suplemen')</script>";
		}
		else{
			  echo "<script>alert('Gagal menyimpan data pembelajaran suplemen erapor, Silahkan ulangi dan isi data dengan benar')
	       location.replace('?page=Data-Pembelajaran-Suplemen')</script>";
		}
}
?>