<?php 
error_reporting(0);
include("config/connection.php");

$actget = $_GET['actget'];
$act = $_POST['act'];
$id = $_POST["id"];
$idjenis = $_POST['idjenis'];
$nama = $_POST['nama'];
$kursi = $_POST['kursi'];

//TAMBAH DATA
if ($act == 1){

	$sql="insert into tb_kapal (Id_Jenis, Nama, Jumlah_Kursi, Status)  values ('".$idjenis."','".$nama."','".$kursi."','1')";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-kapal"</script>
<?php	

//UBAH DATA
}elseif ($act == 2){

	$sql="update tb_kapal set Id_Jenis = '".$idjenis."', Nama = '".$nama."', Jumlah_Kursi = '".$kursi."' where Id_Kapal = '".$id."'";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-kapal"</script>
<?php

//NONAKTIF DATA
}elseif($act == 3){
	$sql="update tb_kapal set Status = '0' where Id_Kapal = '".$id."'";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-kapal"</script>
<?php

//CARI DATA UNTUK EDIT
}elseif ($actget == 1){

	$id = $_GET['id'];
    $sql = "select tb_kapal.*, tb_jenis_kapal.Jenis from tb_kapal inner join tb_jenis_kapal on tb_kapal.Id_Jenis = tb_jenis_kapal.Id where tb_kapal.Status = '1' and Id_Kapal = '".$id."'"; 
	$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
	mysql_close($test);

    $query = mysql_fetch_array($hasil);
    echo json_encode($query);
	
}
?>
