85 lines
2.2 KiB
PHP
85 lines
2.2 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
require_once 'functions.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
redirect('semesterapparat.php');
|
|
}
|
|
|
|
// Collect form data
|
|
$name = post('name');
|
|
$lastname = post('lastname');
|
|
$title = post('title');
|
|
$telno = post('telno');
|
|
$mail = post('mail');
|
|
$apparatsname = post('apparatsname');
|
|
$subject = post('subject');
|
|
$semester_type = post('semester_type');
|
|
$semester_year = post('semester_year');
|
|
$dauerapparat = isset($_POST['dauerapparat']) ? 'true' : 'false';
|
|
$message = post('message');
|
|
|
|
// Validate required fields
|
|
if (
|
|
empty($name) || empty($lastname) || empty($telno) || empty($mail) ||
|
|
empty($apparatsname) || empty($subject) || empty($semester_type) || empty($semester_year)
|
|
) {
|
|
die('Fehler: Alle Pflichtfelder müssen ausgefüllt werden.');
|
|
}
|
|
|
|
// Validate email
|
|
if (!validateEmail($mail)) {
|
|
die('Fehler: Ungültige E-Mail-Adresse.');
|
|
}
|
|
|
|
// Collect book data
|
|
$authornames = postArray('authorname');
|
|
$years = postArray('year');
|
|
$edition = postArray('edition');
|
|
$booktitles = postArray('booktitle');
|
|
$signatures = postArray('signature');
|
|
|
|
// Validate at least one book
|
|
if (empty($authornames) || count($authornames) === 0) {
|
|
die('Fehler: Mindestens ein Medium muss angegeben werden.');
|
|
}
|
|
|
|
// Build books array
|
|
$books = [];
|
|
for ($i = 0; $i < count($authornames); $i++) {
|
|
$books[] = [
|
|
'authorname' => $authornames[$i] ?? '',
|
|
'year' => $years[$i] ?? '',
|
|
'edition' => $edition[$i] ?? '',
|
|
'title' => $booktitles[$i] ?? '',
|
|
'signature' => $signatures[$i] ?? ''
|
|
];
|
|
}
|
|
|
|
// Prepare data for XML generation
|
|
$data = [
|
|
'name' => $name,
|
|
'lastname' => $lastname,
|
|
'title' => $title,
|
|
'telno' => $telno,
|
|
'mail' => $mail,
|
|
'apparatsname' => $apparatsname,
|
|
'subject' => $subject,
|
|
'semester' => $semester_type . ' ' . $semester_year,
|
|
'dauerapparat' => $dauerapparat,
|
|
'message' => $message,
|
|
'books' => $books
|
|
];
|
|
|
|
// Generate XML
|
|
$xml = generateXML($data);
|
|
|
|
// Send email
|
|
$emailSent = sendEmail('Antrag für neuen Semesterapparat', $xml);
|
|
|
|
if ($emailSent || !MAIL_ENABLED) {
|
|
redirect('index.php?success=true');
|
|
} else {
|
|
die('Fehler: E-Mail konnte nicht gesendet werden. Bitte versuchen Sie es später erneut.');
|
|
}
|