<?php 
    include("include/connection.php"); 

    session_start();
    $uID=$_SESSION['uID'];
    if(empty($uID))
	{
		header("location: index.php");
	}
?>

<html>
    <head>
        <title>Host record</title>
		<meta charset="utf-8">
   		<meta name="viewport" content="width=device-width, initial-scale=1">

        <link type="text/css" href="bootstrap/css/bootstrap.min.css" rel="stylesheet">

        <link type="text/css" href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
	    <link type="text/css" href="images/icons/css/font-awesome.css" rel="stylesheet">
	    <link type="text/css" href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600' rel='stylesheet'>

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap.min.css">
        <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.6.2/css/buttons.bootstrap.min.css">

    </head>


<div class="container-fluID"> 
    <div class="row">
        <div class="col-sm-12">	
		
                <center>
					<div class="alert alert-success" role="alert">
					<h2><span class="badge badge-secondary">INTERNAL DATA | Host VIEW</span></h2>
					DASHBOARD
					</div>
					
				</center>
                <a href="adminDashboard.php"> <button class="btn btn-primary approve" type="button">HOME</button></a>
                <a href="hosting_add.php"> <button class="btn btn-info approve" type="button">HOSTING</button></a>	
                <a href="devices.php"> <button type="submit" class="btn btn-info"><b> DEVICES </b></button></a>
                <a href="simcards.php"> <button type="submit" class="btn btn-info"><b> SIMCARDS </b></button></a>
                <a href="fleet_view.php"> <button type="submit" class="btn btn-info"><b> FLEET  </b></button></a>
                <a href="clients.php"> <button type="submit" class="btn btn-info"><b> CLIENTS </b></button> </a>
        <body>

        <!--update client-->
				<div class="form-group">
        			<div class="modal fade" id="edit_modal" aria-hidden="true" style="margin-left: 30%">
					<center>
						<form method="POST" action="">
                			<div class="modal-header alert-success">
                    			<h3>Edit Host </h3>
                			</div>
							<div class="modal-body ">    
							    <table class="datatable-1 table  table-striped" >
							        <tr><td>hNo</td><td><input type="text" id="a" name="hNo" readonly /></td></tr>
							        <tr><td>ClientID</td><td><input type="text" id="b" name="clientID1" readonly /></td></tr>
      								<tr><td>SID</td><td><input type="text" id="c" name="sID1" placeholder="Client Name"/></td></tr>
      								<tr><td>Costs</td><td><input type="text" id="d" name="costs1" placeholder="company Name"/></td></tr>
      								<tr><td>startDate</td><td><input type="text" id="e" name="startDate" placeholder="Email"/></td></tr>
      								<tr><td>Description</td><td><input type="text" id="f" name="description" placeholder="Email"/></td></tr>
      								
                                    <tr><td><input type="submit" name="submit" value="Update Client" class="btn btn-primary" /></td></tr>

      								<?php
									if(isset($_POST['submit'])){
										$hNo=$_POST['hNo'];
										$clientID1=$_POST['clientID1'];
										$sID=$_POST['sID1'];
										$costs=$_POST['costs1'];
										$startDate=$_POST['startDate'];
										$description=$_POST['description'];
								
  										if($clientID1!='' && $sID!=''){
											$query45="UPDATE hosting_tbl SET clientID='$clientID1',sID='$sID',costs='$costs',startDate='$startDate',description='$description' WHERE hNo='$hNo'";
											$result45=mysqli_query($link,$query45);
										}
									}
									?>
                    			</table> 
                			</div>
							<div style="clear:both;"></div>
							<div class="modal-footer">
								<button class="btn btn-danger" type="button" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button>
							</div>
						</form>
	    			</center>
					</div>
				</div>
			<!--update client ends-->
            
        <table id="example" class="table table-striped table-bordered" style="width:100%">
            <thead>
                <tr>
                    <th>hNo</th> 
                    <th>Client ID</th> 
                    <th>SID</th>
                    <th>Client Name</th>
                    <th>Service Name</th>
                    <th>Cost</th>
                    <th>startDate</th>
                    <th>Description</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody
                
                 <?php
			  $result = mysqli_query($link,"SELECT * FROM hosting_view ORDER BY hNo ASC limit 200" );
			  		while($row = mysqli_fetch_array($result)) {
			  ?>
			  
                <tr>
				    <td><?php echo  $row['hNo']; ?></td>
				    <td><?php echo  $row['clientID']; ?></td>
                    <td><?php echo  $row['sID']; ?></td>
                    <td><?php echo  $row['clientName']; ?></td>
                    <td><?php echo  $row['serviceName']; ?></td>
                    <td> <?php echo $row['costs'];?></td>
                    <td><?php echo $row['startDate'];?></td>
                    <td><?php echo $row['description'];?></td>
                    <td><button class="btn btn-primary edit" data-toggle="modal" type="button"><i class="glyphicon glyphicon-edit"></i></button>
                    <a href="hosting_delete.php?hNo=<?php echo $row['hNo']; ?>" <button class="btn btn-danger" type="button"><i class="glyphicon glyphicon-trash"></i></button></a></td>
                </td>
                    
                    	<?php  }  ?>

                </tr>
            </tbody>
</table>	  
    </body>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.2/js/buttons.bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.2/js/buttons.print.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.2/js/buttons.colVis.min.js"></script>

<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script>
    $(document).ready(function() {
        var table = $('#example').DataTable( {
            lengthChange: false,
            buttons: [ 'excel']
        } );
     
        table.buttons().container()
            .appendTo( '#example_wrapper .col-sm-6:eq(0)' );
    } );
</script>

<script>
	$(document).ready(function(){
		$('#example').on('click','.edit',function(){
		$('#edit_modal').modal('show');
		$tr = $(this).closest('tr');
		var data = $tr.children("td").map(function(){ 
			return $(this).text();
		}).get();
			console.log(data);
			$('#a').val(data[0]);
			$('#b').val(data[1]);
			$('#c').val(data[2]);
			$('#d').val(data[5]);
			$('#e').val(data[6]);
			$('#f').val(data[7]);
			
		});
	});
</script> 

</html>