fix grafica
This commit is contained in:
@@ -32,6 +32,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$is_demo = isset($_POST['is_demo']) ? 1 : 0;
|
||||
$is_active = isset($_POST['is_active']) ? 1 : 0;
|
||||
|
||||
// Gestione upload file locale
|
||||
if ($type === 'video' && $video_platform === 'local' && isset($_FILES['video_file']) && $_FILES['video_file']['error'] === UPLOAD_ERR_OK) {
|
||||
$upload_dir = $is_demo ? '../uploads/lessons/demo/' : '../uploads/lessons/pay/';
|
||||
|
||||
// Crea nome file sicuro
|
||||
$file_extension = strtolower(pathinfo($_FILES['video_file']['name'], PATHINFO_EXTENSION));
|
||||
$allowed_extensions = ['mp4', 'webm', 'ogg', 'mov'];
|
||||
|
||||
if (!in_array($file_extension, $allowed_extensions)) {
|
||||
$error = 'Formato video non supportato. Usa: mp4, webm, ogg, mov';
|
||||
} else {
|
||||
$file_name = uniqid('video_') . '_' . time() . '.' . $file_extension;
|
||||
$upload_path = $upload_dir . $file_name;
|
||||
|
||||
if (move_uploaded_file($_FILES['video_file']['tmp_name'], $upload_path)) {
|
||||
// Imposta il percorso relativo per il database
|
||||
$video_url = '/uploads/lessons/' . ($is_demo ? 'demo' : 'pay') . '/' . $file_name;
|
||||
} else {
|
||||
$error = 'Errore durante il caricamento del file';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validazione
|
||||
if (empty($title)) {
|
||||
$error = 'Il titolo è obbligatorio';
|
||||
@@ -39,7 +62,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$error = 'La descrizione è obbligatoria';
|
||||
} elseif ($type === 'live' && empty($live_date)) {
|
||||
$error = 'Per le lezioni live, la data è obbligatoria';
|
||||
} else {
|
||||
} elseif ($type === 'video' && $video_platform === 'local' && empty($video_url)) {
|
||||
$error = 'Devi caricare un file video per le lezioni locali';
|
||||
} elseif (!$error) {
|
||||
$pdo = get_db_connection();
|
||||
|
||||
try {
|
||||
@@ -94,7 +119,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<header class="header">
|
||||
<div class="container">
|
||||
<div class="header-content">
|
||||
<h1 class="logo">Pilates Studio - Admin</h1>
|
||||
<?php if (file_exists('../uploads/images/logo.png')): ?>
|
||||
<div class="logo">
|
||||
<img src="../uploads/images/logo.png" alt="Pilates Studio" class="logo-image">
|
||||
<span style="margin-left: 10px; color: var(--primary-color); font-weight: 600;">Admin</span>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<h1 class="logo">Pilates Studio - Admin</h1>
|
||||
<?php endif; ?>
|
||||
<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>
|
||||
@@ -122,7 +154,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card">
|
||||
<form method="POST" action="">
|
||||
<form method="POST" action="" enctype="multipart/form-data">
|
||||
<!-- Informazioni Base -->
|
||||
<h3 style="margin-bottom: 1rem; color: var(--primary-color);">Informazioni Base</h3>
|
||||
|
||||
@@ -156,20 +188,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
||||
<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">File Locale</option>
|
||||
<select id="video_platform" name="video_platform" class="form-control" onchange="toggleVideoInput()">
|
||||
<option value="local">File Locale (Carica dal PC)</option>
|
||||
<option value="youtube">YouTube</option>
|
||||
<option value="vimeo">Vimeo</option>
|
||||
<option value="s3">AWS S3</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="video_url" class="form-label">URL/Percorso Video</label>
|
||||
<!-- Upload file locale -->
|
||||
<div id="local-upload" class="form-group">
|
||||
<label for="video_file" class="form-label">Carica Video *</label>
|
||||
<input type="file" id="video_file" name="video_file" class="form-control"
|
||||
accept="video/mp4,video/webm,video/ogg,video/quicktime">
|
||||
<small class="text-muted">Formati supportati: MP4, WebM, OGG, MOV. Il file verrà salvato automaticamente nella cartella demo/pay.</small>
|
||||
</div>
|
||||
|
||||
<!-- URL esterno -->
|
||||
<div id="external-url" class="form-group" style="display: none;">
|
||||
<label for="video_url" class="form-label">URL 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'] ?? ''); ?>">
|
||||
<small class="text-muted">Lascia vuoto se caricherai il video successivamente</small>
|
||||
<small class="text-muted">Inserisci l'URL del video sulla piattaforma esterna</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -280,6 +321,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
liveFields.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
// Mostra/nascondi campi upload/URL in base alla piattaforma
|
||||
function toggleVideoInput() {
|
||||
const platform = document.getElementById('video_platform').value;
|
||||
const localUpload = document.getElementById('local-upload');
|
||||
const externalUrl = document.getElementById('external-url');
|
||||
const videoFileInput = document.getElementById('video_file');
|
||||
|
||||
if (platform === 'local') {
|
||||
localUpload.style.display = 'block';
|
||||
externalUrl.style.display = 'none';
|
||||
videoFileInput.required = true;
|
||||
} else {
|
||||
localUpload.style.display = 'none';
|
||||
externalUrl.style.display = 'block';
|
||||
videoFileInput.required = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Inizializza lo stato al caricamento
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
toggleVideoInput();
|
||||
});
|
||||
</script>
|
||||
<script src="../assets/js/main.js"></script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user