94 lines
3.9 KiB
PHP
94 lines
3.9 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'layout_header.php';
|
|
|
|
$pdo = db();
|
|
$message = '';
|
|
$type = '';
|
|
|
|
// Handle Delete action
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_channel') {
|
|
$channel_id_to_delete = $_POST['channel_id'] ?? 0;
|
|
if ($channel_id_to_delete > 0) {
|
|
try {
|
|
$delete_stmt = $pdo->prepare("DELETE FROM channels WHERE id = ?");
|
|
$delete_stmt->execute([$channel_id_to_delete]);
|
|
$message = 'Channel deleted successfully. All associated scheduled posts have also been removed.';
|
|
$type = 'success';
|
|
} catch (PDOException $e) {
|
|
$message = 'Error deleting channel: ' . $e->getMessage();
|
|
$type = 'danger';
|
|
}
|
|
}
|
|
}
|
|
|
|
try {
|
|
$stmt = $pdo->query("SELECT id, channel_identifier, created_at FROM channels ORDER BY created_at DESC");
|
|
$channels = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$message = "Error fetching channels: " . $e->getMessage();
|
|
$type = 'danger';
|
|
$channels = [];
|
|
}
|
|
|
|
?>
|
|
|
|
<div class="container-fluid p-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h3 mb-0 text-white">Channels</h1>
|
|
<a href="add_channel.php" class="btn btn-primary">
|
|
<i data-feather="plus" class="me-1"></i>
|
|
Add Channel
|
|
</a>
|
|
</div>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-<?php echo $type; ?> alert-dismissible fade show" role="alert">
|
|
<?php echo htmlspecialchars($message); ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card bg-dark-surface">
|
|
<div class="card-body">
|
|
<?php if (empty($channels)): ?>
|
|
<div class="text-center p-4">
|
|
<p class="text-muted">No channels found. Get started by adding one.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-dark table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">ID</th>
|
|
<th scope="col">Channel ID/URL</th>
|
|
<th scope="col">Added On</th>
|
|
<th scope="col">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($channels as $channel): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($channel['id']); ?></td>
|
|
<td><?php echo htmlspecialchars($channel['channel_identifier']); ?></td>
|
|
<td><?php echo date("F j, Y, g:i a", strtotime($channel['created_at'])); ?></td>
|
|
<td>
|
|
<form method="POST" action="channels.php" onsubmit="return confirm('Are you sure you want to delete this channel? This will also delete all scheduled posts for this channel.');" style="display: inline;">
|
|
<input type="hidden" name="action" value="delete_channel">
|
|
<input type="hidden" name="channel_id" value="<?php echo $channel['id']; ?>">
|
|
<button type="submit" class="btn btn-danger btn-sm">Delete</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
require_once 'layout_footer.php';
|
|
?>
|