Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
111 lines
4.2 KiB
PHP
111 lines
4.2 KiB
PHP
<?php
|
||
require_once __DIR__ . '/../lib/auth.php';
|
||
require_once __DIR__ . '/../lib/layout.php';
|
||
require_login();
|
||
|
||
$user_id = current_user()['id'];
|
||
$admin = is_admin();
|
||
|
||
if ($admin) {
|
||
$docs = db()->query(
|
||
'SELECT d.*, u.name AS user_name
|
||
FROM dokumente d
|
||
JOIN users u ON u.id = d.user_id
|
||
ORDER BY d.created_at DESC'
|
||
)->fetchAll();
|
||
} else {
|
||
$stmt = db()->prepare('SELECT * FROM dokumente WHERE user_id = ? ORDER BY created_at DESC');
|
||
$stmt->execute([$user_id]);
|
||
$docs = $stmt->fetchAll();
|
||
}
|
||
|
||
layout_start('OMSORG – Dokumentenarchiv', 'dokumentenarchiv');
|
||
?>
|
||
<h1 class="main-title">🗂 Dokumenten­archiv</h1>
|
||
<p class="main-sub">Eigene Nachweise und Dokumente hochladen und verwalten.</p>
|
||
|
||
<?php if (isset($_GET['ok'])): ?>
|
||
<div class="success" style="margin-top:16px">Dokument erfolgreich hochgeladen.</div>
|
||
<?php elseif (isset($_GET['deleted'])): ?>
|
||
<div class="success" style="margin-top:16px">Dokument wurde gelöscht.</div>
|
||
<?php elseif (isset($_GET['error'])): ?>
|
||
<div class="error" style="margin-top:16px"><?= e(urldecode($_GET['error'])) ?></div>
|
||
<?php endif; ?>
|
||
|
||
<div class="page-split" style="margin-top:24px">
|
||
|
||
<div class="page-split-list">
|
||
<h2><?= $admin ? 'Alle Dokumente' : 'Meine Dokumente' ?></h2>
|
||
<?php if (empty($docs)): ?>
|
||
<p style="color:var(--muted)">Noch keine Dokumente vorhanden.</p>
|
||
<?php else: ?>
|
||
<table class="requests-table">
|
||
<thead>
|
||
<tr>
|
||
<?php if ($admin): ?><th>Mitarbeiter</th><?php endif; ?>
|
||
<th>Kategorie</th>
|
||
<th>Beschreibung</th>
|
||
<th>Datei</th>
|
||
<th>Hochgeladen</th>
|
||
<th></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($docs as $d): ?>
|
||
<tr>
|
||
<?php if ($admin): ?>
|
||
<td style="font-weight:800"><?= e($d['user_name']) ?></td>
|
||
<?php endif; ?>
|
||
<td><?= e($d['kategorie']) ?></td>
|
||
<td style="color:var(--muted);font-size:.9rem"><?= $d['beschreibung'] !== '' ? e($d['beschreibung']) : '–' ?></td>
|
||
<td>
|
||
<a href="dokument-serve.php?id=<?= (int)$d['id'] ?>" class="btn download-btn" style="padding:6px 14px;font-size:.85rem">↓ <?= e($d['original_name']) ?></a>
|
||
</td>
|
||
<td style="color:var(--muted);font-size:.9rem"><?= e(date('d.m.Y', strtotime($d['created_at']))) ?></td>
|
||
<td>
|
||
<form method="post" action="../actions/delete-dokument.php" onsubmit="return confirm('Dokument wirklich löschen?')">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="id" value="<?= (int)$d['id'] ?>">
|
||
<button type="submit" class="btn" style="background:rgba(220,50,50,.25);padding:6px 14px;font-size:.85rem">Löschen</button>
|
||
</form>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="page-split-form">
|
||
<div class="glass detail-card">
|
||
<h2>Dokument hochladen</h2>
|
||
<form action="../actions/upload-dokument.php" method="post" enctype="multipart/form-data">
|
||
<?= csrf_field() ?>
|
||
<label>
|
||
<span>Kategorie <span style="color:#ff8080">*</span></span>
|
||
<select name="kategorie" required>
|
||
<option value="">– Bitte wählen –</option>
|
||
<option value="Fortbildungsnachweis">Fortbildungsnachweis</option>
|
||
<option value="Zeugnis">Zeugnis</option>
|
||
<option value="Bescheinigung">Bescheinigung</option>
|
||
<option value="Sonstiges">Sonstiges</option>
|
||
</select>
|
||
</label>
|
||
<label>
|
||
Beschreibung
|
||
<input type="text" name="beschreibung" placeholder="z. B. Erste-Hilfe-Kurs 2025">
|
||
</label>
|
||
<label>
|
||
<span>Datei <span style="color:#ff8080">*</span></span>
|
||
<input type="file" name="datei" accept=".pdf,.doc,.docx,.jpg,.jpeg,.png" required>
|
||
<span class="hint">PDF, Word, JPG, PNG — max. 12 MB</span>
|
||
</label>
|
||
<button type="submit" class="btn" style="margin-top:6px">Hochladen</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<?php layout_end(); ?>
|