<?php include("sass/icon_for_datepicker_and_datatable.php");?>
              
        <div class="wrapper row-offcanvas row-offcanvas-left">
            <!-- Left side column. contains the logo and sidebar -->
            <?php include("sass/sidebar.php");?>

            <!-- Right side column. Contains the navbar and content of the page -->
               <aside class="right-side">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                       <?php echo $company_name ; ?>
                        <small>Control panel</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active">Dashboard</li>
                    </ol>
                </section>
                 <section class="content">
                 	 <div class="row">
                        <div class="col-md-12" id="formdiv">
                 <!---Main Content--->

	<?php
$errMsg=""; 
if(isset($_POST['submit'])) // To check 'submmited or not' by if(isset($_POST['submit'])) 
{
	$hotel_id = $_POST['hotel_id'];
	$room_name = $_POST['room_name'];
	
	
	
	if(empty($hotel_id)) $errMsg="enter room name";
	if(empty($errMsg))
	{
		
		$check=mysqli_query($connection,"select * from room where hotel_id = '$hotel_id' and room_name='$room_name'");
		$checkrows=mysqli_num_rows($check);
		if($checkrows>0){$errMsg="You have entered this room Name before";}
		
		else{
		
		mysqli_query($connection,"INSERT INTO`room`(`hotel_id`, `room_name`) VALUES ('$hotel_id', '$room_name') ")
		or die(mysqli_error()); 
		$errMsg="Room Name Entered Successfully";
	}
}
}



 if(isset($_POST['update']))
    {
	
$room_id = $_POST['room_id'];
$hotel_id = $_POST['hotel_id'];
	$room_name = $_POST['room_name'];
	

mysqli_query($connection,"UPDATE room SET hotel_id ='$hotel_id', room_name ='$room_name' WHERE room_id = '$room_id'")
			or die(mysqli_error());  
	$errMsg="Room Name Successfully Updated";
	}

