Compare commits
10 Commits
22f38f924f
...
optimizar
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c679175c6 | |||
| b8581a611e | |||
| 6adcb9680c | |||
| 99a08b0a34 | |||
| 7661343572 | |||
| e97586b033 | |||
| 42cc1489e9 | |||
| a694f19667 | |||
| 3cc0dfb122 | |||
| 4efb831b7a |
+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 text-white" id="modalAbandonarSalaLabel">¿Abandonar la sala?</h4>
|
<h4 class="modal-title mb-2 fw-bold" id="modalAbandonarSalaLabel">¿Abandonar la sala?</h4>
|
||||||
<p class="text-white-50">Si sales de la sala, perderás tu lugar en el equipo.</p>
|
<p class="text-dark-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">
|
||||||
|
|||||||
+9
-8
@@ -21,9 +21,8 @@
|
|||||||
<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>
|
||||||
|
|
||||||
<!-- Adtoy ti pagianan ti botones / dropdown a patulaon ti JS -->
|
<!-- Contenedor dinámico cargado por js/cabecera.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>
|
||||||
@@ -49,11 +48,6 @@
|
|||||||
<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>
|
||||||
@@ -93,7 +87,14 @@
|
|||||||
<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>
|
||||||
|
|||||||
@@ -12,40 +12,6 @@ class Categoria{
|
|||||||
$this->nombreCategoria = $nombreCategoria;
|
$this->nombreCategoria = $nombreCategoria;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function crear(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
|
|
||||||
if(is_array($conexion)){
|
|
||||||
return $conexion;
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
$consulta = $conexion->prepare("INSERT INTO categoria (nombreCategoria) VALUES (:nombreCategoria)");
|
|
||||||
|
|
||||||
$consulta->bindParam(':nombreCategoria', $this->nombreCategoria);
|
|
||||||
|
|
||||||
$consulta->execute();
|
|
||||||
|
|
||||||
$respuesta = [
|
|
||||||
'exito' => 'Categoría creada correctamente',
|
|
||||||
'exito_tecnico' => $this->nombreCategoria
|
|
||||||
];
|
|
||||||
|
|
||||||
return $respuesta;
|
|
||||||
|
|
||||||
}catch(PDOException $error){
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'Ocurrió un error al guardar la categoría.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
|
|
||||||
$conexion = null;
|
|
||||||
return $respuesta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function listar(){
|
function listar(){
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
|
|
||||||
@@ -73,77 +39,6 @@ class Categoria{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function buscar(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
|
|
||||||
if(is_array($conexion)){
|
|
||||||
return $conexion;
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
$consulta = $conexion->prepare("SELECT * FROM categoria WHERE idCategoria = :idCategoria");
|
|
||||||
|
|
||||||
$consulta->bindParam(':idCategoria', $this->idCategoria);
|
|
||||||
|
|
||||||
$consulta->execute();
|
|
||||||
|
|
||||||
$resultado = $consulta->fetch(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
return $resultado;
|
|
||||||
|
|
||||||
}catch(PDOException $error){
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'Ocurrió un error al buscar la categoría.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
|
|
||||||
$conexion = null;
|
|
||||||
return $respuesta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function borrar(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
|
|
||||||
if(is_array($conexion)){
|
|
||||||
return $conexion;
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
$consulta = $conexion->prepare("DELETE FROM categoria WHERE idCategoria = :idCategoria");
|
|
||||||
|
|
||||||
$consulta->bindParam(':idCategoria', $this->idCategoria);
|
|
||||||
|
|
||||||
$consulta->execute();
|
|
||||||
|
|
||||||
if($consulta->rowCount() > 0){
|
|
||||||
$respuesta = [
|
|
||||||
'exito' => 'Se eliminó correctamente la categoría',
|
|
||||||
'exito_tecnico' => $this->idCategoria
|
|
||||||
];
|
|
||||||
}else{
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'No existe ninguna categoría con ese ID.',
|
|
||||||
'error_tecnico' => $this->idCategoria
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $respuesta;
|
|
||||||
|
|
||||||
}catch(PDOException $error){
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'Ocurrió un error al eliminar la categoría.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
|
|
||||||
$conexion = null;
|
|
||||||
return $respuesta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
|
|
||||||
@@ -466,4 +467,25 @@ class Partida
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function contar()
|
||||||
|
{
|
||||||
|
$conexion = conexionBD();
|
||||||
|
if (is_array($conexion)) {
|
||||||
|
return $conexion;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$sql="SELECT COUNT(*) AS total FROM partida";
|
||||||
|
$consulta = $conexion->prepare($sql);
|
||||||
|
$consulta->execute();
|
||||||
|
return (int) $consulta->fetchColumn();
|
||||||
|
} catch (PDOException $error) {
|
||||||
|
return [
|
||||||
|
"error" => "Ocurrió un error al obtener el listado.",
|
||||||
|
'error_tecnico' => $error->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-42
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
|
|
||||||
@@ -56,56 +57,23 @@ class Pregunta {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cargarRespuestas() {
|
|
||||||
if ($this->idPregunta === null) return;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static function getTodosIds()//devuelve solamente los id de todas las preguntas
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
|
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$sql = "SELECT idRespuesta, nombreRespuesta, correcta FROM respuesta WHERE idPregunta = :idPreg";
|
$consulta = $conexion->prepare("SELECT idPregunta FROM pregunta");
|
||||||
$stmt = $conexion->prepare($sql);
|
$consulta->execute();
|
||||||
$stmt->execute([':idPreg' => $this->idPregunta]);
|
return $consulta->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
$this->respuestas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
} catch (PDOException $error) {
|
} catch (PDOException $error) {
|
||||||
return [
|
return [
|
||||||
'error' => 'Ocurrió un error al cargar las respuestas.',
|
"error" => "Ocurrió un error al obtener el listado.",
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function obtenerPorCategoria(int $idCategoria, int $limite = 10) {
|
|
||||||
$conexion = conexionBD();
|
|
||||||
|
|
||||||
if (is_array($conexion)) {
|
|
||||||
return $conexion;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$sql = "SELECT * FROM pregunta WHERE idCategoria = :idCat ORDER BY RAND() LIMIT :limite";
|
|
||||||
$stmt = $conexion->prepare($sql);
|
|
||||||
|
|
||||||
$stmt->bindValue(':idCat', $idCategoria, PDO::PARAM_INT);
|
|
||||||
$stmt->bindValue(':limite', $limite, PDO::PARAM_INT);
|
|
||||||
$stmt->execute();
|
|
||||||
|
|
||||||
$preguntas = [];
|
|
||||||
while ($datos = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
||||||
$preg = new Pregunta((int)$datos['idCategoria'], $datos['nombrePregunta'], (int)$datos['idPregunta']);
|
|
||||||
$preg->cargarRespuestas();
|
|
||||||
$preguntas[] = $preg;
|
|
||||||
}
|
|
||||||
return $preguntas;
|
|
||||||
|
|
||||||
} catch (PDOException $error) {
|
|
||||||
return [
|
|
||||||
'error' => 'Ocurrió un error al obtener las preguntas aleatorias.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
'error_tecnico' => $error->getMessage()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,130 +40,6 @@ class Respuesta{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}//fin método insertar
|
}//fin método insertar
|
||||||
|
|
||||||
public function listar(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
if(is_array($conexion)){
|
|
||||||
return $conexion;
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
$consulta = $conexion->prepare("SELECT * FROM respuesta");
|
|
||||||
$consulta->execute();
|
|
||||||
return $consulta->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
}catch(PDOException $error){
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'Ocurrió un error al obtener el listado.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
$conexion = null;
|
|
||||||
return $respuesta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}//fin método listar
|
|
||||||
|
|
||||||
public function eliminar(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
if(is_array($conexion)){
|
|
||||||
return $conexion;
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
$consulta = $conexion->prepare("DELETE FROM respuesta WHERE idRespuesta=:idRespuesta");
|
|
||||||
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
|
|
||||||
$consulta->execute();
|
|
||||||
$respuesta = [
|
|
||||||
'exito' => 'La respuesta se eliminó correctamente.',
|
|
||||||
'exito_tecnico' => $this->idRespuesta
|
|
||||||
];
|
|
||||||
return $respuesta;
|
|
||||||
}catch(PDOException $error){
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'No se pudo eliminar la respuesta.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
$conexion = null;
|
|
||||||
return $respuesta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}//fin método eliminar
|
|
||||||
|
|
||||||
public function editar(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
if(is_array($conexion)){
|
|
||||||
return $conexion;
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
$consulta = $conexion->prepare("UPDATE respuesta SET idPregunta=:idPregunta, nombreRespuesta=:nombreRespuesta, correcta=:correcta WHERE idRespuesta=:idRespuesta");
|
|
||||||
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
|
|
||||||
$consulta->bindParam(':idPregunta', $this->idPregunta);
|
|
||||||
$consulta->bindParam(':nombreRespuesta', $this->nombreRespuesta);
|
|
||||||
$consulta->bindParam(':correcta', $this->correcta);
|
|
||||||
$consulta->execute();
|
|
||||||
$respuesta = [
|
|
||||||
'exito' => 'La respuesta se editó correctamente.',
|
|
||||||
'exito_tecnico' => $this->idRespuesta
|
|
||||||
];
|
|
||||||
return $respuesta;
|
|
||||||
}catch(PDOException $error){
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'Ocurrió un error al editar la respuesta.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
$conexion = null;
|
|
||||||
return $respuesta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}//fin método editar
|
|
||||||
|
|
||||||
public function buscar(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
if(is_array($conexion)){
|
|
||||||
return $conexion;
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
$consulta = $conexion->prepare("SELECT * FROM respuesta WHERE idRespuesta=:idRespuesta");
|
|
||||||
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
|
|
||||||
$consulta->execute();
|
|
||||||
return $consulta->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
}catch(PDOException $error){
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'Ocurrió un error al buscar la respuesta.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
$conexion = null;
|
|
||||||
return $respuesta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}//fin método buscar
|
|
||||||
|
|
||||||
public function listarPorPregunta(){//trae todas las respuestas posibles de una pregunta
|
|
||||||
$conexion = conexionBD();
|
|
||||||
if(is_array($conexion)){
|
|
||||||
return $conexion;
|
|
||||||
}else{
|
|
||||||
try{
|
|
||||||
$consulta = $conexion->prepare("SELECT * FROM respuesta WHERE idPregunta=:idPregunta");
|
|
||||||
$consulta->bindParam(':idPregunta', $this->idPregunta);
|
|
||||||
$consulta->execute();
|
|
||||||
$resultado = $consulta->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
if(!isset($resultado[0])){
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'La pregunta no tiene respuestas.'
|
|
||||||
];
|
|
||||||
return $respuesta;
|
|
||||||
}else{
|
|
||||||
return $resultado;
|
|
||||||
}
|
|
||||||
}catch(PDOException $error){
|
|
||||||
$respuesta = [
|
|
||||||
'error' => 'Ocurrió un error al obtener las respuestas de la pregunta.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
$conexion = null;
|
|
||||||
return $respuesta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}//fin método listarPorPregunta
|
|
||||||
|
|
||||||
}//fin clase
|
}//fin clase
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -6,22 +6,6 @@ require_once '../clases/ClaseCategoria.php';
|
|||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
|
|
||||||
case 'crearCategoria':
|
|
||||||
|
|
||||||
$nombreCategoria = trim($_POST['nombreCategoria'] ?? '');
|
|
||||||
|
|
||||||
if ($nombreCategoria == '') {
|
|
||||||
echo json_encode(['error' => 'El nombre de la categoría es obligatorio']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$categoria = new Categoria(null, $nombreCategoria);
|
|
||||||
$resultado = $categoria->crear();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case 'listarCategorias':
|
case 'listarCategorias':
|
||||||
|
|
||||||
$categoria = new Categoria();
|
$categoria = new Categoria();
|
||||||
@@ -29,27 +13,4 @@ switch ($_POST['orden']) {
|
|||||||
|
|
||||||
echo json_encode($resultado);
|
echo json_encode($resultado);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 'buscarCategoria':
|
|
||||||
|
|
||||||
$idCategoria = intval($_POST['idCategoria'] ?? 0);
|
|
||||||
|
|
||||||
$categoria = new Categoria($idCategoria);
|
|
||||||
$resultado = $categoria->buscar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case 'borrarCategoria':
|
|
||||||
|
|
||||||
$idCategoria = intval($_POST['idCategoria'] ?? 0);
|
|
||||||
|
|
||||||
$categoria = new Categoria($idCategoria);
|
|
||||||
$resultado = $categoria->borrar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
session_start();
|
|
||||||
|
|
||||||
require_once '../clases/ClaseEquipo.php';
|
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
|
||||||
|
|
||||||
case 'crearEquipo':
|
|
||||||
|
|
||||||
$nombreEquipo = trim($_POST['nombreEquipo'] ?? '');
|
|
||||||
|
|
||||||
if ($nombreEquipo == '') {
|
|
||||||
echo json_encode(['error' => 'El nombre del equipo es obligatorio']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$equipo = new Equipo(null, $nombreEquipo);
|
|
||||||
$resultado = $equipo->crear();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case 'listarEquipos':
|
|
||||||
|
|
||||||
$equipo = new Equipo();
|
|
||||||
$resultado = $equipo->listar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case 'buscarEquipo':
|
|
||||||
|
|
||||||
$idEquipo = intval($_POST['idEquipo'] ?? 0);
|
|
||||||
|
|
||||||
$equipo = new Equipo($idEquipo);
|
|
||||||
$resultado = $equipo->buscar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case 'borrarEquipo':
|
|
||||||
|
|
||||||
$idEquipo = intval($_POST['idEquipo'] ?? 0);
|
|
||||||
|
|
||||||
$equipo = new Equipo($idEquipo);
|
|
||||||
$resultado = $equipo->borrar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@ require_once '../clases/ClasePartida.php';
|
|||||||
require_once '../clases/ClaseEquipo.php';
|
require_once '../clases/ClaseEquipo.php';
|
||||||
require_once '../clases/ClaseEquipoxUsuario.php';
|
require_once '../clases/ClaseEquipoxUsuario.php';
|
||||||
require_once '../clases/ClaseEquipoxPartida.php';
|
require_once '../clases/ClaseEquipoxPartida.php';
|
||||||
|
require_once '../clases/ClasePregunta.php';
|
||||||
|
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
@@ -119,6 +120,7 @@ switch ($_POST['orden']) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$idPartida = (int)$resultadoPartida['exito_tecnico'];
|
$idPartida = (int)$resultadoPartida['exito_tecnico'];
|
||||||
|
$partida->idPartida = $idPartida;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -211,6 +213,42 @@ switch ($_POST['orden']) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ==========================================
|
||||||
|
* 5. ASIGNAMOS 10 PREGUNTAS ALEATORIAS A LA PARTIDA
|
||||||
|
* ==========================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Obtenemos todos los IDs de las preguntas
|
||||||
|
|
||||||
|
$listaPreguntas = Pregunta::getTodosIds();
|
||||||
|
|
||||||
|
$totalPreguntas = count($listaPreguntas);
|
||||||
|
|
||||||
|
// Guardamos las preguntas que ya hemos asignado
|
||||||
|
$preguntasAsignadas = [];
|
||||||
|
|
||||||
|
// Generamos 10 posiciones aleatorias sin repetir
|
||||||
|
while (count($preguntasAsignadas) < 10) {
|
||||||
|
|
||||||
|
// Generamos una posición aleatoria del array
|
||||||
|
$posicionAleatoria = rand(0, $totalPreguntas - 1);
|
||||||
|
|
||||||
|
// Obtenemos el ID real de la pregunta
|
||||||
|
$idPreguntaAleatoria = $listaPreguntas[$posicionAleatoria];
|
||||||
|
|
||||||
|
// Comprobamos que esa pregunta no haya sido asignada ya
|
||||||
|
if (!in_array($idPreguntaAleatoria, $preguntasAsignadas)) {
|
||||||
|
$preguntasAsignadas[] = $idPreguntaAleatoria;
|
||||||
|
|
||||||
|
// Asignamos el ID real de la pregunta a la partida
|
||||||
|
$partida->asignarPregunta($idPreguntaAleatoria);
|
||||||
|
}
|
||||||
|
}//fin shile
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ==========================================
|
* ==========================================
|
||||||
* TODO CORRECTO
|
* TODO CORRECTO
|
||||||
@@ -218,7 +256,7 @@ switch ($_POST['orden']) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'exito' => 'Sala creada correctamente.',
|
'exito' => 'Sala creada correctamente. Preguntas preparadas.',
|
||||||
'idPartida' => $resultadoPartida['exito_tecnico'],
|
'idPartida' => $resultadoPartida['exito_tecnico'],
|
||||||
'idEquipo1' => $equipo1->idEquipo,
|
'idEquipo1' => $equipo1->idEquipo,
|
||||||
'idEquipo2' => $equipo2->idEquipo
|
'idEquipo2' => $equipo2->idEquipo
|
||||||
|
|||||||
@@ -121,33 +121,4 @@ switch ($_POST['orden']) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case 'obtenerPreguntasPorCategoria':
|
|
||||||
|
|
||||||
$idCategoria = intval($_POST['idCategoria'] ?? 0);
|
|
||||||
$limite = intval($_POST['limite'] ?? 10);
|
|
||||||
|
|
||||||
$preguntas = Pregunta::obtenerPorCategoria($idCategoria, $limite);
|
|
||||||
|
|
||||||
// Si ha devuelto un array de errores (formato ['error'=>...]) lo mandamos tal cual
|
|
||||||
if (isset($preguntas['error'])) {
|
|
||||||
echo json_encode($preguntas);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convertimos cada objeto Pregunta en un array simple para poder mandarlo en JSON
|
|
||||||
$listado = [];
|
|
||||||
foreach ($preguntas as $p) {
|
|
||||||
$listado[] = [
|
|
||||||
'idPregunta' => $p->getIdPregunta(),
|
|
||||||
'idCategoria' => $p->getIdCategoria(),
|
|
||||||
'nombrePregunta' => $p->getNombrePregunta(),
|
|
||||||
'respuestas' => $p->getRespuestas()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode($listado);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
session_start();
|
|
||||||
|
|
||||||
require_once '../clases/ClaseRespuesta.php';
|
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
|
||||||
|
|
||||||
case 'crearRespuesta':
|
|
||||||
|
|
||||||
$idPregunta = intval($_POST['idPregunta'] ?? 0);
|
|
||||||
$nombreRespuesta = trim($_POST['nombreRespuesta'] ?? '');
|
|
||||||
$correcta = intval($_POST['correcta'] ?? 0);
|
|
||||||
|
|
||||||
if ($idPregunta <= 0 || $nombreRespuesta == '') {
|
|
||||||
echo json_encode(['error' => 'La pregunta y el texto de la respuesta son obligatorios']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$respuesta = new Respuesta(null, $idPregunta, $nombreRespuesta, $correcta);
|
|
||||||
$resultado = $respuesta->insertar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case 'listarRespuestas':
|
|
||||||
|
|
||||||
$respuesta = new Respuesta();
|
|
||||||
$resultado = $respuesta->listar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case 'listarRespuestasPorPregunta':
|
|
||||||
|
|
||||||
$idPregunta = intval($_POST['idPregunta'] ?? 0);
|
|
||||||
|
|
||||||
$respuesta = new Respuesta(null, $idPregunta);
|
|
||||||
$resultado = $respuesta->listarPorPregunta();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case 'editarRespuesta':
|
|
||||||
|
|
||||||
$idRespuesta = intval($_POST['idRespuesta'] ?? 0);
|
|
||||||
$idPregunta = intval($_POST['idPregunta'] ?? 0);
|
|
||||||
$nombreRespuesta = trim($_POST['nombreRespuesta'] ?? '');
|
|
||||||
$correcta = intval($_POST['correcta'] ?? 0);
|
|
||||||
|
|
||||||
$respuesta = new Respuesta($idRespuesta, $idPregunta, $nombreRespuesta, $correcta);
|
|
||||||
$resultado = $respuesta->editar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
case 'borrarRespuesta':
|
|
||||||
|
|
||||||
$idRespuesta = intval($_POST['idRespuesta'] ?? 0);
|
|
||||||
|
|
||||||
$respuesta = new Respuesta($idRespuesta);
|
|
||||||
$resultado = $respuesta->eliminar();
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -55,10 +55,11 @@ switch ($_POST['orden']) {
|
|||||||
|
|
||||||
if ($resultado instanceof Usuario) {
|
if ($resultado instanceof Usuario) {
|
||||||
|
|
||||||
// === AÑADIR ESTAS LÍNEAS PARA GUARDAR EN SESIÓN ===
|
// === GUARDAR EN SESIÓN (incluido avatar)===
|
||||||
$_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([
|
||||||
@@ -83,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();
|
||||||
@@ -92,7 +94,6 @@ switch ($_POST['orden']) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mostrarEstadisticas':
|
case 'mostrarEstadisticas':
|
||||||
|
|
||||||
$usuario = Usuario::buscarPorId($_SESSION['idUsuario']);
|
$usuario = Usuario::buscarPorId($_SESSION['idUsuario']);
|
||||||
@@ -242,7 +243,8 @@ switch ($_POST['orden']) {
|
|||||||
'activa' => true,
|
'activa' => true,
|
||||||
'usuario' => [
|
'usuario' => [
|
||||||
'idUsuario' => $_SESSION['idUsuario'],
|
'idUsuario' => $_SESSION['idUsuario'],
|
||||||
'nombreUsuario' => $_SESSION['nombreUsuario'] ?? ''
|
'nombreUsuario' => $_SESSION['nombreUsuario'] ?? '',
|
||||||
|
'avatar' => $_SESSION['avatar'] ?? ''
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+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 |
@@ -1,7 +1,3 @@
|
|||||||
<?php
|
|
||||||
include 'cabecera.php';
|
|
||||||
?>
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es-ES">
|
<html lang="es-ES">
|
||||||
|
|
||||||
@@ -9,16 +5,17 @@ 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 (oculto por defecto, JS lo muestra si hay sesión) -->
|
<!-- Botón Jugar (oculto por defecto, JS lo muestra si hay sesión activa) -->
|
||||||
<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>
|
||||||
|
|||||||
+44
-13
@@ -123,11 +123,23 @@ 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 ${
|
||||||
<span class="avatar">👤</span>
|
esHost ? "jugador-host" : ""
|
||||||
|
}">
|
||||||
|
<div>
|
||||||
|
<span class="avatar">${esHost ? "👑" : "👤"}</span>
|
||||||
${escapeHTML(jugador.nombreUsuario)}
|
${escapeHTML(jugador.nombreUsuario)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
${
|
||||||
|
esHost
|
||||||
|
? `<span class="badge bg-warning text-dark ms-2">HOST</span>`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
</div>
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -138,7 +150,7 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
let botonUnirseHTML = "";
|
let botonUnirseHTML = "";
|
||||||
if (!usuarioYaEstaEnEquipo) {
|
if (!usuarioYaEstaEnEquipo) {
|
||||||
botonUnirseHTML = `
|
botonUnirseHTML = `
|
||||||
<button type="button" class="btn btn-unirse w-100 btn-unirse-equipo mt-2"
|
<button type="button" class="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
|
||||||
@@ -157,17 +169,34 @@ 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) {
|
||||||
accionesSalaHTML = `
|
let botonIniciarHTML = "";
|
||||||
<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}">
|
// Solo el host puede iniciar la partida
|
||||||
Abandonar sala
|
if (partida.idUsuario == idUsuarioSesion) {
|
||||||
</button>
|
botonIniciarHTML = `
|
||||||
<a href="juego.php?idPartida=${partida.idPartida}" class="btn btn-success btn-lg px-4">
|
<a href="juego.php?idPartida=${partida.idPartida}"
|
||||||
|
class="btn btn-success btn-lg px-4">
|
||||||
🎮 ¡Iniciar Partida!
|
🎮 ¡Iniciar Partida!
|
||||||
</a>
|
</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}">
|
||||||
|
Abandonar sala
|
||||||
|
</button>
|
||||||
|
|
||||||
|
${botonIniciarHTML}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -175,7 +204,7 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
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">
|
<div class="sala-header h4 text-center mb-3 text-white">
|
||||||
${escapeHTML(partida.nombrePartida)}
|
${escapeHTML(partida.nombrePartida)}
|
||||||
</div>
|
</div>
|
||||||
<div class="sala-body">
|
<div class="sala-body">
|
||||||
@@ -234,13 +263,15 @@ 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(document.getElementById('modalAbandonarSala'));
|
const modal = new bootstrap.Modal(
|
||||||
|
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);
|
||||||
@@ -275,7 +306,7 @@ $(document).on("click", "#btnConfirmarAbandonar", function () {
|
|||||||
if (modalInstance) {
|
if (modalInstance) {
|
||||||
modalInstance.hide();
|
modalInstance.hide();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// 8. Evento: Crear Sala
|
// 8. Evento: Crear Sala
|
||||||
|
|||||||
+191
-249
@@ -1,275 +1,217 @@
|
|||||||
|
let idUsuarioSesion = null;
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
comprobarSesion();
|
// Comprobar la sesión activa al cargar la página
|
||||||
|
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
|
/**
|
||||||
function escapeHTML(str) {
|
* Comprueba con el servidor si existe una sesión PHP
|
||||||
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
|
/**
|
||||||
function comprobarSesion() {
|
* Petición AJAX para iniciar sesión
|
||||||
$.ajax({
|
*/
|
||||||
method: "POST",
|
function ejecutarLogin() {
|
||||||
url: "controladores/controladorUsuario.php",
|
let email = $('#loginEmail').val().trim();
|
||||||
data: { orden: "comprobarSesion" },
|
let contrasena = $('#loginPassword').val().trim();
|
||||||
}).done(function (respuesta) {
|
$('#errorLogin').text('');
|
||||||
try {
|
|
||||||
if (typeof respuesta === "string") {
|
if (email === '' || contrasena === '') {
|
||||||
respuesta = JSON.parse(respuesta);
|
$('#errorLogin').text('Por favor, rellena todos los campos.');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const contenedor = $("#contenedorUsuarioCabecera");
|
$.ajax({
|
||||||
contenedor.empty();
|
url: 'controladores/controladorUsuario.php',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
orden: 'comprobarUsuario',
|
||||||
|
email: email,
|
||||||
|
contrasena: contrasena
|
||||||
|
},
|
||||||
|
success: function (respuesta) {
|
||||||
|
if (respuesta.error) {
|
||||||
|
$('#errorLogin').text(respuesta.error);
|
||||||
|
} else if (respuesta.exito) {
|
||||||
|
$('#modalLogin').modal('hide');
|
||||||
|
$('#formLogin')[0].reset();
|
||||||
|
|
||||||
if (respuesta.activa && respuesta.usuario) {
|
// Cargar datos de la sesión actualizados
|
||||||
// Usuario autenticado: Mostrar Menú Dropdown
|
comprobarEstadoSesion();
|
||||||
const htmlUsuario = `
|
}
|
||||||
|
},
|
||||||
|
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">
|
<div class="dropdown">
|
||||||
<button class="btn user-dropdown-btn dropdown-toggle d-flex align-items-center gap-2"
|
<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">
|
||||||
type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
<img src="${avatarConCacheBuster}" alt="Avatar" class="rounded-circle border" style="width: 32px; height: 32px; object-fit: cover;">
|
||||||
<i class="fa-solid fa-circle-user fa-lg text-warning"></i>
|
<span>${escapeHtml(usuario.nombreUsuario)}</span>
|
||||||
<span>${escapeHTML(respuesta.usuario.nombreUsuario)}</span>
|
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu dropdown-menu-end user-dropdown-menu" aria-labelledby="userDropdown">
|
<ul class="dropdown-menu dropdown-menu-end shadow border-0 mt-2" aria-labelledby="userMenu">
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item d-flex align-items-center gap-2" href="perfil.php">
|
<a class="dropdown-item py-2 fw-semibold" href="perfil.php">
|
||||||
<i class="fa-solid fa-user text-primary"></i> Perfil
|
<i class="fa-solid fa-user me-2 text-primary"></i>Mi Perfil
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li><hr class="dropdown-divider"></li>
|
<li><hr class="dropdown-divider"></li>
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item logout-item d-flex align-items-center gap-2" href="#" id="botonCerrarSesion">
|
<button class="dropdown-item py-2 fw-semibold text-danger" onclick="cerrarSesion()">
|
||||||
<i class="fa-solid fa-right-from-bracket"></i> Cerrar Sesión
|
<i class="fa-solid fa-right-from-bracket me-2"></i>Cerrar Sesión
|
||||||
</a>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
contenedor.html(htmlUsuario);
|
$('#contenedorUsuarioCabecera').html(html);
|
||||||
|
}
|
||||||
|
|
||||||
// Si estamos en la página principal, mostramos el botón JUGAR
|
/**
|
||||||
if ($("#colBotonJugar").length) {
|
* Renderiza los botones en la cabecera cuando NO hay sesión (Iniciar sesión azul)
|
||||||
$("#colBotonJugar").removeClass("d-none");
|
*/
|
||||||
$("#colRanking").removeClass("col-lg-8").addClass("col-lg-7 col-xl-8");
|
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">
|
||||||
} else {
|
<i class="fa-solid fa-right-to-bracket me-1"></i> Iniciar sesión
|
||||||
// No hay sesión: Mostrar botones de Login y Registro
|
|
||||||
const htmlInvitado = `
|
|
||||||
<button type="button" class="btn btn-kahoot-login rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
|
||||||
<i class="fa-solid fa-right-to-bracket me-1"></i> Iniciar Sesión
|
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn btn-kahoot-register rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalRegistro">
|
<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
|
<i class="fa-solid fa-user-plus me-1"></i> Registrarse
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
contenedor.html(htmlInvitado);
|
$('#contenedorUsuarioCabecera').html(html);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evento Registro
|
function escapeHtml(texto) {
|
||||||
$("#botonAceptarRegistro").click(function (event) {
|
return $('<div>').text(texto).html();
|
||||||
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";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
// ============================================
|
|
||||||
// DATOS DE PRUEBA
|
|
||||||
// ============================================
|
|
||||||
|
|
||||||
const salas = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
nombre: "Sala Principal",
|
|
||||||
equipos: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
nombre: "Equipo 1",
|
|
||||||
jugadores: [
|
|
||||||
"Carlos",
|
|
||||||
"María"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
nombre: "Equipo 2",
|
|
||||||
jugadores: [
|
|
||||||
"Jorge"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
nombre: "Los Trivialeros",
|
|
||||||
equipos: [
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
nombre: "Equipo Rojo",
|
|
||||||
jugadores: [
|
|
||||||
"Ana",
|
|
||||||
"Pedro",
|
|
||||||
"Lucía"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
nombre: "Equipo Azul",
|
|
||||||
jugadores: [
|
|
||||||
"David",
|
|
||||||
"Laura"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
nombre: "Partida rápida",
|
|
||||||
equipos: [
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
nombre: "Equipo 1",
|
|
||||||
jugadores: [
|
|
||||||
"Miguel"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 6,
|
|
||||||
nombre: "Equipo 2",
|
|
||||||
jugadores: []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
nombre: "Noche de Trivial",
|
|
||||||
equipos: [
|
|
||||||
{
|
|
||||||
id: 7,
|
|
||||||
nombre: "Los quesitos",
|
|
||||||
jugadores: [
|
|
||||||
"Pablo",
|
|
||||||
"Sara"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 8,
|
|
||||||
nombre: "Los cerebritos",
|
|
||||||
jugadores: [
|
|
||||||
"Mario",
|
|
||||||
"Elena",
|
|
||||||
"Álvaro"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
// ============================================
|
|
||||||
// MOSTRAR SALAS
|
|
||||||
// ============================================
|
|
||||||
|
|
||||||
function mostrarSalas(salas) {
|
|
||||||
|
|
||||||
const contenedor = document.getElementById("contenedorSalas");
|
|
||||||
|
|
||||||
contenedor.innerHTML = "";
|
|
||||||
|
|
||||||
salas.forEach(sala => {
|
|
||||||
|
|
||||||
const columna = document.createElement("div");
|
|
||||||
|
|
||||||
columna.className = "col-12 col-md-6 col-xl-5";
|
|
||||||
|
|
||||||
|
|
||||||
columna.innerHTML = `
|
|
||||||
|
|
||||||
<div class="sala">
|
|
||||||
|
|
||||||
<div class="sala-header">
|
|
||||||
${sala.nombre}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="sala-body">
|
|
||||||
|
|
||||||
<div class="equipos">
|
|
||||||
|
|
||||||
${crearEquipo(sala, sala.equipos[0])}
|
|
||||||
|
|
||||||
${crearEquipo(sala, sala.equipos[1])}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
`;
|
|
||||||
|
|
||||||
contenedor.appendChild(columna);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ============================================
|
|
||||||
// CREAR EQUIPO
|
|
||||||
// ============================================
|
|
||||||
|
|
||||||
function crearEquipo(sala, equipo) {
|
|
||||||
|
|
||||||
let jugadoresHTML = "";
|
|
||||||
|
|
||||||
equipo.jugadores.forEach(jugador => {
|
|
||||||
|
|
||||||
jugadoresHTML += `
|
|
||||||
<div class="jugador">
|
|
||||||
<span class="avatar">👤</span>
|
|
||||||
${jugador}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
return `
|
|
||||||
|
|
||||||
<div class="equipo">
|
|
||||||
|
|
||||||
<h6>
|
|
||||||
${equipo.nombre}
|
|
||||||
</h6>
|
|
||||||
|
|
||||||
<div class="jugadores">
|
|
||||||
|
|
||||||
${jugadoresHTML}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn btn-unirse"
|
|
||||||
onclick="unirseEquipo(${sala.id}, ${equipo.id})">
|
|
||||||
|
|
||||||
Unirse
|
|
||||||
|
|
||||||
</button>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function unirseEquipo(idSala, idEquipo) {
|
|
||||||
|
|
||||||
console.log("Sala:", idSala);
|
|
||||||
console.log("Equipo:", idEquipo);
|
|
||||||
|
|
||||||
alert(
|
|
||||||
"Has pulsado unirse al equipo " +
|
|
||||||
idEquipo +
|
|
||||||
" de la sala " +
|
|
||||||
idSala
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ============================================
|
|
||||||
// CARGAR DATOS DE PRUEBA
|
|
||||||
// ============================================
|
|
||||||
|
|
||||||
mostrarSalas(salas);
|
|
||||||
+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);
|
||||||
|
|||||||
Reference in New Issue
Block a user