fix lesson_edit.php
This commit is contained in:
329
admin/lesson_edit.php
Normal file
329
admin/lesson_edit.php
Normal file
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
/**
|
||||
* Modifica Lezione
|
||||
*
|
||||
* Form per modificare una videolezione o lezione live esistente
|
||||
*/
|
||||
|
||||
require_once '../includes/config.php';
|
||||
require_once '../includes/functions.php';
|
||||
|
||||
session_start();
|
||||
check_session_timeout();
|
||||
require_admin();
|
||||
|
||||
$error = '';
|
||||
$success = false;
|
||||
$lesson = null;
|
||||
|
||||
// Verifica che sia stato passato un ID valido
|
||||
$lesson_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
||||
|
||||
if ($lesson_id <= 0) {
|
||||
set_flash_message('error', 'ID lezione non valido');
|
||||
header('Location: lessons.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = get_db_connection();
|
||||
|
||||
// Carica i dati della lezione
|
||||
try {
|
||||
$stmt = $pdo->prepare("SELECT * FROM lessons WHERE id = ?");
|
||||
$stmt->execute([$lesson_id]);
|
||||
$lesson = $stmt->fetch();
|
||||
|
||||
if (!$lesson) {
|
||||
set_flash_message('error', 'Lezione non trovata');
|
||||
header('Location: lessons.php');
|
||||
exit;
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
set_flash_message('error', 'Errore durante il caricamento della lezione');
|
||||
header('Location: lessons.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 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 {
|
||||
try {
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE lessons SET
|
||||
title = ?,
|
||||
description = ?,
|
||||
type = ?,
|
||||
video_url = ?,
|
||||
video_platform = ?,
|
||||
duration = ?,
|
||||
live_platform = ?,
|
||||
live_url = ?,
|
||||
live_date = ?,
|
||||
level = ?,
|
||||
category = ?,
|
||||
price = ?,
|
||||
is_demo = ?,
|
||||
is_active = ?,
|
||||
updated_at = NOW()
|
||||
WHERE id = ?
|
||||
");
|
||||
|
||||
$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,
|
||||
$lesson_id
|
||||
]);
|
||||
|
||||
set_flash_message('success', 'Lezione aggiornata con successo!');
|
||||
header('Location: lessons.php');
|
||||
exit;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Errore durante l\'aggiornamento della lezione';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Modifica 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;">Modifica 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'] ?? $lesson['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'] ?? $lesson['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'] ?? $lesson['type']) === 'video' ? 'selected' : ''; ?>>
|
||||
Videolezione Registrata
|
||||
</option>
|
||||
<option value="live" <?php echo ($_POST['type'] ?? $lesson['type']) === 'live' ? 'selected' : ''; ?>>
|
||||
Lezione Live
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Campi Video -->
|
||||
<div id="video-fields" style="display: <?php echo ($_POST['type'] ?? $lesson['type']) === '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" <?php echo ($_POST['video_platform'] ?? $lesson['video_platform']) === 'local' ? 'selected' : ''; ?>>File Locale</option>
|
||||
<option value="youtube" <?php echo ($_POST['video_platform'] ?? $lesson['video_platform']) === 'youtube' ? 'selected' : ''; ?>>YouTube</option>
|
||||
<option value="vimeo" <?php echo ($_POST['video_platform'] ?? $lesson['video_platform']) === 'vimeo' ? 'selected' : ''; ?>>Vimeo</option>
|
||||
<option value="s3" <?php echo ($_POST['video_platform'] ?? $lesson['video_platform']) === 's3' ? 'selected' : ''; ?>>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'] ?? $lesson['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'] ?? $lesson['duration'] ?? ''); ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Campi Live -->
|
||||
<div id="live-fields" style="display: <?php echo ($_POST['type'] ?? $lesson['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'] ?? $lesson['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'] ?? $lesson['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
|
||||
$live_date = $_POST['live_date'] ?? $lesson['live_date'] ?? '';
|
||||
// Converti il formato della data per datetime-local (YYYY-MM-DDTHH:MM)
|
||||
if ($live_date && strpos($live_date, ' ') !== false) {
|
||||
$live_date = str_replace(' ', 'T', substr($live_date, 0, 16));
|
||||
}
|
||||
echo htmlspecialchars($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'] ?? $lesson['level']) === 'principiante' ? 'selected' : ''; ?>>
|
||||
Principiante
|
||||
</option>
|
||||
<option value="intermedio" <?php echo ($_POST['level'] ?? $lesson['level']) === 'intermedio' ? 'selected' : ''; ?>>
|
||||
Intermedio
|
||||
</option>
|
||||
<option value="avanzato" <?php echo ($_POST['level'] ?? $lesson['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'] ?? $lesson['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'] ?? $lesson['price']); ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">
|
||||
<input type="checkbox" name="is_demo" value="1"
|
||||
<?php echo ($_POST['is_demo'] ?? $lesson['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 ($_POST['is_active'] ?? $lesson['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">Salva Modifiche</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>
|
||||
Reference in New Issue
Block a user