-
Notifications
You must be signed in to change notification settings - Fork 4
/
ElternMailSenderCron.class.php
147 lines (95 loc) · 4.5 KB
/
ElternMailSenderCron.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* Sendet die Elternmailnachrichten
* @author Christian
*
*/
class ElternMailSenderCron extends AbstractCron {
private $isDebug = true;
private $sendPerRound = 20;
private $mailsSent = 0;
public function __construct() {
}
public function execute() {
if(DB::getGlobalSettings()->schulnummer != "9400") {
$mails = Message::getUnsentMailsViaEMail();
for($i = 0; $i < sizeof($mails); $i++) {
if($this->mailsSent > 100) break; // Maximal 100 Mails pro Runde vorbereiten.
$user = $mails[$i]->getUser();
if($user != null && $user->getEMail() != '' && $user->receiveEMail()) {
// Mail senden
$betreff = DB::getGlobalSettings()->siteNamePlain . " - Neue Nachricht";
if(!$mails[$i]->isConfidential()) $betreff .= "- " . $mails[$i]->getSubject();
// MailID und MailSecret jetzt immer mit senden, damit man auf die Nachricht mittels Mailprogramm antworten kann.
$betreff .= " - [" . $mails[$i]->getID() . "]";
$betreff .= " {" . $mails[$i]->getConfirmationSecret() . "}";
$subject = $mails[$i]->getSubject();
if($mails[$i]->getSender() != null) $sender = $mails[$i]->getSender()->getDisplayName();
else $sender = null;
$attachmentsHTML = "";
if($mails[$i]->hasAttachment()) {
$attachments = $mails[$i]->getAttachments();
for($a = 0; $a < sizeof($attachments); $a++) {
$attachmentsHTML .= "Anhang" . ($a+1) . ": <a href=\"" . DB::getGlobalSettings()->urlToIndexPHP . "?page=MessageAttachmentDownload&aid=" . $attachments[$a]->getID() . "&ac=" . $attachments[$a]->getAccessCode() . "\">" . $attachments[$a]->getUpload()->getFileName() . "</a><br />";
}
}
$needConfirm = $mails[$i]->needConfirmation();
$confirmLink = DB::getGlobalSettings()->urlToIndexPHP . "?page=MessageConfirm&mailID=" . $mails[$i]->getID() . "&a=" . $mails[$i]->getConfirmationSecret();
$unsubscribeLink = DB::getGlobalSettings()->urlToIndexPHP . "?index.php?page=userprofile";
$messageText = $mails[$i]->getText();
$allowAnswer = $mails[$i]->allowAnswer();
$hasQuestions = $mails[$i]->hasQuestions();
$questionHTML = "<ul>";
$questions = $mails[$i]->getQuestions();
for($q = 0; $q < sizeof($questions); $q++) {
$questionHTML .= "<li>" . $questions[$q]->getQuestionText() . "</li>";
}
$questionHTML .= "</ul>";
$replyOrForwardText = "";
if($mails[$i]->getReplyMessage() !== null) {
// Antwort Nachricht
$replyOrForwardText = $mails[$i]->getReplyMessage()->getText();
}
if($mails[$i]->getForwardMessage() !== null) {
$replyOrForwardText = $mails[$i]->getForwardMessage()->getText();
}
$myRecipient = "";
if($mails[$i]->getMyRecipient() !== null) {
$myRecipient = $mails[$i]->getMyRecipient()->getDisplayName();
}
if($mails[$i]->isConfidential()) $isConfidential = true;
else $isConfidential = false;
$mailHTML = "";
eval("\$mailHTML = \"" . DB::getTPL()->get("messages/send/emailnewmessage") . "\";");
$mail = new email($user->getEMail(), $betreff, $mailHTML);
$mail->isHTML();
if($mails[$i]->needConfirmation() && !$mails[$i]->hasQuestions()) $mail->setLesebestaetigung();
$mail->send();
$this->mailsSent++;
}
$mails[$i]->setSentViaMail();
}
}
}
public function getName() {
return "E-Mails vorbereiten";
}
public function getDescription() {
return "Bereitet den Versand von Benachrichtigungen an Eltern / Lehrer / Schüler und andere Personen vor.";
}
/**
*
*
* @return ['success' => 'true/false', 'resultText' => 'Text, der in der Administration angezeigt wird.']
*/
public function getCronResult() {
return ['success' => true, 'resultText' => $this->mailsSent . " verarbeitet."];
}
public function informAdminIfFail() {
return false;
}
public function executeEveryXSeconds() {
return 120; // alle zwei Minunten ausführen
}
}
?>