?>
                 <?php
							if (!empty($errMsg))
							{echo "<div class='alert alert-warning alert-dismissible' role='alert'>$errMsg";
							echo "<button type='button' class='close' data-dismiss='alert'><span aria-hidden='false'>&times;</span><span class='sr-only'>		Close</span></button>
                        </div>";}
                        ?>
                 			<div class="box box-primary">
                                <div class="box-header">
                                    <h3 class="box-title">Room List Entry</h3>
                                </div><!-- /.box-header -->
                                <!-- form start -->
                                
                            
                                <form role="form"  action="<?php echo "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post" id="login_form">
                                    <div class="box-body">
                                    	<div class="col-md-12">
                                        <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Hotel Name</label>
											<select name="hotel_id" class="form-control">
												<?php  
                                                $query_bank = "select * from hotel";
                                                $result_bank = mysqli_query($connection,$query_bank);
                                                
                                               
                                                while($row_bank=mysqli_fetch_array($result_bank))
                                                {
                                                
                                                echo "<option value='" . $row_bank['hotel_id'] . "'>" . $row_bank['hotel_name'] . "</option>";}?> 
                                            
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Room Name</label>
                                            <input type="text" class="form-control" name="room_name">
                                        </div>
                                        </div>
                                       
									</div>
												<!-- /.box-body -->

                                    <div class="box-footer">
                                        <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                </form>
                            </div>
                 
                 		</div>
                    </div>
                                          <img src="img/ajax-loader1.gif" style="display: none; margin-left:30%;" id="loading_image" width="50%">      
                 
                 
                 </section>
                 
                 
                 
                 <section class="content">
					<div class="box-body table-responsive" id="tbldiv">

                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>Hotel Name</th>
                                                <th>Room Name</th>                               
                                                <th>Action</th>
                                            </tr>

                                        </thead>
                                        <tbody>
										<?php
                                        
                                        $query = "SELECT * FROM room WHERE branch_id  = '$branch_id_for_header_user'";
                                        $result = mysqli_query($connection,$query);
                                        
										 $i=0;
                                        while($row=mysqli_fetch_array($result))
                                        {
                                        
                                         $i++;
										 $room_id = $row['room_id'];
											$hotel_id = $row['hotel_id'];
											$room_name = $row['room_name'];
                                        
                                        $result_for_stock = mysqli_query($connection,"SELECT hotel_name FROM hotel WHERE hotel_id  = '$hotel_id'");
		$test_for_stock = mysqli_fetch_array($result_for_stock);
				
				$hotel_name=$test_for_stock['hotel_name'];
                                        echo "<tr>
                                        <td>$hotel_name
										<input type='hidden' id='hotel_id$i' value='$hotel_id'/>
										</td>
                                        <td>$room_name
										<input type='hidden' id='room_name$i' value='$room_name'/>
										</td>
                                       
                                        <td>
                                       <input type='hidden' id='zipsearch$i' value='$room_id'/> <button type='button' class='btn btn-primary' data-toggle='modal' data-target='#myModal' onClick='sync$i()'><i class='fa fa-edit'></i> &nbsp;Edit</button>
									   
									   <button type='button' class='btn btn-danger' data-toggle='modal' data-target='#delmodel$i'><i class='fa fa-times'></i> &nbsp;Delete</button>
                                        </td> 
                                        </tr>";
										
										
										echo "<script>
function sync$i()
{
  var collect = document.getElementById('zipsearch$i');
  var entry = document.getElementById('xpaytype');
  
  
  var hotel_idcollect = document.getElementById('hotel_id$i');
  var hotel_identry = document.getElementById('hotel_id');
  
  
  var room_namecollect = document.getElementById('room_name$i');
  var room_nameentry = document.getElementById('room_name');
  
  
  
  entry.value = collect.value;
  hotel_identry.value = hotel_idcollect.value;
  room_nameentry.value = room_namecollect.value;
 
}
</script> ";

echo "<div class='modal fade' id='delmodel$i' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
  <div class='modal-dialog'>
    <div class='modal-content'>
      <div class='modal-header'>
        <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
        <h4 class='modal-title' id='myModalLabel'>Delete Package</h4>
      </div>
      <div class='modal-body'>
    Are You sure you want to delete  $room_name ?
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-default' data-dismiss='modal'>No</button>
        <a href='delete.php?tbl=room&idcol=room_id&id=$room_id&redirect=room'><button type='button' class='btn btn-danger'>Yes</button></a>
      </div>
    </div>
  </div>
</div>";

										
										}	
                                        ?>

                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th>Hotel Name</th>
                                                <th>Room Name</th>                               
                                                <th>Action</th>
                                            </tr>

                                        </tfoot>
                                    </table>
                                    
                                    
                                   <form method='post' action='<?php echo $_SERVER['SCRIPT_NAME']; ?>'>
										<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
  <div class='modal-dialog'>
    <div class='modal-content'>
      <div class='modal-header'>
        <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
        <h4 class='modal-title' id='myModalLabel'>Update room</h4>
      </div>
      <div class='modal-body'>
      <input type="hidden" id='xpaytype' name='room_id' class='form-control'/>
        
                    <div class="form-group">
						<select id='hotel_id' name="hotel_id" class="form-control">
												<?php  
                                                $query_bank = "select * from hotel WHERE branch_id  = '$branch_id_for_header_user'";
                                                $result_bank = mysqli_query($connection,$query_bank);
                                                
                                               
                                                while($row_bank=mysqli_fetch_array($result_bank))
                                                {
                                                
                                                echo "<option value='" . $row_bank['hotel_id'] . "'>" . $row_bank['hotel_name'] . "</option>";}?> 
                                            
                                            </select>
                    </div>
                    <div class="form-group">
                        <input type="text" id='room_name' name="room_name" class="form-control" placeholder="room_name"/>
                    </div>
                    
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
        <button type='submit'  name="update" class='btn btn-primary'>Save</button>
      </div>
    </div>
  </div>
</div>
</form>








                                  
                                </div>
                </section>
                 
                </aside>
                <!-- /.right-side -->
        </div><!-- ./wrapper -->

        <!-- add new calendar event modal -->
<script type="text/javascript">
	 $('#login_form').submit(function() {
	$('#formdiv').hide();
	$('#tbldiv').hide();
    $('#loading_image').show(); // show animation
    return true; // allow regular form submission
});
 </script>

        <!-- jQuery 2.0.2 -->
         <?php include("sass/footer_for_datepicker_and_datatable.php");?>

    </body>
</html>