Skip to content

Commit a204303

Browse files
author
Florian Schaal
committed
moved "function send_notification_email" from 300-quota_notify.inc.php to monitor_tools.inc.php
1 parent 559b657 commit a204303

File tree

2 files changed

+60
-65
lines changed

2 files changed

+60
-65
lines changed

server/lib/classes/cron.d/300-quota_notify.inc.php

Lines changed: 7 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -50,64 +50,6 @@ public function onBeforeRun() {
5050
public function onRunJob() {
5151
global $app, $conf;
5252

53-
//########
54-
// function for sending notification emails
55-
//########
56-
function send_notification_email($template, $placeholders, $recipients) {
57-
global $conf;
58-
59-
if(!is_array($recipients) || count($recipients) < 1) return false;
60-
if(!is_array($placeholders)) $placeholders = array();
61-
62-
if(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt')) {
63-
$lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt');
64-
} elseif(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt')) {
65-
$lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt');
66-
} elseif(file_exists($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt')) {
67-
$lines = file($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt');
68-
} else {
69-
$lines = file($conf['rootpath'].'/conf/mail/' . $template . '_en.txt');
70-
}
71-
72-
//* get mail headers, subject and body
73-
$mailHeaders = '';
74-
$mailBody = '';
75-
$mailSubject = '';
76-
$inHeader = true;
77-
for($l = 0; $l < count($lines); $l++) {
78-
if($lines[$l] == '') {
79-
$inHeader = false;
80-
continue;
81-
}
82-
if($inHeader == true) {
83-
$parts = explode(':', $lines[$l], 2);
84-
if(strtolower($parts[0]) == 'subject') $mailSubject = trim($parts[1]);
85-
unset($parts);
86-
$mailHeaders .= trim($lines[$l]) . "\n";
87-
} else {
88-
$mailBody .= trim($lines[$l]) . "\n";
89-
}
90-
}
91-
$mailBody = trim($mailBody);
92-
93-
//* Replace placeholders
94-
$mailHeaders = strtr($mailHeaders, $placeholders);
95-
$mailSubject = strtr($mailSubject, $placeholders);
96-
$mailBody = strtr($mailBody, $placeholders);
97-
98-
for($r = 0; $r < count($recipients); $r++) {
99-
mail($recipients[$r], $mailSubject, $mailBody, $mailHeaders);
100-
}
101-
102-
unset($mailSubject);
103-
unset($mailHeaders);
104-
unset($mailBody);
105-
unset($lines);
106-
107-
return true;
108-
}
109-
110-
11153
//######################################################################################################
11254
// enforce traffic quota (run only on the "master-server")
11355
//######################################################################################################
@@ -170,7 +112,7 @@ function send_notification_email($template, $placeholders, $recipients) {
170112
}
171113
}
172114

173-
send_notification_email('web_traffic_notification', $placeholders, $recipients);
115+
$this->_tools->send_notification_email('web_traffic_notification', $placeholders, $recipients);
174116
}
175117

176118
} else {
@@ -290,7 +232,7 @@ function send_notification_email($template, $placeholders, $recipients) {
290232
$recipients[] = $client['email'];
291233
}
292234
}
293-
send_notification_email('web_quota_ok_notification', $placeholders, $recipients);
235+
$this->_tools->send_notification_email('web_quota_ok_notification', $placeholders, $recipients);
294236
}
295237
} else {
296238

@@ -325,7 +267,7 @@ function send_notification_email($template, $placeholders, $recipients) {
325267
$recipients[] = $client['email'];
326268
}
327269
}
328-
send_notification_email('web_quota_notification', $placeholders, $recipients);
270+
$this->_tools->send_notification_email('web_quota_notification', $placeholders, $recipients);
329271
}
330272
}
331273
}
@@ -419,7 +361,7 @@ function send_notification_email($template, $placeholders, $recipients) {
419361
}
420362
}
421363

422-
send_notification_email('mail_quota_ok_notification', $placeholders, $recipients);
364+
$this->_tools->send_notification_email('mail_quota_ok_notification', $placeholders, $recipients);
423365
}
424366
} else {
425367

@@ -454,7 +396,7 @@ function send_notification_email($template, $placeholders, $recipients) {
454396
}
455397
}
456398

457-
send_notification_email('mail_quota_notification', $placeholders, $recipients);
399+
$this->_tools->send_notification_email('mail_quota_notification', $placeholders, $recipients);
458400
}
459401
}
460402
}
@@ -534,7 +476,7 @@ function send_notification_email($template, $placeholders, $recipients) {
534476
if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '')
535477
$recipients[] = $client['email'];
536478

537-
send_notification_email('db_quota_ok_notification', $placeholders, $recipients);
479+
$this->_tools->send_notification_email('db_quota_ok_notification', $placeholders, $recipients);
538480

539481
}
540482

@@ -566,7 +508,7 @@ function send_notification_email($template, $placeholders, $recipients) {
566508
if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '')
567509
$recipients[] = $client['email'];
568510

569-
send_notification_email('db_quota_notification', $placeholders, $recipients);
511+
$this->_tools->send_notification_email('db_quota_notification', $placeholders, $recipients);
570512

571513
}
572514

server/lib/classes/monitor_tools.inc.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,59 @@ public function delOldRecords($type, $serverId) {
656656
$app->dbmaster->query($sql);
657657
}
658658

659+
public function send_notification_email($template, $placeholders, $recipients) {
660+
global $conf;
661+
662+
if(!is_array($recipients) || count($recipients) < 1) return false;
663+
if(!is_array($placeholders)) $placeholders = array();
664+
665+
if(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt')) {
666+
$lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt');
667+
} elseif(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt')) {
668+
$lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt');
669+
} elseif(file_exists($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt')) {
670+
$lines = file($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt');
671+
} else {
672+
$lines = file($conf['rootpath'].'/conf/mail/' . $template . '_en.txt');
673+
}
674+
675+
//* get mail headers, subject and body
676+
$mailHeaders = '';
677+
$mailBody = '';
678+
$mailSubject = '';
679+
$inHeader = true;
680+
for($l = 0; $l < count($lines); $l++) {
681+
if($lines[$l] == '') {
682+
$inHeader = false;
683+
continue;
684+
}
685+
if($inHeader == true) {
686+
$parts = explode(':', $lines[$l], 2);
687+
if(strtolower($parts[0]) == 'subject') $mailSubject = trim($parts[1]);
688+
unset($parts);
689+
$mailHeaders .= trim($lines[$l]) . "\n";
690+
} else {
691+
$mailBody .= trim($lines[$l]) . "\n";
692+
}
693+
}
694+
$mailBody = trim($mailBody);
695+
696+
//* Replace placeholders
697+
$mailHeaders = strtr($mailHeaders, $placeholders);
698+
$mailSubject = strtr($mailSubject, $placeholders);
699+
$mailBody = strtr($mailBody, $placeholders);
700+
701+
for($r = 0; $r < count($recipients); $r++) {
702+
mail($recipients[$r], $mailSubject, $mailBody, $mailHeaders);
703+
}
704+
705+
unset($mailSubject);
706+
unset($mailHeaders);
707+
unset($mailBody);
708+
unset($lines);
709+
710+
return true;
711+
}
659712

660713
}
661714

0 commit comments

Comments
 (0)