Sindbad~EG File Manager
<?php
require_once 'config/config.php';
require_login();
$database = new Database();
$conn = $database->getConnection();
$user = new User($conn);
$news = new News($conn);
$category = new Category($conn);
$current_user = $user->getById($_SESSION['user_id']);
// Get dashboard statistics
$total_news = $news->getTotalCount();
$user_news = $news->getTotalCount(null, $_SESSION['user_id']);
$published_news = $news->getTotalCount('published');
$draft_news = $news->getTotalCount('draft');
// Get recent news for the user with location filtering
$news_filters = [
'limit' => 5,
'status' => 'published',
'user_location_type' => $_SESSION['location_type'] ?? '',
'user_location_name' => $_SESSION['location_name'] ?? ''
];
// Admins and superusers can see all news
if (in_array($_SESSION['account_type'] ?? '', ['admin', 'superuser'])) {
unset($news_filters['user_location_type']);
unset($news_filters['user_location_name']);
}
$recent_news = $news->getAll($news_filters);
$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>Dashboard - 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="news/index.php"><i class="fas fa-newspaper"></i> News</a></li>
<li><a href="news/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; ?>
<!-- Welcome Section -->
<div class="card mb-4">
<div class="card-body">
<h1>Welcome, <?php echo htmlspecialchars($current_user['name']); ?>!</h1>
<p style="color: var(--primary-grey);">
<i class="fas fa-map-marker-alt"></i>
<?php echo ucfirst($current_user['location_type']); ?>: <?php echo htmlspecialchars($current_user['location_name']); ?>
<span class="ml-3">
<i class="fas fa-user-tag"></i>
<?php echo ucfirst($current_user['account_type']); ?>
</span>
</p>
</div>
</div>
<!-- Statistics Cards -->
<div class="dashboard-stats">
<div class="stat-card">
<div class="stat-number"><?php echo $user_news; ?></div>
<div class="stat-label">My Articles</div>
</div>
<div class="stat-card">
<div class="stat-number"><?php echo $total_news; ?></div>
<div class="stat-label">Total Articles</div>
</div>
<div class="stat-card">
<div class="stat-number"><?php echo $published_news; ?></div>
<div class="stat-label">Published</div>
</div>
<div class="stat-card">
<div class="stat-number"><?php echo $draft_news; ?></div>
<div class="stat-label">Drafts</div>
</div>
</div>
<!-- Quick Actions -->
<div class="card mb-4">
<div class="card-header">
<h2><i class="fas fa-bolt"></i> Quick Actions</h2>
</div>
<div class="card-body">
<div class="grid grid-3">
<a href="news/create.php" class="btn btn-primary">
<i class="fas fa-plus"></i> Create News Article
</a>
<a href="news/index.php" class="btn btn-secondary">
<i class="fas fa-list"></i> View All News
</a>
<a href="profile.php" class="btn btn-outline">
<i class="fas fa-user-edit"></i> Edit Profile
</a>
</div>
</div>
</div>
<div class="grid grid-2">
<!-- Recent News -->
<div class="card">
<div class="card-header">
<h2><i class="fas fa-newspaper"></i> Recent News</h2>
</div>
<div class="card-body">
<?php if (empty($recent_news)): ?>
<p class="text-center" style="color: var(--primary-grey);">No news articles yet.</p>
<?php else: ?>
<?php foreach ($recent_news as $article): ?>
<div class="news-item" style="border-bottom: 1px solid var(--light-grey); padding: 1rem 0;">
<h4 style="margin-bottom: 0.5rem;">
<a href="news/view.php?id=<?php echo $article['id']; ?>"
style="text-decoration: none; color: var(--dark-grey);">
<?php echo htmlspecialchars($article['title']); ?>
</a>
</h4>
<div style="font-size: 0.875rem; color: var(--primary-grey);">
<i class="fas fa-map-marker-alt"></i> <?php echo htmlspecialchars($article['location']); ?>
<span class="ml-3">
<i class="fas fa-calendar"></i>
<?php echo date('M j, Y', strtotime($article['created_at'])); ?>
</span>
</div>
</div>
<?php endforeach; ?>
<div class="text-center mt-3">
<a href="news/index.php" class="btn btn-outline">View All News</a>
</div>
<?php endif; ?>
</div>
</div>
<!-- My Recent Articles -->
<div class="card">
<div class="card-header">
<h2><i class="fas fa-user-edit"></i> My Recent Articles</h2>
</div>
<div class="card-body">
<?php if (empty($user_recent_news)): ?>
<p class="text-center" style="color: var(--primary-grey);">
You haven't created any articles yet.
</p>
<div class="text-center mt-3">
<a href="news/create.php" class="btn btn-primary">
<i class="fas fa-plus"></i> Create Your First Article
</a>
</div>
<?php else: ?>
<?php foreach ($user_recent_news as $article): ?>
<div class="news-item" style="border-bottom: 1px solid var(--light-grey); padding: 1rem 0;">
<h4 style="margin-bottom: 0.5rem;">
<a href="news/view.php?id=<?php echo $article['id']; ?>"
style="text-decoration: none; color: var(--dark-grey);">
<?php echo htmlspecialchars($article['title']); ?>
</a>
</h4>
<div style="font-size: 0.875rem; color: var(--primary-grey);">
<span class="badge badge-<?php echo $article['status']; ?>">
<?php echo ucfirst($article['status']); ?>
</span>
<span class="ml-3">
<i class="fas fa-eye"></i> <?php echo $article['views']; ?> views
</span>
<span class="ml-3">
<i class="fas fa-calendar"></i>
<?php echo date('M j, Y', strtotime($article['created_at'])); ?>
</span>
</div>
<div class="mt-2">
<a href="news/edit.php?id=<?php echo $article['id']; ?>"
class="btn btn-sm btn-secondary">
<i class="fas fa-edit"></i> Edit
</a>
</div>
</div>
<?php endforeach; ?>
<div class="text-center mt-3">
<a href="news/index.php?user=<?php echo $_SESSION['user_id']; ?>" class="btn btn-outline">
View All My Articles
</a>
</div>
<?php endif; ?>
</div>
</div>
</div>
</main>
<style>
.badge {
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 500;
}
.badge-published {
background: var(--success);
color: white;
}
.badge-draft {
background: var(--warning);
color: white;
}
.badge-archived {
background: var(--primary-grey);
color: white;
}
.btn-sm {
padding: 0.375rem 0.75rem;
font-size: 0.875rem;
}
.ml-3 {
margin-left: 1rem;
}
</style>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists