<?php    
$PID = "edit_guest";
$SC = $_SERVER["SCRIPT_NAME"];

require_once("lib/dbconn.php");
require_once("lib/form.php");
require_once("lib/functions.php");


title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  Edit Guest");
if($_POST[cek] == "ceking"){
	mysql_query("update tbl_booking set no_ktp = '".$_POST[no_ktp]."', 
	kd_inisial = '".$_POST[ins]."', nm_lengkap = '".$_POST[nm_pelanggan]."', 
	tgl_lahir = '".$_POST[tgl_lahir]."', alamat = '".$_POST[alamat]."', kota = '".$_POST[kota]."', 
	kd_negara = '".$_POST[negara]."', no_hp = '".$_POST[no_hp]."', email = '".$_POST[email]."', 
	instansi = '".$_POST[instansi]."', guest_type = '".$_POST[guest_type]."' 
	where id_booking = '".$_POST[idx]."' ");
	echo "<script language='JavaScript'>document.location='index2.php?p=".$PID."'</script>";
}


if ($_GET[act] == "act"){
	include_once("keterangan.php");
	
	$r = mysql_query("select a.*, b.keterangan as inisial, c.*, d.keterangan as negara
				from tbl_booking a 
				JOIN tbl_referensi b ON b.id = a.kd_inisial and b.kd = 'INS'
				JOIN tbl_referensi c ON c.id = a.jns_room and c.kd = 'ROM'
				join tbl_referensi d on d.id = a.kd_negara and d.kd = 'NGR'
				where a.id_booking = '".$_GET[idx]."' ");
	$n = mysql_num_rows($r);
	if($n > 0) $d = mysql_fetch_object($r);
	mysql_free_result($r);
	?>
	<div class="ui three column stackable grid">
  	
	<div class="column">
		<form method="POST">
		<h4 class="ui top attached block header">Detail Guest</h4>
		<input type="hidden" name="p" value="<?php echo $PID;?>"/>
		<input type="hidden" name="cek" value="ceking"/>	
		<input type="hidden" name="nm_pemesan" value="">	
			<table width="100%" class="gridtable_form" border="1px">
				<tr>
					<td>Guest ID</td>
					<td>: <input type="text" name="idx" value="<?php echo $d->id_booking; ?>" readonly="readonly"></td>
				</tr>
				
				<tr>
					<td>ID (KTP/SIM/PASPORT)</td>
					<td>: <input type="text" name="no_ktp" value="<?php echo $d->no_ktp; ?>" required="required"></td>
				</tr>
				<tr>
					<td>Initial</td>
					<td>: <?php echo query_inisial("ins",$d->kd_inisial); ?></td>
				</tr>
				<tr>
					<td>Guest Name</td>
					<td>: <input type="text" name="nm_pelanggan" id="nm_lengkap" value="<?php echo $d->nm_lengkap; ?>" required="required"></td>
				</tr>
				<tr>
					<td>Date of Birth</td>
					<td>: <input type="text" name="tgl_lahir" class="tanggal" value="<?php echo $d->tgl_lahir; ?>" required="required"></td>
				</tr>
				<input type="hidden" name="nm_panggilan" value="">
				<tr>
					<td>Address</td>
					<td>: <input type="text" name="alamat" value="<?php echo $d->alamat; ?>" required="required"></td>
				</tr>
				<tr>
					<td>City</td>
					<td>: <input type="text" name="kota" value="<?php echo $d->kota; ?>" required="required"></td>
				</tr>
				<input type="hidden" name="kd_pos" value="" >
				<!--tr>
					<td>Kode Pos</td>
					<td>: <input type="text" name="kd_pos" value="" ></td>
				</tr-->
				<tr>
					<td>Country</td>
					<td>: <?php echo query_negara("negara",$d->kd_negara); ?></td>
				</tr>
				<tr>
					<td>No.Hp</td>
					<td>: <input type="text" name="no_hp" value="<?php echo $d->no_hp; ?>" required="required"></td>
				</tr>
				<tr>
					<td>Email</td>
					<td>: <input type="text" name="email" value="<?php echo $d->email; ?>" required="required"></td>
				</tr>
				<tr>
					<td>Company</td>
					<td>: <input type="text" name="instansi" value="<?php echo $d->instansi; ?>" required="required"></td>
				</tr>
				<tr>
					<td>Guest Type</td>
					<td>: <?php echo query_jnsguest("guest_type",$d->guest_type,"","") ;?> </td>
				</tr>
				<input type="hidden" name="down_paymen" value="0" >
				<tr>
					<td>&nbsp;</td>
					<td>: <input type="submit" value="Submit" class="blue ui mini button"></td>
				</tr>
			</table>
		</form>
		
	</div>	
	<div class="column"></div>	
	<div class="column"></div>
</div>	
	<?php
} else {
	
?>
<table id='mytable' class="gridtable tableWithFloatingHeader" width="100%" border="1px">
	<tr>
		<td class="gridtable_th" align="center">No</td>
		<td class="gridtable_th" align="center">Guest ID</td>
		<td class="gridtable_th" align="center">Check in Date</td>
		<td class="gridtable_th" align="center">No.Room</td>
		<td class="gridtable_th" align="center">Room Type</td>
		<td class="gridtable_th" align="center">Guest</td>
	</tr>
	<?php
	$sql = "select DISTINCT a.*, c.keterangan as inisial, d.*, d.keterangan as negara, f.no_room
			from tbl_booking a 
			join tbl_transaksi b on b.no_booking = a.id_booking
			join tbl_referensi c ON c.id = a.kd_inisial and c.kd = 'INS'
			join tbl_referensi d ON d.id = a.jns_room and d.kd = 'ROM'
			join tbl_referensi e on e.id = a.kd_negara and e.kd = 'NGR'
			join tbl_room f on f.id = b.item_id
			where b.jns_trans = 'ROOM' and a.status_booking = 'cekin' and b.status_trans = 1
			 ";
	$r = mysql_query($sql);
	$n = mysql_num_rows($r);
	
	$no = 1;

while ($row = mysql_fetch_array($r)) {
	?>
	<tr>
		<td class="gridtable_td" align="center"><?php echo $no++; ?></td>
		<td class="gridtable_td" align="center"><a href="<?php echo "$SC?p=$PID&act=act&idx=".$row[id_booking]; ?>"><?php echo $row[id_booking]; ?></a></td>
		<td class="gridtable_td" align="center"><?php echo ucwords(strtolower($row[tgl_cekin])); ?></td>
		<td class="gridtable_td" align="center"><?php echo ucwords(strtolower($row[no_room])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[keterangan])); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[inisial]." ".$row[nm_lengkap])); ?></td>		
	</tr>
	<?php } ?>
</table>

<?php } ?>