Sindbad~EG File Manager

Current Path : /home/copmadinaarea/.trash/news/
Upload File :
Current File : /home/copmadinaarea/.trash/news/delete.php

<?php
require_once '../config/config.php';
require_login();

$database = new Database();
$conn = $database->getConnection();
$news = new News($conn);

$id = intval($_GET['id'] ?? 0);
if (!$id) {
    flash_message('Invalid news article ID', 'error');
    header('Location: index.php');
    exit();
}

$article = $news->getById($id);
if (!$article) {
    flash_message('News article not found', 'error');
    header('Location: index.php');
    exit();
}

// Check permissions
if ($_SESSION['account_type'] === 'user' && $article['user_id'] != $_SESSION['user_id']) {
    flash_message('You do not have permission to delete this article', 'error');
    header('Location: index.php');
    exit();
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if ($news->delete($id)) {
        flash_message('News article deleted successfully', 'success');
    } else {
        flash_message('Failed to delete news article', 'error');
    }
    header('Location: index.php');
    exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Delete News Article - COP News Portal</title>
    <link rel="stylesheet" href="../assets/css/style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body>
    <header class="header">
        <nav class="navbar">
            <a href="../dashboard.php" class="logo">
                <i class="fas fa-church"></i>
                COP News Portal
            </a>
            <ul class="nav-links">
                <li><a href="../dashboard.php"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
                <li><a href="index.php"><i class="fas fa-newspaper"></i> News</a></li>
                <li><a href="create.php"><i class="fas fa-plus"></i> Add News</a></li>
                <?php if ($_SESSION['account_type'] === 'admin' || $_SESSION['account_type'] === 'superuser'): ?>
                    <li><a href="../admin/"><i class="fas fa-cog"></i> Admin</a></li>
                <?php endif; ?>
                <li><a href="../profile.php"><i class="fas fa-user"></i> Profile</a></li>
                <li><a href="../logout.php"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
            </ul>
        </nav>
    </header>

    <main class="container" style="margin-top: 2rem;">
        <div class="card">
            <div class="card-header">
                <h1><i class="fas fa-trash"></i> Delete News Article</h1>
            </div>
            <div class="card-body">
                <div class="alert alert-warning">
                    <i class="fas fa-exclamation-triangle"></i>
                    <strong>Warning:</strong> This action cannot be undone. Are you sure you want to delete this article?
                </div>

                <div class="article-preview" style="background: var(--light-grey); padding: 1.5rem; border-radius: 8px; margin: 1.5rem 0;">
                    <h3><?php echo htmlspecialchars($article['title']); ?></h3>
                    <div style="color: var(--primary-grey); font-size: 0.9rem; margin: 0.5rem 0;">
                        <i class="fas fa-user"></i> <?php echo htmlspecialchars($article['written_by']); ?>
                        <span class="ml-3">
                            <i class="fas fa-map-marker-alt"></i> <?php echo htmlspecialchars($article['location_name'] ?? $article['location'] ?? 'Unknown'); ?>
                        </span>
                        <span class="ml-3">
                            <i class="fas fa-calendar"></i> <?php echo date('M j, Y', strtotime($article['created_at'])); ?>
                        </span>
                    </div>
                    <?php if ($article['description']): ?>
                        <p style="margin-top: 1rem;"><?php echo htmlspecialchars($article['description']); ?></p>
                    <?php endif; ?>
                </div>

                <form method="POST" action="">
                    <div class="flex gap-2">
                        <button type="submit" class="btn btn-danger">
                            <i class="fas fa-trash"></i> Yes, Delete Article
                        </button>
                        <a href="view.php?id=<?php echo $article['id']; ?>" class="btn btn-secondary">
                            <i class="fas fa-times"></i> Cancel
                        </a>
                        <a href="index.php" class="btn btn-outline">
                            <i class="fas fa-arrow-left"></i> Back to News
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </main>

    <style>
        .ml-3 {
            margin-left: 1rem;
        }
    </style>
</body>
</html>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists