157 lines
6.5 KiB
PHP
157 lines
6.5 KiB
PHP
<?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">
|
|
<?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">🎥 Gestione Lezioni</a></li>
|
|
<li><a href="users.php" class="active">👥 Gestione Utenti</a></li>
|
|
<li><a href="purchases.php">💰 Acquisti</a></li>
|
|
<li><a href="../convert_videos.php">🔄 Converti Video</a></li>
|
|
<li><a href="profile.php">👤 Profilo</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)): ?>
|
|
<div class="table-container">
|
|
<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>
|
|
</div>
|
|
<?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>
|