<?php session_start(); ?> <!-- session start -->
<?php include("../include/config.php"); ?> <!-- database connection -->
<?php include("../include/connect_url.php"); ?> <!-- connection url/link folder -->
<?php include("../include/date_time.php"); ?> <!-- date & time format -->
<?php include("../database/account.php"); ?> <!-- query database account -->
<?php include("../include/lang.php"); ?> <!-- language -->
<?php include("../include/session_login.php"); ?> <!-- session login -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title><?php include("../template/title.php"); ?></title>

<link rel="shortcut icon" href="<?php echo $connect_url_data; ?>/favicon.ico" />

<link href="<?php echo $connect_url_data; ?>/css/styles.css" rel="stylesheet" type="text/css" />
<!--[if IE]> <link href="<?php echo $connect_url_data; ?>/css/ie.css" rel="stylesheet" type="text/css"> <![endif]-->
<link rel="stylesheet" href="<?php echo $connect_url_data; ?>/font/font-awesome-4.3.0/css/font-awesome.min.css">

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/download/jquery183.js"></script> 
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/download/jquery192.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/excanvas.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.flot.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.flot.orderBars.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.flot.pie.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.flot.resize.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.sparkline.min.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/tables/jquery.sortable.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/tables/jquery.resizable.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.autosize.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.uniform.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.inputlimiter.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.maskedinput.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.autotab.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.select2.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.dualListBox.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.cleditor.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.ibutton.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.validationEngine.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/globalize/globalize.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/globalize/globalize.culture.de-DE.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/globalize/globalize.culture.ja-JP.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/uploader/plupload.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/uploader/plupload.html4.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/uploader/plupload.html5.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/uploader/jquery.plupload.queue.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/wizards/jquery.form.wizard.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/wizards/jquery.validate.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/wizards/jquery.form.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.collapsible.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.breadcrumbs.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.tipsy.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.progress.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.timeentry.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.colorpicker.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.jgrowl.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.fancybox.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.fileTree.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.sourcerer.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/others/jquery.fullcalendar.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/others/jquery.elfinder.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/forms/jquery.mousewheel.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.easytabs.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/files/bootstrap.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/files/functions.js"></script>

</head>

<body>

<?php    
$query_room2 = mysql_query("SELECT * FROM tbl_room WHERE id='$_GET[room_id]'"); 
while($row= mysql_fetch_assoc($query_room2))
{
    $db_room2_id = $row['id'];
    $db_room2_room_no = $row['room_no'];
    $db_room2_room = $row['room'];
    $db_room2_room_type_id = $row['room_type_id'];
    $db_room2_user_id= $row['user_id'];
    $db_room2_date = $row['date'];
    $db_room2_time = $row['time'];
    $db_room2_a_status = $row['a_status'];
}
?>

<?php
$query_room_type2 = mysql_query("SELECT * FROM tbl_room_type WHERE id='$db_room2_room_type_id'");
while($row= mysql_fetch_assoc($query_room_type2))
{
    $db_room_type2_id = $row['id'];
    $db_room_type2_room_type = $row['room_type'];
}
?>

<?php
$query_room_price2 = mysql_query("SELECT * FROM tbl_room_price WHERE room_id='$db_room2_id' AND a_status=1");
while($row= mysql_fetch_assoc($query_room_price2))
{
    $db_room_price2_id = $row['id'];
    $db_room_price2_price = $row['price'];
}
?>

<?php
$query_room_bed2 = mysql_query("SELECT * FROM tbl_room_bed WHERE room_id='$db_room2_id' AND a_status=1");
while($row= mysql_fetch_assoc($query_room_bed2))
{
    $db_room_bed2_id = $row['id'];
    $db_room_bed2_bed_id = $row['bed_id'];
   
$query_bed2 = mysql_query("SELECT * FROM tbl_bed WHERE id='$db_room_bed2_bed_id'");
while($row= mysql_fetch_assoc($query_bed2))
{
    $db_bed2_id .= "$row[id],";
    $db_bed2_bed .= "<a href='$connect_url_data/room/e/$db_room2_id&type=detele&room_bed_id=$db_room_bed2_id' onclick=\"return confirm('Are you sure you want to delete this bed?')\" class='tablectrl_small bGold tipS' style='color:#fff;'><i class='fa fa-times-circle'></i> $row[bed]</a> ";
}
   
}

if($db_bed2_id){
$db_bed2_id_comp = substr($db_bed2_id, 0, -1);
}
else{
$db_bed2_id_comp = 0;    
}


?>

<?php

