136 lines
6.4 KiB
PHP
136 lines
6.4 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
|
|
header('Location: admin_login.php');
|
|
exit;
|
|
}
|
|
|
|
$content_file = 'premium_content.json';
|
|
$content = json_decode(file_get_contents($content_file), true);
|
|
|
|
// Handle Add/Edit/Delete
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Delete
|
|
if (isset($_POST['delete'])) {
|
|
$id_to_delete = intval($_POST['id']);
|
|
$content = array_filter($content, function($item) use ($id_to_delete) {
|
|
return $item['id'] !== $id_to_delete;
|
|
});
|
|
}
|
|
// Add or Edit
|
|
else {
|
|
$id = intval($_POST['id']);
|
|
$new_item = [
|
|
'id' => $id === 0 ? time() : $id, // new id for new items
|
|
'title' => $_POST['title'],
|
|
'category' => $_POST['category'],
|
|
'poster_url' => $_POST['poster_url'],
|
|
'stream_url' => $_POST['stream_url'],
|
|
];
|
|
|
|
if ($id === 0) { // Add
|
|
$content[] = $new_item;
|
|
} else { // Edit
|
|
foreach ($content as &$item) {
|
|
if ($item['id'] === $id) {
|
|
$item = $new_item;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
file_put_contents($content_file, json_encode(array_values($content), JSON_PRETTY_PRINT));
|
|
header('Location: admin_content.php');
|
|
exit;
|
|
}
|
|
|
|
$edit_item = null;
|
|
if (isset($_GET['edit'])) {
|
|
$id_to_edit = intval($_GET['edit']);
|
|
foreach ($content as $item) {
|
|
if ($item['id'] === $id_to_edit) {
|
|
$edit_item = $item;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Premium Content - Admin Panel</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
<style>
|
|
.sidebar { width: 280px; position: fixed; top: 0; left: 0; height: 100vh; background-color: #1E1E1E; padding-top: 20px; }
|
|
.main-content { margin-left: 280px; padding: 20px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="sidebar d-flex flex-column p-3">
|
|
<h3 class="text-white text-center mb-4">Admin Panel</h3>
|
|
<ul class="nav nav-pills flex-column mb-auto">
|
|
<li class="nav-item"><a href="admin.php" class="nav-link text-white"><i class="bi bi-speedometer2 me-2"></i>Dashboard</a></li>
|
|
<li><a href="admin_users.php" class="nav-link text-white"><i class="bi bi-people-fill me-2"></i>Users</a></li>
|
|
<li><a href="admin_content.php" class="nav-link active text-white"><i class="bi bi-tv-fill me-2"></i>Premium Content</a></li>
|
|
<li><a href="admin_settings.php" class="nav-link text-white"><i class="bi bi-gear-fill me-2"></i>App Settings</a></li>
|
|
</ul>
|
|
<hr>
|
|
<a href="admin.php?action=logout" class="d-flex align-items-center text-white text-decoration-none"><i class="bi bi-box-arrow-right me-2"></i><strong>Sign out</strong></a>
|
|
</div>
|
|
|
|
<main class="main-content">
|
|
<h1 class="mb-4">Premium Content</h1>
|
|
|
|
<div class="card form-card mb-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><?php echo $edit_item ? 'Edit' : 'Add'; ?> Content</h5>
|
|
<form method="POST" action="admin_content.php">
|
|
<input type="hidden" name="id" value="<?php echo $edit_item['id'] ?? 0; ?>">
|
|
<div class="row mb-3">
|
|
<div class="col-md-6"><label class="form-label">Title</label><input type="text" class="form-control" name="title" value="<?php echo htmlspecialchars($edit_item['title'] ?? ''); ?>" required></div>
|
|
<div class="col-md-6"><label class="form-label">Category</label><input type="text" class="form-control" name="category" value="<?php echo htmlspecialchars($edit_item['category'] ?? ''); ?>" required></div>
|
|
</div>
|
|
<div class="mb-3"><label class="form-label">Poster URL</label><input type="url" class="form-control" name="poster_url" value="<?php echo htmlspecialchars($edit_item['poster_url'] ?? ''); ?>" required></div>
|
|
<div class="mb-3"><label class="form-label">Stream URL</label><input type="url" class="form-control" name="stream_url" value="<?php echo htmlspecialchars($edit_item['stream_url'] ?? ''); ?>" required></div>
|
|
<button type="submit" class="btn btn-primary"><?php echo $edit_item ? 'Save Changes' : 'Add Content'; ?></button>
|
|
<?php if ($edit_item): ?><a href="admin_content.php" class="btn btn-secondary">Cancel Edit</a><?php endif; ?>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card form-card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Content Library</h5>
|
|
<div class="table-responsive">
|
|
<table class="table table-dark table-striped">
|
|
<thead><tr><th>Title</th><th>Category</th><th>Actions</th></tr></thead>
|
|
<tbody>
|
|
<?php foreach ($content as $item): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($item['title']); ?></td>
|
|
<td><?php echo htmlspecialchars($item['category']); ?></td>
|
|
<td>
|
|
<a href="?edit=<?php echo $item['id']; ?>" class="btn btn-sm btn-primary"><i class="bi bi-pencil-fill"></i></a>
|
|
<form method="POST" action="admin_content.php" onsubmit="return confirm('Are you sure you want to delete this item?');" style="display: inline-block;">
|
|
<input type="hidden" name="id" value="<?php echo $item['id']; ?>">
|
|
<button type="submit" name="delete" class="btn btn-sm btn-danger"><i class="bi bi-trash-fill"></i></button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
</body>
|
|
</html>
|