192 lines
7.1 KiB
PHP
192 lines
7.1 KiB
PHP
<?php #lib/main.php
|
|
|
|
/********************************************************************************
|
|
* Content: email related functions *
|
|
* Author: Nils Otterpohl *
|
|
********************************************************************************/
|
|
|
|
function emlSendEmail($to, $subject, $text) {
|
|
global $mail;
|
|
|
|
$mail->setFrom(MAILNOREPLY, "Webserver OF Innenstadt");
|
|
$mail->isHTML(true);
|
|
$mail->Subject = $subject;
|
|
$mail->Body = $text;
|
|
$mail->addAddress($to);
|
|
$mail->send();
|
|
$mail->clearAddresses();
|
|
}
|
|
|
|
|
|
// string $email
|
|
// array $prenames
|
|
// array $surnames
|
|
// string $password
|
|
function emlSendInvitation($email, $invites, $password) {
|
|
global $mail;
|
|
|
|
$mail->setFrom(MAILNOREPLY, "Sophia und Nils Hochzeitswebsite");
|
|
$mail->addAddress($email);
|
|
|
|
$mail->isHTML(true);
|
|
$mail->Subject = "Einladung zur Hochzeit von Sophia und Nils";
|
|
|
|
$tpl = tplLoadFile("res/invitation.html");
|
|
$text = tplExtrSection($tpl, "###INVITATION###");
|
|
$to_tpl = tplExtrSection($text, "###TO###");
|
|
$to = "";
|
|
$count = 0;
|
|
foreach ($invites as $names) {
|
|
if ($names["companion"]==0) {
|
|
$count++;
|
|
$replace = array(
|
|
"###ADDRESSING###" => $names["addressing"],
|
|
"###PRENAMES###" => $names["prenames"],
|
|
"###SURNAMES###" => $names["surnames"],
|
|
"###NICKNAME###" => $names["nickname"]=="" ? $names["prenames"] : $names["nickname"]
|
|
);
|
|
$to.= tplReplMarkerArray($to_tpl, $replace);
|
|
}
|
|
}
|
|
$text = tplReplSection($text, "###TO###", $to);
|
|
$text = tplReplSection($text, "###INTRO###", $count>1 ? tplExtrSection($tpl, "###INTRO.MULTI###") : tplExtrSection($tpl, "###INTRO.SINGLE###"));
|
|
$text = tplReplSection($text, "###EXPLANATION###", $count>1 ? tplExtrSection($tpl, "###EXPLANATION.MULTI###") : tplExtrSection($tpl, "###EXPLANATION.SINGLE###"));
|
|
$text = tplReplSection($text, "###MULTIPLEASE###", $count>1 ? tplExtrSection($tpl, "###MULTIPLEASE###") : "");
|
|
$url = parse_url("https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
|
|
$text = tplReplMarker($text, "###PAGEURL###", "https://".$url["host"].$url["path"]);
|
|
$text = tplReplMarker($text, "###EMAIL###", $email);
|
|
$text = tplReplMarker($text, "###PASSWORD###", $password);
|
|
|
|
$mail->Body = $text;
|
|
|
|
|
|
$attachments = explode(";", tplExtrSection($tpl, "###ATTACHMENTS###"));
|
|
foreach ($attachments as $attachment) {
|
|
if ($attachment!="") {
|
|
$attributes = explode("|", $attachment);
|
|
if (count($attributes)>1 && $attributes[0]=="embedded") {
|
|
$mail->addEmbeddedImage($attributes[1].$attributes[2], $attributes[3], $attributes[2]);
|
|
} else {
|
|
$mail->addAttachment($attachment);
|
|
}
|
|
}
|
|
}
|
|
//$mail->addEmbeddedImage("res/Einladung.png", "cid_einladung", "Einladung.png");
|
|
|
|
$mail->send();
|
|
$mail->clearAddresses();
|
|
$mail->clearAttachments();
|
|
return true;
|
|
}
|
|
|
|
// mysql_con mysqli
|
|
// string subject
|
|
// string text
|
|
// int notificationLvl : {1: Neuer Thread, 2: Neue Nachricht}
|
|
// string neededRecipientRight
|
|
function emlSendNotification($mysqli, $sendUser, $subject, $text, $notificationLvl, $neededRecipientRight = null) {
|
|
global $mail;
|
|
|
|
$mail->setFrom(MAILNOREPLY, "Sophia und Nils Hochzeitswebsite");
|
|
$mail->isHTML(false);
|
|
$mail->Subject = $subject;
|
|
$to_tpl = tplExtrSection($text, "###TO###");
|
|
|
|
$qry = "SELECT DISTINCT u.email, u.groupID FROM users u "
|
|
.($neededRecipientRight!==null ? "LEFT JOIN rolerights rr ON rr.roleID=u.roleID LEFT JOIN rights r ON r.ID=rr.rightID " : "")
|
|
."WHERE u.ID!=".$sendUser." AND u.notifications>=".$notificationLvl." ".($neededRecipientRight!==null ? "AND r.name='".$neededRecipientRight."' " : "");
|
|
$res = $mysqli->query($qry);
|
|
while ($row = $res->fetch_assoc()) {
|
|
$nameres = $mysqli->query("SELECT prenames `###PRENAMES###`, surnames `###SURNAMES###`, addressing `###ADDRESSING###`, IFNULL(nickname, prenames) `###NICKNAME###` "
|
|
."FROM guests WHERE companion=0 AND groupID=".$row["groupID"]);
|
|
$to = "";
|
|
while ($namerow = $nameres->fetch_assoc()) {
|
|
$to.= tplReplMarkerArray($to_tpl, $namerow);
|
|
}
|
|
$mail->Body = tplReplSection($text, "###TO###", $to);
|
|
$mail->addAddress($row["email"]);
|
|
$mail->send();
|
|
$mail->clearAddresses();
|
|
}
|
|
}
|
|
|
|
// Sendet eine Mail an ALLE User (die nicht abgesagt haben)
|
|
// mysql_con mysqli
|
|
// int sendUser
|
|
// string from
|
|
// string subject
|
|
// string text
|
|
// string neededRecipientRight
|
|
function emlSendMassMail($mysqli, $sendUser, $from, $subject, $text, $neededRecipientRight = null) {
|
|
global $mail;
|
|
|
|
if (!$res = $mysqli->query("SELECT DISTINCT IFNULL(u.eMailFrom, u.email) email FROM users u WHERE u.ID=".$sendUser))
|
|
addError("Mysql", $mysqli->error);
|
|
$from_mail = $res->fetch_assoc()["email"];
|
|
$mail->setFrom($from_mail, $from);
|
|
|
|
$mail->isHTML(true);
|
|
$mail->Subject = $subject;
|
|
$to_tpl = tplExtrSection($text, "###TO###");
|
|
|
|
$qry = "SELECT DISTINCT u.email, u.groupID FROM guests g LEFT JOIN users u ON u.groupID=g.groupID "
|
|
.($neededRecipientRight!==null ? "LEFT JOIN rolerights rr ON rr.roleID=u.roleID LEFT JOIN rights r ON r.ID=rr.rightID " : "")
|
|
."WHERE u.ID!=".$sendUser." AND IFNULL(g.comes, 99)!=0 ".($neededRecipientRight!==null ? "AND r.name='".$neededRecipientRight."' " : "");
|
|
$res = $mysqli->query($qry);
|
|
while ($row = $res->fetch_assoc()) {
|
|
$tores = $mysqli->query("SELECT prenames `###PRENAMES###`, surnames `###SURNAMES###`, addressing `###ADDRESSING###`, IFNULL(nickname, prenames) `###NICKNAME###` "
|
|
."FROM guests WHERE companion=0 AND groupID=".$row["groupID"]);
|
|
$to = "";
|
|
while ($torow = $tores->fetch_assoc()) {
|
|
$to.= tplReplMarkerArray($to_tpl, $torow);
|
|
}
|
|
$mail->Body = tplReplSection($text, "###TO###", $to);
|
|
$mail->addAddress($row["email"]);
|
|
$mail->send();
|
|
$mail->clearAddresses();
|
|
}
|
|
}
|
|
|
|
// Sendet eine Mail an EINEN User
|
|
// mysql_con mysqli
|
|
// int targetUser
|
|
// string subject
|
|
// string text
|
|
function emlSendSingleMail($mysqli, $targetUser, $subject, $text) {
|
|
global $mail;
|
|
$ret = false;
|
|
|
|
$targetMail = null;
|
|
$groupID = null;
|
|
if ($stmt = $mysqli->prepare("SELECT email, groupID FROM users u WHERE u.ID = ?")) {
|
|
$stmt->bind_param("i", $targetUser);
|
|
$stmt->execute();
|
|
$stmt->bind_result($targetMail, $groupID);
|
|
$stmt->fetch();
|
|
$stmt->close();
|
|
} else {
|
|
addError("Mysql", $mysqli->error);
|
|
}
|
|
if ($targetMail!=null && $groupID!=null) {
|
|
$mail->setFrom(MAILNOREPLY, "Sophia und Nils Hochzeitswebsite");
|
|
|
|
$mail->isHTML(true);
|
|
$mail->Subject = $subject;
|
|
$to_tpl = tplExtrSection($text, "###TO###");
|
|
|
|
$tores = $mysqli->query("SELECT prenames `###PRENAMES###`, surnames `###SURNAMES###`, addressing `###ADDRESSING###`, IFNULL(nickname, prenames) `###NICKNAME###` "
|
|
."FROM guests WHERE companion=0 AND groupID=".$groupID);
|
|
$to = "";
|
|
while ($torow = $tores->fetch_assoc()) {
|
|
$to.= tplReplMarkerArray($to_tpl, $torow);
|
|
}
|
|
$mail->Body = tplReplSection($text, "###TO###", $to);
|
|
$mail->addAddress($targetMail);
|
|
$mail->send();
|
|
$mail->clearAddresses();
|
|
$ret = true;
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
?>
|