Sindbad~EG File Manager
<?php
require_once '../config/config.php';
require_once '../classes/Editorial.php';
require_once '../classes/User.php';
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (!isset($_SESSION['user_id'])) {
header('Location: ../index.php');
exit();
}
// Check if user has editorial permissions
$allowed_types = ['editor', 'admin', 'superuser'];
if (!in_array($_SESSION['account_type'], $allowed_types)) {
header('Location: ../dashboard.php?error=access_denied');
exit();
}
$database = new Database();
$conn = $database->getConnection();
$editorial = new Editorial($conn);
// Handle AJAX requests
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
header('Content-Type: application/json');
switch ($_POST['action']) {
case 'publish_article':
$news_id = (int)$_POST['news_id'];
$result = $editorial->publishArticle($news_id, $_SESSION['user_id']);
echo json_encode($result);
exit();
case 'bulk_publish':
$article_ids = json_decode($_POST['article_ids'], true);
$results = [];
foreach ($article_ids as $news_id) {
$result = $editorial->publishArticle($news_id, $_SESSION['user_id']);
$results[] = ['id' => $news_id, 'success' => $result['success']];
}
echo json_encode(['success' => true, 'results' => $results]);
exit();
}
}
// Get approved articles
$approved_articles = $editorial->getApprovedArticles($_SESSION['user_id']);
// Pagination
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$per_page = 10;
$total_articles = count($approved_articles);
$total_pages = ceil($total_articles / $per_page);
$offset = ($page - 1) * $per_page;
$paginated_articles = array_slice($approved_articles, $offset, $per_page);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Approved Articles - 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">
<style>
.bulk-actions {
background: #f8f9fa;
padding: 1rem;
border-radius: 6px;
margin-bottom: 1rem;
display: none;
}
.bulk-actions.active {
display: block;
}
.article-checkbox {
margin-right: 0.5rem;
}
.btn-publish {
background: #28a745;
color: white;
}
.btn-publish:hover {
background: #218838;
}
.article-preview {
max-height: 100px;
overflow: hidden;
text-overflow: ellipsis;
}
.status-badge {
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.875rem;
font-weight: bold;
}
.status-approved {
background: #d4edda;
color: #155724;
}
.article-actions {
display: flex;
gap: 0.5rem;
}
</style>
</head>
<body>
<header class="header">
<nav class="navbar">
<a href="../dashboard.php" class="logo">
<i class="fas fa-church"></i> COP News Portal
</a>
<div class="nav-links">
<a href="../dashboard.php"><i class="fas fa-home"></i> Dashboard</a>
<a href="../news/index.php"><i class="fas fa-newspaper"></i> News</a>
<a href="dashboard.php"><i class="fas fa-edit"></i> Editorial</a>
<a href="approved.php" class="active"><i class="fas fa-check-circle"></i> Approved</a>
<a href="../profile.php"><i class="fas fa-user"></i> Profile</a>
<a href="../logout.php"><i class="fas fa-sign-out-alt"></i> Logout</a>
</div>
</nav>
</header>
<main class="container">
<div class="page-header">
<h1><i class="fas fa-check-circle"></i> Approved Articles</h1>
<p>Manage and publish approved articles</p>
</div>
<div class="card">
<div class="card-header">
<h2><i class="fas fa-list"></i> Approved Articles (<?= $total_articles ?>)</h2>
<div class="card-actions">
<button type="button" class="btn btn-secondary" onclick="toggleBulkActions()">
<i class="fas fa-tasks"></i> Bulk Actions
</button>
</div>
</div>
<!-- Bulk Actions Panel -->
<div class="bulk-actions" id="bulkActions">
<h4>Bulk Publishing Actions</h4>
<div style="display: flex; gap: 1rem; align-items: center;">
<button type="button" class="btn btn-publish" onclick="bulkPublish()">
<i class="fas fa-globe"></i> Publish Selected
</button>
<span id="selectedCount">0 articles selected</span>
</div>
</div>
<div class="card-body">
<?php if (empty($paginated_articles)): ?>
<div class="empty-state">
<i class="fas fa-check-circle"></i>
<h3>No Approved Articles</h3>
<p>There are no approved articles ready for publishing at this time.</p>
<a href="dashboard.php" class="btn btn-primary">
<i class="fas fa-edit"></i> Go to Review Queue
</a>
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><input type="checkbox" id="selectAll" onchange="toggleSelectAll()"></th>
<th>Title</th>
<th>Author</th>
<th>Location</th>
<th>Approved</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($paginated_articles as $article): ?>
<tr>
<td>
<input type="checkbox" class="article-checkbox" value="<?= $article['id'] ?>" onchange="updateBulkActions()">
</td>
<td>
<strong><?= htmlspecialchars($article['title']) ?></strong>
<br>
<div class="article-preview">
<small class="text-muted"><?= htmlspecialchars(substr($article['description'], 0, 150)) ?>...</small>
</div>
</td>
<td><?= htmlspecialchars($article['author_name'] ?? 'Unknown') ?></td>
<td><?= htmlspecialchars($article['location_name'] ?? 'N/A') ?></td>
<td><?= $article['approved_at'] ? date('M j, Y g:i A', strtotime($article['approved_at'])) : 'N/A' ?></td>
<td>
<span class="status-badge status-approved">
<i class="fas fa-check"></i> Approved
</span>
</td>
<td>
<div class="article-actions">
<button type="button" class="btn btn-sm btn-primary" onclick="previewArticle(<?= $article['id'] ?>)">
<i class="fas fa-eye"></i> Preview
</button>
<button type="button" class="btn btn-sm btn-publish" onclick="publishArticle(<?= $article['id'] ?>)">
<i class="fas fa-globe"></i> Publish
</button>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!-- Pagination -->
<?php if ($total_pages > 1): ?>
<div class="pagination-wrapper">
<div class="pagination">
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
<a href="?page=<?= $i ?>" class="<?= $i === $page ? 'active' : '' ?>"><?= $i ?></a>
<?php endfor; ?>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</main>
<script>
let selectedArticles = [];
function toggleBulkActions() {
const bulkActions = document.getElementById('bulkActions');
bulkActions.classList.toggle('active');
}
function toggleSelectAll() {
const selectAll = document.getElementById('selectAll');
const checkboxes = document.querySelectorAll('.article-checkbox');
checkboxes.forEach(checkbox => {
checkbox.checked = selectAll.checked;
});
updateBulkActions();
}
function updateBulkActions() {
const checkboxes = document.querySelectorAll('.article-checkbox:checked');
selectedArticles = Array.from(checkboxes).map(cb => cb.value);
const selectAll = document.getElementById('selectAll');
const allCheckboxes = document.querySelectorAll('.article-checkbox');
const selectedCount = document.getElementById('selectedCount');
selectedCount.textContent = `${selectedArticles.length} article${selectedArticles.length !== 1 ? 's' : ''} selected`;
if (selectedArticles.length === 0) {
selectAll.indeterminate = false;
selectAll.checked = false;
} else if (selectedArticles.length === allCheckboxes.length) {
selectAll.indeterminate = false;
selectAll.checked = true;
} else {
selectAll.indeterminate = true;
}
}
function bulkPublish() {
if (selectedArticles.length === 0) {
alert('Please select articles to publish.');
return;
}
if (!confirm(`Are you sure you want to publish ${selectedArticles.length} article(s)?`)) {
return;
}
fetch('approved.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
action: 'bulk_publish',
article_ids: JSON.stringify(selectedArticles)
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
const successCount = data.results.filter(r => r.success).length;
alert(`Successfully published ${successCount} article(s).`);
location.reload();
} else {
alert('Error processing bulk publish. Please try again.');
}
})
.catch(error => {
console.error('Error:', error);
alert('Error processing request.');
});
}
function publishArticle(newsId) {
if (!confirm('Are you sure you want to publish this article?')) {
return;
}
fetch('approved.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
action: 'publish_article',
news_id: newsId
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Article published successfully.');
location.reload();
} else {
alert(data.error || 'Error publishing article.');
}
})
.catch(error => {
console.error('Error:', error);
alert('Error processing request.');
});
}
function previewArticle(newsId) {
// Open article preview in new window/tab
window.open(`../news/view.php?id=${newsId}`, '_blank');
}
</script>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists