HEX
Server: Apache
System: Linux sg2plmcpnl492417.prod.sin2.secureserver.net 4.18.0-553.58.1.lve.el8.x86_64 #1 SMP Fri Jul 4 12:07:06 UTC 2025 x86_64
User: nyiet8349bzl (9207396)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/nyiet8349bzl/www/oldwebsite.sbsc.in/wp-content/plugins/Newnoticeboard/admin/dashboard.php
<?php
session_start();
if (!isset($_SESSION['enb_logged_in'])) {
    header('Location: login.php');
    exit;
}

$upload_dir = '../uploads/';

// Handle notice upload
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['category'])) {
    $title = $_POST['title'];
    $description = $_POST['description'];
    $category = $_POST['category']; // 'general' or 'student'
    $file = $_FILES['file'];

    if ($file['error'] === 0) {
        $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
        $basename = uniqid('notice_') . '.' . $ext;
        $target = $upload_dir . $basename;

        if (move_uploaded_file($file['tmp_name'], $target)) {
            $meta = [
                'title' => $title,
                'description' => $description,
                'category' => $category,
                'file' => $basename
            ];
            // Save meta as JSON with same base filename
            file_put_contents($upload_dir . pathinfo($basename, PATHINFO_FILENAME) . '.json', json_encode($meta));
        }
    }
    header('Location: dashboard.php'); // Redirect to avoid resubmission
    exit;
}

// Handle notice deletion
if (isset($_GET['delete'])) {
    $file = basename($_GET['delete']);
    unlink($upload_dir . $file);
    unlink($upload_dir . pathinfo($file, PATHINFO_FILENAME) . '.json');
    header('Location: dashboard.php');
    exit;
}

// Fetch all notices and parse metadata
$files = glob($upload_dir . '*.{pdf,jpg,jpeg,png}', GLOB_BRACE);
$notices = [];
foreach ($files as $file) {
    $filename = basename($file);
    $meta_file = $upload_dir . pathinfo($filename, PATHINFO_FILENAME) . '.json';
    if (file_exists($meta_file)) {
        $meta = json_decode(file_get_contents($meta_file), true);
        if ($meta) {
            $meta['file'] = $filename;
            $notices[] = $meta;
        }
    }
}

// Function to filter notices by category
function filter_notices($notices, $category) {
    return array_filter($notices, fn($n) => $n['category'] === $category);
}

// Optional: get current view from URL (default = general)
$view = $_GET['view'] ?? 'general';

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Notice Admin Dashboard</title>
    <link rel="stylesheet" href="style.css">

    <script>
      // Simple client-side filter for manage notices list
      function filterNotices() {
        const input = document.getElementById('searchInput').value.toLowerCase();
        const listItems = document.querySelectorAll('#manageList li');

        listItems.forEach(li => {
          const text = li.textContent.toLowerCase();
          li.style.display = text.includes(input) ? '' : 'none';
        });
      }
    </script>
</head>
<body>

<div class="sidebar">
    <h2>Notice Panel</h2>
    <a href="dashboard.php?view=general" <?= $view === 'general' ? 'style="background:rgba(255,255,255,0.2);"' : '' ?>>📄 General Notices</a>
    <a href="dashboard.php?view=student" <?= $view === 'student' ? 'style="background:rgba(255,255,255,0.2);"' : '' ?>>🎓 Student Notices</a>
    <a href="dashboard.php?view=manage" <?= $view === 'manage' ? 'style="background:rgba(255,255,255,0.2);"' : '' ?>>🛠 Manage Notices</a>
    <a href="logout.php">🚪 Logout</a>
</div>

<div class="main">

    <?php if ($view === 'general' || $view === 'student'): 
        $category_title = ucfirst($view) . ' Notices';
    ?>
        <div class="card">
            <h2>📤 Upload <?= $category_title ?></h2>
            <form method="post" enctype="multipart/form-data">
                <input type="text" name="title" placeholder="Notice Title" required>
                <textarea name="description" placeholder="Notice Description" required></textarea>
                <input type="file" name="file" required>
                <input type="hidden" name="category" value="<?= $view ?>">
                <button type="submit">Upload</button>
            </form>
        </div>

        <div class="card">
            <h2>📄 <?= $category_title ?> List</h2>
            <ul class="notices">
                <?php
                $filtered = filter_notices($notices, $view);
                if (empty($filtered)) {
                    echo '<li>No notices uploaded yet.</li>';
                } else {
                    foreach ($filtered as $notice): ?>
                        <li>
                            <?= htmlspecialchars($notice['title']) ?>
                            <a href="?delete=<?= urlencode($notice['file']) ?>" onclick="return confirm('Are you sure to delete this notice?')">🗑️ Delete</a>
                        </li>
                    <?php endforeach;
                }
                ?>
            </ul>
        </div>

    <?php elseif ($view === 'manage'): ?>

        <div class="card">
            <h2>🛠 Manage All Notices</h2>
            <input id="searchInput" type="text" onkeyup="filterNotices()" placeholder="Search notices..." style="margin-bottom:15px; padding:8px; width:100%; border-radius:5px; border:1px solid #ccc;">

            <ul id="manageList" class="notices">
                <?php if(empty($notices)): ?>
                    <li>No notices found.</li>
                <?php else: ?>
                    <?php foreach ($notices as $notice): ?>
                        <li>
                            <strong>[<?= ucfirst($notice['category']) ?>]</strong> <?= htmlspecialchars($notice['title']) ?>
                            <a href="?delete=<?= urlencode($notice['file']) ?>" onclick="return confirm('Delete this notice?')">🗑️ Delete</a>
                        </li>
                    <?php endforeach; ?>
                <?php endif; ?>
            </ul>
        </div>

    <?php else: ?>
        <div class="card info">
            <h2>📢 Dashboard Overview</h2>
            <p>Welcome Admin! Use the sidebar menu to upload and manage notices.</p>
        </div>
    <?php endif; ?>

</div>

</body>
</html>