<?php 

//index.php

include_once('include/connection.php');

$query = "
    SELECT * FROM client_tbl
   
";

$result = $link->query($query);

$query1 = "
    SELECT * FROM service_tbl
    ORDER BY serviceName ASC
";

$result1 = $link->query($query1);

?>

<!doctype html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- Bootstrap CSS -->
        <link href="library/bootstrap-5/bootstrap.min.css" rel="stylesheet" />
        <script src="library/bootstrap-5/bootstrap.bundle.min.js"></script>
        <script src="library/dselect.js"></script>
        <link type="text/css" href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
        <title>Internal Data|Fleet record</title>

        
    </head>
    <body>

        <div class="container-fluID">
        <center>
                	<div class="alert alert-success" role="alert">
                    	<h2><span class="badge badge-secondary">CREATE Host </span></h2>
                        	DASHBOARD
                	</div>
            	</center>  

                <div class="form-group">
        
			<form method="POST" action="">
            <a href="hosting_view.php" style="margin: 24.5%;"> <button class="btn btn-info approve" type="button">View Host</button></a>
            <br>
            <br>
            <br>
            
            <div class="row">
                <div class="col-md-3">&nbsp;</div>
                <div class="col-md-6">
                    <tr><td><label for="client" class="form-label">Client </label></td></tr>
                    <tr><td><select name="select_box" class="form-select" id="select_box">
                        <option value="">Select client</option>
                        <?php 
                        foreach($result as $row)
                        {
                            echo '<option value="'.$row["clientID"].'">'.$row["clientName"].'</option>';
                        }
                        ?>  
                    </select></td></tr>
                </div>
                <!-- <div class="col-md-3">&nbsp;</div> -->
            </div>      
            <div class="row">
                <div class="col-md-3">&nbsp;</div>
                <div class="col-md-6">
                <tr></td><label for="device" class="form-label">Service </label></tr>
                <tr></td><select name="select_box1" class="form-select" id="select_box1">
                    <option value="">Select service</option>
                        <?php 
                        foreach($result1 as $row1)
                        {
                            echo '<option value="'.$row1["sID"].'">'.$row1["serviceName"].'</option>';
                        }
                        ?>  
                    </select></td></tr>
                </div>
                <!-- <div class="col-md-3">&nbsp;</div> -->
            </div>  
            <div class="row">
                <div class="col-md-3">&nbsp;</div>
                <div class="col-md-6">
                <label for="email" class="form-label">Cost </label>
                    <input type="interger" class="form-control"  name="costs" value="" required/>
                </div>
                <!-- <div class="col-md-3">&nbsp;</div> -->
            </div>  
            <div class="row">
                <div class="col-md-3">&nbsp;</div>
                <div class="col-md-6">
                <label for="email" class="form-label">startDate </label>
                    <input type="date" class="form-control" name="startDate" value=""/>
                </div>
                <!-- <div class="col-md-3">&nbsp;</div> -->
            </div>  
            <div class="row">
                <div class="col-md-3">&nbsp;</div>
                <div class="col-md-6">
                <label for="email" class="form-label">Description </label>
                    <input type="text" class="form-control" name="description" required value=""/>
                </div>
                <!-- <div class="col-md-3">&nbsp;</div> -->
            </div>  
            <div class="row">
                <div class="col-md-3">&nbsp;</div>
                <div class="col-md-6">
					<input type="submit" class="btn btn-primary" name="submit" value="add" />
                </div>
                <!-- <div class="col-md-3">&nbsp;</div> -->
            </div> 
        
            </div>
         
            </form>

			</div>
            <?php

            if(isset($_POST['submit'])){
            
            $clientID=$_POST['select_box'];
            $sID=$_POST['select_box1'];
            $costs=$_POST['costs'];
            $startDate=$_POST['startDate'];
            $description=$_POST['description'];

            if($costs!='' && $startDate!=''&& $description!=''){
                $query="INSERT INTO hosting_tbl (clientID,sID,costs,startDate,description) values ('$clientID','$sID','$costs','$startDate','$description') ";
                $result=mysqli_query($link,$query);
            }
            }

            ?>

        </div>
    </body>
</html>

<script>

    var select_box_element = document.querySelector('#select_box');

    dselect(select_box_element, {
        search: true
    });

</script>
<script>

    var select_box_element1 = document.querySelector('#select_box1');

    dselect(select_box_element1, {
        search: true
    });

</script>
