Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c3fbf2f90 | |||
| cd53cba69e | |||
| 5f407ce8f4 | |||
| d20b1fa7d7 | |||
| 02e725e0f3 | |||
| 3856db81ef | |||
| bdc7bef169 | |||
| 963ab50f37 | |||
| 9488d7cee7 | |||
| 0b8045544b | |||
| d67e4d76e2 | |||
| 20131bbe7f | |||
| c624f06b88 | |||
| e879a92ac2 | |||
| c18576e97d | |||
| fd4301d741 | |||
| afff6cfb4a | |||
| 46bfb7ea62 | |||
| cbdbd8bc4b | |||
| 83b1ae90c6 | |||
| 90a2ad1256 |
+3
-2
@@ -10,11 +10,12 @@
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
<link rel="stylesheet" href="css/buscadorSala.css">
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php include_once("cabecera.php"); ?>
|
||||
<header id="cabecera-container"></header>
|
||||
|
||||
<main class="container py-4">
|
||||
|
||||
@@ -99,9 +100,9 @@
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
<script src="js/sala.js"></script>
|
||||
<script src="js/buscadorSala.js"></script>
|
||||
<script src="js/cabecera.js"></script>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
<head>
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- FontAwesome para iconos -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
||||
<!-- Google Fonts para estilo Kahoot -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- cabecera.html -->
|
||||
<nav class="navbar navbar-expand-lg navbar-kahoot py-3 mb-4">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">
|
||||
<img src="img/favicon/favicon.svg" alt="TRIVIAGMÁTICO" class="me-2" style="height: 35px;">
|
||||
TRIVIAGMÁTICO
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0"></ul>
|
||||
|
||||
<!-- Contenedor dinámico de usuario/botones -->
|
||||
<div class="d-flex align-items-center gap-3" id="contenedorUsuarioCabecera"></div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- MODAL DE LOGIN -->
|
||||
<div class="modal fade" id="modalLogin" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-dark">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5 fw-bold" id="loginModalLabel">
|
||||
<i class="fa-solid fa-right-to-bracket text-primary me-2"></i>Iniciar sesión
|
||||
</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="formLogin">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="email" class="form-control border-dark" id="loginEmail" name="email" placeholder="Correo electrónico" required>
|
||||
<label for="loginEmail">Correo electrónico</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="loginPassword" name="contrasena" placeholder="Contraseña" required>
|
||||
<label for="loginPassword">Contraseña</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" id="recordar" name="recordar" type="checkbox" />
|
||||
<label for="recordar" class="small">Recuérdeme durante 10 días</label>
|
||||
</div>
|
||||
<input type="hidden" name="orden" value="validar">
|
||||
</form>
|
||||
<div id="errorLogin" class="text-danger fw-bold mt-2"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-primary rounded-pill px-4" id="botonAceptarLogin">Entrar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL DE REGISTRO -->
|
||||
<div class="modal fade" id="modalRegistro" tabindex="-1" aria-labelledby="registroModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-dark">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5 fw-bold" id="registroModalLabel">
|
||||
<i class="fa-solid fa-user-plus text-success me-2"></i>Registrarse
|
||||
</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="formRegistro">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" class="form-control border-dark" id="regNombre" name="nombreUsuario" placeholder="Nombre" required>
|
||||
<label for="regNombre">Nombre</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="email" class="form-control border-dark" id="regEmail" name="email" placeholder="Correo electrónico" required>
|
||||
<label for="regEmail">Correo electrónico</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="regPassword" name="contrasena" placeholder="Contraseña" required>
|
||||
<label for="regPassword">Contraseña</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="regPasswordConfirm" name="contrasenaConfirm" placeholder="Confirmar contraseña" required>
|
||||
<label for="regPasswordConfirm">Confirmar contraseña</label>
|
||||
</div>
|
||||
<input type="hidden" name="orden" value="registrar">
|
||||
</form>
|
||||
<div id="errorRegistro" class="text-danger fw-bold mt-2"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-success rounded-pill px-4" id="botonAceptarRegistro">Registrarse</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
-108
@@ -1,108 +0,0 @@
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- FontAwesome para iconos -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
||||
<!-- Google Fonts para estilo Kahoot -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-kahoot py-3 mb-4">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">
|
||||
<img src="img/favicon/favicon.svg" alt="TRIVIAGMÁTICO" class="me-2" style="height: 35px;">
|
||||
TRIVIAGMÁTICO
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0"></ul>
|
||||
|
||||
<!-- Contenedor dinámico de usuario/botones -->
|
||||
<div class="d-flex align-items-center gap-3" id="contenedorUsuarioCabecera">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- MODAL DE LOGIN -->
|
||||
<div class="modal fade" id="modalLogin" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-dark">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5 fw-bold" id="loginModalLabel">
|
||||
<i class="fa-solid fa-right-to-bracket text-primary me-2"></i>Iniciar sesión
|
||||
</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="formLogin">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="email" class="form-control border-dark" id="loginEmail" name="email" placeholder="Correo electrónico" required>
|
||||
<label for="loginEmail">Correo electrónico</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="loginPassword" name="contrasena" placeholder="Contraseña" required>
|
||||
<label for="loginPassword">Contraseña</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" id="recordar" name="recordar" type="checkbox" />
|
||||
<label for="recordar" class="small">Recuérdeme durante 10 días</label>
|
||||
</div>
|
||||
<input type="hidden" name="orden" value="validar">
|
||||
</form>
|
||||
<div id="errorLogin" class="text-danger fw-bold mt-2"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-primary rounded-pill px-4" id="botonAceptarLogin">Entrar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL DE REGISTRO -->
|
||||
<div class="modal fade" id="modalRegistro" tabindex="-1" aria-labelledby="registroModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-dark">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5 fw-bold" id="registroModalLabel">
|
||||
<i class="fa-solid fa-user-plus text-success me-2"></i>Registrarse
|
||||
</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="formRegistro">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" class="form-control border-dark" id="regNombre" name="nombreUsuario" placeholder="Nombre" required>
|
||||
<label for="regNombre">Nombre</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="email" class="form-control border-dark" id="regEmail" name="email" placeholder="Correo electrónico" required>
|
||||
<label for="regEmail">Correo electrónico</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="regPassword" name="contrasena" placeholder="Contraseña" required>
|
||||
<label for="regPassword">Contraseña</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control border-dark" id="regPasswordConfirm" name="contrasenaConfirm" placeholder="Confirmar contraseña" required>
|
||||
<label for="regPasswordConfirm">Confirmar contraseña</label>
|
||||
</div>
|
||||
<input type="hidden" name="orden" value="registrar">
|
||||
</form>
|
||||
<div id="errorRegistro" class="text-danger fw-bold mt-2"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary rounded-pill px-3" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-success rounded-pill px-4" id="botonAceptarRegistro">Registrarse</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="js/cabecera.js"></script>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/triviagmatico/includes/conexionBD.php';
|
||||
|
||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||
|
||||
class Categoria{
|
||||
|
||||
|
||||
@@ -229,7 +229,13 @@ class Juego
|
||||
* - la respuesta pertenece a esa pregunta
|
||||
* - el usuario no ha respondido ya esa pregunta
|
||||
*/
|
||||
public static function registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta)
|
||||
public static function registrarRespuesta(
|
||||
$idPartida,
|
||||
$idUsuario,
|
||||
$idPartidaxPregunta,
|
||||
$idRespuesta,
|
||||
$tiempoRespuesta
|
||||
)
|
||||
{
|
||||
$conexion = conexionBD();
|
||||
if (is_array($conexion)) {
|
||||
@@ -298,7 +304,8 @@ class Juego
|
||||
null,
|
||||
$idPartidaxPregunta,
|
||||
$idUsuario,
|
||||
$idRespuesta
|
||||
$idRespuesta,
|
||||
$tiempoRespuesta
|
||||
);
|
||||
$guardado = $almacenada->guardarRespuesta();
|
||||
|
||||
|
||||
+35
-19
@@ -132,27 +132,43 @@ class Partida
|
||||
}
|
||||
|
||||
|
||||
public function iniciarPartida(){
|
||||
$conexion = conexionBD();
|
||||
if (is_array($conexion)){
|
||||
return $conexion;
|
||||
}
|
||||
try {
|
||||
$consulta = $conexion->prepare("UPDATE partida SET fechaInicio=NOW() WHERE idPartida=:idPartida AND fechaInicio IS NULL");
|
||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||
$consulta->execute();
|
||||
return [
|
||||
"exito" => "La partida ha comenzado.",
|
||||
"exito_tecnico" => $this->idPartida
|
||||
];
|
||||
} catch (PDOException $error) {
|
||||
return [
|
||||
"error" => "Ocurrió un error al iniciar la partida.",
|
||||
'error_tecnico' => $error->getMessage()
|
||||
];
|
||||
}
|
||||
public function iniciarPartida()
|
||||
{
|
||||
$conexion = conexionBD();
|
||||
|
||||
if (is_array($conexion)) {
|
||||
return $conexion;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$consulta = $conexion->prepare("
|
||||
UPDATE partida
|
||||
SET fechaInicio = NOW()
|
||||
WHERE idPartida = :idPartida
|
||||
AND fechaInicio IS NULL
|
||||
");
|
||||
|
||||
$consulta->bindParam(
|
||||
":idPartida",
|
||||
$this->idPartida
|
||||
);
|
||||
|
||||
$consulta->execute();
|
||||
|
||||
return [
|
||||
"exito" => "La partida ha comenzado.",
|
||||
"exito_tecnico" => $this->idPartida
|
||||
];
|
||||
|
||||
} catch (PDOException $error) {
|
||||
|
||||
return [
|
||||
"error" => "ERROR REAL: " . $error->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function finalizar(){
|
||||
$conexion = conexionBD();
|
||||
|
||||
@@ -24,6 +24,8 @@ class Respuesta{
|
||||
$consulta->bindParam(':idPregunta', $this->idPregunta);
|
||||
$consulta->bindParam(':nombreRespuesta', $this->nombreRespuesta);
|
||||
$consulta->bindParam(':correcta', $this->correcta);
|
||||
|
||||
|
||||
$consulta->execute();
|
||||
$respuesta = [
|
||||
'exito' => 'La respuesta se guardó correctamente.',
|
||||
|
||||
@@ -7,43 +7,53 @@ class RespuestaAlmacenada {
|
||||
public $idPartidaxPregunta;
|
||||
public $idUsuario;
|
||||
public $idRespuesta;
|
||||
public $tiempoRespuesta;
|
||||
|
||||
public function __construct($idRespuestaAlmacenada = null, $idPartidaxPregunta = null, $idUsuario = null, $idRespuesta = null) {
|
||||
public function __construct($idRespuestaAlmacenada = null, $idPartidaxPregunta = null, $idUsuario = null, $idRespuesta = null, $tiempoRespuesta = null) {
|
||||
$this->idRespuestaAlmacenada = $idRespuestaAlmacenada;
|
||||
$this->idPartidaxPregunta = $idPartidaxPregunta;
|
||||
$this->idUsuario = $idUsuario;
|
||||
$this->idRespuesta = $idRespuesta;
|
||||
$this->tiempoRespuesta = $tiempoRespuesta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Guarda la respuesta que ha seleccionado un usuario en una pregunta de la partida.
|
||||
*/
|
||||
public function guardarRespuesta() {
|
||||
$conexion = conexionBD();
|
||||
if (is_array($conexion)) return $conexion;
|
||||
$conexion = conexionBD();
|
||||
|
||||
try {
|
||||
$sql = "INSERT INTO respuestaalmacenada (idPartidaxPregunta, idUsuario, idRespuesta)
|
||||
VALUES (:idPartidaxPregunta, :idUsuario, :idRespuesta)";
|
||||
$consulta = $conexion->prepare($sql);
|
||||
|
||||
$consulta->bindParam(':idPartidaxPregunta', $this->idPartidaxPregunta);
|
||||
$consulta->bindParam(':idUsuario', $this->idUsuario);
|
||||
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
|
||||
$consulta->execute();
|
||||
|
||||
return [
|
||||
'exito' => 'Respuesta del usuario almacenada correctamente.',
|
||||
'exito_tecnico' => $conexion->lastInsertId()
|
||||
];
|
||||
} catch (PDOException $error) {
|
||||
return [
|
||||
'error' => 'Ocurrió un error al guardar la respuesta del jugador.',
|
||||
'error_tecnico' => $error->getMessage()
|
||||
];
|
||||
}
|
||||
if (is_array($conexion)) {
|
||||
return $conexion;
|
||||
}
|
||||
|
||||
try {
|
||||
$sql = "INSERT INTO respuestaalmacenada
|
||||
(idPartidaxPregunta, idUsuario, idRespuesta, tiempoRespuesta)
|
||||
VALUES
|
||||
(:idPartidaxPregunta, :idUsuario, :idRespuesta, :tiempoRespuesta)";
|
||||
|
||||
$consulta = $conexion->prepare($sql);
|
||||
|
||||
$consulta->bindParam(':idPartidaxPregunta', $this->idPartidaxPregunta);
|
||||
$consulta->bindParam(':idUsuario', $this->idUsuario);
|
||||
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
|
||||
$consulta->bindParam(':tiempoRespuesta', $this->tiempoRespuesta);
|
||||
|
||||
$consulta->execute();
|
||||
|
||||
return [
|
||||
'exito' => 'Respuesta almacenada correctamente.'
|
||||
];
|
||||
|
||||
} catch (PDOException $error) {
|
||||
return [
|
||||
'error' => 'Ocurrió un error al guardar la respuesta.',
|
||||
'error_tecnico' => $error->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene los aciertos totales de un usuario en una partida específica.
|
||||
* Útil para calcular las estadísticas individuales al terminar el juego.
|
||||
|
||||
@@ -74,34 +74,47 @@ switch ($orden) {
|
||||
|
||||
case 'responder':
|
||||
|
||||
if (!isset($_POST['idPartidaxPregunta']) || !isset($_POST['idRespuesta'])){
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos para registrar la respuesta.'
|
||||
]);
|
||||
if (
|
||||
!isset($_POST['idPartidaxPregunta']) ||
|
||||
!isset($_POST['idRespuesta']) ||
|
||||
!isset($_POST['tiempoRespuesta'])
|
||||
) {
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos para registrar la respuestfdfa.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta']);
|
||||
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta']);
|
||||
$idRespuesta = intval($_POST['idRespuesta']);
|
||||
$tiempoRespuesta = intval($_POST['tiempoRespuesta']);
|
||||
|
||||
$idRespuesta = intval($_POST['idRespuesta']);
|
||||
|
||||
if ($idPartidaxPregunta <= 0 || $idRespuesta <= 0){
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Los datos de la respuesta no son válidos.'
|
||||
]);
|
||||
if (
|
||||
$idPartidaxPregunta <= 0 ||
|
||||
$idRespuesta <= 0 ||
|
||||
$tiempoRespuesta < 0
|
||||
) {
|
||||
echo json_encode([
|
||||
'error' => 'Los datos de la respuesta no son válidos.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Registramos la respuesta del usuario
|
||||
// Registramos la respuesta del usuario junto con su tiempo de respuesta
|
||||
|
||||
$resultado = Juego::registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta);
|
||||
$resultado = Juego::registrarRespuesta(
|
||||
$idPartida,
|
||||
$idUsuario,
|
||||
$idPartidaxPregunta,
|
||||
$idRespuesta,
|
||||
$tiempoRespuesta
|
||||
);
|
||||
|
||||
echo json_encode($resultado);
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
// Finalizar la partida y registrar los aciertos del usuario
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ switch ($_POST['orden']) {
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* ==========================================
|
||||
* 3. INSERTAMOS LOS EQUIPOS CON SU PARTIDA EN EQUIPOXPARTIDA
|
||||
* ==========================================
|
||||
@@ -220,9 +220,9 @@ switch ($_POST['orden']) {
|
||||
* 5. ASIGNAMOS 10 PREGUNTAS ALEATORIAS A LA PARTIDA
|
||||
* ==========================================
|
||||
*/
|
||||
|
||||
|
||||
// Obtenemos todos los IDs de las preguntas
|
||||
|
||||
|
||||
$listaPreguntas = Pregunta::getTodosIds();
|
||||
|
||||
$totalPreguntas = count($listaPreguntas);
|
||||
@@ -246,7 +246,7 @@ switch ($_POST['orden']) {
|
||||
// Asignamos el ID real de la pregunta a la partida
|
||||
$partida->asignarPregunta($idPreguntaAleatoria);
|
||||
}
|
||||
}//fin shile
|
||||
} //fin shile
|
||||
|
||||
|
||||
/*
|
||||
@@ -795,13 +795,47 @@ switch ($_POST['orden']) {
|
||||
|
||||
*/
|
||||
|
||||
$resultado = $partida->iniciar();
|
||||
$resultado = $partida->iniciarPartida();
|
||||
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
case 'comprobarInicio':
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
$datosPartida = $partida->buscar();
|
||||
|
||||
if (!$datosPartida || isset($datosPartida['error'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'La partida no existe.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'iniciada' => $datosPartida['fechaInicio'] !== null
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
// OBTENER LA PREGUNTA ACTUAL
|
||||
@@ -933,7 +967,7 @@ switch ($_POST['orden']) {
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos para registrar la respuesta.'
|
||||
'error' => 'Faltan datos para registrar la respuestadd.'
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
@@ -4,13 +4,20 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Triviagmático</title>
|
||||
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
||||
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- FontAwesome para iconos -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
||||
<!-- Google Fonts para estilo Kahoot -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="css/index.css">
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php include 'cabecera.php'; ?>
|
||||
<header id="cabecera-container"></header>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="row justify-content-center align-items-center g-4">
|
||||
@@ -46,6 +53,7 @@
|
||||
<!-- JS de Bootstrap -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="js/index.js"></script>
|
||||
<script src="js/cabecera.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+127
-112
@@ -1,14 +1,19 @@
|
||||
let idUsuarioSesion = null;
|
||||
|
||||
$(document).ready(function () {
|
||||
comprobarSesion();
|
||||
// Cargar la cabecera HTML e iniciar comprobación de sesión SOLO al terminar de cargar
|
||||
$("#cabecera-container").load("cabecera.html", function (response, status, xhr) {
|
||||
if (status === "error") {
|
||||
console.error("Error al cargar cabecera.html:", xhr.status, xhr.statusText);
|
||||
} else {
|
||||
comprobarSesion();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Función auxiliar para escapar texto HTML
|
||||
function escapeHTML(str) {
|
||||
return $("<div>")
|
||||
.text(str ?? "")
|
||||
.html();
|
||||
return $("<div>").text(str ?? "").html();
|
||||
}
|
||||
|
||||
// Comprobar estado de sesión al cargar la página
|
||||
@@ -16,83 +21,88 @@ function comprobarSesion() {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
dataType: "json",
|
||||
data: { orden: "comprobarSesion" },
|
||||
}).done(function (respuesta) {
|
||||
try {
|
||||
if (typeof respuesta === "string") {
|
||||
respuesta = JSON.parse(respuesta);
|
||||
})
|
||||
.done(function (respuesta) {
|
||||
const contenedor = $("#contenedorUsuarioCabecera");
|
||||
if (!contenedor.length) return; // Si aún no existe el contenedor en HTML, cancelamos
|
||||
|
||||
contenedor.empty();
|
||||
|
||||
if (respuesta && respuesta.activa && respuesta.usuario) {
|
||||
// Guardar idUsuario globalmente
|
||||
idUsuarioSesion = respuesta.usuario.idUsuario;
|
||||
const avatarUrl = respuesta.usuario.avatar || "img/avatars/defaultProfile.jpeg";
|
||||
|
||||
// Usuario autenticado: Menú desplegable
|
||||
const htmlUsuario = `
|
||||
<div class="dropdown">
|
||||
<button class="btn user-dropdown-btn dropdown-toggle d-flex align-items-center gap-2"
|
||||
type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<img src="${escapeHTML(avatarUrl)}" alt="Avatar" class="rounded-circle" style="width: 32px; height: 32px; object-fit: cover;">
|
||||
<span>${escapeHTML(respuesta.usuario.nombreUsuario)}</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end user-dropdown-menu" aria-labelledby="userDropdown">
|
||||
<li>
|
||||
<a class="dropdown-item d-flex align-items-center gap-2" href="perfil.php">
|
||||
<i class="fa-solid fa-user text-primary"></i> Perfil
|
||||
</a>
|
||||
</li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a class="dropdown-item logout-item d-flex align-items-center gap-2" href="#" id="botonCerrarSesion">
|
||||
<i class="fa-solid fa-right-from-bracket"></i> Cerrar Sesión
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
`;
|
||||
contenedor.html(htmlUsuario);
|
||||
|
||||
// Si estamos en la página de perfil, rellenamos nombre y foto
|
||||
if ($("#nombre").length) {
|
||||
$("#nombre").text(respuesta.usuario.nombreUsuario);
|
||||
// ?t= evita que el navegador enseñe la foto antigua en caché
|
||||
$("#fotoPerfil").attr("src", avatarUrl + "?t=" + new Date().getTime());
|
||||
}
|
||||
|
||||
const contenedor = $("#contenedorUsuarioCabecera");
|
||||
contenedor.empty();
|
||||
|
||||
if (respuesta.activa && respuesta.usuario) {
|
||||
// Recogemos el idUsuario de la sesion en una variable para usarlo (no me lo volváis a borrar por favor os lo pido)
|
||||
idUsuarioSesion = respuesta.usuario.idUsuario;
|
||||
// Obtenemos la ruta del avatar o la de por defecto
|
||||
const avatarUrl =
|
||||
respuesta.usuario.avatar || "img/avatars/defaultProfile.jpeg";
|
||||
|
||||
// Usuario autenticado: Mostrar Menú Dropdown con el avatar
|
||||
const htmlUsuario = `
|
||||
<div class="dropdown">
|
||||
<button class="btn user-dropdown-btn dropdown-toggle d-flex align-items-center gap-2"
|
||||
type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<img src="${escapeHTML(avatarUrl)}" alt="Avatar" class="rounded-circle" style="width: 32px; height: 32px; object-fit: cover;">
|
||||
<span>${escapeHTML(respuesta.usuario.nombreUsuario)}</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end user-dropdown-menu" aria-labelledby="userDropdown">
|
||||
<li>
|
||||
<a class="dropdown-item d-flex align-items-center gap-2" href="perfil.php">
|
||||
<i class="fa-solid fa-user text-primary"></i> Perfil
|
||||
</a>
|
||||
</li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a class="dropdown-item logout-item d-flex align-items-center gap-2" href="#" id="botonCerrarSesion">
|
||||
<i class="fa-solid fa-right-from-bracket"></i> Cerrar Sesión
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
`;
|
||||
contenedor.html(htmlUsuario);
|
||||
|
||||
// Si estamos en la página principal, mostramos el botón JUGAR
|
||||
if ($("#colBotonJugar").length) {
|
||||
$("#colBotonJugar").removeClass("d-none");
|
||||
$("#colRanking")
|
||||
.removeClass("col-lg-8")
|
||||
.addClass("col-lg-7 col-xl-8");
|
||||
}
|
||||
} else {
|
||||
// No hay sesión: Mostrar botones de Login y Registro
|
||||
const htmlInvitado = `
|
||||
<button type="button" class="btn btn-kahoot-login rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
||||
<i class="fa-solid fa-right-to-bracket me-1"></i> Iniciar Sesión
|
||||
</button>
|
||||
<button type="button" class="btn btn-kahoot-register rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalRegistro">
|
||||
<i class="fa-solid fa-user-plus me-1"></i> Registrarse
|
||||
</button>
|
||||
`;
|
||||
contenedor.html(htmlInvitado);
|
||||
|
||||
// Si estamos en la página principal, ocultamos el botón JUGAR
|
||||
if ($("#colBotonJugar").length) {
|
||||
$("#colBotonJugar").addClass("d-none");
|
||||
$("#colRanking")
|
||||
.removeClass("col-lg-7 col-xl-8")
|
||||
.addClass("col-lg-8");
|
||||
}
|
||||
// Si estamos en la página principal, mostramos el botón JUGAR
|
||||
if ($("#colBotonJugar").length) {
|
||||
$("#colBotonJugar").removeClass("d-none");
|
||||
$("#colRanking").removeClass("col-lg-8").addClass("col-lg-7 col-xl-8");
|
||||
}
|
||||
} else {
|
||||
// Si estamos en el perfil y no hay sesión, volvemos al inicio
|
||||
if ($("#nombre").length) {
|
||||
window.location.href = "index.php";
|
||||
return;
|
||||
}
|
||||
|
||||
// No hay sesión: Botones de Login y Registro
|
||||
const htmlInvitado = `
|
||||
<button type="button" class="btn btn-kahoot-login rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
||||
<i class="fa-solid fa-right-to-bracket me-1"></i> Iniciar Sesión
|
||||
</button>
|
||||
<button type="button" class="btn btn-kahoot-register rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalRegistro">
|
||||
<i class="fa-solid fa-user-plus me-1"></i> Registrarse
|
||||
</button>
|
||||
`;
|
||||
contenedor.html(htmlInvitado);
|
||||
|
||||
if ($("#colBotonJugar").length) {
|
||||
$("#colBotonJugar").addClass("d-none");
|
||||
$("#colRanking").removeClass("col-lg-7 col-xl-8").addClass("col-lg-8");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error al procesar la respuesta de la sesión:", e);
|
||||
}
|
||||
})
|
||||
.fail(function (xhr, status, error) {
|
||||
console.error("Error en comprobarSesion AJAX:", error, xhr.responseText);
|
||||
});
|
||||
}
|
||||
|
||||
// Registro
|
||||
$("#botonAceptarRegistro").click(function (event) {
|
||||
// Registro de usuario
|
||||
$(document).on("click", "#botonAceptarRegistro", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let nombreUsuario = $("#regNombre").val().trim();
|
||||
@@ -100,61 +110,64 @@ $("#botonAceptarRegistro").click(function (event) {
|
||||
let contrasena = $("#regPassword").val();
|
||||
let contrasenaConfirmacion = $("#regPasswordConfirm").val();
|
||||
|
||||
$("#regNombre").removeClass("is-invalid");
|
||||
$("#regEmail").removeClass("is-invalid");
|
||||
$("#regPassword").removeClass("is-invalid");
|
||||
$("#regPasswordConfirm").removeClass("is-invalid");
|
||||
$("#errorRegistro").text("");
|
||||
// Resetear estados visuales
|
||||
$("#regNombre, #regEmail, #regPassword, #regPasswordConfirm").removeClass("is-invalid");
|
||||
$("#errorRegistro").removeClass("text-danger text-success").text("").show();
|
||||
|
||||
if (contrasena !== contrasenaConfirmacion) {
|
||||
$("#regPassword").addClass("is-invalid");
|
||||
$("#regPasswordConfirm").addClass("is-invalid");
|
||||
$("#errorRegistro").text("Las contraseñas no coinciden.");
|
||||
$("#regPassword, #regPasswordConfirm").addClass("is-invalid");
|
||||
$("#errorRegistro").addClass("text-danger").text("Las contraseñas no coinciden.");
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
dataType: "json",
|
||||
data: {
|
||||
nombreUsuario: nombreUsuario,
|
||||
email: email,
|
||||
contrasena: contrasena,
|
||||
orden: "registrarUsuario",
|
||||
},
|
||||
}).done(function (respuesta) {
|
||||
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||
|
||||
})
|
||||
.done(function (respuesta) {
|
||||
if (respuesta.error) {
|
||||
$("#errorRegistro").text(respuesta.error);
|
||||
$("#regNombre").addClass("is-invalid");
|
||||
$("#regEmail").addClass("is-invalid");
|
||||
$("#errorRegistro").addClass("text-danger").text(respuesta.error);
|
||||
$("#regNombre, #regEmail").addClass("is-invalid");
|
||||
} else {
|
||||
// Mostrar mensaje de confirmación
|
||||
$("#errorRegistro")
|
||||
.removeClass("text-danger")
|
||||
.addClass("text-success")
|
||||
.text(respuesta.exito);
|
||||
.addClass("text-success fw-bold")
|
||||
.text(respuesta.exito || "¡Registro completado con éxito!");
|
||||
|
||||
$("#formRegistro")[0].reset();
|
||||
if ($("#formRegistro").length) {
|
||||
$("#formRegistro")[0].reset();
|
||||
}
|
||||
|
||||
// Recargar para iniciar sesión tras 1.5 segundos
|
||||
setTimeout(function () {
|
||||
location.reload();
|
||||
}, 1000);
|
||||
}, 1500);
|
||||
}
|
||||
})
|
||||
.fail(function (xhr, status, error) {
|
||||
console.error("Error en el registro:", error, xhr.responseText);
|
||||
$("#errorRegistro").addClass("text-danger").text("Error de conexión con el servidor.");
|
||||
});
|
||||
});
|
||||
|
||||
// Login
|
||||
$("#botonAceptarLogin").click(function (event) {
|
||||
// Login de usuario
|
||||
$(document).on("click", "#botonAceptarLogin", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let email = $("#loginEmail").val().trim();
|
||||
let contrasena = $("#loginPassword").val();
|
||||
let recuerdame = $("#recordar").is(":checked");
|
||||
|
||||
$("#loginEmail").removeClass("is-invalid");
|
||||
$("#loginPassword").removeClass("is-invalid");
|
||||
$("#errorLogin").text("");
|
||||
$("#loginEmail, #loginPassword").removeClass("is-invalid");
|
||||
$("#errorLogin").removeClass("text-success").addClass("text-danger").text("").show();
|
||||
|
||||
if (email === "" || contrasena === "") {
|
||||
$("#errorLogin").text("Todos los campos son obligatorios.");
|
||||
@@ -166,41 +179,43 @@ $("#botonAceptarLogin").click(function (event) {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
dataType: "json",
|
||||
data: {
|
||||
email: email,
|
||||
contrasena: contrasena,
|
||||
recuerdame: recuerdame,
|
||||
orden: "comprobarUsuario",
|
||||
},
|
||||
}).done(function (respuesta) {
|
||||
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||
|
||||
})
|
||||
.done(function (respuesta) {
|
||||
if (respuesta.error) {
|
||||
$("#loginEmail").addClass("is-invalid");
|
||||
$("#loginPassword").addClass("is-invalid");
|
||||
$("#loginEmail, #loginPassword").addClass("is-invalid");
|
||||
$("#errorLogin").text(respuesta.error);
|
||||
} else {
|
||||
// Login correcto: Recargar la vista
|
||||
location.reload();
|
||||
}
|
||||
})
|
||||
.fail(function (xhr, status, error) {
|
||||
console.error("Error en el login:", error, xhr.responseText);
|
||||
$("#errorLogin").text("Error de conexión o respuesta no válida del servidor.");
|
||||
});
|
||||
});
|
||||
|
||||
// Cerrar sesión
|
||||
// Cerrar sesión
|
||||
$(document).on("click", "#botonCerrarSesion", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "controladores/controladorUsuario.php",
|
||||
dataType: "json",
|
||||
data: { orden: "cerrarSesion" },
|
||||
}).done(function (respuesta) {
|
||||
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||
|
||||
if (respuesta.error) {
|
||||
console.log(respuesta.error);
|
||||
} else {
|
||||
window.location.href = "index.php";
|
||||
}
|
||||
})
|
||||
.done(function (respuesta) {
|
||||
window.location.href = "index.php";
|
||||
})
|
||||
.fail(function () {
|
||||
window.location.href = "index.php";
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
+89
-12
@@ -118,7 +118,12 @@ function mostrarPregunta() {
|
||||
// 3. El usuario pulsa una respuesta: se guarda y se enseña si ha acertado
|
||||
function responder($botonPulsado) {
|
||||
clearInterval(intervaloTiempo);
|
||||
console.log("Tiempo de respuesta: " + tiempoRespuesta / 10 + " segundos");
|
||||
|
||||
console.log(
|
||||
"Tiempo de respuesta: " +
|
||||
tiempoRespuesta / 10 +
|
||||
" segundos"
|
||||
);
|
||||
|
||||
if (bloqueado) {
|
||||
return;
|
||||
@@ -127,7 +132,29 @@ function responder($botonPulsado) {
|
||||
bloqueado = true;
|
||||
|
||||
const pregunta = preguntas[indice];
|
||||
const idRespuesta = parseInt($botonPulsado.attr("data-id-respuesta"), 10);
|
||||
|
||||
const idRespuesta = parseInt(
|
||||
$botonPulsado.attr("data-id-respuesta"),
|
||||
10
|
||||
);
|
||||
|
||||
console.log("PREGUNTA ACTUAL:", pregunta);
|
||||
console.log(
|
||||
"idPartidaxPregunta:",
|
||||
pregunta.idPartidaxPregunta
|
||||
);
|
||||
console.log(
|
||||
"idRespuesta:",
|
||||
idRespuesta
|
||||
);
|
||||
console.log(
|
||||
"tiempoRespuesta:",
|
||||
tiempoRespuesta
|
||||
);
|
||||
console.log(
|
||||
"idPartida:",
|
||||
idPartida
|
||||
);
|
||||
|
||||
$("#respuestas").addClass("bloqueado");
|
||||
|
||||
@@ -135,46 +162,96 @@ function responder($botonPulsado) {
|
||||
url: URL_CONTROLADOR,
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "responder",
|
||||
idPartida: idPartida,
|
||||
idPartidaxPregunta: pregunta.idPartidaxPregunta,
|
||||
idRespuesta: idRespuesta,
|
||||
tiempoRespuesta: tiempoRespuesta,
|
||||
idRespuesta: idRespuesta,
|
||||
tiempoRespuesta: tiempoRespuesta
|
||||
},
|
||||
|
||||
success: function (datos) {
|
||||
|
||||
console.log("RESPUESTA DEL SERVIDOR:", datos);
|
||||
|
||||
if (datos.error) {
|
||||
// No se guardó: dejamos que vuelva a intentarlo
|
||||
$("#feedback").text(datos.error).removeClass("ok").addClass("ko");
|
||||
|
||||
$("#feedback")
|
||||
.text(datos.error)
|
||||
.removeClass("ok")
|
||||
.addClass("ko");
|
||||
|
||||
$("#respuestas").removeClass("bloqueado");
|
||||
|
||||
bloqueado = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pregunta.respondida = true;
|
||||
mostrarFeedback($botonPulsado, datos);
|
||||
|
||||
mostrarFeedback(
|
||||
$botonPulsado,
|
||||
datos
|
||||
);
|
||||
|
||||
setTimeout(function () {
|
||||
if (datos.terminada || indice >= preguntas.length - 1) {
|
||||
|
||||
if (
|
||||
datos.terminada ||
|
||||
indice >= preguntas.length - 1
|
||||
) {
|
||||
terminar();
|
||||
} else {
|
||||
|
||||
indice++;
|
||||
$("#respuestas").removeClass("bloqueado");
|
||||
|
||||
$("#respuestas")
|
||||
.removeClass("bloqueado");
|
||||
|
||||
mostrarPregunta();
|
||||
}
|
||||
|
||||
}, PAUSA_FEEDBACK);
|
||||
},
|
||||
error: function () {
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
|
||||
console.error(
|
||||
"ERROR AJAX RESPONDER"
|
||||
);
|
||||
|
||||
console.error(
|
||||
"HTTP:",
|
||||
xhr.status
|
||||
);
|
||||
|
||||
console.error(
|
||||
"ERROR:",
|
||||
error
|
||||
);
|
||||
|
||||
console.error(
|
||||
"RESPUESTA:",
|
||||
xhr.responseText
|
||||
);
|
||||
|
||||
$("#feedback")
|
||||
.text("No se pudo guardar la respuesta. Inténtalo de nuevo.")
|
||||
.text(
|
||||
"No se pudo guardar la respuesta. Inténtalo de nuevo."
|
||||
)
|
||||
.removeClass("ok")
|
||||
.addClass("ko");
|
||||
|
||||
$("#respuestas").removeClass("bloqueado");
|
||||
|
||||
bloqueado = false;
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Marca la respuesta correcta en verde y atenúa el resto
|
||||
function mostrarFeedback($botonPulsado, datos) {
|
||||
$("#respuestas .btn-answer").each(function () {
|
||||
|
||||
+6
-6
@@ -50,10 +50,9 @@ function cambiarNombre() {
|
||||
$("#nuevoNombre").val("");
|
||||
|
||||
|
||||
if (typeof comprobarEstadoSesion === "function") {
|
||||
comprobarEstadoSesion();
|
||||
}
|
||||
comprobarSesion();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,6 +70,7 @@ function borrarNombre() {
|
||||
|
||||
function seleccionarFoto() {
|
||||
$("#inputFoto").click();
|
||||
|
||||
}
|
||||
|
||||
$("#inputFoto").change(function () {
|
||||
@@ -79,6 +79,7 @@ $("#inputFoto").change(function () {
|
||||
if (!archivo) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Comprobamos que sea una imagen
|
||||
if (!archivo.type.startsWith("image/")) {
|
||||
@@ -110,9 +111,8 @@ $("#inputFoto").change(function () {
|
||||
);
|
||||
|
||||
// Actualizamos también el avatar superior en la cabecera
|
||||
if (typeof comprobarEstadoSesion === "function") {
|
||||
comprobarEstadoSesion();
|
||||
}
|
||||
|
||||
comprobarSesion();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+113
-44
@@ -263,15 +263,16 @@ function mostrarSala(partida, equipos, jugadores) {
|
||||
|
||||
if (esHost) {
|
||||
botonIniciarHTML = `
|
||||
<a
|
||||
href="juego.php?idPartida=${partida.idPartida}"
|
||||
class="btn btn-success btn-lg px-4">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-success btn-lg px-4 btn-iniciar-partida"
|
||||
data-id-partida="${partida.idPartida}">
|
||||
|
||||
<i class="bi bi-controller"></i>
|
||||
¡Iniciar Partida!
|
||||
<i class="bi bi-controller"></i>
|
||||
¡Iniciar Partida!
|
||||
|
||||
</a>
|
||||
`;
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
|
||||
const salaHTML = `
|
||||
@@ -313,8 +314,98 @@ function mostrarSala(partida, equipos, jugadores) {
|
||||
`;
|
||||
|
||||
contenedor.html(salaHTML);
|
||||
if (!partida.fechaInicio) {
|
||||
iniciarComprobacionPartida(partida.idPartida);
|
||||
}
|
||||
}
|
||||
|
||||
let intervaloComprobarPartida = null;
|
||||
|
||||
function iniciarComprobacionPartida(idPartida) {
|
||||
if (intervaloComprobarPartida) {
|
||||
clearInterval(intervaloComprobarPartida);
|
||||
}
|
||||
|
||||
intervaloComprobarPartida = setInterval(function () {
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
|
||||
type: "POST",
|
||||
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "comprobarInicio",
|
||||
idPartida: idPartida,
|
||||
},
|
||||
|
||||
success: function (respuesta) {
|
||||
if (respuesta.iniciada) {
|
||||
clearInterval(intervaloComprobarPartida);
|
||||
|
||||
window.location.href = "juego.php?idPartida=" + idPartida;
|
||||
}
|
||||
},
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
$(document).on("click", ".btn-iniciar-partida", function () {
|
||||
const boton = $(this);
|
||||
|
||||
const idPartida = boton.data("id-partida");
|
||||
|
||||
boton.prop("disabled", true);
|
||||
|
||||
boton.html(`
|
||||
<span class="spinner-border spinner-border-sm"></span>
|
||||
Iniciando...
|
||||
`);
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorPartida.php",
|
||||
|
||||
type: "POST",
|
||||
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "iniciar",
|
||||
|
||||
idPartida: idPartida,
|
||||
},
|
||||
|
||||
success: function (respuesta) {
|
||||
if (respuesta.error) {
|
||||
alert(respuesta.error);
|
||||
|
||||
boton.prop("disabled", false);
|
||||
|
||||
boton.html(`
|
||||
<i class="bi bi-controller"></i>
|
||||
¡Iniciar Partida!
|
||||
`);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// El host entra directamente
|
||||
window.location.href = "juego.php?idPartida=" + idPartida;
|
||||
},
|
||||
|
||||
error: function () {
|
||||
alert("Ocurrió un error al iniciar la partida.");
|
||||
|
||||
boton.prop("disabled", false);
|
||||
|
||||
boton.html(`
|
||||
<i class="bi bi-controller"></i>
|
||||
¡Iniciar Partida!
|
||||
`);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("click", ".btn-unirse-equipo", function () {
|
||||
const boton = $(this);
|
||||
|
||||
@@ -364,8 +455,7 @@ $(document).on("click", ".btn-abandonar-sala", function () {
|
||||
botonAbandonarReferencia = $(this);
|
||||
|
||||
const esHost =
|
||||
$(this).data("es-host") === true ||
|
||||
$(this).data("es-host") === "true";
|
||||
$(this).data("es-host") === true || $(this).data("es-host") === "true";
|
||||
|
||||
const titulo = $("#modalAbandonarSalaLabel");
|
||||
|
||||
@@ -384,9 +474,7 @@ $(document).on("click", ".btn-abandonar-sala", function () {
|
||||
} else {
|
||||
titulo.text("¿Abandonar la sala?");
|
||||
|
||||
mensaje.text(
|
||||
"Si sales de la sala, perderás tu lugar en el equipo.",
|
||||
);
|
||||
mensaje.text("Si sales de la sala, perderás tu lugar en el equipo.");
|
||||
|
||||
botonConfirmar.text("Sí, salir");
|
||||
}
|
||||
@@ -399,17 +487,13 @@ $(document).on("click", ".btn-abandonar-sala", function () {
|
||||
});
|
||||
|
||||
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||
const modalEl =
|
||||
document.getElementById("modalAbandonarSala");
|
||||
const modalEl = document.getElementById("modalAbandonarSala");
|
||||
|
||||
const modalInstance =
|
||||
bootstrap.Modal.getInstance(modalEl);
|
||||
const modalInstance = bootstrap.Modal.getInstance(modalEl);
|
||||
|
||||
const btnConfirmar = $(this);
|
||||
|
||||
btnConfirmar
|
||||
.prop("disabled", true)
|
||||
.text("Saliendo...");
|
||||
btnConfirmar.prop("disabled", true).text("Saliendo...");
|
||||
|
||||
$.ajax({
|
||||
url: "controladores/controladorEquipoxUsuario.php",
|
||||
@@ -421,9 +505,7 @@ $(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||
},
|
||||
|
||||
success: function (respuesta) {
|
||||
btnConfirmar
|
||||
.prop("disabled", false)
|
||||
.text("Sí, salir");
|
||||
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||
|
||||
if (modalInstance) {
|
||||
modalInstance.hide();
|
||||
@@ -449,16 +531,11 @@ $(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||
},
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
console.error(
|
||||
"Error al salir de la sala:",
|
||||
error
|
||||
);
|
||||
console.error("Error al salir de la sala:", error);
|
||||
|
||||
alert("No se pudo salir de la sala.");
|
||||
|
||||
btnConfirmar
|
||||
.prop("disabled", false)
|
||||
.text("Sí, salir");
|
||||
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||
|
||||
if (modalInstance) {
|
||||
modalInstance.hide();
|
||||
@@ -473,25 +550,19 @@ function escapeHTML(texto) {
|
||||
.html();
|
||||
}
|
||||
|
||||
function mostrarEquipos(
|
||||
partida,
|
||||
equipos,
|
||||
jugadores
|
||||
) {
|
||||
function mostrarEquipos(partida, equipos, jugadores) {
|
||||
let equiposHTML = "";
|
||||
|
||||
equipos.forEach(function (equipo) {
|
||||
const jugadoresEquipo =
|
||||
jugadores.filter(function (jugador) {
|
||||
return jugador.idEquipo == equipo.idEquipo;
|
||||
});
|
||||
const jugadoresEquipo = jugadores.filter(function (jugador) {
|
||||
return jugador.idEquipo == equipo.idEquipo;
|
||||
});
|
||||
|
||||
let jugadoresHTML = "";
|
||||
|
||||
if (jugadoresEquipo.length > 0) {
|
||||
jugadoresEquipo.forEach(function (jugador) {
|
||||
const esHost =
|
||||
jugador.idUsuario == partida.idUsuario;
|
||||
const esHost = jugador.idUsuario == partida.idUsuario;
|
||||
|
||||
jugadoresHTML += `
|
||||
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
||||
@@ -507,9 +578,7 @@ function mostrarEquipos(
|
||||
}
|
||||
</span>
|
||||
|
||||
${escapeHTML(
|
||||
jugador.nombreUsuario
|
||||
)}
|
||||
${escapeHTML(jugador.nombreUsuario)}
|
||||
</div>
|
||||
|
||||
${
|
||||
@@ -547,4 +616,4 @@ function mostrarEquipos(
|
||||
});
|
||||
|
||||
$("#contenedorSalas .equipos").html(equiposHTML);
|
||||
}
|
||||
}
|
||||
|
||||
+1476
-1388
File diff suppressed because it is too large
Load Diff
+4
-20
@@ -1,17 +1,3 @@
|
||||
<?php
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Redirección si el usuario no ha iniciado sesión
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$nombreUsuario = htmlspecialchars($_SESSION['nombreUsuario'] ?? 'Usuario');
|
||||
$avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultProfile.jpeg');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
|
||||
@@ -41,7 +27,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
||||
|
||||
<body>
|
||||
|
||||
<?php include_once 'cabecera.php'; ?>
|
||||
<header id="cabecera-container"></header>
|
||||
|
||||
<div class="perfil-container">
|
||||
|
||||
@@ -61,15 +47,13 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
||||
<div class="col-md-6 text-center">
|
||||
|
||||
<!-- Nombre -->
|
||||
<h1 id="nombre" class="nombre">
|
||||
<?= $nombreUsuario ?>
|
||||
</h1>
|
||||
<h1 id="nombre" class="nombre"></h1>
|
||||
|
||||
<!-- FOTO DE PERFIL -->
|
||||
<div class="foto-container">
|
||||
|
||||
<img id="fotoPerfil"
|
||||
src="<?= $avatarUsuario ?>"
|
||||
src="img/avatars/defaultProfile.jpeg"
|
||||
alt="Foto de perfil"
|
||||
class="avatar rounded-circle">
|
||||
|
||||
@@ -310,7 +294,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
||||
|
||||
<!-- Tu JavaScript -->
|
||||
<script src="js/perfil.js"></script>
|
||||
|
||||
<script src="js/cabecera.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user