fix mail e converted video flag

This commit is contained in:
Francesco Picone
2025-12-09 17:15:54 +01:00
parent 59c9b1f5be
commit 91e4559bd2
6 changed files with 71 additions and 14 deletions

View File

@@ -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']
]);

View File

@@ -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
]);

View File

@@ -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'])) {
<th>ID</th>
<th>Titolo Lezione</th>
<th>Percorso Video</th>
<th>Formato</th>
<th>Formato & Stato</th>
<th>Dimensione</th>
<th>Azione</th>
</tr>
@@ -228,17 +232,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['convert_video'])) {
<span class="badge" style="background: <?php echo $extension === 'mp4' ? '#2ecc71' : '#e74c3c'; ?>;">
<?php echo strtoupper($extension); ?>
</span>
<?php if ($video['video_converted']): ?>
<span class="badge" style="background: #3498db; margin-left: 5px;">✓ Convertito</span>
<?php endif; ?>
</td>
<td><?php echo $file_size_mb; ?> MB</td>
<td>
<?php if ($exists && $ffmpeg_available): ?>
<form method="POST" style="display: inline;"
onsubmit="return confirm('Vuoi convertire questo video? Il processo potrebbe richiedere alcuni minuti.');">
<input type="hidden" name="lesson_id" value="<?php echo $video['id']; ?>">
<button type="submit" name="convert_video" class="btn btn-primary btn-sm">
🔄 Converti
</button>
</form>
<?php if ($video['video_converted']): ?>
<span style="color: #27ae60; font-size: 0.9em;">✓ Già convertito</span>
<?php else: ?>
<form method="POST" style="display: inline;"
onsubmit="return confirm('Vuoi convertire questo video? Il processo potrebbe richiedere alcuni minuti.');">
<input type="hidden" name="lesson_id" value="<?php echo $video['id']; ?>">
<button type="submit" name="convert_video" class="btn btn-primary btn-sm">
🔄 Converti
</button>
</form>
<?php endif; ?>
<?php else: ?>
<span style="color: #999;">Non disponibile</span>
<?php endif; ?>

View File

@@ -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';

View File

@@ -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',

View File

@@ -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();