5) { $errors[] = 'La calificación debe ser entre 1 y 5.'; } if (empty($errors)) { $stmt = $db->prepare("INSERT INTO testimonios (nombre_cliente, texto, calificacion, activo, created_at) VALUES (?, ?, ?, 1, NOW())"); $stmt->execute([$nombre, $texto, $calificacion]); header('Location: testimonios.php?added=1'); exit; } break; // ── Edit testimonial ──────────────────────────────────── case 'edit_testimonial': $id = (int)($_POST['testimonial_id'] ?? 0); $nombre = trim($_POST['nombre_cliente'] ?? ''); $texto = trim($_POST['texto'] ?? ''); $calificacion = (int)($_POST['calificacion'] ?? 0); if ($nombre === '') { $errors[] = 'El nombre del cliente es obligatorio.'; } if ($texto === '') { $errors[] = 'El texto del testimonio es obligatorio.'; } if ($calificacion < 1 || $calificacion > 5) { $errors[] = 'La calificación debe ser entre 1 y 5.'; } if (empty($errors) && $id > 0) { $stmt = $db->prepare("UPDATE testimonios SET nombre_cliente = ?, texto = ?, calificacion = ? WHERE id = ?"); $stmt->execute([$nombre, $texto, $calificacion, $id]); header('Location: testimonios.php?updated=1'); exit; } break; // ── Toggle active ─────────────────────────────────────── case 'toggle_active': $id = (int)($_POST['testimonial_id'] ?? 0); if ($id > 0) { $stmt = $db->prepare("UPDATE testimonios SET activo = !activo WHERE id = ?"); $stmt->execute([$id]); } header('Location: testimonios.php?toggled=1'); exit; // ── Delete testimonial ────────────────────────────────── case 'delete_testimonial': $id = (int)($_POST['testimonial_id'] ?? 0); if ($id > 0) { $stmt = $db->prepare("DELETE FROM testimonios WHERE id = ?"); $stmt->execute([$id]); } header('Location: testimonios.php?deleted=1'); exit; } } // ── Flash messages from redirect ──────────────────────────────── if (isset($_GET['added'])) $success = 'Testimonio creado correctamente.'; if (isset($_GET['updated'])) $success = 'Testimonio actualizado correctamente.'; if (isset($_GET['toggled'])) $success = 'Estado del testimonio actualizado.'; if (isset($_GET['deleted'])) $success = 'Testimonio eliminado correctamente.'; // ── Load testimonial for editing ──────────────────────────────── $editing = false; $editData = null; $editId = (int)($_GET['edit'] ?? 0); if ($editId > 0) { $stmt = $db->prepare("SELECT * FROM testimonios WHERE id = ?"); $stmt->execute([$editId]); $editData = $stmt->fetch(); if ($editData) { $editing = true; } } // ── Fetch all testimonials ────────────────────────────────────── $stmt = $db->query("SELECT * FROM testimonios ORDER BY created_at DESC"); $testimonios = $stmt->fetchAll(); $totalTestimonios = count($testimonios); $totalActivos = 0; foreach ($testimonios as $t) { if ((int)$t['activo'] === 1) $totalActivos++; } ?>
Gestiona los testimonios de clientes que se muestran en el sitio público
No hay testimonios registrados aún.
“= htmlspecialchars($t['texto']) ?>”