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

$actget = $_GET['actget'];
$act = $_POST['act'];
$id = $_POST["id"];
$Waktu = $_POST['Waktu'];
$Id_Kapal = $_POST['Id_Kapal'];
$Id_Nahkoda = $_POST['Id_Nahkoda'];
$Kuota_Order = $_POST['Kuota_Order'];
$Dari = $_POST['Dari'];
$Tujuan = $_POST['Tujuan'];
$tanggal = $_POST['tanggal'];
$anak = $_POST['anak'];
$dewasa = $_POST['dewasa'];

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

	$sql="insert into tb_jadwal (Waktu, Id_Kapal, Id_Nahkoda, Kuota_Order, Sisa, Dari, Tujuan, Status, tanggal)  values ('".$Waktu."','".$Id_Kapal."','".$Id_Nahkoda."','".$Kuota_Order."', '".$Kuota_Order."', '".$Dari."', '".$Tujuan."', 1, '".$tanggal."')";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-jadwal"</script>
<?php	

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

	if($tanggal == ''){
		$sql="update tb_jadwal set Waktu = '".$Waktu."', Id_Kapal = '".$Id_Kapal."', Id_Nahkoda = '".$Id_Nahkoda."', Kuota_Order = '".$Kuota_Order."', Dari = '".$Dari."', Tujuan = '".$Tujuan."' where Id_Jadwal = '".$id."'";
		if (!mysql_query($sql,$test)){
		die('Error: ' . mysql_error());
		}
	}else{
		$sql="update tb_jadwal set Waktu = '".$Waktu."', Id_Kapal = '".$Id_Kapal."', Id_Nahkoda = '".$Id_Nahkoda."', Kuota_Order = '".$Kuota_Order."', Dari = '".$Dari."', Tujuan = '".$Tujuan."', tanggal = '".$tanggal."' where Id_Jadwal = '".$id."'";
		if (!mysql_query($sql,$test)){
		die('Error: ' . mysql_error());
		}
	}
?>
<script>window.location = "<?php echo $base?>data-jadwal"</script>
<?php

