Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/newsfeed/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/newsfeed/dashboard.php

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

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

// Get current user info
$user_stmt = $conn->prepare("SELECT u.*, l.name as location_name FROM users u LEFT JOIN locations l ON u.location_id = l.id WHERE u.id = ?");
$user_stmt->execute([$_SESSION['user_id']]);
$current_user = $user_stmt->fetch(PDO::FETCH_ASSOC);

// Get recent news (last 5 articles)
$news_stmt = $conn->prepare("SELECT n.*, l.name as location_name FROM news n LEFT JOIN locations l ON n.location_id = l.id WHERE n.status = 'published' ORDER BY n.created_at DESC LIMIT 5");
$news_stmt->execute();
$recent_news = $news_stmt->fetchAll(PDO::FETCH_ASSOC);

// Get user's draft articles
$draft_stmt = $conn->prepare("SELECT COUNT(*) as count FROM news WHERE user_id = ? AND status = 'draft'");
$draft_stmt->execute([$_SESSION['user_id']]);
$draft_count = $draft_stmt->fetch(PDO::FETCH_ASSOC)['count'];

// Get user's published articles
$published_stmt = $conn->prepare("SELECT COUNT(*) as count FROM news WHERE user_id = ? AND status = 'published'");
$published_stmt->execute([$_SESSION['user_id']]);
$published_count = $published_stmt->fetch(PDO::FETCH_ASSOC)['count'];

$flash = get_flash_message();

// Set page variables for header
$page_title = 'Dashboard';
$home_path = 'dashboard.php';
$dashboard_path = 'dashboard.php';
$news_path = 'news/index.php';
$create_path = 'news/create.php';
$editorial_path = 'editorial/dashboard.php';
$admin_path = 'admin/';
$profile_path = 'profile.php';
$logout_path = 'logout.php';

include 'includes/header.php';
?>

    <main class="container" style="margin-top: 2rem;">
        <?php if ($flash): ?>
            <div class="alert alert-<?php echo $flash['type']; ?> mb-6">
                <i class="fas fa-info-circle"></i> <?php echo $flash['message']; ?>
            </div>
        <?php endif; ?>

        <!-- Welcome Section -->
        <div class="card mb-6">
            <div class="card-body">
                <h1 class="text-3xl font-bold text-cop-dark mb-4">Welcome, <?php echo htmlspecialchars($current_user['name']); ?>!</h1>
                <div class="flex flex-col sm:flex-row gap-4 text-gray-600">
                    <div class="flex items-center">
                        <i class="fas fa-map-marker-alt mr-2 text-cop-blue"></i>
                        <span><?php echo htmlspecialchars($current_user['location_name'] ?? 'No location assigned'); ?></span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-user-tag mr-2 text-cop-blue"></i>
                        <span><?php echo ucfirst($current_user['account_type']); ?> Account</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Statistics Cards -->
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
            <div class="card text-center">
                <div class="card-body">
                    <i class="fas fa-file-alt text-4xl text-cop-blue mb-4"></i>
                    <h3 class="text-2xl font-bold text-cop-dark"><?php echo $draft_count; ?></h3>
                    <p class="text-gray-600">Draft Articles</p>
                </div>
            </div>
            <div class="card text-center">
                <div class="card-body">
                    <i class="fas fa-globe text-4xl text-green-600 mb-4"></i>
                    <h3 class="text-2xl font-bold text-cop-dark"><?php echo $published_count; ?></h3>
                    <p class="text-gray-600">Published Articles</p>
                </div>
            </div>
            <div class="card text-center">
                <div class="card-body">
                    <i class="fas fa-clock text-4xl text-cop-yellow mb-4"></i>
                    <h3 class="text-2xl font-bold text-cop-dark"><?php echo date('H:i'); ?></h3>
                    <p class="text-gray-600">Current Time</p>
                </div>
            </div>
        </div>

        <!-- Quick Actions -->
        <div class="card mb-6">
            <div class="card-header">
                <h2 class="text-xl font-semibold text-cop-dark flex items-center">
                    <i class="fas fa-bolt mr-2"></i> Quick Actions
                </h2>
            </div>
            <div class="card-body">
                <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
                    <a href="news/create.php" class="btn btn-primary">
                        <i class="fas fa-plus mr-2"></i> Create News Article
                    </a>
                    <a href="news/index.php" class="btn btn-secondary">
                        <i class="fas fa-list mr-2"></i> View All News
                    </a>
                    <?php if (in_array($_SESSION['account_type'] ?? '', ['editor', 'admin', 'superuser'])): ?>
                    <a href="editorial/dashboard.php" class="btn btn-success">
                        <i class="fas fa-edit mr-2"></i> Editorial Dashboard
                    </a>
                    <?php endif; ?>
                    <a href="profile.php" class="btn btn-outline">
                        <i class="fas fa-user-edit mr-2"></i> Edit Profile
                    </a>
                </div>
            </div>
        </div>

        <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
            <!-- Recent News -->
            <div class="card">
                <div class="card-header">
                    <h2 class="text-xl font-semibold text-cop-dark flex items-center">
                        <i class="fas fa-newspaper mr-2"></i> Recent News
                    </h2>
                </div>
                <div class="card-body">
                    <?php if (empty($recent_news)): ?>
                        <p class="text-center text-gray-600">No news articles yet.</p>
                    <?php else: ?>
                        <div class="space-y-4">
                            <?php foreach ($recent_news as $article): ?>
                                <div class="border-b border-gray-200 pb-4 last:border-b-0">
                                    <h4 class="mb-2">
                                        <a href="news/view.php?id=<?php echo $article['id']; ?>" 
                                           class="text-cop-dark hover:text-cop-blue transition-colors font-medium">
                                            <?php echo htmlspecialchars($article['title']); ?>
                                        </a>
                                    </h4>
                                    <div class="flex flex-wrap gap-4 text-sm text-gray-600 mb-2">
                                        <span class="flex items-center">
                                            <i class="fas fa-map-marker-alt mr-1"></i>
                                            <?php echo htmlspecialchars($article['location_name']); ?>
                                        </span>
                                        <span class="flex items-center">
                                            <i class="fas fa-calendar mr-1"></i>
                                            <?php echo date('M j, Y', strtotime($article['created_at'])); ?>
                                        </span>
                                    </div>
                                    <p class="text-gray-600 text-sm">
                                        <?php echo htmlspecialchars(substr($article['description'], 0, 100)); ?>...
                                    </p>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>

            <!-- User Activity -->
            <div class="card">
                <div class="card-header">
                    <h2 class="text-xl font-semibold text-cop-dark flex items-center">
                        <i class="fas fa-chart-line mr-2"></i> Your Activity
                    </h2>
                </div>
                <div class="card-body">
                    <div class="space-y-4">
                        <div class="border-b border-gray-200 pb-4">
                            <h4 class="font-medium text-cop-dark mb-1">Articles Created</h4>
                            <p class="text-gray-600">You have created <?php echo $draft_count + $published_count; ?> articles in total.</p>
                        </div>
                        <div class="border-b border-gray-200 pb-4">
                            <h4 class="font-medium text-cop-dark mb-1">Account Type</h4>
                            <p class="text-gray-600"><?php echo ucfirst($current_user['account_type']); ?> privileges</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-cop-dark mb-1">Last Login</h4>
                            <p class="text-gray-600">Today at <?php echo date('g:i A'); ?></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

<?php include 'includes/footer.php'; ?>

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