Compare commits
11 Commits
57e3dfc444
...
host2
| Author | SHA1 | Date | |
|---|---|---|---|
| c8c0792bd7 | |||
| 534c20a45d | |||
| 94bfe480cb | |||
| 42cc1489e9 | |||
| a694f19667 | |||
| 3cc0dfb122 | |||
| 4efb831b7a | |||
| 22f38f924f | |||
| 01aa2643f6 | |||
| 07c1f79474 | |||
| 54b6b0d67b |
+57
-154
@@ -4,200 +4,103 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
<title>Trivial - Lobby</title>
|
<title>Trivial - Lobby</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">
|
||||||
<link
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">
|
||||||
rel="stylesheet">
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="css/index.css">
|
<link rel="stylesheet" href="css/index.css">
|
||||||
<link rel="stylesheet" href="css/buscadorSala.css">
|
<link rel="stylesheet" href="css/buscadorSala.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<?php
|
<?php include_once("cabecera.php"); ?>
|
||||||
include_once("cabecera.php");
|
|
||||||
?>
|
|
||||||
|
|
||||||
<main class="container py-5">
|
<main class="container py-4">
|
||||||
|
|
||||||
|
<!-- Botón Volver -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<a href="index.php" class="btn btn-outline-secondary d-inline-flex align-items-center gap-2">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-left" viewBox="0 0 16 16">
|
||||||
|
<path fill-rule="evenodd" d="M15 8a.5.5 0 0 0-.5-.5H2.707l3.147-3.146a.5.5 0 1 0-.708-.708l-4 4a.5.5 0 0 0 0 .708l4 4a.5.5 0 0 0 .708-.708L2.707 8.5H14.5A.5.5 0 0 0 15 8"/>
|
||||||
|
</svg>
|
||||||
|
Volver al Inicio
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Botón Crear Sala -->
|
||||||
<div id="contenedorCrearSala" class="text-center mb-5">
|
<div id="contenedorCrearSala" class="text-center mb-5">
|
||||||
|
<button type="button" class="btn btn-play-kahoot btn-crear-sala" data-bs-toggle="modal" data-bs-target="#modalCrearSala">
|
||||||
|
<span>+</span> Crear sala
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn btn-play-kahoot btn-crear-sala"
|
|
||||||
data-bs-toggle="modal"
|
|
||||||
data-bs-target="#modalCrearSala">
|
|
||||||
|
|
||||||
<span>+</span>
|
|
||||||
Crear sala
|
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<!-- Contenedor Principal de Salas -->
|
||||||
id="contenedorSalas"
|
<div id="contenedorSalas" class="row justify-content-center g-4">
|
||||||
class="row justify-content-center g-4">
|
<div id="cargandoSalas" class="col-12 text-center">
|
||||||
|
<div class="spinner-border text-primary" role="status">
|
||||||
<div
|
<span class="visually-hidden">Cargando...</span>
|
||||||
id="cargandoSalas"
|
|
||||||
class="col-12 text-center">
|
|
||||||
|
|
||||||
<div
|
|
||||||
class="spinner-border text-primary"
|
|
||||||
role="status">
|
|
||||||
|
|
||||||
<span class="visually-hidden">
|
|
||||||
Cargando...
|
|
||||||
</span>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<p class="mt-3 text-muted">Cargando salas...</p>
|
||||||
<p class="mt-3 text-muted">
|
|
||||||
Cargando salas...
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<!-- Modal Crear Sala -->
|
<!-- Modal Crear Sala -->
|
||||||
<div
|
<div class="modal fade" id="modalCrearSala" tabindex="-1" aria-labelledby="modalCrearSalaLabel" aria-hidden="true">
|
||||||
class="modal fade"
|
|
||||||
id="modalCrearSala"
|
|
||||||
tabindex="-1"
|
|
||||||
aria-labelledby="modalCrearSalaLabel"
|
|
||||||
aria-hidden="true">
|
|
||||||
|
|
||||||
<div class="modal-dialog modal-dialog-centered">
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
|
|
||||||
<div class="modal-content modal-kahoot">
|
<div class="modal-content modal-kahoot">
|
||||||
|
|
||||||
<div class="modal-header modal-kahoot-header">
|
<div class="modal-header modal-kahoot-header">
|
||||||
|
<h5 class="modal-title" id="modalCrearSalaLabel">Crear sala</h5>
|
||||||
<h5
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Cerrar"></button>
|
||||||
class="modal-title"
|
|
||||||
id="modalCrearSalaLabel">
|
|
||||||
|
|
||||||
Crear sala
|
|
||||||
|
|
||||||
</h5>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn-close btn-close-white"
|
|
||||||
data-bs-dismiss="modal"
|
|
||||||
aria-label="Cerrar">
|
|
||||||
</button>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-body p-4">
|
<div class="modal-body p-4">
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
<label for="nombreSala" class="form-label">Nombre de la sala</label>
|
||||||
<label
|
<input type="text" id="nombreSala" class="form-control input-kahoot" name="nombreSala" placeholder="Ej. Noche de Trivial" maxlength="100">
|
||||||
for="nombreSala"
|
|
||||||
class="form-label">
|
|
||||||
|
|
||||||
Nombre de la sala
|
|
||||||
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="nombreSala"
|
|
||||||
class="form-control input-kahoot"
|
|
||||||
name="nombreSala"
|
|
||||||
placeholder="Ej. Noche de Trivial"
|
|
||||||
maxlength="100">
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
<label for="nombreEquipo1" class="form-label">Nombre del equipo 1</label>
|
||||||
<label
|
<input type="text" id="nombreEquipo1" name="nombreEquipo1" class="form-control input-kahoot" placeholder="Ej. Los cerebritos" maxlength="50">
|
||||||
for="nombreEquipo1"
|
|
||||||
class="form-label">
|
|
||||||
|
|
||||||
Nombre del equipo 1
|
|
||||||
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="nombreEquipo1"
|
|
||||||
name="nombreEquipo1"
|
|
||||||
class="form-control input-kahoot"
|
|
||||||
placeholder="Ej. Los cerebritos"
|
|
||||||
maxlength="50">
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
<label for="nombreEquipo2" class="form-label">Nombre del equipo 2</label>
|
||||||
<label
|
<input type="text" id="nombreEquipo2" name="nombreEquipo2" class="form-control input-kahoot" placeholder="Ej. Los campeones" maxlength="50">
|
||||||
for="nombreEquipo2"
|
|
||||||
class="form-label">
|
|
||||||
|
|
||||||
Nombre del equipo 2
|
|
||||||
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="nombreEquipo2"
|
|
||||||
name="nombreEquipo2"
|
|
||||||
class="form-control input-kahoot"
|
|
||||||
placeholder="Ej. Los campeones"
|
|
||||||
maxlength="50">
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
||||||
<button
|
<button type="button" class="btn btn-kahoot-login" id="btnCrearSala">Crear sala</button>
|
||||||
type="button"
|
</div>
|
||||||
class="btn btn-secondary"
|
</div>
|
||||||
data-bs-dismiss="modal">
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--MODAL ABANDONAR SALA -->
|
||||||
|
<!-- Modal Confirmar Abandonar Sala -->
|
||||||
|
<div class="modal fade" id="modalAbandonarSala" tabindex="-1" aria-labelledby="modalAbandonarSalaLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
|
<div class="modal-content modal-kahoot text-center p-3">
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="mb-3 fs-1">⚠️</div>
|
||||||
|
<h4 class="modal-title mb-2 fw-bold" id="modalAbandonarSalaLabel">¿Abandonar la sala?</h4>
|
||||||
|
<p class="text-dark-50" id="modalAbandonarSalaMensaje">Si sales de la sala, perderás tu lugar en el equipo.</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer justify-content-center border-0 gap-2">
|
||||||
|
<button type="button" class="btn btn-secondary px-4 py-2" data-bs-dismiss="modal">
|
||||||
Cancelar
|
Cancelar
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" id="btnConfirmarAbandonar" class="btn btn-danger px-4 py-2">
|
||||||
<button
|
Sí, salir
|
||||||
type="button"
|
|
||||||
class="btn btn-kahoot-login"
|
|
||||||
id="btnCrearSala">
|
|
||||||
|
|
||||||
Crear sala
|
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</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>
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script
|
|
||||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js">
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="js/jquery.min.js"></script>
|
|
||||||
|
|
||||||
<script src="js/buscadorSala.js"></script>
|
<script src="js/buscadorSala.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
+10
-55
@@ -1,13 +1,3 @@
|
|||||||
<?php
|
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
|
||||||
session_start();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprobación de sesión
|
|
||||||
$isLoggedIn = isset($_SESSION['idUsuario']) && !empty($_SESSION['idUsuario']);
|
|
||||||
$username = $isLoggedIn ? $_SESSION['nombreUsuario'] : '';
|
|
||||||
?>
|
|
||||||
|
|
||||||
<!-- Bootstrap 5 CSS -->
|
<!-- Bootstrap 5 CSS -->
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<!-- FontAwesome para iconos -->
|
<!-- FontAwesome para iconos -->
|
||||||
@@ -17,7 +7,6 @@ $username = $isLoggedIn ? $_SESSION['nombreUsuario'] : '';
|
|||||||
<link rel="stylesheet" href="css/index.css">
|
<link rel="stylesheet" href="css/index.css">
|
||||||
<script src="js/jquery-4.0.0.min.js"></script>
|
<script src="js/jquery-4.0.0.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
<nav class="navbar navbar-expand-lg navbar-kahoot py-3 mb-4">
|
<nav class="navbar navbar-expand-lg navbar-kahoot py-3 mb-4">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a class="navbar-brand" href="index.php">
|
<a class="navbar-brand" href="index.php">
|
||||||
@@ -32,44 +21,8 @@ $username = $isLoggedIn ? $_SESSION['nombreUsuario'] : '';
|
|||||||
<div class="collapse navbar-collapse" id="navbarContent">
|
<div class="collapse navbar-collapse" id="navbarContent">
|
||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0"></ul>
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0"></ul>
|
||||||
|
|
||||||
<div class="d-flex align-items-center gap-3">
|
<!-- Contenedor dinámico cargado por js/cabecera.js -->
|
||||||
<?php if ($isLoggedIn): ?>
|
<div class="d-flex align-items-center gap-3" id="contenedorUsuarioCabecera">
|
||||||
<!-- Menú desplegable cuando la sesión está iniciada -->
|
|
||||||
<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">
|
|
||||||
<i class="fa-solid fa-circle-user fa-lg text-warning"></i>
|
|
||||||
<span><?= htmlspecialchars($username) ?></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>
|
|
||||||
<?php else: ?>
|
|
||||||
<!-- Botones que abren los modales cuando NO hay sesión iniciada -->
|
|
||||||
<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>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -95,11 +48,6 @@ $username = $isLoggedIn ? $_SESSION['nombreUsuario'] : '';
|
|||||||
<input type="password" class="form-control border-dark" id="loginPassword" name="contrasena" placeholder="Contraseña" required>
|
<input type="password" class="form-control border-dark" id="loginPassword" name="contrasena" placeholder="Contraseña" required>
|
||||||
<label for="loginPassword">Contraseña</label>
|
<label for="loginPassword">Contraseña</label>
|
||||||
</div>
|
</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>
|
</form>
|
||||||
<div id="errorLogin" class="text-danger fw-bold mt-2"></div>
|
<div id="errorLogin" class="text-danger fw-bold mt-2"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -139,7 +87,14 @@ $username = $isLoggedIn ? $_SESSION['nombreUsuario'] : '';
|
|||||||
<input type="password" class="form-control border-dark" id="regPasswordConfirm" name="contrasenaConfirm" placeholder="Confirmar contraseña" required>
|
<input type="password" class="form-control border-dark" id="regPasswordConfirm" name="contrasenaConfirm" placeholder="Confirmar contraseña" required>
|
||||||
<label for="regPasswordConfirm">Confirmar contraseña</label>
|
<label for="regPasswordConfirm">Confirmar contraseña</label>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="orden" value="registrar">
|
|
||||||
|
<!-- Checkbox Recuérdame -->
|
||||||
|
<div class="form-check mb-3">
|
||||||
|
<input class="form-check-input border-dark" type="checkbox" value="" id="recuerdameCheck">
|
||||||
|
<label class="form-check-label fw-semibold" for="recuerdameCheck">
|
||||||
|
Recuérdame en 10 días
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div id="errorRegistro" class="text-danger fw-bold mt-2"></div>
|
<div id="errorRegistro" class="text-danger fw-bold mt-2"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class EquipoxUsuario
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function obtenerSalaUsuario($idUsuario)
|
public function obtenerSalaUsuario($idUsuario)
|
||||||
{
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
@@ -108,7 +109,6 @@ class EquipoxUsuario
|
|||||||
'idEquipo' => $resultado['idEquipo'],
|
'idEquipo' => $resultado['idEquipo'],
|
||||||
'idPartida' => $resultado['idPartida']
|
'idPartida' => $resultado['idPartida']
|
||||||
];
|
];
|
||||||
|
|
||||||
} catch (PDOException $error) {
|
} catch (PDOException $error) {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -118,4 +118,152 @@ class EquipoxUsuario
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function salirDeSala($idUsuario)
|
||||||
|
{
|
||||||
|
$conexion = conexionBD();
|
||||||
|
|
||||||
|
if (is_array($conexion)) {
|
||||||
|
return $conexion;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 1. Averiguamos el equipo y la partida del usuario
|
||||||
|
$sql = "SELECT exu.idEquipo, exp.idPartida, p.idUsuario AS idHost FROM equipoxusuario exu INNER JOIN equipoxpartida exp ON exu.idEquipo = exp.idEquipo INNER JOIN partida p ON exp.idPartida = p.idPartida WHERE exu.idUsuario = :idUsuario LIMIT 1";
|
||||||
|
|
||||||
|
$consulta = $conexion->prepare($sql);
|
||||||
|
$consulta->bindParam(':idUsuario',$idUsuario, PDO::PARAM_INT);
|
||||||
|
$consulta->execute();
|
||||||
|
|
||||||
|
$datosSala = $consulta->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// El usuario no pertenece a ninguna sala
|
||||||
|
if (!$datosSala) {
|
||||||
|
return [
|
||||||
|
'error' => 'No perteneces a ninguna sala.'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$idEquipo = (int)$datosSala['idEquipo'];
|
||||||
|
$idPartida = (int)$datosSala['idPartida'];
|
||||||
|
$idHost = (int)$datosSala['idHost'];
|
||||||
|
|
||||||
|
// Comenzamos una transacción
|
||||||
|
$conexion->beginTransaction();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 2. Comprobamos si quien abandona es el HOST
|
||||||
|
*/
|
||||||
|
if ($idUsuario === $idHost) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Obtenemos todos los equipos pertenecientes
|
||||||
|
* a esta partida.
|
||||||
|
*/
|
||||||
|
$sqlEquipos = "SELECT idEquipo FROM equipoxpartida WHERE idPartida = :idPartida";
|
||||||
|
|
||||||
|
$consultaEquipos = $conexion->prepare($sqlEquipos);
|
||||||
|
$consultaEquipos->bindParam(':idPartida', $idPartida, PDO::PARAM_INT);
|
||||||
|
$consultaEquipos->execute();
|
||||||
|
|
||||||
|
$equipos = $consultaEquipos->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 3. Eliminamos los jugadores de esos equipos
|
||||||
|
* de la tabla equipoxusuario.
|
||||||
|
*/
|
||||||
|
if (!empty($equipos)) {
|
||||||
|
|
||||||
|
$placeholders = implode(',', array_fill(0, count($equipos), '?'));
|
||||||
|
|
||||||
|
$sqlUsuarios = "DELETE FROM equipoxusuario WHERE idEquipo IN ($placeholders)";
|
||||||
|
|
||||||
|
$consultaUsuarios = $conexion->prepare($sqlUsuarios);
|
||||||
|
$consultaUsuarios->execute($equipos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 4. Eliminamos las relaciones
|
||||||
|
* entre equipos y partida.
|
||||||
|
*/
|
||||||
|
$sqlEquipoxPartida = "DELETE FROM equipoxpartida WHERE idPartida = :idPartida";
|
||||||
|
|
||||||
|
$consultaEquipoxPartida = $conexion->prepare($sqlEquipoxPartida);
|
||||||
|
$consultaEquipoxPartida->bindParam(':idPartida', $idPartida,PDO::PARAM_INT);
|
||||||
|
$consultaEquipoxPartida->execute();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 5. Eliminamos los equipos.
|
||||||
|
*
|
||||||
|
* Los equipos ya no tienen relaciones con
|
||||||
|
* usuarios ni con la partida.
|
||||||
|
*/
|
||||||
|
if (!empty($equipos)) {
|
||||||
|
|
||||||
|
$placeholders = implode(',', array_fill(0, count($equipos), '?'));
|
||||||
|
|
||||||
|
$sqlEliminarEquipos = "DELETE FROM equipo WHERE idEquipo IN ($placeholders)";
|
||||||
|
$consultaEliminarEquipos = $conexion->prepare($sqlEliminarEquipos);
|
||||||
|
$consultaEliminarEquipos->execute($equipos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 6. Eliminamos las relaciones
|
||||||
|
* entre preguntas y partida.
|
||||||
|
*/
|
||||||
|
$sqlPartidaxPregunta = "DELETE FROM partidaxpregunta WHERE idPartida = :idPartida";
|
||||||
|
|
||||||
|
$consultaPartidaxPregunta = $conexion->prepare($sqlPartidaxPregunta);
|
||||||
|
$consultaPartidaxPregunta->bindParam(':idPartida', $idPartida, PDO::PARAM_INT);
|
||||||
|
$consultaPartidaxPregunta->execute();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 7. Finalmente eliminamos la partida.
|
||||||
|
*/
|
||||||
|
$sqlPartida = "DELETE FROM partida WHERE idPartida = :idPartida";
|
||||||
|
|
||||||
|
$consultaPartida = $conexion->prepare($sqlPartida);
|
||||||
|
$consultaPartida->bindParam(':idPartida', $idPartida, PDO::PARAM_INT);
|
||||||
|
$consultaPartida->execute();
|
||||||
|
|
||||||
|
// Todo ha ido correctamente
|
||||||
|
$conexion->commit();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'exito' => true,
|
||||||
|
'salaEliminada' => true,
|
||||||
|
'mensaje' => 'La sala ha sido eliminada correctamente.'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 7. Si NO es el host, simplemente abandona
|
||||||
|
* su relación con el equipo.
|
||||||
|
*/
|
||||||
|
$sqlSalir = "DELETE FROM equipoxusuario WHERE idUsuario = :idUsuario";
|
||||||
|
|
||||||
|
$consultaSalir = $conexion->prepare($sqlSalir);
|
||||||
|
$consultaSalir->bindParam(':idUsuario', $idUsuario, PDO::PARAM_INT);
|
||||||
|
$consultaSalir->execute();
|
||||||
|
|
||||||
|
$conexion->commit();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'exito' => true,
|
||||||
|
'salaEliminada' => false,
|
||||||
|
'mensaje' => 'Has abandonado la sala correctamente.'
|
||||||
|
];
|
||||||
|
} catch (PDOException $error) {
|
||||||
|
|
||||||
|
// Si había una transacción activa, la deshacemos
|
||||||
|
if ($conexion->inTransaction()) {
|
||||||
|
$conexion->rollBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'error' => 'Ocurrió un error al abandonar la sala.',
|
||||||
|
'error_tecnico' => $error->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,4 +75,16 @@ switch ($_POST['orden']) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case 'salirDeSala':
|
||||||
|
if (!isset($_SESSION['idUsuario'])) {
|
||||||
|
echo json_encode(['error' => 'Usuario no autenticado']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$idUsuario = $_SESSION['idUsuario'];
|
||||||
|
$respuesta = EquipoxUsuario::salirDeSala($idUsuario);
|
||||||
|
|
||||||
|
echo json_encode($respuesta);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,13 @@ switch ($_POST['orden']) {
|
|||||||
|
|
||||||
if ($resultado instanceof Usuario) {
|
if ($resultado instanceof Usuario) {
|
||||||
|
|
||||||
|
// === GUARDAR EN SESIÓN (incluido avatar)===
|
||||||
|
$_SESSION['idUsuario'] = $resultado->getIdUsuario();
|
||||||
|
$_SESSION['nombreUsuario'] = $resultado->getNombreUsuario();
|
||||||
|
$_SESSION['email'] = $resultado->getEmail();
|
||||||
|
$_SESSION['avatar'] = $resultado->getAvatar();
|
||||||
|
// =================================================
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'exito' => 'Login correcto',
|
'exito' => 'Login correcto',
|
||||||
'idUsuario' => $resultado->getIdUsuario(),
|
'idUsuario' => $resultado->getIdUsuario(),
|
||||||
@@ -77,6 +84,7 @@ switch ($_POST['orden']) {
|
|||||||
unset($_SESSION['idUsuario']);
|
unset($_SESSION['idUsuario']);
|
||||||
unset($_SESSION['email']);
|
unset($_SESSION['email']);
|
||||||
unset($_SESSION['nombreUsuario']);
|
unset($_SESSION['nombreUsuario']);
|
||||||
|
unset($_SESSION['avatar']);
|
||||||
|
|
||||||
// Destruimos la sesión
|
// Destruimos la sesión
|
||||||
session_destroy();
|
session_destroy();
|
||||||
@@ -86,7 +94,6 @@ switch ($_POST['orden']) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mostrarEstadisticas':
|
case 'mostrarEstadisticas':
|
||||||
|
|
||||||
$usuario = Usuario::buscarPorId($_SESSION['idUsuario']);
|
$usuario = Usuario::buscarPorId($_SESSION['idUsuario']);
|
||||||
@@ -229,4 +236,19 @@ switch ($_POST['orden']) {
|
|||||||
'ranking' => $ranking
|
'ranking' => $ranking
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'comprobarSesion':
|
||||||
|
if (isset($_SESSION['idUsuario']) && !empty($_SESSION['idUsuario'])) {
|
||||||
|
echo json_encode([
|
||||||
|
'activa' => true,
|
||||||
|
'usuario' => [
|
||||||
|
'idUsuario' => $_SESSION['idUsuario'],
|
||||||
|
'nombreUsuario' => $_SESSION['nombreUsuario'] ?? '',
|
||||||
|
'avatar' => $_SESSION['avatar'] ?? ''
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(['activa' => false]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -68,8 +68,8 @@
|
|||||||
|
|
||||||
.btn-unirse {
|
.btn-unirse {
|
||||||
border: none;
|
border: none;
|
||||||
border-bottom: 3px solid #0c4891;
|
border-bottom: 3px solid #1f6f09;
|
||||||
background-color: var(--kahoot-blue);
|
background-color: #26890c;
|
||||||
color: white;
|
color: white;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -105,3 +105,11 @@
|
|||||||
border-color: var(--kahoot-purple);
|
border-color: var(--kahoot-purple);
|
||||||
box-shadow: 0 0 0 3px rgba(70, 23, 143, 0.15);
|
box-shadow: 0 0 0 3px rgba(70, 23, 143, 0.15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.jugador-host {
|
||||||
|
background-color: #fff3cd;
|
||||||
|
border: 1px solid #ffc107;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -1,8 +1,3 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
include 'cabecera.php';
|
|
||||||
?>
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es-ES">
|
<html lang="es-ES">
|
||||||
|
|
||||||
@@ -10,28 +5,26 @@ include 'cabecera.php';
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Triviagmático</title>
|
<title>Triviagmático</title>
|
||||||
<script src="js/jquery-4.0.0.min.js"></script>
|
|
||||||
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<?php include 'cabecera.php'; ?>
|
||||||
|
|
||||||
<div class="container my-5">
|
<div class="container my-5">
|
||||||
<div class="row justify-content-center align-items-center g-4">
|
<div class="row justify-content-center align-items-center g-4">
|
||||||
|
|
||||||
<!-- Botón Jugar (solo se muestra si está logueado) -->
|
<!-- Botón Jugar (oculto por defecto, JS lo muestra si hay sesión activa) -->
|
||||||
<?php if ($isLoggedIn): ?>
|
<div class="col-12 col-lg-5 col-xl-4 d-none" id="colBotonJugar">
|
||||||
<div class="col-12 col-lg-5 col-xl-4">
|
|
||||||
<a href="buscadorSala.php" class="btn btn-play-kahoot" id="btnJugar">
|
<a href="buscadorSala.php" class="btn btn-play-kahoot" id="btnJugar">
|
||||||
<i class="fa-solid fa-play"></i>
|
<i class="fa-solid fa-play"></i>
|
||||||
<span>¡JUGAR!</span>
|
<span>¡JUGAR!</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<!-- Ranking -->
|
<!-- Ranking -->
|
||||||
<div class="col-12 <?= $isLoggedIn ? 'col-lg-7 col-xl-8' : 'col-lg-8' ?>">
|
<div class="col-12 col-lg-8" id="colRanking">
|
||||||
<div class="card ranking-card">
|
<div class="card ranking-card">
|
||||||
<div class="ranking-header">
|
<div class="ranking-header">
|
||||||
<h3 class="m-0"><i class="fa-solid fa-trophy me-2"></i> RANKING GLOBAL DE JUGADORES</h3>
|
<h3 class="m-0"><i class="fa-solid fa-trophy me-2"></i> RANKING GLOBAL DE JUGADORES</h3>
|
||||||
|
|||||||
+167
-221
@@ -4,6 +4,7 @@ $(document).ready(function () {
|
|||||||
comprobarSalaUsuario();
|
comprobarSalaUsuario();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 1. Comprobar si el usuario actual ya pertenece a una sala
|
||||||
function comprobarSalaUsuario() {
|
function comprobarSalaUsuario() {
|
||||||
$("#cargandoSalas").remove();
|
$("#cargandoSalas").remove();
|
||||||
|
|
||||||
@@ -11,101 +12,64 @@ function comprobarSalaUsuario() {
|
|||||||
url: "controladores/ControladorEquipoxUsuario.php",
|
url: "controladores/ControladorEquipoxUsuario.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
data: { orden: "obtenerSalaUsuario" },
|
||||||
data: {
|
|
||||||
orden: "obtenerSalaUsuario",
|
|
||||||
},
|
|
||||||
|
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
console.log("Sala del usuario:", respuesta);
|
if (respuesta.error || !respuesta.asociado) {
|
||||||
|
|
||||||
if (respuesta.error) {
|
|
||||||
console.error(respuesta.error);
|
|
||||||
|
|
||||||
usuarioYaEstaEnEquipo = false;
|
usuarioYaEstaEnEquipo = false;
|
||||||
|
$("#contenedorCrearSala").show();
|
||||||
cargarSalas();
|
cargarSalas();
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (respuesta.asociado) {
|
|
||||||
usuarioYaEstaEnEquipo = true;
|
|
||||||
|
|
||||||
$("#contenedorCrearSala").hide();
|
|
||||||
|
|
||||||
cargarSalaUsuario(respuesta.idPartida);
|
|
||||||
} else {
|
} else {
|
||||||
usuarioYaEstaEnEquipo = false;
|
usuarioYaEstaEnEquipo = true;
|
||||||
|
$("#contenedorCrearSala").hide(); // Ocultar "Crear Sala" si ya pertenece a una
|
||||||
cargarSalas();
|
cargarSalaUsuario(respuesta.idPartida);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
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();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. Cargar únicamente la sala en la que está metido el usuario
|
||||||
function cargarSalaUsuario(idPartida) {
|
function cargarSalaUsuario(idPartida) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
data: { orden: "buscar", idPartida: idPartida },
|
||||||
data: {
|
|
||||||
orden: "buscar",
|
|
||||||
idPartida: idPartida,
|
|
||||||
},
|
|
||||||
|
|
||||||
success: function (partida) {
|
success: function (partida) {
|
||||||
if (partida.error) {
|
if (partida.error) {
|
||||||
console.error(partida.error);
|
console.error(partida.error);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#contenedorSalas").empty();
|
$("#contenedorSalas").empty();
|
||||||
|
|
||||||
cargarInformacionSala(partida);
|
cargarInformacionSala(partida);
|
||||||
},
|
},
|
||||||
|
|
||||||
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);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Cargar la lista completa de todas las salas
|
||||||
function cargarSalas() {
|
function cargarSalas() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
data: { orden: "listar" },
|
||||||
data: {
|
|
||||||
orden: "listar",
|
|
||||||
},
|
|
||||||
|
|
||||||
success: function (partidas) {
|
success: function (partidas) {
|
||||||
const contenedor = $("#contenedorSalas");
|
const contenedor = $("#contenedorSalas");
|
||||||
|
|
||||||
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">No hay salas disponibles actualmente.</p>
|
||||||
No hay salas disponibles.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,54 +77,42 @@ function cargarSalas() {
|
|||||||
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);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. Obtener equipos y jugadores asociados a una sala concreta
|
||||||
function cargarInformacionSala(partida) {
|
function cargarInformacionSala(partida) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
data: { orden: "getEquipos", idPartida: partida.idPartida },
|
||||||
data: {
|
|
||||||
orden: "getEquipos",
|
|
||||||
idPartida: partida.idPartida,
|
|
||||||
},
|
|
||||||
|
|
||||||
success: function (equipos) {
|
success: function (equipos) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
data: { orden: "getJugadores", idPartida: partida.idPartida },
|
||||||
data: {
|
|
||||||
orden: "getJugadores",
|
|
||||||
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);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5. Renderizar el HTML de la sala y botones según estado
|
||||||
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) {
|
||||||
@@ -169,230 +121,249 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let jugadoresHTML = "";
|
let jugadoresHTML = "";
|
||||||
|
|
||||||
if (jugadoresEquipo.length > 0) {
|
if (jugadoresEquipo.length > 0) {
|
||||||
jugadoresEquipo.forEach(function (jugador) {
|
jugadoresEquipo.forEach(function (jugador) {
|
||||||
|
const esHost = jugador.idUsuario == partida.idUsuario;
|
||||||
|
|
||||||
jugadoresHTML += `
|
jugadoresHTML += `
|
||||||
<div class="jugador">
|
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
||||||
|
esHost ? "jugador-host" : ""
|
||||||
<span class="avatar">
|
}">
|
||||||
👤
|
<div>
|
||||||
</span>
|
<span class="avatar">${esHost ? '<i class="bi bi-award-fill"></i>' : '<i class="bi bi-person-fill"></i>'}</span>
|
||||||
|
|
||||||
${escapeHTML(jugador.nombreUsuario)}
|
${escapeHTML(jugador.nombreUsuario)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${
|
||||||
|
esHost
|
||||||
|
? `<span class="badge bg-warning text-dark ms-2">HOST</span>`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
jugadoresHTML = `
|
jugadoresHTML = `<div class="text-muted small">Sin jugadores</div>`;
|
||||||
<div class="text-muted small">
|
|
||||||
Sin jugadores
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Botón "Unirse" solo visible si NO pertenece a ningún equipo
|
||||||
let botonUnirseHTML = "";
|
let botonUnirseHTML = "";
|
||||||
|
|
||||||
if (!usuarioYaEstaEnEquipo) {
|
if (!usuarioYaEstaEnEquipo) {
|
||||||
botonUnirseHTML = `
|
botonUnirseHTML = `
|
||||||
<button
|
<button type="button" class="btn-unirse w-100 btn-unirse-equipo mt-2"
|
||||||
type="button"
|
|
||||||
class="btn btn-unirse w-100 btn-unirse-equipo"
|
|
||||||
data-id-partida="${partida.idPartida}"
|
data-id-partida="${partida.idPartida}"
|
||||||
data-id-equipo="${equipo.idEquipo}">
|
data-id-equipo="${equipo.idEquipo}">
|
||||||
|
|
||||||
Unirse
|
Unirse
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
equiposHTML += `
|
equiposHTML += `
|
||||||
<div class="equipo">
|
<div class="equipo me-2 ms-2 p-3 border rounded">
|
||||||
|
<h6>${escapeHTML(equipo.nombreEquipo)}</h6>
|
||||||
<h6>
|
<div class="jugadores mb-2">
|
||||||
${escapeHTML(equipo.nombreEquipo)}
|
|
||||||
</h6>
|
|
||||||
|
|
||||||
<div class="jugadores">
|
|
||||||
|
|
||||||
${jugadoresHTML}
|
${jugadoresHTML}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${botonUnirseHTML}
|
${botonUnirseHTML}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
||||||
|
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
||||||
|
let accionesSalaHTML = "";
|
||||||
|
|
||||||
|
if (usuarioYaEstaEnEquipo) {
|
||||||
|
const esHost = partida.idUsuario == idUsuarioSesion;
|
||||||
|
let botonIniciarHTML = "";
|
||||||
|
|
||||||
|
// Solo el host puede iniciar la partida
|
||||||
|
if (esHost) {
|
||||||
|
botonIniciarHTML = `
|
||||||
|
<a href="juego.php?idPartida=${partida.idPartida}"
|
||||||
|
class="btn btn-success btn-lg px-4">
|
||||||
|
<i class="bi bi-controller"></i> ¡Iniciar Partida!
|
||||||
|
</a>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
accionesSalaHTML = `
|
||||||
|
<div class="sala-acciones text-center mt-4 pt-3 border-top d-flex justify-content-center gap-3">
|
||||||
|
|
||||||
|
<button type="button"
|
||||||
|
class="btn btn-outline-danger btn-abandonar-sala"
|
||||||
|
data-id-partida="${partida.idPartida}"
|
||||||
|
data-es-host="${esHost}">
|
||||||
|
Abandonar sala
|
||||||
|
</button>
|
||||||
|
|
||||||
|
${botonIniciarHTML}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
const salaHTML = `
|
const salaHTML = `
|
||||||
<div class="col-12 col-md-10 col-lg-8">
|
<div class="col-12 col-md-10 col-lg-8">
|
||||||
|
<div class="sala card p-3 shadow-sm mb-4">
|
||||||
<div class="sala">
|
<div class="sala-header h4 text-center mb-3 text-white">
|
||||||
|
|
||||||
<div class="sala-header">
|
|
||||||
|
|
||||||
${escapeHTML(partida.nombrePartida)}
|
${escapeHTML(partida.nombrePartida)}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="sala-body">
|
<div class="sala-body">
|
||||||
|
<div class="equipos d-flex justify-content-around">
|
||||||
<div class="equipos">
|
|
||||||
|
|
||||||
${equiposHTML}
|
${equiposHTML}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
${accionesSalaHTML}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
contenedor.append(salaHTML);
|
contenedor.append(salaHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
// 6. Evento: Unirse a un Equipo
|
||||||
// UNIRSE A UN EQUIPO
|
|
||||||
// ======================================================
|
|
||||||
|
|
||||||
$(document).on("click", ".btn-unirse-equipo", function () {
|
$(document).on("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).text("Uniéndose...");
|
||||||
|
|
||||||
boton.text("Uniéndose...");
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/ControladorEquipoxUsuario.php",
|
url: "controladores/ControladorEquipoxUsuario.php",
|
||||||
|
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "registrarUsuarioEnEquipo",
|
orden: "registrarUsuarioEnEquipo",
|
||||||
idEquipo: idEquipo,
|
idEquipo: idEquipo,
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
console.log("Respuesta al unirse:", respuesta);
|
|
||||||
|
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
|
boton.prop("disabled", false).text("Unirse");
|
||||||
boton.prop("disabled", false);
|
|
||||||
|
|
||||||
boton.text("Unirse");
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// UNIÓN CORRECTA
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
usuarioYaEstaEnEquipo = true;
|
usuarioYaEstaEnEquipo = true;
|
||||||
|
|
||||||
// Ocultamos el botón "Crear sala"
|
|
||||||
|
|
||||||
$("#contenedorCrearSala").hide();
|
$("#contenedorCrearSala").hide();
|
||||||
|
|
||||||
// Eliminamos las salas actuales
|
|
||||||
|
|
||||||
$("#contenedorSalas").empty();
|
$("#contenedorSalas").empty();
|
||||||
|
|
||||||
// Cargamos directamente la sala
|
|
||||||
// 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("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).text("Unirse");
|
||||||
boton.prop("disabled", false);
|
|
||||||
|
|
||||||
boton.text("Unirse");
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ======================================================
|
// 7. Evento: Abandonar Sala
|
||||||
// ESCAPAR HTML
|
// Guardamos temporalmente el botón presionado
|
||||||
// ======================================================
|
let botonAbandonarReferencia = null;
|
||||||
|
|
||||||
function escapeHTML(texto) {
|
// A. Al hacer clic en el botón "Abandonar sala" de la tarjeta, abrimos el modal
|
||||||
return $("<div>")
|
$(document).on("click", ".btn-abandonar-sala", function () {
|
||||||
.text(texto ?? "")
|
botonAbandonarReferencia = $(this);
|
||||||
.html();
|
|
||||||
|
const esHost = $(this).data("es-host") === true || $(this).data("es-host") === "true";
|
||||||
|
const titulo = $("#modalAbandonarSalaLabel");
|
||||||
|
const mensaje = $("#modalAbandonarSalaMensaje");
|
||||||
|
const botonConfirmar = $("#btnConfirmarAbandonar");
|
||||||
|
|
||||||
|
if (esHost) {
|
||||||
|
titulo.text("¿Abandonar la sala?");
|
||||||
|
mensaje.text(
|
||||||
|
"Si abandonas la sala como anfitrión, la partida terminará para todos los jugadores.",
|
||||||
|
);
|
||||||
|
botonConfirmar.text("Sí, abandonar");
|
||||||
|
} else {
|
||||||
|
titulo.text("¿Abandonar la sala?");
|
||||||
|
mensaje.text(
|
||||||
|
"Si sales de la sala, perderás tu lugar en el equipo.",
|
||||||
|
);
|
||||||
|
botonConfirmar.text("Sí, salir");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
const modal = new bootstrap.Modal(
|
||||||
// CREAR SALA
|
document.getElementById("modalAbandonarSala"),
|
||||||
// ======================================================
|
);
|
||||||
|
|
||||||
|
modal.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
||||||
|
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||||
|
const modalEl = document.getElementById("modalAbandonarSala");
|
||||||
|
const modalInstance = bootstrap.Modal.getInstance(modalEl);
|
||||||
|
|
||||||
|
const btnConfirmar = $(this);
|
||||||
|
btnConfirmar.prop("disabled", true).text("Saliendo...");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/ControladorEquipoxUsuario.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
data: { orden: "salirDeSala" },
|
||||||
|
success: function (respuesta) {
|
||||||
|
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||||
|
|
||||||
|
if (modalInstance) {
|
||||||
|
modalInstance.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (respuesta.error) {
|
||||||
|
alert(respuesta.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restablecemos la interfaz a la lista completa de salas
|
||||||
|
usuarioYaEstaEnEquipo = false;
|
||||||
|
$("#contenedorCrearSala").show();
|
||||||
|
cargarSalas();
|
||||||
|
},
|
||||||
|
error: function (xhr, status, 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");
|
||||||
|
if (modalInstance) {
|
||||||
|
modalInstance.hide();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// 8. Evento: Crear Sala
|
||||||
$("#btnCrearSala").on("click", function () {
|
$("#btnCrearSala").on("click", function () {
|
||||||
const nombreSala = $("#nombreSala").val().trim();
|
const nombreSala = $("#nombreSala").val().trim();
|
||||||
|
|
||||||
const nombreEquipo1 = $("#nombreEquipo1").val().trim();
|
const nombreEquipo1 = $("#nombreEquipo1").val().trim();
|
||||||
|
|
||||||
const nombreEquipo2 = $("#nombreEquipo2").val().trim();
|
const nombreEquipo2 = $("#nombreEquipo2").val().trim();
|
||||||
|
|
||||||
let valido = true;
|
let valido = true;
|
||||||
|
|
||||||
$(".mensaje-error-sala").remove();
|
$(".mensaje-error-sala").remove();
|
||||||
|
|
||||||
$(".input-kahoot").removeClass("is-invalid");
|
$(".input-kahoot").removeClass("is-invalid");
|
||||||
|
|
||||||
if (nombreSala === "") {
|
if (nombreSala === "" || nombreSala.length < 3) {
|
||||||
mostrarError("#nombreSala", "El nombre de la sala es obligatorio.");
|
|
||||||
|
|
||||||
valido = false;
|
|
||||||
} 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 === "" || nombreEquipo1.length < 2) {
|
||||||
mostrarError("#nombreEquipo1", "El nombre del equipo 1 es obligatorio.");
|
|
||||||
|
|
||||||
valido = false;
|
|
||||||
} 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 === "" || nombreEquipo2.length < 2) {
|
||||||
mostrarError("#nombreEquipo2", "El nombre del equipo 2 es obligatorio.");
|
|
||||||
|
|
||||||
valido = false;
|
|
||||||
} 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,22 +376,16 @@ $("#btnCrearSala").on("click", function () {
|
|||||||
"#nombreEquipo2",
|
"#nombreEquipo2",
|
||||||
"Los dos equipos deben tener nombres diferentes.",
|
"Los dos equipos deben tener nombres diferentes.",
|
||||||
);
|
);
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valido) {
|
if (!valido) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deshabilitamos el botón mientras se crea la sala
|
|
||||||
const boton = $("#btnCrearSala");
|
const boton = $("#btnCrearSala");
|
||||||
|
boton.prop("disabled", true).text("Creando sala...");
|
||||||
boton.prop("disabled", true);
|
|
||||||
boton.text("Creando sala...");
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php", // <-- cambia esto por la ruta de tu controlador
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: {
|
data: {
|
||||||
@@ -429,16 +394,10 @@ $("#btnCrearSala").on("click", function () {
|
|||||||
nombreEquipo1: nombreEquipo1,
|
nombreEquipo1: nombreEquipo1,
|
||||||
nombreEquipo2: nombreEquipo2,
|
nombreEquipo2: nombreEquipo2,
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
console.log("Respuesta del servidor:", respuesta);
|
|
||||||
|
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
|
boton.prop("disabled", false).text("Crear sala");
|
||||||
boton.prop("disabled", false);
|
|
||||||
boton.text("Crear sala");
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,43 +406,30 @@ $("#btnCrearSala").on("click", function () {
|
|||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error("Error al crear la sala:", error);
|
console.error("Error al crear la sala:", error);
|
||||||
console.error("Respuesta:", xhr.responseText);
|
|
||||||
|
|
||||||
alert("No se ha podido crear la sala.");
|
alert("No se ha podido crear la sala.");
|
||||||
|
boton.prop("disabled", false).text("Crear sala");
|
||||||
boton.prop("disabled", false);
|
|
||||||
boton.text("Crear sala");
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ======================================================
|
// Auxiliares
|
||||||
// MOSTRAR ERROR
|
function escapeHTML(texto) {
|
||||||
// ======================================================
|
return $("<div>")
|
||||||
|
.text(texto ?? "")
|
||||||
|
.html();
|
||||||
|
}
|
||||||
|
|
||||||
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">${mensaje}</div>`,
|
||||||
<div class="mensaje-error-sala text-danger mt-1 small">
|
);
|
||||||
|
|
||||||
${mensaje}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================================================
|
$(document).on("input", ".input-kahoot", function () {
|
||||||
// QUITAR ERROR AL ESCRIBIR
|
|
||||||
// ======================================================
|
|
||||||
|
|
||||||
$(".input-kahoot").on("input", function () {
|
|
||||||
$(this).removeClass("is-invalid");
|
$(this).removeClass("is-invalid");
|
||||||
|
|
||||||
$(this).next(".mensaje-error-sala").remove();
|
$(this).next(".mensaje-error-sala").remove();
|
||||||
});
|
});
|
||||||
|
|||||||
+185
-101
@@ -1,133 +1,217 @@
|
|||||||
// Registro
|
let idUsuarioSesion = null;
|
||||||
$("#botonAceptarRegistro").click(function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
console.log("hola");
|
|
||||||
let nombreUsuario = $("#regNombre").val().trim();
|
|
||||||
let email = $("#regEmail").val().trim();
|
|
||||||
let contrasena = $("#regPassword").val();
|
|
||||||
let contrasenaConfirmacion = $("#regPasswordConfirm").val();
|
|
||||||
|
|
||||||
// Limpiamos errores anteriores
|
$(document).ready(function () {
|
||||||
$("#regNombre").removeClass("is-invalid");
|
// Comprobar la sesión activa al cargar la página
|
||||||
$("#regEmail").removeClass("is-invalid");
|
comprobarEstadoSesion();
|
||||||
$("#regPassword").removeClass("is-invalid");
|
|
||||||
$("#regPasswordConfirm").removeClass("is-invalid");
|
|
||||||
$("#errorRegistro").text("");
|
|
||||||
|
|
||||||
// Comprobamos que las contraseñas coincidan
|
// Evento Click: Login
|
||||||
if (contrasena !== contrasenaConfirmacion) {
|
$('#botonAceptarLogin').on('click', function () {
|
||||||
$("#regPassword").addClass("is-invalid");
|
ejecutarLogin();
|
||||||
$("#regPasswordConfirm").addClass("is-invalid");
|
});
|
||||||
|
|
||||||
$("#errorRegistro").text("Las contraseñas no coinciden.");
|
// Permitir Submit con tecla Enter en el formulario de Login
|
||||||
|
$('#formLogin').on('submit', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
ejecutarLogin();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Evento Click: Registro
|
||||||
|
$('#botonAceptarRegistro').on('click', function () {
|
||||||
|
ejecutarRegistro();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Permitir Submit con tecla Enter en el formulario de Registro
|
||||||
|
$('#formRegistro').on('submit', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
ejecutarRegistro();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comprueba con el servidor si existe una sesión PHP
|
||||||
|
*/
|
||||||
|
function comprobarEstadoSesion() {
|
||||||
|
$.ajax({
|
||||||
|
url: 'controladores/controladorUsuario.php',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { orden: 'comprobarSesion' },
|
||||||
|
success: function (respuesta) {
|
||||||
|
if (respuesta.activa) {
|
||||||
|
idUsuarioSesion = respuesta.usuario.idUsuario;
|
||||||
|
renderizarCabeceraConSesion(respuesta.usuario);
|
||||||
|
$('#colBotonJugar').removeClass('d-none');
|
||||||
|
} else {
|
||||||
|
renderizarCabeceraSinSesion();
|
||||||
|
$('#colBotonJugar').addClass('d-none');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
renderizarCabeceraSinSesion();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Petición AJAX para iniciar sesión
|
||||||
|
*/
|
||||||
|
function ejecutarLogin() {
|
||||||
|
let email = $('#loginEmail').val().trim();
|
||||||
|
let contrasena = $('#loginPassword').val().trim();
|
||||||
|
$('#errorLogin').text('');
|
||||||
|
|
||||||
|
if (email === '' || contrasena === '') {
|
||||||
|
$('#errorLogin').text('Por favor, rellena todos los campos.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "POST",
|
url: 'controladores/controladorUsuario.php',
|
||||||
url: "controladores/controladorUsuario.php",
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
data: {
|
data: {
|
||||||
nombreUsuario: nombreUsuario,
|
orden: 'comprobarUsuario',
|
||||||
email: email,
|
email: email,
|
||||||
contrasena: contrasena,
|
contrasena: contrasena
|
||||||
orden: "registrarUsuario",
|
|
||||||
},
|
},
|
||||||
}).done(function (respuesta) {
|
success: function (respuesta) {
|
||||||
//console.log(respuesta);
|
|
||||||
respuesta = JSON.parse(respuesta);
|
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
$("#errorRegistro").text(respuesta.error);
|
$('#errorLogin').text(respuesta.error);
|
||||||
|
} else if (respuesta.exito) {
|
||||||
|
$('#modalLogin').modal('hide');
|
||||||
|
$('#formLogin')[0].reset();
|
||||||
|
|
||||||
// Marcamos los campos si hay error
|
// Cargar datos de la sesión actualizados
|
||||||
$("#regNombre").addClass("is-invalid");
|
comprobarEstadoSesion();
|
||||||
$("#regEmail").addClass("is-invalid");
|
}
|
||||||
} else {
|
},
|
||||||
// Registro correcto
|
error: function () {
|
||||||
$("#errorRegistro")
|
$('#errorLogin').text('Error al conectar con el servidor.');
|
||||||
.removeClass("text-danger")
|
|
||||||
.addClass("text-success")
|
|
||||||
.text(respuesta.exito);
|
|
||||||
|
|
||||||
// Limpiamos formulario
|
|
||||||
$("#formRegistro")[0].reset();
|
|
||||||
|
|
||||||
// Cerramos modal después de un segundo
|
|
||||||
setTimeout(function () {
|
|
||||||
location.reload();
|
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
}); // Fin función ajax
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Login
|
|
||||||
$("#botonAceptarLogin").click(function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
let email = $("#loginEmail").val().trim();
|
|
||||||
let contrasena = $("#loginPassword").val();
|
|
||||||
|
|
||||||
// Limpiamos errores anteriores
|
|
||||||
$("#loginEmail").removeClass("is-invalid");
|
|
||||||
$("#loginPassword").removeClass("is-invalid");
|
|
||||||
$("#errorLogin").text("");
|
|
||||||
|
|
||||||
// Comprobación básica
|
|
||||||
if (email === "" || contrasena === "") {
|
|
||||||
$("#errorLogin").text("Todos los campos son obligatorios.");
|
|
||||||
|
|
||||||
if (email === "") {
|
|
||||||
$("#loginEmail").addClass("is-invalid");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contrasena === "") {
|
/**
|
||||||
$("#loginPassword").addClass("is-invalid");
|
* Petición AJAX para registrar un usuario
|
||||||
|
*/
|
||||||
|
function ejecutarRegistro() {
|
||||||
|
let nombre = $('#regNombre').val().trim();
|
||||||
|
let email = $('#regEmail').val().trim();
|
||||||
|
let pass = $('#regPassword').val().trim();
|
||||||
|
let passConfirm = $('#regPasswordConfirm').val().trim();
|
||||||
|
|
||||||
|
$('#errorRegistro').text('');
|
||||||
|
|
||||||
|
if (nombre === '' || email === '' || pass === '') {
|
||||||
|
$('#errorRegistro').text('Todos los campos son obligatorios.');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pass !== passConfirm) {
|
||||||
|
$('#errorRegistro').text('Las contraseñas no coinciden.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "POST",
|
url: 'controladores/controladorUsuario.php',
|
||||||
url: "controladores/controladorUsuario.php",
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
data: {
|
data: {
|
||||||
|
orden: 'registrarUsuario',
|
||||||
|
nombreUsuario: nombre,
|
||||||
email: email,
|
email: email,
|
||||||
contrasena: contrasena,
|
contrasena: pass
|
||||||
orden: "comprobarUsuario",
|
|
||||||
},
|
},
|
||||||
}).done(function (respuesta) {
|
success: function (respuesta) {
|
||||||
//console.log(respuesta);
|
|
||||||
respuesta = JSON.parse(respuesta);
|
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
$("#loginEmail").addClass("is-invalid");
|
$('#errorRegistro').text(respuesta.error);
|
||||||
$("#loginPassword").addClass("is-invalid");
|
|
||||||
|
|
||||||
$("#errorLogin").text(respuesta.error);
|
|
||||||
} else {
|
} else {
|
||||||
location.reload();
|
$('#modalRegistro').modal('hide');
|
||||||
|
$('#formRegistro')[0].reset();
|
||||||
|
|
||||||
|
// Autologin tras registrarse
|
||||||
|
$('#loginEmail').val(email);
|
||||||
|
$('#loginPassword').val(pass);
|
||||||
|
ejecutarLogin();
|
||||||
}
|
}
|
||||||
}); // Fin función ajax
|
|
||||||
});
|
|
||||||
|
|
||||||
// Cerrar sesión
|
|
||||||
$("#botonCerrarSesion").click(function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
method: "POST",
|
|
||||||
url: "controladores/controladorUsuario.php",
|
|
||||||
data: {
|
|
||||||
orden: "cerrarSesion",
|
|
||||||
},
|
},
|
||||||
}).done(function (respuesta) {
|
error: function () {
|
||||||
//console.log(respuesta);
|
$('#errorRegistro').text('Error al procesar el registro.');
|
||||||
respuesta = JSON.parse(respuesta);
|
}
|
||||||
if (respuesta.error) {
|
});
|
||||||
console.log(respuesta.error);
|
}
|
||||||
} else {
|
|
||||||
// Sesión cerrada correctamente
|
/**
|
||||||
|
* Petición AJAX para cerrar la sesión
|
||||||
|
*/
|
||||||
|
function cerrarSesion() {
|
||||||
|
$.ajax({
|
||||||
|
url: 'controladores/controladorUsuario.php',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { orden: 'cerrarSesion' },
|
||||||
|
success: function () {
|
||||||
|
renderizarCabeceraSinSesion();
|
||||||
|
$('#colBotonJugar').addClass('d-none');
|
||||||
|
|
||||||
|
if (window.location.pathname.includes('perfil.php') || window.location.pathname.includes('buscadorSala.php')) {
|
||||||
window.location.href = 'index.php';
|
window.location.href = 'index.php';
|
||||||
|
|
||||||
}
|
}
|
||||||
}); // Fin función ajax
|
}
|
||||||
}); // Fin función click
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renderiza la cabecera cuando HAY sesión iniciada
|
||||||
|
*/
|
||||||
|
function renderizarCabeceraConSesion(usuario) {
|
||||||
|
//Mete el avatar en cabecera
|
||||||
|
let avatarImg = (usuario.avatar && usuario.avatar !== '')
|
||||||
|
? usuario.avatar
|
||||||
|
: 'img/avatars/defaultProfile.jpeg';
|
||||||
|
|
||||||
|
// Refrescar avatar si se cambia
|
||||||
|
let avatarConCacheBuster = avatarImg + '?v=' + new Date().getTime();
|
||||||
|
|
||||||
|
let html = `
|
||||||
|
<div class="dropdown">
|
||||||
|
<button class="btn btn-outline-light dropdown-toggle d-flex align-items-center gap-2 rounded-pill px-3 py-1 fw-bold" type="button" id="userMenu" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
<img src="${avatarConCacheBuster}" alt="Avatar" class="rounded-circle border" style="width: 32px; height: 32px; object-fit: cover;">
|
||||||
|
<span>${escapeHtml(usuario.nombreUsuario)}</span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-end shadow border-0 mt-2" aria-labelledby="userMenu">
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item py-2 fw-semibold" href="perfil.php">
|
||||||
|
<i class="fa-solid fa-user me-2 text-primary"></i>Mi Perfil
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li><hr class="dropdown-divider"></li>
|
||||||
|
<li>
|
||||||
|
<button class="dropdown-item py-2 fw-semibold text-danger" onclick="cerrarSesion()">
|
||||||
|
<i class="fa-solid fa-right-from-bracket me-2"></i>Cerrar Sesión
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
$('#contenedorUsuarioCabecera').html(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renderiza los botones en la cabecera cuando NO hay sesión (Iniciar sesión azul)
|
||||||
|
*/
|
||||||
|
function renderizarCabeceraSinSesion() {
|
||||||
|
let html = `
|
||||||
|
<button class="btn btn-primary rounded-pill px-4 fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
||||||
|
<i class="fa-solid fa-right-to-bracket me-1"></i> Iniciar sesión
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-success rounded-pill px-4 fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#modalRegistro">
|
||||||
|
<i class="fa-solid fa-user-plus me-1"></i> Registrarse
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
$('#contenedorUsuarioCabecera').html(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(texto) {
|
||||||
|
return $('<div>').text(texto).html();
|
||||||
|
}
|
||||||
+20
-27
@@ -26,6 +26,10 @@ $.ajax({
|
|||||||
function cambiarNombre() {
|
function cambiarNombre() {
|
||||||
let nuevoNombre = $("#nuevoNombre").val().trim();
|
let nuevoNombre = $("#nuevoNombre").val().trim();
|
||||||
|
|
||||||
|
if (nuevoNombre === "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "controladores/controladorUsuario.php",
|
url: "controladores/controladorUsuario.php",
|
||||||
@@ -42,8 +46,13 @@ function cambiarNombre() {
|
|||||||
// Actualizamos el nombre mostrado en la página
|
// Actualizamos el nombre mostrado en la página
|
||||||
$("#nombre").text(respuesta.nombreUsuario);
|
$("#nombre").text(respuesta.nombreUsuario);
|
||||||
|
|
||||||
// Limpiamos el input
|
|
||||||
$("#nuevoNombre").val("");
|
$("#nuevoNombre").val("");
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof comprobarEstadoSesion === "function") {
|
||||||
|
comprobarEstadoSesion();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -74,14 +83,11 @@ $("#inputFoto").change(function () {
|
|||||||
// Comprobamos que sea una imagen
|
// Comprobamos que sea una imagen
|
||||||
if (!archivo.type.startsWith("image/")) {
|
if (!archivo.type.startsWith("image/")) {
|
||||||
alert("El archivo seleccionado no es una imagen.");
|
alert("El archivo seleccionado no es una imagen.");
|
||||||
|
|
||||||
$("#inputFoto").val("");
|
$("#inputFoto").val("");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let datos = new FormData();
|
let datos = new FormData();
|
||||||
|
|
||||||
datos.append("avatar", archivo);
|
datos.append("avatar", archivo);
|
||||||
datos.append("orden", "cambiarAvatar");
|
datos.append("orden", "cambiarAvatar");
|
||||||
|
|
||||||
@@ -97,18 +103,23 @@ $("#inputFoto").change(function () {
|
|||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
} else {
|
} else {
|
||||||
// Actualizamos la imagen sin recargar la página
|
// Actualizamos la imagen en la página de perfil sin recargar
|
||||||
$("#fotoPerfil").attr(
|
$("#fotoPerfil").attr(
|
||||||
"src",
|
"src",
|
||||||
respuesta.avatar + "?t=" + new Date().getTime(),
|
respuesta.avatar + "?t=" + new Date().getTime()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Actualizamos también el avatar superior en la cabecera
|
||||||
|
if (typeof comprobarEstadoSesion === "function") {
|
||||||
|
comprobarEstadoSesion();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// =========================
|
// =========================
|
||||||
// RECOGER CATEGORIAS
|
// RECOGER CATEGORIAS
|
||||||
// ====
|
// =========================
|
||||||
|
|
||||||
$("#modalCrearPregunta").on("show.bs.modal", function () {
|
$("#modalCrearPregunta").on("show.bs.modal", function () {
|
||||||
const selectCategoria = $("#idCategoria");
|
const selectCategoria = $("#idCategoria");
|
||||||
@@ -141,16 +152,14 @@ $("#modalCrearPregunta").on("show.bs.modal", function () {
|
|||||||
$("<option>", {
|
$("<option>", {
|
||||||
value: categoria.idCategoria,
|
value: categoria.idCategoria,
|
||||||
text: categoria.nombreCategoria,
|
text: categoria.nombreCategoria,
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error("Error al cargar las categorías:", error);
|
console.error("Error al cargar las categorías:", error);
|
||||||
|
|
||||||
console.error("Respuesta del servidor:", xhr.responseText);
|
console.error("Respuesta del servidor:", xhr.responseText);
|
||||||
|
|
||||||
alert("No se han podido cargar las categorías.");
|
alert("No se han podido cargar las categorías.");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -158,7 +167,7 @@ $("#modalCrearPregunta").on("show.bs.modal", function () {
|
|||||||
|
|
||||||
// =========================
|
// =========================
|
||||||
// CREAR PREGUNTA
|
// CREAR PREGUNTA
|
||||||
// ====
|
// =========================
|
||||||
|
|
||||||
$("#formCrearPregunta").on("submit", function (e) {
|
$("#formCrearPregunta").on("submit", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -188,24 +197,15 @@ $("#formCrearPregunta").on("submit", function (e) {
|
|||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPregunta.php",
|
url: "controladores/controladorPregunta.php",
|
||||||
|
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "crearPregunta",
|
orden: "crearPregunta",
|
||||||
|
|
||||||
idCategoria: $("#idCategoria").val(),
|
idCategoria: $("#idCategoria").val(),
|
||||||
|
|
||||||
nombrePregunta: pregunta,
|
nombrePregunta: pregunta,
|
||||||
|
|
||||||
respuestaCorrecta: respuestaCorrecta,
|
respuestaCorrecta: respuestaCorrecta,
|
||||||
|
|
||||||
respuestaIncorrecta1: respuestaIncorrecta1,
|
respuestaIncorrecta1: respuestaIncorrecta1,
|
||||||
|
|
||||||
respuestaIncorrecta2: respuestaIncorrecta2,
|
respuestaIncorrecta2: respuestaIncorrecta2,
|
||||||
|
|
||||||
respuestaIncorrecta3: respuestaIncorrecta3,
|
respuestaIncorrecta3: respuestaIncorrecta3,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -214,10 +214,8 @@ $("#formCrearPregunta").on("submit", function (e) {
|
|||||||
|
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
|
|
||||||
boton.prop("disabled", false);
|
boton.prop("disabled", false);
|
||||||
boton.text("Crear pregunta");
|
boton.text("Crear pregunta");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,17 +231,12 @@ $("#formCrearPregunta").on("submit", function (e) {
|
|||||||
// Volvemos a activar el botón
|
// Volvemos a activar el botón
|
||||||
boton.prop("disabled", false);
|
boton.prop("disabled", false);
|
||||||
boton.text("Crear pregunta");
|
boton.text("Crear pregunta");
|
||||||
|
|
||||||
// Si tienes que actualizar la lista de preguntas:
|
|
||||||
// cargarPreguntas();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error("Error al crear la pregunta:", error);
|
console.error("Error al crear la pregunta:", error);
|
||||||
|
|
||||||
console.error("Respuesta del servidor:", xhr.responseText);
|
console.error("Respuesta del servidor:", xhr.responseText);
|
||||||
|
|
||||||
alert("No se ha podido crear la pregunta.");
|
alert("No se ha podido crear la pregunta.");
|
||||||
|
|
||||||
boton.prop("disabled", false);
|
boton.prop("disabled", false);
|
||||||
|
|||||||
+48
-205
@@ -1,3 +1,17 @@
|
|||||||
|
<?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>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html lang="es">
|
||||||
|
|
||||||
@@ -9,151 +23,99 @@
|
|||||||
<title>Perfil</title>
|
<title>Perfil</title>
|
||||||
|
|
||||||
<!-- Bootstrap -->
|
<!-- Bootstrap -->
|
||||||
<link
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
|
|
||||||
rel="stylesheet">
|
|
||||||
|
|
||||||
<!-- Bootstrap Icons -->
|
<!-- Bootstrap Icons -->
|
||||||
<link
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
rel="stylesheet"
|
|
||||||
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
||||||
|
|
||||||
<!-- Google Font: Fredoka -->
|
<!-- Google Font: Fredoka -->
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||||
<link
|
|
||||||
href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap"
|
|
||||||
rel="stylesheet">
|
|
||||||
|
|
||||||
<!-- Tu CSS -->
|
<!-- Tu CSS -->
|
||||||
<link rel="stylesheet" href="css/index.css">
|
<link rel="stylesheet" href="css/index.css">
|
||||||
<link rel="stylesheet" href="css/perfil.css">
|
<link rel="stylesheet" href="css/perfil.css">
|
||||||
<script src="js/jquery-4.0.0.min.js"></script>
|
<script src="js/jquery-4.0.0.min.js"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<?php
|
<?php include_once 'cabecera.php'; ?>
|
||||||
include_once 'cabecera.php';
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="perfil-container">
|
<div class="perfil-container">
|
||||||
|
|
||||||
<div class="perfil-card">
|
<div class="perfil-card">
|
||||||
|
|
||||||
<!-- ========================= -->
|
|
||||||
<!-- CABECERA -->
|
<!-- CABECERA -->
|
||||||
<!-- ========================= -->
|
|
||||||
|
|
||||||
<div class="perfil-header">
|
<div class="perfil-header">
|
||||||
<i class="bi bi-person-circle"></i>
|
<i class="bi bi-person-circle"></i>
|
||||||
Mi perfil
|
Mi perfil
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="perfil-content">
|
<div class="perfil-content">
|
||||||
|
|
||||||
<div class="row align-items-center g-5">
|
<div class="row align-items-center g-5">
|
||||||
|
|
||||||
|
|
||||||
<!-- ========================= -->
|
|
||||||
<!-- PERFIL -->
|
<!-- PERFIL -->
|
||||||
<!-- ========================= -->
|
|
||||||
|
|
||||||
<div class="col-md-6 text-center">
|
<div class="col-md-6 text-center">
|
||||||
|
|
||||||
<!-- Nombre -->
|
<!-- Nombre -->
|
||||||
|
|
||||||
<h1 id="nombre" class="nombre">
|
<h1 id="nombre" class="nombre">
|
||||||
<?php echo $_SESSION['nombreUsuario'] ?>
|
<?= $nombreUsuario ?>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
|
||||||
<!-- ========================= -->
|
|
||||||
<!-- FOTO DE PERFIL -->
|
<!-- FOTO DE PERFIL -->
|
||||||
<!-- ========================= -->
|
|
||||||
|
|
||||||
<div class="foto-container">
|
<div class="foto-container">
|
||||||
|
|
||||||
<img
|
<img id="fotoPerfil"
|
||||||
id="fotoPerfil"
|
src="<?= $avatarUsuario ?>"
|
||||||
src="<?= htmlspecialchars($_SESSION['avatar'] ?? '') ?>"
|
|
||||||
alt="Foto de perfil"
|
alt="Foto de perfil"
|
||||||
class="avatar rounded-circle">
|
class="avatar rounded-circle">
|
||||||
|
|
||||||
|
|
||||||
<!-- Botón lápiz -->
|
<!-- Botón lápiz -->
|
||||||
|
<button type="button"
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn-foto"
|
class="btn-foto"
|
||||||
onclick="seleccionarFoto()"
|
onclick="seleccionarFoto()"
|
||||||
title="Cambiar foto de perfil"
|
title="Cambiar foto de perfil"
|
||||||
aria-label="Cambiar foto de perfil">
|
aria-label="Cambiar foto de perfil">
|
||||||
|
|
||||||
<i class="bi bi-pencil-fill"></i>
|
<i class="bi bi-pencil-fill"></i>
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
||||||
<!-- Input oculto -->
|
<!-- Input oculto -->
|
||||||
|
<input type="file"
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
id="inputFoto"
|
id="inputFoto"
|
||||||
accept="image/*"
|
accept="image/*"
|
||||||
hidden>
|
hidden>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- ========================= -->
|
|
||||||
<!-- CAMBIAR NOMBRE -->
|
<!-- CAMBIAR NOMBRE -->
|
||||||
<!-- ========================= -->
|
|
||||||
|
|
||||||
<div class="formulario-nombre">
|
<div class="formulario-nombre">
|
||||||
|
|
||||||
<label
|
<label for="nuevoNombre" class="form-label">
|
||||||
for="nuevoNombre"
|
|
||||||
class="form-label">
|
|
||||||
|
|
||||||
Cambia tu nombre
|
Cambia tu nombre
|
||||||
|
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<input type="text"
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="nuevoNombre"
|
id="nuevoNombre"
|
||||||
class="form-control mb-3"
|
class="form-control mb-3"
|
||||||
placeholder="Escribe tu nuevo nombre">
|
placeholder="Escribe tu nuevo nombre">
|
||||||
|
|
||||||
|
|
||||||
<div class="d-flex justify-content-center gap-2">
|
<div class="d-flex justify-content-center gap-2">
|
||||||
|
|
||||||
<button
|
<button type="button"
|
||||||
type="button"
|
|
||||||
class="btn-perfil-cambiar"
|
class="btn-perfil-cambiar"
|
||||||
onclick="cambiarNombre()">
|
onclick="cambiarNombre()">
|
||||||
|
|
||||||
<i class="bi bi-check-lg"></i>
|
<i class="bi bi-check-lg"></i>
|
||||||
Cambiar nombre
|
Cambiar nombre
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button type="button"
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn-perfil-borrar"
|
class="btn-perfil-borrar"
|
||||||
onclick="borrarNombre()">
|
onclick="borrarNombre()">
|
||||||
|
|
||||||
<i class="bi bi-x-lg"></i>
|
<i class="bi bi-x-lg"></i>
|
||||||
Borrar
|
Borrar
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -162,11 +124,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- ========================= -->
|
|
||||||
<!-- ESTADÍSTICAS -->
|
<!-- ESTADÍSTICAS -->
|
||||||
<!-- ========================= -->
|
|
||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
|
|
||||||
<div class="estadisticas">
|
<div class="estadisticas">
|
||||||
@@ -176,60 +134,33 @@
|
|||||||
Estadísticas
|
Estadísticas
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
|
|
||||||
<div class="estadistica estadistica-victorias">
|
<div class="estadistica estadistica-victorias">
|
||||||
|
|
||||||
<i class="bi bi-trophy-fill"></i>
|
<i class="bi bi-trophy-fill"></i>
|
||||||
Victorias:
|
Victorias:
|
||||||
|
<strong id="victorias">0</strong>
|
||||||
<strong id="victorias">
|
|
||||||
|
|
||||||
</strong>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="estadistica estadistica-derrotas">
|
<div class="estadistica estadistica-derrotas">
|
||||||
|
|
||||||
<i class="bi bi-x-circle-fill"></i>
|
<i class="bi bi-x-circle-fill"></i>
|
||||||
Derrotas:
|
Derrotas:
|
||||||
|
<strong id="derrotas">0</strong>
|
||||||
<strong id="derrotas">
|
|
||||||
|
|
||||||
</strong>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="estadistica estadistica-aciertos">
|
<div class="estadistica estadistica-aciertos">
|
||||||
|
|
||||||
<i class="bi bi-bullseye"></i>
|
<i class="bi bi-bullseye"></i>
|
||||||
Aciertos:
|
Aciertos:
|
||||||
|
<strong id="aciertos">0</strong>
|
||||||
<strong id="aciertos">
|
|
||||||
|
|
||||||
</strong>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- ========================= -->
|
|
||||||
<!-- CREAR PREGUNTA -->
|
<!-- CREAR PREGUNTA -->
|
||||||
<!-- ========================= -->
|
|
||||||
|
|
||||||
<div class="text-center mt-4">
|
<div class="text-center mt-4">
|
||||||
|
<button type="button"
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn btn-play-kahoot"
|
class="btn btn-play-kahoot"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
data-bs-target="#modalCrearPregunta">
|
data-bs-target="#modalCrearPregunta">
|
||||||
|
|
||||||
<i class="bi bi-plus-circle-fill"></i>
|
<i class="bi bi-plus-circle-fill"></i>
|
||||||
Crear pregunta
|
Crear pregunta
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -245,12 +176,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- ================================================= -->
|
|
||||||
<!-- MODAL CREAR PREGUNTA -->
|
<!-- MODAL CREAR PREGUNTA -->
|
||||||
<!-- ================================================= -->
|
<div class="modal fade"
|
||||||
|
|
||||||
<div
|
|
||||||
class="modal fade"
|
|
||||||
id="modalCrearPregunta"
|
id="modalCrearPregunta"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
aria-labelledby="modalCrearPreguntaLabel"
|
aria-labelledby="modalCrearPreguntaLabel"
|
||||||
@@ -260,186 +187,107 @@
|
|||||||
|
|
||||||
<div class="modal-content modal-kahoot">
|
<div class="modal-content modal-kahoot">
|
||||||
|
|
||||||
|
|
||||||
<!-- CABECERA DEL MODAL -->
|
|
||||||
|
|
||||||
<div class="modal-header modal-kahoot-header">
|
<div class="modal-header modal-kahoot-header">
|
||||||
|
<h5 class="modal-title" id="modalCrearPreguntaLabel">
|
||||||
<h5
|
|
||||||
class="modal-title"
|
|
||||||
id="modalCrearPreguntaLabel">
|
|
||||||
|
|
||||||
<i class="bi bi-question-circle-fill me-2"></i>
|
<i class="bi bi-question-circle-fill me-2"></i>
|
||||||
Crear pregunta
|
Crear pregunta
|
||||||
|
|
||||||
</h5>
|
</h5>
|
||||||
|
<button type="button"
|
||||||
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn-close btn-close-white"
|
class="btn-close btn-close-white"
|
||||||
data-bs-dismiss="modal"
|
data-bs-dismiss="modal"
|
||||||
aria-label="Cerrar">
|
aria-label="Cerrar">
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- CUERPO DEL MODAL -->
|
|
||||||
|
|
||||||
<div class="modal-body p-4">
|
<div class="modal-body p-4">
|
||||||
|
|
||||||
<form id="formCrearPregunta">
|
<form id="formCrearPregunta">
|
||||||
|
|
||||||
|
|
||||||
<!-- PREGUNTA -->
|
<!-- PREGUNTA -->
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
|
<label for="pregunta" class="form-label fw-semibold">
|
||||||
<label
|
|
||||||
for="pregunta"
|
|
||||||
class="form-label fw-semibold">
|
|
||||||
|
|
||||||
<i class="bi bi-question-lg me-1"></i>
|
<i class="bi bi-question-lg me-1"></i>
|
||||||
Pregunta
|
Pregunta
|
||||||
|
|
||||||
</label>
|
</label>
|
||||||
|
<textarea id="pregunta"
|
||||||
<textarea
|
|
||||||
id="pregunta"
|
|
||||||
name="pregunta"
|
name="pregunta"
|
||||||
class="form-control input-kahoot"
|
class="form-control input-kahoot"
|
||||||
rows="3"
|
rows="3"
|
||||||
placeholder="Escribe aquí la pregunta..."
|
placeholder="Escribe aquí la pregunta..."
|
||||||
required></textarea>
|
required></textarea>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- CATEGORÍA -->
|
<!-- CATEGORÍA -->
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
|
<label for="idCategoria" class="form-label fw-semibold">
|
||||||
<label
|
|
||||||
for="idCategoria"
|
|
||||||
class="form-label fw-semibold">
|
|
||||||
|
|
||||||
<i class="bi bi-folder-fill me-1"></i>
|
<i class="bi bi-folder-fill me-1"></i>
|
||||||
Categoría
|
Categoría
|
||||||
|
|
||||||
</label>
|
</label>
|
||||||
|
<select id="idCategoria"
|
||||||
<select
|
|
||||||
id="idCategoria"
|
|
||||||
name="idCategoria"
|
name="idCategoria"
|
||||||
class="form-select input-kahoot"
|
class="form-select input-kahoot"
|
||||||
required>
|
required>
|
||||||
|
<option value="">Selecciona una categoría</option>
|
||||||
<option value="">
|
|
||||||
Selecciona una categoría
|
|
||||||
</option>
|
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- RESPUESTA CORRECTA -->
|
<!-- RESPUESTA CORRECTA -->
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
<label for="respuestaCorrecta" class="form-label fw-semibold text-success">
|
||||||
<label
|
|
||||||
for="respuestaCorrecta"
|
|
||||||
class="form-label fw-semibold text-success">
|
|
||||||
|
|
||||||
<i class="bi bi-check-circle-fill me-1"></i>
|
<i class="bi bi-check-circle-fill me-1"></i>
|
||||||
Respuesta correcta
|
Respuesta correcta
|
||||||
|
|
||||||
</label>
|
</label>
|
||||||
|
<input type="text"
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="respuestaCorrecta"
|
id="respuestaCorrecta"
|
||||||
name="respuestaCorrecta"
|
name="respuestaCorrecta"
|
||||||
class="form-control input-kahoot"
|
class="form-control input-kahoot"
|
||||||
placeholder="Escribe la respuesta correcta..."
|
placeholder="Escribe la respuesta correcta..."
|
||||||
required>
|
required>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- RESPUESTAS INCORRECTAS -->
|
<!-- RESPUESTAS INCORRECTAS -->
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
<label class="form-label fw-semibold text-danger">
|
||||||
<label
|
|
||||||
class="form-label fw-semibold text-danger">
|
|
||||||
|
|
||||||
<i class="bi bi-x-circle-fill me-1"></i>
|
<i class="bi bi-x-circle-fill me-1"></i>
|
||||||
Respuestas incorrectas
|
Respuestas incorrectas
|
||||||
|
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<input type="text"
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="respuestaIncorrecta1"
|
id="respuestaIncorrecta1"
|
||||||
name="respuestaIncorrecta1"
|
name="respuestaIncorrecta1"
|
||||||
class="form-control input-kahoot mb-2"
|
class="form-control input-kahoot mb-2"
|
||||||
placeholder="Respuesta incorrecta 1"
|
placeholder="Respuesta incorrecta 1"
|
||||||
required>
|
required>
|
||||||
|
|
||||||
|
<input type="text"
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="respuestaIncorrecta2"
|
id="respuestaIncorrecta2"
|
||||||
name="respuestaIncorrecta2"
|
name="respuestaIncorrecta2"
|
||||||
class="form-control input-kahoot mb-2"
|
class="form-control input-kahoot mb-2"
|
||||||
placeholder="Respuesta incorrecta 2"
|
placeholder="Respuesta incorrecta 2"
|
||||||
required>
|
required>
|
||||||
|
|
||||||
|
<input type="text"
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="respuestaIncorrecta3"
|
id="respuestaIncorrecta3"
|
||||||
name="respuestaIncorrecta3"
|
name="respuestaIncorrecta3"
|
||||||
class="form-control input-kahoot"
|
class="form-control input-kahoot"
|
||||||
placeholder="Respuesta incorrecta 3"
|
placeholder="Respuesta incorrecta 3"
|
||||||
required>
|
required>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- PIE DEL MODAL -->
|
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn btn-secondary"
|
|
||||||
data-bs-dismiss="modal">
|
|
||||||
|
|
||||||
<i class="bi bi-x-lg me-1"></i>
|
<i class="bi bi-x-lg me-1"></i>
|
||||||
Cancelar
|
Cancelar
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button type="submit" form="formCrearPregunta" class="btn btn-kahoot-login" id="btnCrearPregunta">
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
form="formCrearPregunta"
|
|
||||||
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
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -449,14 +297,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Bootstrap JS -->
|
<!-- Bootstrap JS -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script
|
|
||||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js">
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Tu JavaScript -->
|
<!-- Tu JavaScript -->
|
||||||
|
|
||||||
<script src="js/perfil.js"></script>
|
<script src="js/perfil.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user