//NONAKTIF DATA
}elseif($act == 3){
	$sql="update tb_jadwal set Status = '0' where Id_Jadwal = '".$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_jadwal.*, DATE_FORMAT(tb_jadwal.tanggal,'%d-%m-%Y') as tgl, tb_kapal.Nama as namakapal, tb_nahkoda.Nahkoda, pDari.Nama as peldari, pTujuan.Nama as peltujuan
							from tb_jadwal inner join tb_kapal on tb_jadwal.Id_Kapal = tb_kapal.Id_Kapal
							inner join tb_nahkoda on tb_jadwal.Id_Nahkoda = tb_nahkoda.Id_Nahkoda
							inner join tb_pelabuhan pDari on (pDari.Id_Pelabuhan = tb_jadwal.Dari)
							inner join tb_pelabuhan pTujuan on (pTujuan.Id_Pelabuhan = tb_jadwal.Tujuan)
							where tb_jadwal.Status = '1' and Id_Jadwal = '".$id."'
"; 
	$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
	mysql_close($test);

    $query = mysql_fetch_array($hasil);
    echo json_encode($query);
	
}elseif ($actget == 2){

	$id = $_GET['id'];
    $sql = "select tb_detil_angkutan.harga, tb_detil_angkutan.id, tb_angkutan.nama as angkutan, tb_jadwal.Id_Jadwal, 			 		 			
			tb_jadwal.Waktu,tb_jadwal.Id_Kapal,tb_jadwal.Id_Nahkoda,tb_jadwal.Kuota_Order,tb_jadwal.Sisa,tb_jadwal.Dari,tb_jadwal.Tujuan,
			tb_jadwal.Status,tb_jadwal.tanggal, DATE_FORMAT(tb_jadwal.tanggal,'%d-%m-%Y') as tgl, tb_kapal.Nama as namakapal, tb_nahkoda.Nahkoda, 
			pDari.Nama as peldari, pTujuan.Nama as peltujuan 
			from tb_jadwal
			inner join tb_detil_angkutan on tb_jadwal.Id_Jadwal = tb_detil_angkutan.id_jadwal
			inner join tb_angkutan on tb_detil_angkutan.id_angkutan = tb_angkutan.id_angkutan
			inner join tb_nahkoda on tb_jadwal.Id_Nahkoda = tb_nahkoda.Id_Nahkoda
			inner join tb_pelabuhan pDari on (pDari.Id_Pelabuhan = tb_jadwal.Dari)
			inner join tb_pelabuhan pTujuan on (pTujuan.Id_Pelabuhan = tb_jadwal.Tujuan)
			inner join tb_kapal on tb_jadwal.Id_Kapal = tb_kapal.Id_Kapal 
			where tb_jadwal.Id_Jadwal = '".$id."' order by tb_detil_angkutan.id_angkutan asc"; 
	$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
	mysql_close($test);

    $query = mysql_fetch_array($hasil);
    echo json_encode($query);
	
}
elseif ($actget == 3){

	$id = $_GET['id'];
    $sql = "select tb_detil_angkutan.harga, tb_detil_angkutan.id, tb_angkutan.nama as angkutan 
							from tb_jadwal
							inner join tb_detil_angkutan on tb_jadwal.Id_Jadwal = tb_detil_angkutan.id_jadwal
							inner join tb_angkutan on tb_detil_angkutan.id_angkutan = tb_angkutan.id_angkutan 
							where tb_jadwal.Id_Jadwal = '".$id."' order by tb_detil_angkutan.id_angkutan asc"; 
	$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
	mysql_close($test);

    $query = mysql_fetch_array($hasil);
    echo "
	          <table id=\"example1\" class=\"table table-bordered table-striped table-hover\">
             <thead>
                <tr>
                    <th>Jenis Angkutan /Penumpang</th>
                    <th>Harga</th>
                </tr>
            </thead>
            <tbody> ";
				    include("config/connection.php");
              		$sql ="select tb_detil_angkutan.harga, tb_detil_angkutan.id, tb_angkutan.nama as angkutan 
							from tb_jadwal
							inner join tb_detil_angkutan on tb_jadwal.Id_Jadwal = tb_detil_angkutan.id_jadwal
							inner join tb_angkutan on tb_detil_angkutan.id_angkutan = tb_angkutan.id_angkutan 
							where tb_jadwal.Id_Jadwal = '".$id."' order by tb_detil_angkutan.id_angkutan asc";
					$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
					mysql_close($test);
					
					while($row = mysql_fetch_object($hasil)){
						$id = $row->id;
						$harga = $row->harga;
						$angkutan = $row->angkutan;
						
			echo "
            
            		<tr>
                        <td>".$angkutan."</td>
                        <td>Rp.".number_format($harga)."</td>
                    </tr>
					";
					}
			echo "
        	</tbody>
          </table> ";

	
}
elseif ($actget == 4){

	$idjadwal = $_GET['idjadwal'];
	$idangkutan = $_GET['idangkutan'];
    $sql = "select harga from tb_detil_angkutan where id_jadwal = '".$idjadwal."' and id_angkutan = '".$idangkutan."'"; 
	$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
	mysql_close($test);

    $query = mysql_fetch_array($hasil);
    echo json_encode($query);
}elseif ($actget == 5){

	$id = $_GET['id'];
    $sql = "select tb_detil_angkutan_def.harga, tb_detil_angkutan_def.id, tb_angkutan.nama as angkutan 
							from tb_jadwal
							inner join tb_detil_angkutan_def on tb_jadwal.Id_Jadwal = tb_detil_angkutan_def.id_jadwal
							inner join tb_angkutan on tb_detil_angkutan_def.id_angkutan = tb_angkutan.id_angkutan 
							  order by tb_detil_angkutan_def.id_angkutan asc"; 
	$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
	mysql_close($test);

    $query = mysql_fetch_array($hasil);
    echo "
	          <table id=\"example1\" class=\"table table-bordered table-striped table-hover\">
             <thead>
                <tr>
                    <th>Jenis Angkutan /Penumpang</th>
                    <th>Harga</th>
                </tr>
            </thead>
            <tbody> ";
				    include("config/connection.php");
              		$sql ="select tb_detil_angkutan_def.harga, tb_detil_angkutan_def.id, tb_angkutan.nama as angkutan 
							from tb_jadwal
							inner join tb_detil_angkutan_def on tb_jadwal.Id_Jadwal = tb_detil_angkutan_def.id_jadwal
							inner join tb_angkutan on tb_detil_angkutan_def.id_angkutan = tb_angkutan.id_angkutan 
							  order by tb_detil_angkutan_def.id_angkutan asc";
					$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
					mysql_close($test);
					
					while($row = mysql_fetch_object($hasil)){
						$id = $row->id;
						$harga = $row->harga;
						$angkutan = $row->angkutan;
						
			echo "
            
            		<tr>
                        <td>".$angkutan."</td>
                        <td>Rp.".number_format($harga)."</td>
                    </tr>
					";
					}
			echo "
        	</tbody>
          </table> ";

	
}
?>
