From 91e4559bd2d30e702aa5bb244998f7b1d10a4222 Mon Sep 17 00:00:00 2001 From: Francesco Picone Date: Tue, 9 Dec 2025 17:15:54 +0100 Subject: [PATCH] fix mail e converted video flag --- admin/lesson_create.php | 11 +++++++-- admin/lesson_edit.php | 8 +++++++ convert_videos.php | 33 ++++++++++++++++++--------- database/add_video_converted_flag.sql | 23 +++++++++++++++++++ database/schema.sql | 1 + includes/functions.php | 9 +++++++- 6 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 database/add_video_converted_flag.sql 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'])) { ID Titolo Lezione Percorso Video - Formato + Formato & Stato Dimensione Azione @@ -228,17 +232,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['convert_video'])) { + + ✓ Convertito + MB -
- - -
+ + ✓ Già convertito + +
+ + +
+ Non disponibile diff --git a/database/add_video_converted_flag.sql b/database/add_video_converted_flag.sql new file mode 100644 index 0000000..d6d8f24 --- /dev/null +++ b/database/add_video_converted_flag.sql @@ -0,0 +1,23 @@ +-- Aggiungi campo per tracciare conversione video +-- Esegui questo script per aggiornare il database + +USE pilatesplatform; + +-- Aggiungi colonna video_converted alla tabella lessons +ALTER TABLE lessons +ADD COLUMN video_converted BOOLEAN DEFAULT FALSE COMMENT 'True se il video è stato convertito in MP4 H.264' +AFTER video_platform; + +-- Aggiorna i video esistenti come non convertiti (NULL = da verificare) +UPDATE lessons +SET video_converted = FALSE +WHERE type = 'video' +AND video_platform = 'local' +AND video_url IS NOT NULL; + +-- Se vuoi marcare i video MP4 esistenti come già convertiti: +-- UPDATE lessons +-- SET video_converted = TRUE +-- WHERE type = 'video' +-- AND video_platform = 'local' +-- AND video_url LIKE '%.mp4'; diff --git a/database/schema.sql b/database/schema.sql index bf12dbc..7cb180a 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -48,6 +48,7 @@ CREATE TABLE IF NOT EXISTS lessons ( -- Informazioni video video_url VARCHAR(500) DEFAULT NULL COMMENT 'URL video (YouTube, Vimeo, S3, o percorso locale)', video_platform VARCHAR(50) DEFAULT 'local' COMMENT 'Piattaforma: local, youtube, vimeo, s3', + video_converted BOOLEAN DEFAULT FALSE COMMENT 'True se il video è stato convertito in MP4 H.264', thumbnail VARCHAR(500) DEFAULT NULL COMMENT 'URL immagine anteprima', duration INT DEFAULT NULL COMMENT 'Durata in minuti', diff --git a/includes/functions.php b/includes/functions.php index 8c01d21..29aada6 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -471,7 +471,14 @@ function send_smtp_email($to, $subject, $message) { if (SMTP_ENCRYPTION === 'tls') { $send("STARTTLS"); $read(); - stream_socket_enable_crypto($smtp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); + + // Usa una versione più compatibile di TLS + $crypto_method = STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT; + if (!stream_socket_enable_crypto($smtp, true, $crypto_method)) { + error_log("SMTP Error: Impossibile avviare crittografia TLS"); + fclose($smtp); + return false; + } $send("EHLO " . SMTP_HOST); $read();