Sindbad~EG File Manager

Current Path : /home/copmadinaarea/.trash/news/
Upload File :
Current File : /home/copmadinaarea/.trash/news/view.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');
    redirect('news/index.php');
}

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

// Check permissions - users can only view their own drafts or published articles
if ($_SESSION['account_type'] === 'user') {
    if ($article['status'] !== 'published' && $article['user_id'] != $_SESSION['user_id']) {
        flash_message('You do not have permission to view this article', 'error');
        redirect('news/index.php');
    }
}

// Increment view count
$news->incrementViews($id);
$article['views']++;

$flash = get_flash_message();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo htmlspecialchars($article['title']); ?> - 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;">
        <?php if ($flash): ?>
            <div class="alert alert-<?php echo $flash['type']; ?>">
                <i class="fas fa-info-circle"></i> <?php echo $flash['message']; ?>
            </div>
        <?php endif; ?>

        <div class="card">
            <div class="card-body">
                <!-- Article Header -->
                <div class="article-header mb-4">
                    <div class="flex justify-between items-start mb-3">
                        <h1 class="article-title"><?php echo htmlspecialchars($article['title']); ?></h1>
                        <span class="badge badge-<?php echo $article['status']; ?>">
                            <?php echo ucfirst($article['status']); ?>
                        </span>
                    </div>
                    
                    <div class="article-meta mb-3">
                        <div class="meta-row">
                            <span><i class="fas fa-user"></i> <?php echo htmlspecialchars($article['written_by']); ?></span>
                            <span><i class="fas fa-map-marker-alt"></i> <?php echo htmlspecialchars($article['location']); ?></span>
                            <?php if ($article['category_name']): ?>
                                <span><i class="fas fa-tag"></i> <?php echo htmlspecialchars($article['category_name']); ?></span>
                            <?php endif; ?>
                        </div>
                        <div class="meta-row">
                            <span><i class="fas fa-calendar"></i> <?php echo date('F j, Y \a\t g:i A', strtotime($article['created_at'])); ?></span>
                            <span><i class="fas fa-eye"></i> <?php echo $article['views']; ?> views</span>
                            <?php if ($article['updated_at'] !== $article['created_at']): ?>
                                <span><i class="fas fa-edit"></i> Updated <?php echo date('M j, Y', strtotime($article['updated_at'])); ?></span>
                            <?php endif; ?>
                        </div>
                    </div>

                    <?php if ($article['description']): ?>
                        <div class="article-description">
                            <p><strong><?php echo htmlspecialchars($article['description']); ?></strong></p>
                        </div>
                    <?php endif; ?>
                </div>

                <!-- Article Content -->
                <div class="article-content">
                    <?php echo $article['content']; ?>
                </div>

                <!-- Article Actions -->
                <div class="article-actions mt-4 pt-4" style="border-top: 1px solid var(--light-grey);">
                    <div class="flex gap-2">
                        <a href="index.php" class="btn btn-secondary">
                            <i class="fas fa-arrow-left"></i> Back to News
                        </a>
                        
                        <?php if ($article['user_id'] == $_SESSION['user_id'] || $_SESSION['account_type'] !== 'user'): ?>
                            <a href="edit.php?id=<?php echo $article['id']; ?>" class="btn btn-primary">
                                <i class="fas fa-edit"></i> Edit Article
                            </a>
                            <a href="delete.php?id=<?php echo $article['id']; ?>" 
                               class="btn btn-danger"
                               onclick="return confirm('Are you sure you want to delete this article?')">
                                <i class="fas fa-trash"></i> Delete Article
                            </a>
                        <?php endif; ?>
                        
                        <button onclick="printArticle()" class="btn btn-outline">
                            <i class="fas fa-print"></i> Print
                        </button>
                        
                        <button onclick="shareArticle()" class="btn btn-outline">
                            <i class="fas fa-share"></i> Share
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Author Info -->
        <div class="card mt-4">
            <div class="card-header">
                <h3><i class="fas fa-user"></i> About the Author</h3>
            </div>
            <div class="card-body">
                <div class="author-info">
                    <h4><?php echo htmlspecialchars($article['author_name']); ?></h4>
                    <p style="color: var(--primary-grey);">
                        <i class="fas fa-map-marker-alt"></i> 
                        <?php echo htmlspecialchars($article['location']); ?>
                    </p>
                </div>
            </div>
        </div>
    </main>

    <script>
        function printArticle() {
            window.print();
        }

        function shareArticle() {
            if (navigator.share) {
                navigator.share({
                    title: '<?php echo addslashes($article['title']); ?>',
                    text: '<?php echo addslashes($article['description'] ?? ''); ?>',
                    url: window.location.href
                });
            } else {
                // Fallback - copy URL to clipboard
                navigator.clipboard.writeText(window.location.href).then(function() {
                    alert('Article URL copied to clipboard!');
                });
            }
        }
    </script>

    <style>
        .article-title {
            font-size: 2.5rem;
            font-weight: 700;
            line-height: 1.2;
            color: var(--dark-grey);
            margin-bottom: 0;
        }

        .article-meta {
            color: var(--primary-grey);
            font-size: 0.9rem;
        }

        .meta-row {
            display: flex;
            flex-wrap: wrap;
            gap: 1.5rem;
            margin-bottom: 0.5rem;
        }

        .meta-row span {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .article-description {
            background: var(--light-blue);
            padding: 1.5rem;
            border-radius: 8px;
            margin: 1.5rem 0;
        }

        .article-description p {
            margin: 0;
            font-size: 1.1rem;
            color: var(--secondary-blue);
        }

        .article-content {
            font-size: 1.1rem;
            line-height: 1.8;
            color: var(--dark-grey);
        }

        .article-content h1,
        .article-content h2,
        .article-content h3,
        .article-content h4,
        .article-content h5,
        .article-content h6 {
            margin-top: 2rem;
            margin-bottom: 1rem;
            color: var(--dark-grey);
        }

        .article-content p {
            margin-bottom: 1.5rem;
        }

        .article-content ul,
        .article-content ol {
            margin-bottom: 1.5rem;
            padding-left: 2rem;
        }

        .article-content li {
            margin-bottom: 0.5rem;
        }

        .article-content blockquote {
            border-left: 4px solid var(--primary-blue);
            padding-left: 1.5rem;
            margin: 2rem 0;
            font-style: italic;
            color: var(--primary-grey);
        }

        .author-info h4 {
            margin-bottom: 0.5rem;
            color: var(--dark-grey);
        }

        @media print {
            .header,
            .article-actions {
                display: none;
            }
            
            .container {
                margin-top: 0;
            }
            
            .card {
                box-shadow: none;
                border: none;
            }
        }

        @media (max-width: 768px) {
            .article-title {
                font-size: 2rem;
            }
            
            .meta-row {
                flex-direction: column;
                gap: 0.5rem;
            }
            
            .article-actions .flex {
                flex-direction: column;
            }
        }
    </style>
</body>
</html>

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