prepare("SELECT * FROM config LIMIT 1"); $stmt->execute(); $rowconfig = $stmt->fetch(PDO::FETCH_ASSOC); if (!$rowconfig) { // Keine Config gefunden return false; } $mailserver = (string)$rowconfig["mailserver"]; $mailUsername = (string)$rowconfig["mailUsername"]; $mailPassword = (string)$rowconfig["mailPassword"]; $mailPort = (int)$rowconfig["mailPort"]; $mailFrom = (string)$rowconfig["mailFrom"]; $mailFromName = (string)$rowconfig["mailFromName"]; $mailSMTPSecure = (string)$rowconfig["mailSMTPSecure"]; // z.B. 'tls' oder 'ssl' oder leer // 2) Mail senden (UTF-8) $mail = new PHPMailer(true); try { $mail->SMTPDebug = 0; $mail->isSMTP(); $mail->Host = $mailserver; $mail->SMTPAuth = true; $mail->Username = $mailUsername; $mail->Password = $mailPassword; if (!empty($mailSMTPSecure)) { $mail->SMTPSecure = $mailSMTPSecure; // 'tls' oder 'ssl' } $mail->Port = $mailPort; // Charset sauber setzen $mail->CharSet = 'UTF-8'; // Absender / Empfänger $mail->setFrom($mailFrom, $mailFromName); $mail->addAddress($empfaenger); // Inhalt $mail->isHTML(true); $mail->Subject = $betreff; $mail->Body = $body; // AltBody sinnvoll: HTML -> Text grob runterbrechen $mail->AltBody = trim(html_entity_decode(strip_tags(str_replace(["
", "
", "
"], "\n", $body)), ENT_QUOTES, 'UTF-8')); $mail->send(); return true; } catch (Exception $e) { // Optional: Logging statt echo // error_log("Mail error: " . $mail->ErrorInfo); return false; } } function SendMailMessageVorlage(PDO $pdo, string $config, int $terminid, string $vorlage) { // ----------------------------------------- // 1) LOGIN CONFIG AUSLESEN // ----------------------------------------- $stmt = $pdo->prepare("SELECT * FROM config LIMIT 1"); $stmt->execute(); $rowconfig = $stmt->fetch(PDO::FETCH_ASSOC); if (!$rowconfig) { throw new RuntimeException("config Tabelle leer / nicht gefunden"); } $mailserver = $rowconfig["mailserver"] ?? null; $mailUsername = $rowconfig["mailUsername"] ?? null; $mailPassword = $rowconfig["mailPassword"] ?? null; $mailPort = $rowconfig["mailPort"] ?? null; $mailFrom = $rowconfig["mailFrom"] ?? null; $mailFromName = $rowconfig["mailFromName"] ?? null; $mailSMTPSecure = $rowconfig["mailSMTPSecure"] ?? null; $logintermin = $rowconfig["logintermin"] ?? null; $loginwarteliste = $rowconfig["loginwarteliste"] ?? null; $logingrippetermin = $rowconfig["logingrippetermin"] ?? null; $logingrippewarteliste = $rowconfig["logingrippewarteliste"] ?? null; $anfragebestaetigung = $rowconfig["anfragebestaetigung"] ?? null; // ----------------------------------------- // 2) E-Mail Vorlage laden // ----------------------------------------- $stmt = $pdo->prepare("SELECT betreff, body FROM mailtemplates WHERE templetid = ?"); $stmt->execute([$vorlage]); $tpl = $stmt->fetch(PDO::FETCH_ASSOC); if (!$tpl) { throw new RuntimeException("Mailtemplate nicht gefunden: templetid=" . $vorlage); } $body = $tpl["body"]; $betreff = $tpl["betreff"]; // ----------------------------------------- // 3) Daten je nach $config laden // ----------------------------------------- $vorname = $nachname = $geburtstag = $tele = $plz = $ort = $strasse = null; $adresse = $empfaenger = $hash = null; // Optional-Felder $Zeitanzeige = null; $impfstofftext = null; $impforttext = null; $terminlogin = null; $grippeterminlogin = null; $wartelistelogin = null; $grippewartelistelogin = null; $anfragenlogin = null; $nachricht = null; $medikamenteins = null; $medikamentzwei = null; $anforderungart = null; $rezeptart = null; if ($config === "1") { // impftermin + timeslots + user (ALT: nutzt noch user) // Wenn du später auch das migrierst: hier JOIN persons statt user. $stmt = $pdo->prepare(" SELECT it.*, ts.*, p.* FROM impftermin it INNER JOIN timeslots ts ON it.timeid = ts.timeid INNER JOIN persons p ON it.userid = p.person_id WHERE it.terminid = ? LIMIT 1 "); $stmt->execute([$terminid]); $rowtime = $stmt->fetch(PDO::FETCH_ASSOC); if (!$rowtime) { throw new RuntimeException("Termin nicht gefunden: terminid=" . $terminid); } $vorname = $rowtime["vorname"]; $nachname = $rowtime["nachname"]; $geburtstag = $rowtime["geburtstag"]; $tele = $rowtime["tele"]; $plz = $rowtime["plz"]; $ort = $rowtime["ort"]; $strasse = $rowtime["strasse"]; $adresse = trim($ort . " " . $plz . ", " . $strasse); $empfaenger = $rowtime["email"]; $hash = $rowtime["hash"]; $impfortid = $rowtime["impfortid"] ?? null; $date = new DateTime($rowtime["date"]); $datum = $date->format('d.m.Y'); $start = substr($rowtime["start"], 0, 5); $ende = substr($rowtime["ende"], 0, 5); $Zeitanzeige = $datum . " " . $start . "-" . $ende; $impfstoff = $rowtime["impfstoff"] ?? null; if (!empty($impfstoff)) { $stmt = $pdo->prepare("SELECT impfname FROM impfstoff WHERE impfid = ? LIMIT 1"); $stmt->execute([$impfstoff]); $impfstofftext = $stmt->fetchColumn() ?: null; } $terminlogin = $logintermin . "?id=" . $hash; $grippeterminlogin = $logingrippetermin . "?id=" . $hash; if (!empty($impfortid)) { $stmt = $pdo->prepare("SELECT adresse FROM impfort WHERE ortid = ? LIMIT 1"); $stmt->execute([$impfortid]); $impforttext = $stmt->fetchColumn() ?: null; } } elseif ($config === "2") { // warteliste + user (ALT: nutzt noch user) $stmt = $pdo->prepare(" SELECT w.*, p.* FROM warteliste w INNER JOIN persons p ON w.userid = p.person_id WHERE w.warteid = ? LIMIT 1 "); $stmt->execute([$terminid]); $rowtime = $stmt->fetch(PDO::FETCH_ASSOC); if (!$rowtime) { throw new RuntimeException("Wartelisteneintrag nicht gefunden: warteid=" . $terminid); } $vorname = $rowtime["vorname"]; $nachname = $rowtime["nachname"]; $geburtstag = $rowtime["geburtstag"]; $tele = $rowtime["tele"]; $plz = $rowtime["plz"]; $ort = $rowtime["ort"]; $strasse = $rowtime["strasse"]; $adresse = trim($ort . " " . $plz . ", " . $strasse); $empfaenger = $rowtime["email"]; $hash = $rowtime["hash"]; $wartelistelogin = $loginwarteliste . "?id=" . $hash; $grippewartelistelogin = $logingrippewarteliste . "?id=" . $hash; $impfstoff = $rowtime["impfstoff"] ?? null; $impfangebot = $rowtime["impfenangebot"] ?? null; if (!empty($impfstoff)) { $stmt = $pdo->prepare("SELECT impfname FROM impfstoff WHERE impfid = ? LIMIT 1"); $stmt->execute([$impfstoff]); $impfstofftextwarte = $stmt->fetchColumn() ?: null; } // deine Funktion: // $impfangebottext = GetimpfenangebotName($impfangebot); } elseif ($config === "3") { // NEU: anfragen + persons (statt user) $stmt = $pdo->prepare(" SELECT a.*, p.vorname, p.nachname, p.geburtstag, p.tele, p.plz, p.ort, p.strasse, p.email FROM anfragen a INNER JOIN persons p ON a.requester_person_id = p.person_id WHERE a.anfrageid = ? LIMIT 1 "); $stmt->execute([$terminid]); $rowtime = $stmt->fetch(PDO::FETCH_ASSOC); if (!$rowtime) { throw new RuntimeException("Anfrage nicht gefunden: anfrageid=" . $terminid); } $vorname = $rowtime["vorname"]; $nachname = $rowtime["nachname"]; $geburtstag = $rowtime["geburtstag"]; $tele = $rowtime["tele"]; $plz = $rowtime["plz"]; $ort = $rowtime["ort"]; $strasse = $rowtime["strasse"]; $adresse = trim($ort . " " . $plz . ", " . $strasse); $empfaenger = $rowtime["email"]; $hash = $rowtime["hash"]; $anfragenlogin = $anfragebestaetigung . "?id=" . $hash; $nachricht = $rowtime["nachricht"]; $medikamenteins = $rowtime["medikament1"]; $medikamentzwei = $rowtime["medikament2"]; $anforderungart = $rowtime["anforderungart"]; $stmt = $pdo->prepare("SELECT artname FROM anfrageart WHERE artid = ? LIMIT 1"); $stmt->execute([$anforderungart]); $rezeptart = $stmt->fetchColumn() ?: null; } elseif ($config === "4") { // NEU: anfragen + persons (statt user), aber wie bei dir mit utf8_decode $stmt = $pdo->prepare(" SELECT a.*, p.vorname, p.nachname, p.geburtstag, p.tele, p.plz, p.ort, p.strasse, p.email FROM anfragen a INNER JOIN persons p ON a.requester_person_id = p.person_id WHERE a.anfrageid = ? LIMIT 1 "); $stmt->execute([$terminid]); $rowtime = $stmt->fetch(PDO::FETCH_ASSOC); if (!$rowtime) { throw new RuntimeException("Anfrage nicht gefunden: anfrageid=" . $terminid); } $vorname = utf8_decode($rowtime["vorname"]); $nachname = utf8_decode($rowtime["nachname"]); $geburtstag = $rowtime["geburtstag"]; $tele = $rowtime["tele"]; $plz = $rowtime["plz"]; $ort = $rowtime["ort"]; $strasse = $rowtime["strasse"]; $adresse = trim($ort . " " . $plz . ", " . $strasse); $empfaenger = $rowtime["email"]; $hash = $rowtime["hash"]; $anfragenlogin = $anfragebestaetigung . "?id=" . $hash; $nachricht = utf8_decode($rowtime["nachricht"]); } else { throw new InvalidArgumentException("Unbekannter config-Wert: " . $config); } $body = str_replace("%BENUTZERVORNAME%", $vorname, $body); $body = str_replace("%BENUTZERNACHNAME%", $nachname, $body); $body = str_replace("%BENUTZERGEBURTSTAG%", $geburtstag, $body); $body = str_replace("%BENUTZERADRESSE%", $adresse, $body); $body = str_replace("%TERMINZEITVORGABE%", $Zeitanzeige, $body); $body = str_replace("%TERMINIMPFSTOFF%", $impfstofftext, $body); $body = str_replace("%TERMINIMPFORT%", $impforttext, $body); $body = str_replace("%TERMINLOGIN%", $terminlogin, $body); $body = str_replace("%GRIPPETERMINLOGIN%", $grippeterminlogin, $body); $body = str_replace("%WARTELISTELOGIN%", $wartelistelogin, $body); $body = str_replace("%GRIPPEWARTELISTELOGIN%", $grippewartelistelogin, $body); $body = str_replace("%WARTELISTEIMPFSTOFF%", $impfstofftextwarte ?? null, $body); $body = str_replace("%WARTELISTEIMPFANGEBOT%", GetimpfenangebotName((int)$impfangebot), $body); $body = str_replace("%REZEPTART%", $rezeptart, $body); $body = str_replace("%MEDIKAMENTNUMMEREINS%", $medikamenteins, $body); $body = str_replace("%MEDIKAMENTNUMMERZWEI%", $medikamentzwei, $body); $body = str_replace("%ANFRAGENACHRICHT%", $nachricht, $body); $body = str_replace("%ANFRAGENLOGIN%", $anfragenlogin, $body); //echo $body; $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = 0; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $mailserver; $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $mailUsername; $mail->Password = $mailPassword; $mail->SMTPSecure = $mailSMTPSecure; // Enable TLS encryption, `ssl` also accepted //$mail->Port = 587; // TCP port to connect to $mail->Port = $mailPort; //Recipients $mail->setFrom($mailFrom , $mailFromName); $mail->addAddress($empfaenger); // Name is optional //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = $betreff; $mail->Body = $body; $mail->AltBody = $body; $mail->send(); echo 'Ihre Nachricht wurde erfolgreich versendet!
Bitte prüfen Sie Ihren Posteingang sowie Ihren Spam-Ordner!
'; } catch (Exception $e) { echo 'Leider gab es einen Fehler bei E-Mailversand. Fehler: ', $mail->ErrorInfo; } } function SendMailMessageHash($empfaenger, $betreff, $body, $hash){ $body = iconv('UTF-8', 'CP1252//IGNORE', $body); $betreff = iconv('UTF-8', 'CP1252//IGNORE', $betreff); $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = 0; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP //$mail->Host = 'vwp0583.webpack.hosteurope.de'; // Specify main and backup SMTP servers $mail->Host = 'mx2f5c.netcup.net'; $mail->SMTPAuth = true; // Enable SMTP authentication //$mail->Username = 'wp1085322-creutzburg'; // SMTP username //$mail->Password = 'praxis.cr'; // SMTP password $mail->Username = 'praxis-creutzburg@ctb-it.de'; $mail->Password = 'Coppenbruegge123'; $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted //$mail->Port = 587; // TCP port to connect to $mail->Port = 587; //Recipients $mail->setFrom('praxis-creutzburg@ctb-it.de', 'Praxis Creutzburg'); #$mail->addAddress('ccreutzburg@live.de', 'Joe User'); // Add a recipient $mail->addAddress($empfaenger); // Name is optional $mail->addReplyTo('kontakt@praxis-creutzburg.de', 'Praxis Creutzburg'); //$mail->addBCC('Arzt@praxis-creutzburg.de'); //$mail->addBCC("praxis@balanceacademie.de"); //Attachments #$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments #$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = $betreff; $mail->Body = $body; $mail->AltBody = $body; //$mail->charSet = "UTF-8"; //$mail->Encoding = 'base64'; $mail->send(); echo 'Ihre Nachricht wurde erfolgreich versendet!

Überprüfen Sie auch Ihren Spam-Filter.
'; } catch (Exception $e) { echo 'Leider gab es einen Fehler bei E-Mailversand. Nutzen Sie diesen Link: '.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']. '?id=' . $hash. '
Mit diesem können Sie den Termin bestätigen und stornieren.
'; #Fehler: ', $mail->ErrorInfo; } } function GetStatus($checked){ if($checked == "0"){ $farbe ="#F0E68C"; $checkausgabe = "nicht bestätigt"; }else if($checked == "1"){ $farbe = "#98FB98"; $checkausgabe = "zugesagt"; }else if($checked == "2"){ $farbe = "#32CD32"; $checkausgabe = "abgemeldet"; }else if($checked == "3"){ $farbe = "#32CD32"; $checkausgabe = "vom Praxisteam abgesagt"; }else if($checked == "4"){ $farbe = "#32CD32"; $checkausgabe = "vom System abgesagt"; }else if($checked == "5"){ $farbe = "#32CD32"; $checkausgabe = "vom System abgesagt"; }else if($checked == "10"){ $farbe = "#ace7ac"; $checkausgabe = "beantwortet"; }else if($checked == "29"){ $farbe = "#97ff97"; $checkausgabe = "telefonisch beantwortet"; }else if($checked == "30"){ $farbe = "#32CD32"; $checkausgabe = "gelöscht mit Info"; }else if($checked == "31"){ $farbe = "#32CD32"; $checkausgabe = "gelöscht ohne Info"; }else{ $checkausgabe = "unbekannt"; $farbe = ""; } return $checkausgabe; } function GetStatusFarbe($checked){ if($checked == "0"){ $farbe ="#F0E68C"; $checkausgabe = "nicht bestätigt"; }else if($checked == "1"){ $farbe = "#98FB98"; $checkausgabe = "zugesagt"; }else if($checked == "2"){ $farbe = "#32CD32"; $checkausgabe = "abgemeldet"; }else if($checked == "3"){ $farbe = "#32CD32"; $checkausgabe = "vom Praxisteam abgesagt"; }else if($checked == "4"){ $farbe = "#32CD32"; $checkausgabe = "vom System abgesagt"; }else if($checked == "5"){ $farbe = "#32CD32"; $checkausgabe = "vom System abgesagt"; }else if($checked == "10"){ $farbe = "#ace7ac"; $checkausgabe = "beantwortet"; }else if($checked == "29"){ $farbe = "#97ff97"; $checkausgabe = "telefonisch beantwortet"; }else if($checked == "30"){ $farbe = "#32CD32"; $checkausgabe = "gelöscht mit Info"; }else if($checked == "31"){ $farbe = "#32CD32"; $checkausgabe = "gelöscht ohne Info"; }else{ $checkausgabe = "unbekannt"; $farbe = ""; } return $farbe; } function GetImpfstoffId($impfstoff){ if($impfstoff == "Egal/Arzt entscheidet"){ $impfstofftext = "0"; }else if($impfstoff == "AstraZeneca"){ $impfstofftext = "1" ; }else if($impfstoff == "Biontech"){ $impfstofftext = "2"; }else if($impfstoff == "Johnson"){ $impfstofftext = "3"; }else{ $impfstofftext = "noch nicht geklärt"; } return $impfstofftext; } function GetImpfstoffName($impfstoff){ if($impfstoff == 0){ $impfstofftext = "Egal/Arzt entscheidet"; }else if($impfstoff == 1){ $impfstofftext = "AstraZeneca"; }else if($impfstoff == 2){ $impfstofftext = "Biontech"; }else if($impfstoff == 3){ $impfstofftext = "Johnson"; }else{ $impfstofftext = "noch nicht geklärt"; } return $impfstofftext; } function GetImpfstoffTermin($impfstoff){ if($impfstoff == 0){ $impfstofftext = "AstraZeneca"; }else if($impfstoff == 1){ $impfstofftext = "Biontech"; }else if($impfstoff == 2){ $impfstofftext = "Arzt entscheidet"; }else{ $impfstofftext = "noch nicht geklärt"; } return $impfstofftext; } function GetImpfArt($wert){ if($wert == "1"){ $text = "Erstimpfung"; }else if($wert == 2){ $text = "Zweitimpfung"; }else if($wert == 3){ $text = "Drittimpfung/Booster"; }else if($wert == 4){ $text = "Vierimpfung"; }else if($wert == 5){ $text = "Zweitimpfung (nur Erstimpfung)"; }else if($wert == 6){ $text = "Erstimpfung (einzeln)"; }else{ $text = ""; } return $text; } function GetBehandelt($wert){ if($wert == 0){ $text = "nicht behandelt"; }else if($wert == 1){ $text = "behandelt"; }else{ $text = ""; } return $text; } function GetVersicherungArt($wert){ if($wert == 0){ $text = "Kassenpatient"; }else if($wert == 1){ $text = "Privatpatient"; }else{ $text = ""; } return $text; } function GetOrdnungsid($wert){ if($wert == 0){ $text = "unklar"; }else if($wert == 1){ $text = "Rezept"; }else if($wert == 2){ $text = "Anfrage"; }else if($wert == 3){ $text = "Terminabsage"; }else if($wert == 5){ $text = "Bewerbung"; }else{ $text = ""; } return $text; } function GetPatientenartName($Patientenart){ if($Patientenart == "0"){ $impfenangebot = "Neupatient"; }else if($Patientenart == "1"){ $impfenangebot = "Patient"; }else{ $impfenangebot = "unklar"; } return $impfenangebot; } function GetimpfenangebotName($Patientenart){ if($Patientenart == "1"){ $impfenangebot = "normal"; }else if($Patientenart == "2"){ $impfenangebot = "Springer"; }else{ $impfenangebot = "unklar"; } return $impfenangebot; } function GetImpfstoffNameTermin($impfstoff){ if($impfstoff == 0){ $impfstofftext = "AstraZeneca"; }else if($impfstoff == 1){ $impfstofftext = "Biontech"; }else{ $impfstofftext = "noch nicht geklärt"; } return $impfstofftext; } ### Togo Termine anlegen function gototerminanlegung() { global $pdo; $statementtermin = $pdo->prepare("SELECT * FROM togo_terminvorgaben"); $statementtermin->execute(); foreach ($statementtermin as $row) { $togovorgabenid = $row["vorgabenid"]; $togodate = $row["date"]; $togostart = $row["start"]; $togoende = $row["ende"]; $standort = $row["standort"]; $error = $row["error"]; $warning = $row["warning"]; $date = new DateTime(); if($togodate == "Mo"){ $date->modify('next monday'); }elseif($togodate == "Di"){ $$date->modify('next tuesday'); #$nextday = date('Y-m-d', $nextTuesday); }elseif($togodate == "Mi"){ $date->modify('next wednesday'); #$nextday = date('Y-m-d', $nextTuesday); }elseif($togodate == "Do"){ $date->modify('next thursday'); #$nextday = date('Y-m-d', $nextTuesday); }elseif($togodate == "Fr"){ $date->modify('next friday'); #$nextday = date('Y-m-d', $nextTuesday); }elseif($togodate == "Sa"){ $date->modify('next saturday'); #$nextday = date('Y-m-d', $nextTuesday); }elseif($togodate == "so"){ $date->modify('next sunday'); #$nextday = date('Y-m-d', $nextTuesday); }else{ $ausgabedate = "error"; } $nextday = $date->format('Y-m-d'); $i=0; while($i < 4){ if($i!=0){ #$nextday = date('Y-m-d', strtotime($nextday .' +7 day')); // Create a new DateTime object $currentDate = new DateTime($nextday); $datetempz = $currentDate->add(new DateInterval('P7D')); //Get yesterday date $nextday = $datetempz->format('Y-m-d'); } $statementuser = $pdo->prepare("SELECT terminid FROM togo_termin WHERE date=:date AND start=:start AND end=:end AND standort=:standort"); $statementuser->execute(array('date' => $nextday , 'start' => $togostart, 'end' => $togoende , 'standort' => $standort )); $count = $statementuser->rowCount(); if($count == 0){ $insert = $pdo->prepare("INSERT INTO togo_termin (date, start, end,standort,error,warning) VALUES (:date, :start, :end,:standort, :error, :warning)"); $insert->execute(array('date' => $nextday , 'start' => $togostart, 'end' => $togoende , 'standort' => $standort, 'error' => $error , 'warning' => $warning )); $userid = $pdo->lastInsertId(); } $i++; } } } function show_header($titeltext){ echo ' '. $titeltext .' '; include('meta.inc'); echo '