<?php
$PID = "change_room";
$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' >  Add Key Card to Staff");
	
	$jns_kamar1 = getFromTable("select kd_jenis from tbl_room where id = ".$_SESSION["SELECT_KAMAR_CEKIN"]);
	$nm_kamar = getFromTable("select keterangan from tbl_referensi where kd = 'ROM' and id = $jns_kamar1");
	$kamar = $_SESSION["SELECT_NOMOR_CEKIN"]." - ".$nm_kamar;
	
	$id_kamar_lama = getFromTable("select item_id from tbl_transaksi where jns_trans = 'ROOM' and status_trans = 1 and no_booking = '".$_GET[idx]."' ");
	
	$hrg_kamar = getFromTable("select harga from tbl_referensi where kd = 'ROM' and id = $jns_kamar1");
	$key_kamar = getFromTable("select id_lock from tbl_room where id = ".$_SESSION["SELECT_KAMAR_CEKIN"]);
	?>
	<br/>
	<div class="ui three column stackable grid" align="center">
		<div class="column"></div>
		<div class="column">
			<h4 class="ui top attached block header">Select Room</h4>
			<br/>
			<!--<form action="actions/changeroom_insert.php" method="POST"> -->
			<input type="hidden" name="p" value="<?php echo $PID;?>"/>
			<input type="hidden" name="id_kamar" value="<?php echo $_SESSION["SELECT_KAMAR_CEKIN"];?>"/>
			<input type="hidden" name="id_kamar_lama" value="<?php echo $id_kamar_lama;?>"/>
			<input type="hidden" name="idx" value="<?php echo $_GET["idx"];?>"/>
			<input type="hidden" name="harga" value="<?php echo $hrg_kamar;?>"/>
			<input type="hidden" name="jns_room" value="<?php echo $jns_kamar1;?>"/>
			<input type="hidden" name="tgl_trans" value="<?php echo $tgl_cekinroom;?>"/>
			<table width="100%" class="gridtable_form" border="1px">						
				<tr>
					<td>Select Room</td>
					<td>: <input type="text" name="kamar" value="<?php echo $kamar; ?>" >
						&nbsp;<a href="javascript:cari_kamar('<?php echo $jns_kamar; ?>')"><img src="images/icon-view.png"></a>
					</td>
				</tr>
				<tr>
					<td>ID Room</td>
					<td>: <input type="text" name="key_id" id="key_id" value="<?php echo $key_kamar; ?>" readonly="readonly"></td>
				</tr>
				<?php if($key_kamar):?>
				<tr>
					<td>Staff Name</td>
					<td>: <input type="text" name="staff_name" id="staff_name"></td>
				</tr>				
				<tr>
					<td>Date From</td>
					<td>: <input type="text" name="tgl1" id="tgl1" class="tgl1" value="<?php echo $_SESSION["SELECT_TGL1"]; ?>" >
					<select name="hour_from" id="hour_from">
					<?php
					for($i=0;$i<24;$i++){
						$j=0;
						if($i<=9){
							$j="0".$i;
						}else{
							$j=$i;
						}
						echo '<option value="'.$j.'">'.$j.'</option>';
					}
					
					?>
					</select> : 
					<select name="minute_from" id="minute_from">
					<?php
					for($i=0;$i<60;$i++){
						$j=0;
						if($i<=9){
							$j="0".$i;
						}else{
							$j=$i;
						}
						echo '<option value="'.$j.'">'.$j.'</option>';
					}
					
					?>
					</select>
					</td>
				</tr>
				<tr>
					<td>Date To</td>
					<td>: <input type="text" name="tgl2" id="tgl2" class="tgl2" value="<?php echo $_SESSION["SELECT_TGL2"]; ?>" >
						<select name="hour_to" id="hour_to">
							<?php
							for($i=0;$i<24;$i++){
								$j=0;
								if($i<=9){
									$j="0".$i;
								}else{
									$j=$i;
								}
								echo '<option value="'.$j.'">'.$j.'</option>';
							}
							
							?>
							</select> : 
							<select name="minute_to" id="minute_to">
							<?php
							for($i=0;$i<60;$i++){
								$j=0;
								if($i<=9){
									$j="0".$i;
								}else{
									$j=$i;
								}
								echo '<option value="'.$j.'">'.$j.'</option>';
							}
							
							?>
							</select>
					
					</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td><br/>&nbsp;&nbsp;<input type="button" onClick="cetakKartuStaff()" value="Print Staff Card" ></td>
				</tr>
				<?php endif;?>
				
			</table>
			<!--</form> -->
		</div>
	</div>
	<div class="column"></div>
<script language='JavaScript'>
	function cari_kamar(tag) {
	    sWin = window.open('includes/carikamar3.php?jns='+tag, 'xWin',
	 	'top=0,left=0,width=1200,height=550,menubar=no,scrollbars=yes');
	    sWin.focus();
	}
	function cetakKartuStaff(){
		var key_id=$("#key_id").val();
		var nama = $("#staff_name").val();
		var tgl_ci=$("#tgl1").val();
		var tgl_co=$("#tgl2").val();
		var jam_ci=$("#hour_from").val();
		var mnt_ci=$("#minute_from").val();
		var jam_co=$("#hour_to").val();
		 var mnt_co=$("#minute_to").val();
		var wktu_ci=tgl_ci.replace("-","").replace("-","")+""+jam_ci.replace("-","")+""+mnt_ci;
		var wktu_co=tgl_co.replace("-","").replace("-","")+""+jam_co.replace("-","")+""+mnt_co;
		
		if(nama!=""){
			var booking_id="";
			var idguest="";
			if(parseInt(wktu_co)>parseInt(wktu_ci)){
				sWin = window.open('includes/add_card_staff.php?nomor_room='+key_id+'&tanggal_ci='+wktu_ci+'&tanggal_co='+wktu_co+'&nama='+nama+'&idguest='+idguest+'&booking_id='+booking_id, 'xWin',
	 	'top=0,left=0,width=550,height=550,menubar=no,scrollbars=yes');
	    sWin.focus();
				
			}else{
				alert("Error in duration ");
			}
		}else{
			alert("please insert name");
		}
		
		
	}
</script>
<?php
unset($_SESSION["SELECT_KAMAR_CEKIN"]);
unset($_SESSION["SELECT_NOMOR_CEKIN"]);
?>
	