Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../lib/auth.php';
|
|
require_once __DIR__ . '/../lib/mail.php';
|
|
require_login();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header('Location: ../pages/urlaubsantrag.php');
|
|
exit;
|
|
}
|
|
|
|
$back = '../pages/urlaubsantrag.php';
|
|
|
|
$von = trim($_POST['von'] ?? '');
|
|
$bis = trim($_POST['bis'] ?? '');
|
|
$vertretung = trim($_POST['vertretung'] ?? '');
|
|
$nachricht = trim($_POST['nachricht'] ?? '');
|
|
|
|
if ($von === '' || $bis === '') {
|
|
header('Location: ' . $back . '?error=' . urlencode('Von und Bis sind Pflichtfelder.'));
|
|
exit;
|
|
}
|
|
|
|
if (!strtotime($von) || !strtotime($bis)) {
|
|
header('Location: ' . $back . '?error=' . urlencode('Ungültiges Datum.'));
|
|
exit;
|
|
}
|
|
|
|
if (strtotime($von) > strtotime($bis)) {
|
|
header('Location: ' . $back . '?error=' . urlencode('Das Startdatum muss vor dem Enddatum liegen.'));
|
|
exit;
|
|
}
|
|
|
|
$user_id = current_user()['id'];
|
|
$now = date('c');
|
|
|
|
db()->prepare(
|
|
'INSERT INTO requests_urlaubsantrag (user_id, status, admin_note, created_at, updated_at, von, bis, vertretung, nachricht)
|
|
VALUES (?, \'pending\', \'\', ?, ?, ?, ?, ?, ?)'
|
|
)->execute([$user_id, $now, $now, $von, $bis, $vertretung, $nachricht]);
|
|
|
|
$config = require __DIR__ . '/../lib/config.php';
|
|
smtp_send(
|
|
$config,
|
|
$config['mail_sabrina'],
|
|
'Neuer Urlaubsantrag: ' . current_name(),
|
|
"Ein Urlaubsantrag wurde eingereicht.\n\n"
|
|
. 'Mitarbeiter: ' . current_name() . "\n"
|
|
. 'Von: ' . $von . "\n"
|
|
. 'Bis: ' . $bis . "\n"
|
|
. 'Vertretung: ' . ($vertretung ?: '—') . "\n"
|
|
. 'Nachricht: ' . ($nachricht ?: '—') . "\n\n"
|
|
. "---\nGesendet über OMSORG Connect"
|
|
);
|
|
|
|
header('Location: ' . $back . '?success=1');
|
|
exit;
|