From a204303e5099dcb88e5e4760a09e7de9a96c4ea3 Mon Sep 17 00:00:00 2001
From: Florian Schaal <florian@schaal-24.de>
Date: Fri, 17 Oct 2014 08:05:51 -0400
Subject: [PATCH] moved "function send_notification_email" from 300-quota_notify.inc.php to monitor_tools.inc.php

---
 server/lib/classes/monitor_tools.inc.php           |   53 +++++++++++++++++
 server/lib/classes/cron.d/300-quota_notify.inc.php |   72 ++---------------------
 2 files changed, 60 insertions(+), 65 deletions(-)

diff --git a/server/lib/classes/cron.d/300-quota_notify.inc.php b/server/lib/classes/cron.d/300-quota_notify.inc.php
index a60f774..f18394c 100644
--- a/server/lib/classes/cron.d/300-quota_notify.inc.php
+++ b/server/lib/classes/cron.d/300-quota_notify.inc.php
@@ -50,64 +50,6 @@
 	public function onRunJob() {
 		global $app, $conf;
 
-		//########
-		// function for sending notification emails
-		//########
-		function send_notification_email($template, $placeholders, $recipients) {
-			global $conf;
-
-			if(!is_array($recipients) || count($recipients) < 1) return false;
-			if(!is_array($placeholders)) $placeholders = array();
-
-			if(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt')) {
-				$lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt');
-			} elseif(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt')) {
-				$lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt');
-			} elseif(file_exists($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt')) {
-				$lines = file($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt');
-			} else {
-				$lines = file($conf['rootpath'].'/conf/mail/' . $template . '_en.txt');
-			}
-
-			//* get mail headers, subject and body
-			$mailHeaders = '';
-			$mailBody = '';
-			$mailSubject = '';
-			$inHeader = true;
-			for($l = 0; $l < count($lines); $l++) {
-				if($lines[$l] == '') {
-					$inHeader = false;
-					continue;
-				}
-				if($inHeader == true) {
-					$parts = explode(':', $lines[$l], 2);
-					if(strtolower($parts[0]) == 'subject') $mailSubject = trim($parts[1]);
-					unset($parts);
-					$mailHeaders .= trim($lines[$l]) . "\n";
-				} else {
-					$mailBody .= trim($lines[$l]) . "\n";
-				}
-			}
-			$mailBody = trim($mailBody);
-
-			//* Replace placeholders
-			$mailHeaders = strtr($mailHeaders, $placeholders);
-			$mailSubject = strtr($mailSubject, $placeholders);
-			$mailBody = strtr($mailBody, $placeholders);
-
-			for($r = 0; $r < count($recipients); $r++) {
-				mail($recipients[$r], $mailSubject, $mailBody, $mailHeaders);
-			}
-
-			unset($mailSubject);
-			unset($mailHeaders);
-			unset($mailBody);
-			unset($lines);
-
-			return true;
-		}
-
-
 		//######################################################################################################
 		// enforce traffic quota (run only on the "master-server")
 		//######################################################################################################
@@ -170,7 +112,7 @@
 								}
 							}
 
-							send_notification_email('web_traffic_notification', $placeholders, $recipients);
+							$this->_tools->send_notification_email('web_traffic_notification', $placeholders, $recipients);
 						}
 
 					} else {
@@ -290,7 +232,7 @@
 									$recipients[] = $client['email'];
 								}
 							}
-							send_notification_email('web_quota_ok_notification', $placeholders, $recipients);
+							$this->_tools->send_notification_email('web_quota_ok_notification', $placeholders, $recipients);
 						}
 					} else {
 
@@ -325,7 +267,7 @@
 									$recipients[] = $client['email'];
 								}
 							}
-							send_notification_email('web_quota_notification', $placeholders, $recipients);
+							$this->_tools->send_notification_email('web_quota_notification', $placeholders, $recipients);
 						}
 					}
 				}
@@ -419,7 +361,7 @@
 								}
 							}
 
-							send_notification_email('mail_quota_ok_notification', $placeholders, $recipients);
+							$this->_tools->send_notification_email('mail_quota_ok_notification', $placeholders, $recipients);
 						}
 					} else {
 
@@ -454,7 +396,7 @@
 								}
 							}
 
-							send_notification_email('mail_quota_notification', $placeholders, $recipients);
+							$this->_tools->send_notification_email('mail_quota_notification', $placeholders, $recipients);
 						}
 					}
 				}
@@ -534,7 +476,7 @@
 										if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '') 
 											$recipients[] = $client['email'];
 
-										send_notification_email('db_quota_ok_notification', $placeholders, $recipients);
+										$this->_tools->send_notification_email('db_quota_ok_notification', $placeholders, $recipients);
 
 									}
 
@@ -566,7 +508,7 @@
 									if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '')
 										$recipients[] = $client['email'];
 
-									send_notification_email('db_quota_notification', $placeholders, $recipients);
+									$this->_tools->send_notification_email('db_quota_notification', $placeholders, $recipients);
 
 								}
 
diff --git a/server/lib/classes/monitor_tools.inc.php b/server/lib/classes/monitor_tools.inc.php
index d754097..98a8c3f 100644
--- a/server/lib/classes/monitor_tools.inc.php
+++ b/server/lib/classes/monitor_tools.inc.php
@@ -656,6 +656,59 @@
 		$app->dbmaster->query($sql);
 	}
 
+	public function send_notification_email($template, $placeholders, $recipients) {
+		global $conf;
+
+		if(!is_array($recipients) || count($recipients) < 1) return false;
+		if(!is_array($placeholders)) $placeholders = array();
+
+		if(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt')) {
+			$lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_'.$conf['language'].'.txt');
+		} elseif(file_exists($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt')) {
+			$lines = file($conf['rootpath'].'/conf-custom/mail/' . $template . '_en.txt');
+		} elseif(file_exists($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt')) {
+			$lines = file($conf['rootpath'].'/conf/mail/' . $template . '_'.$conf['language'].'.txt');
+		} else {
+			$lines = file($conf['rootpath'].'/conf/mail/' . $template . '_en.txt');
+		}
+
+		//* get mail headers, subject and body
+		$mailHeaders = '';
+		$mailBody = '';
+		$mailSubject = '';
+		$inHeader = true;
+		for($l = 0; $l < count($lines); $l++) {
+			if($lines[$l] == '') {
+				$inHeader = false;
+				continue;
+			}
+			if($inHeader == true) {
+				$parts = explode(':', $lines[$l], 2);
+				if(strtolower($parts[0]) == 'subject') $mailSubject = trim($parts[1]);
+				unset($parts);
+				$mailHeaders .= trim($lines[$l]) . "\n";
+			} else {
+				$mailBody .= trim($lines[$l]) . "\n";
+			}
+		}
+		$mailBody = trim($mailBody);
+
+		//* Replace placeholders
+		$mailHeaders = strtr($mailHeaders, $placeholders);
+		$mailSubject = strtr($mailSubject, $placeholders);
+		$mailBody = strtr($mailBody, $placeholders);
+
+		for($r = 0; $r < count($recipients); $r++) {
+			mail($recipients[$r], $mailSubject, $mailBody, $mailHeaders);
+		}
+
+		unset($mailSubject);
+		unset($mailHeaders);
+		unset($mailBody);
+		unset($lines);
+
+		return true;
+	}
 
 }
 

--
Gitblit v1.9.1