<!doctype html>
<html lang="en">

<head>
    <title>Sistema de Hardmant</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="shortcut icon" href="../img/hardmant3.ico">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>

<body>
<nav class="navbar navbar-light " style="background-color: #005a65;color:#fff;justify-content:center;" >
  <span class="navbar-brand mb-0 h1">HARDMANT- Editar Clientes</span>
</nav>
        <!--<center><h3>
        HARDMANT
        <small class="text-muted">Soluciones Informaticas</small>
        </h3>
        </center> -->
    <div class="container mt-3">
        <div class="row">
            <div class="col-4 offset-4 " >
                <?php
                include_once "../db_empresa.php";
                $conexion = mysqli_connect($db_host, $db_user, $db_pass, $db_database);
                /*------------------------empresa-----
                    $sqlCliente="SELECT id_cliente,nombreCliente
                    from cliente";
                    $resultCliente=mysqli_query($conexion,$sqlCliente);

                */

                
                if ($conexion == false) {
                    echo "Error conexion" . mysqli_error($conexion);
                }
                if (isset($_GET['guardar'])) {
                    $sql = "UPDATE cliente SET
                    empresa='" . $_GET['empresa'] . "',
                    direccion='" . $_GET['direccion'] . "',
                    fono='" . $_GET['fono'] . "',
                    email='" . $_GET['email'] . "',
                    rut='" . $_GET['rut'] . "'
                    
                    
                    WHERE id='" . $_GET['id'] . "';
                    ";
                    $resultado = mysqli_query($conexion, $sql);
                    if ($resultado == false) {
                        ?>
                        <div class="alert alert-danger alert-dismissible fade show" role="alert">
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                                <span class="sr-only">Close</span>
                            </button>
                            <strong><?php echo "Error al actualizar ".mysqli_error($conexion); ?></strong>
                        </div>
                    <?php

                        } else {
                            ?>
                        <div class="alert alert-primary alert-dismissible fade show" role="alert">
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                                <span class="sr-only">Close</span>
                            </button>
                            <strong>Actualizacion exitosa</strong>
                        </div>
                <?php
                    }
                }
                $sql = "SELECT 
                    `id`, 
                    `empresa`, 
                    `direccion`,
                    `fono`,
                    `email`,
                    `rut`                   
                                       
                    FROM `cliente`
                    WHERE id='" . $_GET['id'] . "'
                    ;
                    ";

                $resulSet = mysqli_query($conexion, $sql);
                $row = mysqli_fetch_array($resulSet, MYSQLI_ASSOC);
                ?>
                  <form>
                    <div class="form-group">
                        <label>Nombre de la Empresa</label>
                        <input type="text" class="form-control" name="empresa" value="<?php echo $row['empresa'] ?>">
                    </div>
                    <div class="form-group">
                        <label>Direccion</label>
                        <input type="text" class="form-control" name="direccion" value="<?php echo $row['direccion'] ?>">
                    </div>
                    <div class="form-group">
                        <label>Telefono</label>
                        <input type="text" class="form-control" name="fono" value="<?php echo $row['fono'] ?>">
                    </div>
                    <div class="form-group">
                        <label>Email </label>
                        <input type="email" class="form-control" name="email" value="<?php echo $row['email'] ?>">
                    </div>
                    <div class="form-group">
                        <label>Rut</label>
                        <input type="text" class="form-control" name="rut" value="<?php echo $row['rut'] ?>">
                    </div>
                             


                    
                    
                    
                
                    <input type="hidden" name="id" value="<?php echo $row['id'] ?>">
                    <button type="submit" name="guardar" class="btn btn-primary">Guardar</button>
                    <a href="grillaCliente.php" class="btn btn-warning">Regresar</a>
                </form>
            </div>
        </div>
    </div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>

</html>
<?php
mysqli_close($conexion);
?>