Compare commits
1 Commits
toast
..
archivo_env
| Author | SHA1 | Date | |
|---|---|---|---|
| 14e2fd48a1 |
+2
-2
@@ -82,8 +82,8 @@
|
|||||||
<div class="modal-content modal-kahoot text-center p-3">
|
<div class="modal-content modal-kahoot text-center p-3">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="mb-3 fs-1">⚠️</div>
|
<div class="mb-3 fs-1">⚠️</div>
|
||||||
<h4 class="modal-title mb-2 fw-bold" id="modalAbandonarSalaLabel">¿Abandonar la sala?</h4>
|
<h4 class="modal-title mb-2 fw-bold text-white" id="modalAbandonarSalaLabel">¿Abandonar la sala?</h4>
|
||||||
<p class="text-dark-50">Si sales de la sala, perderás tu lugar en el equipo.</p>
|
<p class="text-white-50">Si sales de la sala, perderás tu lugar en el equipo.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer justify-content-center border-0 gap-2">
|
<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">
|
<button type="button" class="btn btn-secondary px-4 py-2" data-bs-dismiss="modal">
|
||||||
|
|||||||
+8
-9
@@ -21,8 +21,9 @@
|
|||||||
<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>
|
||||||
|
|
||||||
<!-- Contenedor dinámico cargado por js/cabecera.js -->
|
<!-- Adtoy ti pagianan ti botones / dropdown a patulaon ti JS -->
|
||||||
<div class="d-flex align-items-center gap-3" id="contenedorUsuarioCabecera">
|
<div class="d-flex align-items-center gap-3" id="contenedorUsuarioCabecera">
|
||||||
|
<!-- Ikapit ti JS ti HTML dita -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -48,6 +49,11 @@
|
|||||||
<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>
|
||||||
@@ -87,14 +93,7 @@
|
|||||||
<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>
|
||||||
|
|||||||
@@ -55,11 +55,10 @@ switch ($_POST['orden']) {
|
|||||||
|
|
||||||
if ($resultado instanceof Usuario) {
|
if ($resultado instanceof Usuario) {
|
||||||
|
|
||||||
// === GUARDAR EN SESIÓN (incluido avatar)===
|
// === AÑADIR ESTAS LÍNEAS PARA GUARDAR EN SESIÓN ===
|
||||||
$_SESSION['idUsuario'] = $resultado->getIdUsuario();
|
$_SESSION['idUsuario'] = $resultado->getIdUsuario();
|
||||||
$_SESSION['nombreUsuario'] = $resultado->getNombreUsuario();
|
$_SESSION['nombreUsuario'] = $resultado->getNombreUsuario();
|
||||||
$_SESSION['email'] = $resultado->getEmail();
|
$_SESSION['email'] = $resultado->getEmail();
|
||||||
$_SESSION['avatar'] = $resultado->getAvatar();
|
|
||||||
// =================================================
|
// =================================================
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
@@ -84,7 +83,6 @@ 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();
|
||||||
@@ -94,6 +92,7 @@ switch ($_POST['orden']) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mostrarEstadisticas':
|
case 'mostrarEstadisticas':
|
||||||
|
|
||||||
$usuario = Usuario::buscarPorId($_SESSION['idUsuario']);
|
$usuario = Usuario::buscarPorId($_SESSION['idUsuario']);
|
||||||
@@ -238,17 +237,16 @@ switch ($_POST['orden']) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'comprobarSesion':
|
case 'comprobarSesion':
|
||||||
if (isset($_SESSION['idUsuario']) && !empty($_SESSION['idUsuario'])) {
|
if (isset($_SESSION['idUsuario']) && !empty($_SESSION['idUsuario'])) {
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'activa' => true,
|
'activa' => true,
|
||||||
'usuario' => [
|
'usuario' => [
|
||||||
'idUsuario' => $_SESSION['idUsuario'],
|
'idUsuario' => $_SESSION['idUsuario'],
|
||||||
'nombreUsuario' => $_SESSION['nombreUsuario'] ?? '',
|
'nombreUsuario' => $_SESSION['nombreUsuario'] ?? ''
|
||||||
'avatar' => $_SESSION['avatar'] ?? ''
|
]
|
||||||
]
|
]);
|
||||||
]);
|
} else {
|
||||||
} else {
|
echo json_encode(['activa' => false]);
|
||||||
echo json_encode(['activa' => false]);
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-10
@@ -68,8 +68,8 @@
|
|||||||
|
|
||||||
.btn-unirse {
|
.btn-unirse {
|
||||||
border: none;
|
border: none;
|
||||||
border-bottom: 3px solid #1f6f09;
|
border-bottom: 3px solid #0c4891;
|
||||||
background-color: #26890c;
|
background-color: var(--kahoot-blue);
|
||||||
color: white;
|
color: white;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -105,11 +105,3 @@
|
|||||||
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.
|
Before Width: | Height: | Size: 6.9 KiB |
+22
-25
@@ -1,29 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//CARGA DE ARCHIVOS .ENV CON PHPDOTENV
|
||||||
|
require('c:/laragon/vendor/autoload.php');//Se carga el módulo instalado con composer
|
||||||
|
$dotenv = Dotenv\Dotenv::createImmutable('c:/laragon/', 'triviagmatico.env');//leemos el archivo. El primer parámetro es la ruta para llegar y el segundo el nombre del archivo .env
|
||||||
|
$dotenv->load();
|
||||||
|
|
||||||
function conexionBD() {
|
function conexionBD (){
|
||||||
// Configuración para Laragon
|
try{
|
||||||
$servidor = "localhost";
|
$servidor = 'mysql:host='.$_ENV['bDatosServer'].';dbname='.$_ENV['bDatos'];
|
||||||
$bd = "triviagmatico"; // Asegúrate de que este sea el nombre de tu BD en HeidiSQL / phpMyAdmin
|
$user=$_ENV['bDatosUser'];
|
||||||
$usuario = "root";
|
$password=$_ENV['bDatosPass'];
|
||||||
$pass = ""; // Laragon deja la contraseña de root vacía por defecto
|
$options=array(
|
||||||
$puerto = "3306";
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
|
||||||
try {
|
);
|
||||||
$dsn = "mysql:host=$servidor;port=$puerto;dbname=$bd;charset=utf8mb4";
|
//Creamos la conexión PDO a la base de datos
|
||||||
|
$pdo = new PDO($servidor, $user, $password, $options);
|
||||||
$opciones = [
|
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
||||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
||||||
PDO::ATTR_EMULATE_PREPARES => false,
|
|
||||||
];
|
|
||||||
|
|
||||||
return new PDO($dsn, $usuario, $pass, $opciones);
|
|
||||||
|
|
||||||
} catch (PDOException $error) {
|
|
||||||
return [
|
|
||||||
'error' => 'No se pudo conectar a la base de datos.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
catch(PDOException $e){
|
||||||
|
//$resultado = ['error' => $e->getMessage()];
|
||||||
|
$resultado = ['error' => 'Error Temporal: No se puede conectar con la base de datos.'];
|
||||||
|
return $resultado;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pdo;
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
include 'cabecera.php';
|
||||||
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es-ES">
|
<html lang="es-ES">
|
||||||
|
|
||||||
@@ -5,17 +9,16 @@
|
|||||||
<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 (oculto por defecto, JS lo muestra si hay sesión activa) -->
|
<!-- Botón Jugar (oculto por defecto, JS lo muestra si hay sesión) -->
|
||||||
<div class="col-12 col-lg-5 col-xl-4 d-none" id="colBotonJugar">
|
<div class="col-12 col-lg-5 col-xl-4 d-none" id="colBotonJugar">
|
||||||
<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>
|
||||||
|
|||||||
+19
-50
@@ -123,24 +123,12 @@ 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 border border-2 d-flex align-items-center justify-content-between ${
|
<div class="jugador">
|
||||||
esHost ? "jugador-host" : ""
|
<span class="avatar">👤</span>
|
||||||
}">
|
${escapeHTML(jugador.nombreUsuario)}
|
||||||
<div>
|
</div>
|
||||||
<span class="avatar">${esHost ? "👑" : "👤"}</span>
|
`;
|
||||||
${escapeHTML(jugador.nombreUsuario)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
${
|
|
||||||
esHost
|
|
||||||
? `<span class="badge bg-warning text-dark ms-2">HOST</span>`
|
|
||||||
: ""
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
jugadoresHTML = `<div class="text-muted small">Sin jugadores</div>`;
|
jugadoresHTML = `<div class="text-muted small">Sin jugadores</div>`;
|
||||||
@@ -150,7 +138,7 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
let botonUnirseHTML = "";
|
let botonUnirseHTML = "";
|
||||||
if (!usuarioYaEstaEnEquipo) {
|
if (!usuarioYaEstaEnEquipo) {
|
||||||
botonUnirseHTML = `
|
botonUnirseHTML = `
|
||||||
<button type="button" class="btn-unirse w-100 btn-unirse-equipo mt-2"
|
<button type="button" class="btn btn-unirse w-100 btn-unirse-equipo mt-2"
|
||||||
data-id-partida="${partida.idPartida}"
|
data-id-partida="${partida.idPartida}"
|
||||||
data-id-equipo="${equipo.idEquipo}">
|
data-id-equipo="${equipo.idEquipo}">
|
||||||
Unirse
|
Unirse
|
||||||
@@ -169,42 +157,25 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
|
||||||
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
||||||
let accionesSalaHTML = "";
|
let accionesSalaHTML = "";
|
||||||
|
|
||||||
if (usuarioYaEstaEnEquipo) {
|
if (usuarioYaEstaEnEquipo) {
|
||||||
let botonIniciarHTML = "";
|
|
||||||
|
|
||||||
// Solo el host puede iniciar la partida
|
|
||||||
if (partida.idUsuario == idUsuarioSesion) {
|
|
||||||
botonIniciarHTML = `
|
|
||||||
<a href="juego.php?idPartida=${partida.idPartida}"
|
|
||||||
class="btn btn-success btn-lg px-4">
|
|
||||||
🎮 ¡Iniciar Partida!
|
|
||||||
</a>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
accionesSalaHTML = `
|
accionesSalaHTML = `
|
||||||
<div class="sala-acciones text-center mt-4 pt-3 border-top d-flex justify-content-center gap-3">
|
<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}">
|
||||||
<button type="button"
|
Abandonar sala
|
||||||
class="btn btn-outline-danger btn-abandonar-sala"
|
</button>
|
||||||
data-id-partida="${partida.idPartida}">
|
<a href="juego.php?idPartida=${partida.idPartida}" class="btn btn-success btn-lg px-4">
|
||||||
Abandonar sala
|
🎮 ¡Iniciar Partida!
|
||||||
</button>
|
</a>
|
||||||
|
</div>
|
||||||
${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 card p-3 shadow-sm mb-4">
|
||||||
<div class="sala-header h4 text-center mb-3 text-white">
|
<div class="sala-header h4 text-center mb-3">
|
||||||
${escapeHTML(partida.nombrePartida)}
|
${escapeHTML(partida.nombrePartida)}
|
||||||
</div>
|
</div>
|
||||||
<div class="sala-body">
|
<div class="sala-body">
|
||||||
@@ -263,15 +234,13 @@ let botonAbandonarReferencia = null;
|
|||||||
// A. Al hacer clic en el botón "Abandonar sala" de la tarjeta, abrimos el modal
|
// A. Al hacer clic en el botón "Abandonar sala" de la tarjeta, abrimos el modal
|
||||||
$(document).on("click", ".btn-abandonar-sala", function () {
|
$(document).on("click", ".btn-abandonar-sala", function () {
|
||||||
botonAbandonarReferencia = $(this);
|
botonAbandonarReferencia = $(this);
|
||||||
const modal = new bootstrap.Modal(
|
const modal = new bootstrap.Modal(document.getElementById('modalAbandonarSala'));
|
||||||
document.getElementById("modalAbandonarSala"),
|
|
||||||
);
|
|
||||||
modal.show();
|
modal.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
||||||
$(document).on("click", "#btnConfirmarAbandonar", 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);
|
const btnConfirmar = $(this);
|
||||||
@@ -306,7 +275,7 @@ $(document).on("click", "#btnConfirmarAbandonar", function () {
|
|||||||
if (modalInstance) {
|
if (modalInstance) {
|
||||||
modalInstance.hide();
|
modalInstance.hide();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// 8. Evento: Crear Sala
|
// 8. Evento: Crear Sala
|
||||||
|
|||||||
+262
-204
@@ -1,217 +1,275 @@
|
|||||||
let idUsuarioSesion = null;
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
// Comprobar la sesión activa al cargar la página
|
comprobarSesion();
|
||||||
comprobarEstadoSesion();
|
|
||||||
|
|
||||||
// Evento Click: Login
|
|
||||||
$('#botonAceptarLogin').on('click', function () {
|
|
||||||
ejecutarLogin();
|
|
||||||
});
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
// Función auxiliar para escapar texto HTML y evitar XSS
|
||||||
* Comprueba con el servidor si existe una sesión PHP
|
function escapeHTML(str) {
|
||||||
*/
|
return $("<div>").text(str ?? "").html();
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Comprobar estado de sesión al cargar la página
|
||||||
* Petición AJAX para iniciar sesión
|
function comprobarSesion() {
|
||||||
*/
|
$.ajax({
|
||||||
function ejecutarLogin() {
|
method: "POST",
|
||||||
let email = $('#loginEmail').val().trim();
|
url: "controladores/controladorUsuario.php",
|
||||||
let contrasena = $('#loginPassword').val().trim();
|
data: { orden: "comprobarSesion" },
|
||||||
$('#errorLogin').text('');
|
}).done(function (respuesta) {
|
||||||
|
try {
|
||||||
|
if (typeof respuesta === "string") {
|
||||||
|
respuesta = JSON.parse(respuesta);
|
||||||
|
}
|
||||||
|
|
||||||
if (email === '' || contrasena === '') {
|
const contenedor = $("#contenedorUsuarioCabecera");
|
||||||
$('#errorLogin').text('Por favor, rellena todos los campos.');
|
contenedor.empty();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$.ajax({
|
if (respuesta.activa && respuesta.usuario) {
|
||||||
url: 'controladores/controladorUsuario.php',
|
// Usuario autenticado: Mostrar Menú Dropdown
|
||||||
type: 'POST',
|
const htmlUsuario = `
|
||||||
dataType: 'json',
|
<div class="dropdown">
|
||||||
data: {
|
<button class="btn user-dropdown-btn dropdown-toggle d-flex align-items-center gap-2"
|
||||||
orden: 'comprobarUsuario',
|
type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
email: email,
|
<i class="fa-solid fa-circle-user fa-lg text-warning"></i>
|
||||||
contrasena: contrasena
|
<span>${escapeHTML(respuesta.usuario.nombreUsuario)}</span>
|
||||||
},
|
|
||||||
success: function (respuesta) {
|
|
||||||
if (respuesta.error) {
|
|
||||||
$('#errorLogin').text(respuesta.error);
|
|
||||||
} else if (respuesta.exito) {
|
|
||||||
$('#modalLogin').modal('hide');
|
|
||||||
$('#formLogin')[0].reset();
|
|
||||||
|
|
||||||
// Cargar datos de la sesión actualizados
|
|
||||||
comprobarEstadoSesion();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
$('#errorLogin').text('Error al conectar con el servidor.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: 'controladores/controladorUsuario.php',
|
|
||||||
type: 'POST',
|
|
||||||
dataType: 'json',
|
|
||||||
data: {
|
|
||||||
orden: 'registrarUsuario',
|
|
||||||
nombreUsuario: nombre,
|
|
||||||
email: email,
|
|
||||||
contrasena: pass
|
|
||||||
},
|
|
||||||
success: function (respuesta) {
|
|
||||||
if (respuesta.error) {
|
|
||||||
$('#errorRegistro').text(respuesta.error);
|
|
||||||
} else {
|
|
||||||
$('#modalRegistro').modal('hide');
|
|
||||||
$('#formRegistro')[0].reset();
|
|
||||||
|
|
||||||
// Autologin tras registrarse
|
|
||||||
$('#loginEmail').val(email);
|
|
||||||
$('#loginPassword').val(pass);
|
|
||||||
ejecutarLogin();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
$('#errorRegistro').text('Error al procesar el registro.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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>
|
</button>
|
||||||
<ul class="dropdown-menu dropdown-menu-end shadow border-0 mt-2" aria-labelledby="userMenu">
|
<ul class="dropdown-menu dropdown-menu-end user-dropdown-menu" aria-labelledby="userDropdown">
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item py-2 fw-semibold" href="perfil.php">
|
<a class="dropdown-item d-flex align-items-center gap-2" href="perfil.php">
|
||||||
<i class="fa-solid fa-user me-2 text-primary"></i>Mi Perfil
|
<i class="fa-solid fa-user text-primary"></i> Perfil
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li><hr class="dropdown-divider"></li>
|
<li><hr class="dropdown-divider"></li>
|
||||||
<li>
|
<li>
|
||||||
<button class="dropdown-item py-2 fw-semibold text-danger" onclick="cerrarSesion()">
|
<a class="dropdown-item logout-item d-flex align-items-center gap-2" href="#" id="botonCerrarSesion">
|
||||||
<i class="fa-solid fa-right-from-bracket me-2"></i>Cerrar Sesión
|
<i class="fa-solid fa-right-from-bracket"></i> Cerrar Sesión
|
||||||
</button>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
$('#contenedorUsuarioCabecera').html(html);
|
contenedor.html(htmlUsuario);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Si estamos en la página principal, mostramos el botón JUGAR
|
||||||
* Renderiza los botones en la cabecera cuando NO hay sesión (Iniciar sesión azul)
|
if ($("#colBotonJugar").length) {
|
||||||
*/
|
$("#colBotonJugar").removeClass("d-none");
|
||||||
function renderizarCabeceraSinSesion() {
|
$("#colRanking").removeClass("col-lg-8").addClass("col-lg-7 col-xl-8");
|
||||||
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
|
} else {
|
||||||
</button>
|
// No hay sesión: Mostrar botones de Login y Registro
|
||||||
<button class="btn btn-success rounded-pill px-4 fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#modalRegistro">
|
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
|
<i class="fa-solid fa-user-plus me-1"></i> Registrarse
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
$('#contenedorUsuarioCabecera').html(html);
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error al procesar la respuesta de la sesión:", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeHtml(texto) {
|
// Evento Registro
|
||||||
return $('<div>').text(texto).html();
|
$("#botonAceptarRegistro").click(function (event) {
|
||||||
}
|
event.preventDefault();
|
||||||
|
|
||||||
|
let nombreUsuario = $("#regNombre").val().trim();
|
||||||
|
let email = $("#regEmail").val().trim();
|
||||||
|
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("");
|
||||||
|
|
||||||
|
if (contrasena !== contrasenaConfirmacion) {
|
||||||
|
$("#regPassword").addClass("is-invalid");
|
||||||
|
$("#regPasswordConfirm").addClass("is-invalid");
|
||||||
|
$("#errorRegistro").text("Las contraseñas no coinciden.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: "controladores/controladorUsuario.php",
|
||||||
|
data: {
|
||||||
|
nombreUsuario: nombreUsuario,
|
||||||
|
email: email,
|
||||||
|
contrasena: contrasena,
|
||||||
|
orden: "registrarUsuario",
|
||||||
|
},
|
||||||
|
}).done(function (respuesta) {
|
||||||
|
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||||
|
|
||||||
|
if (respuesta.error) {
|
||||||
|
$("#errorRegistro").text(respuesta.error);
|
||||||
|
$("#regNombre").addClass("is-invalid");
|
||||||
|
$("#regEmail").addClass("is-invalid");
|
||||||
|
} else {
|
||||||
|
$("#errorRegistro")
|
||||||
|
.removeClass("text-danger")
|
||||||
|
.addClass("text-success")
|
||||||
|
.text(respuesta.exito);
|
||||||
|
|
||||||
|
$("#formRegistro")[0].reset();
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
location.reload();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Evento Login
|
||||||
|
$("#botonAceptarLogin").click(function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
let email = $("#loginEmail").val().trim();
|
||||||
|
let contrasena = $("#loginPassword").val();
|
||||||
|
|
||||||
|
$("#loginEmail").removeClass("is-invalid");
|
||||||
|
$("#loginPassword").removeClass("is-invalid");
|
||||||
|
$("#errorLogin").text("");
|
||||||
|
|
||||||
|
if (email === "" || contrasena === "") {
|
||||||
|
$("#errorLogin").text("Todos los campos son obligatorios.");
|
||||||
|
if (email === "") $("#loginEmail").addClass("is-invalid");
|
||||||
|
if (contrasena === "") $("#loginPassword").addClass("is-invalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: "controladores/controladorUsuario.php",
|
||||||
|
data: {
|
||||||
|
email: email,
|
||||||
|
contrasena: contrasena,
|
||||||
|
orden: "comprobarUsuario",
|
||||||
|
},
|
||||||
|
}).done(function (respuesta) {
|
||||||
|
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||||
|
|
||||||
|
if (respuesta.error) {
|
||||||
|
$("#loginEmail").addClass("is-invalid");
|
||||||
|
$("#loginPassword").addClass("is-invalid");
|
||||||
|
$("#errorLogin").text(respuesta.error);
|
||||||
|
} else {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Evento Cerrar sesión (usa delegación de eventos por crearse dinámicamente)
|
||||||
|
$(document).on("click", "#botonCerrarSesion", function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: "controladores/controladorUsuario.php",
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Registro
|
||||||
|
$("#botonAceptarRegistro").click(function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
let nombreUsuario = $("#regNombre").val().trim();
|
||||||
|
let email = $("#regEmail").val().trim();
|
||||||
|
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("");
|
||||||
|
|
||||||
|
if (contrasena !== contrasenaConfirmacion) {
|
||||||
|
$("#regPassword").addClass("is-invalid");
|
||||||
|
$("#regPasswordConfirm").addClass("is-invalid");
|
||||||
|
$("#errorRegistro").text("Las contraseñas no coinciden.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: "controladores/controladorUsuario.php",
|
||||||
|
data: {
|
||||||
|
nombreUsuario: nombreUsuario,
|
||||||
|
email: email,
|
||||||
|
contrasena: contrasena,
|
||||||
|
orden: "registrarUsuario",
|
||||||
|
},
|
||||||
|
}).done(function (respuesta) {
|
||||||
|
if (typeof respuesta === "string") respuesta = JSON.parse(respuesta);
|
||||||
|
|
||||||
|
if (respuesta.error) {
|
||||||
|
$("#errorRegistro").text(respuesta.error);
|
||||||
|
$("#regNombre").addClass("is-invalid");
|
||||||
|
$("#regEmail").addClass("is-invalid");
|
||||||
|
} else {
|
||||||
|
$("#errorRegistro")
|
||||||
|
.removeClass("text-danger")
|
||||||
|
.addClass("text-success")
|
||||||
|
.text(respuesta.exito);
|
||||||
|
|
||||||
|
$("#formRegistro")[0].reset();
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
location.reload();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Login
|
||||||
|
$("#botonAceptarLogin").click(function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
let email = $("#loginEmail").val().trim();
|
||||||
|
let contrasena = $("#loginPassword").val();
|
||||||
|
|
||||||
|
$("#loginEmail").removeClass("is-invalid");
|
||||||
|
$("#loginPassword").removeClass("is-invalid");
|
||||||
|
$("#errorLogin").text("");
|
||||||
|
|
||||||
|
if (email === "" || contrasena === "") {
|
||||||
|
$("#errorLogin").text("Todos los campos son obligatorios.");
|
||||||
|
if (email === "") $("#loginEmail").addClass("is-invalid");
|
||||||
|
if (contrasena === "") $("#loginPassword").addClass("is-invalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: "controladores/controladorUsuario.php",
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
+27
-30
@@ -26,10 +26,6 @@ $.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",
|
||||||
@@ -46,13 +42,8 @@ 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -83,11 +74,14 @@ $("#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");
|
||||||
|
|
||||||
@@ -103,23 +97,18 @@ $("#inputFoto").change(function () {
|
|||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
} else {
|
} else {
|
||||||
// Actualizamos la imagen en la página de perfil sin recargar
|
// Actualizamos la imagen sin recargar la página
|
||||||
$("#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");
|
||||||
@@ -152,14 +141,16 @@ $("#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.");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -167,7 +158,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();
|
||||||
@@ -197,15 +188,24 @@ $("#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,8 +214,10 @@ $("#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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,14 +233,17 @@ $("#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");
|
||||||
// Toast exito
|
|
||||||
mostrarToast()
|
// 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);
|
||||||
@@ -246,11 +251,3 @@ $("#formCrearPregunta").on("submit", function (e) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
function mostrarToast() {
|
|
||||||
const toastMensaje = document.getElementById("ToastCrearPregunta");
|
|
||||||
|
|
||||||
if (toastMensaje) {
|
|
||||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastMensaje);
|
|
||||||
toastBootstrap.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-11
@@ -174,17 +174,8 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- TOAST PREGUNTA CREADA -->
|
|
||||||
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
|
||||||
<div id="ToastCrearPregunta" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
|
||||||
<div class=" toast-header" style="background-color: #46178f;">
|
|
||||||
<h5 class="text-white me-auto bi bi-joystick me-2"> Pregunta Creada</h5>
|
|
||||||
</div>
|
|
||||||
<div class="fs-6 toast-body">
|
|
||||||
La pregunta ha sido creada correctamente
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- MODAL CREAR PREGUNTA -->
|
<!-- MODAL CREAR PREGUNTA -->
|
||||||
<div class="modal fade"
|
<div class="modal fade"
|
||||||
id="modalCrearPregunta"
|
id="modalCrearPregunta"
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
bDatosServer="localhost"
|
||||||
|
bDatos="triviagmatico"
|
||||||
|
bDatosUser="root"
|
||||||
|
bDatosPass=""
|
||||||
|
urlBase="http://triviagmatico.test"
|
||||||
|
dirBase="C:/laragon/www/triviagmatico"
|
||||||
Reference in New Issue
Block a user