<?php 
include("config.php");
include("config2.php");

$number_of_days = $conn->real_escape_string($_POST['number_of_days']);
$nid2 = $conn->real_escape_string($_POST['nid2']);
$customer_name = $conn->real_escape_string($_POST['customer_name']);
$contact_person = $conn->real_escape_string($_POST['contact_person']);

$personal_phn = $conn->real_escape_string($_POST['personal_phn']);
$personal_email = $conn->real_escape_string($_POST['personal_email']);
$address = $conn->real_escape_string($_POST['address']);

$result2 = $conn->real_escape_string($_POST['result2']);

$room_no = $conn->real_escape_string($_POST['room_no']);
$rprice = $conn->real_escape_string($_POST['rprice']);
$tboking = $conn->real_escape_string($_POST['tboking']);
$addition_service = $conn->real_escape_string($_POST['addition_service']);
$pax = $conn->real_escape_string($_POST['pax']);

$cid='0';
	
if($number_of_days>"0"){
//----------------------customer entry -------------------------
$txt = $result2;
foreach (array_map('trim', explode(",", $txt)) as $p) {
    //echo $p . ", ";
	
  // starting date in d-m-Y format
 
list($day, $month, $year) = explode("-", $p);
$date1 = $year . "-" . $month . "-" . $day;

$bresult=mysql_query("select * from bookings WHERE check_in='$date1' and room_no='$room_no' limit 1");
$brow=mysql_fetch_array($bresult);
if($brow == ""){
	mysql_query("INSERT INTO bookings (id ,room_no ,customer_id ,check_in ,user ,status ,created_at ,ostatus ,additional_ser ,addi_pax,rprice)VALUES (NULL , '$room_no', '$cid', '$date1', '$_SESSION[uid]', 'Hold',CURRENT_TIMESTAMP , '0', '$addition_service', '$pax', '$rprice')");
	
}else{
$bresult=mysql_query("select * from bookings WHERE check_in='$date1' and customer_id='$cid' and ostatus='0' and room_no='$room_no'  limit 1");
$brow=mysql_fetch_array($bresult);
if($brow!=""){
	
 mysql_query("update bookings  set additional_ser='$addition_service' , addi_pax='$pax', rprice='$rprice' where id='$brow[id]' limit 1");
	
}
	
} // check if room is booked/hold

} // loop on date
	
	

}	 // end  check selected room

//----------------------end customer entry -------------------------

$bresult=mysql_query("select * from bookings WHERE customer_id='$cid' and ostatus='0' group by room_no asc");
$brow=mysql_fetch_array($bresult);
if($brow!=""){
?>
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="list_table">
  <tbody>
    <tr>
      <th width="10%">Room No</th>
      <th width="39%">Booked/Hold Date</th>
	  <th width="12%">Price</th>
	  <th width="11%">Days</th>
      <th width="11%">Addition Service</th>
      <th width="11%">Addition Service for Person</th>
    <th width="6%">Total</th>
    <th width="6%">Delete</th>
    </tr>
<?php 
do{
	  ?>
    <tr>
      <td><?php echo $brow[room_no]; ?></td>
      <td><?php 
$cresult=mysql_query("select check_in,rprice from bookings WHERE customer_id='$cid' and ostatus='0' and room_no='$brow[room_no]'");
$crow=mysql_fetch_array($cresult);
	$sr=0;
do{
$sr=$sr+1;
echo $crow[check_in].", ";
$rprice=$crow[rprice];
}while($crow=mysql_fetch_array($cresult));
	
		  
		  ?></td>
      <td><?php echo $brow[rprice]; ?></td>
		<td><?php echo $sr; ?></td>
      <td><?php echo $brow[additional_ser]; ?></td>
      <td><?php echo $brow[addi_pax]; ?></td>
     <td><?php $total=$sr*$rprice; echo $total; $gtotal=$gtotal+$total; ?></td>
     <td align="center"> <a href="javascript:void(0);" onClick="delete_hotel('<?php echo $brow[id]; ?>','<?php echo $brow[room_no]; ?>');">Delete</a>
</td>
    </tr>
    
	 <?php 
	  
	  }while($brow=mysql_fetch_array($bresult));
	  ?>
	  <tr>
      <td colspan="5">&nbsp;</td>
      <td>Total </td>
      <td><?php echo $gtotal;?><input name="stotal_taka" type="hidden" id="stotal_taka" value="<?php echo $gtotal;?>" /></td>
      <td align="center">&nbsp;</td>
    </tr>
  </tbody>
</table>
 
<?php
}
	
//----------------------Booking  -------------------------
	
 
//----------------------end Booking  -------------------------

//header("location:add_client.php");
 
//header("location:hotel_new.php?info=Please Select Date of Booking/Hold");
 
?>