Add multi-announcement management system
- Update inc/announcements.php to support listing, fetching by ID, toggling, and deleting multiple announcements - Upgrade admin/index.php to an announcement management view with data table, status indicators, and create/edit sub-views - Add admin table and action styles to styles.css without using inline style blocks - Update index.php to render all currently active banner and hours announcements dynamically
This commit is contained in:
1 parent
e4cd4f6cfb
commit
bd22299247
4 files changed
+330
-120
No files matched your search
+28
-6
@@ -5,7 +5,7 @@
|
||||
|
||||
require_once __DIR__ . '/db.php';
|
||||
|
||||
function get_active_announcement(): ?array {
|
||||
function get_active_announcements(): array {
|
||||
$pdo = get_db();
|
||||
$today = date('Y-m-d');
|
||||
|
||||
@@ -15,7 +15,6 @@ function get_active_announcement(): ?array {
|
||||
AND (start_date IS NULL OR start_date = '' OR start_date <= :today1)
|
||||
AND (end_date IS NULL OR end_date = '' OR end_date >= :today2)
|
||||
ORDER BY id DESC
|
||||
LIMIT 1
|
||||
";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
@@ -23,15 +22,38 @@ function get_active_announcement(): ?array {
|
||||
':today1' => $today,
|
||||
':today2' => $today
|
||||
]);
|
||||
$result = $stmt->fetch();
|
||||
return $stmt->fetchAll() ?: [];
|
||||
}
|
||||
|
||||
return $result ?: null;
|
||||
function get_active_announcement(): ?array {
|
||||
$all = get_active_announcements();
|
||||
return !empty($all) ? $all[0] : null;
|
||||
}
|
||||
|
||||
function get_all_announcements(): array {
|
||||
$pdo = get_db();
|
||||
$stmt = $pdo->query("SELECT * FROM announcements ORDER BY id DESC");
|
||||
return $stmt->fetchAll();
|
||||
return $stmt->fetchAll() ?: [];
|
||||
}
|
||||
|
||||
function get_announcement_by_id(int $id): ?array {
|
||||
$pdo = get_db();
|
||||
$stmt = $pdo->prepare("SELECT * FROM announcements WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$item = $stmt->fetch();
|
||||
return $item ?: null;
|
||||
}
|
||||
|
||||
function delete_announcement(int $id): bool {
|
||||
$pdo = get_db();
|
||||
$stmt = $pdo->prepare("DELETE FROM announcements WHERE id = ?");
|
||||
return $stmt->execute([$id]);
|
||||
}
|
||||
|
||||
function toggle_announcement_active(int $id): bool {
|
||||
$pdo = get_db();
|
||||
$stmt = $pdo->prepare("UPDATE announcements SET is_active = CASE WHEN is_active = 1 THEN 0 ELSE 1 END, updated_at = CURRENT_TIMESTAMP WHERE id = ?");
|
||||
return $stmt->execute([$id]);
|
||||
}
|
||||
|
||||
function save_announcement(array $data, ?int $id = null): int {
|
||||
@@ -46,7 +68,7 @@ function save_announcement(array $data, ?int $id = null): int {
|
||||
$showBanner = !empty($data['show_banner']) ? 1 : 0;
|
||||
$showInHours = !empty($data['show_in_hours']) ? 1 : 0;
|
||||
|
||||
if ($id) {
|
||||
if ($id && $id > 0) {
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE announcements SET
|
||||
is_active = ?,
|
||||
|
||||
Reference in new issue
Block a user