137 lines
5.6 KiB
PHP
137 lines
5.6 KiB
PHP
<?php
|
|
require_once '../includes/db.php';
|
|
require_once '../includes/functions.php';
|
|
requireAdmin();
|
|
|
|
$id = (int)($_GET['id'] ?? 0);
|
|
$stmt = $pdo->prepare("SELECT * FROM episodes WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$episode = $stmt->fetch();
|
|
|
|
if (!$episode) {
|
|
header("Location: dashboard.php");
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
$success = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$title = $_POST['title'] ?? '';
|
|
$description = $_POST['description'] ?? '';
|
|
$release_date = $_POST['release_date'] ?? $episode['release_date'];
|
|
|
|
$fileName = $episode['audio_file'];
|
|
$coverImage = $episode['cover_image'];
|
|
|
|
// Check if new cover image is uploaded
|
|
if (isset($_FILES['cover_image']) && $_FILES['cover_image']['error'] === 0) {
|
|
$newCover = uploadImage($_FILES['cover_image']);
|
|
if ($newCover) {
|
|
if ($episode['cover_image']) {
|
|
$oldCoverPath = "../assets/uploads/images/" . $episode['cover_image'];
|
|
if (file_exists($oldCoverPath)) unlink($oldCoverPath);
|
|
}
|
|
$coverImage = $newCover;
|
|
}
|
|
}
|
|
|
|
// Check if new audio file is uploaded
|
|
if (isset($_FILES['audio_file']) && $_FILES['audio_file']['error'] === 0) {
|
|
$newFileName = uploadAudio($_FILES['audio_file']);
|
|
if ($newFileName) {
|
|
// Delete old file
|
|
$oldFilePath = "../assets/uploads/audio/" . $episode['audio_file'];
|
|
if (file_exists($oldFilePath)) unlink($oldFilePath);
|
|
$fileName = $newFileName;
|
|
} else {
|
|
$error = "Error uploading new audio file.";
|
|
}
|
|
}
|
|
|
|
if (!$error) {
|
|
$stmt = $pdo->prepare("UPDATE episodes SET title = ?, description = ?, audio_file = ?, cover_image = ?, release_date = ? WHERE id = ?");
|
|
if ($stmt->execute([$title, $description, $fileName, $coverImage, $release_date, $id])) {
|
|
logActivity($_SESSION['admin_id'], 'EPISODE_UPDATE', "Updated episode: $title (ID: $id)");
|
|
$success = "Episode updated successfully!";
|
|
// Refresh episode data
|
|
$stmt = $pdo->prepare("SELECT * FROM episodes WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$episode = $stmt->fetch();
|
|
} else {
|
|
$error = "Failed to update episode.";
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Edit Episode - <?php echo htmlspecialchars($episode['title']); ?></title>
|
|
<link rel="stylesheet" href="../assets/css/style.css">
|
|
</head>
|
|
<body>
|
|
<nav>
|
|
<a href="<?php echo PROJECT_ROOT_URL; ?>/" class="logo">Admin Dashboard</a>
|
|
<div class="nav-links">
|
|
<a href="dashboard.php">Episodes</a>
|
|
<a href="upload.php">Upload New</a>
|
|
<?php if (hasRole('admin')): ?>
|
|
<a href="settings.php">Site Settings</a>
|
|
<a href="users.php">Manage Users</a>
|
|
<a href="system.php">System</a>
|
|
<?php endif; ?>
|
|
<a href="logout.php">Logout</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="form-container">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
|
|
<h2>Edit Episode</h2>
|
|
<a href="dashboard.php" style="color: var(--text-muted); text-decoration: none;">← Back</a>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<p style="color: #ef4444; margin-bottom: 1rem;"><?php echo $error; ?></p>
|
|
<?php endif; ?>
|
|
<?php if ($success): ?>
|
|
<p style="color: #10b981; margin-bottom: 1rem;"><?php echo $success; ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<label for="title">Episode Title</label>
|
|
<input type="text" id="title" name="title" value="<?php echo htmlspecialchars($episode['title']); ?>" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="description">Description</label>
|
|
<textarea id="description" name="description" rows="6"><?php echo htmlspecialchars($episode['description']); ?></textarea>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="release_date">Release Date</label>
|
|
<input type="date" id="release_date" name="release_date" value="<?php echo $episode['release_date']; ?>" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="cover_image">Cover Image (Optional)</label>
|
|
<?php if ($episode['cover_image']): ?>
|
|
<div style="margin-bottom: 1rem;">
|
|
<img src="../assets/uploads/images/<?php echo $episode['cover_image']; ?>" alt="Cover" style="width: 100px; height: 100px; object-fit: cover; border-radius: 8px;">
|
|
</div>
|
|
<?php endif; ?>
|
|
<input type="file" id="cover_image" name="cover_image" accept="image/*">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="audio_file">Replace Audio File (Optional)</label>
|
|
<input type="file" id="audio_file" name="audio_file" accept="audio/*">
|
|
<p style="font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem;">Current file: <?php echo htmlspecialchars($episode['audio_file']); ?></p>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary" style="width: 100%;">Update Episode</button>
|
|
</form>
|
|
</div>
|
|
|
|
<?php include '../includes/footer.php'; ?>
|
|
</body>
|
|
</html>
|