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

203
admin/dashboard.php Normal file
View File

@@ -0,0 +1,203 @@
<?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">
<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" 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>

286
admin/lesson_create.php Normal file
View File

@@ -0,0 +1,286 @@
<?php
/**
* Crea Nuova Lezione
*
* Form per creare una nuova videolezione o lezione live
*/
require_once '../includes/config.php';
require_once '../includes/functions.php';
session_start();
check_session_timeout();
require_admin();
$error = '';
$success = false;
// Processa il form
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = sanitize_input($_POST['title'] ?? '');
$description = sanitize_input($_POST['description'] ?? '');
$type = $_POST['type'] ?? 'video';
$level = $_POST['level'] ?? 'principiante';
$category = sanitize_input($_POST['category'] ?? '');
$price = floatval($_POST['price'] ?? 0);
$duration = !empty($_POST['duration']) ? intval($_POST['duration']) : null;
$video_url = sanitize_input($_POST['video_url'] ?? '');
$video_platform = $_POST['video_platform'] ?? 'local';
$live_url = sanitize_input($_POST['live_url'] ?? '');
$live_platform = sanitize_input($_POST['live_platform'] ?? '');
$live_date = !empty($_POST['live_date']) ? $_POST['live_date'] : null;
$is_demo = isset($_POST['is_demo']) ? 1 : 0;
$is_active = isset($_POST['is_active']) ? 1 : 0;
// Validazione
if (empty($title)) {
$error = 'Il titolo è obbligatorio';
} elseif (empty($description)) {
$error = 'La descrizione è obbligatoria';
} elseif ($type === 'live' && empty($live_date)) {
$error = 'Per le lezioni live, la data è obbligatoria';
} else {
$pdo = get_db_connection();
try {
$stmt = $pdo->prepare("
INSERT INTO lessons (
title, description, type, video_url, video_platform,
duration, live_platform, live_url, live_date,
level, category, price, is_demo, is_active,
created_by, created_at
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW()
)
");
$stmt->execute([
$title,
$description,
$type,
$type === 'video' ? $video_url : null,
$type === 'video' ? $video_platform : null,
$duration,
$type === 'live' ? $live_platform : null,
$type === 'live' ? $live_url : null,
$live_date,
$level,
$category,
$price,
$is_demo,
$is_active,
$_SESSION['user_id']
]);
set_flash_message('success', 'Lezione creata con successo!');
header('Location: lessons.php');
exit;
} catch (PDOException $e) {
$error = 'Errore durante la creazione della lezione';
}
}
}
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nuova Lezione - 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="lessons.php" class="btn btn-outline">← Torna alle Lezioni</a>
<a href="../includes/logout.php" class="btn btn-secondary">Logout</a>
</nav>
</div>
</div>
</header>
<div class="container">
<div class="dashboard">
<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 class="main-content">
<h2 class="section-title" style="text-align: left;">Crea Nuova Lezione</h2>
<?php if ($error): ?>
<div class="alert alert-error"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<div class="card">
<form method="POST" action="">
<!-- Informazioni Base -->
<h3 style="margin-bottom: 1rem; color: var(--primary-color);">Informazioni Base</h3>
<div class="form-group">
<label for="title" class="form-label">Titolo *</label>
<input type="text" id="title" name="title" class="form-control" required
value="<?php echo htmlspecialchars($_POST['title'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="description" class="form-label">Descrizione *</label>
<textarea id="description" name="description" class="form-control" required
rows="4"><?php echo htmlspecialchars($_POST['description'] ?? ''); ?></textarea>
</div>
<div class="form-group">
<label for="type" class="form-label">Tipo Lezione *</label>
<select id="type" name="type" class="form-control" required onchange="toggleTypeFields()">
<option value="video" <?php echo ($_POST['type'] ?? 'video') === 'video' ? 'selected' : ''; ?>>
Videolezione Registrata
</option>
<option value="live" <?php echo ($_POST['type'] ?? '') === 'live' ? 'selected' : ''; ?>>
Lezione Live
</option>
</select>
</div>
<!-- Campi Video -->
<div id="video-fields" style="display: <?php echo ($_POST['type'] ?? 'video') === 'video' ? 'block' : 'none'; ?>;">
<h3 style="margin: 2rem 0 1rem; color: var(--primary-color);">Dettagli Video</h3>
<div class="form-group">
<label for="video_platform" class="form-label">Piattaforma Video</label>
<select id="video_platform" name="video_platform" class="form-control">
<option value="local">File Locale</option>
<option value="youtube">YouTube</option>
<option value="vimeo">Vimeo</option>
<option value="s3">AWS S3</option>
</select>
</div>
<div class="form-group">
<label for="video_url" class="form-label">URL/Percorso Video</label>
<input type="text" id="video_url" name="video_url" class="form-control"
placeholder="es: https://youtube.com/watch?v=..."
value="<?php echo htmlspecialchars($_POST['video_url'] ?? ''); ?>">
<small class="text-muted">Lascia vuoto se caricherai il video successivamente</small>
</div>
<div class="form-group">
<label for="duration" class="form-label">Durata (minuti)</label>
<input type="number" id="duration" name="duration" class="form-control"
min="1" value="<?php echo htmlspecialchars($_POST['duration'] ?? ''); ?>">
</div>
</div>
<!-- Campi Live -->
<div id="live-fields" style="display: <?php echo ($_POST['type'] ?? '') === 'live' ? 'block' : 'none'; ?>;">
<h3 style="margin: 2rem 0 1rem; color: var(--primary-color);">Dettagli Lezione Live</h3>
<div class="form-group">
<label for="live_platform" class="form-label">Piattaforma Live</label>
<input type="text" id="live_platform" name="live_platform" class="form-control"
placeholder="es: Zoom, Google Meet, Teams..."
value="<?php echo htmlspecialchars($_POST['live_platform'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="live_url" class="form-label">Link Lezione Live</label>
<input type="text" id="live_url" name="live_url" class="form-control"
placeholder="es: https://zoom.us/j/..."
value="<?php echo htmlspecialchars($_POST['live_url'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="live_date" class="form-label">Data e Ora Lezione *</label>
<input type="datetime-local" id="live_date" name="live_date" class="form-control"
value="<?php echo htmlspecialchars($_POST['live_date'] ?? ''); ?>">
</div>
</div>
<!-- Classificazione -->
<h3 style="margin: 2rem 0 1rem; color: var(--primary-color);">Classificazione</h3>
<div class="form-group">
<label for="level" class="form-label">Livello *</label>
<select id="level" name="level" class="form-control" required>
<option value="principiante" <?php echo ($_POST['level'] ?? 'principiante') === 'principiante' ? 'selected' : ''; ?>>
Principiante
</option>
<option value="intermedio" <?php echo ($_POST['level'] ?? '') === 'intermedio' ? 'selected' : ''; ?>>
Intermedio
</option>
<option value="avanzato" <?php echo ($_POST['level'] ?? '') === 'avanzato' ? 'selected' : ''; ?>>
Avanzato
</option>
</select>
</div>
<div class="form-group">
<label for="category" class="form-label">Categoria</label>
<input type="text" id="category" name="category" class="form-control"
placeholder="es: Mat Work, Reformer, Stretching..."
value="<?php echo htmlspecialchars($_POST['category'] ?? ''); ?>">
</div>
<!-- Prezzo e Disponibilità -->
<h3 style="margin: 2rem 0 1rem; color: var(--primary-color);">Prezzo e Disponibilità</h3>
<div class="form-group">
<label for="price" class="form-label">Prezzo (€) *</label>
<input type="number" id="price" name="price" class="form-control"
min="0" step="0.01" required
value="<?php echo htmlspecialchars($_POST['price'] ?? '0'); ?>">
</div>
<div class="form-group">
<label class="form-label">
<input type="checkbox" name="is_demo" value="1"
<?php echo isset($_POST['is_demo']) ? 'checked' : ''; ?>>
Lezione Demo (gratuita per tutti)
</label>
</div>
<div class="form-group">
<label class="form-label">
<input type="checkbox" name="is_active" value="1"
<?php echo !isset($_POST['is_active']) || $_POST['is_active'] ? 'checked' : ''; ?>>
Lezione attiva (visibile agli utenti)
</label>
</div>
<div class="d-flex gap-1 mt-3">
<button type="submit" class="btn btn-primary">Crea Lezione</button>
<a href="lessons.php" class="btn btn-outline">Annulla</a>
</div>
</form>
</div>
</main>
</div>
</div>
<script>
// Mostra/nascondi campi in base al tipo di lezione
function toggleTypeFields() {
const type = document.getElementById('type').value;
const videoFields = document.getElementById('video-fields');
const liveFields = document.getElementById('live-fields');
if (type === 'video') {
videoFields.style.display = 'block';
liveFields.style.display = 'none';
} else {
videoFields.style.display = 'none';
liveFields.style.display = 'block';
}
}
</script>
<script src="../assets/js/main.js"></script>
</body>
</html>

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>

