287 lines
14 KiB
PHP
287 lines
14 KiB
PHP
<?php
|
|
/**
|
|
* Crea Nuova Lezione
|
|
*
|
|
* Form per creare una nuova videolezione o lezione live
|
|
*/
|
|
|
|
require_once '../includes/config.php';
|
|
require_once '../includes/functions.php';
|
|
|
|
session_start();
|
|
check_session_timeout();
|
|
require_admin();
|
|
|
|
$error = '';
|
|
$success = false;
|
|
|
|
// 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 {
|
|
$pdo = get_db_connection();
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO lessons (
|
|
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
|
|
) VALUES (
|
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW()
|
|
)
|
|
");
|
|
|
|
$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,
|
|
$_SESSION['user_id']
|
|
]);
|
|
|
|
set_flash_message('success', 'Lezione creata con successo!');
|
|
header('Location: lessons.php');
|
|
exit;
|
|
|
|
} catch (PDOException $e) {
|
|
$error = 'Errore durante la creazione della lezione';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Nuova Lezione - Admin</title>
|
|
<link rel="stylesheet" href="../assets/css/style.css">
|
|
</head>
|
|
<body>
|
|
<header class="header">
|
|
<div class="container">
|
|
<div class="header-content">
|
|
<h1 class="logo">Pilates Studio - Admin</h1>
|
|
<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>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="container">
|
|
<div class="dashboard">
|
|
<aside class="sidebar">
|
|
<ul class="sidebar-menu">
|
|
<li><a href="dashboard.php">📊 Dashboard</a></li>
|
|
<li><a href="lessons.php" class="active">🎥 Gestione Lezioni</a></li>
|
|
<li><a href="users.php">👥 Gestione Utenti</a></li>
|
|
<li><a href="purchases.php">💰 Acquisti</a></li>
|
|
</ul>
|
|
</aside>
|
|
|
|
<main class="main-content">
|
|
<h2 class="section-title" style="text-align: left;">Crea Nuova Lezione</h2>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-error"><?php echo htmlspecialchars($error); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card">
|
|
<form method="POST" action="">
|
|
<!-- Informazioni Base -->
|
|
<h3 style="margin-bottom: 1rem; color: var(--primary-color);">Informazioni Base</h3>
|
|
|
|
<div class="form-group">
|
|
<label for="title" class="form-label">Titolo *</label>
|
|
<input type="text" id="title" name="title" class="form-control" required
|
|
value="<?php echo htmlspecialchars($_POST['title'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="description" class="form-label">Descrizione *</label>
|
|
<textarea id="description" name="description" class="form-control" required
|
|
rows="4"><?php echo htmlspecialchars($_POST['description'] ?? ''); ?></textarea>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="type" class="form-label">Tipo Lezione *</label>
|
|
<select id="type" name="type" class="form-control" required onchange="toggleTypeFields()">
|
|
<option value="video" <?php echo ($_POST['type'] ?? 'video') === 'video' ? 'selected' : ''; ?>>
|
|
Videolezione Registrata
|
|
</option>
|
|
<option value="live" <?php echo ($_POST['type'] ?? '') === 'live' ? 'selected' : ''; ?>>
|
|
Lezione Live
|
|
</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Campi Video -->
|
|
<div id="video-fields" style="display: <?php echo ($_POST['type'] ?? 'video') === 'video' ? 'block' : 'none'; ?>;">
|
|
<h3 style="margin: 2rem 0 1rem; color: var(--primary-color);">Dettagli Video</h3>
|
|
|
|
<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>
|
|
<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>
|
|
<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>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="duration" class="form-label">Durata (minuti)</label>
|
|
<input type="number" id="duration" name="duration" class="form-control"
|
|
min="1" value="<?php echo htmlspecialchars($_POST['duration'] ?? ''); ?>">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Campi Live -->
|
|
<div id="live-fields" style="display: <?php echo ($_POST['type'] ?? '') === 'live' ? 'block' : 'none'; ?>;">
|
|
<h3 style="margin: 2rem 0 1rem; color: var(--primary-color);">Dettagli Lezione Live</h3>
|
|
|
|
<div class="form-group">
|
|
<label for="live_platform" class="form-label">Piattaforma Live</label>
|
|
<input type="text" id="live_platform" name="live_platform" class="form-control"
|
|
placeholder="es: Zoom, Google Meet, Teams..."
|
|
value="<?php echo htmlspecialchars($_POST['live_platform'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="live_url" class="form-label">Link Lezione Live</label>
|
|
<input type="text" id="live_url" name="live_url" class="form-control"
|
|
placeholder="es: https://zoom.us/j/..."
|
|
value="<?php echo htmlspecialchars($_POST['live_url'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="live_date" class="form-label">Data e Ora Lezione *</label>
|
|
<input type="datetime-local" id="live_date" name="live_date" class="form-control"
|
|
value="<?php echo htmlspecialchars($_POST['live_date'] ?? ''); ?>">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Classificazione -->
|
|
<h3 style="margin: 2rem 0 1rem; color: var(--primary-color);">Classificazione</h3>
|
|
|
|
<div class="form-group">
|
|
<label for="level" class="form-label">Livello *</label>
|
|
<select id="level" name="level" class="form-control" required>
|
|
<option value="principiante" <?php echo ($_POST['level'] ?? 'principiante') === 'principiante' ? 'selected' : ''; ?>>
|
|
Principiante
|
|
</option>
|
|
<option value="intermedio" <?php echo ($_POST['level'] ?? '') === 'intermedio' ? 'selected' : ''; ?>>
|
|
Intermedio
|
|
</option>
|
|
<option value="avanzato" <?php echo ($_POST['level'] ?? '') === 'avanzato' ? 'selected' : ''; ?>>
|
|
Avanzato
|
|
</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="category" class="form-label">Categoria</label>
|
|
<input type="text" id="category" name="category" class="form-control"
|
|
placeholder="es: Mat Work, Reformer, Stretching..."
|
|
value="<?php echo htmlspecialchars($_POST['category'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<!-- Prezzo e Disponibilità -->
|
|
<h3 style="margin: 2rem 0 1rem; color: var(--primary-color);">Prezzo e Disponibilità</h3>
|
|
|
|
<div class="form-group">
|
|
<label for="price" class="form-label">Prezzo (€) *</label>
|
|
<input type="number" id="price" name="price" class="form-control"
|
|
min="0" step="0.01" required
|
|
value="<?php echo htmlspecialchars($_POST['price'] ?? '0'); ?>">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">
|
|
<input type="checkbox" name="is_demo" value="1"
|
|
<?php echo isset($_POST['is_demo']) ? 'checked' : ''; ?>>
|
|
Lezione Demo (gratuita per tutti)
|
|
</label>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">
|
|
<input type="checkbox" name="is_active" value="1"
|
|
<?php echo !isset($_POST['is_active']) || $_POST['is_active'] ? 'checked' : ''; ?>>
|
|
Lezione attiva (visibile agli utenti)
|
|
</label>
|
|
</div>
|
|
|
|
<div class="d-flex gap-1 mt-3">
|
|
<button type="submit" class="btn btn-primary">Crea Lezione</button>
|
|
<a href="lessons.php" class="btn btn-outline">Annulla</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Mostra/nascondi campi in base al tipo di lezione
|
|
function toggleTypeFields() {
|
|
const type = document.getElementById('type').value;
|
|
const videoFields = document.getElementById('video-fields');
|
|
const liveFields = document.getElementById('live-fields');
|
|
|
|
if (type === 'video') {
|
|
videoFields.style.display = 'block';
|
|
liveFields.style.display = 'none';
|
|
} else {
|
|
videoFields.style.display = 'none';
|
|
liveFields.style.display = 'block';
|
|
}
|
|
}
|
|
</script>
|
|
<script src="../assets/js/main.js"></script>
|
|
</body>
|
|
</html>
|