<LINK href="images/index.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
    function refreshAndClose() {
        window.opener.location.reload(true);
        window.close();
    }
</script>
<body onbeforeunload="refreshAndClose();"><?php
include("../index.cma.db.php");
mysql_connect("$server", "$username", "$password");
mysql_select_db("$database");
//----------STEP
$key1 = $_POST['do'];
$key2 = $_POST['do2'];
$key3 = $_POST['do3'];
if ($key1 == "editisi"){

$table1 = $_POST['table'];
$id1 = $_POST['id'];
$berkas_anak1 = $_POST["berkasanak"];
$spdp_nama1 = $_POST["s_nama"];
$spdp_nik1 = $_POST["s_nik"];
$spdp_tgl1 = $_POST["tglspdp"];
$spdp_nomorspdp1 = $_POST["s_nomorspdp"];
$spdp_nolaporan1 = $_POST["s_nolaporan"];
$spdp_terimatgl1 = $_POST["spdpterimatanggal"];
$spdp_dari1 = $_POST["s_spdpdari"];
$spdp_pasal1 = $_POST["s_pasalspdp"];
$query = "UPDATE $table1 Set spdp_namatsk = '$spdp_nama1' where uid = '$id1'";  
$result = mysql_query($query); 
$query = "UPDATE $table1 Set spdp_nik = '$spdp_nik1' where uid = '$id1'";  
$result = mysql_query($query); 
$query = "UPDATE $table1 Set spdp_tgl = '$spdp_tgl1' where uid = '$id1'";  
$result = mysql_query($query); 
$query = "UPDATE $table1 Set spdp_nomorspdp = '$spdp_nomorspdp1' where uid = '$id1'";  
$result = mysql_query($query); 
$query = "UPDATE $table1 Set spdp_nolaporan = '$spdp_nolaporan1' where uid = '$id1'";  
$result = mysql_query($query); 
$query = "UPDATE $table1 Set spdp_terimatgl = '$spdp_terimatgl1' where uid = '$id1'";  
$result = mysql_query($query); 
$query = "UPDATE $table1 Set spdp_dari = '$spdp_dari1' where uid = '$id1'";  
$result = mysql_query($query); 
$query = "UPDATE $table1 Set spdp_pasal = '$spdp_pasal1' where uid = '$id1'";  
$result = mysql_query($query); 
echo "<b>BERHASIL MENYIMPAN ISIAN ANDA SILAHKAN TUTUP JENDELA INI</b>";
}
//----------STEP
if ($key2 == "editsop"){
$table2 = $_POST['table2'];
$id2 = $_POST['id2'];
$a11 = $_POST["11"];
$a12 = $_POST["12"];
$a13 = $_POST["13"];
$a14 = $_POST["14"];
$a15 = $_POST["15"];
$a16 = $_POST["16"];
$a17 = $_POST["17"];
$a18 = $_POST["18"];
$query = "UPDATE $table2 Set berkas_tahap1p17tgl = '$a11' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set berkas_tahap1tgl = '$a12' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set berkas_tahap1p18tgl = '$a13' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set berkas_tahap1p19tgl = '$a14' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set berkas_p20 = '$a15' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set berkas_tahap1p21atgl = '$a16' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set berkas_tahap2tgl = '$a17' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set berkas_limpahp31tgl = '$a18' where uid = '$id2'";  
$result = mysql_query($query); 
//LATE
$query = "UPDATE $table2 Set late_spdp = '0' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set late_spdpkembali = '0' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set late_berkas = '0' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set late_p18 = '0' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set late_p21 = '0' where uid = '$id2'";  
$result = mysql_query($query); 
$query = "UPDATE $table2 Set late_p31 = '0' where uid = '$id2'";  
$result = mysql_query($query); 
echo "<b>BERHASIL MENYIMPAN ISIAN ANDA SILAHKAN TUTUP JENDELA INI</b>";
}
//----------STEP
if ($key3 == "delete"){
$table3 = $_POST['table3'];
$id3 = $_POST['id3'];
$conn = new mysqli($server, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// sql to delete a record
$sql = "DELETE FROM $table3 WHERE uid =$id3";

if ($conn->query($sql) === TRUE) {
    echo "BERHASIL MENGHAPUS  KLIK UNTUK KEMBALI SILAHKAN TUTUP JENDELA INI";
} else {
    echo "Error deleting record: " . $conn->error;
}

$conn->close();
}
?>
