<?php

session_start();
include "../koneksi.php";
include "../fungsi.php";
require_once "../model/sk_gaji_berkala_model.php";
$obj = new SKGajiBerkala_Model();
$obj->Record($_GET["id_sk"]);
$obj->Delete();
$sql = "UPDATE tbl_usulan_gaji_berkala_detail SET id_sk=null, status='1' WHERE id_sk='" . $_GET["id_sk"] . "'";
mysql_query($sql);
header("location:../../?mod=gb_daftar_sk");
//echo("Data usulan telah disimpan");
$ugbd = array();
$sql_ugbd = "SELECT\n                    \ta.*, b.id_pangkat\n                    FROM\n                    \ttbl_usulan_gaji_berkala_detail a\n                    \tLEFT JOIN tbl_pegawai b ON a.id_pegawai = b.id_pegawai\n                    WHERE\n                    \tid_detail_gaji_berkala='" . $_GET["id_detail_gaji_berkala"] . "'";
$res_ugbd = mysql_query($sql_ugbd);
$ds_ugbd = mysql_fetch_array($res_ugbd);
$ugbd["id_detail_gaji_berkala"] = $ds_ugbd["id_detail_gaji_berkala"];
$ugbd["id_usulan"] = $ds_ugbd["id_usulan"];
$ugbd["id_sk"] = $ds_ugbd["id_sk"];
$ugbd["id_pegawai"] = $ds_ugbd["id_pegawai"];
$ugbd["status"] = $ds_ugbd["status"];
$ugbd["id_pangkat"] = $ds_ugbd["id_pangkat"];
$ugbd["pangkat"] = apa_pangkat($ds_ugbd["id_pangkat"]);
echo "var ugbd = " . json_encode($ugbd) . ";\n";
// DATA : sk_gaji_berkala
require_once "php/model/sk_gaji_berkala_model.php";
$obj = new SKGajiBerkala_Model();
$obj->Record($ugbd["id_sk"]);
$sk["id_sk"] = $obj->id_sk;
$sk["no_sk"] = $obj->no_sk;
$sk["tgl_sk"] = $obj->tgl_sk;
$sk["jabatan_ttd_sk"] = $obj->jabatan_ttd_sk;
$sk["nama_ttd_sk"] = $obj->nama_ttd_sk;
$sk["nip_ttd_sk"] = $obj->nip_ttd_sk;
$sk["id_pangkat_ttd_sk"] = $obj->id_pangkat_ttd_sk;
echo "var sk = " . json_encode($sk) . ";\n";
?>
</script>
<!-- END OF CONTROLLER -->

<!-- JAVASCRIPT PAGE -->
<script type="text/javascript">
<?php

session_start();
include "../koneksi.php";
include "../fungsi.php";
require_once "../model/sk_gaji_berkala_model.php";
function something_wrong($what_is_wrong)
{
    echo "\n            <script type='text/javascript'>\n                window.parent.window.something_wrong(\"" . $what_is_wrong . "\");\n            </script>\n        ";
}
function success()
{
    echo "\n            <script type='text/javascript'>\n                window.parent.window.success();\n            </script>\n        ";
}
$obj = new SKGajiBerkala_Model();
$obj->Record($_POST["id_sk"]);
$obj->no_sk = $_POST["no_sk"];
$obj->tgl_sk = $_POST["tgl_sk"];
$obj->jabatan_ttd_sk = $_POST["jabatan_ttd_sk"];
$obj->nama_ttd_sk = $_POST["nama_ttd_sk"];
$obj->nip_ttd_sk = $_POST["nip_ttd_sk"];
$obj->id_pangkat_ttd_sk = $_POST["id_pangkat_ttd_sk"];
$validation_result = $obj->Validation();
if ($validation_result == "") {
    $obj->Update();
    success();
} else {
    something_wrong($validation_result);
}
//echo("Data usulan telah disimpan");