Files
pilates-platform/lesson.php
Francesco Picone 0be59cc836 fix grafica
2025-12-06 17:53:12 +01:00

269 lines
12 KiB
PHP

<?php
/**
* Visualizza Lezione
*
* Mostra i dettagli di una lezione e permette di acquistarla o visualizzarla
*/
require_once 'includes/config.php';
require_once 'includes/functions.php';
session_start();
// Ottieni ID lezione
$lesson_id = isset($_GET['id']) && is_numeric($_GET['id']) ? (int)$_GET['id'] : 0;
if (!$lesson_id) {
header('Location: index.php');
exit;
}
// Ottieni dati lezione
$lesson = get_lesson_by_id($lesson_id);
if (!$lesson || !$lesson['is_active']) {
header('Location: index.php');
exit;
}
// Verifica se l'utente è loggato e possiede la lezione
$is_logged_in = is_logged_in();
$user_owns = false;
if ($is_logged_in) {
$user_owns = user_owns_lesson($_SESSION['user_id'], $lesson_id);
}
// Se è demo, tutti possono vedere
$can_view = $lesson['is_demo'] || $user_owns;
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($lesson['title']); ?> - Pilates Platform</title>
<link rel="stylesheet" href="assets/css/style.css">
<!-- PayPal SDK -->
<?php if (!$can_view && $is_logged_in): ?>
<script src="https://www.paypal.com/sdk/js?client-id=<?php echo PAYPAL_CLIENT_ID; ?>&currency=EUR"></script>
<?php endif; ?>
</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">
</div>
<?php else: ?>
<h1 class="logo">Pilates Studio</h1>
<?php endif; ?>
<nav class="nav">
<a href="index.php" class="btn btn-outline">Home</a>
<?php if ($is_logged_in): ?>
<?php if (is_admin()): ?>
<a href="admin/dashboard.php" class="btn btn-secondary">Area Admin</a>
<?php else: ?>
<a href="user/dashboard.php" class="btn btn-secondary">Le Mie Lezioni</a>
<?php endif; ?>
<a href="includes/logout.php" class="btn btn-outline">Logout</a>
<?php else: ?>
<a href="login.php" class="btn btn-secondary">Accedi</a>
<?php endif; ?>
</nav>
</div>
</div>
</header>
<div class="container" style="padding: 2rem 0;">
<div class="card">
<?php echo display_flash_message(); ?>
<h1 style="margin-bottom: 1rem;"><?php echo htmlspecialchars($lesson['title']); ?></h1>
<div style="display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;">
<span class="badge">
<?php echo $lesson['type'] === 'video' ? '📹 Video' : '📡 Live'; ?>
</span>
<span class="badge">
📊 <?php echo ucfirst($lesson['level']); ?>
</span>
<?php if ($lesson['duration']): ?>
<span class="badge">⏱️ <?php echo $lesson['duration']; ?> min</span>
<?php endif; ?>
<?php if ($lesson['category']): ?>
<span class="badge">📂 <?php echo htmlspecialchars($lesson['category']); ?></span>
<?php endif; ?>
</div>
<!-- Video Player o Info Live -->
<?php if ($can_view): ?>
<?php if ($lesson['type'] === 'video'): ?>
<div style="background: #000; border-radius: 8px; margin-bottom: 2rem; aspect-ratio: 16/9;">
<?php if ($lesson['video_url']): ?>
<?php if ($lesson['video_platform'] === 'youtube'): ?>
<!-- Embed YouTube -->
<?php
$video_id = '';
if (preg_match('/(?:youtube\.com\/watch\?v=|youtu\.be\/)([^&\?\/]+)/', $lesson['video_url'], $matches)) {
$video_id = $matches[1];
}
?>
<?php if ($video_id): ?>
<iframe width="100%" height="100%"
src="https://www.youtube.com/embed/<?php echo $video_id; ?>"
frameborder="0" allowfullscreen
style="border-radius: 8px;"></iframe>
<?php endif; ?>
<?php elseif ($lesson['video_platform'] === 'vimeo'): ?>
<!-- Embed Vimeo -->
<?php
$video_id = '';
if (preg_match('/vimeo\.com\/(\d+)/', $lesson['video_url'], $matches)) {
$video_id = $matches[1];
}
?>
<?php if ($video_id): ?>
<iframe width="100%" height="100%"
src="https://player.vimeo.com/video/<?php echo $video_id; ?>"
frameborder="0" allowfullscreen
style="border-radius: 8px;"></iframe>
<?php endif; ?>
<?php else: ?>
<!-- Video locale o altro -->
<video controls width="100%" height="100%" style="border-radius: 8px;">
<source src="<?php echo htmlspecialchars($lesson['video_url']); ?>">
Il tuo browser non supporta il tag video.
</video>
<?php endif; ?>
<?php else: ?>
<div style="display: flex; align-items: center; justify-content: center; height: 100%; color: white;">
Video non ancora disponibile
</div>
<?php endif; ?>
</div>
<?php else: ?>
<!-- Lezione Live -->
<div class="alert alert-info">
<h3>📡 Lezione Live</h3>
<p><strong>Data e ora:</strong> <?php echo format_datetime($lesson['live_date']); ?></p>
<?php if ($lesson['live_platform']): ?>
<p><strong>Piattaforma:</strong> <?php echo htmlspecialchars($lesson['live_platform']); ?></p>
<?php endif; ?>
<?php if ($lesson['live_url']): ?>
<a href="<?php echo htmlspecialchars($lesson['live_url']); ?>"
target="_blank" class="btn btn-primary" style="margin-top: 1rem;">
Partecipa alla Lezione Live
</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
<!-- Descrizione -->
<h3>Descrizione</h3>
<p style="line-height: 1.8; margin-bottom: 2rem;">
<?php echo nl2br(htmlspecialchars($lesson['description'])); ?>
</p>
<!-- Acquisto o Accesso -->
<?php if ($lesson['is_demo']): ?>
<div class="alert alert-success">
<strong>✓ Lezione Gratuita!</strong> Questa lezione è disponibile gratuitamente per tutti.
</div>
<?php elseif ($user_owns): ?>
<div class="alert alert-success">
<strong>✓ Hai già acquistato questa lezione!</strong>
</div>
<?php elseif ($is_logged_in): ?>
<!-- Form Acquisto PayPal -->
<div style="border: 2px solid var(--primary-color); border-radius: 12px; padding: 2rem; text-align: center;">
<h2 style="color: var(--primary-color); margin-bottom: 1rem;">
Prezzo: <?php echo format_price($lesson['price']); ?>
</h2>
<p class="text-muted mb-2">Acquista questa lezione e avrai accesso illimitato per sempre</p>
<!-- PayPal Button Container -->
<div id="paypal-button-container" style="max-width: 400px; margin: 0 auto;"></div>
<p class="text-muted" style="font-size: 0.875rem; margin-top: 1rem;">
Pagamento sicuro tramite PayPal
</p>
</div>
<?php else: ?>
<div class="alert alert-warning text-center">
<h3>Accedi per acquistare questa lezione</h3>
<p>Prezzo: <strong><?php echo format_price($lesson['price']); ?></strong></p>
<a href="login.php" class="btn btn-primary" style="margin-top: 1rem;">Accedi o Registrati</a>
</div>
<?php endif; ?>
</div>
</div>
<?php if (!$can_view && $is_logged_in): ?>
<script>
// Integrazione PayPal
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
description: '<?php echo addslashes($lesson['title']); ?>',
amount: {
value: '<?php echo number_format($lesson['price'], 2, '.', ''); ?>'
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Invia i dettagli al server per registrare l'acquisto
fetch('process_payment.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID,
lessonID: <?php echo $lesson_id; ?>,
payerID: details.payer.payer_id,
amount: '<?php echo number_format($lesson['price'], 2, '.', ''); ?>'
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.href = 'lesson.php?id=<?php echo $lesson_id; ?>&payment=success';
} else {
alert('Errore durante la registrazione del pagamento. Contatta il supporto.');
}
});
});
},
onError: function(err) {
console.error(err);
alert('Si è verificato un errore durante il pagamento. Riprova.');
}
}).render('#paypal-button-container');
</script>
<?php endif; ?>
<style>
.badge {
display: inline-block;
padding: 0.5rem 1rem;
background: var(--secondary-color);
color: var(--primary-color);
border-radius: 20px;
font-size: 0.875rem;
font-weight: 500;
}
</style>
<script src="assets/js/main.js"></script>
</body>
</html>