diff --git a/admin/lesson_edit.php b/admin/lesson_edit.php new file mode 100644 index 0000000..e09a2ea --- /dev/null +++ b/admin/lesson_edit.php @@ -0,0 +1,329 @@ +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'; + } + } +} +?> + + +
+ + +