2026-02-19 15:58:15 +01:00

319 lines
16 KiB
PHP

<?php
/**
* Block Template Management
* Manage recurring time blocks for channels
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/helpers.php';
require_once __DIR__ . '/auth/auth_functions.php';
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
// Require login
requireLogin();
$db = getDbConnection();
// Handle form submissions - Admin only
if ($_SERVER['REQUEST_METHOD'] === 'POST' && canEdit()) {
if (isset($_POST['create_template'])) {
$stmt = $db->prepare("
INSERT INTO block_templates
(channel, name, day_of_week, default_start_time, default_end_time, is_active)
VALUES (?, ?, ?, ?, ?, 1)
");
$stmt->execute([
$_POST['channel'],
$_POST['name'],
$_POST['day_of_week'],
$_POST['default_start_time'],
$_POST['default_end_time'] ?: null
]);
header('Location: blocks.php?success=created');
exit;
}
if (isset($_POST['update_template'])) {
$stmt = $db->prepare("
UPDATE block_templates
SET channel = ?, name = ?, day_of_week = ?,
default_start_time = ?, default_end_time = ?
WHERE id = ?
");
$stmt->execute([
$_POST['channel'],
$_POST['name'],
$_POST['day_of_week'],
$_POST['default_start_time'],
$_POST['default_end_time'] ?: null,
$_POST['template_id']
]);
header('Location: blocks.php?success=updated');
exit;
}
if (isset($_POST['toggle_active'])) {
$stmt = $db->prepare("UPDATE block_templates SET is_active = NOT is_active WHERE id = ?");
$stmt->execute([$_POST['template_id']]);
header('Location: blocks.php');
exit;
}
if (isset($_POST['delete_template'])) {
$stmt = $db->prepare("DELETE FROM block_templates WHERE id = ?");
$stmt->execute([$_POST['template_id']]);
header('Location: blocks.php?success=deleted');
exit;
}
}
// Get all templates
$templates = $db->query("SELECT * FROM block_templates ORDER BY channel, day_of_week, default_start_time")->fetchAll();
// Get template for editing
$editTemplate = null;
if (isset($_GET['edit'])) {
$stmt = $db->prepare("SELECT * FROM block_templates WHERE id = ?");
$stmt->execute([$_GET['edit']]);
$editTemplate = $stmt->fetch();
}
$dayNames = [
'all' => 'Alle dagen',
'ma' => 'Maandag',
'di' => 'Dinsdag',
'wo' => 'Woensdag',
'do' => 'Donderdag',
'vr' => 'Vrijdag',
'za' => 'Zaterdag',
'zo' => 'Zondag'
];
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blok Templates - Telvero Talpa</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body class="bg-light">
<?php $activePage = 'blocks'; include __DIR__ . '/includes/nav.php'; ?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1><i class="bi bi-calendar3"></i> Blok Templates</h1>
<a href="calendar.php" class="btn btn-primary">
<i class="bi bi-calendar-week"></i> Naar Kalender
</a>
</div>
<?php if (isset($_GET['success'])): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?php
$messages = [
'created' => 'Template succesvol aangemaakt!',
'updated' => 'Template succesvol bijgewerkt!',
'deleted' => 'Template succesvol verwijderd!'
];
echo $messages[$_GET['success']] ?? 'Actie succesvol uitgevoerd!';
?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="row">
<?php if (canEdit()): ?>
<div class="col-md-4">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h5 class="mb-0">
<i class="bi bi-plus-circle"></i>
<?= $editTemplate ? 'Template Bewerken' : 'Nieuw Template' ?>
</h5>
</div>
<div class="card-body">
<form method="POST">
<?php if ($editTemplate): ?>
<input type="hidden" name="template_id" value="<?= $editTemplate['id'] ?>">
<?php endif; ?>
<div class="mb-3">
<label class="form-label">Zender</label>
<select name="channel" class="form-select" required>
<option value="">Selecteer zender...</option>
<option value="SBS9" <?= ($editTemplate && $editTemplate['channel'] == 'SBS9') ? 'selected' : '' ?>>SBS9</option>
<option value="NET5" <?= ($editTemplate && $editTemplate['channel'] == 'NET5') ? 'selected' : '' ?>>NET5</option>
<option value="SBS6" <?= ($editTemplate && $editTemplate['channel'] == 'SBS6') ? 'selected' : '' ?>>SBS6</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Template Naam</label>
<input type="text" name="name" class="form-control"
value="<?= htmlspecialchars($editTemplate['name'] ?? '') ?>"
placeholder="bijv. SBS9 Dagblok" required>
</div>
<div class="mb-3">
<label class="form-label">Dag van de Week</label>
<select name="day_of_week" class="form-select" required>
<?php foreach ($dayNames as $value => $label): ?>
<option value="<?= $value ?>"
<?= ($editTemplate && $editTemplate['day_of_week'] == $value) ? 'selected' : '' ?>>
<?= $label ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label">Standaard Starttijd</label>
<input type="time" name="default_start_time" class="form-control"
value="<?= $editTemplate['default_start_time'] ?? '' ?>" required>
</div>
<div class="mb-3">
<label class="form-label">Standaard Eindtijd (optioneel)</label>
<input type="time" name="default_end_time" class="form-control"
value="<?= $editTemplate['default_end_time'] ?? '' ?>">
<small class="text-muted">Laat leeg als niet van toepassing</small>
</div>
<div class="d-grid gap-2">
<button type="submit" name="<?= $editTemplate ? 'update_template' : 'create_template' ?>"
class="btn btn-primary">
<i class="bi bi-<?= $editTemplate ? 'check' : 'plus' ?>-circle"></i>
<?= $editTemplate ? 'Bijwerken' : 'Aanmaken' ?>
</button>
<?php if ($editTemplate): ?>
<a href="blocks.php" class="btn btn-secondary">Annuleren</a>
<?php endif; ?>
</div>
</form>
</div>
</div>
</div>
<?php endif; ?>
<div class="<?= canEdit() ? 'col-md-8' : 'col-md-12' ?>">
<div class="card shadow-sm">
<div class="card-header bg-secondary text-white">
<h5 class="mb-0"><i class="bi bi-list-ul"></i> Bestaande Templates</h5>
</div>
<div class="card-body p-0">
<?php if (empty($templates)): ?>
<div class="p-4 text-center text-muted">
<i class="bi bi-inbox" style="font-size: 3rem;"></i>
<p class="mt-2">Nog geen templates aangemaakt</p>
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead class="table-light">
<tr>
<th>Zender</th>
<th>Naam</th>
<th>Dag</th>
<th>Starttijd</th>
<th>Eindtijd</th>
<th>Status</th>
<th>Acties</th>
</tr>
</thead>
<tbody>
<?php foreach ($templates as $template): ?>
<tr class="<?= $template['is_active'] ? '' : 'table-secondary' ?>">
<td>
<span class="badge bg-info"><?= htmlspecialchars($template['channel']) ?></span>
</td>
<td><?= htmlspecialchars($template['name']) ?></td>
<td><?= $dayNames[$template['day_of_week']] ?></td>
<td><?= substr($template['default_start_time'], 0, 5) ?></td>
<td><?= $template['default_end_time'] ? substr($template['default_end_time'], 0, 5) : '-' ?></td>
<td>
<?php if ($template['is_active']): ?>
<span class="badge bg-success">Actief</span>
<?php else: ?>
<span class="badge bg-secondary">Inactief</span>
<?php endif; ?>
</td>
<td>
<div class="action-buttons">
<?php if (canEdit()): ?>
<a href="?edit=<?= $template['id'] ?>"
class="btn-icon btn-icon-xs btn-icon-primary">
<i class="bi bi-pencil"></i>
</a>
<form method="POST" style="display:inline;">
<input type="hidden" name="template_id" value="<?= $template['id'] ?>">
<button type="submit" name="toggle_active"
class="btn-icon btn-icon-xs btn-icon-<?= $template['is_active'] ? 'warning' : 'success' ?>">
<i class="bi bi-<?= $template['is_active'] ? 'pause' : 'play' ?>-circle"></i>
</button>
</form>
<?php endif; ?>
<?php if (canDelete()): ?>
<form method="POST" style="display:inline;"
onsubmit="return confirm('Weet je zeker dat je dit template wilt verwijderen?');">
<input type="hidden" name="template_id" value="<?= $template['id'] ?>">
<button type="submit" name="delete_template"
class="btn-icon btn-icon-xs btn-icon-danger">
<i class="bi bi-trash"></i>
</button>
</form>
<?php endif; ?>
<?php if (isGuest()): ?>
<span class="text-muted small"><i class="bi bi-eye"></i></span>
<?php endif; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
<div class="card shadow-sm mt-4">
<div class="card-header bg-info text-white">
<h5 class="mb-0"><i class="bi bi-info-circle"></i> Uitleg</h5>
</div>
<div class="card-body">
<h6>Wat zijn Blok Templates?</h6>
<p>Blok templates definiƫren terugkerende tijdslots voor uitzendingen. Bijvoorbeeld:</p>
<ul>
<li><strong>SBS9 Dagblok:</strong> Ma-Zo 07:00-15:00</li>
<li><strong>SBS9 Nachtblok:</strong> Ma-Zo 23:30-02:00</li>
<li><strong>Net5 Ochtend:</strong> Ma-Vr 07:30-11:30</li>
</ul>
<h6 class="mt-3">Hoe werkt het?</h6>
<ol>
<li>Maak templates aan voor vaste blokken</li>
<li>Het systeem genereert automatisch dagelijkse blokken</li>
<li>In de kalender kun je per dag de starttijd aanpassen</li>
<li>Uitzendingen worden automatisch in deze blokken gepland</li>
</ol>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>