Files
proostenkrant.net/app/src/views/submission/form.php
T

193 lines
7.7 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
$page_title = 'Nieuw Artikel Indienen';
ob_start();
$users = $users ?? [];
$oldInput = $oldInput ?? [];
$errors = $errors ?? [];
$article = $article ?? null;
// If editing, populate old input from article
if ($article && empty($oldInput)) {
$oldInput = [
'title' => $article['title'],
'content' => $article['content'],
'writer' => $article['author_id'],
'event_date' => $article['event_date'],
'article_id' => $article['id']
];
// Parse participants
if (!empty($article['participants'])) {
$participantIds = explode(',', $article['participants']);
} else {
$participantIds = [];
}
}
// Get selected participants from old input
$selectedParticipants = [];
if (!empty($oldInput['participants'])) {
if (is_array($oldInput['participants'])) {
$selectedParticipants = $oldInput['participants'];
} else {
$selectedParticipants = [$oldInput['participants']];
}
} elseif (isset($participantIds)) {
$selectedParticipants = $participantIds;
}
// Check if we have an uploaded image in session or from old input
$uploadedImage = null;
if (isset($_SESSION['uploaded_image'])) {
$uploadedImage = $_SESSION['uploaded_image'];
unset($_SESSION['uploaded_image']);
} elseif ($article && $article['article_image']) {
$uploadedImage = $article['article_image'];
}
?>
<div class="article-form">
<div class="section-header">
<h2><?= $article ? 'Artikel Bewerken' : 'Nieuw Artikel Indienen' ?></h2>
<a href="/" class="btn btn-secondary btn-small">
<span class="icon">×</span> Annuleren
</a>
</div>
<form action="/submit/store" method="post" enctype="multipart/form-data">
<?php if ($article): ?>
<input type="hidden" name="article_id" value="<?= $article['id'] ?>">
<?php endif; ?>
<div class="form-row">
<div class="form-group">
<label for="title">Titel *</label>
<input type="text"
name="title"
id="title"
value="<?= htmlspecialchars($oldInput['title'] ?? '') ?>"
required
class="form-control <?= isset($errors['title']) ? 'error' : '' ?>"
placeholder="Voer de titel in">
<?php if (isset($errors['title'])): ?>
<span class="error-message"><?= htmlspecialchars($errors['title']) ?></span>
<?php endif; ?>
</div>
</div>
<div class="form-row">
<div class="form-group full-width">
<label for="content">Tekst *</label>
<textarea name="content"
id="content"
rows="8"
required
class="form-control <?= isset($errors['content']) ? 'error' : '' ?>"
placeholder="Schrijf hier de inhoud van je artikel..."><?= htmlspecialchars($oldInput['content'] ?? '') ?></textarea>
<?php if (isset($errors['content'])): ?>
<span class="error-message"><?= htmlspecialchars($errors['content']) ?></span>
<?php endif; ?>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="writer">Schrijver *</label>
<select name="writer"
id="writer"
required
class="form-control <?= isset($errors['writer']) ? 'error' : '' ?>">
<option value="">-- Selecteer schrijver --</option>
<?php foreach ($users as $user): ?>
<option value="<?= $user['id'] ?>"
<?= (($oldInput['writer'] ?? '') == $user['id']) ? 'selected' : '' ?>>
<?= htmlspecialchars($user['display_name']) ?>
</option>
<?php endforeach; ?>
</select>
<?php if (isset($errors['writer'])): ?>
<span class="error-message"><?= htmlspecialchars($errors['writer']) ?></span>
<?php endif; ?>
</div>
<div class="form-group">
<label for="event_date">Datum van het evenement *</label>
<input type="date"
name="event_date"
id="event_date"
value="<?= htmlspecialchars($oldInput['event_date'] ?? date('Y-m-d')) ?>"
required
class="form-control">
</div>
</div>
<div class="form-row">
<div class="form-group full-width">
<label>Deelnemers *</label>
<p class="help-text">Selecteer alle personages die bij dit verhaal betrokken zijn.</p>
<div class="checkbox-group">
<?php foreach ($users as $user): ?>
<label class="checkbox-label">
<input type="checkbox"
name="participants[]"
value="<?= $user['id'] ?>"
<?= (in_array($user['id'], $selectedParticipants)) ? 'checked' : '' ?>>
<?= htmlspecialchars($user['display_name']) ?>
</label>
<?php endforeach; ?>
</div>
<p class="help-text">Selecteer minstens één deelnemer</p>
<?php if (isset($errors['participants'])): ?>
<span class="error-message"><?= htmlspecialchars($errors['participants']) ?></span>
<?php endif; ?>
</div>
</div>
<div class="form-row">
<div class="form-group full-width">
<label for="image">Afbeelding *</label>
<div class="file-upload-wrapper">
<input type="file"
name="image"
id="image"
accept="image/*"
required>
<label for="image" class="file-upload-label">
<span class="icon">📷</span> Kies een afbeelding
</label>
</div>
<p class="help-text file-upload-info">
Upload een foto bij het artikel. Zowel landscape als portret foto's worden ondersteund.
</p>
<?php if ($uploadedImage): ?>
<div class="image-preview mt-20">
<div class="image-preview-container">
<img src="/<?= htmlspecialchars($uploadedImage) ?>" alt="Geselecteerde afbeelding">
</div>
<p class="text-muted mt-10">Afbeelding succesvol geupload: <?= htmlspecialchars(basename($uploadedImage)) ?></p>
</div>
<?php endif; ?>
<?php if (isset($errors['image'])): ?>
<span class="error-message"><?= htmlspecialchars($errors['image']) ?></span>
<?php endif; ?>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">
<span class="icon"><?= $article ? '✓' : '+' ?></span>
<?= $article ? 'Artikel Bijwerken' : 'Artikel Indienen' ?>
</button>
<a href="/" class="btn btn-secondary">Annuleren</a>
</div>
</form>
</div>
<?php
$content = ob_get_clean();
require __DIR__ . '/../layouts/main.php';
?>