165
admin/purchases.php Normal file
View File

@@ -0,0 +1,165 @@
<?php
/**
* Visualizza Acquisti
*
* Lista di tutti gli acquisti effettuati sulla piattaforma
*/
require_once '../includes/config.php';
require_once '../includes/functions.php';
session_start();
check_session_timeout();
require_admin();
// Ottieni tutti gli acquisti
$pdo = get_db_connection();
$stmt = $pdo->query("
SELECT p.*,
u.first_name, u.last_name, u.email,
l.title as lesson_title, l.type as lesson_type
FROM purchases p
INNER JOIN users u ON p.user_id = u.id
INNER JOIN lessons l ON p.lesson_id = l.id
ORDER BY p.created_at DESC
");
$purchases = $stmt->fetchAll();
// Statistiche
$stmt = $pdo->query("
SELECT
COUNT(*) as total_purchases,
SUM(CASE WHEN status = 'completed' THEN amount ELSE 0 END) as total_revenue,
SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) as pending_count,
SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) as failed_count
FROM purchases
");
$stats = $stmt->fetch();
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Acquisti - 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">🎥 Gestione Lezioni</a></li>
<li><a href="users.php">👥 Gestione Utenti</a></li>
<li><a href="purchases.php" class="active">💰 Acquisti</a></li>
</ul>
</aside>
<!-- Main Content -->
<main class="main-content">
<h2 class="section-title" style="text-align: left;">Storico Acquisti</h2>
<!-- Statistiche rapide -->
<div class="stats-grid" style="grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));">
<div class="stat-card">
<div class="stat-value"><?php echo $stats['total_purchases']; ?></div>
<div class="stat-label">Totale Transazioni</div>
</div>
<div class="stat-card" style="background: linear-gradient(135deg, #2ECC71, #27AE60);">
<div class="stat-value"><?php echo format_price($stats['total_revenue']); ?></div>
<div class="stat-label">Incassi Totali</div>
</div>
<div class="stat-card" style="background: linear-gradient(135deg, #F39C12, #E67E22);">
<div class="stat-value"><?php echo $stats['pending_count']; ?></div>
<div class="stat-label">In Attesa</div>
</div>
<div class="stat-card" style="background: linear-gradient(135deg, #E74C3C, #C0392B);">
<div class="stat-value"><?php echo $stats['failed_count']; ?></div>
<div class="stat-label">Falliti</div>
</div>
</div>
<div class="card">
<?php if (!empty($purchases)): ?>
<table class="table">
<thead>
<tr>
<th>Data</th>
<th>Utente</th>
<th>Lezione</th>
<th>Tipo</th>
<th>Importo</th>
<th>Status</th>
<th>PayPal ID</th>
</tr>
</thead>
<tbody>
<?php foreach ($purchases as $purchase): ?>
<tr>
<td>
<?php
echo $purchase['purchased_at']
? format_datetime($purchase['purchased_at'])
: format_datetime($purchase['created_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><?php echo ucfirst($purchase['lesson_type']); ?></td>
<td><strong><?php echo format_price($purchase['amount']); ?></strong></td>
<td>
<?php
$status_colors = [
'completed' => 'text-success',
'pending' => 'text-warning',
'failed' => 'text-danger',
'refunded' => 'text-muted'
];
$color = $status_colors[$purchase['status']] ?? '';
?>
<span class="<?php echo $color; ?>">
<?php echo ucfirst($purchase['status']); ?>
</span>
</td>
<td>
<small class="text-muted">
<?php echo $purchase['paypal_order_id'] ? htmlspecialchars($purchase['paypal_order_id']) : '-'; ?>
</small>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p class="text-muted text-center">Nessun acquisto ancora.</p>
<?php endif; ?>
</div>
</main>
</div>
</div>
<script src="../assets/js/main.js"></script>
</body>
</html>

145
admin/users.php Normal file
View File

@@ -0,0 +1,145 @@
<?php
/**
* Gestione Utenti
*
* Visualizza tutti gli utenti registrati con opzioni di gestione
*/
require_once '../includes/config.php';
require_once '../includes/functions.php';
session_start();
check_session_timeout();
require_admin();
// Gestione blocco/sblocco utente
if (isset($_GET['toggle_active']) && is_numeric($_GET['toggle_active'])) {
$user_id = (int)$_GET['toggle_active'];
$pdo = get_db_connection();
$stmt = $pdo->prepare("UPDATE users SET is_active = NOT is_active WHERE id = ?");
if ($stmt->execute([$user_id])) {
set_flash_message('success', 'Stato utente aggiornato');
} else {
set_flash_message('error', 'Errore durante l\'aggiornamento');
}
header('Location: users.php');
exit;
}
// Ottieni tutti gli utenti non admin
$pdo = get_db_connection();
$stmt = $pdo->query("
SELECT u.*,
COUNT(DISTINCT p.id) as purchase_count,
SUM(CASE WHEN p.status = 'completed' THEN p.amount ELSE 0 END) as total_spent
FROM users u
LEFT JOIN purchases p ON u.id = p.user_id
WHERE u.is_admin = 0 AND u.deleted_at IS NULL
GROUP BY u.id
ORDER BY u.created_at DESC
");
$users = $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 Utenti - 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">🎥 Gestione Lezioni</a></li>
<li><a href="users.php" class="active">👥 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;">Gestione Utenti</h2>
<?php echo display_flash_message(); ?>
<div class="card">
<p class="text-muted mb-2">Totale utenti registrati: <strong><?php echo count($users); ?></strong></p>
<?php if (!empty($users)): ?>
<table class="table">
<thead>
<tr>
<th>Nome</th>
<th>Email</th>
<th>Registrato il</th>
<th>Ultimo Accesso</th>
<th>Acquisti</th>
<th>Speso</th>
<th>Status</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td>
<strong><?php echo htmlspecialchars($user['first_name'] . ' ' . $user['last_name']); ?></strong>
</td>
<td><?php echo htmlspecialchars($user['email']); ?></td>
<td><?php echo format_date($user['created_at']); ?></td>
<td>
<?php
echo $user['last_login'] ? format_datetime($user['last_login']) : 'Mai';
?>
</td>
<td><?php echo $user['purchase_count']; ?></td>
<td><strong><?php echo format_price($user['total_spent'] ?? 0); ?></strong></td>
<td>
<?php if ($user['is_active']): ?>
<span class="text-success">✓ Attivo</span>
<?php else: ?>
<span class="text-danger">✗ Bloccato</span>
<?php endif; ?>
</td>
<td>
<a href="users.php?toggle_active=<?php echo $user['id']; ?>"
class="btn btn-small <?php echo $user['is_active'] ? 'btn-danger' : 'btn-success'; ?>">
<?php echo $user['is_active'] ? 'Blocca' : 'Sblocca'; ?>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p class="text-muted text-center">Nessun utente registrato ancora.</p>
<?php endif; ?>
</div>
</main>
</div>
</div>
<script src="../assets/js/main.js"></script>
</body>
</html>