<?php include 'includes/header.php'; require_permission('videos_view'); ?>
<div class="row mb-4">
<div class="col">
<h3 class="fs-4 mb-3">إدارة الفيديوهات</h3>
</div>
<div class="col text-start">
<a href="video_form.php" class="btn btn-success"><i class="fas fa-plus"></i> إضافة فيديو جديد</a>
</div>
</div>
<div class="row">
<div class="col">
<div class="glass-card p-3">
<table class="table table-dark table-hover align-middle">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">المعاينة</th>
<th scope="col">العنوان</th>
<th scope="col">النوع</th>
<th scope="col">الحالة</th>
<th scope="col">تاريخ الإضافة</th>
<th scope="col">الإجراءات</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM videos ORDER BY created_at DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$status = $row['active'] ? '<span class="badge bg-success">فعال</span>' : '<span class="badge bg-secondary">غير فعال</span>';
$type = $row['video_type'] == 'url' ? '<span class="badge bg-info">رابط خارجي</span>' : '<span class="badge bg-warning">ملف محلي</span>';
// Generate preview
$preview = '';
if ($row['video_type'] == 'url') {
$video_url = $row['video_url'];
$video_id = '';
if (strpos($video_url, 'youtube.com/watch?v=') !== false) {
parse_str(parse_url($video_url, PHP_URL_QUERY), $params);
$video_id = $params['v'] ?? '';
} elseif (strpos($video_url, 'youtu.be/') !== false) {
$video_id = substr(parse_url($video_url, PHP_URL_PATH), 1);
}
if ($video_id) {
$preview = '<img src="https://img.youtube.com/vi/' . $video_id . '/mqdefault.jpg" width="120" class="rounded">';
} else {
$preview = '<div class="bg-secondary rounded d-flex align-items-center justify-content-center" style="width:120px;height:90px;"><i class="fas fa-video text-white"></i></div>';
}
} else {
if ($row['thumbnail']) {
$preview = '<img src="../uploads/videos/' . htmlspecialchars($row['thumbnail']) . '" width="120" class="rounded">';
} else {
$preview = '<div class="bg-secondary rounded d-flex align-items-center justify-content-center" style="width:120px;height:90px;"><i class="fas fa-video text-white"></i></div>';
}
}
echo "<tr>";
echo "<th scope='row'>" . $row["id"] . "</th>";
echo "<td>" . $preview . "</td>";
echo "<td>" . htmlspecialchars($row["title"]) . "</td>";
echo "<td>" . $type . "</td>";
echo "<td>" . $status . "</td>";
echo "<td>" . date('d/m/Y', strtotime($row["created_at"])) . "</td>";
echo "<td>
<a href='video_form.php?id=" . $row["id"] . "' class='btn btn-primary btn-sm'><i class='fas fa-edit'></i></a>
<a href='video_delete.php?id=" . $row["id"] . "' class='btn btn-danger btn-sm' onclick='return confirm(\"هل أنت متأكد من حذف هذا الفيديو؟\");'><i class='fas fa-trash'></i></a>
</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='7' class='text-center'>لا توجد فيديوهات مضافة حالياً.</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>