fix
This commit is contained in:
@@ -93,6 +93,7 @@ $top_lessons = $stmt->fetchAll();
|
||||
<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>
|
||||
<li><a href="profile.php">👤 Profilo</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<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>
|
||||
<li><a href="profile.php">👤 Profilo</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
|
||||
@@ -191,6 +191,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<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>
|
||||
<li><a href="profile.php">👤 Profilo</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ $lessons = $stmt->fetchAll();
|
||||
<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>
|
||||
<li><a href="profile.php">👤 Profilo</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
|
||||
279
admin/profile.php
Normal file
279
admin/profile.php
Normal file
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
/**
|
||||
* Profilo Amministratore
|
||||
*
|
||||
* Permette all'amministratore di visualizzare e modificare i propri dati e password
|
||||
*/
|
||||
|
||||
require_once '../includes/config.php';
|
||||
require_once '../includes/functions.php';
|
||||
|
||||
session_start();
|
||||
check_session_timeout();
|
||||
require_admin();
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$user = get_user_by_id($user_id);
|
||||
|
||||
$error = '';
|
||||
$success = false;
|
||||
|
||||
// Processa aggiornamento profilo
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_profile'])) {
|
||||
$first_name = sanitize_input($_POST['first_name'] ?? '');
|
||||
$last_name = sanitize_input($_POST['last_name'] ?? '');
|
||||
$email = sanitize_input($_POST['email'] ?? '');
|
||||
$phone = sanitize_input($_POST['phone'] ?? '');
|
||||
|
||||
if (empty($first_name) || empty($last_name) || empty($email)) {
|
||||
$error = 'Nome, cognome ed email sono obbligatori';
|
||||
} elseif (!validate_email($email)) {
|
||||
$error = 'Email non valida';
|
||||
} else {
|
||||
// Verifica se l'email è già usata da un altro utente
|
||||
$pdo = get_db_connection();
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ? AND id != ?");
|
||||
$stmt->execute([$email, $user_id]);
|
||||
|
||||
if ($stmt->fetch()) {
|
||||
$error = 'Questa email è già in uso';
|
||||
} else {
|
||||
// Aggiorna profilo
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE users
|
||||
SET first_name = ?, last_name = ?, email = ?, phone = ?, updated_at = NOW()
|
||||
WHERE id = ?
|
||||
");
|
||||
|
||||
if ($stmt->execute([$first_name, $last_name, $email, $phone, $user_id])) {
|
||||
$success = true;
|
||||
$user = get_user_by_id($user_id); // Ricarica dati
|
||||
set_flash_message('success', 'Profilo aggiornato con successo!');
|
||||
} else {
|
||||
$error = 'Errore durante l\'aggiornamento';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Processa cambio password
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['change_password'])) {
|
||||
$current_password = $_POST['current_password'] ?? '';
|
||||
$new_password = $_POST['new_password'] ?? '';
|
||||
$confirm_password = $_POST['confirm_password'] ?? '';
|
||||
|
||||
if (empty($current_password) || empty($new_password)) {
|
||||
$error = 'Inserisci la password attuale e la nuova password';
|
||||
} elseif (!verify_password($current_password, $user['password'])) {
|
||||
$error = 'Password attuale non corretta';
|
||||
} elseif (strlen($new_password) < 6) {
|
||||
$error = 'La nuova password deve essere di almeno 6 caratteri';
|
||||
} elseif ($new_password !== $confirm_password) {
|
||||
$error = 'Le password non corrispondono';
|
||||
} else {
|
||||
$pdo = get_db_connection();
|
||||
$hashed_password = hash_password($new_password);
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE users SET password = ?, updated_at = NOW() WHERE id = ?");
|
||||
|
||||
if ($stmt->execute([$hashed_password, $user_id])) {
|
||||
set_flash_message('success', 'Password cambiata con successo!');
|
||||
header('Location: profile.php');
|
||||
exit;
|
||||
} else {
|
||||
$error = 'Errore durante il cambio password';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Profilo Amministratore - Pilates Platform</title>
|
||||
<link rel="stylesheet" href="../assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="header">
|
||||
<div class="container">
|
||||
<nav class="nav">
|
||||
<a href="<?php echo SITE_URL; ?>" class="logo">Pilates Platform</a>
|
||||
<div class="nav-links">
|
||||
<a href="dashboard.php">Dashboard</a>
|
||||
<a href="lessons.php">Lezioni</a>
|
||||
<a href="users.php">Utenti</a>
|
||||
<a href="purchases.php">Acquisti</a>
|
||||
<a href="profile.php" class="active">Profilo</a>
|
||||
<a href="../includes/logout.php" class="btn-logout">Logout</a>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="main-content">
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>Profilo Amministratore</h1>
|
||||
<p class="subtitle">Gestisci i tuoi dati personali e la password</p>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-error">
|
||||
<?php echo htmlspecialchars($error); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (has_flash_message('success')): ?>
|
||||
<div class="alert alert-success">
|
||||
<?php echo htmlspecialchars(get_flash_message('success')); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="profile-container">
|
||||
<!-- Sezione Dati Personali -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Dati Personali</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" class="form">
|
||||
<div class="form-group">
|
||||
<label for="first_name">Nome</label>
|
||||
<input
|
||||
type="text"
|
||||
id="first_name"
|
||||
name="first_name"
|
||||
value="<?php echo htmlspecialchars($user['first_name']); ?>"
|
||||
required
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="last_name">Cognome</label>
|
||||
<input
|
||||
type="text"
|
||||
id="last_name"
|
||||
name="last_name"
|
||||
value="<?php echo htmlspecialchars($user['last_name']); ?>"
|
||||
required
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
name="email"
|
||||
value="<?php echo htmlspecialchars($user['email']); ?>"
|
||||
required
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="phone">Telefono</label>
|
||||
<input
|
||||
type="tel"
|
||||
id="phone"
|
||||
name="phone"
|
||||
value="<?php echo htmlspecialchars($user['phone'] ?? ''); ?>"
|
||||
>
|
||||
</div>
|
||||
|
||||
<button type="submit" name="update_profile" class="btn btn-primary">
|
||||
Aggiorna Profilo
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sezione Cambio Password -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Cambia Password</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" class="form">
|
||||
<div class="form-group">
|
||||
<label for="current_password">Password Attuale</label>
|
||||
<input
|
||||
type="password"
|
||||
id="current_password"
|
||||
name="current_password"
|
||||
required
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new_password">Nuova Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="new_password"
|
||||
name="new_password"
|
||||
minlength="6"
|
||||
required
|
||||
>
|
||||
<small class="form-text">Minimo 6 caratteri</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirm_password">Conferma Nuova Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="confirm_password"
|
||||
name="confirm_password"
|
||||
minlength="6"
|
||||
required
|
||||
>
|
||||
</div>
|
||||
|
||||
<button type="submit" name="change_password" class="btn btn-primary">
|
||||
Cambia Password
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Informazioni Account -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Informazioni Account</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<span class="info-label">Ruolo:</span>
|
||||
<span class="info-value">
|
||||
<strong class="badge badge-admin">Amministratore</strong>
|
||||
</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Account creato:</span>
|
||||
<span class="info-value">
|
||||
<?php echo format_date($user['created_at']); ?>
|
||||
</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Ultimo aggiornamento:</span>
|
||||
<span class="info-value">
|
||||
<?php echo format_date($user['updated_at']); ?>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="container">
|
||||
<p>© <?php echo date('Y'); ?> Pilates Platform. Tutti i diritti riservati.</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="../assets/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -74,6 +74,7 @@ $stats = $stmt->fetch();
|
||||
<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>
|
||||
<li><a href="profile.php">👤 Profilo</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ $users = $stmt->fetchAll();
|
||||
<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="profile.php">👤 Profilo</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user