<?php

include "cabecera.php";
include "BL/cuestionarios_funciones.php";
include "BL/preguntas_funciones.php";
include "BL/respuestas_funciones.php";
$pregunta = consultar_preguntas('id', $_GET['pregunta']);
$pregunta = $pregunta[0];
if (isset($_POST['pregunta'])) {
    preguntas_upd($_GET['pregunta'], $_POST['pregunta'], $_GET["cuestionario"]);
    if (isset($_POST['Correcta'])) {
        switch ($_POST['Correcta']) {
            case '1':
                respuesta_upd($_POST['id1'], $_POST['Alt1'], 1, $_GET['pregunta']);
                respuesta_upd($_POST['id2'], $_POST['Alt2'], 0, $_GET['pregunta']);
                respuesta_upd($_POST['id3'], $_POST['Alt3'], 0, $_GET['pregunta']);
                break;
            case '2':
                respuesta_upd($_POST['id1'], $_POST['Alt1'], 0, $_GET['pregunta']);
                respuesta_upd($_POST['id2'], $_POST['Alt2'], 1, $_GET['pregunta']);
                respuesta_upd($_POST['id3'], $_POST['Alt3'], 0, $_GET['pregunta']);
                break;
            case '3':
                respuesta_upd($_POST['id1'], $_POST['Alt1'], 0, $_GET['pregunta']);
                respuesta_upd($_POST['id2'], $_POST['Alt2'], 0, $_GET['pregunta']);
                respuesta_upd($_POST['id3'], $_POST['Alt3'], 1, $_GET['pregunta']);
                break;
            default:
                break;
        }
        echo "<div align=center><h1>GUARDANDO, ESPERA...\n    <meta http-equiv='Refresh' content='2;url=ficha_cuestionario.php?cuestionario=" . $_GET["cuestionario"] . "'></font></h1></div>";
<?php

include "cabecera.php";
include "BL/cuestionarios_funciones.php";
include "BL/preguntas_funciones.php";
include "BL/respuestas_funciones.php";
if (isset($_POST['pregunta'])) {
    insertar_preguntas($_POST['pregunta'], $_GET["cuestionario"]);
    $pregunta = consultar_preguntas('enunciado', $_POST['pregunta']);
    $pregunta = $pregunta[0]['id_pregunta'];
    if (isset($_POST['Correcta'])) {
        switch ($_POST['Correcta']) {
            case '1':
                respuesta_insertar($_POST['Alt1'], 1, $pregunta);
                respuesta_insertar($_POST['Alt2'], 0, $pregunta);
                respuesta_insertar($_POST['Alt3'], 0, $pregunta);
                break;
            case '2':
                respuesta_insertar($_POST['Alt1'], 0, $pregunta);
                respuesta_insertar($_POST['Alt2'], 1, $pregunta);
                respuesta_insertar($_POST['Alt3'], 0, $pregunta);
                break;
            case '3':
                respuesta_insertar($_POST['Alt1'], 0, $pregunta);
                respuesta_insertar($_POST['Alt2'], 0, $pregunta);
                respuesta_insertar($_POST['Alt3'], 1, $pregunta);
                break;
            default:
                break;
        }
        echo "<div align=center><h1>GUARDANDO, ESPERA...\n    <meta http-equiv='Refresh' content='2;url=ficha_cuestionario.php?cuestionario=" . $_GET["cuestionario"] . "'></font></h1></div>";
<?php

include "cabecera.php";
include "BL/preguntas_funciones.php";
if (isset($_GET["pregunta"]) and isset($_GET["borra"])) {
    borrar_preguntas($_GET["pregunta"]);
    echo "<div align=center><h1>BORRANDO, ESPERA...\n\t<meta http-equiv='Refresh' content='2;url=ficha_cuestionario.php?cuestionario=" . $_GET["cuestionario"] . "'></font></h1></div>";
} else {
    $pregunta = consultar_preguntas('id', $_GET["pregunta"]);
    $pregunta = $pregunta[0];
    echo "<div align=center><h1>Borrar la pregunta</h1><br><h2>" . $pregunta["pregunta"] . " </h2><br><br>";
    echo "<notif>¿ESTA SEGURO?</notif><br><br>";
    echo "<table class=tablas><tr>";
    echo "<td width=50%><a href=ficha_pregunta_borrar.php?pregunta=" . $_GET["pregunta"] . "&borra=1&cuestionario=" . $_GET["cuestionario"] . "><notifsi>SI</notifsi></a></td>";
    echo "<td width=50%><a href=ficha_cuestionario.php?cuestionario=" . $_GET["cuestionario"] . "><notifno>NO</notifno></a></td>";
    echo "</tr></table>";
}
include "pie.php";
<?php

include "cabecera.php";
include "BL/cuestionarios_funciones.php";
include "BL/preguntas_funciones.php";
include "BL/respuestas_funciones.php";
$cuestionario = cuestionario_consultar("id", $_GET["cuestionario"]);
$cuestionario = $cuestionario[0];
$preguntas = consultar_preguntas('cuestionario', $_GET["cuestionario"]);
$total = count($preguntas);
echo "\n<div id='maincontent' class='bodywidth clear' align='center'>\n    <h2>Ficha del cuestionario " . $cuestionario['cuestionario'] . " </h2><br>\n    <h3>Total de preguntas del cuestionario: " . $total . " </h3>\n    <a href=ficha_nueva_pregunta.php?cuestionario=" . $cuestionario['id_cuestionario'] . "><br>\n          <img src=images/add.png width=50></a><h3>Añadir Pregunta</h3>";
echo "<table>\n  <thead>\n    <tr>\n    <th><h3>Preguntas</h3></th>\n    <th width='10%'><h3>Opciones</h3></th>\n    </tr>\n  </thead>\n  <tbody>";
if (is_array($preguntas)) {
    foreach ($preguntas as $pregunta) {
        echo "<tr>";
        echo "<td><h3>" . $pregunta['pregunta'] . "</h3><br>";
        $respuestas = respuestas_consultar('pregunta', $pregunta['id_pregunta']);
        if (is_array($respuestas)) {
            echo "<ul>";
            foreach ($respuestas as $respuesta) {
                if ($respuesta['correcta'] == 1) {
                    echo "<li><mark>" . $respuesta['respuesta'] . "</mark></li><br>";
                } else {
                    echo "<li>" . $respuesta['respuesta'] . "</li><br>";
                }
            }
            echo "</ul>";
        } else {
            echo "Sin respuestas";
        }
        echo "</td>";