36439-vm/admin.php
2025-11-28 19:14:48 +00:00

83 lines
3.5 KiB
PHP

<?php
session_start();
// If the user is not logged in, redirect to the login page.
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin | MyTube</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">MyTube Admin</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
<h1>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?>!</h1>
<div class="d-flex justify-content-between align-items-center mb-3">
<h2>Manage Videos</h2>
<a href="video_add.php" class="btn btn-success">Add New Video</a>
</div>
<table class="table table-striped table-dark">
<thead>
<tr>
<th>Title</th>
<th>Creator</th>
<th>Views</th>
<th>Upload Date</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
require_once __DIR__ . '/db/config.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT * FROM videos ORDER BY created_at DESC");
while ($video = $stmt->fetch()) {
echo '<tr>';
echo '<td>' . htmlspecialchars($video['title']) . '</td>';
echo '<td>' . htmlspecialchars($video['creator']) . '</td>';
echo '<td>' . htmlspecialchars($video['views']) . '</td>';
echo '<td>' . date("M j, Y", strtotime($video['upload_date'])) . '</td>';
echo '<td><span class="badge bg-' . ($video['status'] === 'approved' ? 'success' : 'warning') . '">' . htmlspecialchars($video['status']) . '</span></td>';
echo '<td>';
if ($video['status'] === 'pending') {
echo '<a href="video_approve.php?id=' . $video['id'] . '" class="btn btn-sm btn-success">Approve</a> ';
}
echo '<a href="video_edit.php?id=' . $video['id'] . '" class="btn btn-sm btn-primary">Edit</a> ';
echo '<a href="video_delete.php?id=' . $video['id'] . '" class="btn btn-sm btn-danger">Delete</a>';
echo '</td>';
echo '</tr>';
}
} catch (PDOException $e) {
echo '<tr><td colspan="6">Database error: ' . $e->getMessage() . '</td></tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>