Files
pilates-platform/admin/lessons.php
Francesco Picone 0be59cc836 fix grafica
2025-12-06 17:53:12 +01:00

158 lines
6.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Gestione Lezioni - Lista tutte le lezioni
*
* Visualizza tutte le lezioni con opzioni per modificare ed eliminare
*/
require_once '../includes/config.php';
require_once '../includes/functions.php';
session_start();
check_session_timeout();
require_admin();
// Gestione eliminazione
if (isset($_GET['delete']) && is_numeric($_GET['delete'])) {
$lesson_id = (int)$_GET['delete'];
$pdo = get_db_connection();
// Soft delete
$stmt = $pdo->prepare("UPDATE lessons SET deleted_at = NOW() WHERE id = ?");
if ($stmt->execute([$lesson_id])) {
set_flash_message('success', 'Lezione eliminata con successo');
} else {
set_flash_message('error', 'Errore durante l\'eliminazione');
}
header('Location: lessons.php');
exit;
}
// Ottieni tutte le lezioni
$pdo = get_db_connection();
$stmt = $pdo->query("
SELECT l.*,
COUNT(DISTINCT p.id) as purchase_count,
SUM(CASE WHEN p.status = 'completed' THEN p.amount ELSE 0 END) as total_revenue
FROM lessons l
LEFT JOIN purchases p ON l.id = p.lesson_id
WHERE l.deleted_at IS NULL
GROUP BY l.id
ORDER BY l.created_at DESC
");
$lessons = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gestione Lezioni - Admin</title>
<link rel="stylesheet" href="../assets/css/style.css">
</head>
<body>
<header class="header">
<div class="container">
<div class="header-content">
<?php if (file_exists('../uploads/images/logo.png')): ?>
<div class="logo">
<img src="../uploads/images/logo.png" alt="Pilates Studio" class="logo-image">
<span style="margin-left: 10px; color: var(--primary-color); font-weight: 600;">Admin</span>
</div>
<?php else: ?>
<h1 class="logo">Pilates Studio - Admin</h1>
<?php endif; ?>
<nav class="nav">
<a href="../index.php" class="btn btn-outline">Vedi Sito</a>
<a href="../includes/logout.php" class="btn btn-secondary">Logout</a>
</nav>
</div>
</div>
</header>
<div class="container">
<div class="dashboard">
<!-- Sidebar -->
<aside class="sidebar">
<ul class="sidebar-menu">
<li><a href="dashboard.php">📊 Dashboard</a></li>
<li><a href="lessons.php" class="active">🎥 Gestione Lezioni</a></li>
<li><a href="users.php">👥 Gestione Utenti</a></li>
<li><a href="purchases.php">💰 Acquisti</a></li>
</ul>
</aside>
<!-- Main Content -->
<main class="main-content">
<div class="d-flex justify-between align-center mb-2">
<h2 class="section-title" style="text-align: left; margin: 0;">Gestione Lezioni</h2>
<a href="lesson_create.php" class="btn btn-primary"> Nuova Lezione</a>
</div>
<?php echo display_flash_message(); ?>
<div class="card">
<?php if (!empty($lessons)): ?>
<div class="table-container">
<table class="table">
<thead>
<tr>
<th>Titolo</th>
<th>Tipo</th>
<th>Livello</th>
<th>Prezzo</th>
<th>Vendite</th>
<th>Guadagno</th>
<th>Status</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php foreach ($lessons as $lesson): ?>
<tr>
<td>
<strong><?php echo htmlspecialchars($lesson['title']); ?></strong>
<?php if ($lesson['is_demo']): ?>
<br><span class="text-success"><small>✓ Demo</small></span>
<?php endif; ?>
</td>
<td><?php echo ucfirst($lesson['type']); ?></td>
<td><?php echo ucfirst($lesson['level']); ?></td>
<td><?php echo format_price($lesson['price']); ?></td>
<td><?php echo $lesson['purchase_count']; ?></td>
<td><strong><?php echo format_price($lesson['total_revenue'] ?? 0); ?></strong></td>
<td>
<?php if ($lesson['is_active']): ?>
<span class="text-success">Attiva</span>
<?php else: ?>
<span class="text-muted">Disattiva</span>
<?php endif; ?>
</td>
<td>
<a href="lesson_edit.php?id=<?php echo $lesson['id']; ?>"
class="btn btn-small btn-secondary">Modifica</a>
<a href="lessons.php?delete=<?php echo $lesson['id']; ?>"
class="btn btn-small btn-danger"
data-confirm-delete>Elimina</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p class="text-muted text-center">Nessuna lezione disponibile. <a href="lesson_create.php">Creane una!</a></p>
<?php endif; ?>
</div>
</main>
</div>
</div>
<script src="../assets/js/main.js"></script>
</body>
</html>