Drink it cold: Terminplanung für Kühlanhänger
6
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
docs/credentials.txt
|
||||
app/config.local.php
|
||||
storage/*
|
||||
!storage/.htaccess
|
||||
*.log
|
||||
.DS_Store
|
||||
116
README.md
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
# Drink it cold – Terminplanung
|
||||
|
||||
Interne Web-App zur Verwaltung von acht Kühlanhängern: Buchungen, Mietzeiträume,
|
||||
Mitarbeiterzuordnung und automatische Erinnerungen. Farbschema und Logo der
|
||||
bestehenden Website (Weiß/Blau, `#196abc`) wurden übernommen.
|
||||
|
||||
Die Anforderungen stammen aus
|
||||
[`docs/Anforderungen_Online_Terminplanung_Drink_it_cold-1.pdf`](docs/Anforderungen_Online_Terminplanung_Drink_it_cold-1.pdf).
|
||||
|
||||
## Was die App kann
|
||||
|
||||
- **Kalender** mit Tages-, Wochen- und Monatsansicht. Alle acht Anhänger haben
|
||||
eine eigene Zeile und sind immer gleichzeitig sichtbar. Jeder Termin ist ein
|
||||
durchgehender, farbiger Balken in der Farbe des Anhängers.
|
||||
- **Buchungen** mit Anfangs- und Endtermin (ganztägig), Anzahlung,
|
||||
Gesamtbetrag, automatisch berechnetem Restbetrag, Rechnung JA/NEIN,
|
||||
Abholung/Lieferung und vollständigen Kundendaten.
|
||||
- **Buchungstext kopieren** mit einem Klick – exakt in der geforderten
|
||||
Reihenfolge und mit erhaltenen Zeilenumbrüchen.
|
||||
- **Doppelbelegungsschutz**: Ein Anhänger kann im gleichen Zeitraum nicht
|
||||
doppelt vergeben werden. Der Wechseltag (letzter Tag der einen = erster Tag
|
||||
der nächsten Buchung) ist erlaubt und wird als zweite Lane sichtbar.
|
||||
- **Mitarbeiterzuordnung** pro Buchung, änderbar. Erinnerungen sind an diese
|
||||
Zuordnung gebunden.
|
||||
- **Automatische Erinnerungen** 8 Tage vor Mietbeginn, 1 Tag vor Mietbeginn und
|
||||
1 Tag vor Mietende. Sie entstehen aus den Buchungsdaten, passen sich bei
|
||||
Terminänderungen an und entfallen bei Stornierung.
|
||||
- **Buchungen verwalten**: anlegen, bearbeiten, per Drag & Drop verschieben,
|
||||
anderen Anhänger oder Mitarbeiter zuordnen, stornieren, wiederherstellen und
|
||||
nach Kundenname suchen.
|
||||
- **Benutzerverwaltung** wie bei tippspiel2027: Konten werden ausschließlich
|
||||
vom Administrator angelegt. Anmeldung mit Vorname, Nachname und Passwort;
|
||||
keine Selbstregistrierung.
|
||||
- **Übersicht** mit heutiger Auslastung, freien Anhängern, nächsten Übergaben
|
||||
und Rücknahmen sowie offenen Erinnerungen.
|
||||
|
||||
## Technik
|
||||
|
||||
- PHP 8.1+ (getestet mit 8.3), MariaDB 10.11, keine Build-Tools nötig.
|
||||
- Server-gerendertes HTML, wenig JavaScript (Kalender-Dialog, Drag & Drop,
|
||||
Live-Prüfung, Kopieren). Keine externen CDNs.
|
||||
- Die App läuft direkt im DocumentRoot der Subdomain
|
||||
`drink-it-cold.programmschmiede.de`; `app/`, `views/` und `sql/` sind per
|
||||
`.htaccess` gesperrt.
|
||||
- Schriften (Manrope/Inter), Logo und Hero-Bild stammen aus den alten Assets
|
||||
der Vorgängerseite.
|
||||
|
||||
## Lokal starten
|
||||
|
||||
Voraussetzungen: PHP mit `pdo_mysql`, MariaDB/MySQL. Kein Composer.
|
||||
|
||||
```bash
|
||||
cp app/config.example.php app/config.local.php
|
||||
# DB-Zugang in app/config.local.php eintragen, install_token setzen
|
||||
mkdir -p storage/logs
|
||||
php -S 127.0.0.1:8099 -t web tools/router.php
|
||||
```
|
||||
|
||||
Dann `http://127.0.0.1:8099/install.php?token=<install_token>` öffnen und den
|
||||
ersten Administrator anlegen. Der Installer legt Schema, acht Anhänger und die
|
||||
Mitarbeiter M. Krücken, N. Jorns und M. Schmitz an. Danach `install.php`
|
||||
löschen.
|
||||
|
||||
## Deployment
|
||||
|
||||
Zugangsdaten liegen in `docs/credentials.txt` (nicht eingecheckt).
|
||||
|
||||
```bash
|
||||
./tools/deploy.sh --sync # Code, Assets und Konfiguration hochladen
|
||||
./tools/deploy.sh --install # Schema + ersten Admin anlegen
|
||||
./tools/deploy.sh --check # Health, Login und Assets prüfen
|
||||
./tools/deploy.sh --all
|
||||
```
|
||||
|
||||
Für `--install` werden `DIC_ADMIN_FIRST`, `DIC_ADMIN_LAST` und
|
||||
`DIC_ADMIN_PASSWORD` aus der Umgebung gelesen oder interaktiv abgefragt.
|
||||
`install.php` wird nach erfolgreicher Installation vom Server entfernt.
|
||||
|
||||
## Erinnerungen per E-Mail (optional)
|
||||
|
||||
Die Erinnerungen sind immer in der App sichtbar. Zusätzlich kann ein täglicher
|
||||
Digest an Mitarbeiter gehen, deren Benutzerkonto eine E-Mail-Adresse hat:
|
||||
|
||||
1. In `app/config.local.php` `mail_enabled` auf `true` setzen (beim Deployment
|
||||
aktuell `false`; die Datei wird aus `tools/deploy.sh` erzeugt).
|
||||
2. Cron einrichten:
|
||||
```
|
||||
0 7 * * * /usr/bin/php /pfad/zu/drink-it-cold/tools/send_reminders.php
|
||||
```
|
||||
3. Alternativ `GET /cron/reminders?token=<cron_token>` aufrufen.
|
||||
|
||||
Jede Erinnerung wird genau einmal versendet (`reminder_mail_log`).
|
||||
|
||||
## Sicherheit
|
||||
|
||||
- Passwörter: Argon2id (Fallback bcrypt), Session-Cookies `HttpOnly`,
|
||||
`SameSite=Lax`, `Secure` unter HTTPS.
|
||||
- CSRF-Schutz für alle Formulare und die Move-API.
|
||||
- Login-Ratenbegrenzung pro IP und Name, generische Fehlermeldungen.
|
||||
- „Angemeldet bleiben“ über rotierende Tokens; Passwortwechsel und
|
||||
Deaktivierung machen bestehende Sitzungen ungültig.
|
||||
- CSP ohne Inline-JavaScript, `X-Frame-Options: DENY`, `noindex`.
|
||||
|
||||
## Struktur
|
||||
|
||||
```
|
||||
app/ Bootstrap, Auth, Datenzugriff, Routing, Admin
|
||||
views/ HTML-Vorlagen
|
||||
web/ DocumentRoot: index.php, Assets
|
||||
sql/ Schema und Grunddaten
|
||||
tools/ Deployment, lokaler Router, E-Mail-Digest
|
||||
docs/ Anforderungen und Architektur
|
||||
```
|
||||
|
||||
Mehr Details zu Entscheidungen und Anforderungsabdeckung:
|
||||
[`docs/architecture.md`](docs/architecture.md).
|
||||
7
app/.htaccess
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
</IfModule>
|
||||
389
app/admin.php
Normal file
|
|
@ -0,0 +1,389 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/** Verwaltung: Benutzer, Mitarbeiter, Anhänger, Erinnerungsversand. */
|
||||
|
||||
function admin_handle(string $path, array $user): void
|
||||
{
|
||||
auth_require_admin();
|
||||
|
||||
if ($path === '/admin' || $path === '/admin/') {
|
||||
redirect('/admin/users');
|
||||
}
|
||||
if ($path === '/admin/users') {
|
||||
admin_users_list();
|
||||
return;
|
||||
}
|
||||
if ($path === '/admin/users/new') {
|
||||
admin_user_form(null);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/admin/users/(\d+)$#', $path, $m) === 1) {
|
||||
admin_user_form((int) $m[1]);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/admin/users/(\d+)/delete$#', $path, $m) === 1) {
|
||||
admin_user_delete((int) $m[1], $user);
|
||||
return;
|
||||
}
|
||||
if ($path === '/admin/employees') {
|
||||
admin_employees();
|
||||
return;
|
||||
}
|
||||
if ($path === '/admin/trailers') {
|
||||
admin_trailers();
|
||||
return;
|
||||
}
|
||||
if ($path === '/admin/reminders/send') {
|
||||
admin_reminders_send();
|
||||
return;
|
||||
}
|
||||
|
||||
abort_page(404, 'Diese Verwaltungsseite gibt es nicht.');
|
||||
}
|
||||
|
||||
function admin_users_list(): void
|
||||
{
|
||||
$sql = 'SELECT u.*, e.name AS employee_name
|
||||
FROM users u LEFT JOIN employees e ON e.id = u.employee_id
|
||||
ORDER BY u.last_name, u.first_name';
|
||||
$users = db()->query($sql)->fetchAll();
|
||||
render_page('admin_users', ['users' => $users], 'Benutzer');
|
||||
}
|
||||
|
||||
function admin_user_form(?int $id): void
|
||||
{
|
||||
$editing = $id !== null ? auth_user_by_id($id) : null;
|
||||
if ($id !== null && !$editing) {
|
||||
abort_page(404, 'Benutzer nicht gefunden.');
|
||||
}
|
||||
|
||||
$employees = employees_all();
|
||||
$errors = [];
|
||||
$values = $editing ? [
|
||||
'first_name' => (string) $editing['first_name'],
|
||||
'last_name' => (string) $editing['last_name'],
|
||||
'email' => (string) ($editing['email'] ?? ''),
|
||||
'role' => (string) $editing['role'],
|
||||
'status' => (string) $editing['status'],
|
||||
'employee_id' => (int) ($editing['employee_id'] ?? 0),
|
||||
'must_change_password' => (int) $editing['must_change_password'],
|
||||
] : [
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'email' => '',
|
||||
'role' => 'user',
|
||||
'status' => 'active',
|
||||
'employee_id' => 0,
|
||||
'must_change_password' => 1,
|
||||
];
|
||||
|
||||
if (is_post()) {
|
||||
require_post();
|
||||
$values = [
|
||||
'first_name' => post_string('first_name'),
|
||||
'last_name' => post_string('last_name'),
|
||||
'email' => post_string('email'),
|
||||
'role' => post_string('role') === 'admin' ? 'admin' : 'user',
|
||||
'status' => post_string('status') === 'disabled' ? 'disabled' : 'active',
|
||||
'employee_id' => (int) post_string('employee_id'),
|
||||
'must_change_password' => post_string('must_change_password') === '1' ? 1 : 0,
|
||||
];
|
||||
$password = (string) ($_POST['password'] ?? '');
|
||||
|
||||
if ($values['first_name'] === '' || mb_strlen($values['first_name']) > 80) {
|
||||
$errors['first_name'] = 'Bitte einen Vornamen angeben (max. 80 Zeichen).';
|
||||
}
|
||||
if ($values['last_name'] === '' || mb_strlen($values['last_name']) > 80) {
|
||||
$errors['last_name'] = 'Bitte einen Nachnamen angeben (max. 80 Zeichen).';
|
||||
}
|
||||
if ($values['email'] !== '' && (!filter_var($values['email'], FILTER_VALIDATE_EMAIL) || mb_strlen($values['email']) > 190)) {
|
||||
$errors['email'] = 'Bitte eine gültige E-Mail-Adresse angeben.';
|
||||
} elseif ($values['email'] !== '') {
|
||||
$stmt = db()->prepare('SELECT id FROM users WHERE email = ? AND id <> ? LIMIT 1');
|
||||
$stmt->execute([$values['email'], $id ?? 0]);
|
||||
if ($stmt->fetchColumn()) {
|
||||
$errors['email'] = 'Diese E-Mail-Adresse ist bereits einem anderen Benutzer zugeordnet.';
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = db()->prepare('SELECT id FROM users WHERE first_name = ? AND last_name = ? AND id <> ? LIMIT 1');
|
||||
$stmt->execute([$values['first_name'], $values['last_name'], $id ?? 0]);
|
||||
if ($stmt->fetchColumn()) {
|
||||
$errors['name'] = 'Ein Benutzer mit diesem Vor- und Nachnamen existiert bereits.';
|
||||
}
|
||||
|
||||
if ($values['employee_id'] > 0) {
|
||||
$stmt = db()->prepare('SELECT id, first_name, last_name FROM users WHERE employee_id = ? AND id <> ? LIMIT 1');
|
||||
$stmt->execute([$values['employee_id'], $id ?? 0]);
|
||||
if ($other = $stmt->fetch()) {
|
||||
$errors['employee_id'] = 'Dieser Mitarbeiter ist bereits mit ' . $other['first_name'] . ' ' . $other['last_name'] . ' verknüpft.';
|
||||
}
|
||||
if (!employee_find($values['employee_id'])) {
|
||||
$errors['employee_id'] = 'Mitarbeiter nicht gefunden.';
|
||||
}
|
||||
}
|
||||
|
||||
if ($id === null && mb_strlen($password) < 8) {
|
||||
$errors['password'] = 'Das Startpasswort muss mindestens 8 Zeichen haben.';
|
||||
}
|
||||
if ($id !== null && $password !== '' && mb_strlen($password) < 8) {
|
||||
$errors['password'] = 'Das neue Passwort muss mindestens 8 Zeichen haben.';
|
||||
}
|
||||
|
||||
// Der letzte aktive Admin darf nicht degradiert oder deaktiviert werden.
|
||||
if ($editing && ($editing['role'] === 'admin' && $editing['status'] === 'active')
|
||||
&& ($values['role'] !== 'admin' || $values['status'] !== 'active')
|
||||
) {
|
||||
$stmt = db()->query("SELECT COUNT(*) FROM users WHERE role = 'admin' AND status = 'active' AND id <> " . (int) $editing['id']);
|
||||
if ((int) $stmt->fetchColumn() === 0) {
|
||||
$errors['role'] = 'Der letzte aktive Administrator kann nicht herabgestuft oder deaktiviert werden.';
|
||||
}
|
||||
}
|
||||
if ($editing && (int) $editing['id'] === auth_user()['id']
|
||||
&& ($values['role'] !== 'admin' || $values['status'] !== 'active')
|
||||
) {
|
||||
$errors['role'] = 'Das eigene Konto kann nicht deaktiviert oder zum normalen Benutzer gemacht werden.';
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
$email = $values['email'] === '' ? null : $values['email'];
|
||||
$pdo = db();
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
if ($id === null) {
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO users (first_name, last_name, email, password_hash, role, status, employee_id,
|
||||
must_change_password, auth_epoch, created_at, updated_at, password_changed_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?, ?)'
|
||||
);
|
||||
$stmt->execute([
|
||||
$values['first_name'], $values['last_name'], $email, hash_password($password),
|
||||
$values['role'], $values['status'], $values['employee_id'] ?: null,
|
||||
$values['must_change_password'], utc_now(), utc_now(), utc_now(),
|
||||
]);
|
||||
$newId = (int) $pdo->lastInsertId();
|
||||
$pdo->commit();
|
||||
flash('success', 'Benutzer ' . $values['first_name'] . ' ' . $values['last_name'] . ' wurde angelegt.');
|
||||
redirect('/admin/users/' . $newId);
|
||||
}
|
||||
|
||||
$newId = (int) $editing['id'];
|
||||
$securityChange = $password !== '' || ($editing['status'] === 'active' && $values['status'] === 'disabled');
|
||||
$stmt = $pdo->prepare(
|
||||
'UPDATE users SET first_name = ?, last_name = ?, email = ?, role = ?, status = ?,
|
||||
employee_id = ?, must_change_password = ?, updated_at = ? WHERE id = ?'
|
||||
);
|
||||
$stmt->execute([
|
||||
$values['first_name'], $values['last_name'], $email, $values['role'], $values['status'],
|
||||
$values['employee_id'] ?: null, $values['must_change_password'], utc_now(), $newId,
|
||||
]);
|
||||
if ($password !== '') {
|
||||
$pdo->prepare(
|
||||
'UPDATE users SET password_hash = ?, password_changed_at = ?, must_change_password = ?,
|
||||
auth_epoch = auth_epoch + 1 WHERE id = ?'
|
||||
)->execute([hash_password($password), utc_now(), $values['must_change_password'], $newId]);
|
||||
$pdo->prepare('DELETE FROM auth_tokens WHERE user_id = ?')->execute([$newId]);
|
||||
} elseif ($securityChange) {
|
||||
$pdo->prepare('UPDATE users SET auth_epoch = auth_epoch + 1 WHERE id = ?')->execute([$newId]);
|
||||
$pdo->prepare('DELETE FROM auth_tokens WHERE user_id = ?')->execute([$newId]);
|
||||
}
|
||||
$pdo->commit();
|
||||
} catch (Throwable $error) {
|
||||
$pdo->rollBack();
|
||||
throw $error;
|
||||
}
|
||||
|
||||
flash('success', 'Benutzer wurde gespeichert.');
|
||||
if ($password !== '' && $newId === (int) auth_user()['id']) {
|
||||
auth_logout();
|
||||
redirect('/login');
|
||||
}
|
||||
redirect('/admin/users');
|
||||
}
|
||||
http_response_code(422);
|
||||
}
|
||||
|
||||
render_page('admin_user_form', [
|
||||
'editing' => $editing,
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'employees' => $employees,
|
||||
], $editing ? 'Benutzer bearbeiten' : 'Benutzer anlegen');
|
||||
}
|
||||
|
||||
function admin_user_delete(int $id, array $actor): void
|
||||
{
|
||||
require_post();
|
||||
$target = auth_user_by_id($id);
|
||||
if (!$target) {
|
||||
abort_page(404, 'Benutzer nicht gefunden.');
|
||||
}
|
||||
if ($id === (int) $actor['id']) {
|
||||
abort_page(422, 'Das eigene Konto kann nicht gelöscht werden.');
|
||||
}
|
||||
if ($target['role'] === 'admin' && $target['status'] === 'active') {
|
||||
$count = (int) db()->query("SELECT COUNT(*) FROM users WHERE role = 'admin' AND status = 'active' AND id <> $id")->fetchColumn();
|
||||
if ($count === 0) {
|
||||
abort_page(422, 'Der letzte aktive Administrator kann nicht gelöscht werden.');
|
||||
}
|
||||
}
|
||||
db()->prepare('DELETE FROM users WHERE id = ?')->execute([$id]);
|
||||
flash('success', 'Benutzer ' . $target['first_name'] . ' ' . $target['last_name'] . ' wurde gelöscht.');
|
||||
redirect('/admin/users');
|
||||
}
|
||||
|
||||
function admin_employees(): void
|
||||
{
|
||||
$errors = [];
|
||||
$editId = query_int('edit');
|
||||
$editing = $editId > 0 ? employee_find($editId) : null;
|
||||
$values = ['name' => '', 'sort_order' => 0, 'active' => 1];
|
||||
|
||||
if (is_post()) {
|
||||
require_post();
|
||||
$action = post_string('action');
|
||||
$id = (int) post_string('id');
|
||||
$values = [
|
||||
'name' => post_string('name'),
|
||||
'sort_order' => (int) post_string('sort_order'),
|
||||
'active' => post_string('active') === '1' ? 1 : 0,
|
||||
];
|
||||
if ($values['name'] === '' || mb_strlen($values['name']) > 100) {
|
||||
$errors['name'] = 'Bitte einen Namen angeben (max. 100 Zeichen).';
|
||||
}
|
||||
$stmt = db()->prepare('SELECT id FROM employees WHERE name = ? AND id <> ? LIMIT 1');
|
||||
$stmt->execute([$values['name'], $id]);
|
||||
if ($stmt->fetchColumn()) {
|
||||
$errors['name'] = 'Dieser Mitarbeiter existiert bereits.';
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
if ($action === 'create') {
|
||||
db()->prepare('INSERT INTO employees (name, active, sort_order, created_at) VALUES (?, ?, ?, ?)')
|
||||
->execute([$values['name'], $values['active'], $values['sort_order'], utc_now()]);
|
||||
flash('success', 'Mitarbeiter ' . $values['name'] . ' wurde angelegt.');
|
||||
} elseif ($action === 'update' && $id > 0) {
|
||||
$existing = employee_find($id);
|
||||
if (!$existing) {
|
||||
abort_page(404, 'Mitarbeiter nicht gefunden.');
|
||||
}
|
||||
if ((int) $existing['active'] === 1 && $values['active'] === 0) {
|
||||
$stmt = db()->prepare("SELECT COUNT(*) FROM bookings WHERE employee_id = ? AND status = 'active' AND end_date >= ?");
|
||||
$stmt->execute([$id, today_iso()]);
|
||||
if ((int) $stmt->fetchColumn() > 0) {
|
||||
$errors['active'] = 'Der Mitarbeiter hat noch aktive Buchungen und kann nicht deaktiviert werden. Bitte zuerst umbuchen.';
|
||||
}
|
||||
}
|
||||
if (!$errors) {
|
||||
db()->prepare('UPDATE employees SET name = ?, active = ?, sort_order = ? WHERE id = ?')
|
||||
->execute([$values['name'], $values['active'], $values['sort_order'], $id]);
|
||||
flash('success', 'Mitarbeiter wurde gespeichert.');
|
||||
}
|
||||
}
|
||||
if (!$errors) {
|
||||
redirect('/admin/employees');
|
||||
}
|
||||
}
|
||||
http_response_code(422);
|
||||
$editId = $action === 'update' ? $id : 0;
|
||||
if ($editId > 0) {
|
||||
$editing = employee_find($editId);
|
||||
if (!$editing) {
|
||||
abort_page(404, 'Mitarbeiter nicht gefunden.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($editId > 0 && !$editing) {
|
||||
abort_page(404, 'Mitarbeiter nicht gefunden.');
|
||||
}
|
||||
if ($editing && !is_post()) {
|
||||
$values = [
|
||||
'name' => (string) $editing['name'],
|
||||
'sort_order' => (int) $editing['sort_order'],
|
||||
'active' => (int) $editing['active'],
|
||||
];
|
||||
}
|
||||
|
||||
$rows = db()->query(
|
||||
'SELECT e.*, u.first_name, u.last_name,
|
||||
(SELECT COUNT(*) FROM bookings b WHERE b.employee_id = e.id AND b.status = "active" AND b.end_date >= CURDATE()) AS future_bookings
|
||||
FROM employees e LEFT JOIN users u ON u.employee_id = e.id
|
||||
ORDER BY e.sort_order, e.name'
|
||||
)->fetchAll();
|
||||
|
||||
render_page('admin_employees', [
|
||||
'rows' => $rows,
|
||||
'editing' => $editing,
|
||||
'editId' => $editId,
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
], 'Mitarbeiter');
|
||||
}
|
||||
|
||||
function admin_trailers(): void
|
||||
{
|
||||
$errors = [];
|
||||
if (is_post()) {
|
||||
require_post();
|
||||
$labels = post_array('label');
|
||||
$colorNames = post_array('color_name');
|
||||
$colors = post_array('color_hex');
|
||||
$sorts = post_array('sort_order');
|
||||
|
||||
$existing = trailers_map();
|
||||
$seen = [];
|
||||
foreach ($existing as $id => $trailer) {
|
||||
$label = trim((string) ($labels[$id] ?? ''));
|
||||
$colorName = trim((string) ($colorNames[$id] ?? ''));
|
||||
$color = strtolower(trim((string) ($colors[$id] ?? '')));
|
||||
$sort = (int) ($sorts[$id] ?? $trailer['sort_order']);
|
||||
|
||||
if ($label === '' || mb_strlen($label) > 40) {
|
||||
$errors['trailer_' . $id] = 'Bitte eine Bezeichnung angeben (max. 40 Zeichen).';
|
||||
continue;
|
||||
}
|
||||
if (isset($seen[mb_strtolower($label)])) {
|
||||
$errors['trailer_' . $id] = 'Die Bezeichnung muss eindeutig sein.';
|
||||
continue;
|
||||
}
|
||||
$seen[mb_strtolower($label)] = true;
|
||||
if ($colorName === '' || mb_strlen($colorName) > 40) {
|
||||
$errors['trailer_' . $id] = 'Bitte einen Farbnamen angeben.';
|
||||
continue;
|
||||
}
|
||||
if (!preg_match('/^#[0-9a-f]{6}$/', $color)) {
|
||||
$errors['trailer_' . $id] = 'Bitte eine gültige Farbe (#rrggbb) wählen.';
|
||||
continue;
|
||||
}
|
||||
db()->prepare('UPDATE trailers SET label = ?, color_name = ?, color_hex = ?, sort_order = ? WHERE id = ?')
|
||||
->execute([$label, $colorName, $color, $sort, $id]);
|
||||
}
|
||||
if (!$errors) {
|
||||
flash('success', 'Anhänger wurden gespeichert.');
|
||||
redirect('/admin/trailers');
|
||||
}
|
||||
http_response_code(422);
|
||||
}
|
||||
|
||||
$rows = trailers_all(false);
|
||||
render_page('admin_trailers', [
|
||||
'rows' => $rows,
|
||||
'errors' => $errors,
|
||||
], 'Anhänger');
|
||||
}
|
||||
|
||||
function admin_reminders_send(): void
|
||||
{
|
||||
require_post();
|
||||
$result = reminder_send_due();
|
||||
if (!$result['enabled']) {
|
||||
flash('info', 'Der E-Mail-Versand ist in der Konfiguration deaktiviert. Die Erinnerungen bleiben in der App sichtbar.');
|
||||
} elseif ($result['errors']) {
|
||||
flash('error', implode(' ', $result['errors']));
|
||||
} else {
|
||||
flash('success', 'E-Mail-Versand ausgeführt: ' . $result['sent'] . ' Erinnerung(en) versendet, ' . $result['skipped'] . ' übersprungen.');
|
||||
}
|
||||
redirect('/reminders');
|
||||
}
|
||||
323
app/auth.php
Normal file
|
|
@ -0,0 +1,323 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Anmeldung, Sessions, Angemeldet-bleiben und Ratenbegrenzung.
|
||||
*
|
||||
* Angemeldet wird – wie bei tippspiel2027 – mit Vorname, Nachname und
|
||||
* Passwort. Konten werden ausschließlich vom Admin angelegt.
|
||||
*/
|
||||
|
||||
const DIC_DUMMY_HASH = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2uheWG/igi.';
|
||||
const DIC_REMEMBER_COOKIE = 'DIC_REMEMBER';
|
||||
|
||||
function hash_password(string $password): string
|
||||
{
|
||||
if (defined('PASSWORD_ARGON2ID')) {
|
||||
return password_hash($password, PASSWORD_ARGON2ID, [
|
||||
'memory_cost' => 32768,
|
||||
'time_cost' => 3,
|
||||
'threads' => 1,
|
||||
]);
|
||||
}
|
||||
return password_hash($password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
function password_needs_upgrade(string $hash): bool
|
||||
{
|
||||
if (defined('PASSWORD_ARGON2ID')) {
|
||||
return password_needs_rehash($hash, PASSWORD_ARGON2ID, [
|
||||
'memory_cost' => 32768,
|
||||
'time_cost' => 3,
|
||||
'threads' => 1,
|
||||
]);
|
||||
}
|
||||
return password_needs_rehash($hash, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
function auth_user(): ?array
|
||||
{
|
||||
static $loaded = false;
|
||||
static $user = null;
|
||||
if ($loaded) {
|
||||
return $user;
|
||||
}
|
||||
$loaded = true;
|
||||
|
||||
$uid = $_SESSION['uid'] ?? null;
|
||||
if (!is_int($uid) && !ctype_digit((string) $uid)) {
|
||||
auth_restore_from_remember();
|
||||
$uid = $_SESSION['uid'] ?? null;
|
||||
if (!is_int($uid) && !ctype_digit((string) $uid)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = db()->prepare('SELECT * FROM users WHERE id = ? LIMIT 1');
|
||||
$stmt->execute([(int) $uid]);
|
||||
$row = $stmt->fetch();
|
||||
if (!$row || $row['status'] !== 'active') {
|
||||
auth_clear_session();
|
||||
return null;
|
||||
}
|
||||
if ((int) ($_SESSION['epoch'] ?? 0) !== (int) $row['auth_epoch']) {
|
||||
auth_clear_session();
|
||||
return null;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$idleLimit = (int) config('app.session_idle_seconds', 2592000);
|
||||
$absoluteLimit = (int) config('app.session_absolute_seconds', 7776000);
|
||||
$created = (int) ($_SESSION['created'] ?? 0);
|
||||
$lastSeen = (int) ($_SESSION['last_seen'] ?? 0);
|
||||
if ($created === 0 || $lastSeen === 0
|
||||
|| $now - $lastSeen > $idleLimit
|
||||
|| $now - $created > $absoluteLimit
|
||||
) {
|
||||
auth_clear_session();
|
||||
return null;
|
||||
}
|
||||
if ($now - $lastSeen > 300) {
|
||||
$_SESSION['last_seen'] = $now;
|
||||
}
|
||||
|
||||
$row['id'] = (int) $row['id'];
|
||||
$row['auth_epoch'] = (int) $row['auth_epoch'];
|
||||
$row['must_change_password'] = (int) $row['must_change_password'];
|
||||
$user = $row;
|
||||
return $user;
|
||||
}
|
||||
|
||||
function auth_user_by_id(int $id): ?array
|
||||
{
|
||||
$stmt = db()->prepare('SELECT * FROM users WHERE id = ? LIMIT 1');
|
||||
$stmt->execute([$id]);
|
||||
$row = $stmt->fetch();
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
$row['id'] = (int) $row['id'];
|
||||
$row['auth_epoch'] = (int) $row['auth_epoch'];
|
||||
$row['must_change_password'] = (int) $row['must_change_password'];
|
||||
return $row;
|
||||
}
|
||||
|
||||
function auth_login(array $user, bool $remember = false): void
|
||||
{
|
||||
session_regenerate_id(true);
|
||||
$_SESSION['uid'] = (int) $user['id'];
|
||||
$_SESSION['epoch'] = (int) $user['auth_epoch'];
|
||||
$_SESSION['created'] = time();
|
||||
$_SESSION['last_seen'] = time();
|
||||
$_SESSION['csrf'] = bin2hex(random_bytes(32));
|
||||
|
||||
$stmt = db()->prepare('UPDATE users SET last_login_at = ? WHERE id = ?');
|
||||
$stmt->execute([utc_now(), (int) $user['id']]);
|
||||
|
||||
if ($remember) {
|
||||
auth_issue_remember((int) $user['id']);
|
||||
}
|
||||
db()->prepare('DELETE FROM login_attempts WHERE name_key = ?')->execute([auth_name_key((string) $user['first_name'], (string) $user['last_name'])]);
|
||||
}
|
||||
|
||||
function auth_clear_session(): void
|
||||
{
|
||||
$_SESSION = [];
|
||||
if (session_status() === PHP_SESSION_ACTIVE) {
|
||||
session_regenerate_id(true);
|
||||
}
|
||||
}
|
||||
|
||||
function auth_logout(): void
|
||||
{
|
||||
auth_forget_remember();
|
||||
auth_clear_session();
|
||||
if (session_status() === PHP_SESSION_ACTIVE) {
|
||||
session_destroy();
|
||||
}
|
||||
}
|
||||
|
||||
function auth_require_login(): array
|
||||
{
|
||||
$user = auth_user();
|
||||
if ($user === null) {
|
||||
$target = current_path();
|
||||
$query = (string) ($_SERVER['QUERY_STRING'] ?? '');
|
||||
if ($query !== '') {
|
||||
$target .= '?' . $query;
|
||||
}
|
||||
redirect('/login?next=' . rawurlencode($target));
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
||||
function auth_require_admin(): array
|
||||
{
|
||||
$user = auth_require_login();
|
||||
if (($user['role'] ?? '') !== 'admin') {
|
||||
abort_page(403, 'Diese Seite ist nur für Administratoren.');
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
||||
function auth_name_key(string $first, string $last): string
|
||||
{
|
||||
return mb_strtolower(trim($first) . ' ' . trim($last), 'UTF-8');
|
||||
}
|
||||
|
||||
function auth_find_by_name(string $first, string $last): ?array
|
||||
{
|
||||
$stmt = db()->prepare('SELECT * FROM users WHERE first_name = ? AND last_name = ? LIMIT 1');
|
||||
$stmt->execute([trim($first), trim($last)]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
function auth_is_locked_out(string $first, string $last): bool
|
||||
{
|
||||
$window = (int) config('app.login_window_seconds', 900);
|
||||
$maxIp = (int) config('app.login_max_per_ip', 15);
|
||||
$maxName = (int) config('app.login_max_per_user', 5);
|
||||
|
||||
$stmt = db()->prepare('SELECT COUNT(*) FROM login_attempts WHERE ip = ? AND attempted_at >= ?');
|
||||
$stmt->execute([client_ip(), utc_after(-$window)]);
|
||||
if ((int) $stmt->fetchColumn() >= $maxIp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$stmt = db()->prepare('SELECT COUNT(*) FROM login_attempts WHERE name_key = ? AND attempted_at >= ?');
|
||||
$stmt->execute([auth_name_key($first, $last), utc_after(-$window)]);
|
||||
return (int) $stmt->fetchColumn() >= $maxName;
|
||||
}
|
||||
|
||||
function auth_record_failure(string $first, string $last): void
|
||||
{
|
||||
$stmt = db()->prepare('INSERT INTO login_attempts (ip, name_key, attempted_at) VALUES (?, ?, ?)');
|
||||
$stmt->execute([client_ip(), auth_name_key($first, $last), utc_now()]);
|
||||
|
||||
// Tabelle klein halten; nur das Ratenfenster ist relevant.
|
||||
$window = (int) config('app.login_window_seconds', 900);
|
||||
db()->prepare('DELETE FROM login_attempts WHERE attempted_at < ?')->execute([utc_after(-max($window * 8, 86400))]);
|
||||
}
|
||||
|
||||
function auth_verify_login(string $first, string $last, string $password): array
|
||||
{
|
||||
if (auth_is_locked_out($first, $last)) {
|
||||
throw new RuntimeException('locked');
|
||||
}
|
||||
|
||||
$user = auth_find_by_name($first, $last);
|
||||
$hash = $user['password_hash'] ?? DIC_DUMMY_HASH;
|
||||
$ok = password_verify($password, $hash);
|
||||
if (!$user || !$ok) {
|
||||
auth_record_failure($first, $last);
|
||||
throw new RuntimeException('invalid');
|
||||
}
|
||||
if ($user['status'] !== 'active') {
|
||||
auth_record_failure($first, $last);
|
||||
throw new RuntimeException('disabled');
|
||||
}
|
||||
if (password_needs_upgrade($hash)) {
|
||||
db()->prepare('UPDATE users SET password_hash = ?, updated_at = ? WHERE id = ?')
|
||||
->execute([hash_password($password), utc_now(), (int) $user['id']]);
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
||||
function auth_invalidate_sessions(int $userId): void
|
||||
{
|
||||
db()->prepare('UPDATE users SET auth_epoch = auth_epoch + 1, updated_at = ? WHERE id = ?')
|
||||
->execute([utc_now(), $userId]);
|
||||
db()->prepare('DELETE FROM auth_tokens WHERE user_id = ?')->execute([$userId]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------ Angemeldet bleiben */
|
||||
|
||||
function auth_issue_remember(int $userId): void
|
||||
{
|
||||
$selector = bin2hex(random_bytes(12));
|
||||
$validator = bin2hex(random_bytes(32));
|
||||
$lifetime = (int) config('app.remember_seconds', 7776000);
|
||||
|
||||
db()->prepare('DELETE FROM auth_tokens WHERE expires_at < ?')->execute([utc_now()]);
|
||||
$stmt = db()->prepare('INSERT INTO auth_tokens (user_id, selector, validator_hash, created_at, expires_at) VALUES (?, ?, ?, ?, ?)');
|
||||
$stmt->execute([$userId, $selector, hash('sha256', $validator), utc_now(), utc_after($lifetime)]);
|
||||
|
||||
setcookie(DIC_REMEMBER_COOKIE, $selector . '.' . $validator, [
|
||||
'expires' => time() + $lifetime,
|
||||
'path' => '/',
|
||||
'secure' => is_https(),
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax',
|
||||
]);
|
||||
}
|
||||
|
||||
function auth_forget_remember(): void
|
||||
{
|
||||
$raw = $_COOKIE[DIC_REMEMBER_COOKIE] ?? '';
|
||||
if (is_string($raw) && str_contains($raw, '.')) {
|
||||
[$selector] = explode('.', $raw, 2);
|
||||
if ($selector !== '') {
|
||||
db()->prepare('DELETE FROM auth_tokens WHERE selector = ?')->execute([$selector]);
|
||||
}
|
||||
}
|
||||
if (isset($_COOKIE[DIC_REMEMBER_COOKIE])) {
|
||||
setcookie(DIC_REMEMBER_COOKIE, '', [
|
||||
'expires' => time() - 3600,
|
||||
'path' => '/',
|
||||
'secure' => is_https(),
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax',
|
||||
]);
|
||||
unset($_COOKIE[DIC_REMEMBER_COOKIE]);
|
||||
}
|
||||
}
|
||||
|
||||
function auth_restore_from_remember(): void
|
||||
{
|
||||
$raw = $_COOKIE[DIC_REMEMBER_COOKIE] ?? '';
|
||||
if (!is_string($raw) || !preg_match('/^([a-f0-9]{24})\.([a-f0-9]{64})$/', $raw, $m)) {
|
||||
return;
|
||||
}
|
||||
$stmt = db()->prepare(
|
||||
'SELECT t.*, u.auth_epoch, u.status, u.must_change_password
|
||||
FROM auth_tokens t JOIN users u ON u.id = t.user_id
|
||||
WHERE t.selector = ? AND t.expires_at >= ? LIMIT 1'
|
||||
);
|
||||
$stmt->execute([$m[1], utc_now()]);
|
||||
$token = $stmt->fetch();
|
||||
if (!$token || !hash_equals((string) $token['validator_hash'], hash('sha256', $m[2]))) {
|
||||
auth_forget_remember();
|
||||
return;
|
||||
}
|
||||
if ($token['status'] !== 'active') {
|
||||
auth_forget_remember();
|
||||
return;
|
||||
}
|
||||
|
||||
// Token rotieren, damit ein gestohlenes Cookie nur einmal nutzbar ist.
|
||||
db()->prepare('DELETE FROM auth_tokens WHERE id = ?')->execute([(int) $token['id']]);
|
||||
session_regenerate_id(true);
|
||||
$_SESSION['uid'] = (int) $token['user_id'];
|
||||
$_SESSION['epoch'] = (int) $token['auth_epoch'];
|
||||
$_SESSION['created'] = time();
|
||||
$_SESSION['last_seen'] = time();
|
||||
$_SESSION['csrf'] = bin2hex(random_bytes(32));
|
||||
auth_issue_remember((int) $token['user_id']);
|
||||
}
|
||||
|
||||
function auth_can_manage(User|null|array $user): bool
|
||||
{
|
||||
return is_array($user) && ($user['role'] ?? '') === 'admin';
|
||||
}
|
||||
|
||||
function auth_employee_id(array $user): int
|
||||
{
|
||||
return (int) ($user['employee_id'] ?? 0);
|
||||
}
|
||||
|
||||
/** Offene Erinnerungen, die den Benutzer betreffen (für die Navigation). */
|
||||
function auth_reminder_badge(array $user): int
|
||||
{
|
||||
return reminder_open_count($user, add_days(today_iso(), 7));
|
||||
}
|
||||
57
app/bootstrap.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Drink it cold – Bootstrap.
|
||||
*
|
||||
* Lädt Konfiguration, Datenbank, Session und Helfer. Die Konfiguration mit
|
||||
* Zugangsdaten liegt in app/config.local.php und wird beim Deployment erzeugt.
|
||||
*/
|
||||
|
||||
define('DIC_ROOT', dirname(__DIR__));
|
||||
define('DIC_APP', __DIR__);
|
||||
|
||||
$configFile = DIC_APP . '/config.local.php';
|
||||
if (!is_file($configFile)) {
|
||||
http_response_code(500);
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
echo "Die Anwendung ist noch nicht konfiguriert (app/config.local.php fehlt).\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$GLOBALS['dic_config'] = require $configFile;
|
||||
|
||||
date_default_timezone_set('Europe/Berlin');
|
||||
ini_set('display_errors', '0');
|
||||
ini_set('log_errors', '1');
|
||||
|
||||
require DIC_APP . '/util.php';
|
||||
require DIC_APP . '/db.php';
|
||||
require DIC_APP . '/auth.php';
|
||||
require DIC_APP . '/data.php';
|
||||
require DIC_APP . '/mail.php';
|
||||
require DIC_APP . '/pages.php';
|
||||
require DIC_APP . '/admin.php';
|
||||
|
||||
$storage = (string) config('app.storage_path', DIC_ROOT . '/storage');
|
||||
if (is_dir($storage) && is_dir($storage . '/logs') && is_writable($storage . '/logs')) {
|
||||
ini_set('error_log', $storage . '/logs/php.log');
|
||||
}
|
||||
|
||||
set_exception_handler(static function (Throwable $error): void {
|
||||
error_log('Drink it cold: ' . $error::class . ': ' . $error->getMessage() . ' in ' . $error->getFile() . ':' . $error->getLine());
|
||||
if (function_exists('wants_json') && wants_json()) {
|
||||
json_response(['error' => ['code' => 'server_error', 'message' => 'Interner Fehler.']], 500);
|
||||
return;
|
||||
}
|
||||
http_response_code(500);
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
echo '<!doctype html><meta charset="utf-8"><title>Fehler 500</title>'
|
||||
. '<body style="font-family:system-ui;background:#f4f9fe;color:#0e1b26;padding:2rem">'
|
||||
. '<h1>Interner Fehler</h1><p>Bitte später erneut versuchen.</p></body>';
|
||||
});
|
||||
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
security_headers();
|
||||
start_session();
|
||||
}
|
||||
33
app/config.example.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* Beispielkonfiguration. Wird nicht ausgeliefert; beim Deployment erzeugt
|
||||
* tools/deploy.sh daraus app/config.local.php.
|
||||
*/
|
||||
return [
|
||||
'db' => [
|
||||
'host' => 'localhost',
|
||||
'port' => 3306,
|
||||
'name' => 'DB_NAME',
|
||||
'user' => 'DB_USER',
|
||||
'password' => 'DB_PASSWORD',
|
||||
'charset' => 'utf8mb4',
|
||||
],
|
||||
'app' => [
|
||||
// Leer, wenn die App direkt im DocumentRoot der Subdomain liegt.
|
||||
'base_path' => '',
|
||||
'public_url' => 'https://drink-it-cold.programmschmiede.de',
|
||||
'storage_path' => dirname(__DIR__) . '/storage',
|
||||
'install_token' => 'wird-beim-deployment-erzeugt',
|
||||
'session_idle_seconds' => 30 * 86400,
|
||||
'session_absolute_seconds' => 90 * 86400,
|
||||
'remember_seconds' => 90 * 86400,
|
||||
'login_window_seconds' => 900,
|
||||
'login_max_per_user' => 5,
|
||||
'login_max_per_ip' => 15,
|
||||
// Optionaler täglicher E-Mail-Digest (tools/send_reminders.php).
|
||||
'mail_enabled' => false,
|
||||
'mail_from' => 'Drink it cold <noreply@drink-it-cold.programmschmiede.de>',
|
||||
// Token für /cron/reminders?token=…, falls kein CLI-Cron möglich ist.
|
||||
'cron_token' => '',
|
||||
],
|
||||
];
|
||||
685
app/data.php
Normal file
|
|
@ -0,0 +1,685 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/** Anhänger, Mitarbeiter, Buchungen, Kalendergeometrie und Erinnerungen. */
|
||||
|
||||
/* --------------------------------------------------------------- Anhänger */
|
||||
|
||||
function trailers_all(bool $activeOnly = true): array
|
||||
{
|
||||
$sql = 'SELECT * FROM trailers' . ($activeOnly ? ' WHERE active = 1' : '') . ' ORDER BY sort_order, id';
|
||||
return db()->query($sql)->fetchAll();
|
||||
}
|
||||
|
||||
function trailers_map(bool $activeOnly = false): array
|
||||
{
|
||||
$out = [];
|
||||
foreach (trailers_all($activeOnly) as $trailer) {
|
||||
$out[(int) $trailer['id']] = $trailer;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function trailer_find(int $id): ?array
|
||||
{
|
||||
$stmt = db()->prepare('SELECT * FROM trailers WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ Mitarbeiter */
|
||||
|
||||
function employees_all(bool $activeOnly = true): array
|
||||
{
|
||||
$sql = 'SELECT * FROM employees' . ($activeOnly ? ' WHERE active = 1' : '') . ' ORDER BY sort_order, name';
|
||||
return db()->query($sql)->fetchAll();
|
||||
}
|
||||
|
||||
function employees_map(bool $activeOnly = false): array
|
||||
{
|
||||
$out = [];
|
||||
foreach (employees_all($activeOnly) as $employee) {
|
||||
$out[(int) $employee['id']] = $employee;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function employee_find(int $id): ?array
|
||||
{
|
||||
$stmt = db()->prepare('SELECT * FROM employees WHERE id = ?');
|
||||
$stmt->execute([$id]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- Buchungen */
|
||||
|
||||
const BOOKING_SELECT = 'SELECT b.*, t.label AS trailer_label, t.color_hex AS trailer_color,
|
||||
t.color_name AS trailer_color_name, t.sort_order AS trailer_sort,
|
||||
e.name AS employee_name
|
||||
FROM bookings b
|
||||
JOIN trailers t ON t.id = b.trailer_id
|
||||
JOIN employees e ON e.id = b.employee_id';
|
||||
|
||||
function booking_find(int $id): ?array
|
||||
{
|
||||
$stmt = db()->prepare(BOOKING_SELECT . ' WHERE b.id = ? LIMIT 1');
|
||||
$stmt->execute([$id]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/** Aktive (und optional stornierte) Buchungen, die den Zeitraum berühren. */
|
||||
function booking_list(string $from, string $to, bool $includeCancelled = false, int $employeeId = 0): array
|
||||
{
|
||||
$sql = BOOKING_SELECT . ' WHERE b.start_date <= ? AND b.end_date >= ?';
|
||||
$params = [$to, $from];
|
||||
if (!$includeCancelled) {
|
||||
$sql .= " AND b.status = 'active'";
|
||||
}
|
||||
if ($employeeId > 0) {
|
||||
$sql .= ' AND b.employee_id = ?';
|
||||
$params[] = $employeeId;
|
||||
}
|
||||
$sql .= ' ORDER BY t.sort_order, b.start_date, b.end_date, b.id';
|
||||
$stmt = db()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
function booking_search(string $query, int $limit = 100): array
|
||||
{
|
||||
$query = trim($query);
|
||||
if ($query === '') {
|
||||
return [];
|
||||
}
|
||||
$like = '%' . addcslashes($query, '%_\\') . '%';
|
||||
$stmt = db()->prepare(
|
||||
BOOKING_SELECT . ' WHERE b.customer_name LIKE ? OR b.city LIKE ? OR b.street LIKE ?
|
||||
ORDER BY b.start_date DESC, b.id DESC LIMIT ' . max(1, min(200, $limit))
|
||||
);
|
||||
$stmt->execute([$like, $like, $like]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
function booking_conflicts(int $trailerId, string $start, string $end, int $excludeId = 0): array
|
||||
{
|
||||
$stmt = db()->prepare(
|
||||
BOOKING_SELECT . " WHERE b.trailer_id = ? AND b.status = 'active'
|
||||
AND b.start_date < ? AND b.end_date > ? AND b.id <> ?
|
||||
ORDER BY b.start_date"
|
||||
);
|
||||
$stmt->execute([$trailerId, $end, $start, $excludeId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/** Formulardaten in ein normalisiertes Array übersetzen. */
|
||||
function booking_input(array $source): array
|
||||
{
|
||||
$kind = (string) ($source['kind'] ?? 'pickup');
|
||||
return [
|
||||
'trailer_id' => (int) ($source['trailer_id'] ?? 0),
|
||||
'employee_id' => (int) ($source['employee_id'] ?? 0),
|
||||
'start_date' => trim((string) ($source['start_date'] ?? '')),
|
||||
'end_date' => trim((string) ($source['end_date'] ?? '')),
|
||||
'deposit_cents' => parse_money((string) ($source['deposit'] ?? '0')),
|
||||
'total_cents' => parse_money((string) ($source['total'] ?? '0')),
|
||||
'invoice' => ((string) ($source['invoice'] ?? '0')) === '1' ? 1 : 0,
|
||||
'kind' => in_array($kind, ['pickup', 'delivery'], true) ? $kind : 'pickup',
|
||||
'customer_name' => trim((string) ($source['customer_name'] ?? '')),
|
||||
'street' => trim((string) ($source['street'] ?? '')),
|
||||
'city' => trim((string) ($source['city'] ?? '')),
|
||||
'mobile' => trim((string) ($source['mobile'] ?? '')),
|
||||
'email' => trim((string) ($source['email'] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId = 0, int $allowEmployeeId = 0): array
|
||||
{
|
||||
$errors = [];
|
||||
|
||||
$trailer = $data['trailer_id'] > 0 ? trailer_find((int) $data['trailer_id']) : null;
|
||||
if (!$trailer || ((int) $trailer['active'] !== 1 && (int) $trailer['id'] !== $allowTrailerId)) {
|
||||
$errors['trailer_id'] = 'Bitte einen Kühlanhänger auswählen.';
|
||||
}
|
||||
|
||||
$employee = $data['employee_id'] > 0 ? employee_find((int) $data['employee_id']) : null;
|
||||
if (!$employee || ((int) $employee['active'] !== 1 && (int) $employee['id'] !== $allowEmployeeId)) {
|
||||
$errors['employee_id'] = 'Bitte einen zuständigen Mitarbeiter auswählen.';
|
||||
}
|
||||
|
||||
if (!valid_date($data['start_date'])) {
|
||||
$errors['start_date'] = 'Bitte ein gültiges Mietbeginn-Datum angeben.';
|
||||
}
|
||||
if (!valid_date($data['end_date'])) {
|
||||
$errors['end_date'] = 'Bitte ein gültiges Mietende-Datum angeben.';
|
||||
}
|
||||
if (!isset($errors['start_date']) && !isset($errors['end_date'])) {
|
||||
if ($data['end_date'] < $data['start_date']) {
|
||||
$errors['end_date'] = 'Das Mietende darf nicht vor dem Mietbeginn liegen.';
|
||||
} elseif (days_between($data['start_date'], $data['end_date']) > 365) {
|
||||
$errors['end_date'] = 'Der Mietzeitraum darf höchstens 365 Tage betragen.';
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['customer_name'] === '') {
|
||||
$errors['customer_name'] = 'Bitte den Kundennamen angeben.';
|
||||
} elseif (mb_strlen($data['customer_name']) > 190) {
|
||||
$errors['customer_name'] = 'Der Kundenname ist zu lang (max. 190 Zeichen).';
|
||||
}
|
||||
foreach (['street' => 'Straße', 'city' => 'Ort', 'mobile' => 'Handy'] as $field => $label) {
|
||||
if (mb_strlen((string) $data[$field]) > 190) {
|
||||
$errors[$field] = $label . ' ist zu lang (max. 190 Zeichen).';
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['email'] !== '') {
|
||||
if (mb_strlen($data['email']) > 190) {
|
||||
$errors['email'] = 'Die E-Mail-Adresse ist zu lang.';
|
||||
} elseif (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$errors['email'] = 'Bitte eine gültige E-Mail-Adresse angeben.';
|
||||
}
|
||||
}
|
||||
|
||||
$maxAmount = 10000000; // 100.000,00 €
|
||||
if ($data['total_cents'] < 0 || $data['deposit_cents'] < 0) {
|
||||
$errors['total'] = 'Beträge dürfen nicht negativ sein.';
|
||||
} elseif ($data['total_cents'] > $maxAmount || $data['deposit_cents'] > $maxAmount) {
|
||||
$errors['total'] = 'Der Betrag ist unrealistisch hoch.';
|
||||
} elseif ($data['deposit_cents'] > $data['total_cents']) {
|
||||
$errors['deposit'] = 'Die Anzahlung darf den Gesamtbetrag nicht übersteigen.';
|
||||
}
|
||||
|
||||
if (!$errors && $trailer) {
|
||||
$conflicts = booking_conflicts((int) $trailer['id'], $data['start_date'], $data['end_date'], $excludeId);
|
||||
if ($conflicts) {
|
||||
$c = $conflicts[0];
|
||||
$errors['period'] = sprintf(
|
||||
'%s ist vom %s bis %s bereits an %s vergeben. Ein Wechseltag (letzter Tag = erster Tag) ist erlaubt.',
|
||||
$trailer['label'],
|
||||
fmt_date($c['start_date']),
|
||||
fmt_date($c['end_date']),
|
||||
$c['customer_name']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/** Serialisiert Änderungen pro Anhänger, damit parallele Buchungen nicht kollidieren. */
|
||||
function booking_lock_trailers(array $trailerIds): void
|
||||
{
|
||||
$ids = array_values(array_unique(array_map('intval', $trailerIds)));
|
||||
if (!$ids) {
|
||||
return;
|
||||
}
|
||||
sort($ids);
|
||||
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
||||
$stmt = db()->prepare("SELECT id FROM trailers WHERE id IN ($placeholders) ORDER BY id FOR UPDATE");
|
||||
$stmt->execute($ids);
|
||||
$stmt->fetchAll();
|
||||
}
|
||||
|
||||
function booking_create(array $data, int $userId): int
|
||||
{
|
||||
$pdo = db();
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
booking_lock_trailers([$data['trailer_id']]);
|
||||
$errors = booking_validate($data);
|
||||
if ($errors) {
|
||||
throw new InvalidArgumentException(json_encode($errors, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO bookings
|
||||
(trailer_id, employee_id, start_date, end_date, deposit_cents, total_cents, invoice, kind,
|
||||
customer_name, street, city, mobile, email, status, created_at, updated_at, created_by, updated_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "active", ?, ?, ?, ?)'
|
||||
);
|
||||
$stmt->execute([
|
||||
$data['trailer_id'], $data['employee_id'], $data['start_date'], $data['end_date'],
|
||||
$data['deposit_cents'], $data['total_cents'], $data['invoice'], $data['kind'],
|
||||
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
|
||||
utc_now(), utc_now(), $userId, $userId,
|
||||
]);
|
||||
$id = (int) $pdo->lastInsertId();
|
||||
$pdo->commit();
|
||||
return $id;
|
||||
} catch (Throwable $error) {
|
||||
$pdo->rollBack();
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
||||
function booking_update(int $id, array $data, int $userId): void
|
||||
{
|
||||
$existing = booking_find($id);
|
||||
if (!$existing) {
|
||||
throw new RuntimeException('not_found');
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
booking_lock_trailers([(int) $existing['trailer_id'], (int) $data['trailer_id']]);
|
||||
$errors = booking_validate($data, $id, (int) $existing['trailer_id'], (int) $existing['employee_id']);
|
||||
if ($errors) {
|
||||
throw new InvalidArgumentException(json_encode($errors, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$stmt = $pdo->prepare(
|
||||
'UPDATE bookings SET trailer_id = ?, employee_id = ?, start_date = ?, end_date = ?,
|
||||
deposit_cents = ?, total_cents = ?, invoice = ?, kind = ?, customer_name = ?, street = ?,
|
||||
city = ?, mobile = ?, email = ?, updated_at = ?, updated_by = ? WHERE id = ?'
|
||||
);
|
||||
$stmt->execute([
|
||||
$data['trailer_id'], $data['employee_id'], $data['start_date'], $data['end_date'],
|
||||
$data['deposit_cents'], $data['total_cents'], $data['invoice'], $data['kind'],
|
||||
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
|
||||
utc_now(), $userId, $id,
|
||||
]);
|
||||
$pdo->commit();
|
||||
} catch (Throwable $error) {
|
||||
$pdo->rollBack();
|
||||
throw $error;
|
||||
}
|
||||
|
||||
// Wechselt der zuständige Mitarbeiter, gehören die Erinnerungen (inkl.
|
||||
// Erledigt-Status und Versandprotokoll) dem neuen Mitarbeiter.
|
||||
if ((int) $existing['employee_id'] !== (int) $data['employee_id']) {
|
||||
db()->prepare('DELETE FROM reminder_done WHERE booking_id = ?')->execute([$id]);
|
||||
db()->prepare('DELETE FROM reminder_mail_log WHERE booking_id = ?')->execute([$id]);
|
||||
}
|
||||
|
||||
// Abgehakte Erinnerungen gelten nur für ihr Fälligkeitsdatum. Bleibt das
|
||||
// Datum gleich, bleibt auch der Haken; sonst öffnet die Erinnerung wieder.
|
||||
db()->prepare(
|
||||
'DELETE rd FROM reminder_done rd
|
||||
JOIN bookings b ON b.id = rd.booking_id
|
||||
WHERE rd.booking_id = ? AND (
|
||||
(rd.kind = "start_8" AND rd.due_date <> DATE_SUB(b.start_date, INTERVAL 8 DAY)) OR
|
||||
(rd.kind = "start_1" AND rd.due_date <> DATE_SUB(b.start_date, INTERVAL 1 DAY)) OR
|
||||
(rd.kind = "end_1" AND rd.due_date <> DATE_SUB(b.end_date, INTERVAL 1 DAY))
|
||||
)'
|
||||
)->execute([$id]);
|
||||
}
|
||||
|
||||
function booking_cancel(int $id, int $userId): void
|
||||
{
|
||||
db()->prepare(
|
||||
"UPDATE bookings SET status = 'cancelled', cancelled_at = ?, cancelled_by = ?, updated_at = ?, updated_by = ?
|
||||
WHERE id = ? AND status = 'active'"
|
||||
)->execute([utc_now(), $userId, utc_now(), $userId, $id]);
|
||||
}
|
||||
|
||||
function booking_restore(int $id, int $userId): array
|
||||
{
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
throw new RuntimeException('not_found');
|
||||
}
|
||||
$errors = booking_validate([
|
||||
'trailer_id' => (int) $booking['trailer_id'],
|
||||
'employee_id' => (int) $booking['employee_id'],
|
||||
'start_date' => $booking['start_date'],
|
||||
'end_date' => $booking['end_date'],
|
||||
'deposit_cents' => (int) $booking['deposit_cents'],
|
||||
'total_cents' => (int) $booking['total_cents'],
|
||||
'invoice' => (int) $booking['invoice'],
|
||||
'kind' => $booking['kind'],
|
||||
'customer_name' => $booking['customer_name'],
|
||||
'street' => $booking['street'],
|
||||
'city' => $booking['city'],
|
||||
'mobile' => $booking['mobile'],
|
||||
'email' => $booking['email'],
|
||||
], $id, (int) $booking['trailer_id'], (int) $booking['employee_id']);
|
||||
if ($errors) {
|
||||
return $errors;
|
||||
}
|
||||
db()->prepare(
|
||||
"UPDATE bookings SET status = 'active', cancelled_at = NULL, cancelled_by = NULL,
|
||||
updated_at = ?, updated_by = ? WHERE id = ?"
|
||||
)->execute([utc_now(), $userId, $id]);
|
||||
db()->prepare('DELETE FROM reminder_done WHERE booking_id = ?')->execute([$id]);
|
||||
return [];
|
||||
}
|
||||
|
||||
function booking_delete(int $id): void
|
||||
{
|
||||
db()->prepare('DELETE FROM bookings WHERE id = ?')->execute([$id]);
|
||||
}
|
||||
|
||||
/** Drag & Drop: Beginn verschieben, Dauer beibehalten, optional Anhänger wechseln. */
|
||||
function booking_move(int $id, string $newStart, int $newTrailerId, int $userId): array
|
||||
{
|
||||
$booking = booking_find($id);
|
||||
if (!$booking || $booking['status'] !== 'active') {
|
||||
return ['error' => 'Diese Buchung kann nicht verschoben werden.'];
|
||||
}
|
||||
if (!valid_date($newStart)) {
|
||||
return ['error' => 'Ungültiges Datum.'];
|
||||
}
|
||||
$duration = days_between((string) $booking['start_date'], (string) $booking['end_date']);
|
||||
$newEnd = add_days($newStart, $duration);
|
||||
$trailer = trailer_find($newTrailerId);
|
||||
if (!$trailer || (int) $trailer['active'] !== 1) {
|
||||
return ['error' => 'Bitte einen gültigen Kühlanhänger wählen.'];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'trailer_id' => $newTrailerId,
|
||||
'employee_id' => (int) $booking['employee_id'],
|
||||
'start_date' => $newStart,
|
||||
'end_date' => $newEnd,
|
||||
'deposit_cents' => (int) $booking['deposit_cents'],
|
||||
'total_cents' => (int) $booking['total_cents'],
|
||||
'invoice' => (int) $booking['invoice'],
|
||||
'kind' => (string) $booking['kind'],
|
||||
'customer_name' => (string) $booking['customer_name'],
|
||||
'street' => (string) $booking['street'],
|
||||
'city' => (string) $booking['city'],
|
||||
'mobile' => (string) $booking['mobile'],
|
||||
'email' => (string) $booking['email'],
|
||||
];
|
||||
|
||||
$pdo = db();
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
booking_lock_trailers([(int) $booking['trailer_id'], $newTrailerId]);
|
||||
$errors = booking_validate($data, $id, 0, (int) $booking['employee_id']);
|
||||
if ($errors) {
|
||||
$pdo->rollBack();
|
||||
return ['error' => reset($errors) ?: 'Der neue Zeitraum ist belegt.'];
|
||||
}
|
||||
$pdo->prepare(
|
||||
'UPDATE bookings SET trailer_id = ?, start_date = ?, end_date = ?, updated_at = ?, updated_by = ? WHERE id = ?'
|
||||
)->execute([$newTrailerId, $newStart, $newEnd, utc_now(), $userId, $id]);
|
||||
$pdo->commit();
|
||||
} catch (Throwable $error) {
|
||||
$pdo->rollBack();
|
||||
throw $error;
|
||||
}
|
||||
|
||||
db()->prepare(
|
||||
'DELETE rd FROM reminder_done rd
|
||||
JOIN bookings b ON b.id = rd.booking_id
|
||||
WHERE rd.booking_id = ? AND (
|
||||
(rd.kind = "start_8" AND rd.due_date <> DATE_SUB(b.start_date, INTERVAL 8 DAY)) OR
|
||||
(rd.kind = "start_1" AND rd.due_date <> DATE_SUB(b.start_date, INTERVAL 1 DAY)) OR
|
||||
(rd.kind = "end_1" AND rd.due_date <> DATE_SUB(b.end_date, INTERVAL 1 DAY))
|
||||
)'
|
||||
)->execute([$id]);
|
||||
|
||||
$fresh = booking_find($id);
|
||||
return [
|
||||
'ok' => true,
|
||||
'booking' => $fresh,
|
||||
'start_date' => $fresh['start_date'],
|
||||
'end_date' => $fresh['end_date'],
|
||||
'trailer_id' => (int) $fresh['trailer_id'],
|
||||
];
|
||||
}
|
||||
|
||||
function booking_kind_label(string $kind): string
|
||||
{
|
||||
return $kind === 'delivery' ? 'Lieferung' : 'Abholer';
|
||||
}
|
||||
|
||||
function booking_invoice_label(int|string $invoice): string
|
||||
{
|
||||
return (int) $invoice === 1 ? 'JA' : 'NEIN';
|
||||
}
|
||||
|
||||
/** Exakt der Text aus der Anforderung, Zeile für Zeile. */
|
||||
function booking_copy_text(array $booking): string
|
||||
{
|
||||
return implode("\n", [
|
||||
'Anzahlung: ' . fmt_money((int) $booking['deposit_cents']),
|
||||
'Gesamtbetrag: ' . fmt_money((int) $booking['total_cents']),
|
||||
'Noch zu zahlen: ' . fmt_money(due_cents((int) $booking['total_cents'], (int) $booking['deposit_cents'])),
|
||||
'Rechnung: ' . booking_invoice_label($booking['invoice']),
|
||||
'Von: ' . fmt_date_short((string) $booking['start_date']),
|
||||
'Bis: ' . fmt_date_short((string) $booking['end_date']),
|
||||
'Art: ' . booking_kind_label((string) $booking['kind']),
|
||||
'Name: ' . $booking['customer_name'],
|
||||
'Straße: ' . $booking['street'],
|
||||
'Ort: ' . $booking['city'],
|
||||
'Handy: ' . $booking['mobile'],
|
||||
'E-Mail: ' . $booking['email'],
|
||||
]);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- Erinnerungen */
|
||||
|
||||
function reminder_kinds(): array
|
||||
{
|
||||
return [
|
||||
'start_8' => [
|
||||
'label' => 'Übergabetermin vereinbaren',
|
||||
'short' => '8 Tage vor Mietbeginn',
|
||||
'message' => 'Bitte mit dem Kunden einen Übergabetermin für den Kühlanhänger vereinbaren.',
|
||||
'anchor' => 'start',
|
||||
'offset' => -8,
|
||||
],
|
||||
'start_1' => [
|
||||
'label' => 'Übergabe / Lieferung',
|
||||
'short' => '1 Tag vor Mietbeginn',
|
||||
'message' => 'Morgen steht die Übergabe bzw. Lieferung des Kühlanhängers an.',
|
||||
'anchor' => 'start',
|
||||
'offset' => -1,
|
||||
],
|
||||
'end_1' => [
|
||||
'label' => 'Abholung / Rücknahme',
|
||||
'short' => '1 Tag vor Mietende',
|
||||
'message' => 'Morgen muss der Kühlanhänger beim Kunden abgeholt bzw. zurückgenommen werden.',
|
||||
'anchor' => 'end',
|
||||
'offset' => -1,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
function booking_reminders(array $booking): array
|
||||
{
|
||||
$rows = [];
|
||||
foreach (reminder_kinds() as $kind => $meta) {
|
||||
$anchor = $meta['anchor'] === 'start' ? (string) $booking['start_date'] : (string) $booking['end_date'];
|
||||
$rows[] = [
|
||||
'kind' => $kind,
|
||||
'label' => $meta['label'],
|
||||
'short' => $meta['short'],
|
||||
'message' => $meta['message'],
|
||||
'due_date' => add_days($anchor, (int) $meta['offset']),
|
||||
];
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** @return array<string,bool> Schlüssel: bookingId:kind:dueDate */
|
||||
function reminder_done_map(array $bookingIds): array
|
||||
{
|
||||
if (!$bookingIds) {
|
||||
return [];
|
||||
}
|
||||
$ids = array_values(array_unique(array_map('intval', $bookingIds)));
|
||||
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
||||
$stmt = db()->prepare("SELECT booking_id, kind, due_date FROM reminder_done WHERE booking_id IN ($placeholders)");
|
||||
$stmt->execute($ids);
|
||||
$out = [];
|
||||
foreach ($stmt->fetchAll() as $row) {
|
||||
$out[$row['booking_id'] . ':' . $row['kind'] . ':' . $row['due_date']] = true;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
function reminder_done_key(array $booking, string $kind, string $dueDate): string
|
||||
{
|
||||
return (int) $booking['id'] . ':' . $kind . ':' . $dueDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle fälligen Erinnerungen im Zeitraum. Erinnerungen werden aus den
|
||||
* Buchungsdaten berechnet und sind damit bei Terminänderungen automatisch
|
||||
* aktuell; eine Stornierung entfernt sie, weil nur aktive Buchungen zählen.
|
||||
*/
|
||||
function reminder_list(string $from, string $to, int $employeeId = 0, bool $includeDone = false): array
|
||||
{
|
||||
if ($from > $to) {
|
||||
[$from, $to] = [$to, $from];
|
||||
}
|
||||
$sql = BOOKING_SELECT . " WHERE b.status = 'active' AND b.start_date <= ? AND b.end_date >= ?";
|
||||
$params = [add_days($to, 8), add_days($from, -2)];
|
||||
if ($employeeId > 0) {
|
||||
$sql .= ' AND b.employee_id = ?';
|
||||
$params[] = $employeeId;
|
||||
}
|
||||
$sql .= ' ORDER BY b.start_date, b.id';
|
||||
$stmt = db()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$bookings = $stmt->fetchAll();
|
||||
|
||||
$done = reminder_done_map(array_column($bookings, 'id'));
|
||||
$rows = [];
|
||||
foreach ($bookings as $booking) {
|
||||
foreach (booking_reminders($booking) as $reminder) {
|
||||
if ($reminder['due_date'] < $from || $reminder['due_date'] > $to) {
|
||||
continue;
|
||||
}
|
||||
$isDone = isset($done[reminder_done_key($booking, $reminder['kind'], $reminder['due_date'])]);
|
||||
if ($isDone && !$includeDone) {
|
||||
continue;
|
||||
}
|
||||
$rows[] = $reminder + [
|
||||
'booking' => $booking,
|
||||
'done' => $isDone,
|
||||
];
|
||||
}
|
||||
}
|
||||
usort($rows, static function (array $a, array $b): int {
|
||||
return [$a['due_date'], $a['booking']['trailer_sort'], $a['kind']]
|
||||
<=> [$b['due_date'], $b['booking']['trailer_sort'], $b['kind']];
|
||||
});
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** Sichtbarkeit: Admins sehen alles, Mitarbeiter nur ihre Buchungen. */
|
||||
function reminder_scope_employee(array $user): int
|
||||
{
|
||||
return ($user['role'] ?? '') === 'admin' ? 0 : auth_employee_id($user);
|
||||
}
|
||||
|
||||
function reminder_open_count(array $user, string $until, string $from = ''): int
|
||||
{
|
||||
if ($from === '') {
|
||||
$from = add_days(today_iso(), -30);
|
||||
}
|
||||
$rows = reminder_list($from, $until, reminder_scope_employee($user), false);
|
||||
return count($rows);
|
||||
}
|
||||
|
||||
function reminder_done_set(int $bookingId, string $kind, bool $done, int $userId): bool
|
||||
{
|
||||
$booking = booking_find($bookingId);
|
||||
if (!$booking || $booking['status'] !== 'active') {
|
||||
return false;
|
||||
}
|
||||
$row = null;
|
||||
foreach (booking_reminders($booking) as $reminder) {
|
||||
if ($reminder['kind'] === $kind) {
|
||||
$row = $reminder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($row === null) {
|
||||
return false;
|
||||
}
|
||||
if ($done) {
|
||||
$stmt = db()->prepare(
|
||||
'INSERT INTO reminder_done (booking_id, kind, due_date, done_by, done_at) VALUES (?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE done_by = VALUES(done_by), done_at = VALUES(done_at)'
|
||||
);
|
||||
$stmt->execute([$bookingId, $kind, $row['due_date'], $userId, utc_now()]);
|
||||
} else {
|
||||
db()->prepare('DELETE FROM reminder_done WHERE booking_id = ? AND kind = ? AND due_date = ?')
|
||||
->execute([$bookingId, $kind, $row['due_date']]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------- Kalendergeometrie */
|
||||
|
||||
/**
|
||||
* Verteilt Buchungen einer Zeile auf Lanes. Ein Wechseltag (eine Buchung endet,
|
||||
* eine andere beginnt am selben Tag) ist erlaubt und wird als zweite Lane
|
||||
* dargestellt, damit beide Balken sichtbar bleiben.
|
||||
*
|
||||
* @return array{bookings: array, lanes: int}
|
||||
*/
|
||||
function calendar_lanes(array $bookings): array
|
||||
{
|
||||
usort($bookings, static function (array $a, array $b): int {
|
||||
return [(string) $a['start_date'], (string) $a['end_date'], (int) $a['id']]
|
||||
<=> [(string) $b['start_date'], (string) $b['end_date'], (int) $b['id']];
|
||||
});
|
||||
|
||||
$laneEnds = [];
|
||||
$out = [];
|
||||
foreach ($bookings as $booking) {
|
||||
$lane = 0;
|
||||
while (isset($laneEnds[$lane]) && $laneEnds[$lane] >= $booking['start_date']) {
|
||||
$lane++;
|
||||
}
|
||||
$laneEnds[$lane] = $booking['end_date'];
|
||||
$booking['_lane'] = $lane;
|
||||
$out[] = $booking;
|
||||
}
|
||||
return ['bookings' => $out, 'lanes' => max(1, count($laneEnds))];
|
||||
}
|
||||
|
||||
/** Position eines Balkens im sichtbaren Zeitraum (Prozent). */
|
||||
function calendar_geometry(array $booking, string $from, string $to, int $lanes): array
|
||||
{
|
||||
$total = max(1, days_between($from, $to) + 1);
|
||||
$start = max((string) $booking['start_date'], $from);
|
||||
$end = min((string) $booking['end_date'], $to);
|
||||
$offset = max(0, days_between($from, $start));
|
||||
$span = max(1, days_between($start, $end) + 1);
|
||||
$lane = (int) ($booking['_lane'] ?? 0);
|
||||
return [
|
||||
'left' => $offset / $total * 100,
|
||||
'width' => $span / $total * 100,
|
||||
'top' => $lane / $lanes * 100,
|
||||
'height' => 100 / $lanes,
|
||||
'span' => $span,
|
||||
'cut_start' => (string) $booking['start_date'] < $from,
|
||||
'cut_end' => (string) $booking['end_date'] > $to,
|
||||
];
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- Auswertung */
|
||||
|
||||
function bookings_by_date(string $date): array
|
||||
{
|
||||
return booking_list($date, $date, false);
|
||||
}
|
||||
|
||||
/** Nächste Übergaben und Rücknahmen ab heute. */
|
||||
function upcoming_handovers(int $days = 14, int $employeeId = 0): array
|
||||
{
|
||||
$today = today_iso();
|
||||
$until = add_days($today, $days);
|
||||
$bookings = booking_list($today, $until, false, $employeeId);
|
||||
$events = [];
|
||||
foreach ($bookings as $booking) {
|
||||
if ($booking['start_date'] >= $today && $booking['start_date'] <= $until) {
|
||||
$events[] = ['type' => 'handover', 'date' => $booking['start_date'], 'booking' => $booking];
|
||||
}
|
||||
if ($booking['end_date'] >= $today && $booking['end_date'] <= $until) {
|
||||
$events[] = ['type' => 'return', 'date' => $booking['end_date'], 'booking' => $booking];
|
||||
}
|
||||
}
|
||||
usort($events, static function (array $a, array $b): int {
|
||||
return [$a['date'], $a['type']] <=> [$b['date'], $b['type']];
|
||||
});
|
||||
return $events;
|
||||
}
|
||||
28
app/db.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
function db(): PDO
|
||||
{
|
||||
static $pdo = null;
|
||||
if ($pdo instanceof PDO) {
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
$db = (array) config('db', []);
|
||||
$dsn = sprintf(
|
||||
'mysql:host=%s;port=%d;dbname=%s;charset=%s',
|
||||
(string) ($db['host'] ?? 'localhost'),
|
||||
(int) ($db['port'] ?? 3306),
|
||||
(string) ($db['name'] ?? ''),
|
||||
(string) ($db['charset'] ?? 'utf8mb4')
|
||||
);
|
||||
|
||||
$pdo = new PDO($dsn, (string) ($db['user'] ?? ''), (string) ($db['password'] ?? ''), [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||
]);
|
||||
$pdo->exec("SET time_zone = '+00:00'");
|
||||
return $pdo;
|
||||
}
|
||||
122
app/mail.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Optionaler täglicher E-Mail-Digest für fällige Erinnerungen.
|
||||
*
|
||||
* Die In-App-Erinnerungen sind immer vorhanden. Dieser Versand ist zusätzlich
|
||||
* und wird über tools/send_reminders.php (Cron) oder /cron/reminders?token=…
|
||||
* ausgelöst. Jede Erinnerung wird genau einmal verschickt; das Protokoll steht
|
||||
* in reminder_mail_log.
|
||||
*/
|
||||
|
||||
function reminder_mail_recipients(): array
|
||||
{
|
||||
$sql = "SELECT u.employee_id, u.email, u.first_name, u.last_name, e.name AS employee_name
|
||||
FROM users u JOIN employees e ON e.id = u.employee_id
|
||||
WHERE u.status = 'active' AND u.employee_id IS NOT NULL AND u.email IS NOT NULL AND u.email <> ''
|
||||
ORDER BY e.sort_order";
|
||||
$out = [];
|
||||
foreach (db()->query($sql)->fetchAll() as $row) {
|
||||
$out[(int) $row['employee_id']] = $row;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verschickt alle offenen, heute (oder in den letzten 7 Tagen) fälligen
|
||||
* Erinnerungen als einen Digest pro Mitarbeiter.
|
||||
*
|
||||
* @return array{enabled: bool, sent: int, skipped: int, errors: array, details: array}
|
||||
*/
|
||||
function reminder_send_due(int $lookbackDays = 7): array
|
||||
{
|
||||
$result = ['enabled' => (bool) config('app.mail_enabled', false), 'sent' => 0, 'skipped' => 0, 'errors' => [], 'details' => []];
|
||||
if (!$result['enabled']) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$today = today_iso();
|
||||
$from = add_days($today, -max(1, $lookbackDays));
|
||||
$recipients = reminder_mail_recipients();
|
||||
$rows = reminder_list($from, $today, 0, false);
|
||||
if (!$rows) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$byEmployee = [];
|
||||
foreach ($rows as $row) {
|
||||
$employeeId = (int) $row['booking']['employee_id'];
|
||||
if (!isset($recipients[$employeeId])) {
|
||||
$result['skipped']++;
|
||||
continue;
|
||||
}
|
||||
// Bereits verschickt?
|
||||
$stmt = db()->prepare('SELECT 1 FROM reminder_mail_log WHERE booking_id = ? AND kind = ? AND due_date = ?');
|
||||
$stmt->execute([(int) $row['booking']['id'], $row['kind'], $row['due_date']]);
|
||||
if ($stmt->fetchColumn()) {
|
||||
$result['skipped']++;
|
||||
continue;
|
||||
}
|
||||
$byEmployee[$employeeId][] = $row;
|
||||
}
|
||||
|
||||
$fromHeader = (string) config('app.mail_from', 'Drink it cold <noreply@localhost>');
|
||||
$appUrl = rtrim((string) config('app.public_url', ''), '/');
|
||||
|
||||
foreach ($byEmployee as $employeeId => $items) {
|
||||
$recipient = $recipients[$employeeId];
|
||||
$lines = [
|
||||
'Guten Tag ' . $recipient['employee_name'] . ',',
|
||||
'',
|
||||
'diese Erinnerungen stehen an:',
|
||||
'',
|
||||
];
|
||||
foreach ($items as $item) {
|
||||
$booking = $item['booking'];
|
||||
$lines[] = '• ' . fmt_date($item['due_date']) . ' – ' . $item['label'];
|
||||
$lines[] = ' ' . $item['message'];
|
||||
$lines[] = ' ' . $booking['customer_name'] . ', ' . $booking['trailer_label'] . ' (' . $booking['trailer_color_name'] . ')';
|
||||
$lines[] = ' Miete: ' . fmt_date($booking['start_date']) . ' bis ' . fmt_date($booking['end_date']);
|
||||
if ($appUrl !== '') {
|
||||
$lines[] = ' ' . $appUrl . '/bookings/' . (int) $booking['id'];
|
||||
}
|
||||
$lines[] = '';
|
||||
}
|
||||
$lines[] = 'Diese Nachricht wurde automatisch von der Terminplanung erzeugt.';
|
||||
$body = implode("\n", $lines);
|
||||
$subject = 'Drink it cold – ' . count($items) . ' fällige Erinnerung' . (count($items) === 1 ? '' : 'en');
|
||||
|
||||
$headers = [
|
||||
'From: ' . $fromHeader,
|
||||
'MIME-Version: 1.0',
|
||||
'Content-Type: text/plain; charset=UTF-8',
|
||||
'Content-Transfer-Encoding: 8bit',
|
||||
];
|
||||
$ok = @mail(
|
||||
(string) $recipient['email'],
|
||||
mb_encode_mimeheader($subject, 'UTF-8', 'B'),
|
||||
$body,
|
||||
implode("\r\n", $headers)
|
||||
);
|
||||
if (!$ok) {
|
||||
$result['errors'][] = 'Versand an ' . $recipient['email'] . ' fehlgeschlagen.';
|
||||
continue;
|
||||
}
|
||||
|
||||
$log = db()->prepare(
|
||||
'INSERT IGNORE INTO reminder_mail_log (booking_id, kind, due_date, employee_id, sent_to, sent_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)'
|
||||
);
|
||||
foreach ($items as $item) {
|
||||
$log->execute([
|
||||
(int) $item['booking']['id'], $item['kind'], $item['due_date'],
|
||||
$employeeId, (string) $recipient['email'], utc_now(),
|
||||
]);
|
||||
$result['sent']++;
|
||||
}
|
||||
$result['details'][] = $recipient['email'] . ' (' . count($items) . ')';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
789
app/pages.php
Normal file
|
|
@ -0,0 +1,789 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/** Web-Oberfläche: Anmeldung, Übersicht, Kalender, Buchungen, Erinnerungen. */
|
||||
|
||||
function render_page(string $template, array $vars, string $pageTitle): void
|
||||
{
|
||||
$user = auth_user();
|
||||
$contentFile = DIC_ROOT . '/views/' . $template . '.php';
|
||||
if (!is_file($contentFile)) {
|
||||
throw new RuntimeException('View fehlt: ' . $template);
|
||||
}
|
||||
extract($vars, EXTR_SKIP);
|
||||
$title = $pageTitle;
|
||||
ob_start();
|
||||
require $contentFile;
|
||||
$content = (string) ob_get_clean();
|
||||
require DIC_ROOT . '/views/layout.php';
|
||||
}
|
||||
|
||||
function render_partial(string $template, array $vars): string
|
||||
{
|
||||
$contentFile = DIC_ROOT . '/views/' . $template . '.php';
|
||||
extract($vars, EXTR_SKIP);
|
||||
ob_start();
|
||||
require $contentFile;
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
|
||||
function render_standalone(string $template, array $vars, string $pageTitle): void
|
||||
{
|
||||
$contentFile = DIC_ROOT . '/views/' . $template . '.php';
|
||||
extract($vars, EXTR_SKIP);
|
||||
$title = $pageTitle;
|
||||
require $contentFile;
|
||||
}
|
||||
|
||||
function page_handle(string $method, string $path): void
|
||||
{
|
||||
$path = '/' . trim($path, '/');
|
||||
if (!in_array($method, ['GET', 'POST'], true)) {
|
||||
abort_page(405, 'Methode nicht erlaubt.');
|
||||
}
|
||||
|
||||
if ($path === '/health') {
|
||||
health_check();
|
||||
return;
|
||||
}
|
||||
if ($path === '/cron/reminders') {
|
||||
cron_reminders();
|
||||
return;
|
||||
}
|
||||
if ($path === '/login') {
|
||||
page_login($method);
|
||||
return;
|
||||
}
|
||||
|
||||
$user = auth_user();
|
||||
if ($user !== null && $user['must_change_password'] === 1
|
||||
&& !in_array($path, ['/account', '/logout'], true)
|
||||
) {
|
||||
flash('info', 'Bitte zuerst das eigene Passwort ändern.');
|
||||
redirect('/account');
|
||||
}
|
||||
|
||||
if ($path === '/logout') {
|
||||
require_post();
|
||||
auth_logout();
|
||||
redirect('/login');
|
||||
}
|
||||
|
||||
$user = auth_require_login();
|
||||
|
||||
if ($path === '/') {
|
||||
page_dashboard($user);
|
||||
return;
|
||||
}
|
||||
if ($path === '/calendar') {
|
||||
page_calendar($user);
|
||||
return;
|
||||
}
|
||||
if ($path === '/bookings/new') {
|
||||
page_booking_new($user, $method);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/bookings/(\d+)$#', $path, $m) === 1) {
|
||||
page_booking_detail($user, (int) $m[1]);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/bookings/(\d+)/panel$#', $path, $m) === 1) {
|
||||
page_booking_panel($user, (int) $m[1]);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/bookings/(\d+)/edit$#', $path, $m) === 1) {
|
||||
page_booking_edit($user, (int) $m[1], $method);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/bookings/(\d+)/cancel$#', $path, $m) === 1) {
|
||||
page_booking_cancel($user, (int) $m[1]);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/bookings/(\d+)/restore$#', $path, $m) === 1) {
|
||||
page_booking_restore($user, (int) $m[1]);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/bookings/(\d+)/delete$#', $path, $m) === 1) {
|
||||
page_booking_delete($user, (int) $m[1]);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/bookings/(\d+)/move$#', $path, $m) === 1) {
|
||||
page_booking_move($user, (int) $m[1]);
|
||||
return;
|
||||
}
|
||||
if ($path === '/api/availability') {
|
||||
api_availability();
|
||||
return;
|
||||
}
|
||||
if ($path === '/search') {
|
||||
page_search($user);
|
||||
return;
|
||||
}
|
||||
if ($path === '/reminders') {
|
||||
page_reminders($user);
|
||||
return;
|
||||
}
|
||||
if ($path === '/reminders/done') {
|
||||
page_reminder_done($user);
|
||||
return;
|
||||
}
|
||||
if ($path === '/account') {
|
||||
page_account($user, $method);
|
||||
return;
|
||||
}
|
||||
if ($path === '/admin' || str_starts_with($path, '/admin/')) {
|
||||
admin_handle($path, $user);
|
||||
return;
|
||||
}
|
||||
|
||||
abort_page(404, 'Diese Seite gibt es nicht.');
|
||||
}
|
||||
|
||||
function health_check(): void
|
||||
{
|
||||
try {
|
||||
db()->query('SELECT 1');
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
echo "ok\n";
|
||||
} catch (Throwable) {
|
||||
http_response_code(503);
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
echo "db error\n";
|
||||
}
|
||||
}
|
||||
|
||||
function cron_reminders(): void
|
||||
{
|
||||
$expected = (string) config('app.cron_token', '');
|
||||
$given = query_string('token');
|
||||
if ($expected === '' || $given === '' || !hash_equals($expected, $given)) {
|
||||
abort_page(403, 'Kein Zugriff.');
|
||||
}
|
||||
$result = reminder_send_due();
|
||||
json_response($result);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- Anmeldung */
|
||||
|
||||
function page_login(string $method): void
|
||||
{
|
||||
if (auth_user() !== null) {
|
||||
redirect('/');
|
||||
}
|
||||
$error = '';
|
||||
$first = '';
|
||||
$last = '';
|
||||
$remember = true;
|
||||
|
||||
if ($method === 'POST') {
|
||||
$first = post_string('first_name');
|
||||
$last = post_string('last_name');
|
||||
$password = (string) ($_POST['password'] ?? '');
|
||||
$remember = post_string('remember') === '1';
|
||||
$next = safe_next(post_string('next'), '/');
|
||||
|
||||
if (!csrf_valid()) {
|
||||
$error = 'Die Sitzung ist abgelaufen. Bitte erneut versuchen.';
|
||||
} elseif ($first === '' || $last === '' || $password === '') {
|
||||
$error = 'Bitte Vorname, Nachname und Passwort angeben.';
|
||||
} else {
|
||||
try {
|
||||
$user = auth_verify_login($first, $last, $password);
|
||||
auth_login($user, $remember);
|
||||
if ((int) $user['must_change_password'] === 1) {
|
||||
flash('info', 'Bitte zuerst ein neues Passwort vergeben.');
|
||||
redirect('/account');
|
||||
}
|
||||
redirect($next);
|
||||
} catch (RuntimeException $e) {
|
||||
$error = match ($e->getMessage()) {
|
||||
'locked' => 'Zu viele Fehlversuche. Bitte in einigen Minuten erneut versuchen.',
|
||||
'disabled' => 'Dieses Konto ist deaktiviert. Bitte beim Administrator melden.',
|
||||
default => 'Vorname, Nachname oder Passwort stimmen nicht.',
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render_standalone('login', [
|
||||
'error' => $error,
|
||||
'first' => $first,
|
||||
'last' => $last,
|
||||
'remember' => $remember,
|
||||
'next' => safe_next(query_string('next') ?: post_string('next'), '/'),
|
||||
], 'Anmelden');
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- Übersicht */
|
||||
|
||||
function page_dashboard(array $user): void
|
||||
{
|
||||
$today = today_iso();
|
||||
$trailers = trailers_all();
|
||||
$todayBookings = bookings_by_date($today);
|
||||
$byTrailer = [];
|
||||
foreach ($todayBookings as $booking) {
|
||||
$byTrailer[(int) $booking['trailer_id']][] = $booking;
|
||||
}
|
||||
|
||||
$upcoming = upcoming_handovers(14, reminder_scope_employee($user));
|
||||
$employeeScope = reminder_scope_employee($user);
|
||||
$allReminders = reminder_list(add_days($today, -30), add_days($today, 7), $employeeScope, false);
|
||||
$openReminderCount = count($allReminders);
|
||||
$reminders = array_slice($allReminders, 0, 6);
|
||||
$upcoming = array_slice($upcoming, 0, 10);
|
||||
|
||||
$roadmap = [];
|
||||
foreach ($trailers as $trailer) {
|
||||
$roadmap[] = [
|
||||
'trailer' => $trailer,
|
||||
'bookings' => $byTrailer[(int) $trailer['id']] ?? [],
|
||||
];
|
||||
}
|
||||
|
||||
$weekEnd = add_days($today, 7);
|
||||
$handoverCount = 0;
|
||||
foreach (booking_list($today, $weekEnd, false, $employeeScope) as $booking) {
|
||||
if ($booking['start_date'] >= $today && $booking['start_date'] <= $weekEnd) {
|
||||
$handoverCount++;
|
||||
}
|
||||
}
|
||||
|
||||
render_page('dashboard', [
|
||||
'today' => $today,
|
||||
'trailers' => $trailers,
|
||||
'roadmap' => $roadmap,
|
||||
'upcoming' => $upcoming,
|
||||
'reminders' => $reminders,
|
||||
'openReminderCount' => $openReminderCount,
|
||||
'handoverCount' => $handoverCount,
|
||||
'employeeScope' => $employeeScope,
|
||||
], 'Übersicht');
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- Kalender */
|
||||
|
||||
function calendar_url(string $date, string $view, int $employeeId, bool $showCancelled): string
|
||||
{
|
||||
$params = ['view' => $view, 'date' => $date];
|
||||
if ($employeeId > 0) {
|
||||
$params['employee'] = $employeeId;
|
||||
}
|
||||
if ($showCancelled) {
|
||||
$params['cancelled'] = '1';
|
||||
}
|
||||
return '/calendar?' . http_build_query($params);
|
||||
}
|
||||
|
||||
function page_calendar(array $user): void
|
||||
{
|
||||
$view = query_string('view', 'week');
|
||||
if (!in_array($view, ['day', 'week', 'month'], true)) {
|
||||
$view = 'week';
|
||||
}
|
||||
$date = query_string('date');
|
||||
if (!valid_date($date)) {
|
||||
$date = today_iso();
|
||||
}
|
||||
$employeeId = query_int('employee');
|
||||
$showCancelled = query_string('cancelled') === '1';
|
||||
|
||||
if ($view === 'day') {
|
||||
$from = $to = $date;
|
||||
} elseif ($view === 'month') {
|
||||
$from = month_start($date);
|
||||
$to = month_end($date);
|
||||
} else {
|
||||
$from = week_start($date);
|
||||
$to = add_days($from, 6);
|
||||
}
|
||||
|
||||
$trailers = trailers_all();
|
||||
$bookings = booking_list($from, $to, $showCancelled, $employeeId);
|
||||
$byTrailer = [];
|
||||
foreach ($bookings as $booking) {
|
||||
$byTrailer[(int) $booking['trailer_id']][] = $booking;
|
||||
}
|
||||
|
||||
$days = [];
|
||||
$cursor = $from;
|
||||
while ($cursor <= $to) {
|
||||
$days[] = [
|
||||
'iso' => $cursor,
|
||||
'day' => (int) date_obj($cursor)->format('j'),
|
||||
'weekday' => fmt_weekday_short($cursor),
|
||||
'is_today' => $cursor === today_iso(),
|
||||
'is_weekend' => (int) date_obj($cursor)->format('N') >= 6,
|
||||
'is_first_of_month' => date_obj($cursor)->format('j') === '1',
|
||||
];
|
||||
$cursor = add_days($cursor, 1);
|
||||
}
|
||||
|
||||
$barBase = ['day' => 76, 'week' => 48, 'month' => 28][$view];
|
||||
$rowMin = ['day' => 104, 'week' => 64, 'month' => 40][$view];
|
||||
|
||||
$rows = [];
|
||||
foreach ($trailers as $trailer) {
|
||||
$laneInfo = calendar_lanes($byTrailer[(int) $trailer['id']] ?? []);
|
||||
$lanes = $laneInfo['lanes'];
|
||||
$bars = [];
|
||||
foreach ($laneInfo['bookings'] as $booking) {
|
||||
$bars[] = [
|
||||
'booking' => $booking,
|
||||
'geo' => calendar_geometry($booking, $from, $to, $lanes),
|
||||
];
|
||||
}
|
||||
$rows[] = [
|
||||
'trailer' => $trailer,
|
||||
'lanes' => $lanes,
|
||||
'bars' => $bars,
|
||||
'height' => max($rowMin, $barBase * $lanes + 16),
|
||||
];
|
||||
}
|
||||
|
||||
$prevDate = $nextDate = $date;
|
||||
if ($view === 'day') {
|
||||
$prevDate = add_days($date, -1);
|
||||
$nextDate = add_days($date, 1);
|
||||
} elseif ($view === 'week') {
|
||||
$prevDate = add_days($date, -7);
|
||||
$nextDate = add_days($date, 7);
|
||||
} else {
|
||||
$prevDate = date_obj(month_start($date))->modify('first day of previous month')->format('Y-m-d');
|
||||
$nextDate = date_obj(month_start($date))->modify('first day of next month')->format('Y-m-d');
|
||||
}
|
||||
|
||||
if ($view === 'day') {
|
||||
$title = fmt_date_long($date);
|
||||
} elseif ($view === 'week') {
|
||||
$title = 'KW ' . date_obj($from)->format('W') . ' · ' . fmt_date_range($from, $to);
|
||||
} else {
|
||||
$title = fmt_month($date);
|
||||
}
|
||||
|
||||
$employees = employees_all();
|
||||
render_page('calendar', [
|
||||
'view' => $view,
|
||||
'date' => $date,
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'days' => $days,
|
||||
'rows' => $rows,
|
||||
'calTitle' => $title,
|
||||
'prevDate' => $prevDate,
|
||||
'nextDate' => $nextDate,
|
||||
'today' => today_iso(),
|
||||
'employeeId' => $employeeId,
|
||||
'showCancelled' => $showCancelled,
|
||||
'employees' => $employees,
|
||||
'bookingCount' => count($bookings),
|
||||
'urlFor' => static function (string $d) use ($view, $employeeId, $showCancelled): string {
|
||||
return calendar_url($d, $view, $employeeId, $showCancelled);
|
||||
},
|
||||
], 'Kalender');
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- Buchungen */
|
||||
|
||||
function booking_form_context(array $user, ?array $booking = null, array $values = [], array $errors = []): array
|
||||
{
|
||||
$trailers = trailers_all(false);
|
||||
$employees = employees_all(false);
|
||||
$currentTrailer = (int) ($values['trailer_id'] ?? 0);
|
||||
$currentEmployee = (int) ($values['employee_id'] ?? 0);
|
||||
$trailerOptions = array_values(array_filter(
|
||||
$trailers,
|
||||
static fn (array $t): bool => (int) $t['active'] === 1 || (int) $t['id'] === $currentTrailer
|
||||
));
|
||||
$employeeOptions = array_values(array_filter(
|
||||
$employees,
|
||||
static fn (array $e): bool => (int) $e['active'] === 1 || (int) $e['id'] === $currentEmployee
|
||||
));
|
||||
|
||||
return [
|
||||
'booking' => $booking,
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'trailers' => $trailerOptions,
|
||||
'employees' => $employeeOptions,
|
||||
'user' => $user,
|
||||
'isEdit' => $booking !== null,
|
||||
];
|
||||
}
|
||||
|
||||
function form_values_from_input(array $data): array
|
||||
{
|
||||
return [
|
||||
'trailer_id' => (int) $data['trailer_id'],
|
||||
'employee_id' => (int) $data['employee_id'],
|
||||
'start_date' => (string) $data['start_date'],
|
||||
'end_date' => (string) $data['end_date'],
|
||||
'deposit' => number_format($data['deposit_cents'] / 100, 2, ',', ''),
|
||||
'total' => number_format($data['total_cents'] / 100, 2, ',', ''),
|
||||
'invoice' => (int) $data['invoice'],
|
||||
'kind' => (string) $data['kind'],
|
||||
'customer_name' => (string) $data['customer_name'],
|
||||
'street' => (string) $data['street'],
|
||||
'city' => (string) $data['city'],
|
||||
'mobile' => (string) $data['mobile'],
|
||||
'email' => (string) $data['email'],
|
||||
];
|
||||
}
|
||||
|
||||
function page_booking_new(array $user, string $method): void
|
||||
{
|
||||
$trailers = trailers_all();
|
||||
$employees = employees_all();
|
||||
if (!$trailers || !$employees) {
|
||||
abort_page(500, 'Es sind keine Kühlanhänger oder Mitarbeiter hinterlegt.');
|
||||
}
|
||||
|
||||
$start = query_string('start');
|
||||
if (!valid_date($start)) {
|
||||
$start = today_iso();
|
||||
}
|
||||
$end = query_string('end');
|
||||
if (!valid_date($end) || $end < $start) {
|
||||
$end = add_days($start, 3);
|
||||
}
|
||||
$trailerId = query_int('trailer');
|
||||
if (!array_filter($trailers, static fn (array $t): bool => (int) $t['id'] === $trailerId)) {
|
||||
$trailerId = (int) $trailers[0]['id'];
|
||||
}
|
||||
$employeeId = auth_employee_id($user);
|
||||
if (!array_filter($employees, static fn (array $e): bool => (int) $e['id'] === $employeeId)) {
|
||||
$employeeId = (int) $employees[0]['id'];
|
||||
}
|
||||
|
||||
$values = [
|
||||
'trailer_id' => $trailerId,
|
||||
'employee_id' => $employeeId,
|
||||
'start_date' => $start,
|
||||
'end_date' => $end,
|
||||
'deposit' => '',
|
||||
'total' => '',
|
||||
'invoice' => 0,
|
||||
'kind' => 'pickup',
|
||||
'customer_name' => '',
|
||||
'street' => '',
|
||||
'city' => '',
|
||||
'mobile' => '',
|
||||
'email' => '',
|
||||
];
|
||||
$errors = [];
|
||||
|
||||
if ($method === 'POST') {
|
||||
require_post();
|
||||
$data = booking_input($_POST);
|
||||
$values = form_values_from_input($data);
|
||||
$errors = booking_validate($data);
|
||||
if (!$errors) {
|
||||
try {
|
||||
$id = booking_create($data, (int) $user['id']);
|
||||
flash('success', 'Buchung für ' . $data['customer_name'] . ' wurde angelegt.');
|
||||
redirect('/bookings/' . $id);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$errors = json_decode($e->getMessage(), true) ?: ['form' => 'Buchung konnte nicht gespeichert werden.'];
|
||||
}
|
||||
}
|
||||
http_response_code(422);
|
||||
}
|
||||
|
||||
render_page('booking_form', booking_form_context($user, null, $values, $errors), 'Neue Buchung');
|
||||
}
|
||||
|
||||
function page_booking_edit(array $user, int $id, string $method): void
|
||||
{
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
}
|
||||
|
||||
$values = [
|
||||
'trailer_id' => (int) $booking['trailer_id'],
|
||||
'employee_id' => (int) $booking['employee_id'],
|
||||
'start_date' => (string) $booking['start_date'],
|
||||
'end_date' => (string) $booking['end_date'],
|
||||
'deposit' => number_format((int) $booking['deposit_cents'] / 100, 2, ',', ''),
|
||||
'total' => number_format((int) $booking['total_cents'] / 100, 2, ',', ''),
|
||||
'invoice' => (int) $booking['invoice'],
|
||||
'kind' => (string) $booking['kind'],
|
||||
'customer_name' => (string) $booking['customer_name'],
|
||||
'street' => (string) $booking['street'],
|
||||
'city' => (string) $booking['city'],
|
||||
'mobile' => (string) $booking['mobile'],
|
||||
'email' => (string) $booking['email'],
|
||||
];
|
||||
$errors = [];
|
||||
|
||||
if ($method === 'POST') {
|
||||
require_post();
|
||||
$data = booking_input($_POST);
|
||||
$values = form_values_from_input($data);
|
||||
$errors = booking_validate($data, $id, (int) $booking['trailer_id'], (int) $booking['employee_id']);
|
||||
if (!$errors) {
|
||||
try {
|
||||
booking_update($id, $data, (int) $user['id']);
|
||||
flash('success', 'Buchung wurde aktualisiert.');
|
||||
redirect('/bookings/' . $id);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$errors = json_decode($e->getMessage(), true) ?: ['form' => 'Buchung konnte nicht gespeichert werden.'];
|
||||
}
|
||||
}
|
||||
http_response_code(422);
|
||||
}
|
||||
|
||||
render_page('booking_form', booking_form_context($user, $booking, $values, $errors), 'Buchung bearbeiten');
|
||||
}
|
||||
|
||||
function booking_detail_context(array $booking, array $user): array
|
||||
{
|
||||
$reminders = booking_reminders($booking);
|
||||
$done = reminder_done_map([(int) $booking['id']]);
|
||||
return [
|
||||
'booking' => $booking,
|
||||
'reminders' => $reminders,
|
||||
'doneMap' => $done,
|
||||
'copyText' => booking_copy_text($booking),
|
||||
'canDelete' => ($user['role'] ?? '') === 'admin',
|
||||
];
|
||||
}
|
||||
|
||||
function page_booking_detail(array $user, int $id): void
|
||||
{
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
}
|
||||
render_page('booking_detail', booking_detail_context($booking, $user), 'Buchung ' . $booking['customer_name']);
|
||||
}
|
||||
|
||||
function page_booking_panel(array $user, int $id): void
|
||||
{
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
}
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
echo render_partial('booking_panel', booking_detail_context($booking, $user) + ['panel' => true]);
|
||||
}
|
||||
|
||||
function page_booking_cancel(array $user, int $id): void
|
||||
{
|
||||
require_post();
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
}
|
||||
if ($booking['status'] === 'active') {
|
||||
booking_cancel($id, (int) $user['id']);
|
||||
flash('success', 'Buchung von ' . $booking['customer_name'] . ' wurde storniert. Die Erinnerungen entfallen.');
|
||||
}
|
||||
$back = safe_next(post_string('return_to'), '/bookings/' . $id);
|
||||
redirect($back);
|
||||
}
|
||||
|
||||
function page_booking_restore(array $user, int $id): void
|
||||
{
|
||||
require_post();
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
}
|
||||
if ($booking['status'] === 'cancelled') {
|
||||
try {
|
||||
$errors = booking_restore($id, (int) $user['id']);
|
||||
if ($errors) {
|
||||
flash('error', reset($errors) ?: 'Buchung kann nicht wiederhergestellt werden.');
|
||||
} else {
|
||||
flash('success', 'Buchung wurde wieder aktiviert.');
|
||||
}
|
||||
} catch (RuntimeException) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
}
|
||||
}
|
||||
redirect('/bookings/' . $id);
|
||||
}
|
||||
|
||||
function page_booking_delete(array $user, int $id): void
|
||||
{
|
||||
require_post();
|
||||
if (($user['role'] ?? '') !== 'admin') {
|
||||
abort_page(403, 'Nur Administratoren dürfen Buchungen löschen.');
|
||||
}
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
}
|
||||
booking_delete($id);
|
||||
flash('success', 'Buchung von ' . $booking['customer_name'] . ' wurde endgültig gelöscht.');
|
||||
redirect('/calendar?view=month&date=' . $booking['start_date']);
|
||||
}
|
||||
|
||||
function page_booking_move(array $user, int $id): void
|
||||
{
|
||||
require_post();
|
||||
$result = booking_move(
|
||||
$id,
|
||||
post_string('start_date'),
|
||||
(int) post_string('trailer_id'),
|
||||
(int) $user['id']
|
||||
);
|
||||
if (isset($result['error'])) {
|
||||
json_response(['ok' => false, 'error' => $result['error']], 409);
|
||||
}
|
||||
json_response($result);
|
||||
}
|
||||
|
||||
function api_availability(): void
|
||||
{
|
||||
auth_require_login();
|
||||
$trailerId = query_int('trailer');
|
||||
$start = query_string('start');
|
||||
$end = query_string('end');
|
||||
$exclude = query_int('exclude');
|
||||
if ($trailerId <= 0 || !valid_date($start) || !valid_date($end) || $end < $start) {
|
||||
json_response(['ok' => false, 'error' => 'Bitte Anhänger und Zeitraum angeben.'], 422);
|
||||
}
|
||||
$conflicts = booking_conflicts($trailerId, $start, $end, $exclude);
|
||||
json_response([
|
||||
'ok' => !$conflicts,
|
||||
'conflicts' => array_map(static fn (array $b): array => [
|
||||
'id' => (int) $b['id'],
|
||||
'customer' => $b['customer_name'],
|
||||
'start' => $b['start_date'],
|
||||
'end' => $b['end_date'],
|
||||
], $conflicts),
|
||||
]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ Suche */
|
||||
|
||||
function page_search(array $user): void
|
||||
{
|
||||
$query = query_string('q');
|
||||
$results = $query !== '' ? booking_search($query) : [];
|
||||
render_page('search', [
|
||||
'query' => $query,
|
||||
'results' => $results,
|
||||
], 'Suche');
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ Erinnerungen */
|
||||
|
||||
function page_reminders(array $user): void
|
||||
{
|
||||
$range = query_string('range', '14');
|
||||
if (!in_array($range, ['7', '14', '30', 'all'], true)) {
|
||||
$range = '14';
|
||||
}
|
||||
$scope = reminder_scope_employee($user);
|
||||
$employeeFilter = $scope;
|
||||
if (($user['role'] ?? '') === 'admin') {
|
||||
$employeeFilter = query_int('employee');
|
||||
}
|
||||
$showDone = query_string('done') === '1';
|
||||
$today = today_iso();
|
||||
|
||||
if ($range === 'all') {
|
||||
$from = add_days($today, -365);
|
||||
$to = add_days($today, 365);
|
||||
} else {
|
||||
$from = add_days($today, -30);
|
||||
$to = add_days($today, (int) $range);
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$hasEmployee = $scope > 0 || ($user['role'] ?? '') === 'admin';
|
||||
if ($hasEmployee) {
|
||||
$rows = reminder_list($from, $to, $employeeFilter, $showDone);
|
||||
}
|
||||
$groups = [];
|
||||
foreach ($rows as $row) {
|
||||
$groups[$row['due_date']][] = $row;
|
||||
}
|
||||
|
||||
$employees = employees_all();
|
||||
render_page('reminders', [
|
||||
'rows' => $rows,
|
||||
'groups' => $groups,
|
||||
'range' => $range,
|
||||
'employeeFilter' => $employeeFilter,
|
||||
'showDone' => $showDone,
|
||||
'employees' => $employees,
|
||||
'hasEmployee' => $hasEmployee,
|
||||
'isAdmin' => ($user['role'] ?? '') === 'admin',
|
||||
'today' => $today,
|
||||
'mailEnabled' => (bool) config('app.mail_enabled', false),
|
||||
], 'Erinnerungen');
|
||||
}
|
||||
|
||||
function page_reminder_done(array $user): void
|
||||
{
|
||||
require_post();
|
||||
$bookingId = (int) post_string('booking_id');
|
||||
$kind = post_string('kind');
|
||||
$done = post_string('done') === '1';
|
||||
$booking = booking_find($bookingId);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
}
|
||||
$allowed = ($user['role'] ?? '') === 'admin'
|
||||
|| (auth_employee_id($user) > 0 && (int) $booking['employee_id'] === auth_employee_id($user));
|
||||
if (!$allowed) {
|
||||
abort_page(403, 'Diese Erinnerung gehört zu einem anderen Mitarbeiter.');
|
||||
}
|
||||
if (!reminder_done_set($bookingId, $kind, $done, (int) $user['id'])) {
|
||||
abort_page(422, 'Erinnerung nicht gefunden.');
|
||||
}
|
||||
flash('success', $done ? 'Erinnerung als erledigt markiert.' : 'Erinnerung wieder geöffnet.');
|
||||
$back = safe_next(post_string('return_to'), '/reminders');
|
||||
redirect($back);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ Konto */
|
||||
|
||||
function page_account(array $user, string $method): void
|
||||
{
|
||||
$errors = [];
|
||||
if ($method === 'POST') {
|
||||
require_post();
|
||||
$current = (string) ($_POST['current_password'] ?? '');
|
||||
$new = (string) ($_POST['new_password'] ?? '');
|
||||
$repeat = (string) ($_POST['repeat_password'] ?? '');
|
||||
if (!password_verify($current, (string) $user['password_hash'])) {
|
||||
$errors['current_password'] = 'Das aktuelle Passwort stimmt nicht.';
|
||||
}
|
||||
if (mb_strlen($new) < 8) {
|
||||
$errors['new_password'] = 'Das neue Passwort muss mindestens 8 Zeichen haben.';
|
||||
}
|
||||
if ($new !== $repeat) {
|
||||
$errors['repeat_password'] = 'Die beiden neuen Passwörter stimmen nicht überein.';
|
||||
}
|
||||
if (!$errors) {
|
||||
$pdo = db();
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
$stmt = $pdo->prepare('UPDATE users SET password_hash = ?, password_changed_at = ?, updated_at = ?,
|
||||
must_change_password = 0, auth_epoch = auth_epoch + 1 WHERE id = ?');
|
||||
$stmt->execute([hash_password($new), utc_now(), utc_now(), (int) $user['id']]);
|
||||
$newEpoch = (int) $pdo->query('SELECT auth_epoch FROM users WHERE id = ' . (int) $user['id'])->fetchColumn();
|
||||
$pdo->prepare('DELETE FROM auth_tokens WHERE user_id = ?')->execute([(int) $user['id']]);
|
||||
$pdo->commit();
|
||||
$_SESSION['epoch'] = $newEpoch;
|
||||
$_SESSION['csrf'] = bin2hex(random_bytes(32));
|
||||
flash('success', 'Das Passwort wurde geändert. Andere Geräte müssen sich neu anmelden.');
|
||||
redirect('/');
|
||||
} catch (Throwable $error) {
|
||||
$pdo->rollBack();
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
http_response_code(422);
|
||||
}
|
||||
|
||||
render_page('account', [
|
||||
'errors' => $errors,
|
||||
'employee' => auth_employee_id($user) > 0 ? employee_find(auth_employee_id($user)) : null,
|
||||
], 'Mein Konto');
|
||||
}
|
||||
433
app/util.php
Normal file
|
|
@ -0,0 +1,433 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/** Kleine Helfer: Konfiguration, Session, CSRF, Ausgabe, Zeit und Geld. */
|
||||
|
||||
function config(string $key, mixed $default = null): mixed
|
||||
{
|
||||
$value = $GLOBALS['dic_config'] ?? [];
|
||||
foreach (explode('.', $key) as $part) {
|
||||
if (!is_array($value) || !array_key_exists($part, $value)) {
|
||||
return $default;
|
||||
}
|
||||
$value = $value[$part];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function is_https(): bool
|
||||
{
|
||||
if (!empty($_SERVER['HTTPS']) && strtolower((string) $_SERVER['HTTPS']) !== 'off') {
|
||||
return true;
|
||||
}
|
||||
return strtolower((string) ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '')) === 'https';
|
||||
}
|
||||
|
||||
function security_headers(): void
|
||||
{
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('X-Frame-Options: DENY');
|
||||
header('X-Robots-Tag: noindex, nofollow, noarchive');
|
||||
header('Referrer-Policy: same-origin');
|
||||
header('Permissions-Policy: camera=(), microphone=(), geolocation=()');
|
||||
header(
|
||||
"Content-Security-Policy: default-src 'self'; img-src 'self' data:; "
|
||||
. "font-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; "
|
||||
. "connect-src 'self'; media-src 'self'; form-action 'self'; "
|
||||
. "frame-ancestors 'none'; base-uri 'none'"
|
||||
);
|
||||
header('Cache-Control: no-store');
|
||||
if (is_https()) {
|
||||
header('Strict-Transport-Security: max-age=15552000');
|
||||
}
|
||||
}
|
||||
|
||||
function start_session(): void
|
||||
{
|
||||
if (session_status() === PHP_SESSION_ACTIVE) {
|
||||
return;
|
||||
}
|
||||
$absolute = (int) config('app.session_absolute_seconds', 7776000);
|
||||
ini_set('session.use_strict_mode', '1');
|
||||
ini_set('session.use_only_cookies', '1');
|
||||
ini_set('session.cookie_httponly', '1');
|
||||
ini_set('session.cookie_samesite', 'Lax');
|
||||
ini_set('session.cookie_secure', is_https() ? '1' : '0');
|
||||
ini_set('session.cookie_path', '/');
|
||||
ini_set('session.gc_maxlifetime', (string) $absolute);
|
||||
session_name('DIC_SESSION');
|
||||
session_start();
|
||||
}
|
||||
|
||||
function utc_now(): string
|
||||
{
|
||||
return gmdate('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
function utc_after(int $seconds): string
|
||||
{
|
||||
return gmdate('Y-m-d H:i:s', time() + $seconds);
|
||||
}
|
||||
|
||||
function e(mixed $value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
}
|
||||
|
||||
function e_attr(mixed $value): string
|
||||
{
|
||||
return e($value);
|
||||
}
|
||||
|
||||
function url(string $path = '/'): string
|
||||
{
|
||||
$base = rtrim((string) config('app.base_path', ''), '/');
|
||||
if ($path === '' || $path[0] !== '/') {
|
||||
$path = '/' . $path;
|
||||
}
|
||||
return $base . $path;
|
||||
}
|
||||
|
||||
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
|
||||
const DIC_ASSET_VERSION = '1';
|
||||
|
||||
function asset(string $path): string
|
||||
{
|
||||
return url('/assets/' . ltrim($path, '/')) . '?v=' . DIC_ASSET_VERSION;
|
||||
}
|
||||
|
||||
function redirect(string $path, int $status = 303): never
|
||||
{
|
||||
header('Location: ' . url($path), true, $status);
|
||||
exit;
|
||||
}
|
||||
|
||||
function current_path(): string
|
||||
{
|
||||
$path = (string) parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH);
|
||||
$base = rtrim((string) config('app.base_path', ''), '/');
|
||||
if ($base !== '' && str_starts_with($path, $base)) {
|
||||
$path = substr($path, strlen($base));
|
||||
}
|
||||
return '/' . trim($path, '/');
|
||||
}
|
||||
|
||||
function client_ip(): string
|
||||
{
|
||||
$ip = (string) ($_SERVER['REMOTE_ADDR'] ?? '');
|
||||
return $ip !== '' ? substr($ip, 0, 45) : '0.0.0.0';
|
||||
}
|
||||
|
||||
function request_method(): string
|
||||
{
|
||||
return strtoupper((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET'));
|
||||
}
|
||||
|
||||
function is_post(): bool
|
||||
{
|
||||
return request_method() === 'POST';
|
||||
}
|
||||
|
||||
function post_string(string $key, string $default = ''): string
|
||||
{
|
||||
$value = $_POST[$key] ?? $default;
|
||||
return is_string($value) ? trim($value) : $default;
|
||||
}
|
||||
|
||||
function post_array(string $key): array
|
||||
{
|
||||
$value = $_POST[$key] ?? [];
|
||||
return is_array($value) ? $value : [];
|
||||
}
|
||||
|
||||
function query_string(string $key, string $default = ''): string
|
||||
{
|
||||
$value = $_GET[$key] ?? $default;
|
||||
return is_string($value) ? trim($value) : $default;
|
||||
}
|
||||
|
||||
function query_int(string $key, int $default = 0): int
|
||||
{
|
||||
$value = $_GET[$key] ?? null;
|
||||
return is_numeric($value) ? (int) $value : $default;
|
||||
}
|
||||
|
||||
function wants_json(): bool
|
||||
{
|
||||
$accept = strtolower((string) ($_SERVER['HTTP_ACCEPT'] ?? ''));
|
||||
return str_contains($accept, 'application/json')
|
||||
|| strtolower((string) ($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '')) === 'fetch';
|
||||
}
|
||||
|
||||
function json_response(array $payload, int $status = 200): never
|
||||
{
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
function flash(string $type, string $message): void
|
||||
{
|
||||
$_SESSION['flash'][] = ['type' => $type, 'message' => $message];
|
||||
}
|
||||
|
||||
function flash_pull(): array
|
||||
{
|
||||
$items = $_SESSION['flash'] ?? [];
|
||||
unset($_SESSION['flash']);
|
||||
return is_array($items) ? $items : [];
|
||||
}
|
||||
|
||||
function csrf_token(): string
|
||||
{
|
||||
if (empty($_SESSION['csrf'])) {
|
||||
$_SESSION['csrf'] = bin2hex(random_bytes(32));
|
||||
}
|
||||
return (string) $_SESSION['csrf'];
|
||||
}
|
||||
|
||||
function csrf_field(): string
|
||||
{
|
||||
return '<input type="hidden" name="_csrf" value="' . e(csrf_token()) . '">';
|
||||
}
|
||||
|
||||
function csrf_valid(): bool
|
||||
{
|
||||
$sent = $_POST['_csrf'] ?? ($_SERVER['HTTP_X_CSRF_TOKEN'] ?? '');
|
||||
return is_string($sent) && $sent !== '' && hash_equals(csrf_token(), $sent);
|
||||
}
|
||||
|
||||
function require_post(): void
|
||||
{
|
||||
if (!is_post()) {
|
||||
abort_page(405, 'Diese Aktion ist nur per POST möglich.');
|
||||
}
|
||||
if (!csrf_valid()) {
|
||||
abort_page(419, 'Die Sitzung ist abgelaufen. Bitte die Seite neu laden und erneut versuchen.');
|
||||
}
|
||||
}
|
||||
|
||||
/** Nur lokale Pfade als Rücksprungziel zulassen. */
|
||||
function safe_next(string $next, string $fallback = '/'): string
|
||||
{
|
||||
$next = trim($next);
|
||||
if ($next === '' || $next[0] !== '/' || str_starts_with($next, '//') || str_contains($next, '\\')) {
|
||||
return $fallback;
|
||||
}
|
||||
return $next;
|
||||
}
|
||||
|
||||
function abort_page(int $code, string $message): never
|
||||
{
|
||||
http_response_code($code);
|
||||
$titles = [403 => 'Kein Zugriff', 404 => 'Nicht gefunden', 405 => 'Nicht erlaubt', 419 => 'Sitzung abgelaufen'];
|
||||
$title = $titles[$code] ?? 'Fehler';
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
echo '<!doctype html><html lang="de"><head><meta charset="utf-8">'
|
||||
. '<meta name="viewport" content="width=device-width, initial-scale=1">'
|
||||
. '<title>' . e($title) . ' · Drink it cold</title>'
|
||||
. '<link rel="stylesheet" href="' . e(asset('app.css')) . '"></head>'
|
||||
. '<body class="error-page"><div class="error-card">'
|
||||
. '<img src="' . e(asset('logo-mark.svg')) . '" alt="" width="64" height="46">'
|
||||
. '<p class="eyebrow">Drink it cold · Terminplanung</p>'
|
||||
. '<h1>' . e($title) . '</h1><p>' . e($message) . '</p>'
|
||||
. '<p><a class="btn primary" href="' . e(url('/')) . '">Zur Übersicht</a></p>'
|
||||
. '</div></body></html>';
|
||||
exit;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- Datum */
|
||||
|
||||
function today_iso(): string
|
||||
{
|
||||
return date('Y-m-d');
|
||||
}
|
||||
|
||||
function valid_date(?string $iso): bool
|
||||
{
|
||||
if ($iso === null || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $iso)) {
|
||||
return false;
|
||||
}
|
||||
[$y, $m, $d] = array_map('intval', explode('-', $iso));
|
||||
return checkdate($m, $d, $y);
|
||||
}
|
||||
|
||||
function date_obj(string $iso): DateTimeImmutable
|
||||
{
|
||||
return new DateTimeImmutable($iso . ' 12:00:00', new DateTimeZone('Europe/Berlin'));
|
||||
}
|
||||
|
||||
function add_days(string $iso, int $days): string
|
||||
{
|
||||
return date_obj($iso)->modify(($days >= 0 ? '+' : '') . $days . ' days')->format('Y-m-d');
|
||||
}
|
||||
|
||||
function days_between(string $from, string $to): int
|
||||
{
|
||||
return (int) date_obj($from)->diff(date_obj($to))->format('%r%a');
|
||||
}
|
||||
|
||||
function week_start(string $iso): string
|
||||
{
|
||||
$date = date_obj($iso);
|
||||
$weekday = (int) $date->format('N');
|
||||
return $date->modify('-' . ($weekday - 1) . ' days')->format('Y-m-d');
|
||||
}
|
||||
|
||||
function month_start(string $iso): string
|
||||
{
|
||||
return date_obj($iso)->modify('first day of this month')->format('Y-m-d');
|
||||
}
|
||||
|
||||
function month_end(string $iso): string
|
||||
{
|
||||
return date_obj($iso)->modify('last day of this month')->format('Y-m-d');
|
||||
}
|
||||
|
||||
function fmt_date(string $iso): string
|
||||
{
|
||||
return valid_date($iso) ? date_obj($iso)->format('d.m.Y') : '–';
|
||||
}
|
||||
|
||||
function fmt_date_short(string $iso): string
|
||||
{
|
||||
return valid_date($iso) ? date_obj($iso)->format('d.m.y') : '–';
|
||||
}
|
||||
|
||||
function fmt_date_long(string $iso): string
|
||||
{
|
||||
if (!valid_date($iso)) {
|
||||
return '–';
|
||||
}
|
||||
$days = ['', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'];
|
||||
$months = ['', 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
|
||||
$date = date_obj($iso);
|
||||
return $days[(int) $date->format('N')] . ', ' . (int) $date->format('j') . '. ' . $months[(int) $date->format('n')] . ' ' . $date->format('Y');
|
||||
}
|
||||
|
||||
function fmt_month(string $iso): string
|
||||
{
|
||||
$months = ['', 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
|
||||
return $months[(int) date_obj($iso)->format('n')] . ' ' . date_obj($iso)->format('Y');
|
||||
}
|
||||
|
||||
function fmt_weekday_short(string $iso): string
|
||||
{
|
||||
$days = ['', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'];
|
||||
return $days[(int) date_obj($iso)->format('N')];
|
||||
}
|
||||
|
||||
function fmt_date_range(string $from, string $to): string
|
||||
{
|
||||
if ($from === $to) {
|
||||
return fmt_date($from);
|
||||
}
|
||||
if (date_obj($from)->format('Y-m') === date_obj($to)->format('Y-m')) {
|
||||
return (int) date_obj($from)->format('j') . '.–' . fmt_date($to);
|
||||
}
|
||||
return fmt_date($from) . ' – ' . fmt_date($to);
|
||||
}
|
||||
|
||||
function fmt_datetime(?string $utc): string
|
||||
{
|
||||
if ($utc === null || $utc === '') {
|
||||
return '–';
|
||||
}
|
||||
try {
|
||||
$date = new DateTimeImmutable($utc, new DateTimeZone('UTC'));
|
||||
return $date->setTimezone(new DateTimeZone('Europe/Berlin'))->format('d.m.Y H:i');
|
||||
} catch (Throwable) {
|
||||
return '–';
|
||||
}
|
||||
}
|
||||
|
||||
function relative_day(string $iso): string
|
||||
{
|
||||
$diff = days_between(today_iso(), $iso);
|
||||
return match (true) {
|
||||
$diff === 0 => 'Heute',
|
||||
$diff === 1 => 'Morgen',
|
||||
$diff === -1 => 'Gestern',
|
||||
$diff < 0 => abs($diff) . ' Tage überfällig',
|
||||
default => 'in ' . $diff . ' Tagen',
|
||||
};
|
||||
}
|
||||
|
||||
function greeting(): string
|
||||
{
|
||||
$hour = (int) date('G');
|
||||
if ($hour < 11) {
|
||||
return 'Guten Morgen';
|
||||
}
|
||||
if ($hour < 18) {
|
||||
return 'Guten Tag';
|
||||
}
|
||||
return 'Guten Abend';
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- Geld */
|
||||
|
||||
function fmt_money(int $cents): string
|
||||
{
|
||||
return number_format($cents / 100, 2, ',', '.') . ' €';
|
||||
}
|
||||
|
||||
function parse_money(string $value): int
|
||||
{
|
||||
$value = trim($value);
|
||||
$value = str_replace(["\u{00A0}", ' ', '€', 'EUR'], '', $value);
|
||||
$value = preg_replace('/[^0-9,.\-]/u', '', $value) ?? '';
|
||||
if ($value === '' || $value === '-') {
|
||||
return 0;
|
||||
}
|
||||
if (str_contains($value, ',')) {
|
||||
$value = str_replace('.', '', $value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
} elseif (preg_match('/^\d{1,3}(\.\d{3})+$/', $value) === 1) {
|
||||
$value = str_replace('.', '', $value);
|
||||
}
|
||||
return (int) round((float) $value * 100);
|
||||
}
|
||||
|
||||
function due_cents(int $total, int $deposit): int
|
||||
{
|
||||
return $total - $deposit;
|
||||
}
|
||||
|
||||
/** Lesbare Textfarbe für eine Anhängerfarbe. */
|
||||
function contrast_color(string $hex): string
|
||||
{
|
||||
$hex = ltrim($hex, '#');
|
||||
if (strlen($hex) !== 6) {
|
||||
return '#ffffff';
|
||||
}
|
||||
$r = hexdec(substr($hex, 0, 2)) / 255;
|
||||
$g = hexdec(substr($hex, 2, 2)) / 255;
|
||||
$b = hexdec(substr($hex, 4, 2)) / 255;
|
||||
$channel = static function (float $c): float {
|
||||
return $c <= 0.03928 ? $c / 12.92 : (($c + 0.055) / 1.055) ** 2.4;
|
||||
};
|
||||
$luminance = 0.2126 * $channel($r) + 0.7152 * $channel($g) + 0.0722 * $channel($b);
|
||||
return $luminance > 0.46 ? '#10202c' : '#ffffff';
|
||||
}
|
||||
|
||||
function initials(string $name): string
|
||||
{
|
||||
$parts = preg_split('/\s+/', trim($name)) ?: [];
|
||||
$out = '';
|
||||
foreach (array_slice($parts, 0, 2) as $part) {
|
||||
if ($part !== '') {
|
||||
$out .= mb_strtoupper(mb_substr($part, 0, 1));
|
||||
}
|
||||
}
|
||||
return $out !== '' ? $out : '?';
|
||||
}
|
||||
|
||||
function truncate(string $value, int $length): string
|
||||
{
|
||||
if (mb_strlen($value) <= $length) {
|
||||
return $value;
|
||||
}
|
||||
return mb_substr($value, 0, max(0, $length - 1)) . '…';
|
||||
}
|
||||
BIN
docs/Anforderungen_Online_Terminplanung_Drink_it_cold-1.pdf
Normal file
8
docs/README.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Dokumentation
|
||||
|
||||
- [Anforderungen (PDF)](Anforderungen_Online_Terminplanung_Drink_it_cold-1.pdf)
|
||||
- [Architektur, Datenmodell und Anforderungsabdeckung](architecture.md)
|
||||
- [Haupt-README](../README.md)
|
||||
|
||||
Zugangsdaten für Deployment und Datenbank stehen in `credentials.txt` und sind
|
||||
per `.gitignore` vom Repository ausgeschlossen.
|
||||
138
docs/architecture.md
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
# Architektur und Entscheidungen
|
||||
|
||||
## Überblick
|
||||
|
||||
Die Anwendung ist eine klassische, server-gerenderte PHP-App ohne Framework und
|
||||
ohne Composer-Abhängigkeiten. Das passt zum vorhandenen Shared Hosting
|
||||
(PHP/MariaDB, FTP-Deployment) und hält den Betrieb einfach.
|
||||
|
||||
```
|
||||
Browser
|
||||
│
|
||||
├─ web/index.php (Front Controller) ── app/bootstrap.php
|
||||
│ ├─ util.php (Session, CSRF, Helfer)
|
||||
│ ├─ db.php (PDO, utf8mb4)
|
||||
│ ├─ auth.php (Login, Tokens, Ratenlimit)
|
||||
│ ├─ data.php (Buchungen, Kalender, Reminder)
|
||||
│ ├─ mail.php (optionaler Digest)
|
||||
│ ├─ pages.php (Routen, Formulare)
|
||||
│ └─ admin.php (Verwaltung)
|
||||
│
|
||||
├─ views/… (HTML, keine Business-Logik)
|
||||
└─ web/assets/app.css, app.js
|
||||
```
|
||||
|
||||
## Datenmodell
|
||||
|
||||
| Tabelle | Zweck |
|
||||
|---|---|
|
||||
| `trailers` | Acht Anhänger mit Bezeichnung, Farbname, Hex-Farbe, Sortierung |
|
||||
| `employees` | Mitarbeiter (M. Krücken, N. Jorns, M. Schmitz), aktiv/inaktiv |
|
||||
| `users` | Login-Konten (Vorname, Nachname, Passwort-Hash, Rolle, optional E-Mail, optional Mitarbeiter-Link) |
|
||||
| `bookings` | Buchung inkl. Zeitraum, Beträge, Rechnungsflag, Art, Kundendaten, Status |
|
||||
| `reminder_done` | Abgehakte Erinnerung, Schlüssel `(booking_id, kind, due_date)` |
|
||||
| `reminder_mail_log` | Versandprotokoll, verhindert doppelte E-Mails |
|
||||
| `auth_tokens` | Remember-Me-Tokens (Selector + Hash, rotierend) |
|
||||
| `login_attempts` | Ratenbegrenzung des Logins |
|
||||
| `schema_migrations` | Installationsversion |
|
||||
|
||||
Zeitstempel sind UTC; Kalenderdaten sind reine `DATE`-Werte in Europe/Berlin.
|
||||
Beträge werden als Cent-Ganzzahlen gespeichert, damit keine Rundungsfehler
|
||||
entstehen.
|
||||
|
||||
## Kalender und Überschneidungen
|
||||
|
||||
- Zeitraum einer Buchung: `start_date` bis `end_date`, **beide inklusive**.
|
||||
- Eine Überschneidung liegt vor, wenn `bestehend.start < neu.ende` **und**
|
||||
`bestehend.ende > neu.start`. Dadurch ist der Wechseltag erlaubt:
|
||||
`13.–16.11.` und `16.–19.11.` überschneiden sich nur am 16.11. und sind
|
||||
zulässig. Der Restbetrag wird nie gespeichert, sondern immer berechnet.
|
||||
- Beim Anlegen/Ändern/Verschieben wird die Anhängerzeile mit
|
||||
`SELECT … FOR UPDATE` gesperrt. Damit können zwei gleichzeitige Mitarbeiter
|
||||
keine sich überschneidenden Buchungen anlegen.
|
||||
- Der Kalender gruppiert Buchungen pro Anhänger und verteilt sie auf Lanes.
|
||||
Zwei Buchungen mit Wechseltag liegen in zwei Lanes und bleiben beide
|
||||
sichtbar. Lanes und Balkenpositionen werden serverseitig in Prozent
|
||||
berechnet; das funktioniert ohne JavaScript und ohne externe Kalender-Library.
|
||||
- Tages-, Wochen- und Monatsansicht nutzen dieselbe Zeilenstruktur
|
||||
(8 Anhänger × Zeitraum). Die Monatsansicht ist bewusst als horizontale
|
||||
Zeitachse umgesetzt, damit auch dort jeder Anhänger eine eigene Zeile behält
|
||||
und kein Termin in „weitere Termine“ wandert.
|
||||
|
||||
Drag & Drop verschiebt den Mietbeginn horizontal um ganze Tage (Mietdauer
|
||||
bleibt erhalten) und den Anhänger vertikal. Die Server-API validiert erneut,
|
||||
inklusive Überschneidungsprüfung; bei Konflikt bleibt die Buchung unverändert.
|
||||
|
||||
## Erinnerungen
|
||||
|
||||
Die drei Erinnerungen werden **nicht** als Datensätze angelegt, sondern bei
|
||||
jeder Anzeige aus `start_date`/`end_date` berechnet:
|
||||
|
||||
| Art | Fälligkeit | Text |
|
||||
|---|---|---|
|
||||
| `start_8` | Mietbeginn − 8 Tage | „Bitte mit dem Kunden einen Übergabetermin für den Kühlanhänger vereinbaren.“ |
|
||||
| `start_1` | Mietbeginn − 1 Tag | „Morgen steht die Übergabe bzw. Lieferung des Kühlanhängers an.“ |
|
||||
| `end_1` | Mietende − 1 Tag | „Morgen muss der Kühlanhänger beim Kunden abgeholt bzw. zurückgenommen werden.“ |
|
||||
|
||||
Vorteile: Terminänderungen passen die Erinnerungen automatisch an,
|
||||
Stornierungen lassen sie sofort verschwinden, und es kann kein veralteter
|
||||
Erinnerungsdatensatz zurückbleiben. „Erledigt“ wird separat in
|
||||
`reminder_done` gespeichert – inklusive Fälligkeitsdatum. Verschiebt sich der
|
||||
Termin, öffnet sich die Erinnerung wieder.
|
||||
|
||||
Sichtbarkeit: Admins sehen alle Erinnerungen, Mitarbeiter nur die Buchungen
|
||||
ihres verknüpften Mitarbeiterkontos. Das Mitarbeiterkonto wird im
|
||||
Benutzerformular zugeordnet (1:1).
|
||||
|
||||
Der optionale E-Mail-Digest (`tools/send_reminders.php` oder
|
||||
`/cron/reminders?token=…`) verschickt heute fällige und bis zu sieben Tage
|
||||
überfällige Erinnerungen gesammelt pro Mitarbeiter. Die In-App-Erinnerungen
|
||||
sind die primäre Anzeige und funktionieren ohne Mailversand.
|
||||
|
||||
## Benutzer und Anmeldung
|
||||
|
||||
- Anmeldung mit **Vorname + Nachname + Passwort** (wie tippspiel2027).
|
||||
- Keine Registrierung; Konten legt nur ein Admin an. Vor- und Nachname sind
|
||||
eindeutig und zugleich der Loginname.
|
||||
- Rollen: `admin` (darf Benutzer, Mitarbeiter, Anhänger verwalten) und `user`
|
||||
(darf Buchungen und Erinnerungen bearbeiten).
|
||||
- Der letzte aktive Admin kann nicht herabgestuft, deaktiviert oder gelöscht
|
||||
werden; das eigene Konto kann nicht deaktiviert werden.
|
||||
- Startpasswort und Passwort-Reset durch den Admin können
|
||||
„Passwort bei nächster Anmeldung ändern“ erzwingen.
|
||||
- Passwortwechsel erhöht `auth_epoch` und löscht Remember-Tokens; andere
|
||||
Geräte müssen sich neu anmelden.
|
||||
|
||||
## Anforderungsabdeckung
|
||||
|
||||
| Anforderung | Umsetzung |
|
||||
|---|---|
|
||||
| 2. Kalender, 8 Anhänger, je eine Zeile | `trailers` (8 Seeds), Kalenderzeilen mit fester Lane-Spalte, alle aktiven Anhänger immer sichtbar |
|
||||
| Tag/Woche/Monat, Google-ähnlich | `?view=day|week|month`, Navigation, Heute, Datumssprung |
|
||||
| Durchgehende farbige Balken | absolute Balken pro Zeile, Farbe aus `trailers.color_hex` |
|
||||
| Keine ausgeblendeten Termine | alle Buchungen im Zeitraum werden gerendert; Lanes statt „weitere Termine“ |
|
||||
| 3. Ganztägige Mietzeiträume | `DATE` ohne Uhrzeit, inklusive Endtag |
|
||||
| Keine Doppelbelegung, Wechseltag erlaubt | strikte Intervallprüfung + Zeilensperre, Wechseltag bewusst erlaubt |
|
||||
| 4. Felder in fester Reihenfolge | Formular und Kopiervorlage in exakt der vorgegebenen Reihenfolge |
|
||||
| Restbetrag automatisch | `total_cents − deposit_cents`, live im Formular und serverseitig berechnet |
|
||||
| Rechnung JA/NEIN, Art Abholer/Lieferung | Radio-Auswahl, Labels wie gefordert |
|
||||
| Komplett kopieren | Button nutzt Clipboard-API, Fallback `execCommand`; Text enthält Zeilenumbrüche |
|
||||
| 5. Mitarbeiterzuordnung | `bookings.employee_id`, Auswahl im Formular, änderbar |
|
||||
| 6. Drei automatische Erinnerungen | serverseitig aus den Daten berechnet, an den Mitarbeiter gebunden |
|
||||
| Erinnerungen passen sich an | keine gespeicherten Termine; Neuberechnung bei jedem Aufruf |
|
||||
| Stornierung entfernt Erinnerungen | nur `status = active` wird berücksichtigt |
|
||||
| 7. Buchungen verwalten | anlegen, bearbeiten, verschieben (Drag & Drop + Formular), stornieren, Anhänger/Mitarbeiter wechseln, Suche |
|
||||
| 8. Browser, PC/Tablet/Smartphone | responsive Layout, Kalender horizontal scrollbar, Touch-freundliche Formulare |
|
||||
| Mehrere Mitarbeiter gleichzeitig | zentrale DB, Sessions, Transaktionen |
|
||||
| 9. Übersicht | Dashboard mit Auslastung, freien Anhängern, Übergaben/Rücknahmen, Erinnerungen |
|
||||
| Benutzerverwaltung tippspiel2027 | Admin-only, Vorname/Nachname/Passwort, keine Selbstregistrierung |
|
||||
|
||||
## Betrieb
|
||||
|
||||
- Installation: `install.php?token=…` legt Schema und Grunddaten an, erzeugt den
|
||||
ersten Admin und ist danach gesperrt. Das Deployment löscht die Datei.
|
||||
- Backups: tägliches `mysqldump` der Datenbank empfohlen; Uploads gibt es keine.
|
||||
- Logs: `storage/logs/php.log` (außerhalb des öffentlichen Zugriffs).
|
||||
- E-Mail: `mail_enabled` ist standardmäßig aus. Der Digest ist optional; die
|
||||
App bleibt ohne Mailserver voll funktionsfähig.
|
||||
- Cron: `tools/send_reminders.php` per CLI oder token-geschützter HTTP-Aufruf.
|
||||
173
install.php
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Einmaliger Installer: legt das Schema an, setzt die Grunddaten und erzeugt
|
||||
* den ersten Administrator. Wird nach erfolgreicher Installation vom
|
||||
* Deployment entfernt.
|
||||
*/
|
||||
|
||||
define('DIC_ROOT', is_dir(__DIR__ . '/app') ? __DIR__ : dirname(__DIR__));
|
||||
define('DIC_APP', DIC_ROOT . '/app');
|
||||
|
||||
$configFile = DIC_APP . '/config.local.php';
|
||||
if (!is_file($configFile)) {
|
||||
http_response_code(500);
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
echo "app/config.local.php fehlt. Bitte zuerst deployen.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$config = require $configFile;
|
||||
$GLOBALS['dic_config'] = $config;
|
||||
date_default_timezone_set('Europe/Berlin');
|
||||
require DIC_APP . '/util.php';
|
||||
require DIC_APP . '/db.php';
|
||||
require DIC_APP . '/auth.php';
|
||||
|
||||
$expectedToken = (string) ($config['app']['install_token'] ?? '');
|
||||
$token = (string) ($_POST['token'] ?? $_GET['token'] ?? '');
|
||||
$tokenOk = $expectedToken !== '' && $token !== '' && hash_equals($expectedToken, $token);
|
||||
|
||||
$errors = [];
|
||||
$done = false;
|
||||
$alreadyInstalled = false;
|
||||
$installedName = '';
|
||||
|
||||
if (!$tokenOk) {
|
||||
http_response_code(403);
|
||||
$errors[] = 'Der Installations-Token ist ungültig. Bitte den Link aus dem Deployment verwenden.';
|
||||
} else {
|
||||
try {
|
||||
$pdo = db();
|
||||
$usersTable = $pdo->query("SHOW TABLES LIKE 'users'")->fetchColumn();
|
||||
if ($usersTable) {
|
||||
$count = (int) $pdo->query('SELECT COUNT(*) FROM users')->fetchColumn();
|
||||
if ($count > 0) {
|
||||
$alreadyInstalled = true;
|
||||
$row = $pdo->query('SELECT first_name, last_name FROM users ORDER BY id LIMIT 1')->fetch();
|
||||
$installedName = $row ? $row['first_name'] . ' ' . $row['last_name'] : '';
|
||||
}
|
||||
}
|
||||
} catch (Throwable $error) {
|
||||
$errors[] = 'Datenbankverbindung fehlgeschlagen. Bitte die Konfiguration prüfen.';
|
||||
}
|
||||
}
|
||||
|
||||
$values = [
|
||||
'first_name' => trim((string) ($_POST['first_name'] ?? '')),
|
||||
'last_name' => trim((string) ($_POST['last_name'] ?? '')),
|
||||
];
|
||||
|
||||
if ($tokenOk && !$alreadyInstalled && $_SERVER['REQUEST_METHOD'] === 'POST' && !$errors) {
|
||||
$password = (string) ($_POST['password'] ?? '');
|
||||
$repeat = (string) ($_POST['password_repeat'] ?? '');
|
||||
|
||||
if ($values['first_name'] === '' || $values['last_name'] === '') {
|
||||
$errors[] = 'Bitte Vor- und Nachnamen angeben.';
|
||||
}
|
||||
if (mb_strlen($password) < 8) {
|
||||
$errors[] = 'Das Passwort muss mindestens 8 Zeichen haben.';
|
||||
}
|
||||
if ($password !== $repeat) {
|
||||
$errors[] = 'Die Passwörter stimmen nicht überein.';
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$schema = (string) file_get_contents(DIC_APP . '/../sql/schema.sql');
|
||||
$schema = preg_replace('/^\s*--.*$/m', '', $schema) ?? $schema;
|
||||
foreach (array_filter(array_map('trim', explode(';', $schema))) as $statement) {
|
||||
if ($statement !== '') {
|
||||
$pdo->exec($statement);
|
||||
}
|
||||
}
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO users (first_name, last_name, email, password_hash, role, status, employee_id,
|
||||
must_change_password, auth_epoch, created_at, updated_at, last_login_at, password_changed_at)
|
||||
VALUES (?, ?, NULL, ?, "admin", "active", NULL, 0, 1, ?, ?, NULL, ?)'
|
||||
);
|
||||
$stmt->execute([$values['first_name'], $values['last_name'], hash_password($password), utc_now(), utc_now(), utc_now()]);
|
||||
$done = true;
|
||||
} catch (Throwable $error) {
|
||||
$errors[] = 'Installation fehlgeschlagen: ' . $error->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$base = rtrim((string) ($config['app']['base_path'] ?? ''), '/');
|
||||
$css = ($base !== '' ? $base : '') . '/assets/app.css';
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Installation · Drink it cold</title>
|
||||
<link rel="icon" type="image/svg+xml" href="<?= htmlspecialchars(($base !== '' ? $base : '') . '/assets/favicon.svg') ?>">
|
||||
<link rel="stylesheet" href="<?= htmlspecialchars($css) ?>">
|
||||
</head>
|
||||
<body class="auth-page">
|
||||
<div class="auth-shell">
|
||||
<section class="auth-visual" aria-hidden="true">
|
||||
<img class="auth-visual__bg" src="<?= htmlspecialchars(($base !== '' ? $base : '') . '/assets/img/hero-1280.webp') ?>" alt="">
|
||||
<div class="auth-visual__shade"></div>
|
||||
<div class="auth-visual__content">
|
||||
<div class="auth-brand">
|
||||
<img src="<?= htmlspecialchars(($base !== '' ? $base : '') . '/assets/logo-mark.svg') ?>" alt="" width="56" height="40">
|
||||
<span><strong>Drink it cold</strong><small>Kühlanhänger-Vermietung</small></span>
|
||||
</div>
|
||||
<div class="auth-visual__claim">
|
||||
<p class="eyebrow">Einrichtung</p>
|
||||
<h2>Einmal einrichten.<br>Dann läuft es.</h2>
|
||||
<p>Der Installer legt die acht Anhänger, das Mitarbeiter-Team und den ersten Administrator an.</p>
|
||||
</div>
|
||||
<p class="auth-visual__foot">Drink it cold · Neuss</p>
|
||||
</div>
|
||||
</section>
|
||||
<section class="auth-panel">
|
||||
<div class="auth-card">
|
||||
<p class="eyebrow">Installation</p>
|
||||
<h1>Drink it cold</h1>
|
||||
|
||||
<?php if ($alreadyInstalled): ?>
|
||||
<p class="auth-card__lede">Die Anwendung ist bereits eingerichtet<?= $installedName !== '' ? ' (erster Benutzer: ' . htmlspecialchars($installedName) . ')' : '' ?>.</p>
|
||||
<div class="alert alert--error"><strong>Der Installer ist gesperrt.</strong><p>Bitte die Datei install.php auf dem Server löschen, falls das noch nicht geschehen ist.</p></div>
|
||||
<a class="btn primary btn--block" href="<?= htmlspecialchars(($base !== '' ? $base : '') . '/login') ?>">Zur Anmeldung</a>
|
||||
<?php elseif ($done): ?>
|
||||
<p class="auth-card__lede">Die Anwendung ist eingerichtet.</p>
|
||||
<div class="alert" style="background:var(--green-soft);border-color:#bfe3bf;color:#1f5a23">
|
||||
<strong>Fertig.</strong><p>Der Administrator wurde angelegt. Bitte install.php jetzt vom Server entfernen.</p>
|
||||
</div>
|
||||
<a class="btn primary btn--block" href="<?= htmlspecialchars(($base !== '' ? $base : '') . '/login') ?>">Jetzt anmelden</a>
|
||||
<?php else: ?>
|
||||
<p class="auth-card__lede">Erster Administrator und Grunddaten. Der Token steht in der Server-Konfiguration.</p>
|
||||
|
||||
<?php if ($errors): ?>
|
||||
<div class="alert alert--error" role="alert"><div><strong>Bitte prüfen.</strong>
|
||||
<?php foreach ($errors as $error): ?><p><?= htmlspecialchars($error) ?></p><?php endforeach; ?>
|
||||
</div></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" class="auth-form">
|
||||
<?php if ($tokenOk): ?>
|
||||
<input type="hidden" name="token" value="<?= htmlspecialchars($token) ?>">
|
||||
<?php else: ?>
|
||||
<label class="field"><span>Installations-Token</span><input type="text" name="token" required autocomplete="off"></label>
|
||||
<?php endif; ?>
|
||||
<div class="field-row">
|
||||
<label class="field"><span>Vorname</span><input type="text" name="first_name" value="<?= htmlspecialchars($values['first_name']) ?>" required autofocus></label>
|
||||
<label class="field"><span>Nachname</span><input type="text" name="last_name" value="<?= htmlspecialchars($values['last_name']) ?>" required></label>
|
||||
</div>
|
||||
<label class="field"><span>Passwort</span><input type="password" name="password" minlength="8" required autocomplete="new-password"></label>
|
||||
<label class="field"><span>Passwort wiederholen</span><input type="password" name="password_repeat" minlength="8" required autocomplete="new-password"></label>
|
||||
<button class="btn primary btn--block" type="submit">Installation starten</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
7
sql/.htaccess
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
</IfModule>
|
||||
163
sql/schema.sql
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
-- Drink it cold – Datenbankschema (MariaDB 10.11, utf8mb4)
|
||||
--
|
||||
-- Wird vom Installer (install.php) angewendet. Datumsangaben sind reine
|
||||
-- Kalendertage; Zeitstempel werden in UTC gespeichert. Änderungen am Schema
|
||||
-- bekommen eine neue Nummer in schema_migrations.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
version INT UNSIGNED NOT NULL,
|
||||
applied_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (version)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS trailers (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
label VARCHAR(40) NOT NULL,
|
||||
color_name VARCHAR(40) NOT NULL,
|
||||
color_hex CHAR(7) NOT NULL,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_trailers_label (label),
|
||||
KEY idx_trailers_sort (active, sort_order)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS employees (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_employees_name (name),
|
||||
KEY idx_employees_sort (active, sort_order)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
first_name VARCHAR(80) NOT NULL,
|
||||
last_name VARCHAR(80) NOT NULL,
|
||||
email VARCHAR(190) NULL,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
role ENUM('admin', 'user') NOT NULL DEFAULT 'user',
|
||||
status ENUM('active', 'disabled') NOT NULL DEFAULT 'active',
|
||||
employee_id BIGINT UNSIGNED NULL,
|
||||
must_change_password TINYINT(1) NOT NULL DEFAULT 1,
|
||||
auth_epoch INT UNSIGNED NOT NULL DEFAULT 1,
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL,
|
||||
last_login_at DATETIME NULL,
|
||||
password_changed_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_users_name (first_name, last_name),
|
||||
UNIQUE KEY uq_users_email (email),
|
||||
UNIQUE KEY uq_users_employee (employee_id),
|
||||
CONSTRAINT fk_users_employee FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS bookings (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
trailer_id BIGINT UNSIGNED NOT NULL,
|
||||
employee_id BIGINT UNSIGNED NOT NULL,
|
||||
start_date DATE NOT NULL,
|
||||
end_date DATE NOT NULL,
|
||||
deposit_cents INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
total_cents INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
invoice TINYINT(1) NOT NULL DEFAULT 0,
|
||||
kind ENUM('pickup', 'delivery') NOT NULL DEFAULT 'pickup',
|
||||
customer_name VARCHAR(190) NOT NULL,
|
||||
street VARCHAR(190) NOT NULL DEFAULT '',
|
||||
city VARCHAR(190) NOT NULL DEFAULT '',
|
||||
mobile VARCHAR(60) NOT NULL DEFAULT '',
|
||||
email VARCHAR(190) NOT NULL DEFAULT '',
|
||||
status ENUM('active', 'cancelled') NOT NULL DEFAULT 'active',
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL,
|
||||
created_by BIGINT UNSIGNED NULL,
|
||||
updated_by BIGINT UNSIGNED NULL,
|
||||
cancelled_at DATETIME NULL,
|
||||
cancelled_by BIGINT UNSIGNED NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_bookings_period (status, start_date, end_date),
|
||||
KEY idx_bookings_trailer (trailer_id, status, start_date),
|
||||
KEY idx_bookings_employee (employee_id, status, start_date),
|
||||
KEY idx_bookings_customer (customer_name),
|
||||
CONSTRAINT fk_bookings_trailer FOREIGN KEY (trailer_id) REFERENCES trailers (id) ON DELETE RESTRICT,
|
||||
CONSTRAINT fk_bookings_employee FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE RESTRICT,
|
||||
CONSTRAINT fk_bookings_created_by FOREIGN KEY (created_by) REFERENCES users (id) ON DELETE SET NULL,
|
||||
CONSTRAINT fk_bookings_updated_by FOREIGN KEY (updated_by) REFERENCES users (id) ON DELETE SET NULL,
|
||||
CONSTRAINT fk_bookings_cancelled_by FOREIGN KEY (cancelled_by) REFERENCES users (id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Abgehakte Erinnerungen. Der Schlüssel enthält das Fälligkeitsdatum, damit
|
||||
-- eine Terminverschiebung die Erinnerung automatisch wieder öffnet.
|
||||
CREATE TABLE IF NOT EXISTS reminder_done (
|
||||
booking_id BIGINT UNSIGNED NOT NULL,
|
||||
kind ENUM('start_8', 'start_1', 'end_1') NOT NULL,
|
||||
due_date DATE NOT NULL,
|
||||
done_by BIGINT UNSIGNED NULL,
|
||||
done_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (booking_id, kind, due_date),
|
||||
KEY idx_reminder_done_due (due_date),
|
||||
CONSTRAINT fk_reminder_done_booking FOREIGN KEY (booking_id) REFERENCES bookings (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_reminder_done_user FOREIGN KEY (done_by) REFERENCES users (id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Versandprotokoll für den täglichen E-Mail-Digest (verhindert Doppelmails).
|
||||
CREATE TABLE IF NOT EXISTS reminder_mail_log (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
booking_id BIGINT UNSIGNED NOT NULL,
|
||||
kind ENUM('start_8', 'start_1', 'end_1') NOT NULL,
|
||||
due_date DATE NOT NULL,
|
||||
employee_id BIGINT UNSIGNED NULL,
|
||||
sent_to VARCHAR(190) NOT NULL,
|
||||
sent_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_reminder_mail (booking_id, kind, due_date),
|
||||
KEY idx_reminder_mail_employee (employee_id, sent_at),
|
||||
CONSTRAINT fk_reminder_mail_booking FOREIGN KEY (booking_id) REFERENCES bookings (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_reminder_mail_employee FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS auth_tokens (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
user_id BIGINT UNSIGNED NOT NULL,
|
||||
selector CHAR(24) NOT NULL,
|
||||
validator_hash CHAR(64) NOT NULL,
|
||||
created_at DATETIME NOT NULL,
|
||||
expires_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_auth_tokens_selector (selector),
|
||||
KEY idx_auth_tokens_user (user_id, expires_at),
|
||||
CONSTRAINT fk_auth_tokens_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS login_attempts (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
name_key VARCHAR(170) NOT NULL,
|
||||
attempted_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_login_ip (ip, attempted_at),
|
||||
KEY idx_login_name (name_key, attempted_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Grundausstattung: 8 Kühlanhänger (Farben laut Anforderung) und das
|
||||
-- bestehende Mitarbeiter-Team. Bestehende Zeilen bleiben bei erneutem
|
||||
-- Installationslauf unverändert.
|
||||
INSERT IGNORE INTO trailers (label, color_name, color_hex, sort_order) VALUES
|
||||
('Nr. 1', 'Grün', '#2e7d32', 10),
|
||||
('Nr. 2', 'Gelb', '#d8a412', 20),
|
||||
('Nr. 3', 'Rot', '#c0392b', 30),
|
||||
('Nr. 4', 'Blau', '#196abc', 40),
|
||||
('Nr. 5', 'Lila', '#7b3fa0', 50),
|
||||
('Nr. 6', 'Braun', '#795548', 60),
|
||||
('Nr. 7', 'Hellgrau', '#9aa7b1', 70),
|
||||
('Nr. 8', 'Schwarz', '#263238', 80);
|
||||
|
||||
INSERT IGNORE INTO employees (name, sort_order, created_at) VALUES
|
||||
('M. Krücken', 10, UTC_TIMESTAMP()),
|
||||
('N. Jorns', 20, UTC_TIMESTAMP()),
|
||||
('M. Schmitz', 30, UTC_TIMESTAMP());
|
||||
|
||||
INSERT IGNORE INTO schema_migrations (version, applied_at) VALUES (1, UTC_TIMESTAMP());
|
||||
7
storage/.htaccess
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
</IfModule>
|
||||
7
tools/.htaccess
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
</IfModule>
|
||||
251
tools/deploy.sh
Executable file
|
|
@ -0,0 +1,251 @@
|
|||
#!/usr/bin/env bash
|
||||
# Deployt die Drink-it-cold-Terminplanung auf
|
||||
# drink-it-cold.programmschmiede.de.
|
||||
#
|
||||
# Aufruf:
|
||||
# ./tools/deploy.sh --check # Health, Login-Seite und Asset prüfen
|
||||
# ./tools/deploy.sh --sync # Code, Assets und Konfiguration hochladen
|
||||
# ./tools/deploy.sh --install # Schema + ersten Admin anlegen (einmalig)
|
||||
# ./tools/deploy.sh --all # sync + install + check
|
||||
#
|
||||
# Die Zugangsdaten kommen aus docs/credentials.txt (gitignored). Für die
|
||||
# Installation werden DIC_ADMIN_FIRST, DIC_ADMIN_LAST und DIC_ADMIN_PASSWORD
|
||||
# aus der Umgebung gelesen; fehlen sie, wird interaktiv gefragt.
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
CREDENTIALS="$REPO_ROOT/docs/credentials.txt"
|
||||
REMOTE_DIR="drink-it-cold.programmschmiede.de"
|
||||
PUBLIC_URL="https://drink-it-cold.programmschmiede.de"
|
||||
|
||||
MODE="check"
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--check) MODE="check" ;;
|
||||
--sync) MODE="sync" ;;
|
||||
--install) MODE="install" ;;
|
||||
--all) MODE="all" ;;
|
||||
-h|--help)
|
||||
sed -n '2,13p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
;;
|
||||
*) echo "Unbekannte Option: $1" >&2; exit 2 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
[[ -f "$CREDENTIALS" ]] || { echo "Fehlt: $CREDENTIALS" >&2; exit 1; }
|
||||
|
||||
cred() {
|
||||
grep -m1 "^$1=" "$CREDENTIALS" | cut -d= -f2- | tr -d '\r' | sed 's/[[:space:]]*$//'
|
||||
}
|
||||
|
||||
FTP_URL="$(cred FTP_URL)"
|
||||
FTP_USER="$(cred FTP_USER)"
|
||||
FTP_PASSWORD="$(cred FTP_PASSWORD)"
|
||||
DB_HOST="$(cred DB_HOST)"
|
||||
DB_NAME="$(cred DB_NAME)"
|
||||
DB_USER="$(cred DB_USER)"
|
||||
DB_PASSWORD="$(cred DB_PASSWORD)"
|
||||
|
||||
HOST="${FTP_URL#ftp://}"
|
||||
HOST="${HOST#ftps://}"
|
||||
HOST="${HOST%%/*}"
|
||||
HOST="${HOST%%:*}"
|
||||
[[ -n "$HOST" && -n "$FTP_USER" ]] || { echo "FTP-Zugang unvollständig." >&2; exit 1; }
|
||||
|
||||
TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/dic-deploy.XXXXXX")"
|
||||
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||
|
||||
CURL=(curl --ssl-reqd --insecure --silent --show-error --connect-timeout 20 --max-time 900 --user "$FTP_USER:$FTP_PASSWORD")
|
||||
|
||||
ftp_url() {
|
||||
printf 'ftp://%s/%s/%s' "$HOST" "$REMOTE_DIR" "$1"
|
||||
}
|
||||
|
||||
ftp_put() {
|
||||
local local_path="$1" remote_path="$2"
|
||||
"${CURL[@]}" --ftp-create-dirs -T "$local_path" "$(ftp_url "$remote_path")"
|
||||
}
|
||||
|
||||
ftp_get() {
|
||||
local remote_path="$1" local_path="$2"
|
||||
"${CURL[@]}" -o "$local_path" "$(ftp_url "$remote_path")"
|
||||
}
|
||||
|
||||
ftp_chmod() {
|
||||
local mode="$1" remote_path="$2"
|
||||
"${CURL[@]}" "ftp://$HOST/" -Q "SITE CHMOD $mode $REMOTE_DIR/$remote_path" >/dev/null || true
|
||||
}
|
||||
|
||||
http_code() {
|
||||
curl -sS -o /dev/null -w '%{http_code}' --max-time 30 "$1" || true
|
||||
}
|
||||
|
||||
make_config() {
|
||||
local token="$1" cron_token="$2"
|
||||
DIC_INSTALL_TOKEN="$token" DIC_CRON_TOKEN="$cron_token" DIC_PUBLIC_URL="$PUBLIC_URL" \
|
||||
DIC_MAIL_ENABLED="${DIC_MAIL_ENABLED:-false}" \
|
||||
DIC_MAIL_FROM="${DIC_MAIL_FROM:-Drink it cold <noreply@drink-it-cold.programmschmiede.de>}" \
|
||||
DB_HOST="${DB_HOST:-localhost}" DB_NAME="$DB_NAME" DB_USER="$DB_USER" DB_PASSWORD="$DB_PASSWORD" \
|
||||
python3 - "$TMP_DIR/config.local.php" <<'PY'
|
||||
import os
|
||||
import sys
|
||||
|
||||
def php(value):
|
||||
return "'" + str(value).replace('\\', '\\\\').replace("'", "\\'") + "'"
|
||||
|
||||
target = sys.argv[1]
|
||||
mail_enabled = 'true' if os.environ.get('DIC_MAIL_ENABLED', '').strip().lower() in ('1', 'true', 'yes', 'on') else 'false'
|
||||
config = f"""<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
'db' => [
|
||||
'host' => {php(os.environ.get('DB_HOST') or 'localhost')},
|
||||
'port' => 3306,
|
||||
'name' => {php(os.environ['DB_NAME'])},
|
||||
'user' => {php(os.environ['DB_USER'])},
|
||||
'password' => {php(os.environ['DB_PASSWORD'])},
|
||||
'charset' => 'utf8mb4',
|
||||
],
|
||||
'app' => [
|
||||
'base_path' => '',
|
||||
'public_url' => {php(os.environ['DIC_PUBLIC_URL'])},
|
||||
'storage_path' => dirname(__DIR__) . '/storage',
|
||||
'install_token' => {php(os.environ['DIC_INSTALL_TOKEN'])},
|
||||
'session_idle_seconds' => 30 * 86400,
|
||||
'session_absolute_seconds' => 90 * 86400,
|
||||
'remember_seconds' => 90 * 86400,
|
||||
'login_window_seconds' => 900,
|
||||
'login_max_per_user' => 5,
|
||||
'login_max_per_ip' => 15,
|
||||
'mail_enabled' => {mail_enabled},
|
||||
'mail_from' => {php(os.environ['DIC_MAIL_FROM'])},
|
||||
|
||||
'cron_token' => {php(os.environ['DIC_CRON_TOKEN'])},
|
||||
],
|
||||
];
|
||||
"""
|
||||
with open(target, 'w', encoding='utf-8') as handle:
|
||||
handle.write(config)
|
||||
os.chmod(target, 0o600)
|
||||
PY
|
||||
}
|
||||
|
||||
upload_tree() {
|
||||
local source_root="$1" remote_prefix="$2"
|
||||
while IFS= read -r file; do
|
||||
local relative="${file#"$source_root"/}"
|
||||
case "$relative" in
|
||||
config.local.php|config.example.php|.DS_Store|*.swp) continue ;;
|
||||
esac
|
||||
ftp_put "$file" "$remote_prefix$relative"
|
||||
echo " $remote_prefix$relative"
|
||||
done < <(find "$source_root" -type f | sort)
|
||||
}
|
||||
|
||||
do_sync() {
|
||||
local token cron_token
|
||||
token="$(openssl rand -hex 24)"
|
||||
cron_token="$(openssl rand -hex 24)"
|
||||
make_config "$token" "$cron_token"
|
||||
|
||||
echo "Lade Anwendung hoch …"
|
||||
upload_tree "$REPO_ROOT/app" "app/"
|
||||
upload_tree "$REPO_ROOT/views" "views/"
|
||||
upload_tree "$REPO_ROOT/sql" "sql/"
|
||||
upload_tree "$REPO_ROOT/web" ""
|
||||
echo "Lade Cron-Skript und Konfiguration hoch …"
|
||||
ftp_put "$REPO_ROOT/tools/send_reminders.php" "tools/send_reminders.php"
|
||||
ftp_put "$REPO_ROOT/tools/.htaccess" "tools/.htaccess"
|
||||
ftp_put "$TMP_DIR/config.local.php" "app/config.local.php"
|
||||
ftp_chmod 600 "app/config.local.php"
|
||||
|
||||
# Leeres Log-Verzeichnis anlegen (FTP kann keine Ordner ohne Datei erstellen).
|
||||
printf '' > "$TMP_DIR/.gitkeep"
|
||||
ftp_put "$TMP_DIR/.gitkeep" "storage/logs/.gitkeep"
|
||||
ftp_put "$REPO_ROOT/storage/.htaccess" "storage/.htaccess"
|
||||
echo "Sync fertig. Install-Token liegt nur auf dem Server."
|
||||
}
|
||||
|
||||
install_if_needed() {
|
||||
local config_file="$TMP_DIR/remote-config.php"
|
||||
if ! ftp_get "app/config.local.php" "$config_file" 2>/dev/null; then
|
||||
echo "Konfiguration fehlt auf dem Server; zuerst --sync ausführen." >&2
|
||||
exit 1
|
||||
fi
|
||||
local token
|
||||
token="$(python3 - "$config_file" <<'PY'
|
||||
import re, sys
|
||||
text = open(sys.argv[1], encoding='utf-8').read()
|
||||
match = re.search(r"'install_token'\s*=>\s*'([^']+)'", text)
|
||||
print(match.group(1) if match else '')
|
||||
PY
|
||||
)"
|
||||
[[ -n "$token" ]] || { echo "Install-Token nicht gefunden." >&2; exit 1; }
|
||||
|
||||
local first="${DIC_ADMIN_FIRST:-$(cred DIC_ADMIN_FIRST)}"
|
||||
local last="${DIC_ADMIN_LAST:-$(cred DIC_ADMIN_LAST)}"
|
||||
local password="${DIC_ADMIN_PASSWORD:-$(cred DIC_ADMIN_PASSWORD)}"
|
||||
if [[ -z "$first" ]]; then
|
||||
read -r -p "Vorname des Administrators: " first
|
||||
fi
|
||||
if [[ -z "$last" ]]; then
|
||||
read -r -p "Nachname des Administrators: " last
|
||||
fi
|
||||
if [[ -z "$password" ]]; then
|
||||
read -r -s -p "Passwort (mind. 8 Zeichen): " password
|
||||
echo
|
||||
fi
|
||||
|
||||
echo "Lade Installer hoch …"
|
||||
ftp_put "$REPO_ROOT/install.php" "install.php"
|
||||
echo "Rufe Installer auf …"
|
||||
local response status
|
||||
response="$(curl -sS --max-time 300 -w '\n%{http_code}' \
|
||||
--data-urlencode "token=$token" \
|
||||
--data-urlencode "first_name=$first" \
|
||||
--data-urlencode "last_name=$last" \
|
||||
--data-urlencode "password=$password" \
|
||||
--data-urlencode "password_repeat=$password" \
|
||||
"$PUBLIC_URL/install.php" 2>&1)" || true
|
||||
status="${response##*$'\n'}"
|
||||
local body="${response%$'\n'*}"
|
||||
if [[ "$body" == *"bereits eingerichtet"* ]]; then
|
||||
echo "Anwendung ist bereits installiert; kein zweiter Admin angelegt."
|
||||
elif [[ "$status" == "200" && "$body" == *"Fertig."* ]]; then
|
||||
echo "Installation abgeschlossen."
|
||||
else
|
||||
echo "Installation fehlgeschlagen (HTTP $status)." >&2
|
||||
echo "$body" | sed -E 's/<[^>]+>/ /g' | tr -s ' \n' ' ' | head -c 1200 >&2
|
||||
echo >&2
|
||||
exit 1
|
||||
fi
|
||||
"${CURL[@]}" "ftp://$HOST/" -Q "-DELE $REMOTE_DIR/install.php" >/dev/null 2>&1 || true
|
||||
echo "install.php auf dem Server entfernt."
|
||||
}
|
||||
|
||||
do_check() {
|
||||
local health login title css
|
||||
health="$(curl -sS --max-time 30 "$PUBLIC_URL/health" || true)"
|
||||
if [[ "$health" != "ok" ]]; then
|
||||
echo "Health-Check fehlgeschlagen: $health" >&2
|
||||
exit 1
|
||||
fi
|
||||
login="$(http_code "$PUBLIC_URL/login")"
|
||||
css="$(http_code "$PUBLIC_URL/assets/app.css")"
|
||||
title="$(curl -sS --max-time 30 "$PUBLIC_URL/login" | grep -o '<title>[^<]*' | head -1 || true)"
|
||||
echo "Health: ok"
|
||||
echo "Login: HTTP $login"
|
||||
echo "Assets: HTTP $css"
|
||||
echo "Titel: ${title#<title>}"
|
||||
[[ "$login" == "200" && "$css" == "200" ]] || { echo "Check fehlgeschlagen." >&2; exit 1; }
|
||||
}
|
||||
|
||||
case "$MODE" in
|
||||
sync) do_sync ;;
|
||||
install) install_if_needed ;;
|
||||
check) do_check ;;
|
||||
all) do_sync; install_if_needed; do_check ;;
|
||||
esac
|
||||
18
tools/router.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Router für den lokalen Entwicklungsserver:
|
||||
* php -S 127.0.0.1:8099 -t web tools/router.php
|
||||
*/
|
||||
|
||||
$path = (string) parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
|
||||
if ($path === '/install.php') {
|
||||
require __DIR__ . '/../install.php';
|
||||
return;
|
||||
}
|
||||
$file = __DIR__ . '/../web' . $path;
|
||||
if ($path !== '/' && is_file($file)) {
|
||||
return false;
|
||||
}
|
||||
require __DIR__ . '/../web/index.php';
|
||||
42
tools/send_reminders.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Täglicher Erinnerungs-Digest per E-Mail.
|
||||
*
|
||||
* Cron-Beispiel (täglich 07:00):
|
||||
* 0 7 * * * /usr/bin/php /pfad/zu/drink-it-cold/tools/send_reminders.php
|
||||
*
|
||||
* Voraussetzung: app.mail_enabled = true und Benutzer mit E-Mail-Adresse,
|
||||
* die mit einem Mitarbeiterkonto verknüpft sind. Die In-App-Erinnerungen
|
||||
* funktionieren unabhängig davon.
|
||||
*/
|
||||
|
||||
require __DIR__ . '/../app/bootstrap.php';
|
||||
|
||||
$lookback = 7;
|
||||
foreach ($argv ?? [] as $arg) {
|
||||
if (preg_match('/^--lookback=(\d+)$/', $arg, $m)) {
|
||||
$lookback = max(1, min(60, (int) $m[1]));
|
||||
}
|
||||
}
|
||||
|
||||
$result = reminder_send_due($lookback);
|
||||
|
||||
if (!$result['enabled']) {
|
||||
fwrite(STDOUT, "E-Mail-Versand ist deaktiviert (app.mail_enabled = false).\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fwrite(STDOUT, sprintf(
|
||||
"Erinnerungen: %d versendet, %d übersprungen.\n",
|
||||
$result['sent'],
|
||||
$result['skipped']
|
||||
));
|
||||
foreach ($result['details'] as $detail) {
|
||||
fwrite(STDOUT, ' ' . $detail . "\n");
|
||||
}
|
||||
foreach ($result['errors'] as $error) {
|
||||
fwrite(STDERR, ' Fehler: ' . $error . "\n");
|
||||
}
|
||||
exit($result['errors'] ? 1 : 0);
|
||||
7
views/.htaccess
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
</IfModule>
|
||||
15
views/_admin_nav.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
$path = current_path();
|
||||
$items = [
|
||||
'/admin/users' => ['label' => 'Benutzer', 'icon' => 'i-user'],
|
||||
'/admin/employees' => ['label' => 'Mitarbeiter', 'icon' => 'i-users'],
|
||||
'/admin/trailers' => ['label' => 'Anhänger', 'icon' => 'i-truck'],
|
||||
];
|
||||
?>
|
||||
<nav class="admin-nav" aria-label="Verwaltung">
|
||||
<?php foreach ($items as $href => $item): ?>
|
||||
<a href="<?= e(url($href)) ?>"<?= str_starts_with($path, $href) ? ' class="is-active" aria-current="page"' : '' ?>>
|
||||
<svg class="ico" aria-hidden="true"><use href="#<?= e($item['icon']) ?>"/></svg><?= e($item['label']) ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</nav>
|
||||
68
views/account.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/** @var array $errors */
|
||||
/** @var array|null $employee */
|
||||
$mustChange = (int) ($user['must_change_password'] ?? 0) === 1;
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Mein Konto</p>
|
||||
<h1><?= e($user['first_name'] . ' ' . $user['last_name']) ?></h1>
|
||||
<p class="page-head__lede">Persönlicher Zugang für die Terminplanung.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($mustChange): ?>
|
||||
<div class="alert alert--warning">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Bitte ein neues Passwort vergeben.</strong> Das Startpasswort wurde vom Administrator gesetzt.</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="account-grid">
|
||||
<section class="card">
|
||||
<h2>Zugang</h2>
|
||||
<dl class="meta-list">
|
||||
<div><dt>Vorname</dt><dd><?= e($user['first_name']) ?></dd></div>
|
||||
<div><dt>Nachname</dt><dd><?= e($user['last_name']) ?></dd></div>
|
||||
<div><dt>Rolle</dt><dd><span class="pill <?= ($user['role'] ?? '') === 'admin' ? 'pill--blue' : 'pill--grey' ?>"><?= ($user['role'] ?? '') === 'admin' ? 'Administrator' : 'Mitarbeiter' ?></span></dd></div>
|
||||
<div><dt>Mitarbeiterkonto</dt><dd><?= e($employee['name'] ?? 'nicht verknüpft') ?></dd></div>
|
||||
<?php if (!empty($user['email'])): ?>
|
||||
<div><dt>E-Mail</dt><dd><?= e($user['email']) ?></dd></div>
|
||||
<?php endif; ?>
|
||||
<div><dt>Letzte Anmeldung</dt><dd><?= e(fmt_datetime($user['last_login_at'] ?? null)) ?></dd></div>
|
||||
</dl>
|
||||
<p class="muted small">Vor- und Nachname werden ausschließlich vom Administrator verwaltet. Für Änderungen bitte dort melden.</p>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Passwort ändern</h2>
|
||||
<p class="muted">Mindestens 8 Zeichen. Nach der Änderung müssen sich andere Geräte neu anmelden.</p>
|
||||
|
||||
<?php if ($errors): ?>
|
||||
<div class="alert alert--error" role="alert">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div>Bitte die markierten Felder prüfen.</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="<?= e(url('/account')) ?>" class="stack">
|
||||
<?= csrf_field() ?>
|
||||
<label class="field<?= isset($errors['current_password']) ? ' has-error' : '' ?>">
|
||||
<span>Aktuelles Passwort</span>
|
||||
<input type="password" name="current_password" autocomplete="current-password" required>
|
||||
<?php if (isset($errors['current_password'])): ?><em class="field-error"><?= e($errors['current_password']) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field<?= isset($errors['new_password']) ? ' has-error' : '' ?>">
|
||||
<span>Neues Passwort</span>
|
||||
<input type="password" name="new_password" autocomplete="new-password" minlength="8" required>
|
||||
<?php if (isset($errors['new_password'])): ?><em class="field-error"><?= e($errors['new_password']) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field<?= isset($errors['repeat_password']) ? ' has-error' : '' ?>">
|
||||
<span>Neues Passwort wiederholen</span>
|
||||
<input type="password" name="repeat_password" autocomplete="new-password" minlength="8" required>
|
||||
<?php if (isset($errors['repeat_password'])): ?><em class="field-error"><?= e($errors['repeat_password']) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<button class="btn primary" type="submit">Passwort speichern</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
96
views/admin_employees.php
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/** @var array $rows */
|
||||
/** @var array|null $editing */
|
||||
/** @var int $editId */
|
||||
/** @var array $values */
|
||||
/** @var array $errors */
|
||||
$fieldError = static fn (string $key): string => (string) ($errors[$key] ?? '');
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Verwaltung</p>
|
||||
<h1>Mitarbeiter</h1>
|
||||
<p class="page-head__lede">Jede Buchung bekommt einen zuständigen Mitarbeiter. Erinnerungen gehen an diese Zuordnung.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require __DIR__ . '/_admin_nav.php'; ?>
|
||||
|
||||
<div class="admin-split">
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2><?= $editing ? 'Mitarbeiter bearbeiten' : 'Mitarbeiter anlegen' ?></h2>
|
||||
<p><?= $editing ? 'Name, Reihenfolge und Status anpassen.' : 'Neue Mitarbeiter stehen sofort in der Buchungsmaske zur Auswahl.' ?></p>
|
||||
</div>
|
||||
|
||||
<?php if ($errors): ?>
|
||||
<div class="alert alert--error" role="alert">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Bitte prüfen.</strong>
|
||||
<?php if ($fieldError('name')): ?><p><?= e($fieldError('name')) ?></p><?php endif; ?>
|
||||
<?php if ($fieldError('active')): ?><p><?= e($fieldError('active')) ?></p><?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="<?= e(url('/admin/employees' . ($editing ? '?edit=' . (int) $editing['id'] : ''))) ?>" class="stack">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="action" value="<?= $editing ? 'update' : 'create' ?>">
|
||||
<?php if ($editing): ?><input type="hidden" name="id" value="<?= (int) $editing['id'] ?>"><?php endif; ?>
|
||||
<label class="field<?= $fieldError('name') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Name (wie im Kalender)</span>
|
||||
<input type="text" name="name" value="<?= e($values['name']) ?>" maxlength="100" required placeholder="z. B. M. Krücken">
|
||||
<?php if ($fieldError('name')): ?><em class="field-error"><?= e($fieldError('name')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Sortierung</span>
|
||||
<input type="number" name="sort_order" value="<?= (int) $values['sort_order'] ?>" step="10">
|
||||
</label>
|
||||
<div class="field">
|
||||
<span>Status</span>
|
||||
<label class="check check--boxed">
|
||||
<input type="hidden" name="active" value="0">
|
||||
<input type="checkbox" name="active" value="1"<?= (int) $values['active'] === 1 ? ' checked' : '' ?>>
|
||||
<span>Mitarbeiter ist aktiv</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn primary" type="submit"><?= $editing ? 'Speichern' : 'Mitarbeiter anlegen' ?></button>
|
||||
<?php if ($editing): ?><a class="btn" href="<?= e(url('/admin/employees')) ?>">Abbrechen</a><?php endif; ?>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2>Team</h2>
|
||||
<p>Buchungen bleiben auch bei Namensänderungen erhalten.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Benutzerkonto</th>
|
||||
<th>Kommende Buchungen</th>
|
||||
<th>Status</th>
|
||||
<th class="ta-right">Aktion</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($rows as $row): ?>
|
||||
<tr>
|
||||
<td><strong><?= e($row['name']) ?></strong></td>
|
||||
<td><?= e($row['first_name'] ? $row['first_name'] . ' ' . $row['last_name'] : '–') ?></td>
|
||||
<td><?= (int) $row['future_bookings'] ?></td>
|
||||
<td><span class="pill <?= (int) $row['active'] === 1 ? 'pill--green' : 'pill--grey' ?>"><?= (int) $row['active'] === 1 ? 'aktiv' : 'inaktiv' ?></span></td>
|
||||
<td class="ta-right"><a class="btn small" href="<?= e(url('/admin/employees?edit=' . (int) $row['id'])) ?>">Bearbeiten</a></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
62
views/admin_trailers.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/** @var array $rows */
|
||||
/** @var array $errors */
|
||||
$fieldError = static fn (int $id): string => (string) ($errors['trailer_' . $id] ?? '');
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Verwaltung</p>
|
||||
<h1>Kühlanhänger</h1>
|
||||
<p class="page-head__lede">Acht Anhänger, acht Farben. Bezeichnung und Farbe lassen sich anpassen – die Farbe steuert die Balken im Kalender.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require __DIR__ . '/_admin_nav.php'; ?>
|
||||
|
||||
<?php if ($errors): ?>
|
||||
<div class="alert alert--error" role="alert">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Bitte die markierten Anhänger prüfen.</strong>
|
||||
<?php foreach ($errors as $message): ?><p><?= e($message) ?></p><?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="<?= e(url('/admin/trailers')) ?>" class="panel">
|
||||
<?= csrf_field() ?>
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2>Anhänger & Farben</h2>
|
||||
<p>Alle acht Anhänger bleiben gleichzeitig im Kalender sichtbar.</p>
|
||||
</div>
|
||||
<button class="btn primary" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Speichern</button>
|
||||
</div>
|
||||
|
||||
<div class="trailer-admin">
|
||||
<div class="trailer-admin__head" aria-hidden="true">
|
||||
<span>Farbe</span>
|
||||
<span>Bezeichnung</span>
|
||||
<span>Farbname</span>
|
||||
<span>Sortierung</span>
|
||||
<span>Vorschau</span>
|
||||
</div>
|
||||
<?php foreach ($rows as $row): ?>
|
||||
<?php $id = (int) $row['id']; ?>
|
||||
<div class="trailer-admin__row<?= $fieldError($id) !== '' ? ' has-error' : '' ?>">
|
||||
<span class="trailer-admin__color">
|
||||
<input type="color" value="<?= e($row['color_hex']) ?>" data-color-sync aria-label="Farbe für <?= e($row['label']) ?>">
|
||||
<input type="text" name="color_hex[<?= $id ?>]" value="<?= e($row['color_hex']) ?>" maxlength="7" pattern="#[0-9a-fA-F]{6}" class="color-hex" data-color-text aria-label="Farbe als Hex-Wert">
|
||||
</span>
|
||||
<input type="text" name="label[<?= $id ?>]" value="<?= e($row['label']) ?>" maxlength="40" required aria-label="Bezeichnung">
|
||||
<input type="text" name="color_name[<?= $id ?>]" value="<?= e($row['color_name']) ?>" maxlength="40" required aria-label="Farbname">
|
||||
<input type="number" name="sort_order[<?= $id ?>]" value="<?= (int) $row['sort_order'] ?>" step="10" aria-label="Sortierung">
|
||||
<span class="trailer-admin__preview" data-color-preview style="--trailer: <?= e($row['color_hex']) ?>; --trailer-text: <?= e(contrast_color($row['color_hex'])) ?>">
|
||||
<span class="trailer-dot" style="--trailer: <?= e($row['color_hex']) ?>"></span>
|
||||
<?= e($row['label']) ?>
|
||||
</span>
|
||||
<?php if ($fieldError($id)): ?><em class="field-error"><?= e($fieldError($id)) ?></em><?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<p class="muted small">Hinweis: Die Farbe wird bei allen Buchungen dieses Anhängers sofort übernommen. Der Buchungstext selbst bleibt unverändert.</p>
|
||||
</form>
|
||||
154
views/admin_user_form.php
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
/** @var array|null $editing */
|
||||
/** @var array $values */
|
||||
/** @var array $errors */
|
||||
/** @var array $employees */
|
||||
$isSelf = $editing !== null && (int) $editing['id'] === (int) auth_user()['id'];
|
||||
$fieldError = static fn (string $key): string => (string) ($errors[$key] ?? '');
|
||||
?>
|
||||
<div class="breadcrumb">
|
||||
<a href="<?= e(url('/admin/users')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-left"/></svg> Benutzer</a>
|
||||
<span>/</span>
|
||||
<span><?= $editing ? 'Bearbeiten' : 'Neu' ?></span>
|
||||
</div>
|
||||
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Verwaltung · Benutzer</p>
|
||||
<h1><?= $editing ? e($editing['first_name'] . ' ' . $editing['last_name']) : 'Benutzer anlegen' ?></h1>
|
||||
<p class="page-head__lede"><?= $editing ? 'Zugang, Rolle und Mitarbeiterzuordnung bearbeiten.' : 'Der Benutzer meldet sich anschließend mit Vor- und Nachnamen sowie dem Startpasswort an.' ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($errors): ?>
|
||||
<div class="alert alert--error" role="alert">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Bitte die markierten Felder prüfen.</strong>
|
||||
<?php foreach (['name', 'role', 'employee_id'] as $key): ?>
|
||||
<?php if ($fieldError($key)): ?><p><?= e($fieldError($key)) ?></p><?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form class="booking-form" method="post" action="<?= e(url($editing ? '/admin/users/' . (int) $editing['id'] : '/admin/users/new')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<div class="form-layout">
|
||||
<div class="form-main">
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2>Person</h2>
|
||||
<p>Vorname und Nachname sind zugleich der Anmeldename und müssen eindeutig sein.</p>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<label class="field<?= $fieldError('first_name') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Vorname</span>
|
||||
<input type="text" name="first_name" value="<?= e($values['first_name']) ?>" maxlength="80" autocomplete="off" required>
|
||||
<?php if ($fieldError('first_name')): ?><em class="field-error"><?= e($fieldError('first_name')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field<?= $fieldError('last_name') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Nachname</span>
|
||||
<input type="text" name="last_name" value="<?= e($values['last_name']) ?>" maxlength="80" autocomplete="off" required>
|
||||
<?php if ($fieldError('last_name')): ?><em class="field-error"><?= e($fieldError('last_name')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field field--wide<?= $fieldError('email') !== '' ? ' has-error' : '' ?>">
|
||||
<span>E-Mail <small class="optional">(optional, für Erinnerungs-E-Mails)</small></span>
|
||||
<input type="email" name="email" value="<?= e($values['email']) ?>" maxlength="190" autocomplete="off">
|
||||
<?php if ($fieldError('email')): ?><em class="field-error"><?= e($fieldError('email')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2><?= $editing ? 'Passwort zurücksetzen' : 'Startpasswort' ?></h2>
|
||||
<p><?= $editing ? 'Leer lassen, wenn das Passwort unverändert bleiben soll. Ein neues Passwort macht bestehende Anmeldungen ungültig.' : 'Mindestens 8 Zeichen. Der Benutzer sollte es nach der ersten Anmeldung ändern.' ?></p>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<label class="field<?= $fieldError('password') !== '' ? ' has-error' : '' ?>">
|
||||
<span><?= $editing ? 'Neues Passwort' : 'Passwort' ?></span>
|
||||
<input type="password" name="password" autocomplete="new-password" minlength="8"<?= $editing ? '' : ' required' ?>>
|
||||
<?php if ($fieldError('password')): ?><em class="field-error"><?= e($fieldError('password')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<div class="field">
|
||||
<span>Sicherheit</span>
|
||||
<label class="check check--boxed">
|
||||
<input type="checkbox" name="must_change_password" value="1"<?= (int) $values['must_change_password'] === 1 ? ' checked' : '' ?>>
|
||||
<span>Passwort muss bei der nächsten Anmeldung geändert werden</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($isSelf && $editing): ?>
|
||||
<p class="muted small">Wenn Sie Ihr eigenes Passwort hier ändern, werden Sie abgemeldet und müssen sich neu anmelden.</p>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2>Rolle & Zuordnung</h2>
|
||||
<p>Nur Administratoren dürfen Benutzer, Mitarbeiter und Anhänger verwalten.</p>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<label class="field<?= $fieldError('role') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Rolle</span>
|
||||
<select name="role"<?= $isSelf ? ' disabled' : '' ?>>
|
||||
<option value="user"<?= $values['role'] === 'user' ? ' selected' : '' ?>>Mitarbeiter</option>
|
||||
<option value="admin"<?= $values['role'] === 'admin' ? ' selected' : '' ?>>Administrator</option>
|
||||
</select>
|
||||
<?php if ($isSelf): ?><input type="hidden" name="role" value="<?= e($values['role']) ?>"><?php endif; ?>
|
||||
<?php if ($fieldError('role')): ?><em class="field-error"><?= e($fieldError('role')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Status</span>
|
||||
<select name="status"<?= $isSelf ? ' disabled' : '' ?>>
|
||||
<option value="active"<?= $values['status'] === 'active' ? ' selected' : '' ?>>Aktiv</option>
|
||||
<option value="disabled"<?= $values['status'] === 'disabled' ? ' selected' : '' ?>>Deaktiviert</option>
|
||||
</select>
|
||||
<?php if ($isSelf): ?><input type="hidden" name="status" value="<?= e($values['status']) ?>"><?php endif; ?>
|
||||
</label>
|
||||
<label class="field field--wide<?= $fieldError('employee_id') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Mitarbeiterkonto verknüpfen <small class="optional">(steuert die persönlichen Erinnerungen)</small></span>
|
||||
<select name="employee_id">
|
||||
<option value="0">Keine Verknüpfung</option>
|
||||
<?php foreach ($employees as $employee): ?>
|
||||
<option value="<?= (int) $employee['id'] ?>"<?= (int) $values['employee_id'] === (int) $employee['id'] ? ' selected' : '' ?>>
|
||||
<?= e($employee['name']) ?><?= (int) $employee['active'] === 1 ? '' : ' (inaktiv)' ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php if ($fieldError('employee_id')): ?><em class="field-error"><?= e($fieldError('employee_id')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<aside class="form-side">
|
||||
<section class="card card--summary">
|
||||
<h2>Anmeldung</h2>
|
||||
<dl class="summary-list">
|
||||
<div><dt>Vorname</dt><dd><?= e($values['first_name'] ?: '–') ?></dd></div>
|
||||
<div><dt>Nachname</dt><dd><?= e($values['last_name'] ?: '–') ?></dd></div>
|
||||
<div><dt>Rolle</dt><dd><?= $values['role'] === 'admin' ? 'Administrator' : 'Mitarbeiter' ?></dd></div>
|
||||
<div><dt>Status</dt><dd><?= $values['status'] === 'active' ? 'aktiv' : 'deaktiviert' ?></dd></div>
|
||||
</dl>
|
||||
<div class="form-actions">
|
||||
<button class="btn primary btn--block" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Speichern</button>
|
||||
<a class="btn btn--block" href="<?= e(url('/admin/users')) ?>">Abbrechen</a>
|
||||
</div>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php if ($editing && !$isSelf): ?>
|
||||
<section class="card card--danger">
|
||||
<div class="card__head">
|
||||
<h2>Benutzer löschen</h2>
|
||||
<p>Das Konto wird entfernt. Buchungen bleiben erhalten; der Ersteller-Hinweis wird geleert.</p>
|
||||
</div>
|
||||
<form method="post" action="<?= e(url('/admin/users/' . (int) $editing['id'] . '/delete')) ?>" data-confirm="Benutzer <?= e($editing['first_name'] . ' ' . $editing['last_name']) ?> endgültig löschen?">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn danger-ghost" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Benutzer endgültig löschen</button>
|
||||
</form>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
70
views/admin_users.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/** @var array $users */
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Verwaltung</p>
|
||||
<h1>Benutzer</h1>
|
||||
<p class="page-head__lede">Zugänge werden ausschließlich hier angelegt – eine Selbstregistrierung gibt es nicht.</p>
|
||||
</div>
|
||||
<div class="page-head__actions">
|
||||
<a class="btn primary" href="<?= e(url('/admin/users/new')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Benutzer anlegen</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require __DIR__ . '/_admin_nav.php'; ?>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2><?= count($users) ?> Benutzerkonto<?= count($users) === 1 ? '' : 'en' ?></h2>
|
||||
<p>Angemeldet wird mit Vorname, Nachname und Passwort.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-wrap">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Rolle</th>
|
||||
<th>Mitarbeiterkonto</th>
|
||||
<th>Status</th>
|
||||
<th>Letzte Anmeldung</th>
|
||||
<th class="ta-right">Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($users as $row): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="table-person">
|
||||
<span class="avatar avatar--small"><?= e(initials($row['first_name'] . ' ' . $row['last_name'])) ?></span>
|
||||
<span><strong><?= e($row['first_name'] . ' ' . $row['last_name']) ?></strong>
|
||||
<small><?= e($row['email'] ?: 'keine E-Mail hinterlegt') ?></small></span>
|
||||
</span>
|
||||
</td>
|
||||
<td><span class="pill <?= $row['role'] === 'admin' ? 'pill--blue' : 'pill--grey' ?>"><?= $row['role'] === 'admin' ? 'Administrator' : 'Mitarbeiter' ?></span></td>
|
||||
<td><?= e($row['employee_name'] ?: '–') ?></td>
|
||||
<td><span class="pill <?= $row['status'] === 'active' ? 'pill--green' : 'pill--red' ?>"><?= $row['status'] === 'active' ? 'aktiv' : 'deaktiviert' ?></span></td>
|
||||
<td><?= e(fmt_datetime($row['last_login_at'])) ?></td>
|
||||
<td class="ta-right">
|
||||
<a class="btn small" href="<?= e(url('/admin/users/' . (int) $row['id'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg> Bearbeiten</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="info-grid">
|
||||
<section class="card card--note">
|
||||
<h2>So funktioniert die Anmeldung</h2>
|
||||
<p>Benutzer melden sich mit <strong>Vorname</strong>, <strong>Nachname</strong> und <strong>Passwort</strong> an. Namen sind eindeutig; ein Benutzer kann nur vom Administrator angelegt, geändert oder deaktiviert werden.</p>
|
||||
</section>
|
||||
<section class="card card--note">
|
||||
<h2>Erinnerungen zuordnen</h2>
|
||||
<p>Verknüpfen Sie einen Benutzer mit einem Mitarbeiterkonto, damit er nur die für ihn relevanten Erinnerungen und Aufgaben sieht. Administratoren sehen alle Erinnerungen.</p>
|
||||
</section>
|
||||
</div>
|
||||
181
views/booking_detail.php
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
/** @var array $booking */
|
||||
/** @var array $reminders */
|
||||
/** @var array $doneMap */
|
||||
/** @var string $copyText */
|
||||
/** @var bool $canDelete */
|
||||
$cancelled = $booking['status'] === 'cancelled';
|
||||
$lines = explode("\n", $copyText);
|
||||
$due = due_cents((int) $booking['total_cents'], (int) $booking['deposit_cents']);
|
||||
$returnTo = '/bookings/' . (int) $booking['id'];
|
||||
?>
|
||||
<div class="breadcrumb">
|
||||
<a href="<?= e(url('/calendar?view=month&date=' . $booking['start_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-left"/></svg> Kalender</a>
|
||||
<span>/</span>
|
||||
<span>Buchung #<?= (int) $booking['id'] ?></span>
|
||||
</div>
|
||||
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">
|
||||
<?= e(fmt_date_range($booking['start_date'], $booking['end_date'])) ?> ·
|
||||
<?= e($booking['trailer_label']) ?> · <?= e($booking['employee_name']) ?>
|
||||
</p>
|
||||
<h1><?= e($booking['customer_name']) ?>
|
||||
<span class="pill <?= $cancelled ? 'pill--grey' : 'pill--green' ?>"><?= $cancelled ? 'storniert' : 'aktiv' ?></span>
|
||||
</h1>
|
||||
</div>
|
||||
<div class="page-head__actions">
|
||||
<a class="btn" href="<?= e(url($returnTo . '/edit')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg> Bearbeiten</a>
|
||||
<?php if (!$cancelled): ?>
|
||||
<form method="post" action="<?= e(url($returnTo . '/cancel')) ?>" data-confirm="Buchung von <?= e($booking['customer_name']) ?> wirklich stornieren?">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="return_to" value="<?= e($returnTo) ?>">
|
||||
<button class="btn danger" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-close"/></svg> Stornieren</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<form method="post" action="<?= e(url($returnTo . '/restore')) ?>" data-confirm="Buchung wieder aktivieren?">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-return"/></svg> Wiederherstellen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($cancelled): ?>
|
||||
<div class="alert alert--warning">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Storniert<?= $booking['cancelled_at'] ? ' am ' . e(fmt_datetime($booking['cancelled_at'])) : '' ?>.</strong> Die Erinnerungen für diese Buchung entfallen.</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="detail-grid">
|
||||
<div class="detail-main">
|
||||
<section class="card card--copy" data-copy-wrap>
|
||||
<div class="card__head card__head--row">
|
||||
<div>
|
||||
<h2>Buchungsinformation</h2>
|
||||
<p>Genau diese Reihenfolge wird beim Kopieren übernommen.</p>
|
||||
</div>
|
||||
<button class="btn primary" type="button" data-copy>
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-copy"/></svg> Alles kopieren
|
||||
</button>
|
||||
</div>
|
||||
<textarea class="copy-source" readonly aria-hidden="true" tabindex="-1"><?= e($copyText) ?></textarea>
|
||||
<dl class="copy-list">
|
||||
<?php foreach ($lines as $line): ?>
|
||||
<?php
|
||||
$parts = explode(': ', $line, 2);
|
||||
$label = $parts[0] ?? $line;
|
||||
$value = $parts[1] ?? '';
|
||||
?>
|
||||
<div class="copy-list__row<?= $label === 'Noch zu zahlen' ? ' is-strong' : '' ?>">
|
||||
<dt><?= e($label) ?></dt>
|
||||
<dd><?= e($value) ?></dd>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</dl>
|
||||
<p class="copy-hint"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Zeilenumbrüche und Formatierung bleiben beim Kopieren erhalten.</p>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2>Automatische Erinnerungen</h2>
|
||||
<p>Wird der Termin verschoben, passen sich die Fälligkeiten automatisch an.</p>
|
||||
</div>
|
||||
<?php if ($cancelled): ?>
|
||||
<div class="empty-state small"><p>Diese Buchung ist storniert – es werden keine Erinnerungen erzeugt.</p></div>
|
||||
<?php else: ?>
|
||||
<ul class="reminder-list">
|
||||
<?php foreach ($reminders as $reminder): ?>
|
||||
<?php
|
||||
$key = reminder_done_key($booking, $reminder['kind'], $reminder['due_date']);
|
||||
$done = isset($doneMap[$key]);
|
||||
$overdue = !$done && $reminder['due_date'] < today_iso();
|
||||
?>
|
||||
<li class="reminder-row<?= $done ? ' is-done' : '' ?><?= $overdue ? ' is-overdue' : '' ?>">
|
||||
<div class="reminder-row__date">
|
||||
<strong><?= e(fmt_date($reminder['due_date'])) ?></strong>
|
||||
<span><?= e(relative_day($reminder['due_date'])) ?></span>
|
||||
</div>
|
||||
<div class="reminder-row__body">
|
||||
<strong><?= e($reminder['label']) ?></strong>
|
||||
<p><?= e($reminder['message']) ?></p>
|
||||
<span class="muted small"><?= e($reminder['short']) ?> · <?= e($booking['employee_name']) ?></span>
|
||||
</div>
|
||||
<div class="reminder-row__action">
|
||||
<?php if ($done): ?>
|
||||
<span class="pill pill--green"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> erledigt</span>
|
||||
<form method="post" action="<?= e(url('/reminders/done')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="booking_id" value="<?= (int) $booking['id'] ?>">
|
||||
<input type="hidden" name="kind" value="<?= e($reminder['kind']) ?>">
|
||||
<input type="hidden" name="done" value="0">
|
||||
<input type="hidden" name="return_to" value="<?= e($returnTo) ?>">
|
||||
<button class="link-button small" type="submit">rückgängig</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<form method="post" action="<?= e(url('/reminders/done')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="booking_id" value="<?= (int) $booking['id'] ?>">
|
||||
<input type="hidden" name="kind" value="<?= e($reminder['kind']) ?>">
|
||||
<input type="hidden" name="done" value="1">
|
||||
<input type="hidden" name="return_to" value="<?= e($returnTo) ?>">
|
||||
<button class="btn small" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Erledigt</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<aside class="detail-side">
|
||||
<section class="card">
|
||||
<h2>Zuordnung</h2>
|
||||
<dl class="meta-list">
|
||||
<div>
|
||||
<dt>Kühlanhänger</dt>
|
||||
<dd>
|
||||
<span class="trailer-chip" style="--trailer: <?= e($booking['trailer_color']) ?>; --trailer-text: <?= e(contrast_color($booking['trailer_color'])) ?>">
|
||||
<span class="trailer-dot" style="--trailer: <?= e($booking['trailer_color']) ?>"></span>
|
||||
<?= e($booking['trailer_label']) ?> · <?= e($booking['trailer_color_name']) ?>
|
||||
</span>
|
||||
</dd>
|
||||
</div>
|
||||
<div><dt>Mitarbeiter</dt><dd><?= e($booking['employee_name']) ?></dd></div>
|
||||
<div><dt>Von</dt><dd><?= e(fmt_date_long($booking['start_date'])) ?></dd></div>
|
||||
<div><dt>Bis</dt><dd><?= e(fmt_date_long($booking['end_date'])) ?></dd></div>
|
||||
<div><dt>Art</dt><dd><span class="pill pill--blue"><?= e(booking_kind_label((string) $booking['kind'])) ?></span></dd></div>
|
||||
<div><dt>Rechnung</dt><dd><span class="pill <?= (int) $booking['invoice'] === 1 ? 'pill--green' : 'pill--grey' ?>"><?= e(booking_invoice_label($booking['invoice'])) ?></span></dd></div>
|
||||
</dl>
|
||||
<hr>
|
||||
<dl class="money-list">
|
||||
<div><dt>Anzahlung</dt><dd><?= e(fmt_money((int) $booking['deposit_cents'])) ?></dd></div>
|
||||
<div><dt>Gesamtbetrag</dt><dd><?= e(fmt_money((int) $booking['total_cents'])) ?></dd></div>
|
||||
<div class="is-strong"><dt>Noch zu zahlen</dt><dd><?= e(fmt_money($due)) ?></dd></div>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Aktionen</h2>
|
||||
<div class="stack-actions">
|
||||
<a class="btn btn--block" href="<?= e(url($returnTo . '/edit')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg> Buchung bearbeiten</a>
|
||||
<a class="btn btn--block" href="<?= e(url('/bookings/new?trailer=' . (int) $booking['trailer_id'] . '&start=' . $booking['end_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Anschlussbuchung anlegen</a>
|
||||
<?php if ($canDelete): ?>
|
||||
<form method="post" action="<?= e(url($returnTo . '/delete')) ?>" data-confirm="Buchung endgültig löschen? Das kann nicht rückgängig gemacht werden.">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn danger-ghost btn--block" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Endgültig löschen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<p class="muted small detail-meta">
|
||||
Angelegt am <?= e(fmt_datetime($booking['created_at'])) ?>.
|
||||
Zuletzt geändert am <?= e(fmt_datetime($booking['updated_at'])) ?>.
|
||||
</p>
|
||||
</aside>
|
||||
</div>
|
||||
249
views/booking_form.php
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
<?php
|
||||
/** @var array|null $booking */
|
||||
/** @var array $values */
|
||||
/** @var array $errors */
|
||||
/** @var array $trailers */
|
||||
/** @var array $employees */
|
||||
/** @var array $user */
|
||||
/** @var bool $isEdit */
|
||||
$fieldError = static fn (string $key): string => (string) ($errors[$key] ?? '');
|
||||
$cancelled = $isEdit && ($booking['status'] ?? '') === 'cancelled';
|
||||
$selectedTrailer = null;
|
||||
foreach ($trailers as $trailer) {
|
||||
if ((int) $trailer['id'] === (int) $values['trailer_id']) {
|
||||
$selectedTrailer = $trailer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$selectedEmployee = null;
|
||||
foreach ($employees as $employee) {
|
||||
if ((int) $employee['id'] === (int) $values['employee_id']) {
|
||||
$selectedEmployee = $employee;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$backUrl = $isEdit ? '/bookings/' . (int) $booking['id'] : '/calendar';
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow"><?= $isEdit ? 'Buchung bearbeiten' : 'Neue Buchung' ?></p>
|
||||
<h1><?= $isEdit ? e($booking['customer_name']) : 'Mietzeitraum erfassen' ?></h1>
|
||||
<p class="page-head__lede"><?= $isEdit ? 'Änderungen an Termin oder Anhänger verschieben die Erinnerungen automatisch.' : 'Alle Angaben in der Reihenfolge, in der sie später kopiert werden.' ?></p>
|
||||
</div>
|
||||
<div class="page-head__actions">
|
||||
<a class="btn" href="<?= e(url($backUrl)) ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-left"/></svg> <?= $isEdit ? 'Zur Buchung' : 'Zum Kalender' ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($cancelled): ?>
|
||||
<div class="alert alert--warning">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Diese Buchung ist storniert.</strong> Änderungen bleiben gespeichert, die Erinnerungen sind aber ausgeblendet. Über „Wiederherstellen“ wird die Buchung erneut aktiv.</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($errors): ?>
|
||||
<div class="alert alert--error" role="alert">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div>
|
||||
<strong>Bitte die markierten Felder prüfen.</strong>
|
||||
<?php if (isset($errors['period'])): ?><p><?= e($errors['period']) ?></p><?php endif; ?>
|
||||
<?php if (isset($errors['form'])): ?><p><?= e($errors['form']) ?></p><?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form class="booking-form" method="post" action="<?= e(url($isEdit ? '/bookings/' . (int) $booking['id'] . '/edit' : '/bookings/new')) ?>"
|
||||
data-booking-form data-availability-url="<?= e(url('/api/availability')) ?>" data-exclude="<?= $isEdit ? (int) $booking['id'] : 0 ?>">
|
||||
<?= csrf_field() ?>
|
||||
|
||||
<div class="form-layout">
|
||||
<div class="form-main">
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2>Mietzeitraum & Zuständigkeit</h2>
|
||||
<p>Ganztägig – Uhrzeiten sind nicht nötig. Ein Wechseltag am Ende und Anfang ist erlaubt.</p>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<label class="field<?= $fieldError('trailer_id') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Kühlanhänger</span>
|
||||
<select name="trailer_id" required data-trailer-select>
|
||||
<?php foreach ($trailers as $trailer): ?>
|
||||
<option value="<?= (int) $trailer['id'] ?>" data-color="<?= e($trailer['color_hex']) ?>" data-color-name="<?= e($trailer['color_name']) ?>"<?= (int) $values['trailer_id'] === (int) $trailer['id'] ? ' selected' : '' ?>>
|
||||
<?= e($trailer['label'] . ' · ' . $trailer['color_name']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php if ($fieldError('trailer_id')): ?><em class="field-error"><?= e($fieldError('trailer_id')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
|
||||
<div class="field field--trailer-preview" aria-hidden="true">
|
||||
<span>Farbe im Kalender</span>
|
||||
<span class="trailer-preview" data-trailer-preview
|
||||
style="--trailer: <?= e($selectedTrailer['color_hex'] ?? '#196abc') ?>; --trailer-text: <?= e(contrast_color($selectedTrailer['color_hex'] ?? '#196abc')) ?>">
|
||||
<span class="trailer-dot" style="--trailer: <?= e($selectedTrailer['color_hex'] ?? '#196abc') ?>"></span>
|
||||
<span data-trailer-preview-label><?= e($selectedTrailer['label'] ?? '') ?> · <?= e($selectedTrailer['color_name'] ?? '') ?></span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<label class="field<?= $fieldError('start_date') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Mietbeginn (Von)</span>
|
||||
<input type="date" name="start_date" value="<?= e($values['start_date']) ?>" required data-date-start>
|
||||
<?php if ($fieldError('start_date')): ?><em class="field-error"><?= e($fieldError('start_date')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field<?= $fieldError('end_date') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Mietende (Bis)</span>
|
||||
<input type="date" name="end_date" value="<?= e($values['end_date']) ?>" required data-date-end>
|
||||
<?php if ($fieldError('end_date')): ?><em class="field-error"><?= e($fieldError('end_date')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
|
||||
<label class="field<?= $fieldError('employee_id') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Zuständiger Mitarbeiter</span>
|
||||
<select name="employee_id" required>
|
||||
<?php foreach ($employees as $employee): ?>
|
||||
<option value="<?= (int) $employee['id'] ?>"<?= (int) $values['employee_id'] === (int) $employee['id'] ? ' selected' : '' ?>>
|
||||
<?= e($employee['name']) ?><?= (int) $employee['active'] === 1 ? '' : ' (inaktiv)' ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php if ($fieldError('employee_id')): ?><em class="field-error"><?= e($fieldError('employee_id')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
|
||||
<div class="field field--wide">
|
||||
<div class="conflict-hint" data-conflict hidden></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2>Beträge & Rechnung</h2>
|
||||
<p>„Noch zu zahlen“ wird automatisch aus Gesamtbetrag minus Anzahlung berechnet.</p>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<label class="field<?= $fieldError('deposit') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Anzahlung</span>
|
||||
<span class="money-input">
|
||||
<input type="text" name="deposit" value="<?= e($values['deposit']) ?>" inputmode="decimal" placeholder="0,00" data-money="deposit">
|
||||
<span>€</span>
|
||||
</span>
|
||||
<?php if ($fieldError('deposit')): ?><em class="field-error"><?= e($fieldError('deposit')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field<?= $fieldError('total') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Gesamtbetrag</span>
|
||||
<span class="money-input">
|
||||
<input type="text" name="total" value="<?= e($values['total']) ?>" inputmode="decimal" placeholder="0,00" data-money="total">
|
||||
<span>€</span>
|
||||
</span>
|
||||
<?php if ($fieldError('total')): ?><em class="field-error"><?= e($fieldError('total')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<div class="field">
|
||||
<span>Noch zu zahlen</span>
|
||||
<output class="due-output" data-due><?= e(fmt_money(due_cents(parse_money((string) $values['total']), parse_money((string) $values['deposit'])))) ?></output>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<span>Rechnung</span>
|
||||
<div class="segmented-radio">
|
||||
<label><input type="radio" name="invoice" value="0"<?= (int) $values['invoice'] === 0 ? ' checked' : '' ?>><span>NEIN</span></label>
|
||||
<label><input type="radio" name="invoice" value="1"<?= (int) $values['invoice'] === 1 ? ' checked' : '' ?>><span>JA</span></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Art</span>
|
||||
<div class="segmented-radio">
|
||||
<label><input type="radio" name="kind" value="pickup"<?= $values['kind'] === 'pickup' ? ' checked' : '' ?>><span>Abholer</span></label>
|
||||
<label><input type="radio" name="kind" value="delivery"<?= $values['kind'] === 'delivery' ? ' checked' : '' ?>><span>Lieferung</span></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2>Kundendaten</h2>
|
||||
<p>Erscheint in genau dieser Reihenfolge im kopierbaren Buchungstext.</p>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<label class="field field--wide<?= $fieldError('customer_name') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Name</span>
|
||||
<input type="text" name="customer_name" value="<?= e($values['customer_name']) ?>" autocomplete="name" required data-customer-name>
|
||||
<?php if ($fieldError('customer_name')): ?><em class="field-error"><?= e($fieldError('customer_name')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field field--wide<?= $fieldError('street') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Straße</span>
|
||||
<input type="text" name="street" value="<?= e($values['street']) ?>" autocomplete="street-address">
|
||||
<?php if ($fieldError('street')): ?><em class="field-error"><?= e($fieldError('street')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field<?= $fieldError('city') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Ort</span>
|
||||
<input type="text" name="city" value="<?= e($values['city']) ?>" autocomplete="address-level2" placeholder="z. B. 41569 Rommerskirchen">
|
||||
<?php if ($fieldError('city')): ?><em class="field-error"><?= e($fieldError('city')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field<?= $fieldError('mobile') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Handy</span>
|
||||
<input type="tel" name="mobile" value="<?= e($values['mobile']) ?>" autocomplete="tel">
|
||||
<?php if ($fieldError('mobile')): ?><em class="field-error"><?= e($fieldError('mobile')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field field--wide<?= $fieldError('email') !== '' ? ' has-error' : '' ?>">
|
||||
<span>E-Mail</span>
|
||||
<input type="email" name="email" value="<?= e($values['email']) ?>" autocomplete="email">
|
||||
<?php if ($fieldError('email')): ?><em class="field-error"><?= e($fieldError('email')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<aside class="form-side">
|
||||
<section class="card card--summary">
|
||||
<h2>Übersicht</h2>
|
||||
<dl class="summary-list">
|
||||
<div><dt>Kühlanhänger</dt><dd><span class="trailer-dot" style="--trailer: <?= e($selectedTrailer['color_hex'] ?? '#196abc') ?>"></span> <span data-summary-trailer><?= e($selectedTrailer['label'] ?? '–') ?></span></dd></div>
|
||||
<div><dt>Zeitraum</dt><dd data-summary-dates><?= e(fmt_date_range($values['start_date'], $values['end_date'])) ?></dd></div>
|
||||
<div><dt>Mitarbeiter</dt><dd><span data-summary-employee><?= e($selectedEmployee['name'] ?? '–') ?></span></dd></div>
|
||||
<div><dt>Gesamtbetrag</dt><dd data-summary-total><?= e(fmt_money(parse_money((string) $values['total']))) ?></dd></div>
|
||||
<div><dt>Anzahlung</dt><dd data-summary-deposit><?= e(fmt_money(parse_money((string) $values['deposit']))) ?></dd></div>
|
||||
<div class="is-strong"><dt>Noch zu zahlen</dt><dd data-summary-due><?= e(fmt_money(due_cents(parse_money((string) $values['total']), parse_money((string) $values['deposit'])))) ?></dd></div>
|
||||
</dl>
|
||||
<div class="form-actions">
|
||||
<button class="btn primary btn--block" type="submit">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> <?= $isEdit ? 'Änderungen speichern' : 'Buchung anlegen' ?>
|
||||
</button>
|
||||
<a class="btn btn--block" href="<?= e(url($backUrl)) ?>">Abbrechen</a>
|
||||
</div>
|
||||
<p class="muted small">Erinnerungen entstehen automatisch: 8 Tage vor Mietbeginn, 1 Tag vor Mietbeginn und 1 Tag vor Mietende.</p>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php if ($isEdit): ?>
|
||||
<section class="card card--danger">
|
||||
<div class="card__head">
|
||||
<h2>Buchung verwalten</h2>
|
||||
<p>Stornieren blendet die Erinnerungen aus; die Buchung bleibt mit allen Daten erhalten.</p>
|
||||
</div>
|
||||
<div class="danger-actions">
|
||||
<?php if ($booking['status'] === 'active'): ?>
|
||||
<form method="post" action="<?= e(url('/bookings/' . (int) $booking['id'] . '/cancel')) ?>" data-confirm="Buchung von <?= e($booking['customer_name']) ?> wirklich stornieren?">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="return_to" value="<?= e('/bookings/' . (int) $booking['id']) ?>">
|
||||
<button class="btn danger" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-close"/></svg> Buchung stornieren</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<form method="post" action="<?= e(url('/bookings/' . (int) $booking['id'] . '/restore')) ?>" data-confirm="Buchung wieder aktivieren?">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-return"/></svg> Wiederherstellen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php if (($user['role'] ?? '') === 'admin'): ?>
|
||||
<form method="post" action="<?= e(url('/bookings/' . (int) $booking['id'] . '/delete')) ?>" data-confirm="Buchung endgültig löschen? Das kann nicht rückgängig gemacht werden.">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn danger-ghost" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Endgültig löschen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
91
views/booking_panel.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/** @var array $booking */
|
||||
/** @var array $reminders */
|
||||
/** @var array $doneMap */
|
||||
/** @var string $copyText */
|
||||
/** @var bool $canDelete */
|
||||
$cancelled = $booking['status'] === 'cancelled';
|
||||
$lines = explode("\n", $copyText);
|
||||
$due = due_cents((int) $booking['total_cents'], (int) $booking['deposit_cents']);
|
||||
$bookingUrl = '/bookings/' . (int) $booking['id'];
|
||||
$openReminder = null;
|
||||
foreach ($reminders as $reminder) {
|
||||
$key = reminder_done_key($booking, $reminder['kind'], $reminder['due_date']);
|
||||
if (!isset($doneMap[$key]) && !$cancelled) {
|
||||
$openReminder = $reminder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="panel-head">
|
||||
<div class="panel-head__main">
|
||||
<div class="panel-head__trailer">
|
||||
<span class="trailer-dot" style="--trailer: <?= e($booking['trailer_color']) ?>"></span>
|
||||
<?= e($booking['trailer_label']) ?> · <?= e($booking['trailer_color_name']) ?>
|
||||
</div>
|
||||
<h2><?= e($booking['customer_name']) ?></h2>
|
||||
<p>
|
||||
<?= e(fmt_date_range($booking['start_date'], $booking['end_date'])) ?>
|
||||
· <?= e($booking['employee_name']) ?>
|
||||
<span class="pill <?= $cancelled ? 'pill--grey' : 'pill--green' ?>"><?= $cancelled ? 'storniert' : 'aktiv' ?></span>
|
||||
</p>
|
||||
</div>
|
||||
<button class="icon-btn" type="button" data-close-dialog aria-label="Dialog schließen"><svg class="ico" aria-hidden="true"><use href="#i-close"/></svg></button>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<section class="panel-copy" data-copy-wrap>
|
||||
<div class="panel-copy__head">
|
||||
<h3>Buchungsinformation</h3>
|
||||
<button class="btn small primary" type="button" data-copy>
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-copy"/></svg> Kopieren
|
||||
</button>
|
||||
</div>
|
||||
<textarea class="copy-source" readonly aria-hidden="true" tabindex="-1"><?= e($copyText) ?></textarea>
|
||||
<dl class="copy-list copy-list--compact">
|
||||
<?php foreach ($lines as $line): ?>
|
||||
<?php $parts = explode(': ', $line, 2); ?>
|
||||
<div class="copy-list__row<?= ($parts[0] ?? '') === 'Noch zu zahlen' ? ' is-strong' : '' ?>">
|
||||
<dt><?= e($parts[0] ?? $line) ?></dt>
|
||||
<dd><?= e($parts[1] ?? '') ?></dd>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="panel-meta">
|
||||
<dl class="meta-list meta-list--compact">
|
||||
<div><dt>Anhänger</dt><dd><?= e($booking['trailer_label'] . ' · ' . $booking['trailer_color_name']) ?></dd></div>
|
||||
<div><dt>Mitarbeiter</dt><dd><?= e($booking['employee_name']) ?></dd></div>
|
||||
<div><dt>Art</dt><dd><?= e(booking_kind_label((string) $booking['kind'])) ?></dd></div>
|
||||
<div><dt>Rechnung</dt><dd><?= e(booking_invoice_label($booking['invoice'])) ?></dd></div>
|
||||
<div><dt>Anzahlung</dt><dd><?= e(fmt_money((int) $booking['deposit_cents'])) ?></dd></div>
|
||||
<div><dt>Gesamt</dt><dd><?= e(fmt_money((int) $booking['total_cents'])) ?></dd></div>
|
||||
<div class="is-strong"><dt>Noch zu zahlen</dt><dd><?= e(fmt_money($due)) ?></dd></div>
|
||||
</dl>
|
||||
<?php if ($openReminder): ?>
|
||||
<div class="next-reminder<?= $openReminder['due_date'] < today_iso() ? ' is-overdue' : '' ?>">
|
||||
<span>Nächste Erinnerung</span>
|
||||
<strong><?= e(fmt_date($openReminder['due_date'])) ?> · <?= e(relative_day($openReminder['due_date'])) ?></strong>
|
||||
<p><?= e($openReminder['label']) ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div class="panel-actions">
|
||||
<a class="btn primary" href="<?= e(url($bookingUrl . '/edit')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg> Bearbeiten</a>
|
||||
<a class="btn" href="<?= e(url($bookingUrl)) ?>">Vollständige Buchung</a>
|
||||
<?php if (!$cancelled): ?>
|
||||
<form method="post" action="<?= e(url($bookingUrl . '/cancel')) ?>" data-confirm="Buchung von <?= e($booking['customer_name']) ?> wirklich stornieren?">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="return_to" value="<?= e($bookingUrl) ?>">
|
||||
<button class="btn danger-ghost" type="submit">Stornieren</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<form method="post" action="<?= e(url($bookingUrl . '/restore')) ?>" data-confirm="Buchung wieder aktivieren?">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn" type="submit">Wiederherstellen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
169
views/calendar.php
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
/** @var string $view */
|
||||
/** @var string $date */
|
||||
/** @var string $from */
|
||||
/** @var string $to */
|
||||
/** @var array $days */
|
||||
/** @var array $rows */
|
||||
/** @var string $calTitle */
|
||||
/** @var string $prevDate */
|
||||
/** @var string $nextDate */
|
||||
/** @var string $today */
|
||||
/** @var int $employeeId */
|
||||
/** @var bool $showCancelled */
|
||||
/** @var array $employees */
|
||||
/** @var int $bookingCount */
|
||||
/** @var callable $urlFor */
|
||||
$cols = count($days);
|
||||
$laneWidth = 150;
|
||||
$minWidth = match ($view) {
|
||||
'week' => $laneWidth + 7 * 92,
|
||||
'month' => $laneWidth + $cols * 40,
|
||||
default => 0,
|
||||
};
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Kalender · <?= $bookingCount ?> Buchung<?= $bookingCount === 1 ? '' : 'en' ?> im Zeitraum</p>
|
||||
<h1><?= e($calTitle) ?></h1>
|
||||
</div>
|
||||
<div class="page-head__actions">
|
||||
<a class="btn primary" href="<?= e(url('/bookings/new?start=' . $date)) ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cal-toolbar">
|
||||
<div class="cal-toolbar__left">
|
||||
<div class="segmented" role="group" aria-label="Ansicht">
|
||||
<?php foreach (['day' => 'Tag', 'week' => 'Woche', 'month' => 'Monat'] as $key => $label): ?>
|
||||
<a href="<?= e(url(calendar_url($date, $key, $employeeId, $showCancelled))) ?>"<?= $view === $key ? ' class="is-active" aria-current="page"' : '' ?>><?= $label ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div class="cal-nav">
|
||||
<a class="icon-btn" href="<?= e(url($urlFor($prevDate))) ?>" aria-label="Vorheriger Zeitraum"><svg class="ico" aria-hidden="true"><use href="#i-left"/></svg></a>
|
||||
<a class="btn small" href="<?= e(url($urlFor($today))) ?>">Heute</a>
|
||||
<a class="icon-btn" href="<?= e(url($urlFor($nextDate))) ?>" aria-label="Nächster Zeitraum"><svg class="ico" aria-hidden="true"><use href="#i-right"/></svg></a>
|
||||
<form class="date-jump" method="get" action="<?= e(url('/calendar')) ?>">
|
||||
<input type="hidden" name="view" value="<?= e($view) ?>">
|
||||
<?php if ($employeeId > 0): ?><input type="hidden" name="employee" value="<?= (int) $employeeId ?>"><?php endif; ?>
|
||||
<?php if ($showCancelled): ?><input type="hidden" name="cancelled" value="1"><?php endif; ?>
|
||||
<label class="sr-only" for="cal-date">Datum</label>
|
||||
<input type="date" id="cal-date" name="date" value="<?= e($date) ?>" data-autosubmit>
|
||||
<button class="btn small" type="submit">Springen</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<form class="cal-filters" method="get" action="<?= e(url('/calendar')) ?>">
|
||||
<input type="hidden" name="view" value="<?= e($view) ?>">
|
||||
<input type="hidden" name="date" value="<?= e($date) ?>">
|
||||
<?php if (count($employees) > 1): ?>
|
||||
<label class="inline-field">
|
||||
<span>Mitarbeiter</span>
|
||||
<select name="employee" data-autosubmit>
|
||||
<option value="">Alle</option>
|
||||
<?php foreach ($employees as $employee): ?>
|
||||
<option value="<?= (int) $employee['id'] ?>"<?= $employeeId === (int) $employee['id'] ? ' selected' : '' ?>><?= e($employee['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<label class="check check--small">
|
||||
<input type="checkbox" name="cancelled" value="1" data-autosubmit<?= $showCancelled ? ' checked' : '' ?>>
|
||||
<span>Stornierte</span>
|
||||
</label>
|
||||
<button class="btn small cal-filters__submit" type="submit">Anwenden</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php if ($view !== 'day'): ?>
|
||||
<p class="cal-scroll-hint"><svg class="ico" aria-hidden="true"><use href="#i-left"/></svg> Seitlich scrollen, um alle Tage zu sehen <svg class="ico" aria-hidden="true"><use href="#i-right"/></svg></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="cal-shell" data-calendar-view="<?= e($view) ?>" data-calendar-date="<?= e($date) ?>">
|
||||
<div class="cal-scroll">
|
||||
<div class="cal" style="--cols: <?= $cols ?>;<?= $minWidth > 0 ? ' min-width: ' . $minWidth . 'px;' : '' ?>">
|
||||
<div class="cal-corner">
|
||||
<span class="cal-corner__title">Anhänger</span>
|
||||
<span class="cal-corner__hint">Farbe = Anhänger</span>
|
||||
</div>
|
||||
<div class="cal-head">
|
||||
<?php foreach ($days as $day): ?>
|
||||
<div class="cal-head__day<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?>">
|
||||
<span class="cal-head__weekday"><?= e($day['weekday']) ?></span>
|
||||
<span class="cal-head__num"><?= (int) $day['day'] ?></span>
|
||||
<?php if ($view === 'day' || ($view === 'month' && $day['is_first_of_month']) || ($view === 'week' && $day['is_first_of_month'])): ?>
|
||||
<span class="cal-head__month"><?= e(fmt_month($day['iso'])) ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<?php foreach ($rows as $row): ?>
|
||||
<?php $trailer = $row['trailer']; ?>
|
||||
<div class="cal-label" style="--row-h: <?= (int) $row['height'] ?>px">
|
||||
<span class="trailer-dot" style="--trailer: <?= e($trailer['color_hex']) ?>"></span>
|
||||
<span class="cal-label__text">
|
||||
<strong><?= e($trailer['label']) ?></strong>
|
||||
<small><?= e($trailer['color_name']) ?></small>
|
||||
</span>
|
||||
<a class="cal-label__add" href="<?= e(url('/bookings/new?trailer=' . (int) $trailer['id'] . '&start=' . $date)) ?>" aria-label="Neue Buchung für <?= e($trailer['label']) ?>">+</a>
|
||||
</div>
|
||||
<div class="cal-track" style="--row-h: <?= (int) $row['height'] ?>px; --lanes: <?= (int) $row['lanes'] ?>" data-trailer-id="<?= (int) $trailer['id'] ?>">
|
||||
<div class="cal-cells">
|
||||
<?php foreach ($days as $day): ?>
|
||||
<a class="cal-cell<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?>"
|
||||
href="<?= e(url('/bookings/new?trailer=' . (int) $trailer['id'] . '&start=' . $day['iso'] . '&end=' . $day['iso'])) ?>"
|
||||
data-cell="1"
|
||||
data-date="<?= e($day['iso']) ?>"
|
||||
aria-label="Neue Buchung <?= e($trailer['label']) ?> am <?= e(fmt_date($day['iso'])) ?>"></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php foreach ($row['bars'] as $bar): ?>
|
||||
<?php
|
||||
$booking = $bar['booking'];
|
||||
$geo = $bar['geo'];
|
||||
$cancelled = $booking['status'] === 'cancelled';
|
||||
$showMeta = $view === 'day' || ($view === 'week' && $geo['span'] >= 2);
|
||||
$label = $view === 'month' ? truncate((string) $booking['customer_name'], 18) : (string) $booking['customer_name'];
|
||||
$aria = $booking['customer_name'] . ', ' . $booking['trailer_label'] . ', '
|
||||
. fmt_date($booking['start_date']) . ' bis ' . fmt_date($booking['end_date'])
|
||||
. ', ' . $booking['employee_name'] . ($cancelled ? ', storniert' : '');
|
||||
?>
|
||||
<a class="cal-bar<?= $cancelled ? ' is-cancelled' : '' ?><?= $geo['cut_start'] ? ' is-cut-start' : '' ?><?= $geo['cut_end'] ? ' is-cut-end' : '' ?><?= $geo['span'] <= 1 ? ' is-tiny' : '' ?>"
|
||||
href="<?= e(url('/bookings/' . (int) $booking['id'])) ?>"
|
||||
draggable="false"
|
||||
data-panel="<?= (int) $booking['id'] ?>"
|
||||
data-booking-id="<?= (int) $booking['id'] ?>"
|
||||
data-trailer-id="<?= (int) $booking['trailer_id'] ?>"
|
||||
data-start-date="<?= e($booking['start_date']) ?>"
|
||||
data-days="<?= days_between($booking['start_date'], $booking['end_date']) + 1 ?>"
|
||||
style="--left: <?= number_format($geo['left'], 5, '.', '') ?>%; --width: <?= number_format($geo['width'], 5, '.', '') ?>%; --top: <?= number_format($geo['top'], 5, '.', '') ?>%; --height: <?= number_format($geo['height'], 5, '.', '') ?>%; --bar: <?= e($booking['trailer_color']) ?>; --bar-text: <?= e(contrast_color($booking['trailer_color'])) ?>;"
|
||||
aria-label="<?= e($aria) ?>"
|
||||
title="<?= e($booking['customer_name'] . ' · ' . fmt_date_range($booking['start_date'], $booking['end_date']) . ' · ' . $booking['employee_name'] . ($cancelled ? ' · storniert' : '')) ?>">
|
||||
<span class="cal-bar__name"><?= e($label) ?></span>
|
||||
<?php if ($showMeta): ?>
|
||||
<span class="cal-bar__meta"><?= e($view === 'day' ? fmt_date_range($booking['start_date'], $booking['end_date']) : $booking['employee_name']) ?><?= $view === 'day' ? ' · ' . e($booking['employee_name']) : '' ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ($view === 'day'): ?>
|
||||
<span class="cal-bar__meta cal-bar__meta--soft"><?= e(booking_kind_label((string) $booking['kind'])) ?> · <?= e(fmt_money((int) $booking['total_cents'])) ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ($cancelled): ?><span class="cal-bar__flag">storniert</span><?php endif; ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cal-foot">
|
||||
<p>
|
||||
<span class="legend-dot"></span>
|
||||
Farbige Balken gehören zum jeweiligen Anhänger. Zwei Buchungen dürfen sich am Wechseltag (letzter Tag = erster Tag) überschneiden – beide Balken bleiben sichtbar.
|
||||
</p>
|
||||
<?php if ($view !== 'month'): ?>
|
||||
<p class="cal-foot__hint">Tipp: Balken lassen sich mit der Maus verschieben – horizontal ändert das Datum, vertikal den Anhänger.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
212
views/dashboard.php
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
/** @var string $today */
|
||||
/** @var array $trailers */
|
||||
/** @var array $roadmap */
|
||||
/** @var array $upcoming */
|
||||
/** @var array $reminders */
|
||||
/** @var int $openReminderCount */
|
||||
/** @var int $handoverCount */
|
||||
/** @var int $employeeScope */
|
||||
$rentedToday = 0;
|
||||
foreach ($roadmap as $row) {
|
||||
if ($row['bookings']) {
|
||||
$rentedToday++;
|
||||
}
|
||||
}
|
||||
$freeToday = count($trailers) - $rentedToday;
|
||||
$isEmployeeView = $employeeScope > 0;
|
||||
?>
|
||||
<div class="page-head">
|
||||
<div>
|
||||
<p class="eyebrow"><?= e(fmt_date_long($today)) ?></p>
|
||||
<h1><?= e(greeting()) ?><?= isset($user) ? ', ' . e($user['first_name']) : '' ?></h1>
|
||||
<p class="page-head__lede">Was heute ansteht – und wer sich um welche Übergabe kümmert.</p>
|
||||
</div>
|
||||
<div class="page-head__actions">
|
||||
<a class="btn" href="<?= e(url('/calendar')) ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg> Kalender
|
||||
</a>
|
||||
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="kpi-grid" aria-label="Kennzahlen">
|
||||
<article class="kpi">
|
||||
<span class="kpi__icon kpi__icon--blue"><svg class="ico" aria-hidden="true"><use href="#i-truck"/></svg></span>
|
||||
<div><strong><?= $rentedToday ?> von <?= count($trailers) ?></strong><span>Heute vermietet</span></div>
|
||||
</article>
|
||||
<article class="kpi">
|
||||
<span class="kpi__icon kpi__icon--green"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg></span>
|
||||
<div><strong><?= $freeToday ?></strong><span>Heute frei</span></div>
|
||||
</article>
|
||||
<article class="kpi">
|
||||
<span class="kpi__icon kpi__icon--amber"><svg class="ico" aria-hidden="true"><use href="#i-clock"/></svg></span>
|
||||
<div><strong><?= $handoverCount ?></strong><span>Übergaben (7 Tage)</span></div>
|
||||
</article>
|
||||
<article class="kpi">
|
||||
<span class="kpi__icon kpi__icon--red"><svg class="ico" aria-hidden="true"><use href="#i-bell"/></svg></span>
|
||||
<div><strong><?= $openReminderCount ?></strong><span>Offene Erinnerungen</span></div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<div class="dash-grid">
|
||||
<div class="dash-main">
|
||||
<section class="panel">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2>Heute im Einsatz</h2>
|
||||
<p>Alle acht Anhänger auf einen Blick<?= $isEmployeeView ? ' – mit Ihren Buchungen hervorgehoben' : '' ?>.</p>
|
||||
</div>
|
||||
<a class="link-arrow" href="<?= e(url('/calendar?view=day')) ?>">Tagesansicht <svg class="ico" aria-hidden="true"><use href="#i-right"/></svg></a>
|
||||
</div>
|
||||
<div class="trailer-grid">
|
||||
<?php foreach ($roadmap as $row): ?>
|
||||
<?php
|
||||
$trailer = $row['trailer'];
|
||||
$bookings = $row['bookings'];
|
||||
$own = false;
|
||||
foreach ($bookings as $b) {
|
||||
if ($isEmployeeView && (int) $b['employee_id'] === $employeeScope) {
|
||||
$own = true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<article class="trailer-card<?= $bookings ? ' is-rented' : ' is-free' ?><?= $own ? ' is-own' : '' ?>"
|
||||
style="--trailer: <?= e($trailer['color_hex']) ?>; --trailer-text: <?= e(contrast_color($trailer['color_hex'])) ?>">
|
||||
<div class="trailer-card__head">
|
||||
<span class="trailer-dot"></span>
|
||||
<div class="trailer-card__name">
|
||||
<strong><?= e($trailer['label']) ?></strong>
|
||||
<small><?= e($trailer['color_name']) ?></small>
|
||||
</div>
|
||||
<span class="pill <?= $bookings ? 'pill--red' : 'pill--green' ?>"><?= $bookings ? 'vermietet' : 'frei' ?></span>
|
||||
</div>
|
||||
<?php if ($bookings): ?>
|
||||
<ul class="trailer-card__bookings">
|
||||
<?php foreach ($bookings as $booking): ?>
|
||||
<li>
|
||||
<a href="<?= e(url('/bookings/' . (int) $booking['id'])) ?>" data-panel="<?= (int) $booking['id'] ?>">
|
||||
<strong><?= e($booking['customer_name']) ?></strong>
|
||||
<span><?= e(fmt_date_range($booking['start_date'], $booking['end_date'])) ?> · <?= e($booking['employee_name']) ?></span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php else: ?>
|
||||
<p class="trailer-card__free">Frei – neue Buchung möglich.</p>
|
||||
<?php endif; ?>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2>Nächste Übergaben & Rücknahmen</h2>
|
||||
<p>Die kommenden 14 Tage.</p>
|
||||
</div>
|
||||
<a class="link-arrow" href="<?= e(url('/calendar')) ?>">Im Kalender <svg class="ico" aria-hidden="true"><use href="#i-right"/></svg></a>
|
||||
</div>
|
||||
<?php if (!$upcoming): ?>
|
||||
<div class="empty-state">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg>
|
||||
<h3>Keine Übergaben in den nächsten zwei Wochen</h3>
|
||||
<p>Neue Buchungen erscheinen hier automatisch mit Übergabe- und Rücknahmetermin.</p>
|
||||
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">Buchung anlegen</a>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<ul class="event-list">
|
||||
<?php foreach ($upcoming as $event): ?>
|
||||
<?php $b = $event['booking']; ?>
|
||||
<li class="event-row">
|
||||
<span class="event-row__icon <?= $event['type'] === 'handover' ? 'is-handover' : 'is-return' ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#<?= $event['type'] === 'handover' ? 'i-truck' : 'i-return' ?>"/></svg>
|
||||
</span>
|
||||
<div class="event-row__date">
|
||||
<strong><?= e(fmt_weekday_short($event['date'])) ?>, <?= e(fmt_date($event['date'])) ?></strong>
|
||||
<span class="<?= $event['date'] === $today ? 'is-today' : '' ?>"><?= e(relative_day($event['date'])) ?></span>
|
||||
</div>
|
||||
<div class="event-row__main">
|
||||
<strong><?= e($b['customer_name']) ?></strong>
|
||||
<span><?= $event['type'] === 'handover' ? 'Übergabe' : 'Rücknahme' ?> · <?= e($b['trailer_label']) ?> · <?= e($b['employee_name']) ?></span>
|
||||
</div>
|
||||
<a class="btn small" href="<?= e(url('/bookings/' . (int) $b['id'])) ?>" data-panel="<?= (int) $b['id'] ?>">Details</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<aside class="dash-side">
|
||||
<section class="panel panel--reminders">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2>Erinnerungen</h2>
|
||||
<p>Fällig bis <?= e(fmt_date(add_days($today, 7))) ?>.</p>
|
||||
</div>
|
||||
<a class="link-arrow" href="<?= e(url('/reminders')) ?>">Alle <svg class="ico" aria-hidden="true"><use href="#i-right"/></svg></a>
|
||||
</div>
|
||||
<?php if (($user['role'] ?? '') !== 'admin' && $employeeScope === 0): ?>
|
||||
<div class="empty-state small"><p>Ihrem Konto ist noch kein Mitarbeiter zugeordnet.</p></div>
|
||||
<?php elseif (!$reminders): ?>
|
||||
<div class="empty-state small">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg>
|
||||
<h3>Alles erledigt</h3>
|
||||
<p>Keine offenen Erinnerungen in den nächsten Tagen.</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<ul class="mini-reminders">
|
||||
<?php foreach ($reminders as $reminder): ?>
|
||||
<?php $b = $reminder['booking']; $overdue = $reminder['due_date'] < $today; ?>
|
||||
<li class="mini-reminder<?= $overdue ? ' is-overdue' : '' ?>">
|
||||
<div class="mini-reminder__top">
|
||||
<span class="mini-reminder__date"><?= e(fmt_date($reminder['due_date'])) ?></span>
|
||||
<span class="pill <?= $overdue ? 'pill--red' : 'pill--blue' ?>"><?= e(relative_day($reminder['due_date'])) ?></span>
|
||||
</div>
|
||||
<strong><?= e($reminder['label']) ?></strong>
|
||||
<p><?= e($reminder['message']) ?></p>
|
||||
<div class="mini-reminder__meta">
|
||||
<span><?= e($b['customer_name']) ?> · <?= e($b['trailer_label']) ?></span>
|
||||
<span><?= e($b['employee_name']) ?></span>
|
||||
</div>
|
||||
<div class="mini-reminder__actions">
|
||||
<a href="<?= e(url('/bookings/' . (int) $b['id'])) ?>" data-panel="<?= (int) $b['id'] ?>">Buchung öffnen</a>
|
||||
<form method="post" action="<?= e(url('/reminders/done')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="booking_id" value="<?= (int) $b['id'] ?>">
|
||||
<input type="hidden" name="kind" value="<?= e($reminder['kind']) ?>">
|
||||
<input type="hidden" name="done" value="1">
|
||||
<input type="hidden" name="return_to" value="/">
|
||||
<button class="link-button" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Erledigt</button>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
|
||||
<section class="panel panel--quick">
|
||||
<h2>Kurz zugreifen</h2>
|
||||
<a class="quick-link" href="<?= e(url('/bookings/new')) ?>">
|
||||
<span class="quick-link__icon"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg></span>
|
||||
<span><strong>Neue Buchung</strong><small>Zeitraum und Kunde erfassen</small></span>
|
||||
<svg class="ico chev" aria-hidden="true"><use href="#i-right"/></svg>
|
||||
</a>
|
||||
<a class="quick-link" href="<?= e(url('/search')) ?>">
|
||||
<span class="quick-link__icon"><svg class="ico" aria-hidden="true"><use href="#i-search"/></svg></span>
|
||||
<span><strong>Kunde suchen</strong><small>Buchung nach Name finden</small></span>
|
||||
<svg class="ico chev" aria-hidden="true"><use href="#i-right"/></svg>
|
||||
</a>
|
||||
<a class="quick-link" href="<?= e(url('/reminders?range=all')) ?>">
|
||||
<span class="quick-link__icon"><svg class="ico" aria-hidden="true"><use href="#i-bell"/></svg></span>
|
||||
<span><strong>Alle Erinnerungen</strong><small>Offene Aufgaben prüfen</small></span>
|
||||
<svg class="ico chev" aria-hidden="true"><use href="#i-right"/></svg>
|
||||
</a>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
151
views/layout.php
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
/** @var string $title */
|
||||
/** @var string $content */
|
||||
/** @var array|null $user */
|
||||
$flashes = flash_pull();
|
||||
$path = current_path();
|
||||
$badge = $user !== null ? auth_reminder_badge($user) : 0;
|
||||
$searchValue = $path === '/search' ? query_string('q') : '';
|
||||
$isAdmin = ($user['role'] ?? '') === 'admin';
|
||||
$navActive = static function (string $area) use ($path): string {
|
||||
return match ($area) {
|
||||
'dashboard' => $path === '/' ? ' aria-current="page"' : '',
|
||||
'calendar' => ($path === '/calendar' || str_starts_with($path, '/bookings')) ? ' aria-current="page"' : '',
|
||||
'reminders' => str_starts_with($path, '/reminders') ? ' aria-current="page"' : '',
|
||||
'admin' => str_starts_with($path, '/admin') ? ' aria-current="page"' : '',
|
||||
default => '',
|
||||
};
|
||||
};
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#196abc">
|
||||
<meta name="csrf-token" content="<?= e(csrf_token()) ?>">
|
||||
<title><?= e($title) ?> · Drink it cold</title>
|
||||
<link rel="icon" type="image/svg+xml" href="<?= e(asset('favicon.svg')) ?>">
|
||||
<link rel="apple-touch-icon" href="<?= e(asset('logo-mark.svg')) ?>">
|
||||
<link rel="preload" as="font" type="font/woff2" href="<?= e(asset('fonts/manrope-latin.woff2')) ?>" crossorigin>
|
||||
<link rel="preload" as="font" type="font/woff2" href="<?= e(asset('fonts/inter-latin.woff2')) ?>" crossorigin>
|
||||
<link rel="stylesheet" href="<?= e(asset('app.css')) ?>">
|
||||
<script src="<?= e(asset('app.js')) ?>" defer></script>
|
||||
</head>
|
||||
<body class="app">
|
||||
<a class="skip-link" href="#main">Zum Inhalt springen</a>
|
||||
|
||||
<svg width="0" height="0" aria-hidden="true" focusable="false" style="position:absolute">
|
||||
<defs>
|
||||
<symbol id="i-grid" viewBox="0 0 24 24"><rect x="3" y="3" width="7.5" height="7.5" rx="1.6"/><rect x="13.5" y="3" width="7.5" height="7.5" rx="1.6"/><rect x="3" y="13.5" width="7.5" height="7.5" rx="1.6"/><rect x="13.5" y="13.5" width="7.5" height="7.5" rx="1.6"/></symbol>
|
||||
<symbol id="i-calendar" viewBox="0 0 24 24"><rect x="3" y="5" width="18" height="16" rx="2.5"/><path d="M8 3v4M16 3v4M3 10.5h18"/></symbol>
|
||||
<symbol id="i-bell" viewBox="0 0 24 24"><path d="M18 8.5a6 6 0 1 0-12 0c0 5-2 6.5-2 6.5h16s-2-1.5-2-6.5z"/><path d="M10 19a2.2 2.2 0 0 0 4 0"/></symbol>
|
||||
<symbol id="i-users" viewBox="0 0 24 24"><circle cx="9" cy="8" r="3.4"/><path d="M2.8 20a6.2 6.2 0 0 1 12.4 0"/><path d="M16.4 5.2a3.2 3.2 0 0 1 0 6.1M18 14.6a5.4 5.4 0 0 1 3.2 4.9"/></symbol>
|
||||
<symbol id="i-search" viewBox="0 0 24 24"><circle cx="10.5" cy="10.5" r="6.5"/><path d="m15.5 15.5 5 5"/></symbol>
|
||||
<symbol id="i-plus" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></symbol>
|
||||
<symbol id="i-left" viewBox="0 0 24 24"><path d="m14.5 5.5-6.5 6.5 6.5 6.5"/></symbol>
|
||||
<symbol id="i-right" viewBox="0 0 24 24"><path d="m9.5 5.5 6.5 6.5-6.5 6.5"/></symbol>
|
||||
<symbol id="i-close" viewBox="0 0 24 24"><path d="m6 6 12 12M18 6 6 18"/></symbol>
|
||||
<symbol id="i-copy" viewBox="0 0 24 24"><rect x="8" y="8" width="12" height="12" rx="2"/><path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"/></symbol>
|
||||
<symbol id="i-check" viewBox="0 0 24 24"><path d="m5 12.5 4.5 4.5L19 6.5"/></symbol>
|
||||
<symbol id="i-clock" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M12 7v5.4l3.4 2"/></symbol>
|
||||
<symbol id="i-truck" viewBox="0 0 24 24"><path d="M2.5 6.5h10.5v10H2.5z"/><path d="M13 10h4l4 3.6v2.9h-8z"/><circle cx="6.5" cy="18.5" r="1.8"/><circle cx="17" cy="18.5" r="1.8"/></symbol>
|
||||
<symbol id="i-return" viewBox="0 0 24 24"><path d="M4 9h11a5 5 0 0 1 0 10H9"/><path d="m8 5-4 4 4 4"/></symbol>
|
||||
<symbol id="i-pin" viewBox="0 0 24 24"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0z"/><circle cx="12" cy="10" r="2.8"/></symbol>
|
||||
<symbol id="i-phone" viewBox="0 0 24 24"><path d="M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.1 4.2 2 2 0 0 1 4.1 2h3a2 2 0 0 1 2 1.7c.1 1 .4 1.9.7 2.8a2 2 0 0 1-.5 2.1L8.1 9.9a16 16 0 0 0 6 6l1.3-1.3a2 2 0 0 1 2.1-.4c.9.3 1.8.6 2.8.7a2 2 0 0 1 1.7 2z"/></symbol>
|
||||
<symbol id="i-mail" viewBox="0 0 24 24"><rect x="2.5" y="4.5" width="19" height="15" rx="2"/><path d="m3 7 9 6 9-6"/></symbol>
|
||||
<symbol id="i-edit" viewBox="0 0 24 24"><path d="M4 20h4L20 8l-4-4L4 16z"/><path d="m13.5 6.5 4 4"/></symbol>
|
||||
<symbol id="i-trash" viewBox="0 0 24 24"><path d="M4 7h16M9 7V4.5h6V7M6 7l1 13h10l1-13"/><path d="M10 11v5M14 11v5"/></symbol>
|
||||
<symbol id="i-logout" viewBox="0 0 24 24"><path d="M10 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h5"/><path d="M15 8l4 4-4 4M19 12H9"/></symbol>
|
||||
<symbol id="i-user" viewBox="0 0 24 24"><circle cx="12" cy="8" r="4"/><path d="M4.5 20a7.5 7.5 0 0 1 15 0"/></symbol>
|
||||
<symbol id="i-alert" viewBox="0 0 24 24"><path d="M12 3.5 2.5 20.5h19z"/><path d="M12 9.5v5M12 17.6v.4"/></symbol>
|
||||
<symbol id="i-snow" viewBox="0 0 24 24"><path d="M12 2v20M4.5 6.8l15 10.4M19.5 6.8 4.5 17.2M12 6.4 9.6 4M12 6.4 14.4 4M12 17.6 9.6 20M12 17.6l2.4 2.4"/></symbol>
|
||||
<symbol id="i-sun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9 7 7M17 17l2.1 2.1M19.1 4.9 17 7M7 17l-2.1 2.1"/></symbol>
|
||||
</defs>
|
||||
</svg>
|
||||
|
||||
<header class="topbar">
|
||||
<div class="topbar__inner">
|
||||
<a class="brand" href="<?= e(url('/')) ?>" aria-label="Drink it cold – zur Übersicht">
|
||||
<img class="brand__mark" src="<?= e(asset('logo-mark.svg')) ?>" alt="" width="44" height="32">
|
||||
<span class="brand__text">
|
||||
<span class="brand__name">Drink it cold</span>
|
||||
<span class="brand__sub">Terminplanung</span>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="mainnav" aria-label="Hauptnavigation">
|
||||
<a href="<?= e(url('/')) ?>"<?= $navActive('dashboard') ?>>
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-grid"/></svg><span><span class="nav-long">Übersicht</span><span class="nav-short">Start</span></span>
|
||||
</a>
|
||||
<a href="<?= e(url('/calendar')) ?>"<?= $navActive('calendar') ?>>
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg><span><span class="nav-long">Kalender</span><span class="nav-short">Kalender</span></span>
|
||||
</a>
|
||||
<a href="<?= e(url('/reminders')) ?>"<?= $navActive('reminders') ?>>
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-bell"/></svg><span><span class="nav-long">Erinnerungen</span><span class="nav-short">Aufgaben</span></span>
|
||||
<?php if ($badge > 0): ?><span class="nav-badge" aria-label="<?= $badge ?> offene Erinnerungen"><?= $badge > 99 ? '99+' : $badge ?></span><?php endif; ?>
|
||||
</a>
|
||||
<?php if ($isAdmin): ?>
|
||||
<a href="<?= e(url('/admin/users')) ?>"<?= $navActive('admin') ?>>
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-users"/></svg><span><span class="nav-long">Verwaltung</span><span class="nav-short">Admin</span></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</nav>
|
||||
|
||||
<div class="topbar__tools">
|
||||
<form class="global-search" method="get" action="<?= e(url('/search')) ?>" role="search">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-search"/></svg>
|
||||
<input type="search" name="q" value="<?= e($searchValue) ?>" placeholder="Kunde suchen …" aria-label="Buchung nach Kundenname suchen">
|
||||
</form>
|
||||
|
||||
<details class="user-menu">
|
||||
<summary aria-label="Benutzermenü">
|
||||
<span class="avatar"><?= e(initials($user['first_name'] . ' ' . $user['last_name'])) ?></span>
|
||||
<span class="user-menu__name"><?= e($user['first_name']) ?></span>
|
||||
<svg class="ico chev" aria-hidden="true"><use href="#i-left"/></svg>
|
||||
</summary>
|
||||
<div class="user-menu__panel">
|
||||
<p class="user-menu__who"><strong><?= e($user['first_name'] . ' ' . $user['last_name']) ?></strong>
|
||||
<span><?= $isAdmin ? 'Administrator' : 'Mitarbeiter' ?></span></p>
|
||||
<a href="<?= e(url('/account')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-user"/></svg>Mein Konto</a>
|
||||
<?php if ($isAdmin): ?>
|
||||
<a href="<?= e(url('/admin/users')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-users"/></svg>Benutzerverwaltung</a>
|
||||
<?php endif; ?>
|
||||
<form method="post" action="<?= e(url('/logout')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<button type="submit" class="menu-button"><svg class="ico" aria-hidden="true"><use href="#i-logout"/></svg>Abmelden</button>
|
||||
</form>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<?php if ($flashes): ?>
|
||||
<div class="flash-wrap" role="status" aria-live="polite">
|
||||
<?php foreach ($flashes as $flash): ?>
|
||||
<div class="flash flash--<?= e($flash['type'] ?? 'info') ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#<?= ($flash['type'] ?? '') === 'success' ? 'i-check' : (($flash['type'] ?? '') === 'error' ? 'i-alert' : 'i-bell') ?>"/></svg>
|
||||
<span><?= e($flash['message'] ?? '') ?></span>
|
||||
<button type="button" class="flash__close" data-dismiss aria-label="Meldung schließen"><svg class="ico" aria-hidden="true"><use href="#i-close"/></svg></button>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<main class="page" id="main">
|
||||
<?= $content ?>
|
||||
</main>
|
||||
|
||||
<footer class="footer">
|
||||
<span>Drink it cold · Kühlanhänger-Vermietung</span>
|
||||
<span class="footer__hint">Interner Bereich · <?= e(fmt_date(today_iso())) ?></span>
|
||||
</footer>
|
||||
|
||||
<dialog class="booking-dialog" id="booking-dialog" aria-label="Buchungsdetails">
|
||||
<div class="booking-dialog__inner" id="booking-dialog-content"></div>
|
||||
</dialog>
|
||||
|
||||
<div class="toast" id="toast" role="status" aria-live="polite" hidden></div>
|
||||
</body>
|
||||
</html>
|
||||
109
views/login.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/** @var string $error */
|
||||
/** @var string $first */
|
||||
/** @var string $last */
|
||||
/** @var bool $remember */
|
||||
/** @var string $next */
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#196abc">
|
||||
<title>Anmelden · Drink it cold</title>
|
||||
<link rel="icon" type="image/svg+xml" href="<?= e(asset('favicon.svg')) ?>">
|
||||
<link rel="apple-touch-icon" href="<?= e(asset('logo-mark.svg')) ?>">
|
||||
<link rel="preload" as="image" href="<?= e(asset('img/hero-1280.webp')) ?>" imagesrcset="<?= e(asset('img/hero-800.webp')) ?> 800w, <?= e(asset('img/hero-1280.webp')) ?> 1280w" imagesizes="50vw">
|
||||
<link rel="preload" as="font" type="font/woff2" href="<?= e(asset('fonts/manrope-latin.woff2')) ?>" crossorigin>
|
||||
<link rel="stylesheet" href="<?= e(asset('app.css')) ?>">
|
||||
</head>
|
||||
<body class="auth-page">
|
||||
<div class="auth-shell">
|
||||
<section class="auth-visual" aria-label="Drink it cold – Kühlanhänger-Vermietung">
|
||||
<img class="auth-visual__bg"
|
||||
src="<?= e(asset('img/hero-1280.webp')) ?>"
|
||||
srcset="<?= e(asset('img/hero-800.webp')) ?> 800w, <?= e(asset('img/hero-1280.webp')) ?> 1280w"
|
||||
sizes="50vw" alt="Kühlanhänger von Drink it cold">
|
||||
<div class="auth-visual__shade"></div>
|
||||
<div class="auth-visual__content">
|
||||
<div class="auth-brand">
|
||||
<img src="<?= e(asset('logo-mark.svg')) ?>" alt="" width="56" height="40">
|
||||
<span>
|
||||
<strong>Drink it cold</strong>
|
||||
<small>Kühlanhänger-Vermietung</small>
|
||||
</span>
|
||||
</div>
|
||||
<div class="auth-visual__claim">
|
||||
<p class="eyebrow">Terminplanung</p>
|
||||
<h2>Alle acht Anhänger.<br>Ein Blick.</h2>
|
||||
<p>Buchungen, Übergaben und Erinnerungen zentral – damit niemand mehr im Kalender blättern muss.</p>
|
||||
<ul class="auth-points">
|
||||
<li><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Kalender für Tag, Woche und Monat</li>
|
||||
<li><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Automatische Erinnerungen fürs Team</li>
|
||||
<li><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Zentrale Buchungsdaten für alle</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p class="auth-visual__foot">Zum Kühlen. Für Feste. Seit jeher.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="auth-panel">
|
||||
<div class="auth-card">
|
||||
<a class="auth-card__mobilebrand" href="<?= e(url('/')) ?>" aria-label="Drink it cold">
|
||||
<img src="<?= e(asset('logo-mark.svg')) ?>" alt="" width="44" height="32">
|
||||
<span>Drink it cold</span>
|
||||
</a>
|
||||
<p class="eyebrow">Interner Bereich</p>
|
||||
<h1>Anmelden</h1>
|
||||
<p class="auth-card__lede">Bitte mit dem vom Administrator angelegten Zugang anmelden.</p>
|
||||
|
||||
<?php if ($error !== ''): ?>
|
||||
<div class="flash flash--error" role="alert">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<span><?= e($error) ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="<?= e(url('/login')) ?>" class="auth-form">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="next" value="<?= e_attr($next) ?>">
|
||||
<div class="field-row">
|
||||
<label class="field">
|
||||
<span>Vorname</span>
|
||||
<input type="text" name="first_name" value="<?= e($first) ?>" autocomplete="given-name" required autofocus>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Nachname</span>
|
||||
<input type="text" name="last_name" value="<?= e($last) ?>" autocomplete="family-name" required>
|
||||
</label>
|
||||
</div>
|
||||
<label class="field">
|
||||
<span>Passwort</span>
|
||||
<input type="password" name="password" autocomplete="current-password" required>
|
||||
</label>
|
||||
<label class="check">
|
||||
<input type="checkbox" name="remember" value="1"<?= $remember ? ' checked' : '' ?>>
|
||||
<span>Auf diesem Gerät angemeldet bleiben</span>
|
||||
</label>
|
||||
<button class="btn primary btn--block" type="submit">Anmelden</button>
|
||||
</form>
|
||||
|
||||
<p class="auth-card__hint">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-snow"/></svg>
|
||||
Kein Zugang? Benutzerkonten werden ausschließlich vom Administrator eingerichtet – eine Selbstregistrierung gibt es nicht.
|
||||
</p>
|
||||
</div>
|
||||
<p class="auth-foot">© <?= date('Y') ?> Drink it cold · Neuss</p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<svg width="0" height="0" aria-hidden="true" style="position:absolute">
|
||||
<defs>
|
||||
<symbol id="i-check" viewBox="0 0 24 24"><path d="m5 12.5 4.5 4.5L19 6.5"/></symbol>
|
||||
<symbol id="i-alert" viewBox="0 0 24 24"><path d="M12 3.5 2.5 20.5h19z"/><path d="M12 9.5v5M12 17.6v.4"/></symbol>
|
||||
<symbol id="i-snow" viewBox="0 0 24 24"><path d="M12 2v20M4.5 6.8l15 10.4M19.5 6.8 4.5 17.2M12 6.4 9.6 4M12 6.4 14.4 4M12 17.6 9.6 20M12 17.6l2.4 2.4"/></symbol>
|
||||
</defs>
|
||||
</svg>
|
||||
</body>
|
||||
</html>
|
||||
139
views/reminders.php
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
/** @var array $rows */
|
||||
/** @var array $groups */
|
||||
/** @var string $range */
|
||||
/** @var int $employeeFilter */
|
||||
/** @var bool $showDone */
|
||||
/** @var array $employees */
|
||||
/** @var bool $hasEmployee */
|
||||
/** @var bool $isAdmin */
|
||||
/** @var string $today */
|
||||
/** @var bool $mailEnabled */
|
||||
$rangeUrl = static function (string $r) use ($employeeFilter, $showDone): string {
|
||||
$params = ['range' => $r];
|
||||
if ($employeeFilter > 0) {
|
||||
$params['employee'] = $employeeFilter;
|
||||
}
|
||||
if ($showDone) {
|
||||
$params['done'] = '1';
|
||||
}
|
||||
return '/reminders?' . http_build_query($params);
|
||||
};
|
||||
$openCount = 0;
|
||||
foreach ($rows as $row) {
|
||||
if (!$row['done']) {
|
||||
$openCount++;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Aufgaben & Erinnerungen</p>
|
||||
<h1>Was als Nächstes ansteht</h1>
|
||||
<p class="page-head__lede">Automatisch aus Mietbeginn und Mietende berechnet – für den zuständigen Mitarbeiter.</p>
|
||||
</div>
|
||||
<div class="page-head__actions">
|
||||
<?php if ($isAdmin && $mailEnabled): ?>
|
||||
<form method="post" action="<?= e(url('/admin/reminders/send')) ?>" data-confirm="Fällige Erinnerungen jetzt per E-Mail an die Mitarbeiter senden?">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-mail"/></svg> E-Mail-Versand starten</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<a class="btn primary" href="<?= e(url('/calendar')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg> Kalender</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="reminder-toolbar">
|
||||
<div class="segmented" role="group" aria-label="Zeitraum">
|
||||
<?php foreach (['7' => '7 Tage', '14' => '14 Tage', '30' => '30 Tage', 'all' => 'Alle offenen'] as $key => $label): ?>
|
||||
<a href="<?= e(url($rangeUrl($key))) ?>"<?= $range === $key ? ' class="is-active" aria-current="page"' : '' ?>><?= $label ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<form class="cal-filters" method="get" action="<?= e(url('/reminders')) ?>">
|
||||
<input type="hidden" name="range" value="<?= e($range) ?>">
|
||||
<?php if ($isAdmin && count($employees) > 1): ?>
|
||||
<label class="inline-field">
|
||||
<span>Mitarbeiter</span>
|
||||
<select name="employee" data-autosubmit>
|
||||
<option value="">Alle</option>
|
||||
<?php foreach ($employees as $employee): ?>
|
||||
<option value="<?= (int) $employee['id'] ?>"<?= $employeeFilter === (int) $employee['id'] ? ' selected' : '' ?>><?= e($employee['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<label class="check check--small">
|
||||
<input type="checkbox" name="done" value="1" data-autosubmit<?= $showDone ? ' checked' : '' ?>>
|
||||
<span>Erledigte anzeigen</span>
|
||||
</label>
|
||||
<button class="btn small" type="submit">Anwenden</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php if (!$hasEmployee): ?>
|
||||
<div class="alert alert--warning">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Ihrem Benutzerkonto ist noch kein Mitarbeiter zugeordnet.</strong> Ein Administrator kann das in der Benutzerverwaltung nachholen. Bis dahin sehen Sie hier keine persönlichen Erinnerungen.</div>
|
||||
</div>
|
||||
<?php elseif (!$rows): ?>
|
||||
<div class="empty-state">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg>
|
||||
<h3>Keine offenen Erinnerungen</h3>
|
||||
<p>Für den gewählten Zeitraum ist alles erledigt. Neue Erinnerungen entstehen automatisch, sobald eine Buchung angelegt wird.</p>
|
||||
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">Neue Buchung anlegen</a>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p class="list-summary"><?= $openCount ?> offene Erinnerung<?= $openCount === 1 ? '' : 'en' ?><?= $isAdmin ? '' : ' für Sie' ?><?= $employeeFilter > 0 ? ' · ' . e(employees_map()[$employeeFilter]['name'] ?? '') : '' ?></p>
|
||||
<?php foreach ($groups as $date => $items): ?>
|
||||
<?php $isPast = $date < $today; $isToday = $date === $today; ?>
|
||||
<section class="reminder-day<?= $isPast ? ' is-past' : '' ?>">
|
||||
<header class="reminder-day__head">
|
||||
<h2><?= e(fmt_date_long($date)) ?></h2>
|
||||
<span class="pill <?= $isPast ? 'pill--red' : ($isToday ? 'pill--amber' : 'pill--blue') ?>"><?= e(relative_day($date)) ?></span>
|
||||
<span class="reminder-day__count"><?= count($items) ?></span>
|
||||
</header>
|
||||
<ul class="reminder-cards">
|
||||
<?php foreach ($items as $row): ?>
|
||||
<?php
|
||||
$b = $row['booking'];
|
||||
$overdue = !$row['done'] && $date < $today;
|
||||
?>
|
||||
<li class="reminder-card<?= $row['done'] ? ' is-done' : '' ?><?= $overdue ? ' is-overdue' : '' ?>">
|
||||
<div class="reminder-card__main">
|
||||
<div class="reminder-card__top">
|
||||
<span class="pill <?= $row['kind'] === 'end_1' ? 'pill--amber' : 'pill--blue' ?>"><?= e($row['label']) ?></span>
|
||||
<span class="reminder-card__employee"><?= e($b['employee_name']) ?></span>
|
||||
</div>
|
||||
<p class="reminder-card__message"><?= e($row['message']) ?></p>
|
||||
<div class="reminder-card__booking">
|
||||
<span class="trailer-dot" style="--trailer: <?= e($b['trailer_color']) ?>"></span>
|
||||
<strong><?= e($b['customer_name']) ?></strong>
|
||||
<span><?= e($b['trailer_label']) ?> · <?= e(fmt_date_range($b['start_date'], $b['end_date'])) ?></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="reminder-card__actions">
|
||||
<a class="btn small" href="<?= e(url('/bookings/' . (int) $b['id'])) ?>" data-panel="<?= (int) $b['id'] ?>">Buchung öffnen</a>
|
||||
<form method="post" action="<?= e(url('/reminders/done')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="booking_id" value="<?= (int) $b['id'] ?>">
|
||||
<input type="hidden" name="kind" value="<?= e($row['kind']) ?>">
|
||||
<input type="hidden" name="done" value="<?= $row['done'] ? '0' : '1' ?>">
|
||||
<input type="hidden" name="return_to" value="<?= e(current_path() . '?' . http_build_query($_GET)) ?>">
|
||||
<?php if ($row['done']): ?>
|
||||
<button class="link-button small" type="submit">Rückgängig</button>
|
||||
<?php else: ?>
|
||||
<button class="btn small" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Erledigt</button>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</section>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<div class="reminder-note">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-bell"/></svg>
|
||||
<p>Die drei Erinnerungen entstehen automatisch: 8 Tage vor Mietbeginn, 1 Tag vor Mietbeginn und 1 Tag vor Mietende. Bei einer Terminänderung oder Stornierung passen sie sich sofort an.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
60
views/search.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/** @var string $query */
|
||||
/** @var array $results */
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Buchungssuche</p>
|
||||
<h1>Kunde finden</h1>
|
||||
<p class="page-head__lede">Suche nach Kundenname, Straße oder Ort – auch in stornierten Buchungen.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form class="search-hero" method="get" action="<?= e(url('/search')) ?>" role="search">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-search"/></svg>
|
||||
<label class="sr-only" for="q">Suchbegriff</label>
|
||||
<input type="search" id="q" name="q" value="<?= e($query) ?>" placeholder="Name, Straße oder Ort …" autofocus>
|
||||
<button class="btn primary" type="submit">Suchen</button>
|
||||
</form>
|
||||
|
||||
<?php if ($query !== ''): ?>
|
||||
<section class="panel">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2><?= count($results) ?> Treffer</h2>
|
||||
<p>für „<?= e($query) ?>“</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!$results): ?>
|
||||
<div class="empty-state">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-search"/></svg>
|
||||
<h3>Keine Buchung gefunden</h3>
|
||||
<p>Bitte einen anderen Namen, eine Straße oder einen Ort versuchen.</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<ul class="result-list">
|
||||
<?php foreach ($results as $booking): ?>
|
||||
<?php $cancelled = $booking['status'] === 'cancelled'; ?>
|
||||
<li class="result-row<?= $cancelled ? ' is-cancelled' : '' ?>">
|
||||
<span class="trailer-dot" style="--trailer: <?= e($booking['trailer_color']) ?>"></span>
|
||||
<div class="result-row__main">
|
||||
<strong><?= e($booking['customer_name']) ?></strong>
|
||||
<span><?= e(fmt_date_range($booking['start_date'], $booking['end_date'])) ?> · <?= e($booking['trailer_label']) ?> · <?= e($booking['employee_name']) ?></span>
|
||||
</div>
|
||||
<div class="result-row__meta">
|
||||
<span><?= e($booking['city'] ?: '–') ?></span>
|
||||
<?php if ($cancelled): ?><span class="pill pill--grey">storniert</span><?php endif; ?>
|
||||
</div>
|
||||
<a class="btn small" href="<?= e(url('/bookings/' . (int) $booking['id'])) ?>" data-panel="<?= (int) $booking['id'] ?>">Details</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
<?php else: ?>
|
||||
<div class="empty-state empty-state--plain">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-search"/></svg>
|
||||
<h3>Welchen Kunden suchen Sie?</h3>
|
||||
<p>Ein Teil des Namens genügt. Die Suche berücksichtigt alle Buchungen, auch vergangene und stornierte.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
46
web/.htaccess
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# Drink it cold – Apache-Konfiguration für die Subdomain.
|
||||
# Öffentlich ist nur dieses Verzeichnis; app/, views/, sql/ und storage/
|
||||
# liegen zwar im selben FTP-Baum, sind aber zusätzlich per .htaccess gesperrt.
|
||||
|
||||
Options -Indexes
|
||||
DirectoryIndex index.php index.html
|
||||
AddDefaultCharset UTF-8
|
||||
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
|
||||
# Immer HTTPS. Der Hoster kann TLS terminieren, daher auch der Proxy-Header.
|
||||
RewriteCond %{HTTPS} !=on
|
||||
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
|
||||
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
|
||||
|
||||
# Interne Verzeichnisse nie ausliefern.
|
||||
RewriteRule ^(app|views|sql|storage|tools)(/|$) - [F,L]
|
||||
RewriteCond %{REQUEST_URI} !^/\.well-known/
|
||||
RewriteRule (^|/)\. - [F,L]
|
||||
|
||||
# Nicht vorhandene Pfade an den Front Controller.
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^ index.php [QSA,L]
|
||||
</IfModule>
|
||||
|
||||
<IfModule mod_headers.c>
|
||||
Header always set X-Content-Type-Options "nosniff"
|
||||
Header always set X-Frame-Options "DENY"
|
||||
Header always set Referrer-Policy "same-origin"
|
||||
<FilesMatch "\.(css|js|svg|png|jpg|jpeg|webp|ico|woff2)$">
|
||||
Header set Cache-Control "public, max-age=604800"
|
||||
</FilesMatch>
|
||||
</IfModule>
|
||||
|
||||
<FilesMatch "^(\.env|\.git.*|composer\..*)$">
|
||||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
</FilesMatch>
|
||||
|
||||
<IfModule mod_php.c>
|
||||
php_flag display_errors off
|
||||
php_flag log_errors on
|
||||
</IfModule>
|
||||
897
web/assets/app.css
Normal file
|
|
@ -0,0 +1,897 @@
|
|||
/* ==========================================================================
|
||||
Drink it cold – Terminplanung
|
||||
Design: Eisblau (#196abc) + Weiß, Schriften Manrope/Inter (lokal)
|
||||
========================================================================== */
|
||||
|
||||
@font-face {
|
||||
font-family: 'Inter';
|
||||
font-style: normal;
|
||||
font-weight: 400 700;
|
||||
font-display: swap;
|
||||
src: url('fonts/inter-latin.woff2') format('woff2');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Manrope';
|
||||
font-style: normal;
|
||||
font-weight: 400 800;
|
||||
font-display: swap;
|
||||
src: url('fonts/manrope-latin.woff2') format('woff2');
|
||||
}
|
||||
|
||||
:root {
|
||||
--brand: #196abc;
|
||||
--brand-600: #1560ab;
|
||||
--brand-700: #12528f;
|
||||
--brand-800: #0d3d6d;
|
||||
--brand-900: #0a2c4e;
|
||||
--ice-50: #f4f9fe;
|
||||
--ice-100: #e6f1fc;
|
||||
--ice-200: #d3e6f9;
|
||||
--ice-300: #b9daf6;
|
||||
--ink: #0e1b26;
|
||||
--ink-2: #31485a;
|
||||
--muted: #667b8a;
|
||||
--line: #dbe6f0;
|
||||
--line-soft: #eaf2f9;
|
||||
--white: #fff;
|
||||
--green: #2e7d32;
|
||||
--green-soft: #eaf6ea;
|
||||
--red: #bb3a2f;
|
||||
--red-soft: #fdeeec;
|
||||
--amber: #b16d0a;
|
||||
--amber-soft: #fff5e3;
|
||||
|
||||
--radius-sm: 8px;
|
||||
--radius: 12px;
|
||||
--radius-lg: 18px;
|
||||
--radius-xl: 24px;
|
||||
|
||||
--shadow-sm: 0 1px 2px rgba(10, 44, 78, .05);
|
||||
--shadow: 0 2px 8px rgba(10, 44, 78, .06), 0 12px 28px rgba(10, 44, 78, .06);
|
||||
--shadow-lg: 0 10px 30px rgba(10, 44, 78, .12), 0 30px 60px rgba(10, 44, 78, .12);
|
||||
|
||||
--font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
||||
--font-display: 'Manrope', 'Inter', system-ui, sans-serif;
|
||||
|
||||
--topbar-h: 68px;
|
||||
--page-max: 1520px;
|
||||
--gutter: clamp(1rem, 2.6vw, 2rem);
|
||||
}
|
||||
|
||||
*, *::before, *::after { box-sizing: border-box; }
|
||||
html { -webkit-text-size-adjust: 100%; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: var(--font-body);
|
||||
font-size: 1rem;
|
||||
line-height: 1.55;
|
||||
color: var(--ink-2);
|
||||
background:
|
||||
radial-gradient(1200px 500px at 100% -10%, #e9f3fd 0%, rgba(233, 243, 253, 0) 60%),
|
||||
var(--ice-50);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
min-height: 100vh;
|
||||
}
|
||||
img, svg { display: block; max-width: 100%; }
|
||||
a { color: var(--brand); text-decoration: none; }
|
||||
a:hover { color: var(--brand-700); }
|
||||
button, input, select, textarea { font: inherit; color: inherit; }
|
||||
h1, h2, h3 { font-family: var(--font-display); color: var(--ink); line-height: 1.18; margin: 0; letter-spacing: -.02em; }
|
||||
h1 { font-size: clamp(1.55rem, 2.6vw, 2.15rem); font-weight: 800; }
|
||||
h2 { font-size: 1.12rem; font-weight: 800; }
|
||||
h3 { font-size: .98rem; font-weight: 800; }
|
||||
p { margin: 0; }
|
||||
hr { border: 0; border-top: 1px solid var(--line-soft); margin: 16px 0; }
|
||||
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
|
||||
a .ico, button .ico { pointer-events: none; }
|
||||
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
||||
.muted { color: var(--muted); }
|
||||
.small { font-size: .82rem; }
|
||||
.ta-right { text-align: right; }
|
||||
.inline { display: inline; }
|
||||
.optional { font-weight: 500; color: var(--muted); }
|
||||
|
||||
.skip-link {
|
||||
position: fixed; left: 12px; top: -60px; z-index: 999;
|
||||
background: var(--white); color: var(--ink); padding: 10px 16px; border-radius: 10px;
|
||||
box-shadow: var(--shadow); transition: top .2s;
|
||||
}
|
||||
.skip-link:focus { top: 12px; }
|
||||
|
||||
/* --------------------------------------------------------------- Topbar */
|
||||
.topbar {
|
||||
position: sticky; top: 0; z-index: 40;
|
||||
background: rgba(255, 255, 255, .92);
|
||||
backdrop-filter: blur(14px);
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.topbar__inner {
|
||||
max-width: var(--page-max); margin: 0 auto;
|
||||
min-height: var(--topbar-h);
|
||||
padding: 0 var(--gutter);
|
||||
display: flex; align-items: center; gap: 22px;
|
||||
}
|
||||
.brand { display: inline-flex; align-items: center; gap: 10px; flex: 0 0 auto; color: var(--ink); }
|
||||
.brand:hover { color: var(--ink); }
|
||||
.brand__mark { width: 44px; height: 32px; }
|
||||
.brand__text { display: flex; flex-direction: column; line-height: 1.05; }
|
||||
.brand__name { font-family: var(--font-display); font-weight: 800; font-size: 1.02rem; letter-spacing: -.02em; }
|
||||
.brand__sub { font-size: .68rem; text-transform: uppercase; letter-spacing: .13em; color: var(--muted); margin-top: 3px; }
|
||||
|
||||
.mainnav { display: flex; align-items: center; gap: 2px; flex: 1 1 auto; min-width: 0; }
|
||||
.mainnav a {
|
||||
display: inline-flex; align-items: center; gap: 7px;
|
||||
padding: 9px 12px; border-radius: 10px;
|
||||
font-weight: 600; font-size: .88rem; color: var(--ink-2);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.mainnav a:hover { background: var(--ice-50); color: var(--brand-700); }
|
||||
.mainnav a[aria-current="page"] { background: var(--ice-100); color: var(--brand-700); }
|
||||
.mainnav .ico { width: 18px; height: 18px; }
|
||||
.nav-short { display: none; }
|
||||
.nav-badge {
|
||||
min-width: 19px; height: 19px; padding: 0 6px; border-radius: 99px;
|
||||
background: var(--brand); color: #fff; font-size: .7rem; font-weight: 700;
|
||||
display: inline-flex; align-items: center; justify-content: center; line-height: 1;
|
||||
}
|
||||
|
||||
.topbar__tools { display: flex; align-items: center; gap: 10px; margin-left: auto; }
|
||||
.global-search {
|
||||
position: relative; display: flex; align-items: center;
|
||||
}
|
||||
.global-search .ico { position: absolute; left: 10px; width: 17px; height: 17px; color: var(--muted); }
|
||||
.global-search input {
|
||||
width: 190px; height: 38px; padding: 0 12px 0 34px;
|
||||
border: 1px solid var(--line); border-radius: 10px; background: var(--ice-50);
|
||||
outline: none; font-size: .86rem;
|
||||
}
|
||||
.global-search input:focus { background: #fff; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(25, 106, 188, .12); }
|
||||
|
||||
.user-menu { position: relative; }
|
||||
.user-menu summary {
|
||||
list-style: none; display: flex; align-items: center; gap: 8px;
|
||||
cursor: pointer; padding: 4px 6px 4px 4px; border-radius: 99px;
|
||||
border: 1px solid transparent; user-select: none;
|
||||
}
|
||||
.user-menu summary::-webkit-details-marker { display: none; }
|
||||
.user-menu summary:hover { background: var(--ice-50); }
|
||||
.avatar {
|
||||
width: 34px; height: 34px; border-radius: 50%;
|
||||
background: linear-gradient(145deg, var(--brand), var(--brand-700));
|
||||
color: #fff; font-weight: 700; font-size: .78rem;
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
letter-spacing: .02em; flex: 0 0 auto;
|
||||
}
|
||||
.avatar--small { width: 30px; height: 30px; font-size: .7rem; }
|
||||
.user-menu__name { font-weight: 600; font-size: .87rem; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.user-menu .chev { width: 14px; height: 14px; transform: rotate(-90deg); color: var(--muted); transition: transform .2s; }
|
||||
.user-menu[open] .chev { transform: rotate(90deg); }
|
||||
.user-menu__panel {
|
||||
position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
|
||||
width: 248px; padding: 8px; background: #fff;
|
||||
border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg);
|
||||
}
|
||||
.user-menu__who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line-soft); margin-bottom: 6px; display: flex; flex-direction: column; }
|
||||
.user-menu__who strong { color: var(--ink); font-size: .9rem; }
|
||||
.user-menu__who span { font-size: .76rem; color: var(--muted); }
|
||||
.user-menu__panel a, .menu-button {
|
||||
display: flex; align-items: center; gap: 9px; width: 100%;
|
||||
padding: 9px 10px; border-radius: 8px; border: 0; background: none;
|
||||
color: var(--ink-2); font-size: .87rem; font-weight: 500; text-align: left; cursor: pointer;
|
||||
}
|
||||
.user-menu__panel a:hover, .menu-button:hover { background: var(--ice-50); color: var(--brand-700); }
|
||||
.user-menu__panel form { margin: 0; }
|
||||
.user-menu__panel .ico { width: 17px; height: 17px; color: var(--muted); }
|
||||
|
||||
/* --------------------------------------------------------------- Flashes */
|
||||
.flash-wrap { max-width: var(--page-max); margin: 0 auto; padding: 14px var(--gutter) 0; display: grid; gap: 8px; }
|
||||
.flash {
|
||||
display: flex; align-items: flex-start; gap: 10px;
|
||||
padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
|
||||
background: #fff; color: var(--ink-2); box-shadow: var(--shadow-sm); font-size: .9rem;
|
||||
}
|
||||
.flash .ico { width: 18px; height: 18px; margin-top: 1px; }
|
||||
.flash--success { border-color: #bfe3bf; background: var(--green-soft); color: #1f5a23; }
|
||||
.flash--error { border-color: #f0c4be; background: var(--red-soft); color: #7d241b; }
|
||||
.flash--info { border-color: var(--ice-200); background: var(--ice-50); color: var(--brand-800); }
|
||||
.flash__close { margin-left: auto; border: 0; background: none; color: inherit; opacity: .55; cursor: pointer; padding: 2px; }
|
||||
.flash__close:hover { opacity: 1; }
|
||||
.flash__close .ico { width: 16px; height: 16px; }
|
||||
|
||||
/* --------------------------------------------------------------- Layout */
|
||||
.page { max-width: var(--page-max); margin: 0 auto; padding: clamp(18px, 2.4vw, 30px) var(--gutter) 48px; }
|
||||
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; flex-wrap: wrap; }
|
||||
.page-head--compact { margin-bottom: 18px; }
|
||||
.page-head h1 { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
||||
.page-head__lede { margin-top: 6px; color: var(--muted); max-width: 62ch; }
|
||||
.page-head__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||
.page-head__actions form { margin: 0; }
|
||||
.eyebrow {
|
||||
font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
|
||||
color: var(--brand); margin-bottom: 7px;
|
||||
}
|
||||
.footer {
|
||||
max-width: var(--page-max); margin: 0 auto; padding: 20px var(--gutter) 30px;
|
||||
display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
|
||||
border-top: 1px solid var(--line); color: var(--muted); font-size: .78rem;
|
||||
}
|
||||
.footer__hint { color: #8a9aa7; }
|
||||
|
||||
/* --------------------------------------------------------------- Buttons */
|
||||
.btn {
|
||||
display: inline-flex; align-items: center; justify-content: center; gap: 7px;
|
||||
min-height: 40px; padding: 9px 15px;
|
||||
border: 1px solid var(--line); border-radius: 10px;
|
||||
background: #fff; color: var(--ink-2); font-weight: 600; font-size: .87rem;
|
||||
cursor: pointer; text-decoration: none; white-space: nowrap;
|
||||
transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .15s;
|
||||
}
|
||||
.btn:hover { background: var(--ice-50); border-color: var(--ice-300); color: var(--brand-700); }
|
||||
.btn:active { transform: translateY(1px); }
|
||||
.btn .ico { width: 17px; height: 17px; }
|
||||
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 5px 14px rgba(25, 106, 188, .2); }
|
||||
.btn.primary:hover { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
|
||||
.btn.small { min-height: 32px; padding: 5px 11px; font-size: .8rem; border-radius: 8px; }
|
||||
.btn.small .ico { width: 15px; height: 15px; }
|
||||
.btn--block { width: 100%; }
|
||||
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
|
||||
.btn.danger:hover { background: #9e2f25; border-color: #9e2f25; color: #fff; }
|
||||
.btn.danger-ghost { background: transparent; border-color: #e7b8b2; color: #9e2f25; }
|
||||
.btn.danger-ghost:hover { background: var(--red-soft); border-color: var(--red); color: #7d241b; }
|
||||
.btn:focus-visible, .icon-btn:focus-visible, a:focus-visible, summary:focus-visible {
|
||||
outline: 3px solid rgba(25, 106, 188, .3); outline-offset: 2px;
|
||||
}
|
||||
.icon-btn {
|
||||
width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line);
|
||||
background: #fff; display: inline-flex; align-items: center; justify-content: center;
|
||||
color: var(--ink-2); cursor: pointer;
|
||||
}
|
||||
.icon-btn:hover { background: var(--ice-50); color: var(--brand-700); border-color: var(--ice-300); }
|
||||
.icon-btn .ico { width: 18px; height: 18px; }
|
||||
.link-button {
|
||||
border: 0; background: none; padding: 0; color: var(--brand);
|
||||
font-weight: 600; font-size: .85rem; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
|
||||
}
|
||||
.link-button:hover { color: var(--brand-700); text-decoration: underline; }
|
||||
.link-button .ico { width: 15px; height: 15px; }
|
||||
.link-arrow { display: inline-flex; align-items: center; gap: 4px; font-size: .84rem; font-weight: 600; white-space: nowrap; }
|
||||
.link-arrow .ico { width: 15px; height: 15px; }
|
||||
|
||||
/* --------------------------------------------------------------- Bits */
|
||||
.pill {
|
||||
display: inline-flex; align-items: center; gap: 4px;
|
||||
padding: 2px 8px; border-radius: 99px;
|
||||
font-size: .7rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
|
||||
background: var(--ice-100); color: var(--brand-700);
|
||||
}
|
||||
.pill .ico { width: 12px; height: 12px; }
|
||||
.pill--green { background: var(--green-soft); color: #246328; }
|
||||
.pill--red { background: var(--red-soft); color: #9e2f25; }
|
||||
.pill--amber { background: var(--amber-soft); color: #8a5507; }
|
||||
.pill--blue { background: var(--ice-100); color: var(--brand-700); }
|
||||
.pill--grey { background: #eef2f5; color: #556a78; }
|
||||
.trailer-dot {
|
||||
width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto;
|
||||
background: var(--trailer, var(--brand));
|
||||
box-shadow: 0 0 0 1px rgba(0, 0, 0, .08);
|
||||
}
|
||||
.trailer-chip {
|
||||
display: inline-flex; align-items: center; gap: 7px;
|
||||
background: var(--trailer); color: var(--trailer-text);
|
||||
padding: 4px 10px; border-radius: 99px; font-weight: 600; font-size: .8rem;
|
||||
}
|
||||
.panel, .card {
|
||||
background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
.panel { padding: 20px; }
|
||||
.card { padding: 22px; }
|
||||
.panel__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
|
||||
.panel__head p, .card__head p { color: var(--muted); font-size: .84rem; margin-top: 4px; }
|
||||
.card__head { margin-bottom: 18px; }
|
||||
.card__head--row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
||||
.card h2 { margin-bottom: 0; }
|
||||
.empty-state {
|
||||
text-align: center; padding: 38px 20px; color: var(--muted);
|
||||
border: 1px dashed var(--ice-300); border-radius: var(--radius); background: var(--ice-50);
|
||||
}
|
||||
.empty-state .ico { width: 34px; height: 34px; color: var(--brand); margin: 0 auto 10px; }
|
||||
.empty-state h3 { color: var(--ink); margin-bottom: 5px; }
|
||||
.empty-state p { max-width: 50ch; margin: 0 auto 14px; font-size: .88rem; }
|
||||
.empty-state.small { padding: 20px 14px; }
|
||||
.empty-state.small .ico { width: 26px; height: 26px; }
|
||||
.empty-state.small h3 { font-size: .9rem; }
|
||||
.empty-state--plain { border: 0; background: transparent; padding: 60px 20px; }
|
||||
.alert {
|
||||
display: flex; align-items: flex-start; gap: 11px;
|
||||
padding: 13px 15px; border-radius: 12px; margin-bottom: 16px;
|
||||
border: 1px solid var(--ice-200); background: var(--ice-50); color: var(--brand-800);
|
||||
font-size: .88rem;
|
||||
}
|
||||
.alert .ico { width: 19px; height: 19px; margin-top: 1px; }
|
||||
.alert--warning { background: var(--amber-soft); border-color: #f2d6a4; color: #754805; }
|
||||
.alert--error { background: var(--red-soft); border-color: #f0c4be; color: #7d241b; }
|
||||
.alert p { margin-top: 3px; }
|
||||
.breadcrumb { display: flex; align-items: center; gap: 7px; font-size: .82rem; color: var(--muted); margin-bottom: 14px; }
|
||||
.breadcrumb a { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
|
||||
.breadcrumb .ico { width: 14px; height: 14px; }
|
||||
.stack { display: grid; gap: 14px; }
|
||||
.stack-actions { display: grid; gap: 8px; }
|
||||
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }
|
||||
.card--note { background: linear-gradient(160deg, #fff, var(--ice-50)); }
|
||||
.card--note p { margin-top: 6px; color: var(--muted); font-size: .86rem; }
|
||||
.list-summary { font-size: .84rem; color: var(--muted); margin: -4px 0 16px; }
|
||||
|
||||
/* --------------------------------------------------------------- KPI + Dashboard */
|
||||
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
|
||||
.kpi {
|
||||
display: flex; align-items: center; gap: 12px;
|
||||
background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
|
||||
padding: 14px 16px; box-shadow: var(--shadow-sm);
|
||||
}
|
||||
.kpi__icon {
|
||||
width: 40px; height: 40px; border-radius: 11px; flex: 0 0 auto;
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.kpi__icon .ico { width: 20px; height: 20px; }
|
||||
.kpi__icon--blue { background: var(--ice-100); color: var(--brand); }
|
||||
.kpi__icon--green { background: var(--green-soft); color: var(--green); }
|
||||
.kpi__icon--amber { background: var(--amber-soft); color: var(--amber); }
|
||||
.kpi__icon--red { background: var(--red-soft); color: var(--red); }
|
||||
.kpi strong { display: block; font-family: var(--font-display); font-size: 1.3rem; color: var(--ink); line-height: 1.1; }
|
||||
.kpi span { font-size: .78rem; color: var(--muted); }
|
||||
|
||||
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(300px, .85fr); gap: 18px; align-items: start; }
|
||||
.dash-main, .dash-side { display: grid; gap: 18px; min-width: 0; }
|
||||
.trailer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.trailer-card {
|
||||
border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 13px;
|
||||
background: #fff; position: relative; overflow: hidden;
|
||||
}
|
||||
.trailer-card::before {
|
||||
content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--trailer);
|
||||
}
|
||||
.trailer-card.is-rented { background: linear-gradient(180deg, #fff, #fbfdff); }
|
||||
.trailer-card.is-own { box-shadow: 0 0 0 2px rgba(25, 106, 188, .28); }
|
||||
.trailer-card__head { display: flex; align-items: center; gap: 8px; }
|
||||
.trailer-card__name { display: flex; flex-direction: column; line-height: 1.15; }
|
||||
.trailer-card__name strong { color: var(--ink); font-size: .9rem; }
|
||||
.trailer-card__name small { color: var(--muted); font-size: .7rem; }
|
||||
.trailer-card__head .pill { margin-left: auto; }
|
||||
.trailer-card__bookings { list-style: none; margin: 9px 0 0; padding: 0; display: grid; gap: 6px; }
|
||||
.trailer-card__bookings a { display: flex; flex-direction: column; padding: 6px 8px; border-radius: 8px; background: var(--ice-50); }
|
||||
.trailer-card__bookings a:hover { background: var(--ice-100); }
|
||||
.trailer-card__bookings strong { font-size: .82rem; color: var(--ink); }
|
||||
.trailer-card__bookings span { font-size: .72rem; color: var(--muted); }
|
||||
.trailer-card__free { font-size: .78rem; color: var(--muted); margin-top: 9px; }
|
||||
|
||||
.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
|
||||
.event-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
|
||||
.event-row:first-child { border-top: 0; }
|
||||
.event-row__icon {
|
||||
width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto;
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.event-row__icon.is-handover { background: var(--ice-100); color: var(--brand); }
|
||||
.event-row__icon.is-return { background: var(--amber-soft); color: var(--amber); }
|
||||
.event-row__date { width: 120px; flex: 0 0 auto; line-height: 1.2; }
|
||||
.event-row__date strong { display: block; font-size: .82rem; color: var(--ink); }
|
||||
.event-row__date span { font-size: .72rem; color: var(--muted); }
|
||||
.event-row__date .is-today { color: var(--brand); font-weight: 700; }
|
||||
.event-row__main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
|
||||
.event-row__main strong { font-size: .88rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.event-row__main span { font-size: .76rem; color: var(--muted); }
|
||||
|
||||
.panel--reminders .mini-reminders { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
|
||||
.mini-reminder { border: 1px solid var(--line-soft); background: var(--ice-50); border-radius: 11px; padding: 10px 11px; }
|
||||
.mini-reminder.is-overdue { border-color: #f0c4be; background: var(--red-soft); }
|
||||
.mini-reminder__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
|
||||
.mini-reminder__date { font-size: .74rem; font-weight: 700; color: var(--ink); }
|
||||
.mini-reminder > strong { font-size: .84rem; color: var(--ink); display: block; }
|
||||
.mini-reminder p { font-size: .77rem; color: var(--muted); margin-top: 2px; }
|
||||
.mini-reminder__meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 7px; font-size: .72rem; color: var(--muted); }
|
||||
.mini-reminder__actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
|
||||
.mini-reminder__actions a { font-size: .76rem; font-weight: 600; }
|
||||
.mini-reminder__actions form { margin: 0; }
|
||||
.panel--quick { display: grid; gap: 4px; }
|
||||
.panel--quick h2 { margin-bottom: 8px; }
|
||||
.quick-link { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-top: 1px solid var(--line-soft); border-radius: 8px; }
|
||||
.quick-link:first-of-type { border-top: 0; }
|
||||
.quick-link:hover { background: var(--ice-50); }
|
||||
.quick-link__icon { width: 34px; height: 34px; border-radius: 9px; background: var(--ice-100); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
|
||||
.quick-link__icon .ico { width: 17px; height: 17px; }
|
||||
.quick-link > span:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
|
||||
.quick-link strong { font-size: .84rem; color: var(--ink); }
|
||||
.quick-link small { font-size: .72rem; color: var(--muted); }
|
||||
.quick-link .chev { margin-left: auto; width: 15px; height: 15px; color: var(--muted); }
|
||||
|
||||
/* --------------------------------------------------------------- Calendar */
|
||||
.cal-toolbar {
|
||||
display: flex; align-items: center; justify-content: space-between; gap: 10px;
|
||||
flex-wrap: wrap; padding: 9px 10px; margin-bottom: 12px;
|
||||
background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm);
|
||||
}
|
||||
.cal-toolbar__left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
||||
.segmented { display: inline-flex; padding: 3px; background: var(--ice-50); border: 1px solid var(--line-soft); border-radius: 10px; gap: 2px; }
|
||||
.segmented a {
|
||||
padding: 6px 13px; border-radius: 8px; font-size: .82rem; font-weight: 600; color: var(--ink-2);
|
||||
}
|
||||
.segmented a:hover { color: var(--brand-700); }
|
||||
.segmented a.is-active { background: #fff; color: var(--brand-700); box-shadow: 0 1px 3px rgba(10, 44, 78, .12); }
|
||||
.cal-nav { display: flex; align-items: center; gap: 5px; }
|
||||
.date-jump { display: flex; align-items: center; gap: 5px; margin-left: 3px; }
|
||||
.date-jump input[type="date"] {
|
||||
height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: .8rem;
|
||||
}
|
||||
.cal-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }
|
||||
.inline-field { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted); }
|
||||
.inline-field select {
|
||||
height: 32px; padding: 0 26px 0 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: .8rem; color: var(--ink-2);
|
||||
}
|
||||
.cal-filters__submit { display: inline-flex; }
|
||||
.check { display: inline-flex; align-items: flex-start; gap: 8px; font-size: .86rem; color: var(--ink-2); cursor: pointer; }
|
||||
.check input,
|
||||
.check input[type="checkbox"],
|
||||
.check input[type="radio"],
|
||||
.field .check input {
|
||||
width: 16px; height: 16px; min-width: 16px; min-height: 16px;
|
||||
margin: 2px 0 0; padding: 0; flex: 0 0 auto;
|
||||
accent-color: var(--brand); box-shadow: none; border-radius: 3px;
|
||||
}
|
||||
.check--small { font-size: .78rem; }
|
||||
.check--boxed { display: flex; align-items: flex-start; width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--ice-50); }
|
||||
.check--boxed .check span { font-weight: 500; }
|
||||
|
||||
.cal-scroll-hint {
|
||||
display: none; align-items: center; gap: 6px; margin: -2px 0 10px;
|
||||
color: var(--muted); font-size: .76rem;
|
||||
}
|
||||
.cal-scroll-hint .ico { width: 14px; height: 14px; }
|
||||
|
||||
.cal-shell { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
|
||||
.cal-scroll { overflow-x: auto; overflow-y: hidden; }
|
||||
.cal { --lane: 150px; display: grid; grid-template-columns: var(--lane) minmax(0, 1fr); }
|
||||
.cal-corner {
|
||||
position: sticky; left: 0; z-index: 6; background: #fff;
|
||||
border-bottom: 1px solid var(--line); padding: 10px 12px;
|
||||
display: flex; flex-direction: column; justify-content: center;
|
||||
}
|
||||
.cal-corner__title { font-family: var(--font-display); font-weight: 800; font-size: .86rem; color: var(--ink); }
|
||||
.cal-corner__hint { font-size: .67rem; color: var(--muted); margin-top: 1px; }
|
||||
.cal-head {
|
||||
display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
|
||||
border-bottom: 1px solid var(--line); background: #fff;
|
||||
}
|
||||
.cal-head__day {
|
||||
padding: 8px 4px 7px; text-align: center; border-left: 1px solid var(--line-soft);
|
||||
display: flex; flex-direction: column; align-items: center; line-height: 1.1; min-width: 0;
|
||||
}
|
||||
.cal-head__weekday { font-size: .64rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
|
||||
.cal-head__num { font-family: var(--font-display); font-size: 1rem; font-weight: 800; color: var(--ink); margin-top: 2px; }
|
||||
.cal-head__month { font-size: .6rem; color: var(--muted); margin-top: 1px; white-space: nowrap; }
|
||||
.cal-head__day.is-weekend { background: #fbfdff; }
|
||||
.cal-head__day.is-today { background: var(--ice-100); }
|
||||
.cal-head__day.is-today .cal-head__num, .cal-head__day.is-today .cal-head__weekday { color: var(--brand-700); }
|
||||
|
||||
.cal-label {
|
||||
position: sticky; left: 0; z-index: 5; background: #fff;
|
||||
height: var(--row-h); border-top: 1px solid var(--line);
|
||||
display: flex; align-items: center; gap: 9px; padding: 0 12px;
|
||||
}
|
||||
.cal-label__text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
|
||||
.cal-label__text strong { font-size: .85rem; color: var(--ink); }
|
||||
.cal-label__text small { font-size: .68rem; color: var(--muted); }
|
||||
.cal-label__add {
|
||||
margin-left: auto; width: 23px; height: 23px; border-radius: 6px;
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
color: var(--brand); font-size: 1rem; font-weight: 700; line-height: 1;
|
||||
opacity: 0; transition: opacity .15s, background .15s;
|
||||
}
|
||||
.cal-label:hover .cal-label__add { opacity: 1; }
|
||||
.cal-label__add:hover { background: var(--ice-100); }
|
||||
.cal-track { position: relative; height: var(--row-h); border-top: 1px solid var(--line); min-width: 0; }
|
||||
.cal-cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
|
||||
.cal-cell { border-left: 1px solid var(--line-soft); background: #fff; transition: background .12s; }
|
||||
.cal-cell:hover { background: #f2f8ff; }
|
||||
.cal-cell.is-weekend { background: #fbfdff; }
|
||||
.cal-cell.is-weekend:hover { background: #f1f8ff; }
|
||||
.cal-cell.is-today { background: rgba(230, 241, 252, .5); }
|
||||
.cal-cell.is-today:hover { background: rgba(211, 230, 249, .7); }
|
||||
.cal-track.is-drop-target { background: rgba(25, 106, 188, .06); }
|
||||
|
||||
.cal-bar {
|
||||
position: absolute; z-index: 2; display: flex; flex-direction: column; justify-content: center;
|
||||
left: calc(var(--left) + 2px); width: calc(var(--width) - 4px);
|
||||
top: calc(var(--top) + 3px); height: calc(var(--height) - 6px);
|
||||
background: var(--bar); color: var(--bar-text);
|
||||
border-radius: 7px; padding: 3px 8px; min-width: 3px; overflow: hidden;
|
||||
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06), 0 1px 2px rgba(10, 44, 78, .12);
|
||||
transition: filter .12s, box-shadow .12s, transform .12s;
|
||||
touch-action: pan-y;
|
||||
user-select: none;
|
||||
-webkit-user-drag: none;
|
||||
}
|
||||
.cal-bar:hover { filter: brightness(1.05); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08), 0 4px 10px rgba(10, 44, 78, .18); color: var(--bar-text); z-index: 3; }
|
||||
.cal-bar.is-cut-start { border-top-left-radius: 2px; border-bottom-left-radius: 2px; }
|
||||
.cal-bar.is-cut-end { border-top-right-radius: 2px; border-bottom-right-radius: 2px; }
|
||||
.cal-bar.is-tiny { padding: 2px 5px; }
|
||||
.cal-bar.is-tiny .cal-bar__name { font-size: .68rem; }
|
||||
.cal-bar.is-cancelled {
|
||||
opacity: .58;
|
||||
background:
|
||||
repeating-linear-gradient(135deg, rgba(255, 255, 255, .22) 0 5px, rgba(255, 255, 255, 0) 5px 10px),
|
||||
var(--bar);
|
||||
}
|
||||
.cal-bar.is-cancelled .cal-bar__name { text-decoration: line-through; }
|
||||
.cal-bar.is-dragging { z-index: 50; opacity: .88; filter: brightness(1.06); cursor: grabbing; box-shadow: 0 10px 20px rgba(10, 44, 78, .3); transition: none; }
|
||||
.cal-bar__name { font-size: .76rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
|
||||
.cal-bar__meta { font-size: .63rem; font-weight: 500; opacity: .88; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25; }
|
||||
.cal-bar__meta--soft { opacity: .72; }
|
||||
.cal-bar__flag { font-size: .58rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; opacity: .9; }
|
||||
.cal-foot { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 12px 4px 0; color: var(--muted); font-size: .76rem; }
|
||||
.cal-foot p { display: flex; align-items: center; gap: 7px; max-width: 90ch; }
|
||||
.cal-foot__hint { font-style: italic; }
|
||||
.legend-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--brand); flex: 0 0 auto; }
|
||||
|
||||
/* --------------------------------------------------------------- Forms */
|
||||
.booking-form { margin: 0; }
|
||||
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
|
||||
.form-main { display: grid; gap: 16px; min-width: 0; }
|
||||
.form-side { display: grid; gap: 16px; position: sticky; top: calc(var(--topbar-h) + 16px); }
|
||||
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
|
||||
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
|
||||
.field--wide { grid-column: 1 / -1; }
|
||||
.field > span, .field > label > span { font-size: .8rem; font-weight: 600; color: var(--ink-2); }
|
||||
.field input, .field select, .field textarea {
|
||||
width: 100%; height: 42px; padding: 0 11px;
|
||||
border: 1px solid var(--line); border-radius: 9px; background: #fff;
|
||||
font-size: .9rem; outline: none; color: var(--ink);
|
||||
transition: border-color .15s, box-shadow .15s;
|
||||
}
|
||||
.field textarea { height: auto; min-height: 90px; padding: 10px 11px; resize: vertical; }
|
||||
.field input:focus, .field select:focus, .field textarea:focus {
|
||||
border-color: var(--brand); box-shadow: 0 0 0 3px rgba(25, 106, 188, .12);
|
||||
}
|
||||
.field input::placeholder { color: #98a8b4; }
|
||||
.field.has-error input, .field.has-error select { border-color: #d26a5f; background: #fffafa; }
|
||||
.field-error { font-size: .75rem; color: #a43227; font-style: normal; }
|
||||
.field--trailer-preview { justify-content: flex-start; }
|
||||
.trailer-preview { display: inline-flex; align-items: center; gap: 7px; width: fit-content; padding: 9px 11px; border-radius: 9px; background: var(--ice-50); border: 1px solid var(--line-soft); font-size: .82rem; }
|
||||
.money-input { position: relative; display: flex; align-items: center; }
|
||||
.money-input input { padding-right: 30px; }
|
||||
.money-input > span { position: absolute; right: 11px; color: var(--muted); font-size: .84rem; pointer-events: none; }
|
||||
.due-output {
|
||||
height: 42px; display: flex; align-items: center; padding: 0 11px;
|
||||
background: var(--ice-50); border: 1px solid var(--ice-200); border-radius: 9px;
|
||||
font-family: var(--font-display); font-weight: 800; color: var(--brand-700); font-size: 1.05rem;
|
||||
}
|
||||
.segmented-radio { display: inline-flex; padding: 3px; background: var(--ice-50); border: 1px solid var(--line-soft); border-radius: 10px; gap: 2px; width: fit-content; }
|
||||
.segmented-radio label { position: relative; cursor: pointer; }
|
||||
.segmented-radio input { position: absolute; opacity: 0; pointer-events: none; }
|
||||
.segmented-radio span { display: inline-flex; align-items: center; justify-content: center; min-width: 64px; padding: 7px 13px; border-radius: 8px; font-size: .82rem; font-weight: 600; color: var(--ink-2); }
|
||||
.segmented-radio input:checked + span { background: #fff; color: var(--brand-700); box-shadow: 0 1px 3px rgba(10, 44, 78, .14); }
|
||||
.segmented-radio input:focus-visible + span { outline: 3px solid rgba(25, 106, 188, .25); }
|
||||
.conflict-hint { display: flex; gap: 8px; padding: 10px 12px; border-radius: 9px; background: var(--red-soft); border: 1px solid #f0c4be; color: #7d241b; font-size: .82rem; }
|
||||
.conflict-hint.is-ok { background: var(--green-soft); border-color: #bfe3bf; color: #1f5a23; }
|
||||
.conflict-hint[hidden] { display: none; }
|
||||
.form-actions { display: grid; gap: 8px; margin-top: 16px; }
|
||||
.card--summary { background: linear-gradient(180deg, #fff, #fbfdff); }
|
||||
.summary-list, .meta-list, .money-list { margin: 0; display: grid; gap: 0; }
|
||||
.summary-list > div, .meta-list > div, .money-list > div {
|
||||
display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
|
||||
padding: 8px 0; border-bottom: 1px solid var(--line-soft);
|
||||
}
|
||||
.summary-list > div:last-child, .meta-list > div:last-child, .money-list > div:last-child { border-bottom: 0; }
|
||||
.summary-list dt, .meta-list dt, .money-list dt { font-size: .78rem; color: var(--muted); }
|
||||
.summary-list dd, .meta-list dd, .money-list dd { margin: 0; font-size: .84rem; font-weight: 600; color: var(--ink); text-align: right; display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
|
||||
.summary-list .is-strong dd, .money-list .is-strong dd { color: var(--brand-700); font-family: var(--font-display); font-size: 1rem; font-weight: 800; }
|
||||
.card--danger { margin-top: 16px; border-color: #efc9c4; background: #fffdfd; }
|
||||
.danger-actions { display: flex; gap: 10px; flex-wrap: wrap; }
|
||||
.danger-actions form { margin: 0; }
|
||||
|
||||
/* --------------------------------------------------------------- Detail */
|
||||
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 16px; align-items: start; }
|
||||
.detail-main, .detail-side { display: grid; gap: 16px; min-width: 0; }
|
||||
.detail-side { position: sticky; top: calc(var(--topbar-h) + 16px); }
|
||||
.detail-meta { margin: 0; }
|
||||
.card--copy { overflow: hidden; }
|
||||
.copy-source { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
|
||||
.copy-list { margin: 0; display: grid; grid-template-columns: 1fr; gap: 0; border-top: 1px solid var(--line-soft); }
|
||||
.copy-list__row { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 14px; padding: 9px 2px; border-bottom: 1px solid var(--line-soft); }
|
||||
.copy-list__row:last-child { border-bottom: 0; }
|
||||
.copy-list dt { margin: 0; font-size: .78rem; font-weight: 600; color: var(--muted); }
|
||||
.copy-list dd { margin: 0; font-size: .9rem; color: var(--ink); word-break: break-word; }
|
||||
.copy-list__row.is-strong dd { color: var(--brand-700); font-weight: 800; font-family: var(--font-display); }
|
||||
.copy-list--compact .copy-list__row { padding: 6px 0; grid-template-columns: 130px 1fr; }
|
||||
.copy-list--compact dd { font-size: .84rem; }
|
||||
.copy-hint { display: flex; align-items: center; gap: 6px; margin-top: 12px; color: var(--muted); font-size: .76rem; }
|
||||
.copy-hint .ico { width: 14px; height: 14px; color: var(--green); }
|
||||
|
||||
.reminder-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
||||
.reminder-row {
|
||||
display: flex; align-items: flex-start; gap: 14px;
|
||||
padding: 12px; border: 1px solid var(--line-soft); border-radius: 11px; background: #fff;
|
||||
}
|
||||
.reminder-row.is-overdue { border-color: #f0c4be; background: #fffafa; }
|
||||
.reminder-row.is-done { opacity: .62; background: var(--ice-50); }
|
||||
.reminder-row__date { width: 90px; flex: 0 0 auto; display: flex; flex-direction: column; line-height: 1.2; }
|
||||
.reminder-row__date strong { font-size: .82rem; color: var(--ink); }
|
||||
.reminder-row__date span { font-size: .7rem; color: var(--muted); }
|
||||
.reminder-row.is-overdue .reminder-row__date span { color: #a43227; font-weight: 700; }
|
||||
.reminder-row__body { flex: 1; min-width: 0; }
|
||||
.reminder-row__body strong { font-size: .86rem; color: var(--ink); }
|
||||
.reminder-row__body p { font-size: .8rem; color: var(--muted); margin-top: 2px; }
|
||||
.reminder-row__action { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
|
||||
.reminder-row__action form { margin: 0; }
|
||||
|
||||
/* --------------------------------------------------------------- Panel dialog */
|
||||
.booking-dialog {
|
||||
width: min(720px, calc(100vw - 28px)); max-height: min(90vh, 900px);
|
||||
padding: 0; border: 0; border-radius: var(--radius-xl);
|
||||
background: #fff; box-shadow: var(--shadow-lg); color: var(--ink-2);
|
||||
}
|
||||
.booking-dialog::backdrop { background: rgba(6, 26, 46, .42); backdrop-filter: blur(3px); }
|
||||
.booking-dialog__inner { max-height: min(90vh, 900px); overflow-y: auto; }
|
||||
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 14px; border-bottom: 1px solid var(--line-soft); background: linear-gradient(180deg, var(--ice-50), #fff); }
|
||||
.panel-head__main { min-width: 0; }
|
||||
.panel-head__trailer { display: flex; align-items: center; gap: 7px; font-size: .76rem; font-weight: 700; color: var(--muted); }
|
||||
.panel-head h2 { font-size: 1.35rem; margin: 4px 0 3px; }
|
||||
.panel-head p { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
|
||||
.panel-body { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(220px, .9fr); gap: 18px; padding: 18px 22px; }
|
||||
.panel-copy__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
|
||||
.panel-copy h3 { font-size: .92rem; }
|
||||
.panel-meta .next-reminder { margin-top: 12px; padding: 10px 11px; border-radius: 10px; background: var(--ice-50); border: 1px solid var(--ice-200); }
|
||||
.panel-meta .next-reminder.is-overdue { background: var(--red-soft); border-color: #f0c4be; }
|
||||
.next-reminder > span { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
|
||||
.next-reminder strong { display: block; font-size: .82rem; color: var(--ink); margin-top: 2px; }
|
||||
.next-reminder p { font-size: .76rem; color: var(--muted); }
|
||||
.panel-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 14px 22px; border-top: 1px solid var(--line-soft); background: var(--ice-50); }
|
||||
.panel-actions form { margin: 0; }
|
||||
|
||||
/* --------------------------------------------------------------- Search */
|
||||
.search-hero {
|
||||
display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px;
|
||||
background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm);
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
.search-hero > .ico { width: 21px; height: 21px; color: var(--muted); }
|
||||
.search-hero input { flex: 1; border: 0; outline: none; height: 42px; font-size: 1rem; background: transparent; min-width: 0; }
|
||||
.result-list { list-style: none; margin: 0; padding: 0; }
|
||||
.result-row { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-top: 1px solid var(--line-soft); }
|
||||
.result-row:first-child { border-top: 0; }
|
||||
.result-row.is-cancelled { opacity: .62; }
|
||||
.result-row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
||||
.result-row__main strong { font-size: .9rem; color: var(--ink); }
|
||||
.result-row__main span { font-size: .76rem; color: var(--muted); }
|
||||
.result-row__meta { display: flex; align-items: center; gap: 8px; font-size: .76rem; color: var(--muted); }
|
||||
|
||||
/* --------------------------------------------------------------- Reminders */
|
||||
.reminder-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
|
||||
.reminder-day { margin-bottom: 20px; }
|
||||
.reminder-day__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; padding: 0 2px; }
|
||||
.reminder-day__head h2 { font-size: .98rem; }
|
||||
.reminder-day.is-past .reminder-day__head h2 { color: #7d241b; }
|
||||
.reminder-day__count { margin-left: auto; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 99px; background: var(--ice-100); color: var(--brand-700); font-size: .72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
|
||||
.reminder-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
||||
.reminder-card { display: flex; gap: 14px; align-items: flex-start; padding: 14px 15px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-sm); }
|
||||
.reminder-card.is-overdue { border-color: #efc0ba; background: linear-gradient(180deg, #fff, #fffafa); }
|
||||
.reminder-card.is-done { opacity: .62; background: var(--ice-50); }
|
||||
.reminder-card__main { flex: 1; min-width: 0; }
|
||||
.reminder-card__top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 5px; }
|
||||
.reminder-card__employee { font-size: .75rem; color: var(--muted); margin-left: auto; }
|
||||
.reminder-card__message { font-size: .88rem; color: var(--ink-2); }
|
||||
.reminder-card__booking { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-top: 7px; font-size: .76rem; color: var(--muted); }
|
||||
.reminder-card__booking strong { color: var(--ink); font-size: .8rem; }
|
||||
.reminder-card__actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
|
||||
.reminder-card__actions form { margin: 0; }
|
||||
.reminder-note { display: flex; gap: 10px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--ice-50); border: 1px solid var(--ice-200); color: var(--brand-800); font-size: .82rem; max-width: 900px; }
|
||||
|
||||
/* --------------------------------------------------------------- Admin */
|
||||
.admin-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
|
||||
.admin-nav a { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; font-size: .84rem; font-weight: 600; color: var(--ink-2); }
|
||||
.admin-nav a:hover { background: var(--ice-50); color: var(--brand-700); }
|
||||
.admin-nav a.is-active { background: var(--ice-100); color: var(--brand-700); }
|
||||
.admin-nav .ico { width: 16px; height: 16px; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
.data-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
|
||||
.data-table th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
||||
.data-table td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
|
||||
.data-table tr:last-child td { border-bottom: 0; }
|
||||
.data-table tr:hover td { background: #fbfdff; }
|
||||
.table-person { display: inline-flex; align-items: center; gap: 9px; }
|
||||
.table-person > span:last-child { display: flex; flex-direction: column; line-height: 1.2; }
|
||||
.table-person strong { color: var(--ink); font-size: .85rem; }
|
||||
.table-person small { color: var(--muted); font-size: .72rem; }
|
||||
.admin-split { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 16px; align-items: start; }
|
||||
.trailer-admin { display: grid; gap: 0; border-top: 1px solid var(--line-soft); }
|
||||
.trailer-admin__head, .trailer-admin__row {
|
||||
display: grid; grid-template-columns: 150px minmax(110px, 1fr) minmax(100px, .8fr) 90px 170px;
|
||||
gap: 10px; align-items: center;
|
||||
}
|
||||
.trailer-admin__head { padding: 8px 2px; font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; }
|
||||
.trailer-admin__row { padding: 9px 2px; border-top: 1px solid var(--line-soft); position: relative; }
|
||||
.trailer-admin__row.has-error { background: #fffafa; }
|
||||
.trailer-admin__row input[type="text"], .trailer-admin__row input[type="number"] {
|
||||
height: 38px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; font-size: .84rem;
|
||||
}
|
||||
.trailer-admin__row input[type="number"] { width: 78px; }
|
||||
.trailer-admin__color { display: flex; align-items: center; gap: 7px; }
|
||||
.trailer-admin__color input[type="color"] { width: 38px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
|
||||
.trailer-admin__color .color-hex { width: 82px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .76rem; }
|
||||
.trailer-admin__preview { display: inline-flex; align-items: center; gap: 7px; padding: 7px 9px; border-radius: 8px; background: var(--trailer); color: var(--trailer-text); font-size: .76rem; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
||||
.trailer-admin__row .field-error { grid-column: 1 / -1; }
|
||||
|
||||
/* --------------------------------------------------------------- Account */
|
||||
.account-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
|
||||
|
||||
/* --------------------------------------------------------------- Auth */
|
||||
.auth-page { background: var(--white); margin: 0; }
|
||||
.auth-shell { display: grid; grid-template-columns: 1.05fr .95fr; min-height: 100vh; }
|
||||
.auth-visual { position: relative; overflow: hidden; background: var(--brand-900); }
|
||||
.auth-visual__bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
|
||||
.auth-visual__shade {
|
||||
position: absolute; inset: 0;
|
||||
background: linear-gradient(150deg, rgba(6, 26, 46, .88) 0%, rgba(10, 44, 78, .74) 48%, rgba(25, 106, 188, .42) 100%);
|
||||
}
|
||||
.auth-visual__content { position: relative; z-index: 1; min-height: 100%; display: flex; flex-direction: column; padding: clamp(26px, 4vw, 54px); color: #fff; }
|
||||
.auth-brand { display: flex; align-items: center; gap: 11px; }
|
||||
.auth-brand span { display: flex; flex-direction: column; line-height: 1.05; }
|
||||
.auth-brand strong { font-family: var(--font-display); font-weight: 800; font-size: 1.05rem; }
|
||||
.auth-brand small { font-size: .68rem; letter-spacing: .13em; text-transform: uppercase; opacity: .72; margin-top: 4px; }
|
||||
.auth-visual__claim { margin: auto 0; max-width: 560px; padding: 30px 0; }
|
||||
.auth-visual__claim .eyebrow { color: #9ed2ff; }
|
||||
.auth-visual__claim h2 { color: #fff; font-size: clamp(2.1rem, 4.3vw, 3.8rem); font-weight: 800; letter-spacing: -.035em; line-height: 1.02; margin-bottom: 16px; }
|
||||
.auth-visual__claim > p { color: #d6e8f9; font-size: clamp(.92rem, 1.1vw, 1.02rem); max-width: 44ch; }
|
||||
.auth-points { list-style: none; margin: 24px 0 0; padding: 0; display: grid; gap: 9px; font-size: .88rem; color: #e8f3fd; }
|
||||
.auth-points li { display: flex; align-items: center; gap: 8px; }
|
||||
.auth-points .ico { width: 16px; height: 16px; color: #9ed2ff; }
|
||||
.auth-visual__foot { color: rgba(255, 255, 255, .54); font-size: .75rem; letter-spacing: .02em; }
|
||||
.auth-panel { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: clamp(22px, 4vw, 56px); background: linear-gradient(160deg, #fff 20%, var(--ice-50)); }
|
||||
.auth-card { width: min(420px, 100%); }
|
||||
.auth-card__mobilebrand { display: none; align-items: center; gap: 9px; margin-bottom: 26px; color: var(--ink); font-family: var(--font-display); font-weight: 800; }
|
||||
.auth-card h1 { font-size: 2rem; margin-bottom: 8px; }
|
||||
.auth-card__lede { color: var(--muted); font-size: .9rem; margin-bottom: 22px; }
|
||||
.auth-form { display: grid; gap: 14px; }
|
||||
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.auth-form .field input { height: 46px; background: #fff; }
|
||||
.auth-form .btn { min-height: 46px; margin-top: 2px; }
|
||||
.auth-card__hint { display: flex; gap: 9px; align-items: flex-start; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: .76rem; line-height: 1.5; }
|
||||
.auth-card__hint .ico { width: 17px; height: 17px; color: var(--brand); margin-top: 1px; }
|
||||
.auth-foot { position: absolute; bottom: 22px; color: #8a9aa7; font-size: .72rem; }
|
||||
.auth-panel { position: relative; }
|
||||
.auth-panel .flash { margin-bottom: 16px; }
|
||||
|
||||
/* --------------------------------------------------------------- Toast */
|
||||
.toast {
|
||||
position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
|
||||
z-index: 100; max-width: min(460px, calc(100vw - 32px));
|
||||
padding: 11px 16px; border-radius: 11px;
|
||||
background: var(--brand-900); color: #fff; font-size: .86rem;
|
||||
box-shadow: var(--shadow-lg);
|
||||
}
|
||||
.toast.is-error { background: #7d241b; }
|
||||
|
||||
/* --------------------------------------------------------------- Error page */
|
||||
.error-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
|
||||
.error-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-xl); box-shadow: var(--shadow); padding: 38px; max-width: 460px; text-align: center; }
|
||||
.error-card img { margin: 0 auto 14px; }
|
||||
.error-card h1 { margin-bottom: 8px; }
|
||||
.error-card p { color: var(--muted); margin-bottom: 18px; }
|
||||
|
||||
/* --------------------------------------------------------------- Responsive */
|
||||
@media (max-width: 1240px) {
|
||||
.dash-grid { grid-template-columns: 1fr; }
|
||||
.dash-side { grid-template-columns: 1fr 1fr; align-items: start; }
|
||||
.form-layout { grid-template-columns: 1fr; }
|
||||
.form-side { position: static; }
|
||||
.detail-grid { grid-template-columns: 1fr; }
|
||||
.detail-side { position: static; grid-template-columns: 1fr 1fr; align-items: start; }
|
||||
.detail-side > .detail-meta { grid-column: 1 / -1; }
|
||||
.admin-split { grid-template-columns: 1fr; }
|
||||
}
|
||||
@media (max-width: 1080px) {
|
||||
.global-search input { width: 150px; }
|
||||
.mainnav a span { font-size: .82rem; }
|
||||
.kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.account-grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
@media (max-width: 960px) {
|
||||
.topbar__inner { flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; gap: 8px 16px; }
|
||||
.brand { order: 1; }
|
||||
.topbar__tools { order: 2; margin-left: auto; }
|
||||
.mainnav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; gap: 0; }
|
||||
.mainnav::-webkit-scrollbar { display: none; }
|
||||
.mainnav a { padding: 9px 10px; gap: 6px; }
|
||||
.nav-long { display: none; }
|
||||
.nav-short { display: inline; }
|
||||
.global-search { display: none; }
|
||||
.dash-side { grid-template-columns: 1fr; }
|
||||
.detail-side { grid-template-columns: 1fr; }
|
||||
.info-grid { grid-template-columns: 1fr; }
|
||||
.auth-shell { grid-template-columns: 1fr; }
|
||||
.auth-visual { display: none; }
|
||||
.auth-card__mobilebrand { display: inline-flex; }
|
||||
.auth-panel { min-height: 100vh; }
|
||||
.auth-foot { position: static; margin-top: 28px; }
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.cal { --lane: 112px; }
|
||||
.cal-label { padding: 0 9px; gap: 7px; }
|
||||
.cal-label__text strong { font-size: .8rem; }
|
||||
.cal-label__text small { font-size: .64rem; }
|
||||
.cal-label__add { display: none; }
|
||||
.cal-head__weekday { font-size: .6rem; }
|
||||
.cal-head__num { font-size: .92rem; }
|
||||
.trailer-grid { grid-template-columns: 1fr; }
|
||||
.event-row__date { width: 98px; }
|
||||
.event-row .btn { display: none; }
|
||||
.form-grid { grid-template-columns: 1fr; }
|
||||
.field--wide { grid-column: auto; }
|
||||
.panel, .card { padding: 16px; }
|
||||
.page { padding-bottom: 70px; }
|
||||
.reminder-card { flex-direction: column; }
|
||||
.reminder-card__actions { width: 100%; justify-content: flex-end; }
|
||||
.reminder-card__employee { margin-left: 0; }
|
||||
.copy-list__row { grid-template-columns: 120px 1fr; }
|
||||
.panel-body { grid-template-columns: 1fr; }
|
||||
.booking-dialog { width: 100%; max-width: none; margin: auto 0 0; border-radius: 20px 20px 0 0; }
|
||||
.booking-dialog__inner { max-height: 88vh; }
|
||||
.trailer-admin__head { display: none; }
|
||||
.trailer-admin__row { grid-template-columns: 1fr 1fr; gap: 8px; padding: 14px 0; }
|
||||
.trailer-admin__row .trailer-admin__color { grid-column: 1 / -1; }
|
||||
.trailer-admin__row .trailer-admin__preview { grid-column: 1 / -1; }
|
||||
.trailer-admin__row input[type="number"] { width: 100%; }
|
||||
.admin-nav { overflow-x: auto; flex-wrap: nowrap; }
|
||||
.admin-nav a { flex: 0 0 auto; }
|
||||
.panel-head { padding: 16px 16px 12px; }
|
||||
.panel-head h2 { font-size: 1.15rem; }
|
||||
.panel-body { padding: 14px 16px; }
|
||||
.panel-actions { padding: 12px 16px; }
|
||||
.reminder-toolbar { align-items: flex-start; flex-direction: column; }
|
||||
.cal-toolbar { align-items: flex-start; }
|
||||
.cal-toolbar__left { width: 100%; justify-content: space-between; }
|
||||
.cal-filters { width: 100%; justify-content: flex-end; }
|
||||
.cal-scroll-hint { display: inline-flex; }
|
||||
.date-jump input[type="date"] { width: 124px; }
|
||||
.reminder-row { flex-wrap: wrap; }
|
||||
.reminder-row__action { margin-left: auto; }
|
||||
}
|
||||
@media (max-width: 520px) {
|
||||
.mainnav a { padding: 8px 5px; gap: 4px; font-size: .75rem; }
|
||||
.mainnav .ico { width: 16px; height: 16px; }
|
||||
.nav-badge { min-width: 17px; height: 17px; font-size: .64rem; padding: 0 5px; }
|
||||
.brand__sub { display: none; }
|
||||
.user-menu__name { display: none; }
|
||||
.user-menu summary { padding: 3px; }
|
||||
.page-head__actions { width: 100%; }
|
||||
.page-head__actions .btn { flex: 1; }
|
||||
.page-head__actions form { flex: 1; }
|
||||
.page-head__actions form .btn { width: 100%; }
|
||||
.kpi { padding: 11px 12px; }
|
||||
.kpi strong { font-size: 1.1rem; }
|
||||
.kpi span { font-size: .72rem; }
|
||||
.segmented a { padding: 6px 9px; font-size: .78rem; }
|
||||
.cal-toolbar { padding: 7px; }
|
||||
.date-jump .btn { display: none; }
|
||||
.auth-panel { padding: 20px; }
|
||||
.auth-card h1 { font-size: 1.7rem; }
|
||||
.field-row { grid-template-columns: 1fr; }
|
||||
.result-row__meta { display: none; }
|
||||
.copy-list__row { grid-template-columns: 110px 1fr; gap: 8px; }
|
||||
.footer { flex-direction: column; }
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- Motion + Print */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
|
||||
}
|
||||
@media print {
|
||||
.topbar, .footer, .flash-wrap, .page-head__actions, .cal-toolbar, .cal-foot,
|
||||
.panel-actions, .breadcrumb, .detail-side .card:last-child, .toast, .booking-dialog { display: none !important; }
|
||||
body { background: #fff; }
|
||||
.page { padding: 0; max-width: none; }
|
||||
.card, .panel { box-shadow: none; border-color: #ccc; }
|
||||
.detail-grid { display: block; }
|
||||
.detail-main { display: block; }
|
||||
.card { margin-bottom: 12px; }
|
||||
}
|
||||
485
web/assets/app.js
Normal file
|
|
@ -0,0 +1,485 @@
|
|||
/* Drink it cold – Terminplanung: Interaktionen ohne Framework. */
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
const csrf = document.querySelector('meta[name="csrf-token"]')?.content || '';
|
||||
let toastTimer = 0;
|
||||
|
||||
const toast = (message, isError = false) => {
|
||||
const el = document.getElementById('toast');
|
||||
if (!el) return;
|
||||
el.textContent = message;
|
||||
el.hidden = false;
|
||||
el.classList.toggle('is-error', isError);
|
||||
window.clearTimeout(toastTimer);
|
||||
toastTimer = window.setTimeout(() => { el.hidden = true; }, isError ? 5200 : 3200);
|
||||
};
|
||||
|
||||
try {
|
||||
const storedToast = window.sessionStorage.getItem('dic-toast');
|
||||
if (storedToast) {
|
||||
window.sessionStorage.removeItem('dic-toast');
|
||||
toast(storedToast);
|
||||
}
|
||||
} catch (error) { /* sessionStorage kann blockiert sein */ }
|
||||
|
||||
/* ------------------------------------------------------------- Meldungen */
|
||||
document.addEventListener('click', (event) => {
|
||||
const dismiss = event.target.closest('[data-dismiss]');
|
||||
if (dismiss) {
|
||||
dismiss.closest('.flash')?.remove();
|
||||
}
|
||||
});
|
||||
|
||||
/* --------------------------------------------------------------- Toasts */
|
||||
const flash = document.querySelector('.flash--success');
|
||||
if (flash) {
|
||||
// Server-Flash bleibt sichtbar; kein zusätzlicher Toast nötig.
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------- Formulare */
|
||||
document.addEventListener('change', (event) => {
|
||||
const control = event.target.closest('[data-autosubmit]');
|
||||
if (control) {
|
||||
const form = control.form;
|
||||
if (form) form.submit();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('submit', (event) => {
|
||||
const form = event.target;
|
||||
if (!(form instanceof HTMLFormElement)) return;
|
||||
const message = form.dataset.confirm;
|
||||
if (message && !window.confirm(message)) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
const submitter = event.submitter;
|
||||
if (submitter && !submitter.disabled) {
|
||||
window.setTimeout(() => { submitter.disabled = true; }, 30);
|
||||
}
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------- Kopieren */
|
||||
const copyToClipboard = async (text) => {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return;
|
||||
}
|
||||
const helper = document.createElement('textarea');
|
||||
helper.value = text;
|
||||
helper.setAttribute('readonly', '');
|
||||
helper.style.position = 'fixed';
|
||||
helper.style.left = '-9999px';
|
||||
document.body.appendChild(helper);
|
||||
helper.select();
|
||||
document.execCommand('copy');
|
||||
helper.remove();
|
||||
};
|
||||
|
||||
document.addEventListener('click', async (event) => {
|
||||
const button = event.target.closest('[data-copy]');
|
||||
if (!button) return;
|
||||
const wrap = button.closest('[data-copy-wrap]');
|
||||
const source = wrap?.querySelector('.copy-source');
|
||||
if (!source) return;
|
||||
try {
|
||||
await copyToClipboard(source.value);
|
||||
toast('Buchungstext kopiert.');
|
||||
const original = button.innerHTML;
|
||||
button.innerHTML = '<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Kopiert';
|
||||
window.setTimeout(() => { button.innerHTML = original; }, 1800);
|
||||
} catch (error) {
|
||||
toast('Kopieren nicht möglich. Bitte den Text markieren und manuell kopieren.', true);
|
||||
}
|
||||
});
|
||||
|
||||
/* --------------------------------------------------------- Buchungsdialog */
|
||||
const dialog = document.getElementById('booking-dialog');
|
||||
const dialogContent = document.getElementById('booking-dialog-content');
|
||||
|
||||
const closeDialog = () => {
|
||||
if (dialog?.open) dialog.close();
|
||||
};
|
||||
|
||||
document.addEventListener('click', async (event) => {
|
||||
const trigger = event.target.closest('a[data-panel]');
|
||||
if (!trigger || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
||||
if (!dialog || !dialogContent || typeof dialog.showModal !== 'function') return;
|
||||
event.preventDefault();
|
||||
const id = trigger.dataset.panel;
|
||||
try {
|
||||
const response = await fetch(trigger.href.replace(/\/?$/, '') + '/panel', {
|
||||
headers: { 'Accept': 'text/html', 'X-Requested-With': 'fetch' },
|
||||
credentials: 'same-origin'
|
||||
});
|
||||
if (!response.ok || response.url.includes('/login')) {
|
||||
window.location.href = trigger.href;
|
||||
return;
|
||||
}
|
||||
dialogContent.innerHTML = await response.text();
|
||||
dialog.showModal();
|
||||
dialogContent.querySelector('[data-close-dialog]')?.focus();
|
||||
} catch (error) {
|
||||
window.location.href = trigger.href;
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
if (event.target.closest('[data-close-dialog]')) closeDialog();
|
||||
});
|
||||
|
||||
if (dialog) {
|
||||
dialog.addEventListener('click', (event) => {
|
||||
if (event.target === dialog) closeDialog();
|
||||
});
|
||||
dialog.addEventListener('close', () => {
|
||||
if (dialogContent) dialogContent.innerHTML = '';
|
||||
});
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------- Nutzermenü */
|
||||
document.addEventListener('click', (event) => {
|
||||
document.querySelectorAll('details.user-menu[open]').forEach((menu) => {
|
||||
if (!menu.contains(event.target)) menu.removeAttribute('open');
|
||||
});
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ Buchungsformular */
|
||||
const bookingForm = document.querySelector('[data-booking-form]');
|
||||
if (bookingForm) {
|
||||
const trailerSelect = bookingForm.querySelector('[data-trailer-select]');
|
||||
const employeeSelect = bookingForm.querySelector('select[name="employee_id"]');
|
||||
const startInput = bookingForm.querySelector('[data-date-start]');
|
||||
const endInput = bookingForm.querySelector('[data-date-end]');
|
||||
const depositInput = bookingForm.querySelector('[data-money="deposit"]');
|
||||
const totalInput = bookingForm.querySelector('[data-money="total"]');
|
||||
const dueOutput = bookingForm.querySelector('[data-due]');
|
||||
const conflictBox = bookingForm.querySelector('[data-conflict]');
|
||||
const availabilityUrl = bookingForm.dataset.availabilityUrl;
|
||||
const excludeId = bookingForm.dataset.exclude || '0';
|
||||
|
||||
const parseMoney = (value) => {
|
||||
let text = String(value || '').replace(/[^\d,.\-]/g, '');
|
||||
if (text.includes(',')) {
|
||||
text = text.replace(/\./g, '').replace(',', '.');
|
||||
} else if (/^\d{1,3}(\.\d{3})+$/.test(text)) {
|
||||
text = text.replace(/\./g, '');
|
||||
}
|
||||
const number = Number.parseFloat(text || '0');
|
||||
return Number.isFinite(number) ? Math.round(number * 100) : 0;
|
||||
};
|
||||
const formatMoney = (cents) => {
|
||||
return (cents / 100).toLocaleString('de-DE', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) + ' €';
|
||||
};
|
||||
const formatDate = (iso) => {
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(iso)) return '–';
|
||||
const [y, m, d] = iso.split('-');
|
||||
return `${d}.${m}.${y}`;
|
||||
};
|
||||
const formatRange = (a, b) => {
|
||||
if (!a || !b) return '–';
|
||||
return a === b ? formatDate(a) : `${formatDate(a)} – ${formatDate(b)}`;
|
||||
};
|
||||
const contrast = (hex) => {
|
||||
const clean = String(hex || '').replace('#', '');
|
||||
if (clean.length !== 6) return '#ffffff';
|
||||
const channels = [0, 2, 4].map((i) => {
|
||||
const c = Number.parseInt(clean.slice(i, i + 2), 16) / 255;
|
||||
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
||||
});
|
||||
const luminance = 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2];
|
||||
return luminance > 0.46 ? '#10202c' : '#ffffff';
|
||||
};
|
||||
|
||||
const updateTrailer = () => {
|
||||
if (!trailerSelect) return;
|
||||
const option = trailerSelect.selectedOptions[0];
|
||||
if (!option) return;
|
||||
const color = option.dataset.color || '#196abc';
|
||||
const name = option.dataset.colorName || '';
|
||||
const label = option.textContent.split('·')[0].trim();
|
||||
const preview = bookingForm.querySelector('[data-trailer-preview]');
|
||||
if (preview) {
|
||||
preview.style.setProperty('--trailer', color);
|
||||
preview.style.setProperty('--trailer-text', contrast(color));
|
||||
const dot = preview.querySelector('.trailer-dot');
|
||||
if (dot) dot.style.setProperty('--trailer', color);
|
||||
const text = preview.querySelector('[data-trailer-preview-label]');
|
||||
if (text) text.textContent = `${label} · ${name}`;
|
||||
}
|
||||
const summary = bookingForm.querySelector('[data-summary-trailer]');
|
||||
if (summary) summary.textContent = label;
|
||||
};
|
||||
|
||||
const updateTotals = () => {
|
||||
const deposit = parseMoney(depositInput?.value);
|
||||
const total = parseMoney(totalInput?.value);
|
||||
const due = total - deposit;
|
||||
if (dueOutput) dueOutput.textContent = formatMoney(due);
|
||||
const totalSummary = bookingForm.querySelector('[data-summary-total]');
|
||||
const depositSummary = bookingForm.querySelector('[data-summary-deposit]');
|
||||
const dueSummary = bookingForm.querySelector('[data-summary-due]');
|
||||
if (totalSummary) totalSummary.textContent = formatMoney(total);
|
||||
if (depositSummary) depositSummary.textContent = formatMoney(deposit);
|
||||
if (dueSummary) dueSummary.textContent = formatMoney(due);
|
||||
};
|
||||
|
||||
const updateSummary = () => {
|
||||
const dates = bookingForm.querySelector('[data-summary-dates]');
|
||||
if (dates) dates.textContent = formatRange(startInput?.value, endInput?.value);
|
||||
const employee = bookingForm.querySelector('[data-summary-employee]');
|
||||
if (employee && employeeSelect) {
|
||||
employee.textContent = employeeSelect.selectedOptions[0]?.textContent.trim() || '–';
|
||||
}
|
||||
};
|
||||
|
||||
const showConflict = (html, ok = false) => {
|
||||
if (!conflictBox) return;
|
||||
if (!html) {
|
||||
conflictBox.hidden = true;
|
||||
conflictBox.innerHTML = '';
|
||||
conflictBox.classList.remove('is-ok');
|
||||
return;
|
||||
}
|
||||
conflictBox.hidden = false;
|
||||
conflictBox.innerHTML = html;
|
||||
conflictBox.classList.toggle('is-ok', ok);
|
||||
};
|
||||
|
||||
let availabilityTimer = 0;
|
||||
const checkAvailability = () => {
|
||||
if (!availabilityUrl || !trailerSelect || !startInput || !endInput) return;
|
||||
const start = startInput.value;
|
||||
const end = endInput.value;
|
||||
if (!start || !end || end < start) {
|
||||
showConflict('');
|
||||
return;
|
||||
}
|
||||
window.clearTimeout(availabilityTimer);
|
||||
availabilityTimer = window.setTimeout(async () => {
|
||||
const params = new URLSearchParams({
|
||||
trailer: trailerSelect.value,
|
||||
start,
|
||||
end,
|
||||
exclude: excludeId
|
||||
});
|
||||
try {
|
||||
const response = await fetch(`${availabilityUrl}?${params.toString()}`, {
|
||||
headers: { 'Accept': 'application/json', 'X-Requested-With': 'fetch' },
|
||||
credentials: 'same-origin'
|
||||
});
|
||||
if (!response.ok) {
|
||||
showConflict('');
|
||||
return;
|
||||
}
|
||||
const data = await response.json();
|
||||
if (data.ok) {
|
||||
showConflict('<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg><span>Der Zeitraum ist für diesen Anhänger frei.</span>', true);
|
||||
return;
|
||||
}
|
||||
const conflict = data.conflicts && data.conflicts[0];
|
||||
if (conflict) {
|
||||
showConflict(`<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg><span>Belegt: ${formatDate(conflict.start)} – ${formatDate(conflict.end)} (${conflict.customer}). Ein Wechseltag ist erlaubt.</span>`);
|
||||
} else {
|
||||
showConflict('');
|
||||
}
|
||||
} catch (error) {
|
||||
showConflict('');
|
||||
}
|
||||
}, 320);
|
||||
};
|
||||
|
||||
trailerSelect?.addEventListener('change', () => { updateTrailer(); checkAvailability(); });
|
||||
employeeSelect?.addEventListener('change', updateSummary);
|
||||
startInput?.addEventListener('change', () => {
|
||||
if (endInput && endInput.value && endInput.value < startInput.value) {
|
||||
endInput.value = startInput.value;
|
||||
}
|
||||
updateSummary();
|
||||
checkAvailability();
|
||||
});
|
||||
endInput?.addEventListener('change', () => { updateSummary(); checkAvailability(); });
|
||||
depositInput?.addEventListener('input', updateTotals);
|
||||
totalInput?.addEventListener('input', updateTotals);
|
||||
|
||||
updateTrailer();
|
||||
updateTotals();
|
||||
updateSummary();
|
||||
if (startInput?.value && endInput?.value) checkAvailability();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------- Kalender: Ziehen */
|
||||
const calendar = document.querySelector('.cal-shell');
|
||||
if (calendar && window.matchMedia('(pointer: fine)').matches) {
|
||||
let drag = null;
|
||||
let suppressClick = false;
|
||||
|
||||
const addDays = (iso, days) => {
|
||||
const date = new Date(`${iso}T12:00:00Z`);
|
||||
date.setUTCDate(date.getUTCDate() + days);
|
||||
return date.toISOString().slice(0, 10);
|
||||
};
|
||||
|
||||
const resetDrag = () => {
|
||||
if (!drag) return;
|
||||
drag.bar.style.transform = '';
|
||||
drag.bar.classList.remove('is-dragging');
|
||||
drag.target?.classList.remove('is-drop-target');
|
||||
drag = null;
|
||||
};
|
||||
|
||||
calendar.addEventListener('pointerdown', (event) => {
|
||||
if (event.button !== 0) return;
|
||||
const bar = event.target.closest('.cal-bar');
|
||||
if (!bar || bar.classList.contains('is-cancelled')) return;
|
||||
const track = bar.closest('.cal-track');
|
||||
if (!track) return;
|
||||
const cell = track.querySelector('.cal-cell');
|
||||
if (!cell) return;
|
||||
drag = {
|
||||
bar,
|
||||
track,
|
||||
startX: event.clientX,
|
||||
startY: event.clientY,
|
||||
dayWidth: cell.getBoundingClientRect().width || 1,
|
||||
moved: false,
|
||||
target: null,
|
||||
pointerId: event.pointerId
|
||||
};
|
||||
});
|
||||
|
||||
document.addEventListener('pointermove', (event) => {
|
||||
if (!drag || event.pointerId !== drag.pointerId) return;
|
||||
const dx = event.clientX - drag.startX;
|
||||
const dy = event.clientY - drag.startY;
|
||||
if (!drag.moved && Math.abs(dx) > 6 && Math.abs(dx) > Math.abs(dy)) {
|
||||
drag.moved = true;
|
||||
drag.bar.classList.add('is-dragging');
|
||||
drag.bar.style.transform = `translateX(${dx}px)`;
|
||||
} else if (drag.moved) {
|
||||
event.preventDefault();
|
||||
drag.bar.style.transform = `translateX(${dx}px)`;
|
||||
}
|
||||
if (drag.moved) {
|
||||
const hit = document.elementFromPoint(event.clientX, event.clientY)?.closest('.cal-track');
|
||||
if (hit !== drag.target) {
|
||||
drag.target?.classList.remove('is-drop-target');
|
||||
drag.target = hit && hit !== drag.track ? hit : null;
|
||||
drag.target?.classList.add('is-drop-target');
|
||||
}
|
||||
}
|
||||
}, { passive: false });
|
||||
|
||||
document.addEventListener('pointerup', async (event) => {
|
||||
if (!drag || event.pointerId !== drag.pointerId) return;
|
||||
const active = drag;
|
||||
if (!active.moved) {
|
||||
resetDrag();
|
||||
return;
|
||||
}
|
||||
suppressClick = true;
|
||||
window.setTimeout(() => { suppressClick = false; }, 120);
|
||||
|
||||
const dx = event.clientX - active.startX;
|
||||
const shift = Math.round(dx / active.dayWidth);
|
||||
const startDate = active.bar.dataset.startDate;
|
||||
const originalTrailer = active.bar.dataset.trailerId;
|
||||
const targetTrailer = active.target?.dataset.trailerId || originalTrailer;
|
||||
const bookingId = active.bar.dataset.bookingId;
|
||||
|
||||
resetDrag();
|
||||
|
||||
if ((shift === 0 && targetTrailer === originalTrailer) || !bookingId || !startDate) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const body = new URLSearchParams({
|
||||
start_date: addDays(startDate, shift),
|
||||
trailer_id: targetTrailer,
|
||||
_csrf: csrf
|
||||
});
|
||||
const response = await fetch(`/bookings/${bookingId}/move`, {
|
||||
method: 'POST',
|
||||
body,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
||||
'Accept': 'application/json',
|
||||
'X-Requested-With': 'fetch',
|
||||
'X-CSRF-Token': csrf
|
||||
},
|
||||
credentials: 'same-origin'
|
||||
});
|
||||
if (response.url.includes('/login')) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok || !data.ok) {
|
||||
toast(data.error || 'Verschieben nicht möglich.', true);
|
||||
return;
|
||||
}
|
||||
const message = 'Buchung verschoben – Erinnerungen wurden angepasst.';
|
||||
try { window.sessionStorage.setItem('dic-toast', message); } catch (error) { /* ignore */ }
|
||||
toast(message);
|
||||
window.setTimeout(() => window.location.reload(), 500);
|
||||
} catch (error) {
|
||||
toast('Verschieben fehlgeschlagen. Bitte erneut versuchen.', true);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('pointercancel', resetDrag);
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
if (!suppressClick) return;
|
||||
if (event.target.closest('.cal-bar')) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------- Anhängerfarben (Admin) */
|
||||
document.querySelectorAll('[data-color-sync]').forEach((colorInput) => {
|
||||
const row = colorInput.closest('.trailer-admin__row');
|
||||
const textInput = row?.querySelector('[data-color-text]');
|
||||
const preview = row?.querySelector('[data-color-preview]');
|
||||
const dot = preview?.querySelector('.trailer-dot');
|
||||
const labelInput = row?.querySelector('input[name^="label"]');
|
||||
|
||||
const contrast = (hex) => {
|
||||
const clean = String(hex || '').replace('#', '');
|
||||
if (clean.length !== 6) return '#ffffff';
|
||||
const channels = [0, 2, 4].map((i) => {
|
||||
const c = Number.parseInt(clean.slice(i, i + 2), 16) / 255;
|
||||
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
||||
});
|
||||
const luminance = 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2];
|
||||
return luminance > 0.46 ? '#10202c' : '#ffffff';
|
||||
};
|
||||
const apply = (hex) => {
|
||||
if (!/^#[0-9a-fA-F]{6}$/.test(hex) || !preview) return;
|
||||
preview.style.setProperty('--trailer', hex);
|
||||
preview.style.setProperty('--trailer-text', contrast(hex));
|
||||
if (dot) dot.style.setProperty('--trailer', hex);
|
||||
};
|
||||
|
||||
colorInput.addEventListener('input', () => {
|
||||
if (textInput) textInput.value = colorInput.value;
|
||||
apply(colorInput.value);
|
||||
});
|
||||
textInput?.addEventListener('input', () => {
|
||||
const value = textInput.value.startsWith('#') ? textInput.value : `#${textInput.value}`;
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(value)) {
|
||||
colorInput.value = value;
|
||||
apply(value);
|
||||
}
|
||||
});
|
||||
labelInput?.addEventListener('input', () => {
|
||||
if (!preview) return;
|
||||
const textNode = [...preview.childNodes].find((node) => node.nodeType === Node.TEXT_NODE && node.textContent.trim());
|
||||
if (textNode) textNode.textContent = ` ${labelInput.value}`;
|
||||
});
|
||||
});
|
||||
})();
|
||||
4
web/assets/favicon.svg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
||||
<rect width="64" height="64" rx="14" fill="#196abc"/>
|
||||
<g transform="translate(32 32) scale(1.62)"><g fill="none" stroke="#fff" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(0)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(60)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(120)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(180)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(240)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(300)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g></g></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
BIN
web/assets/fonts/inter-latin.woff2
Normal file
BIN
web/assets/fonts/manrope-latin.woff2
Normal file
BIN
web/assets/img/achtung-900.webp
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
web/assets/img/alpen-800.webp
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
web/assets/img/flotte-1400.webp
Normal file
|
After Width: | Height: | Size: 219 KiB |
BIN
web/assets/img/heck-600.webp
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
web/assets/img/hero-1280.webp
Normal file
|
After Width: | Height: | Size: 196 KiB |
BIN
web/assets/img/hero-1920.webp
Normal file
|
After Width: | Height: | Size: 340 KiB |
BIN
web/assets/img/hero-800.webp
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
web/assets/img/innen-560.webp
Normal file
|
After Width: | Height: | Size: 13 KiB |
4
web/assets/logo-mark.svg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 72" role="img" aria-label="Drink it cold">
|
||||
<path d="M50 1.5 L98.5 36 L50 70.5 L1.5 36 Z" fill="#196abc"/>
|
||||
<g transform="translate(50 35.5) scale(1.02)"><g fill="none" stroke="#fff" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><g transform="rotate(0)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(60)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(120)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(180)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(240)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g><g transform="rotate(300)"><path d="M0 -13 V0"/><path d="M0 -4.6 L-3.3 -8"/> <path d="M0 -4.6 L3.3 -8"/><path d="M0 -8.6 L-2.3 -11"/> <path d="M0 -8.6 L2.3 -11"/></g></g></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
20
web/index.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Drink it cold – Front Controller.
|
||||
* Apache leitet alle nicht vorhandenen Dateien über .htaccess hierher.
|
||||
*/
|
||||
|
||||
$appRoot = is_dir(__DIR__ . '/app') ? __DIR__ . '/app' : dirname(__DIR__) . '/app';
|
||||
require $appRoot . '/bootstrap.php';
|
||||
|
||||
$uriPath = (string) parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH);
|
||||
$basePath = rtrim((string) config('app.base_path', ''), '/');
|
||||
if ($basePath !== '' && str_starts_with($uriPath, $basePath)) {
|
||||
$uriPath = substr($uriPath, strlen($basePath));
|
||||
}
|
||||
$path = '/' . trim($uriPath, '/');
|
||||
$method = request_method();
|
||||
|
||||
page_handle($method, $path);
|
||||