function RegistrarEntrevista()
{
    session_start();
    if (!isset($_SESSION['Usuario'])) {
        Respoder(false, 'Debe iniciar sesión', null);
    }
    if ($_SESSION['Usuario']['tipo'] != 'B') {
        Respoder(false, 'No tiene autorización', null);
    }
    $entr = new Entrevista();
    $preguntas;
    if (!(($entr->titulo = filter_input(INPUT_POST, 'titulo', FILTER_SANITIZE_STRING)) && ($entr->descripcion = filter_input(INPUT_POST, 'descripcion', FILTER_SANITIZE_STRING)) && ($entr->fchInicio = filter_input(INPUT_POST, 'fchInicio', FILTER_SANITIZE_STRING)) && ($entr->fchFin = filter_input(INPUT_POST, 'fchFin', FILTER_SANITIZE_STRING)) && ($preguntas = filter_input(INPUT_POST, 'preguntas')))) {
        Respoder(false, 'Error al recibir parámetros', null);
    }
    try {
        $entr->fchInicio = new DateTime($entr->fchInicio);
        $entr->fchFin = new DateTime($entr->fchFin);
    } catch (Exception $ex) {
        Respoder(false, 'Fecha inicio o fin incorrecta', 'Formato de la fecha incorrecto');
    }
    $preguntas = json_decode($preguntas);
    if (is_null($preguntas)) {
        Respoder(false, 'Error al recibir preguntas', 'No se pudo procesar el JSON recibido');
    }
    try {
        foreach ($preguntas as $p) {
            if (!is_int((int) $p->tiempo)) {
                throw new Exception($p->tiempo . ' no es entero');
            }
        }
    } catch (Exception $ex) {
        Respoder(false, 'Error al recibir parámetros de las preguntas', $ex->getMessage());
    }
    //Hasta aquí los param se verificaron
    //Aqui se procesan los datos y se guardan
    $entr->idUsuario = $_SESSION['Usuario']['idUsuario'];
    if (!$entr->set()) {
        Respoder(true, 'Error al guardar la entrevista nueva', null, $preguntas);
    }
    try {
        foreach ($preguntas as $c => $p) {
            $pa = new Pregunta();
            $pa->premisa = $p->premisa;
            $pa->tiempo = $p->tiempo;
            $pa->idEntrevista = $entr->idEntrevista;
            if (!$pa->set()) {
                throw new Exception($p->md_detalle);
            }
        }
        Respoder(true, 'La entrevista se guardó', null, '/invitar?idEntrevista=' . $entr->idEntrevista);
    } catch (Exception $ex) {
        Respoder(false, 'Error al guardar pregunta', $ex->getMessage());
    }
}
 function getListPagina($pagina = 0, $rpp = 10, $condicion = "1=1", $parametros = array(), $orderby = "1")
 {
     $pos = $pagina * $rpp;
     $sql = "select * from encuesta e join pregunta p on e.id=p.idencuesta join respuesta r on p.id=r.idpregunta;";
     $r = $this->bd->setConsulta($sql, $parametros);
     $respuesta = array();
     //$cont=0;
     while ($fila = $this->bd->getFila()) {
         $objeto1 = new Encuesta();
         $objeto1->set($fila);
         $objeto2 = new Pregunta();
         $objeto2->set($fila, 3);
         $objeto3 = new Respuesta();
         $objeto3->set($fila, 6);
         $respuesta[] = new JoinEPR($objeto1, $objeto2, $objeto3);
         /*
                       $respuesta[$cont][0] = $objeto1;
                       $respuesta[$cont][1] = $objeto2;
                       $respuesta[$cont][2] = $objeto3;
                       $cont++;
         */
     }
     return $respuesta;
 }
 function getListaPaginadaJSON($pagina = 0, $rpp = 3, $condicion = "1=1", $parametros = array(), $orderby = "1")
 {
     $pos = $pagina * $rpp;
     $sql = "select * from " . $this->tabla . " where {$condicion} order by {$orderby} limit {$pos}, {$rpp}";
     $this->bd->setConsulta($sql, $parametros);
     $r = "[ ";
     while ($fila = $this->bd->getFila()) {
         $objeto = new Pregunta();
         $objeto->set($fila);
         $r .= $objeto->getJSON() . ",";
     }
     $r = substr($r, 0, -1) . "]";
     return $r;
 }