<?php

include_once "includes/constantes.php";
include_once "includes/DBConnector.php";
include_once "includes/dUsuarios.php";
$id = $_POST['txtCedula'];
$usuario = $_POST['usuario'];
$contrasena = $_POST['pass'];
#$confimar=$_POST['confirmPass'];#AQUI aún no se le da uso
$nombre = $_POST['txtNombre'];
$apellidos = $_POST['txtApellidos'];
$correo = $_POST['correo'];
$telefono = $_POST['txtTelefono'];
$permisos = 2;
$db = new dUsuarios(__HOST__, __USUARIODB__, __PASSDB__, __DATABASE__);
$resultado = $db->agregarUsuario($id, $usuario, $contrasena, $nombre, $apellidos, $correo, $telefono, $permisos);
if ($resultado) {
    echo "La información se incluyó con éxito";
} else {
    echo "Error al incluir usuario";
}
?>

<html>
    <head>
        <meta charset="UTF-8">
        <title>Módulo de Activos</title>
        <link rel="stylesheet" type="text/css" href="../css/cambAplicados.css">
    </head>

    <body>
                    <h1>Información Solicitante</h1>


                    <table border=2 class="table table-striped table-hover table-responsive tabla">

                        <thead>
                            <tr>
                                <th>Cédula</th>
                                <th>Nombre</th>
                                <th>Teléfono</th>
                                <th>Correo</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
$conexion = new dUsuarios(__HOST__, __USUARIODB__, __PASSDB__, __DATABASE__);
$datos = $conexion->obtenerDatosID($_GET['ID_U']);
if ($datos !== false) {
    echo "<tr>\n                                        <td>" . $datos['id'] . "</td>\n\n                                        <td>" . $datos['nombre'] . "&nbsp;" . $datos['apellidos'] . "</td>\n                                        <td>" . $datos['telefono'] . "</td>\n                                        <td><input type='email' id='email' name='email' value='" . $datos['correo'] . "' disabled></td>\n                                    </tr>";
    echo "La solicitud ha sido rechazada.";
} else {
    echo "Por favor regrese y seleccione la solicitud que desea rechazar.;\n                                        <td>" . $datos['nombre'] . "&nbsp;" . $datos['apellidos'] . "</td>\n                                        <td>" . $datos['telefono'] . "</td>\n                                        <td>" . $datos['correo'] . "</td>\n                                    </tr>";
}
?>
                        </tbody>
                    </table>


                    <form id="form" action="rechazarSolicitud.php?ID=<?php 
echo $id_s;
?>
        } elseif ($fila['estado'] == 2 or $fila['estado'] == 3) {
            echo "<tr>\n                                                    <td><a href=''>" . $fila['ID'] . "</a></td>\n                                                    <td>" . $fila['ID_departamento'] . "</td>\n                                                    <td>" . $fila['activo'] . "</td>\n                                                    <td>" . $fila['descripcion'] . "</td>\n                                                    <td>en revisión</td>";
        } elseif ($fila['estado'] == 4) {
            echo "<tr>\n                                                    <td><a href=''>" . $fila['ID'] . "</a></td>\n                                                    <td>" . $fila['ID_departamento'] . "</td>\n                                                    <td>" . $fila['activo'] . "</td>\n                                                    <td>" . $fila['descripcion'] . "</td>\n                                                    <td>no disponible</td>";
        }
        echo "</tr>";
    }
}
?>

                            </tbody>
                        </table>
                    </div><!-- cierre del dov contTabla -->

                    <?php 
$conexion = new dUsuarios(__HOST__, __USUARIODB__, __PASSDB__, __DATABASE__);
$datos = $conexion->obtenerDatos($_SESSION['usuario']);
?>
                    <a href="seleccionarDep.php"><div class="regresar">
                        <div class="regresar2">

                        </div>
                        </div></a>
                    <?php 
if ($_GET['ID'] != 0) {
    echo "<a href='javascript:openForm();'><div class='continuar'></div></a>";
}
?>


                    <div class="ventanaModal">
        include_once "dUsuarios.php";
        $conexion = new dUsuarios(__HOST__, __USUARIODB__, __PASSDB__, __DATABASE__);
        $datos = $conexion->autenticarUsuario($usuario, $password);
        if ($datos != null) {
            if ($datos['permisos'] == 2) {
                $_SESSION['SESSION_STARTED'] = TRUE;
                header("Location:../seleccionarDep.php");
                exit;
            } else {
                header("Location:../../index.php");
            }
        }
        break;
    case 3:
        include_once "DBConnector.php";
        include_once "dUsuarios.php";
        $conexion = new dUsuarios(__HOST__, __USUARIODB__, __PASSDB__, __DATABASE__);
        $datos = $conexion->autenticarUsuario($usuario, $password);
        if ($datos != null) {
            if ($datos['permisos'] >= 3) {
                $_SESSION['SESSION_STARTED'] = TRUE;
                header("Location:../bienvAdmin.php");
                exit;
            } else {
                header("Location:../../index.php");
            }
        }
}
session_destroy();
header("location:../../index.php");
exit;