374 lines
16 KiB
PHP
374 lines
16 KiB
PHP
<?php
|
|
/**
|
|
* Profilo Amministratore (Profilo Istruttrice)
|
|
*
|
|
* 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';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Processa test invio email
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['test_email'])) {
|
|
$test_email = sanitize_input($_POST['test_email_address'] ?? '');
|
|
|
|
if (empty($test_email) || !validate_email($test_email)) {
|
|
$error = 'Inserisci un indirizzo email valido';
|
|
} else {
|
|
$subject = "Test Email - " . SITE_NAME;
|
|
$body = "
|
|
<html>
|
|
<head>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
|
|
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
|
|
.header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; text-align: center; border-radius: 8px 8px 0 0; }
|
|
.content { background: #f9f9f9; padding: 30px; border-radius: 0 0 8px 8px; }
|
|
.success { color: #2ECC71; font-size: 24px; font-weight: bold; }
|
|
.info { background: #e8f4f8; padding: 15px; border-left: 4px solid #3498db; margin: 15px 0; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class='container'>
|
|
<div class='header'>
|
|
<h1>✅ Test Email Configurazione SMTP</h1>
|
|
</div>
|
|
<div class='content'>
|
|
<p class='success'>Congratulazioni!</p>
|
|
<p>La configurazione SMTP funziona correttamente.</p>
|
|
<p>Hai ricevuto questa email di test da <strong>" . SITE_NAME . "</strong></p>
|
|
<div class='info'>
|
|
<strong>Dettagli configurazione:</strong><br>
|
|
Host: " . SMTP_HOST . "<br>
|
|
Port: " . SMTP_PORT . "<br>
|
|
Username: " . SMTP_USERNAME . "<br>
|
|
Encryption: " . SMTP_ENCRYPTION . "
|
|
</div>
|
|
<p>Ora il sistema è pronto per inviare email agli utenti per:</p>
|
|
<ul>
|
|
<li>Benvenuto alla registrazione</li>
|
|
<li>Reset password</li>
|
|
<li>Conferma acquisti</li>
|
|
<li>Notifiche importanti</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
";
|
|
|
|
if (send_email($test_email, $subject, $body)) {
|
|
set_flash_message('success', '✅ Email di test inviata con successo a ' . htmlspecialchars($test_email) . '! Controlla la casella di posta.');
|
|
header('Location: profile.php');
|
|
exit;
|
|
} else {
|
|
$error = '❌ Errore durante l\'invio dell\'email. Verifica le impostazioni SMTP in config.php';
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!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">
|
|
<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">👥 Gestione Utenti</a></li>
|
|
<li><a href="purchases.php">💰 Acquisti</a></li>
|
|
<li><a href="profile.php" class="active">👤 Profilo</a></li>
|
|
</ul>
|
|
</aside>
|
|
|
|
<!-- Main Content -->
|
|
<main class="main-content">
|
|
<h2 class="section-title" style="text-align: left;">Profilo Amministratore</h2>
|
|
|
|
<?php echo display_flash_message(); ?>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-error"><?php echo htmlspecialchars($error); ?></div>
|
|
<?php endif; ?>
|
|
<!-- 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>
|
|
|
|
<!-- Test Invio Email -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h2>📧 Test Invio Email</h2>
|
|
</div>
|
|
<div class="card-body">
|
|
<p style="margin-bottom: 1rem; color: #666;">
|
|
Verifica che la configurazione SMTP funzioni correttamente inviando una email di test.
|
|
</p>
|
|
<form method="POST" class="form">
|
|
<div class="form-group">
|
|
<label for="test_email_address">Indirizzo Email per Test</label>
|
|
<input
|
|
type="email"
|
|
id="test_email_address"
|
|
name="test_email_address"
|
|
value="<?php echo htmlspecialchars($user['email']); ?>"
|
|
placeholder="tua-email@esempio.com"
|
|
required
|
|
>
|
|
<small class="form-text">Riceverai una email di test a questo indirizzo</small>
|
|
</div>
|
|
|
|
<button type="submit" name="test_email" class="btn btn-secondary">
|
|
📨 Invia Email di Test
|
|
</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>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
|
|
<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>
|