Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c7958ad96 | |||
| bf2361ad43 |
@@ -3,6 +3,7 @@
|
|||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once '../clases/ClasePregunta.php';
|
require_once '../clases/ClasePregunta.php';
|
||||||
|
require_once '../clases/ClaseRespuesta.php';
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
|
|
||||||
@@ -11,16 +12,116 @@ switch ($_POST['orden']) {
|
|||||||
$idCategoria = intval($_POST['idCategoria'] ?? 0);
|
$idCategoria = intval($_POST['idCategoria'] ?? 0);
|
||||||
$nombrePregunta = trim($_POST['nombrePregunta'] ?? '');
|
$nombrePregunta = trim($_POST['nombrePregunta'] ?? '');
|
||||||
|
|
||||||
if ($idCategoria <= 0 || $nombrePregunta == '') {
|
$respuestaCorrecta = trim($_POST['respuestaCorrecta'] ?? '');
|
||||||
echo json_encode(['error' => 'La categoría y el texto de la pregunta son obligatorios']);
|
$respuestaIncorrecta1 = trim($_POST['respuestaIncorrecta1'] ?? '');
|
||||||
|
$respuestaIncorrecta2 = trim($_POST['respuestaIncorrecta2'] ?? '');
|
||||||
|
$respuestaIncorrecta3 = trim($_POST['respuestaIncorrecta3'] ?? '');
|
||||||
|
|
||||||
|
// Comprobamos los datos
|
||||||
|
if (
|
||||||
|
$idCategoria <= 0 ||
|
||||||
|
$nombrePregunta === '' ||
|
||||||
|
$respuestaCorrecta === '' ||
|
||||||
|
$respuestaIncorrecta1 === '' ||
|
||||||
|
$respuestaIncorrecta2 === '' ||
|
||||||
|
$respuestaIncorrecta3 === ''
|
||||||
|
) {
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'La categoría, la pregunta y todas las respuestas son obligatorias.'
|
||||||
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pregunta = new Pregunta($idCategoria, $nombrePregunta);
|
|
||||||
$resultado = $pregunta->guardar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
/*
|
||||||
|
* ==========================================
|
||||||
|
* 1. CREAMOS LA PREGUNTA
|
||||||
|
* ==========================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
$pregunta = new Pregunta(
|
||||||
|
$idCategoria,
|
||||||
|
$nombrePregunta
|
||||||
|
);
|
||||||
|
|
||||||
|
$resultadoPregunta = $pregunta->guardar();
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($resultadoPregunta['error'])) {
|
||||||
|
|
||||||
|
echo json_encode($resultadoPregunta);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Obtenemos el ID de la pregunta creada
|
||||||
|
$idPregunta = (int)$resultadoPregunta['exito_tecnico'];
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ==========================================
|
||||||
|
* 2. CREAMOS LAS RESPUESTAS
|
||||||
|
* ==========================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
$respuestas = [
|
||||||
|
[
|
||||||
|
'texto' => $respuestaCorrecta,
|
||||||
|
'correcta' => 1
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'texto' => $respuestaIncorrecta1,
|
||||||
|
'correcta' => 0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'texto' => $respuestaIncorrecta2,
|
||||||
|
'correcta' => 0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'texto' => $respuestaIncorrecta3,
|
||||||
|
'correcta' => 0
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($respuestas as $respuesta) {
|
||||||
|
|
||||||
|
$objRespuesta = new Respuesta(
|
||||||
|
null,
|
||||||
|
$idPregunta,
|
||||||
|
$respuesta['texto'],
|
||||||
|
$respuesta['correcta']
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$resultadoRespuesta = $objRespuesta->insertar();
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($resultadoRespuesta['error'])) {
|
||||||
|
|
||||||
|
echo json_encode($resultadoRespuesta);
|
||||||
|
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ==========================================
|
||||||
|
* 3. TODO CORRECTO
|
||||||
|
* ==========================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'exito' => 'Pregunta creada correctamente.',
|
||||||
|
'idPregunta' => $idPregunta
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case 'obtenerPreguntasPorCategoria':
|
case 'obtenerPreguntasPorCategoria':
|
||||||
@@ -49,5 +150,4 @@ switch ($_POST['orden']) {
|
|||||||
|
|
||||||
echo json_encode($listado);
|
echo json_encode($listado);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+69
-214
@@ -5,7 +5,6 @@ comprobarSalaUsuario();
|
|||||||
});
|
});
|
||||||
|
|
||||||
function comprobarSalaUsuario() {
|
function comprobarSalaUsuario() {
|
||||||
|
|
||||||
$("#cargandoSalas").remove();
|
$("#cargandoSalas").remove();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -14,15 +13,13 @@ $.ajax({
|
|||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "obtenerSalaUsuario"
|
orden: "obtenerSalaUsuario",
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
|
|
||||||
console.log("Sala del usuario:", respuesta);
|
console.log("Sala del usuario:", respuesta);
|
||||||
|
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
|
|
||||||
console.error(respuesta.error);
|
console.error(respuesta.error);
|
||||||
|
|
||||||
usuarioYaEstaEnEquipo = false;
|
usuarioYaEstaEnEquipo = false;
|
||||||
@@ -33,15 +30,12 @@ $.ajax({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (respuesta.asociado) {
|
if (respuesta.asociado) {
|
||||||
|
|
||||||
usuarioYaEstaEnEquipo = true;
|
usuarioYaEstaEnEquipo = true;
|
||||||
|
|
||||||
$("#contenedorCrearSala").hide();
|
$("#contenedorCrearSala").hide();
|
||||||
|
|
||||||
cargarSalaUsuario(respuesta.idPartida);
|
cargarSalaUsuario(respuesta.idPartida);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
usuarioYaEstaEnEquipo = false;
|
usuarioYaEstaEnEquipo = false;
|
||||||
|
|
||||||
cargarSalas();
|
cargarSalas();
|
||||||
@@ -49,23 +43,16 @@ $.ajax({
|
|||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al comprobar la sala del usuario:", error);
|
||||||
console.error(
|
|
||||||
"Error al comprobar la sala del usuario:",
|
|
||||||
error
|
|
||||||
);
|
|
||||||
|
|
||||||
usuarioYaEstaEnEquipo = false;
|
usuarioYaEstaEnEquipo = false;
|
||||||
|
|
||||||
cargarSalas();
|
cargarSalas();
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cargarSalaUsuario(idPartida) {
|
function cargarSalaUsuario(idPartida) {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@@ -73,13 +60,11 @@ $.ajax({
|
|||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "buscar",
|
orden: "buscar",
|
||||||
idPartida: idPartida
|
idPartida: idPartida,
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (partida) {
|
success: function (partida) {
|
||||||
|
|
||||||
if (partida.error) {
|
if (partida.error) {
|
||||||
|
|
||||||
console.error(partida.error);
|
console.error(partida.error);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -91,37 +76,28 @@ $.ajax({
|
|||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al obtener la sala del usuario:", error);
|
||||||
console.error(
|
},
|
||||||
"Error al obtener la sala del usuario:",
|
|
||||||
error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cargarSalas() {
|
function cargarSalas() {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "listar"
|
orden: "listar",
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (partidas) {
|
success: function (partidas) {
|
||||||
|
|
||||||
const contenedor = $("#contenedorSalas");
|
const contenedor = $("#contenedorSalas");
|
||||||
|
|
||||||
contenedor.empty();
|
contenedor.empty();
|
||||||
contenedor.empty();
|
contenedor.empty();
|
||||||
|
|
||||||
if (!Array.isArray(partidas) || partidas.length === 0) {
|
if (!Array.isArray(partidas) || partidas.length === 0) {
|
||||||
|
|
||||||
contenedor.html(`
|
contenedor.html(`
|
||||||
<div class="col-12 text-center">
|
<div class="col-12 text-center">
|
||||||
<p class="text-muted">
|
<p class="text-muted">
|
||||||
@@ -134,26 +110,17 @@ $.ajax({
|
|||||||
}
|
}
|
||||||
|
|
||||||
partidas.forEach(function (partida) {
|
partidas.forEach(function (partida) {
|
||||||
|
|
||||||
cargarInformacionSala(partida);
|
cargarInformacionSala(partida);
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al obtener las partidas:", error);
|
||||||
console.error(
|
},
|
||||||
"Error al obtener las partidas:",
|
|
||||||
error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cargarInformacionSala(partida) {
|
function cargarInformacionSala(partida) {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@@ -161,11 +128,10 @@ $.ajax({
|
|||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "getEquipos",
|
orden: "getEquipos",
|
||||||
idPartida: partida.idPartida
|
idPartida: partida.idPartida,
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (equipos) {
|
success: function (equipos) {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@@ -173,60 +139,39 @@ $.ajax({
|
|||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "getJugadores",
|
orden: "getJugadores",
|
||||||
idPartida: partida.idPartida
|
idPartida: partida.idPartida,
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (jugadores) {
|
success: function (jugadores) {
|
||||||
|
mostrarSala(partida, equipos, jugadores);
|
||||||
mostrarSala(
|
|
||||||
partida,
|
|
||||||
equipos,
|
|
||||||
jugadores
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al obtener jugadores:", error);
|
||||||
console.error(
|
},
|
||||||
"Error al obtener jugadores:",
|
|
||||||
error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al obtener equipos:", error);
|
||||||
console.error(
|
},
|
||||||
"Error al obtener equipos:",
|
|
||||||
error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mostrarSala(partida, equipos, jugadores) {
|
function mostrarSala(partida, equipos, jugadores) {
|
||||||
|
|
||||||
const contenedor = $("#contenedorSalas");
|
const contenedor = $("#contenedorSalas");
|
||||||
|
|
||||||
let equiposHTML = "";
|
let equiposHTML = "";
|
||||||
|
|
||||||
equipos.forEach(function (equipo) {
|
equipos.forEach(function (equipo) {
|
||||||
|
|
||||||
const jugadoresEquipo = jugadores.filter(function (jugador) {
|
const jugadoresEquipo = jugadores.filter(function (jugador) {
|
||||||
|
|
||||||
return jugador.idEquipo == equipo.idEquipo;
|
return jugador.idEquipo == equipo.idEquipo;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let jugadoresHTML = "";
|
let jugadoresHTML = "";
|
||||||
|
|
||||||
if (jugadoresEquipo.length > 0) {
|
if (jugadoresEquipo.length > 0) {
|
||||||
|
|
||||||
jugadoresEquipo.forEach(function (jugador) {
|
jugadoresEquipo.forEach(function (jugador) {
|
||||||
|
|
||||||
jugadoresHTML += `
|
jugadoresHTML += `
|
||||||
<div class="jugador">
|
<div class="jugador">
|
||||||
|
|
||||||
@@ -239,9 +184,7 @@ equipos.forEach(function (equipo) {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
jugadoresHTML = `
|
jugadoresHTML = `
|
||||||
<div class="text-muted small">
|
<div class="text-muted small">
|
||||||
Sin jugadores
|
Sin jugadores
|
||||||
@@ -249,11 +192,9 @@ equipos.forEach(function (equipo) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let botonUnirseHTML = "";
|
let botonUnirseHTML = "";
|
||||||
|
|
||||||
if (!usuarioYaEstaEnEquipo) {
|
if (!usuarioYaEstaEnEquipo) {
|
||||||
|
|
||||||
botonUnirseHTML = `
|
botonUnirseHTML = `
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -267,7 +208,6 @@ equipos.forEach(function (equipo) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
equiposHTML += `
|
equiposHTML += `
|
||||||
<div class="equipo">
|
<div class="equipo">
|
||||||
|
|
||||||
@@ -287,7 +227,6 @@ equipos.forEach(function (equipo) {
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const salaHTML = `
|
const salaHTML = `
|
||||||
<div class="col-12 col-md-10 col-lg-8">
|
<div class="col-12 col-md-10 col-lg-8">
|
||||||
|
|
||||||
@@ -314,35 +253,25 @@ const salaHTML = `
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
||||||
contenedor.append(salaHTML);
|
contenedor.append(salaHTML);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
// UNIRSE A UN EQUIPO
|
// UNIRSE A UN EQUIPO
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|
||||||
$(document).on(
|
$(document).on("click", ".btn-unirse-equipo", function () {
|
||||||
"click",
|
|
||||||
".btn-unirse-equipo",
|
|
||||||
function () {
|
|
||||||
|
|
||||||
const boton = $(this);
|
const boton = $(this);
|
||||||
|
|
||||||
const idEquipo = boton.data("id-equipo");
|
const idEquipo = boton.data("id-equipo");
|
||||||
|
|
||||||
const idPartida = boton.data("id-partida");
|
const idPartida = boton.data("id-partida");
|
||||||
|
|
||||||
|
|
||||||
boton.prop("disabled", true);
|
boton.prop("disabled", true);
|
||||||
|
|
||||||
boton.text("Uniéndose...");
|
boton.text("Uniéndose...");
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|
||||||
url: "controladores/ControladorEquipoxUsuario.php",
|
url: "controladores/ControladorEquipoxUsuario.php",
|
||||||
|
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@@ -351,20 +280,13 @@ function () {
|
|||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "registrarUsuarioEnEquipo",
|
orden: "registrarUsuarioEnEquipo",
|
||||||
idEquipo: idEquipo
|
idEquipo: idEquipo,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
|
console.log("Respuesta al unirse:", respuesta);
|
||||||
console.log(
|
|
||||||
"Respuesta al unirse:",
|
|
||||||
respuesta
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
|
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
|
|
||||||
boton.prop("disabled", false);
|
boton.prop("disabled", false);
|
||||||
@@ -374,161 +296,114 @@ function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// UNIÓN CORRECTA
|
// UNIÓN CORRECTA
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
usuarioYaEstaEnEquipo = true;
|
usuarioYaEstaEnEquipo = true;
|
||||||
|
|
||||||
|
|
||||||
// Ocultamos el botón "Crear sala"
|
// Ocultamos el botón "Crear sala"
|
||||||
|
|
||||||
$("#contenedorCrearSala").hide();
|
$("#contenedorCrearSala").hide();
|
||||||
|
|
||||||
|
|
||||||
// Eliminamos las salas actuales
|
// Eliminamos las salas actuales
|
||||||
|
|
||||||
$("#contenedorSalas").empty();
|
$("#contenedorSalas").empty();
|
||||||
|
|
||||||
|
|
||||||
// Cargamos directamente la sala
|
// Cargamos directamente la sala
|
||||||
// donde acaba de entrar el usuario
|
// donde acaba de entrar el usuario
|
||||||
|
|
||||||
cargarSalaUsuario(idPartida);
|
cargarSalaUsuario(idPartida);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al unirse al equipo:", error);
|
||||||
|
|
||||||
console.error(
|
console.error("Respuesta del servidor:", xhr.responseText);
|
||||||
"Error al unirse al equipo:",
|
|
||||||
error
|
|
||||||
);
|
|
||||||
|
|
||||||
console.error(
|
|
||||||
"Respuesta del servidor:",
|
|
||||||
xhr.responseText
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
alert(
|
|
||||||
"No se ha podido unir al equipo."
|
|
||||||
);
|
|
||||||
|
|
||||||
|
alert("No se ha podido unir al equipo.");
|
||||||
|
|
||||||
boton.prop("disabled", false);
|
boton.prop("disabled", false);
|
||||||
|
|
||||||
boton.text("Unirse");
|
boton.text("Unirse");
|
||||||
}
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
// ESCAPAR HTML
|
// ESCAPAR HTML
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|
||||||
function escapeHTML(texto) {
|
function escapeHTML(texto) {
|
||||||
|
|
||||||
return $("<div>")
|
return $("<div>")
|
||||||
.text(texto ?? "")
|
.text(texto ?? "")
|
||||||
.html();
|
.html();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
// CREAR SALA
|
// CREAR SALA
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|
||||||
$('#btnCrearSala').on('click', function () {
|
$("#btnCrearSala").on("click", function () {
|
||||||
|
const nombreSala = $("#nombreSala").val().trim();
|
||||||
|
|
||||||
const nombreSala =
|
const nombreEquipo1 = $("#nombreEquipo1").val().trim();
|
||||||
$('#nombreSala').val().trim();
|
|
||||||
|
|
||||||
const nombreEquipo1 =
|
const nombreEquipo2 = $("#nombreEquipo2").val().trim();
|
||||||
$('#nombreEquipo1').val().trim();
|
|
||||||
|
|
||||||
const nombreEquipo2 =
|
|
||||||
$('#nombreEquipo2').val().trim();
|
|
||||||
|
|
||||||
let valido = true;
|
let valido = true;
|
||||||
|
|
||||||
$('.mensaje-error-sala').remove();
|
$(".mensaje-error-sala").remove();
|
||||||
|
|
||||||
$('.input-kahoot')
|
$(".input-kahoot").removeClass("is-invalid");
|
||||||
.removeClass('is-invalid');
|
|
||||||
|
|
||||||
if (nombreSala === '') {
|
if (nombreSala === "") {
|
||||||
|
mostrarError("#nombreSala", "El nombre de la sala es obligatorio.");
|
||||||
mostrarError(
|
|
||||||
'#nombreSala',
|
|
||||||
'El nombre de la sala es obligatorio.'
|
|
||||||
);
|
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
|
|
||||||
} else if (nombreSala.length < 3) {
|
} else if (nombreSala.length < 3) {
|
||||||
|
|
||||||
mostrarError(
|
mostrarError(
|
||||||
'#nombreSala',
|
"#nombreSala",
|
||||||
'El nombre de la sala debe tener al menos 3 caracteres.'
|
"El nombre de la sala debe tener al menos 3 caracteres.",
|
||||||
);
|
);
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nombreEquipo1 === '') {
|
if (nombreEquipo1 === "") {
|
||||||
|
mostrarError("#nombreEquipo1", "El nombre del equipo 1 es obligatorio.");
|
||||||
mostrarError(
|
|
||||||
'#nombreEquipo1',
|
|
||||||
'El nombre del equipo 1 es obligatorio.'
|
|
||||||
);
|
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
|
|
||||||
} else if (nombreEquipo1.length < 2) {
|
} else if (nombreEquipo1.length < 2) {
|
||||||
|
|
||||||
mostrarError(
|
mostrarError(
|
||||||
'#nombreEquipo1',
|
"#nombreEquipo1",
|
||||||
'El nombre del equipo debe tener al menos 2 caracteres.'
|
"El nombre del equipo debe tener al menos 2 caracteres.",
|
||||||
);
|
);
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nombreEquipo2 === '') {
|
if (nombreEquipo2 === "") {
|
||||||
|
mostrarError("#nombreEquipo2", "El nombre del equipo 2 es obligatorio.");
|
||||||
mostrarError(
|
|
||||||
'#nombreEquipo2',
|
|
||||||
'El nombre del equipo 2 es obligatorio.'
|
|
||||||
);
|
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
|
|
||||||
} else if (nombreEquipo2.length < 2) {
|
} else if (nombreEquipo2.length < 2) {
|
||||||
|
|
||||||
mostrarError(
|
mostrarError(
|
||||||
'#nombreEquipo2',
|
"#nombreEquipo2",
|
||||||
'El nombre del equipo debe tener al menos 2 caracteres.'
|
"El nombre del equipo debe tener al menos 2 caracteres.",
|
||||||
);
|
);
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
nombreEquipo1 !== '' &&
|
nombreEquipo1 !== "" &&
|
||||||
nombreEquipo2 !== '' &&
|
nombreEquipo2 !== "" &&
|
||||||
nombreEquipo1.toLowerCase() ===
|
nombreEquipo1.toLowerCase() === nombreEquipo2.toLowerCase()
|
||||||
nombreEquipo2.toLowerCase()
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
mostrarError(
|
mostrarError(
|
||||||
'#nombreEquipo2',
|
"#nombreEquipo2",
|
||||||
'Los dos equipos deben tener nombres diferentes.'
|
"Los dos equipos deben tener nombres diferentes.",
|
||||||
);
|
);
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
@@ -539,69 +414,61 @@ $('#btnCrearSala').on('click', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deshabilitamos el botón mientras se crea la sala
|
// Deshabilitamos el botón mientras se crea la sala
|
||||||
const boton = $('#btnCrearSala');
|
const boton = $("#btnCrearSala");
|
||||||
|
|
||||||
boton.prop('disabled', true);
|
boton.prop("disabled", true);
|
||||||
boton.text('Creando sala...');
|
boton.text("Creando sala...");
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'controladores/controladorPartida.php', // <-- cambia esto por la ruta de tu controlador
|
url: "controladores/controladorPartida.php", // <-- cambia esto por la ruta de tu controlador
|
||||||
type: 'POST',
|
type: "POST",
|
||||||
dataType: 'json',
|
dataType: "json",
|
||||||
data: {
|
data: {
|
||||||
orden: 'crear',
|
orden: "crear",
|
||||||
nombrePartida: nombreSala,
|
nombrePartida: nombreSala,
|
||||||
nombreEquipo1: nombreEquipo1,
|
nombreEquipo1: nombreEquipo1,
|
||||||
nombreEquipo2: nombreEquipo2
|
nombreEquipo2: nombreEquipo2,
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
|
console.log("Respuesta del servidor:", respuesta);
|
||||||
console.log('Respuesta del servidor:', respuesta);
|
|
||||||
|
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
|
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
|
|
||||||
boton.prop('disabled', false);
|
boton.prop("disabled", false);
|
||||||
boton.text('Crear sala');
|
boton.text("Crear sala");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (respuesta.exito) {
|
if (respuesta.exito) {
|
||||||
|
$("#modalCrearSala").modal("hide");
|
||||||
$('#modalCrearSala').modal('hide');
|
|
||||||
location.reload();
|
location.reload();
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al crear la sala:", error);
|
||||||
|
console.error("Respuesta:", xhr.responseText);
|
||||||
|
|
||||||
console.error('Error al crear la sala:', error);
|
alert("No se ha podido crear la sala.");
|
||||||
console.error('Respuesta:', xhr.responseText);
|
|
||||||
|
|
||||||
alert('No se ha podido crear la sala.');
|
boton.prop("disabled", false);
|
||||||
|
boton.text("Crear sala");
|
||||||
boton.prop('disabled', false);
|
},
|
||||||
boton.text('Crear sala');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
// MOSTRAR ERROR
|
// MOSTRAR ERROR
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|
||||||
function mostrarError(selector, mensaje) {
|
function mostrarError(selector, mensaje) {
|
||||||
|
|
||||||
const input = $(selector);
|
const input = $(selector);
|
||||||
|
|
||||||
input.addClass("is-invalid");
|
input.addClass("is-invalid");
|
||||||
|
|
||||||
|
|
||||||
input.after(`
|
input.after(`
|
||||||
<div class="mensaje-error-sala text-danger mt-1 small">
|
<div class="mensaje-error-sala text-danger mt-1 small">
|
||||||
|
|
||||||
@@ -609,26 +476,14 @@ input.after(`
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
// QUITAR ERROR AL ESCRIBIR
|
// QUITAR ERROR AL ESCRIBIR
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|
||||||
$(".input-kahoot").on(
|
$(".input-kahoot").on("input", function () {
|
||||||
"input",
|
$(this).removeClass("is-invalid");
|
||||||
function () {
|
|
||||||
|
|
||||||
$(this).removeClass(
|
$(this).next(".mensaje-error-sala").remove();
|
||||||
"is-invalid"
|
});
|
||||||
);
|
|
||||||
|
|
||||||
$(this)
|
|
||||||
.next(".mensaje-error-sala")
|
|
||||||
.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|||||||
+146
-1
@@ -56,7 +56,6 @@ function borrarNombre() {
|
|||||||
document.getElementById("nuevoNombre").value = "";
|
document.getElementById("nuevoNombre").value = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// =========================
|
// =========================
|
||||||
// CAMBIAR FOTO
|
// CAMBIAR FOTO
|
||||||
// =========================
|
// =========================
|
||||||
@@ -106,3 +105,149 @@ $("#inputFoto").change(function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// RECOGER CATEGORIAS
|
||||||
|
// ====
|
||||||
|
|
||||||
|
$("#modalCrearPregunta").on("show.bs.modal", function () {
|
||||||
|
const selectCategoria = $("#idCategoria");
|
||||||
|
|
||||||
|
// Limpiamos las categorías anteriores
|
||||||
|
selectCategoria.empty();
|
||||||
|
|
||||||
|
// Opción inicial
|
||||||
|
selectCategoria.append('<option value="">Selecciona una categoría</option>');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorCategoria.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "listarCategorias",
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (respuesta) {
|
||||||
|
console.log("Categorías:", respuesta);
|
||||||
|
|
||||||
|
if (respuesta.error) {
|
||||||
|
alert(respuesta.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.each(respuesta, function (index, categoria) {
|
||||||
|
selectCategoria.append(
|
||||||
|
$("<option>", {
|
||||||
|
value: categoria.idCategoria,
|
||||||
|
text: categoria.nombreCategoria,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al cargar las categorías:", error);
|
||||||
|
|
||||||
|
console.error("Respuesta del servidor:", xhr.responseText);
|
||||||
|
|
||||||
|
alert("No se han podido cargar las categorías.");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// CREAR PREGUNTA
|
||||||
|
// ====
|
||||||
|
|
||||||
|
$("#formCrearPregunta").on("submit", function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const boton = $("#btnCrearPregunta");
|
||||||
|
|
||||||
|
const pregunta = $("#pregunta").val().trim();
|
||||||
|
const respuestaCorrecta = $("#respuestaCorrecta").val().trim();
|
||||||
|
const respuestaIncorrecta1 = $("#respuestaIncorrecta1").val().trim();
|
||||||
|
const respuestaIncorrecta2 = $("#respuestaIncorrecta2").val().trim();
|
||||||
|
const respuestaIncorrecta3 = $("#respuestaIncorrecta3").val().trim();
|
||||||
|
|
||||||
|
// Comprobamos que no haya campos vacíos
|
||||||
|
if (
|
||||||
|
pregunta === "" ||
|
||||||
|
respuestaCorrecta === "" ||
|
||||||
|
respuestaIncorrecta1 === "" ||
|
||||||
|
respuestaIncorrecta2 === "" ||
|
||||||
|
respuestaIncorrecta3 === ""
|
||||||
|
) {
|
||||||
|
alert("Todos los campos son obligatorios.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boton.prop("disabled", true);
|
||||||
|
boton.text("Creando pregunta...");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorPregunta.php",
|
||||||
|
|
||||||
|
type: "POST",
|
||||||
|
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "crearPregunta",
|
||||||
|
|
||||||
|
idCategoria: $("#idCategoria").val(),
|
||||||
|
|
||||||
|
nombrePregunta: pregunta,
|
||||||
|
|
||||||
|
respuestaCorrecta: respuestaCorrecta,
|
||||||
|
|
||||||
|
respuestaIncorrecta1: respuestaIncorrecta1,
|
||||||
|
|
||||||
|
respuestaIncorrecta2: respuestaIncorrecta2,
|
||||||
|
|
||||||
|
respuestaIncorrecta3: respuestaIncorrecta3,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (respuesta) {
|
||||||
|
console.log("Respuesta del servidor:", respuesta);
|
||||||
|
|
||||||
|
if (respuesta.error) {
|
||||||
|
alert(respuesta.error);
|
||||||
|
|
||||||
|
boton.prop("disabled", false);
|
||||||
|
boton.text("Crear pregunta");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (respuesta.exito) {
|
||||||
|
console.log("Pregunta creada:", respuesta.idPregunta);
|
||||||
|
|
||||||
|
// Cerramos el modal
|
||||||
|
$("#modalCrearPregunta").modal("hide");
|
||||||
|
|
||||||
|
// Limpiamos el formulario
|
||||||
|
$("#formCrearPregunta")[0].reset();
|
||||||
|
|
||||||
|
// Volvemos a activar el botón
|
||||||
|
boton.prop("disabled", false);
|
||||||
|
boton.text("Crear pregunta");
|
||||||
|
|
||||||
|
// Si tienes que actualizar la lista de preguntas:
|
||||||
|
// cargarPreguntas();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al crear la pregunta:", error);
|
||||||
|
|
||||||
|
console.error("Respuesta del servidor:", xhr.responseText);
|
||||||
|
|
||||||
|
alert("No se ha podido crear la pregunta.");
|
||||||
|
|
||||||
|
boton.prop("disabled", false);
|
||||||
|
boton.text("Crear pregunta");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
+30
-1
@@ -315,6 +315,34 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- CATEGORÍA -->
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
|
||||||
|
<label
|
||||||
|
for="idCategoria"
|
||||||
|
class="form-label fw-semibold">
|
||||||
|
|
||||||
|
<i class="bi bi-folder-fill me-1"></i>
|
||||||
|
Categoría
|
||||||
|
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<select
|
||||||
|
id="idCategoria"
|
||||||
|
name="idCategoria"
|
||||||
|
class="form-select input-kahoot"
|
||||||
|
required>
|
||||||
|
|
||||||
|
<option value="">
|
||||||
|
Selecciona una categoría
|
||||||
|
</option>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- RESPUESTA CORRECTA -->
|
<!-- RESPUESTA CORRECTA -->
|
||||||
|
|
||||||
@@ -404,7 +432,8 @@
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
form="formCrearPregunta"
|
form="formCrearPregunta"
|
||||||
class="btn btn-kahoot-login">
|
class="btn btn-kahoot-login"
|
||||||
|
id="btnCrearPregunta">
|
||||||
|
|
||||||
<i class="bi bi-check-lg me-1"></i>
|
<i class="bi bi-check-lg me-1"></i>
|
||||||
Crear pregunta
|
Crear pregunta
|
||||||
|
|||||||
Reference in New Issue
Block a user