211 lines
8.7 KiB
PHP
211 lines
8.7 KiB
PHP
<?php
|
||
/**
|
||
* Dashboard Amministratore
|
||
*
|
||
* Panoramica generale con statistiche e azioni rapide
|
||
*/
|
||
|
||
require_once '../includes/config.php';
|
||
require_once '../includes/functions.php';
|
||
|
||
session_start();
|
||
check_session_timeout();
|
||
require_admin();
|
||
|
||
// Ottieni statistiche
|
||
$pdo = get_db_connection();
|
||
|
||
// Conta utenti totali
|
||
$stmt = $pdo->query("SELECT COUNT(*) as count FROM users WHERE deleted_at IS NULL AND is_admin = 0");
|
||
$total_users = $stmt->fetch()['count'];
|
||
|
||
// Conta lezioni totali
|
||
$stmt = $pdo->query("SELECT COUNT(*) as count FROM lessons WHERE deleted_at IS NULL");
|
||
$total_lessons = $stmt->fetch()['count'];
|
||
|
||
// Conta acquisti completati
|
||
$stmt = $pdo->query("SELECT COUNT(*) as count FROM purchases WHERE status = 'completed'");
|
||
$total_purchases = $stmt->fetch()['count'];
|
||
|
||
// Totale guadagni
|
||
$stmt = $pdo->query("SELECT SUM(amount) as total FROM purchases WHERE status = 'completed'");
|
||
$total_revenue = $stmt->fetch()['total'] ?? 0;
|
||
|
||
// Ultimi acquisti
|
||
$stmt = $pdo->query("
|
||
SELECT p.*, u.first_name, u.last_name, u.email, l.title as lesson_title
|
||
FROM purchases p
|
||
INNER JOIN users u ON p.user_id = u.id
|
||
INNER JOIN lessons l ON p.lesson_id = l.id
|
||
WHERE p.status = 'completed'
|
||
ORDER BY p.purchased_at DESC
|
||
LIMIT 10
|
||
");
|
||
$recent_purchases = $stmt->fetchAll();
|
||
|
||
// Lezioni più vendute
|
||
$stmt = $pdo->query("
|
||
SELECT l.*, COUNT(p.id) as sales_count
|
||
FROM lessons l
|
||
LEFT JOIN purchases p ON l.id = p.lesson_id AND p.status = 'completed'
|
||
WHERE l.deleted_at IS NULL AND l.is_demo = 0
|
||
GROUP BY l.id
|
||
ORDER BY sales_count DESC
|
||
LIMIT 5
|
||
");
|
||
$top_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>Dashboard Admin - Pilates Platform</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" class="active">📊 Dashboard</a></li>
|
||
<li><a href="lessons.php">🎥 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">
|
||
<h2 class="section-title" style="text-align: left;">Dashboard</h2>
|
||
|
||
<?php echo display_flash_message(); ?>
|
||
|
||
<!-- Statistiche -->
|
||
<div class="stats-grid">
|
||
<div class="stat-card">
|
||
<div class="stat-value"><?php echo $total_users; ?></div>
|
||
<div class="stat-label">Utenti Registrati</div>
|
||
</div>
|
||
|
||
<div class="stat-card">
|
||
<div class="stat-value"><?php echo $total_lessons; ?></div>
|
||
<div class="stat-label">Lezioni Totali</div>
|
||
</div>
|
||
|
||
<div class="stat-card">
|
||
<div class="stat-value"><?php echo $total_purchases; ?></div>
|
||
<div class="stat-label">Acquisti</div>
|
||
</div>
|
||
|
||
<div class="stat-card">
|
||
<div class="stat-value"><?php echo format_price($total_revenue); ?></div>
|
||
<div class="stat-label">Guadagni Totali</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Azioni rapide -->
|
||
<div class="card">
|
||
<h3 class="card-header">Azioni Rapide</h3>
|
||
<div class="d-flex gap-1">
|
||
<a href="lesson_create.php" class="btn btn-primary">➕ Nuova Lezione</a>
|
||
<a href="lessons.php" class="btn btn-secondary">📋 Vedi Tutte le Lezioni</a>
|
||
<a href="users.php" class="btn btn-secondary">👥 Gestisci Utenti</a>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Lezioni più vendute -->
|
||
<div class="card">
|
||
<h3 class="card-header">Lezioni Più Vendute</h3>
|
||
<?php if (!empty($top_lessons)): ?>
|
||
<table class="table">
|
||
<thead>
|
||
<tr>
|
||
<th>Lezione</th>
|
||
<th>Tipo</th>
|
||
<th>Prezzo</th>
|
||
<th>Vendite</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($top_lessons as $lesson): ?>
|
||
<tr>
|
||
<td>
|
||
<strong><?php echo htmlspecialchars($lesson['title']); ?></strong>
|
||
<?php if ($lesson['is_demo']): ?>
|
||
<span class="text-success"> (Demo)</span>
|
||
<?php endif; ?>
|
||
</td>
|
||
<td><?php echo ucfirst($lesson['type']); ?></td>
|
||
<td><?php echo format_price($lesson['price']); ?></td>
|
||
<td><strong><?php echo $lesson['sales_count']; ?></strong></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
<?php else: ?>
|
||
<p class="text-muted">Nessuna lezione venduta ancora.</p>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<!-- Ultimi acquisti -->
|
||
<div class="card">
|
||
<h3 class="card-header">Ultimi Acquisti</h3>
|
||
<?php if (!empty($recent_purchases)): ?>
|
||
<table class="table">
|
||
<thead>
|
||
<tr>
|
||
<th>Data</th>
|
||
<th>Utente</th>
|
||
<th>Lezione</th>
|
||
<th>Importo</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($recent_purchases as $purchase): ?>
|
||
<tr>
|
||
<td><?php echo format_datetime($purchase['purchased_at']); ?></td>
|
||
<td>
|
||
<?php echo htmlspecialchars($purchase['first_name'] . ' ' . $purchase['last_name']); ?>
|
||
<br>
|
||
<small class="text-muted"><?php echo htmlspecialchars($purchase['email']); ?></small>
|
||
</td>
|
||
<td><?php echo htmlspecialchars($purchase['lesson_title']); ?></td>
|
||
<td><strong><?php echo format_price($purchase['amount']); ?></strong></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
<?php else: ?>
|
||
<p class="text-muted">Nessun acquisto ancora.</p>
|
||
<?php endif; ?>
|
||
</div>
|
||
</main>
|
||
</div>
|
||
</div>
|
||
|
||
<script src="../assets/js/main.js"></script>
|
||
</body>
|
||
</html>
|