VERO/sendFinalMails.php
2026-03-04 10:12:09 +01:00

336 lines
13 KiB
PHP

<?php
/* Testdata */
$bibliographicArray = [
[ "fieldId" => "authorinput1","fieldValue" => "Keck, Roland","fieldType" => "input","inputType" => "text","isSelected" => true ],
[ "fieldId" => "titleinput1","fieldValue" => "Testtitel","fieldType" => "input","inputType" => "text","isSelected" => true ]
];
require_once "config.php";
$ini_array = parse_ini_file("config.ini", true);
$baseURL = $ini_array['base']['URL'];
session_start();
if(! isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] === false){
header("location: " .$baseURL ."/redirecttologin.php");
exit;
}
// Arrays dekodieren
if (isset ($_POST['bibliographicArray']))
$bibliographicArray = json_decode($_POST['bibliographicArray'] ?? '[]', true);
$identificatorArray = json_decode($_POST['identificatorArray'] ?? '[]', true);
$typeArray = json_decode($_POST['typeArray'] ?? '[]', true);
$subjectArray = json_decode($_POST['subjectArray'] ?? '[]', true);
$contractArray = json_decode($_POST['contractArray'] ?? '[]', true);
$uploadArray = json_decode($_POST['uploadArray'] ?? '[]', true);
$bibliographicArray = convertToArray($bibliographicArray);
$typeArray = convertToArray($typeArray);
$subjectArray = convertToArray($subjectArray);
$contractArray = convertToArray($contractArray);
$uploadArray = convertToArray($uploadArray);
$identificatorArray = convertToArray($identificatorArray);
// Arrays zusammenfassen
$dataArrays = [
'Bibliografische Grunddaten' => $bibliographicArray,
'Identifikatoren' => $identificatorArray,
'Dokumenttyp und weitere Daten' => $typeArray,
'Freie Schlagworte' => $subjectArray,
'Vertragssektion' => $contractArray,
'Dateiupload' => $uploadArray
];
// echo prepareMetadata($dataArrays, $baseURL);
$firstname = isset($_SESSION['firstname']) ? $_SESSION['firstname'] : "Roland";
$lastname = isset($_SESSION['lastname']) ? $_SESSION['lastname'] : "Keck";
$email = isset($_SESSION['email']) ? $_SESSION['email'] : "roland.keck@conlicom.de";
$title = isset($bibliographicArray['titleinput1']) ? $bibliographicArray['titleinput1'] : "Testitel";
// echo $title; return;
/*
* Mail aufbereiten
*/
prepareMailToVETTeam($dataArrays, $title, $firstname, $lastname, $email, $baseURL);
prepareMailToUser($title, $firstname, $lastname, $email);
function prepareMailToUser($title, $firstname, $lastname, $email) {
date_default_timezone_set('Europe/Berlin');
$replyto = "noreply@bibb-service.de";
$subject = '=?UTF-8?B?' . base64_encode('Bestätigung des Uploads einer Publikation ins VET Repository') . '?=';
define("DEFCALLBACKMAIL", $replyto); // Will be shown as "from".
// Mailtext as HTML (necessary because of the links used in the Mail
$html = "<html>
<head>
<title>Bestätigung des Uploads einer Publikation ins VET Repository</title>
<meta charset='UTF-8'>
</head>
<body style='font-family: Arial, sans-serif; font-size: 14px;'>";
//falls doch noch einmal LOGO benötigt wird
// <img src='vet_repository.png' width='85' height='30' alt='VET Repository Logo'>
// <p>&nbsp;</p>
$html .= "
<p>Hallo {$firstname} {$lastname}, </p>
<p>Vielen Dank für die Übermittlung Ihrer Publikation '{$title}' .</p>
<p> Wir prüfen den Vorgang und informieren Sie, sobald Ihre Publikation im VET Repository hochgeladen wurde.</p>
<p></p>
<p> Sollten sich bei der Bearbeitung Rückfragen ergeben, setzen wir uns mit Ihnen in Verbindung.</p>
<p>Die Bearbeitung kann ggf. einige Werktage in Anspruch nehmen, wir bitten Sie daher um etwas Geduld.</p><p></p>
<p>Wurde Ihre Publikation angenommen, erhalten Sie von uns den Direktlink zu Ihrer Publikation, sofern notwendig den Publikationsvertrag und das geltende DSGVO-Informationsschreiben für Ihre Unterlagen.</p><p></p>
<p>Bei weiteren Fragen stehen wir Ihnen gerne unter der E-Mail-Adresse <a href=\"mailto:repository@bibb.de\">repository@bibb.de</a> zur Verfügung.
<p>Ihr Team des VET Repository</p>
<p>
<small>
--
<br>
Bundesinstitut für Berufsbildung
<br>
Stabsstelle \"Publikationen und wissenschaftliche Informationsdienste\"
<br>
Federal Institute for Vocational Education and Training (BIBB)
<br>
Strategic office \"Publications and Scientific Information Services\"
<br>
Friedrich-Ebert-Allee 114 - 116
<br>
D-53113 Bonn
<br><br>
<a href=\"mailto:repository@bibb.de\">repository@bibb.de</a>
<br>
<a href=\"https://www.bibb.de\">www.bibb.de</a>
<br>
<a href=\"https://www.bibb.de/repository\">www.bibb.de/repository</a>
<br>
<a href=\"https://www.vet-repository.info\">www.vet-repository.info</a>
<br>
</small>
</body>
</html>
";
// echo $html;
// now let`s generate the mail including all links, images, etc.
$final_msg = preparehtmlmail($html); // give a function your html*
$message = $final_msg['multipart'];
$headers = $final_msg['headers'];
// send the mail using sendmail as underlying service
mail($email, $subject, $message, $headers);
}
function prepareMailToVETTeam($dataArrays, $title, $firstname, $lastname, $email, $baseURL) {
date_default_timezone_set('Europe/Berlin');
$replyto = "noreply@bibb-service.de";
$sendto = "repository@bibb.de"; // "roland.keck@conlicom.de" ; //"repository@bibb.de";
$subject = '=?UTF-8?B?' . base64_encode('VERO: neue Publikation ' .$title) . '?=';
define("DEFCALLBACKMAIL", $replyto); // Will be shown as "from".
// Mailtext as HTML (necessary because of the links used in the Mail
$html = "<html>
<head>
<title>'VERO: neue Publikation " .$title ."</title>
<meta charset='UTF-8'>
</head>
<body style='font-family: Arial, sans-serif; font-size: 14px;'>";
$html = '<table><tr>';
$html .= "<td>Eingereicht von</td><td>" .$firstname ." " .$lastname ." (" .$email .") am " .date("Y-m-d H:i:s") ."</td></tr>";
$html .= prepareMetadata($dataArrays, $baseURL);
$html .= '</table>';
$final_msg = preparehtmlmail($html);
$message = $final_msg['multipart'];
$headers = $final_msg['headers'];
// send the mail using sendmail as underlying service
mail($sendto, $subject, $message, $headers);
}
// Feldlabel-Funktion
function getFieldLabel($fieldId) {
include "include/summaryLabels.php" ;
return $labels[$fieldId] ?? $fieldId;
}
function prepareMetadata($dataArrays, $baseURL) {
$ret = '';
foreach ($dataArrays as $sectionName => $sectionData) {
if (!empty($sectionData)) {
$ret .= '<tr><td colspan="2"><h3>' .$sectionName .'</h3></td></tr>';
foreach ($sectionData as $key => $field) {
if (strncmp($key, 'uploadHiddenItem', strlen('uploadHiddenItem')) == 0) {
$ret .= '<tr><td>' .getFieldLabel($key) .'</td><td><a href="' .$baseURL .'/uploads/' .$field .'"</a>' .$field .'</td></tr>';
} else {
$ret .= '<tr><td>' .getFieldLabel($key) .'</td><td>' .$field .'</td></tr>';
}
}
}
}
return $ret;
}
// prepare email with all images from html attached (will be presented embedded depending on the Mailclient used
function preparehtmlmail($html) {
preg_match_all('~<img.*?src=.([\/.a-z0-9:_-]+).*?>~si',$html,$matches);
$i = 0;
$paths = array();
foreach ($matches[1] as $img) {
$img_old = $img;
if(strpos($img, "http://") === false || strpos($img, "https://")) {
$uri = parse_url($img);
$paths[$i]['path'] = $_SERVER['DOCUMENT_ROOT'].$uri['path'];
$content_id = md5($img);
$html = str_replace($img_old,'cid:'.$content_id,$html);
// print_r($html);
$paths[$i++]['cid'] = $content_id;
}
}
$boundary = "--".md5(uniqid(time()));
$headers = "MIME-Version: 1.0\n";
$headers .="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
$headers .= "From: ".DEFCALLBACKMAIL."\r\n";
$multipart = '';
$multipart .= "--$boundary\n";
$kod = 'utf-8';
$multipart .= "Content-Type: text/html; charset=$kod\n";
$multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n";
$multipart .= $html ."\n\n";
foreach ($paths as $path) {
if(file_exists($path['path']))
$fp = fopen($path['path'],"r");
if (!$fp) {
return false;
}
$imagetype = substr(strrchr($path['path'], '.' ),1);
$file = fread($fp, filesize($path['path']));
fclose($fp);
$message_part = "";
switch (strtolower($imagetype)) {
case 'png':
$message_part .= "Content-Type: image/png";
break;
case 'jpg':
case 'jpeg':
$message_part .= "Content-Type: image/jpeg";
break;
case 'gif':
$message_part .= "Content-Type: image/gif";
break;
}
$p = $path['path'];
$message_part .= "; file_name = \"$p\"\n";
$message_part .= 'Content-ID: <'.$path['cid'].">\n";
$message_part .= "Content-Transfer-Encoding: base64\n";
$message_part .= "Content-Disposition: inline; filename = \"".basename($path['path'])."\"\n\n";
$message_part .= chunk_split(base64_encode($file))."\n";
$multipart .= "--$boundary\n".$message_part."\n";
}
$multipart .= "--$boundary--\n";
return array('multipart' => $multipart, 'headers' => $headers);
}
function convertToArray($object) {
//print_r($object);
// Alle Arrays umwandeln
$ret = [];
foreach ($object as $field) {
$ret[$field['fieldId']] = $field['fieldValue'];
}
return ($ret);
}
$html = '<div class="stickywrapper">
<!-- Hauptinhalt der Seite -->
<div class="content">
<div class="container my-5">
<div id="confirmationScreen" class="wrapperconfirmation ml-10 shadow p-3 mb-5 bg-box rounded align-items-center">
<h4>Ihre Publikation wird bearbeitet</h4> ';
/* <div class="row">
Hallo ';
$html .= $firstname ." " .$lastname;
$html .= '</div>
*/
$html .= ' <div class="row"></div>
<div class="row">
Herzlichen Dank für die Einreichung Ihrer Publikation. Sie erhalten in Kürze eine automatische Bestätigung per E-Mail.
</div>
<div>
Wir bereiten zeitnah die Veröffentlichung Ihrer Einreichung im VET Repository vor. Nach der Veröffentlichung erhalten Sie von uns den Direktlink zu Ihrer Publikation, sofern notwendig den Publikationsvertrag und das geltende DSGVO-Informationsschreiben für Ihre Unterlagen.
<form action="indexBT5.php" method="post">
<button class="btn-publish" type="submit" style="float: right; margin-top: 5px;">Neue Publikation einreichen</button>
</form>
</div>
</div>
</div>
</div>';
$html = '<div class="stickywrapper">
<!-- Hauptinhalt der Seite -->
<div class="content">
<div class="container my-5">
<div id="confirmationScreen" class="wrapperconfirmation ml-10 shadow p-3 mb-5 bg-box rounded align-items-center">
<h4>Ihre Publikation wird bearbeitet</h4> ';
/* <div class="row">
Hallo ';
$html .= $firstname ." " .$lastname;
$html .= '</div>
*/
$html .= ' <div class="row"></div>
<div class="row">
Herzlichen Dank für die Einreichung Ihrer Publikation. Sie erhalten in Kürze eine automatische Bestätigung per E-Mail.
</div>
<div>
Wir bereiten zeitnah die Veröffentlichung Ihrer Einreichung im VET Repository vor. Nach der Veröffentlichung erhalten Sie von uns den Direktlink zu Ihrer Publikation, sofern notwendig den Publikationsvertrag und das geltende DSGVO-Informationsschreiben für Ihre Unterlagen.
</div>
<form action="indexBT5.php" method="post">
<button class="btn-publish" type="submit" style="float: right; margin-top: 35px; margin-bottom:120px">Neue Publikation einreichen</button>
</form>
</div>
</div>
</div>
</div>';
echo $html;
?>