diff --git a/admin/lesson_create.php b/admin/lesson_create.php index 0e77250..eb6a14b 100644 --- a/admin/lesson_create.php +++ b/admin/lesson_create.php @@ -75,6 +75,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { unlink($upload_path); $file_name = pathinfo($file_name, PATHINFO_FILENAME) . '.mp4'; $upload_path = $converted_path; + $video_converted = true; } // Se la conversione fallisce, usa comunque il file originale } @@ -83,6 +84,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Imposta il percorso relativo per il database (senza slash iniziale) $video_url = 'uploads/lessons/' . ($is_demo ? 'demo' : 'pay') . '/' . $file_name; + // Se è già MP4, considera già convertito + if ($file_extension === 'mp4') { + $video_converted = true; + } + // Estrai durata automaticamente se non specificata if (empty($duration)) { $duration = get_video_duration($upload_path); @@ -111,9 +117,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { title, description, type, video_url, video_platform, duration, live_platform, live_url, live_date, level, category, price, is_demo, is_active, - created_by, created_at + video_converted, created_by, created_at ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW() + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW() ) "); @@ -132,6 +138,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $price, $is_demo, $is_active, + $video_converted ?? false, $_SESSION['user_id'] ]); diff --git a/admin/lesson_edit.php b/admin/lesson_edit.php index e5b51a6..102e924 100644 --- a/admin/lesson_edit.php +++ b/admin/lesson_edit.php @@ -104,6 +104,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { unlink($upload_path); $file_name = pathinfo($file_name, PATHINFO_FILENAME) . '.mp4'; $upload_path = $converted_path; + $video_converted = true; } // Se la conversione fallisce, usa comunque il file originale } @@ -117,6 +118,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Imposta il nuovo percorso (senza slash iniziale) $video_url = 'uploads/lessons/' . ($is_demo ? 'demo' : 'pay') . '/' . $file_name; + // Se è già MP4, considera già convertito + if ($file_extension === 'mp4') { + $video_converted = true; + } + // Estrai durata automaticamente se non specificata if (empty($duration)) { $duration = get_video_duration($upload_path); @@ -152,6 +158,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { price = ?, is_demo = ?, is_active = ?, + video_converted = ?, updated_at = NOW() WHERE id = ? "); @@ -171,6 +178,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $price, $is_demo, $is_active, + $video_converted ?? $lesson['video_converted'] ?? false, $lesson_id ]); diff --git a/convert_videos.php b/convert_videos.php index 22b5034..7923150 100644 --- a/convert_videos.php +++ b/convert_videos.php @@ -20,7 +20,7 @@ $videos = []; // Trova tutti i video che potrebbero aver bisogno di conversione $pdo = get_db_connection(); $stmt = $pdo->query(" - SELECT id, title, video_url, video_platform + SELECT id, title, video_url, video_platform, video_converted FROM lessons WHERE type = 'video' AND video_platform = 'local' @@ -96,15 +96,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['convert_video'])) { $new_file_path = str_replace('.' . $old_extension, '.' . $new_extension, $input_file); rename($input_file, $new_file_path); - $stmt = $pdo->prepare("UPDATE lessons SET video_url = ? WHERE id = ?"); + $stmt = $pdo->prepare("UPDATE lessons SET video_url = ?, video_converted = TRUE WHERE id = ?"); $stmt->execute([$new_video_url, $lesson_id]); + } else { + // Aggiorna solo il flag video_converted + $stmt = $pdo->prepare("UPDATE lessons SET video_converted = TRUE WHERE id = ?"); + $stmt->execute([$lesson_id]); } $message = "✅ Video convertito con successo! Il file originale è stato salvato come backup."; // Ricarica la lista $stmt = $pdo->query(" - SELECT id, title, video_url, video_platform + SELECT id, title, video_url, video_platform, video_converted FROM lessons WHERE type = 'video' AND video_platform = 'local' @@ -200,7 +204,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['convert_video'])) {