<?php
    include ("conexion.php");
    $conexion=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
    if(!$conexion)
    {
        die("Error connecting to databse ".mysqli_connect_error());
    }
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>CONTROL ESP32</title>
    <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css?h=8b0ee9ac812eb0acc7602d49cbc208d5">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="assets/fonts/fontawesome5-overrides.min.css?h=320bd0471c3e8d6b9dd55c98e185506c">
</head>

<body class="bg-gradient-primary">
    <div class="container">
        <div class="card shadow-lg o-hidden border-0 my-5">
            <div class="card-body p-0">
                        <div class="p-5">
                            <div class="text-center">
                                <h4 class="text-dark mb-4">Registro de Usuarios</h4>
                            </div>
                            <?php
                                if($_SERVER["REQUEST_METHOD"] == "POST")
                                {
                                    $nombres=$_POST["nombres"];
                                    $sql=mysqli_query($conexion,"select * from usuarios where nombres='$nombres';");
                                    while($row=mysqli_fetch_array($sql))
                                    {
                                        $password=$row["PASSWORD"];
                                        $telefono=$row["TELEFONO"];
                                        $cargo=$row["CARGO"];
                                        $direccion=$row["DIRECCION"];
                                        $tag=$row["TAG"];
                                    }
                                }
                            ?>
                            <form class="user" method="post" action="guardar_usuario2.php">
                                <div class="form-group row">
                                    <input class="form-control form-control-user" type="text" value="<?php echo $nombres ?>" name="nombres" required="" onKeyUp="this.value=this.value.toUpperCase();">
                                </div>
                                <div class="form-group row">
                                    <input class="form-control form-control-user" type="password" value="<?php echo $password ?>" name="password">
                                </div>
                                <div class="form-group row">
                                    <input class="form-control form-control-user" type="text" value="<?php echo $telefono ?>" name="telefono" required="" inputmode="numeric">
                                </div>
                                <div class="form-group row">
                                    <select class="form-control" style="border-radius: 10PX;" name="cargo">
                                        <optgroup label="SELECCIONE CARGO">
                                            <option value="<?php echo $cargo ?>" selected=""><?php echo $cargo ?></option>
                                            <?php
                                                if ($cargo=="MONITOREO")
                                                    echo "<option value='ADMINISTRADOR'>ADMINISTRADOR</option>";
                                                else
                                                     echo "<option value='MONITOREO'>MONITOREO</option>";
                                            ?>
                                            
                                            
                                        </optgroup>
                                    </select>
                                </div>
                                <div class="form-group row">
                                    <input class="form-control form-control-user" type="text" value="<?php echo $direccion ?>" name="direccion" onKeyUp="this.value=this.value.toUpperCase();">
                                </div>
                                <div class="form-group row">
                                    <select class="form-control" style="border-radius: 10PX;" name="tag">
                                        <optgroup label="SELECCIONE TAG">
                                            <option value="<?php echo $tag ?>" selected=""><?php echo $tag ?></option>
                                            <?php
                                                $sql=mysqli_query($conexion,"select tag from tags where estado='SIN ASIGNAR';");
                                                while($row=mysqli_fetch_array($sql))
                                                {
                                                    echo "<option value='".$row['tag']."'>".$row["tag"]."</option>";
                                                }
                                            ?>
                                            
                                        </optgroup>
                                    </select></div>
                                    <div class="form-group row">
                                    <input class="form-control form-control-user invisible" type="text" value="<?php echo $nombres ?>" name="nombres2" >
                                     </div>
                                    <button class="btn btn-primary btn-block text-white btn-user" type="submit">Registrar Usuario</button>
                                <hr>
                            </form>
                           
                            <a class="btn btn-primary btn-block text-white btn-user" type="submit" href="principal.php">Regresar</a>
                                <hr>
                                <hr>
                            
                        </div>
                    
                
            </div>
        </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.js"></script>
    <script src="assets/js/script.min.js?h=99c003fa89398340e3d8f90406f57bdc"></script>
</body>

</html>