feat: refactor into php for mrbs page
This commit is contained in:
139
php/submit_elsa.php
Normal file
139
php/submit_elsa.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
require_once 'functions.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
redirect('elsa.php');
|
||||
}
|
||||
|
||||
// Collect general information
|
||||
$name = post('name');
|
||||
$lastname = post('lastname');
|
||||
$title = post('title');
|
||||
$mail = post('mail');
|
||||
$subject = post('subject');
|
||||
$classname = post('classname');
|
||||
$usage_date_from = post('usage_date_from');
|
||||
$usage_date_to = post('usage_date_to');
|
||||
$availability_date = post('availability_date');
|
||||
$message = post('message');
|
||||
|
||||
// Validate required fields
|
||||
if (empty($name) || empty($lastname) || empty($mail) || empty($subject) ||
|
||||
empty($classname) || empty($usage_date_from) || empty($usage_date_to) || empty($availability_date)) {
|
||||
die('Fehler: Alle Pflichtfelder müssen ausgefüllt werden.');
|
||||
}
|
||||
|
||||
// Validate email
|
||||
if (!validateEmail($mail)) {
|
||||
die('Fehler: Ungültige E-Mail-Adresse.');
|
||||
}
|
||||
|
||||
// Collect media data
|
||||
$monografien = [];
|
||||
$zeitschriftenartikel = [];
|
||||
$herausgeberwerke = [];
|
||||
|
||||
// Process Monografie entries
|
||||
if (isset($_POST['monografie_author']) && is_array($_POST['monografie_author'])) {
|
||||
$authors = postArray('monografie_author');
|
||||
$years = postArray('monografie_year');
|
||||
$editions = postArray('monografie_edition');
|
||||
$titles = postArray('monografie_title');
|
||||
$signatures = postArray('monografie_signature');
|
||||
$pagesFrom = postArray('monografie_pages_from');
|
||||
$pagesTo = postArray('monografie_pages_to');
|
||||
|
||||
for ($i = 0; $i < count($authors); $i++) {
|
||||
$monografien[] = [
|
||||
'author' => $authors[$i] ?? '',
|
||||
'year' => $years[$i] ?? '',
|
||||
'edition' => $editions[$i] ?? '',
|
||||
'title' => $titles[$i] ?? '',
|
||||
'signature' => $signatures[$i] ?? '',
|
||||
'pages_from' => $pagesFrom[$i] ?? '',
|
||||
'pages_to' => $pagesTo[$i] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Process Zeitschriftenartikel entries
|
||||
if (isset($_POST['zeitschrift_author']) && is_array($_POST['zeitschrift_author'])) {
|
||||
$authors = postArray('zeitschrift_author');
|
||||
$years = postArray('zeitschrift_year');
|
||||
$volumes = postArray('zeitschrift_volume');
|
||||
$articleTitles = postArray('zeitschrift_article_title');
|
||||
$journalTitles = postArray('zeitschrift_journal_title');
|
||||
$signatures = postArray('zeitschrift_signature');
|
||||
$pagesFrom = postArray('zeitschrift_pages_from');
|
||||
$pagesTo = postArray('zeitschrift_pages_to');
|
||||
|
||||
for ($i = 0; $i < count($authors); $i++) {
|
||||
$zeitschriftenartikel[] = [
|
||||
'author' => $authors[$i] ?? '',
|
||||
'year' => $years[$i] ?? '',
|
||||
'volume' => $volumes[$i] ?? '',
|
||||
'article_title' => $articleTitles[$i] ?? '',
|
||||
'journal_title' => $journalTitles[$i] ?? '',
|
||||
'signature' => $signatures[$i] ?? '',
|
||||
'pages_from' => $pagesFrom[$i] ?? '',
|
||||
'pages_to' => $pagesTo[$i] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Process Herausgeberwerk entries
|
||||
if (isset($_POST['herausgeber_publisher']) && is_array($_POST['herausgeber_publisher'])) {
|
||||
$publishers = postArray('herausgeber_publisher');
|
||||
$workTitles = postArray('herausgeber_work_title');
|
||||
$years = postArray('herausgeber_year');
|
||||
$editions = postArray('herausgeber_edition');
|
||||
$articleAuthors = postArray('herausgeber_article_author');
|
||||
$articleTitles = postArray('herausgeber_article_title');
|
||||
$signatures = postArray('herausgeber_signature');
|
||||
$pagesFrom = postArray('herausgeber_pages_from');
|
||||
$pagesTo = postArray('herausgeber_pages_to');
|
||||
|
||||
for ($i = 0; $i < count($publishers); $i++) {
|
||||
$herausgeberwerke[] = [
|
||||
'publisher' => $publishers[$i] ?? '',
|
||||
'work_title' => $workTitles[$i] ?? '',
|
||||
'year' => $years[$i] ?? '',
|
||||
'edition' => $editions[$i] ?? '',
|
||||
'article_author' => $articleAuthors[$i] ?? '',
|
||||
'article_title' => $articleTitles[$i] ?? '',
|
||||
'signature' => $signatures[$i] ?? '',
|
||||
'pages_from' => $pagesFrom[$i] ?? '',
|
||||
'pages_to' => $pagesTo[$i] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare data for XML generation
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'lastname' => $lastname,
|
||||
'title' => $title,
|
||||
'mail' => $mail,
|
||||
'subject' => $subject,
|
||||
'classname' => $classname,
|
||||
'usage_date_from' => $usage_date_from,
|
||||
'usage_date_to' => $usage_date_to,
|
||||
'availability_date' => $availability_date,
|
||||
'message' => $message,
|
||||
'monografien' => $monografien,
|
||||
'zeitschriftenartikel' => $zeitschriftenartikel,
|
||||
'herausgeberwerke' => $herausgeberwerke
|
||||
];
|
||||
|
||||
// Generate XML
|
||||
$xml = generateELSAXML($data);
|
||||
|
||||
// Send email
|
||||
$emailSent = sendEmail('New ELSA Form Submission', $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.');
|
||||
}
|
||||
Reference in New Issue
Block a user