Files
urbanis.openeye.app/source/meldung.php
2025-06-06 12:16:00 +02:00

197 lines
7.5 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// meldung.php verarbeitet das Formular aus formular.inc.php und versendet die Begehungsnotiz
header('Content-Type: text/html; charset=utf-8');
session_start();
require_once("inc/config.inc.php");
require_once("inc/functions.inc.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once '/opt/php-libs/vendor/autoload.php';
$user = check_user();
$werbeflaechen_betreuer = 'wegener@urbanis-berlin.de';
$werbeflaechen_betreuer2 = 'menke@urbanis-berlin.de';
$automaten_betreuer = 'breuer@urbanis-berlin.de';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
include 'inc/formular.inc.php';
exit;
}
date_default_timezone_set(TIMEZONE);
$timestamp = time();
$datum = date("d.m.Y - H:i", $timestamp);
$bahnhof = isset($_POST['bahnhof']) ? substr(strip_tags($_POST['bahnhof']), 0, 255) : 'Unbekannt';
$sql = "SELECT * FROM `standorte` WHERE `bahnhof` = :bahnhof LIMIT 1;";
$stmt = $pdo->prepare($sql);
$stmt->execute(['bahnhof' => $bahnhof]);
$betreuer = $stmt->fetch(PDO::FETCH_ASSOC);
$mail = new PHPMailer(true);
try {
$mail->CharSet = 'UTF-8';
$mail->Encoding = 'quoted-printable';
$mail->isSMTP();
$mail->Host = SMTP_HOST;
$mail->Port = SMTP_PORT;
$mail->SMTPSecure = SMTP_SECURE;
$mail->SMTPAuth = SMTP_AUTH;
$mail->Username = SMTP_USER;
$mail->Password = SMTP_PASS;
$mail->setFrom(MAIL_FROM, MAIL_FROM_NAME);
$mail->addReplyTo($user['email'], $user['vorname'] . ' ' . $user['nachname']);
if (DEBUG_MODE) {
$mail->addAddress(DEBUG_EMAIL);
} else {
$mail->addAddress($betreuer['betreuer'] ?? MAIL_TO);
}
$mail->Subject = (DEBUG_MODE ? '[TEST] ' : '') . "Begehungsnotiz zu $bahnhof am $datum";
$mail->isHTML(true);
$cc_debug = [];
$bilder_html = "";
$bilder = ['userfile', 'userfile2', 'userfile3'];
$bildCounter = 1;
foreach ($bilder as $feld) {
if (!empty($_FILES[$feld]['tmp_name'])) {
$tmp = $_FILES[$feld]['tmp_name'];
$mime = mime_content_type($tmp);
if (in_array($mime, ['image/jpeg', 'image/png', 'image/webp'])) {
list($width, $height) = getimagesize($tmp);
$targetW = 1600;
$scale = $width > $targetW ? ($targetW / $width) : 1.0;
$newW = (int)($width * $scale);
$newH = (int)($height * $scale);
$src = imagecreatefromstring(file_get_contents($tmp));
$dst = imagecreatetruecolor($newW, $newH);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $newW, $newH, $width, $height);
$out = sys_get_temp_dir() . '/upload_' . uniqid() . '.jpg';
imagejpeg($dst, $out, 85);
imagedestroy($src);
imagedestroy($dst);
if (filesize($out) <= 5 * 1024 * 1024) {
$cid = 'bild' . $bildCounter;
$mail->addEmbeddedImage($out, $cid);
$bilder_html .= "<img src='cid:$cid' style='max-width:100%; height:auto; margin: 20px 0; border:1px solid #ccc; border-radius:8px;'>";
$bildCounter++;
} else {
unlink($out);
}
}
}
}
$felder = [
'muell' => 'Müllraum',
'wc' => 'WC-Anlage',
'miet' => 'Mietobjekte',
'automaten' => 'Automaten',
'werbeflaechen' => 'Werbeflächen'
];
$abschnitt_html = "";
$abschnitt_plain = "";
foreach ($felder as $feld => $label) {
$status = isset($_POST[$feld]) ? $_POST[$feld] : 'wurde nicht kontrolliert';
$html_content = htmlspecialchars($status);
$plain_content = "Status: $status";
if ($status === 'Technische Mängel' && !empty($_POST[$feld . '-tech-maengel-text'])) {
$html_content = "<em>Technische Mängel:</em> " . nl2br(htmlspecialchars(trim($_POST[$feld . '-tech-maengel-text'])));
$plain_content = "Technische Mängel: " . trim($_POST[$feld . '-tech-maengel-text']);
}
if ($status === 'Sonstiges' && !empty($_POST[$feld . '-sonstiges-text'])) {
$html_content = "<em>Sonstiges:</em> " . nl2br(htmlspecialchars(trim($_POST[$feld . '-sonstiges-text'])));
$plain_content = "Sonstiges: " . trim($_POST[$feld . '-sonstiges-text']);
}
if (strcasecmp($status, "wurde nicht kontrolliert") !== 0) {
if ($feld === 'automaten') {
if (!DEBUG_MODE) {
$mail->addCC($automaten_betreuer, 'Mike Breuer');
}
$html_content .= ' <small>(Mike Breuer im CC)</small>';
$plain_content .= ' (Mike Breuer im CC)';
$cc_debug[] = 'Mike Breuer';
}
if ($feld === 'werbeflaechen') {
if (!DEBUG_MODE) {
$mail->addCC($werbeflaechen_betreuer, 'Thomas Wegener');
$mail->addCC($werbeflaechen_betreuer2, 'Henning Menke');
}
$html_content .= ' <small>(Thomas Wegener und Henning Menke im CC)</small>';
$plain_content .= ' (Thomas Wegener und Henning Menke im CC)';
$cc_debug[] = 'Thomas Wegener';
$cc_debug[] = 'Henning Menke';
}
}
$abschnitt_html .= "<tr><td><strong>$label:</strong></td><td>$html_content</td></tr>";
$abschnitt_plain .= "== $label ==\n$plain_content\n\n";
}
$body_html = "<div style='font-family:sans-serif; font-size:14px;'>
<div style='background:#f0f0f0;padding:20px;text-align:center;'>
<h1 style='margin:0;font-size:24px;'>OpenEye Urbanis</h1>
<p style='margin:0;font-size:14px;color:#666;'>Begehungsnotiz</p>
</div>
<p>Hallo " . htmlspecialchars($betreuer['Vorname'] . ' ' . $betreuer['Nachname']) . ",</p>
<p>für <strong>$bahnhof</strong> wurde am <strong>$datum</strong> von <strong>" .
htmlspecialchars($user['vorname'] . ' ' . $user['nachname']) . "</strong> eine Begehungsnotiz mit folgendem Inhalt übermittelt:</p>
<table cellspacing='0' cellpadding='6' style='font-size: 14px; border-collapse: collapse;'>$abschnitt_html</table>";
if (!empty($bilder_html)) {
$body_html .= "<hr style='margin-top:30px;'>
<h4>Fotos zur Meldung</h4>
$bilder_html";
}
$body_html .= "<hr style='margin-top: 30px;'><p style='font-size: 0.9em; color: #666;'>Diese E-Mail wurde über <a href='https://urbanis.openeye.app'>urbanis.openeye.app</a> gesendet.<br>
Antworten Sie direkt auf diese Nachricht Ihre Antwort wird an <strong>" .
htmlspecialchars($user['vorname'] . ' ' . $user['nachname']) . " (" . htmlspecialchars($user['email']) . ")</strong> weitergeleitet.</p>";
if (DEBUG_MODE && !empty($cc_debug)) {
$body_html .= "<br><br><hr><small>[Debug-Info: wäre CC an: " . implode(', ', $cc_debug) . "]</small>";
}
$body_html .= "</div>";
$mail->Body = $body_html;
$body_plain = "Hallo {$betreuer['Vorname']} {$betreuer['Nachname']},\n\n";
$body_plain .= "für {$bahnhof} wurde am {$datum} von {$user['vorname']} {$user['nachname']} eine Begehungsnotiz mit folgendem Inhalt übermittelt:\n\n";
$body_plain .= $abschnitt_plain;
$body_plain .= "--\nDiese E-Mail wurde über urbanis.openeye.app gesendet.\nAntworten Sie direkt Ihre Antwort wird an {$user['vorname']} {$user['nachname']} ({$user['email']}) weitergeleitet.";
$mail->AltBody = $body_plain;
$mail->send();
include("templates/header.inc.php");
echo '<div class="container-fluid bg-body w-100 mb-3"></div>';
echo '<div class="container-fluid">';
echo '<div class="container-md border rounded-3 bg-light px-5 py-4">';
echo '<h2 style="text-align:center;">✅ Meldung erfolgreich versendet</h2>';
echo '<div style="text-align:center;"><a href="" style="display:inline-block;margin-top:1em;">Neue Meldung erfassen</a></div>';
include("templates/footer.inc.php");
} catch (Exception $e) {
include("templates/header.inc.php");
echo '<div class="container-fluid bg-body w-100 mb-3"></div>';
echo '<div class="container-fluid">';
echo '<div class="container-md border rounded-3 bg-light px-5 py-4">';
echo "<h2 style='text-align:center; color: red;'>❌ Fehler beim Versand</h2>";
echo "<p style='text-align:center;'>" . htmlspecialchars($mail->ErrorInfo) . "</p>";
include("templates/footer.inc.php");
}