<?php
session_start();
include('conexion.php');

$username = $_POST['usuario'];
$password = $_POST['pass'];
$val = 0;
$cantidad = 0;


if($username == 'admin' && $password == 'admin2021*'){
    $_SESSION['usuario'] = 99;
    //$_SESSION['departamento'] = 'Administrador';
    //$_SESSION['vigia'] = $username;
    header("location: ../vistas/funcionarios.php");
} else {

    $sql = $connection->prepare("SELECT count(*) AS cantidad, cedula_fun FROM funcionarios 
                                    WHERE cedula_fun = '$username' AND cedula_fun = '$password'");
    $sql->execute();
    $array = $sql->fetchAll(PDO::FETCH_ASSOC);

    foreach ($array as $valor) {
        if($valor['cantidad'] > 0){
            $_SESSION['usuario'] = $valor['cedula_fun'];
            //echo "SI";
            header("Location: ../vistas/carnet.php");
        }else{
            echo"<script> alert('Por favor verifique los campos'); </script>";
            header("Location: ../index.php");
            //echo "NO";
        }
    }
}
?>