if($_POST)
{
$query_room1= mysql_query("SELECT * FROM tbl_room");
while($row= mysql_fetch_assoc($query_room1))
{
    $db_room1_id= $row['id'];
}
    $db_room1_id_add = $db_room1_id + 1;
    $db_room1_id_add_comp = "$date_year$db_room1_id_add";




$room =mysql_real_escape_string(ucwords($_POST['room']));
$room_type =$_POST['room_type'];
$bed = $_POST['bed'];

//number format
include("../include/number_format.php");


$a_status = $_POST['a_status'];

if($room==""){
die ("<script> alert('Please fill room.');
window.location.href='javascript:history.back();';		
</script> ");
}

//room
$sql = "UPDATE tbl_room SET  room='$room', room_type_id = '$room_type', a_status='$a_status' WHERE  id ='$db_room2_id '";
$result = mysql_query($sql) or die("Error: Failed to Update!");

//price
if($price_nf==$db_room_price2_price)
{}else{
$sql = "UPDATE tbl_room_price SET  a_status='2' WHERE room_id ='$db_room2_id ' AND a_status='1'";
$result = mysql_query($sql) or die("Error: Failed to Update!");  
    
$query_insert = mysql_query("
  INSERT INTO tbl_room_price VALUES ('','$db_room2_id','$price_nf','$db_user_id','$date','$time','1');
");
}



for($i=0;$i<sizeof($bed);$i++)
{
//bed
if($bed[$i]){
$query_insert = mysql_query("
 INSERT INTO tbl_room_bed VALUES ('','$db_room2_id','$bed[$i]','$db_user_id','$date','$time','1');
");
}
}


die ("<script> alert('Saved.');
window.close();		
</script> ");
}


if($_GET['type']=="detele"&&$_GET['room_bed_id']){
$sql = "UPDATE tbl_room_bed SET  a_status='2' WHERE id ='$_GET[room_bed_id]' AND a_status='1'";
$result = mysql_query($sql) or die("Error: Failed to Update!");      
    
die ("<script> alert('Deleted.');
window.location.href='$connect_url_data/room/e/$db_room2_id';		
</script> ");   
}
?>

<form name="form" id="form" action="<?php echo $connect_url_data; ?>/room/e/<?php echo $db_room2_id; ?>" class="main" method="POST"  enctype="multipart/form-data">
            <fieldset style="margin-top:-35px;">
                <div class="widget fluid">
                    <div class="whead"><h6><span class="fa fa-edit" style="margin-top:-2px;"></span>&nbsp; <?php echo $lang['Edit Room']; ?></h6></div>
                    
		    <!-- Tabs -->
		<div class="fluid" >
                <div class="widget grid12" style="margin-top:-0px;">       
                    <div class="tabs">
                        <ul>
                            <li><a href="#tabs-1"><?php echo $lang['Room Information']; ?></a></li>
                            <li><a href="#tabs-2"><?php echo $lang['Price']; ?></a></li>
                            <li><a href="#tabs-3"><?php echo $lang['Beds']; ?></a></li>
                        </ul>
			
			
			
                <div id="tabs-1">
		    
		    <div class="formRow">
                        <div class="grid2"><label><?php echo $lang['Room']; ?>:</label></div>
                        <div class="grid10"><input type="text" name="room" id="room" value="<?php echo $db_room2_room; ?>"/></div>
                    </div>
		    
		     <div class="formRow">
                            <div class="grid2"><label><?php echo $lang['Room Type']; ?>:</label></div>
                            <div class="grid10">
                               <?php
				$query_room_type1=mysql_query("SELECT * FROM tbl_room_type WHERE id!='$db_room_type2_id' ORDER BY room_type ASC");
				$option_room_type1="";
				while($row=mysql_fetch_array($query_room_type1)) {
				$option_room_type1 .= "<option value='$row[id]'";
				$option_room_type1 .= ">". $row['room_type'] ."</option>";  }
				?>    
				<select name="room_type" id="room_type"  data-placeholder="Choose" class="select" tabindex="2" style="width:100%;">
                                <?php if($db_room2_room_type_id!=0){echo "<option value='$db_room2_room_type_id'>$db_room_type2_room_type</option>"; }else{echo"<option value=''></option> ";}?>
				<?php echo $option_room_type1; ?>
				</select>
                            </div>             
                    </div>
		    
		    <div class="formRow">
                            <div class="grid2"><label><?php echo $lang['Status']; ?>:</label></div>
                            <div class="grid10">
                               <select name="a_status" id="a_status" class="select" tabindex="2" style="width:100%;">
				<?php
				if($db_room2_a_status==1){
				echo "
				<option value='1' SELECTED>Active</option>
				<option value='2'>Inactive</option>
				";
				}
				if($db_room2_a_status==2){
				echo "
				<option value='2' SELECTED>Inactive</option>
				<option value='1'>Active</option>
				";
				}							
				
				?>
				</select>
                            </div>             
                    </div>
		    
		
		    
	     </div>
	    <!-- end tabs 1 -->
	    
	    <div id="tabs-2">
                
                    <div class="formRow">
                        <div class="grid2"><label><?php echo $lang['Price']; ?>:</label></div>
                        <div class="grid10"><input type="text" name="price" id="price" value="<?php echo $db_room_price2_price; ?>"/></div>
                    </div>    
            </div>
            
              <div id="tabs-3">
                 <div class="formRow">
                            <div class="grid2"><label><?php echo $lang['Beds']; ?>:</label></div>
                            <div class="grid10">
                              <?php echo $db_bed2_bed; ?>
                            </div>             
                    </div>
         
                 <div class="formRow">
                            <div class="grid2"><label><?php echo $lang['Add Beds']; ?>:</label></div>
                            <div class="grid10">
                               <?php
				$query_bed1=mysql_query("SELECT * FROM tbl_bed WHERE id not in ($db_bed2_id_comp) ORDER BY bed ASC");
				$option_bed1="";
				while($row=mysql_fetch_array($query_bed1)) {
				$option_bed1 .= "<option value='$row[id]'";
				$option_bed1 .= ">". $row['bed'] ."</option>";  }
				?>    
				<select name="bed[]" id="bed[]"  data-placeholder="Choose" class="selectMultiple" multiple="multiple" tabindex="2" style="width:100%;">
				<?php echo $option_bed1; ?>
				</select>
                            </div>             
                    </div>
            </div>
	
	    
</div>
</div>	    
<!-- end tabs body -->
                  
                </div>
            </fieldset>
	    
    <div class="formRow">
                    <div class="grid2"></div>
                    <div class="grid10">
			 	<a href="#" class="buttonM bBlue" onclick="document.getElementById('form').submit();"><span class="fa fa-save"></span><span><?php echo $lang['Save']; ?></span></a>
		        <a href="#" class="buttonM bBlue" onclick="window.close();"><span class="fa fa-times-circle"></span><span><?php echo $lang['Cancel']; ?></span></a>
		    </div>
		    
		    </div>
             
</body>
</html>
