<?php
$PID = "booking";
session_start();
require_once("../lib/dbconn.php");


$cek1 = getFromTable("select count(id_booking) from tbl_booking");
//$cek2 = $cek1 + 1;
$cek2 = str_pad(((int) $cek1 + 1), 3, "0", STR_PAD_LEFT);
$tgl = date("d");
$bln = date("m");

$kd = "BO-".$bln.$tgl.$cek2;

if ($_POST[p] == "cek_in"){
	$tgl1 = "CURRENT_DATE";
	$tgl2 = getFromTable("select CURDATE() + INTERVAL ".$_POST[lama_inap]." DAY");
	$stat = "cekin";
} else {
	$tgl1 = $_POST[tgl1];
	$tgl2 = $_POST[tgl2];
	$stat = "booking";
}

/*echo "<pre>";
echo print_r($_POST);
echo "</pre>";
die();*/

if ($_POST[p] == "cek_in"){
	mysql_query("insert into tbl_booking (id_booking, jns_room, tgl_cekin, 
				tgl_cekout, kd_inisial, nm_lengkap, nm_panggilan, alamat, 
				kota, kd_negara, no_hp, email, instansi, down_paymen, 
				kd_pos, status_booking, tgl_booking, user_entry, nm_pemesan, guest_type, 
				tgl_lahir, no_ktp, lama_inap, wkt_booking) values 
	            ('$kd', '".$_POST[jns]."', $tgl1, 
	        	$tgl2, '".$_POST[ins]."', '".$_POST[nm_pelanggan]."', '".$_POST[nm_panggilan]."', '".$_POST[alamat]."',
	        	'".$_POST[kota]."', '".$_POST[negara]."', '".$_POST[no_hp]."', '".$_POST[email]."', '".$_POST[instansi]."', ".$_POST[down_paymen].",
	        	'".$_POST[kd_pos]."', '$stat', CURRENT_DATE, '".$_SESSION[nama_usr]."', '".$_POST[nm_pemesan]."', 
	        	'".$_POST[guest_type]."', '".$_POST[tgl_lahir]."', '".$_POST[no_ktp]."', ".$_POST[lama_inap].", CURRENT_TIME)");

	/*
	* @var Insert ke tabel Guest
	*/
	$cek3 = getFromTable("select count(guest_id) from tbl_guest");

	mysql_query("insert into tbl_guest (guest_id, kd_inisial, nm_lengkap,alamat,kota, kd_negara, no_hp, email,
				 tgl_entry, user_entry) values ($cek3, '".$_POST[ins]."', '".$_POST[nm_pelanggan]."', '".$_POST[alamat]."',
				'".$_POST[kota]."', '".$_POST[negara]."', '".$_POST[no_hp]."', '".$_POST[email]."', CURRENT_DATE, '".$_SESSION[nama_usr]."')");
} else {
	mysql_query("insert into tbl_booking (id_booking, jns_room, tgl_cekin, 
				tgl_cekout, kd_inisial, nm_lengkap, nm_panggilan, alamat, 
				kota, kd_negara, no_hp, email, instansi, down_paymen, 
				kd_pos, status_booking, tgl_booking, user_entry, nm_pemesan, guest_type, tgl_lahir, 
				lama_inap, wkt_booking) values 
	            ('$kd', '".$_POST[jns]."', $tgl1, 
	        	$tgl2, '".$_POST[ins]."', '".$_POST[nm_pelanggan]."', '".$_POST[nm_panggilan]."', '".$_POST[alamat]."',
	        	'".$_POST[kota]."', '".$_POST[negara]."', '".$_POST[no_hp]."', '".$_POST[email]."', '".$_POST[instansi]."', ".$_POST[down_paymen].",
	        	'".$_POST[kd_pos]."', '$stat', CURRENT_DATE, '".$_SESSION[nama_usr]."', '".$_POST[nm_pemesan]."', 
	        	'".$_POST[guest_type]."', '".$_POST[tgl_lahir]."', '".$_POST[lama_inap]."', CURRENT_TIME)");

	/*
	* @var Insert ke tabel Guest
	*/
	$cek3 = getFromTable("select count(guest_id) from tbl_guest");

	mysql_query("insert into tbl_guest (guest_id, kd_inisial, nm_lengkap,alamat,kota, kd_negara, no_hp, email,
				 tgl_entry, user_entry) values ($cek3, '".$_POST[ins]."', '".$_POST[nm_pelanggan]."', '".$_POST[alamat]."',
				'".$_POST[kota]."', '".$_POST[negara]."', '".$_POST[no_hp]."', '".$_POST[email]."', CURRENT_DATE, '".$_SESSION[nama_usr]."')");
} 

unset($_SESSION["SELECT_KAMAR"]);
unset($_SESSION["SELECT_TGL1"]);
unset($_SESSION["SELECT_TGL2"]);
if ($_POST[p] == "cek_in"){
	echo "<script language='JavaScript'>document.location='../index2.php?p=cek_in&idx=$kd'</script>";
} else {
	echo "<script language='JavaScript'>document.location='../index2.php?p=input_dp&idx=$kd'</script>";
}
?>