<?php
	$id = $_GET["id"];
	
	$hoy = date("Y-m-d H:i:s");


	//CONSULTA PARA NUEVO CLIENTE
	//CONSULTA PARA NUEVO CLIENTE
	if($_POST["boton"] != ""){

		if($_POST["id_registro"] != ""){
			
			mysqli_query($connect,"UPDATE Botones SET boton = '".$_POST["boton"]."', estado = '".$_POST["estado"]."', hora_inicia = '".$_POST["hora_inicia"]."', 
			hora_termina = '".$_POST["hora_termina"]."' WHERE id = '".$_POST["id_registro"]."'  ");
		}
		else{

			mysqli_query($connect,"INSERT INTO Botones (boton, estado, hora_inicia, hora_termina, created_at ) 
			VALUES 
			( '".$_POST["boton"]."', '".$_POST["estado"]."', '".$_POST["hora_inicia"]."', '".$_POST["hora_termina"]."', '".$hoy."' ) ");
		}
		echo '<script>window.location = "?pg=botones";</script>';//para evitar reinsersion
	}

	
	//INFORMACION DE LA BATERIA
	$query = mysqli_query($connect,"SELECT * FROM Botones WHERE id = '".$id."' ");
	$data = mysqli_fetch_array($query);
	
?>





<?php echo $respuesta; ?>

<div class="container-fluid">
	
	<nav aria-label="breadcrumb" style=" margin-top: 10px; margin-bottom: 10px" >
		<ol class="breadcrumb" style="background-color: rgba(0,0,0,0); margin-bottom:0px">
			<li class="breadcrumb-item"><a href="?pg=home">Home</a></li>
			<li class="breadcrumb-item active" aria-current="page"><a href="?pg=botones">Botones</a></li>
			<li class="breadcrumb-item active" aria-current="page">Detalle</li>
		</ol>
	</nav>
	
	<div class="card" style="margin-bottom: 15px">

        <div class="card-body">
      
            <form action="" method="post" enctype="multipart/form-data">
                <div class="row">
                
                    <input type="hidden" name="id_registro" value="<?php echo $id; ?>">

                    <div class="col-md-12 item_input">
                        <label class="ti_label">Boton</label>
						<input type="text" class="form-control" name="boton" required value="<?php echo $data["boton"]; ?>"> 
                    </div>
                    
                    
                    <div class="col-md-12 item_input">
                        <label class="ti_label">Inicia</label>
						<input type="text" class="form-control" name="hora_inicia" value="<?php echo $data["hora_inicia"]; ?>"> 
                    </div>
                    
                    <div class="col-md-12 item_input">
                        <label class="ti_label">Termina</label>
						<input type="text" class="form-control" name="hora_termina"  value="<?php echo $data["hora_termina"]; ?>"> 
                    </div>

					<div class="col-md-4 item_input">
                        <label class="ti_label">Estado</label>
                        <select class="form-control" name="estado" required>
                            <option value="">Selecciona...</option>
                            <?php
                                foreach($Array_Estado as $estado){
									if($estado[0] == $data["estado"]){
										echo '<option value="'.$estado[0].'" selected="selected">'.$estado[1].'</option>';
									}
									else{
										echo '<option value="'.$estado[0].'">'.$estado[1].'</option>';
									}
								}
                            ?>
                        </select>
                    </div>
                    
                  
                   <div class="col-md-12" style="margin-top: 15px; text-align: left;">
                        <button type="submit" class="btn btn-success btn-block" style="border-radius: 30px;">Guardar</button>
                    </div>
                            
                </div>
            </form>
    
        </div>
    </div>


</div>





<style>
.item_input{
	margin-bottom:15px;
}
</style>



<script>
$( document ).ready(function() {
    $("#bt_sala").addClass( "btn-primary" );
});
	

</script>