This commit is contained in:
Francesco Picone
2025-12-03 18:35:21 +01:00
commit 4e41ca9bf7
22 changed files with 4836 additions and 0 deletions

148
admin/lessons.php Normal file
View File

@@ -0,0 +1,148 @@
<?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">
<h1 class="logo">Pilates Studio - Admin</h1>
<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)): ?>
<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>
<?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>