<?php 
    session_start();
    include "../conexion/conexion.php";
    include '../validacion.php';
    include '../siguientedia.php';
    
    $idusuario = $_GET['usuario'];

if (isset($_SESSION['start']) && $idrol_sesion == 1 || $idrol_sesion == 4 || $idusuario_sesion == $idusuario) {
    
    $sql = "SELECT * FROM usuario WHERE idusuario='$idusuario'";
    $consulta = $pdo->prepare($sql);
    $consulta->execute();
    $usuarios = $consulta->fetchAll(PDO::FETCH_ASSOC);

    foreach ($usuarios as $gousuario) {

      $nombreusuario = $gousuario['nombreusuario'];
      $tipodocumento = $gousuario['cbotipodocumento'];
      $dni = $gousuario['dni'];
      $correo = $gousuario['correo'];
      $pass = $gousuario['pass'];
      $sede = $gousuario['sede'];
      $turno = $gousuario['turno'];
      $estado = $gousuario['estado'];
      $idrol = $gousuario['idrol'];
      $fechaingreso = $gousuario['fechaingreso'];
      $celular = $gousuario['celular'];    
    }
    
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Editar Usuario - Recursos Humanos</title>
  <?php 
    include '../layout/header.php'; 
  ?>
</head>

<body class="inner_page general_elements">
  <div class="full_container">
    <div class="inner_container">
      <!-- MENÚ  -->
      <?php include '../layout/menu.php'; ?>
      <!-- FIN DEL MENÚ -->
      <!-- right content -->
      <div id="content">
        <!-- SUBMENÚ  -->
        <?php include '../layout/submenu.php'; ?>
        <!-- FIN DEL SUBMENU -->
        <!-- dashboard inner -->
        <div class="midde_cont">
          <div class="container-fluid">
            <div class="row column_title">
              <div class="col-md-12">
                <div class="card-title">
                  <br>
                  <h2>Editar Usuario</h2>
                  <br>
                </div>
              </div>
            </div>
            <!-- row -->
            <form action="validareditarusuario.php?usuario=<?php echo $idusuario; ?>" method="POST">
              <div class="row column4 graph">
                <!-- tab style 1 -->
                <div class="col-md-12">
                  <!-- CUADRO DE CLIENTE-->
                  <div class="card">
                    <div class="card-header" style="background-color:#111638; color:white; font-weight:bold;">
                      <h3 class="card-title">Datos del Usuario</h3>
                    </div>
                    <br>
                    
                    <div class="card-body row">
                      <div class="form-group col-md-4">
                        <label for="exampleInputEmail1">Nombres y Apellidos</label>
                        <input type="text" class="form-control" id="txtnombresyapellidos" value="<?php echo $nombreusuario;?>" name="txtnombreusuario" required placeholder="Nombres y Apellidos" onkeyup="mayus(this)">
                      </div>
                      <div class="form-group col-md-2">
                        <label for="exampleSelectBorderWidth2">Doc. Identidad</label>
                        <select class="form-control rounded-2" name="cbotipodocumento">
                          <option value="DNI" <?php if($tipodocumento == "DNI"){echo "selected";}?>>DNI</option>
                          <option value="CE" <?php if($tipodocumento == "CE"){echo "selected";}?>>CARNET.EXT</option>
                          <option value="PASAPORTE" <?php if($tipodocumento == "PASAPORTE"){echo "selected";}?>>PASAPORTE</option>
                        </select>
                      </div>
                      <div class="form-group col-md-2">
                        <label for="exampleInputEmail1">DNI/C.E/PASAPORTE</label>
                        <input type="text" class="form-control" name="txtnumerodocumento" value="<?php echo $dni;?>" required placeholder="12345678" onkeyup="mayus(this)" maxlength="10">
                      </div>
                      <div class="form-group col-md-2">
                        <label for="exampleSelectBorderWidth2">Turno</label>
                        <select class="form-control rounded-2" name="cboturno">
                          <option value="MANANA" <?php if($turno == "MANANA"){echo "selected";}?>>MAÑANA</option>
                          <option value="TARDE" <?php if($turno == "TARDE"){echo "selected";}?>>TARDE</option>
                        </select>
                      </div>
                      <div class="form-group col-md-2">
                        <label for="exampleInputEmail1">Celular</label>
                        <input type="text" class="form-control" name="txtcelular" value="<?php echo $celular;?>" placeholder="Celular" maxlength="9">
                      </div>
                      <div class="form-group col-md-4">
                        <label for="exampleInputEmail1">Correo</label>
                        <input type="text" class="form-control" name="txtcorreo" value="<?php echo $correo;?>" placeholder="Correo Electrónico" onkeyup="mayus(this)">
                      </div>
                      <div class="form-group col-md-2">
                        <label for="exampleInputEmail1">Contraseña</label>
                        <input type="password" class="form-control" name="txtpass" value="<?php echo $pass;?>">
                      </div>
                      <div class="form-group col-md-3">
                        <label for="exampleSelectBorderWidth2">Estado</label>
                        <select class="form-control rounded-2" name="cbosede">
                            <option value="VALLE SHARON" <?php if($sede == "VALLE SHARON"){echo "selected";}?>>VALLE SHARON</option>
                            <option value="VILLA MARIA" <?php if($sede == "VILLA MARIA"){echo "selected";}?>>VILLA MARIA</option>
                            <option value="SAN JUAN" <?php if($sede == "SAN JUAN"){echo "selected";}?>>SAN JUAN</option>
                        </select>
                      </div>
                    <?php if($idrol_sesion == 1 || $idrol_sesion == 4){ ?>
                      <div class="form-group col-md-3">
                        <label>Fecha Ingreso:</label>
                        <div class="input-group date" id="txtfechanacimiento" data-target-input="nearest">
                          <input type="date" class="form-control datetimepicker-input" value="<?php echo $fechaingreso;?>" name="txtfechaingreso" data-target="#reservationdate" required/>
                        </div>
                      </div>
                      
                      <div class="form-group col-md-3">
                        <label for="exampleSelectBorderWidth2">Estado</label>
                        <select class="form-control rounded-2" name="cboestado">
                            <option value="1" <?php if($estado == "1"){echo "selected";}?>>Pendiente</option>
                            <option value="2" <?php if($estado == "2"){echo "selected";}?>>Activo</option>
                            <option value="2" <?php if($estado == "3"){echo "selected";}?>>Desactivo</option>
                        </select>
                      </div>

                      <div class="form-group col-md-3">
                        <label for="exampleSelectBorderWidth2">Rol</label>
                        <select class="form-control rounded-2" name="cborol">
                            <option value="1" <?php if($idrol == "1"){echo "selected";}?>>Jefe</option>
                            <option value="2" <?php if($idrol == "2"){echo "selected";}?>>Líder de Equipo</option>
                            <option value="3" <?php if($idrol == "3"){echo "selected";}?>>Colaborador</option>
                            <?php if($idrol_sesion == 4){ ?>
                            <option value="4" <?php if($idrol == "4"){echo "selected";}?>>Administrador</option>
                            <?php } ?>
                        </select>
                      </div>
                        
                    <?php } ?>        
                    </div>

                  </div>

                  <div class="card-body row">
                    <div class="col-md-12 mb-3">
                      <a href="" class="btn btn-default">Cancelar</a>
                      <input type="submit" class="btn btn-primary ml-3" value="Continuar">
                    </div>
                  </div>
                </div>
              </div>
            </form>
          </div>
          <!-- FOOTER -->
          <?php include '../layout/footer.php' ?>
          <!-- FIN DEL FOOTER -->
        </div>
        <!-- end dashboard inner -->
      </div>
    </div>
  </div>
  <!-- INCLUYENDO JS. -->
  <!-- <?  ?> -->
</body>
</html>

<?php
} else {
  echo'<script type="text/javascript">alert("Inicie Sesión Nuevamente");window.location.href="../login/login.php";</script>';
}
?>