IT Dashboard

<?php

// === IT DASHBOARD - WASSERIJ ===
if (!isset($_GET['key']) || $_GET['key'] !== 'wasserij2026') {
    wp_die('<h2>Geen toegang</h2><p>Je hebt het juiste wachtwoord nodig.</p>');
}

global $wpdb;

$wpdb->query("CREATE TABLE IF NOT EXISTS wp_it_meldingen (
    id INT AUTO_INCREMENT PRIMARY KEY,
    datum DATETIME NOT NULL,
    locatie VARCHAR(50) NOT NULL,
    pc VARCHAR(50) NOT NULL,
    probleem TEXT NOT NULL,
    status VARCHAR(20) DEFAULT 'Nieuw'
)");

$meldingen = $wpdb->get_results("SELECT * FROM wp_it_meldingen ORDER BY datum DESC");
?>

<h1>🛠 IT Dashboard - Wasserij Meldingen</h1>

<p><strong>Link:</strong> https://jouwsite.nl/it-dashboard/?key=wasserij2026</p>

<table border="1" cellpadding="10" cellspacing="0" style="width:100%; border-collapse:collapse; font-size:16px;">
    <tr style="background:#333; color:white;">
        <th>Datum & Tijd</th>
        <th>Locatie</th>
        <th>PC / Werkplek</th>
        <th>Probleem</th>
        <th>Status</th>
    </tr>
    
    <?php if (empty($meldingen)): ?>
        <tr><td colspan="5" style="text-align:center; padding:40px;">Nog geen meldingen</td></tr>
    <?php else: ?>
        <?php foreach ($meldingen as $m): ?>
        <tr>
            <td><?= date('d-m-Y H:i', strtotime($m->datum)) ?></td>
            <td><strong><?= esc_html($m->locatie) ?></strong></td>
            <td><?= esc_html($m->pc) ?></td>
            <td><?= nl2br(esc_html($m->probleem)) ?></td>
            <td>
                <select onchange="updateStatus(<?= $m->id ?>, this.value)">
                    <option value="Nieuw" <?= $m->status == 'Nieuw' ? 'selected' : '' ?>>🟡 Nieuw</option>
                    <option value="Bezig" <?= $m->status == 'Bezig' ? 'selected' : '' ?>>🔵 Bezig</option>
                    <option value="Opgelost" <?= $m->status == 'Opgelost' ? 'selected' : '' ?>>🟢 Opgelost</option>
                </select>
            </td>
        </tr>
        <?php endforeach; ?>
    <?php endif; ?>
</table>

<script>
function updateStatus(id, status) {
    fetch('/it-status-update/', {
        method: 'POST',
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        body: 'id=' + id + '&status=' + encodeURIComponent(status)
    }).then(() => location.reload());
}
</script>