]> git.mxchange.org Git - mailer.git/blobdiff - inc/email-functions.php
Renamed more:
[mailer.git] / inc / email-functions.php
index ced06aa03725df374534e08ab6966f8f6daadd92..7731595ae4163e39aa19ea5a535ab6a2ecd3002e 100644 (file)
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Mailversand bezogene Funktionen                  *
  * -------------------------------------------------------------------- *
- * $Revision:: 2773                                                   $ *
- * $Date:: 2012-06-26 01:02:44 +0200 (Tue, 26 Jun 2012)               $ *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
- * $Author:: quix0r                                                   $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -59,7 +59,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
                        // Set webmaster
                        $toEmail = getWebmaster();
                }
-       } elseif ($toEmail == '0') {
+       } elseif (($toEmail == '0') || (is_null($toEmail))) {
                // Is the webmaster!
                $toEmail = getWebmaster();
        }
@@ -81,17 +81,21 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
        } // END - if
 
        // Debug mode enabled?
-       if (isDebugModeEnabled()) {
-               // In debug mode we want to display the mail instead of sending it away so we can debug this part
-               outputHtml('<pre>
-<strong>Headers</strong> : ' . htmlentities(trim($mailHeader)) . '
-<strong>To</strong>      : ' . htmlentities($toEmail) . '
-<strong>Subject</strong> : ' . htmlentities($subject) . '
-<strong>Message(' . strlen($message) . ')</strong> : ' . htmlentities($message) . '
-</pre>');
+       if ((isDebugModeEnabled()) && (!isAjaxOutputMode())) {
+               // Init content array
+               $content = array(
+                       'headers' => htmlentities(trim($mailHeader)),
+                       'to'      => htmlentities($toEmail),
+                       'subject' => htmlentities($subject),
+                       'message' => htmlentities($message),
+                       'length'  => strlen($message)
+               );
+
+               // In debug mode display the mail instead of sending it away so it can be debugged
+               loadTemplate('display_email', FALSE, $content);
 
                // This is always fine
-               return true;
+               return TRUE;
        } elseif (!empty($toEmail)) {
                // Send Mail away
                return sendRawEmail($toEmail, $subject, $message, $mailHeader);
@@ -116,12 +120,12 @@ function isPhpMailerConfigured () {
 // Send out a raw email with PHPMailer class or plain mail() command
 function sendRawEmail ($toEmail, $subject, $message, $headers) {
        // Just compile all to put out all configs, etc.
-       $eval  = '$toEmail = decodeEntities("' . escapeQuotes(doFinalCompilation(compileRawCode($toEmail), false)) . '"); ';
-       $eval .= '$subject = decodeEntities("' . escapeQuotes(doFinalCompilation(compileRawCode($subject), false)) . '"); ';
-       $eval .= '$headers = decodeEntities("' . escapeQuotes(doFinalCompilation(compileRawCode($headers), false)) . '"); ';
+       $eval  = '$toEmail = decodeEntities("' . escapeQuotes(doFinalCompilation(compileRawCode($toEmail), FALSE)) . '"); ';
+       $eval .= '$subject = decodeEntities("' . escapeQuotes(doFinalCompilation(compileRawCode($subject), FALSE)) . '"); ';
+       $eval .= '$headers = decodeEntities("' . escapeQuotes(doFinalCompilation(compileRawCode($headers), FALSE)) . '"); ';
 
        // Do not decode entities in the message because we also send HTML mails through this function
-       $eval .= '$message = "' . escapeQuotes(doFinalCompilation(compileRawCode($message), false)) . '";';
+       $eval .= '$message = "' . escapeQuotes(doFinalCompilation(compileRawCode($message), FALSE)) . '";';
 
        // Run the final eval() command
        eval($eval);
@@ -142,7 +146,7 @@ function sendRawEmail ($toEmail, $subject, $message, $headers) {
                $mail->PluginDir  = sprintf("%sinc/phpmailer/", getPath());
 
                $mail->IsSMTP();
-               $mail->SMTPAuth   = true;
+               $mail->SMTPAuth   = TRUE;
                $mail->Host       = getConfig('SMTP_HOSTNAME');
                $mail->Port       = 25;
                $mail->Username   = getConfig('SMTP_USER');
@@ -158,7 +162,7 @@ function sendRawEmail ($toEmail, $subject, $message, $headers) {
                        $mail->Body       = $message;
                        $mail->AltBody    = decodeEntities($message);
                        $mail->WordWrap   = 70;
-                       $mail->IsHTML(true);
+                       $mail->IsHTML(TRUE);
                } else {
                        $mail->Body       = decodeEntities(strip_tags($message));
                }
@@ -176,10 +180,10 @@ function sendRawEmail ($toEmail, $subject, $message, $headers) {
                        logDebugMessage(__FUNCTION__, __LINE__, 'Error while sending mail: ' . $mail->ErrorInfo);
 
                        // Raise an error
-                       return false;
+                       return FALSE;
                } else {
                        // All fine!
-                       return true;
+                       return TRUE;
                }
        } else {
                // Use plain mail() command
@@ -201,6 +205,54 @@ function sendAdminNotification ($subject, $templateName, $content = array(), $us
        }
 }
 
+// Send mails for del/edit/lock build modes
+// @TODO $rawUserId is currently unused
+function sendGenericBuildMails ($mode, $tableName, $content, $id, $subjectPart = '', $userIdColumn = array('userid'), $rawUserId = array('userid')) {
+       // $tableName must be an array
+       if ((!is_array($tableName)) || (count($tableName) != 1)) {
+               // $tableName is no array
+               reportBug(__FUNCTION__, __LINE__, 'tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn);
+       } elseif ((!is_array($userIdColumn)) || (count($userIdColumn) != 1)) {
+               // $tableName is no array
+               reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn);
+       } // END - if
+
+       // Default subject is the subject part
+       $subject = $subjectPart;
+
+       // Is the subject part not set?
+       if (empty($subjectPart)) {
+               // Then use it from the mode
+               $subject = strtoupper($mode);
+       } // END - if
+
+       // Is the raw userid set?
+       if (isValidId(postRequestElement($userIdColumn[0], $id))) {
+               // Set it in content
+               $content[$userIdColumn[0]] = bigintval(postRequestElement($userIdColumn[0], $id));
+
+               // Load email template
+               if (!empty($subjectPart)) {
+                       $mail = loadEmailTemplate('member_' . $mode . '_' . strtolower($subjectPart) . '_' . $tableName[0], $content);
+               } else {
+                       $mail = loadEmailTemplate('member_' . $mode . '_' . $tableName[0], $content);
+               }
+
+               // Send email out
+               sendEmail(postRequestElement($userIdColumn[0], $id), strtoupper('{--MEMBER_' . $subject . '_' . $tableName[0] . '_SUBJECT--}'), $mail);
+       } // END - if
+
+       // Generate subject
+       $subject = strtoupper('{--ADMIN_' . $subject . '_' . $tableName[0] . '_SUBJECT--}');
+
+       // Send admin notification out
+       if (!empty($subjectPart)) {
+               sendAdminNotification($subject, 'admin_' . $mode . '_' . strtolower($subjectPart) . '_' . $tableName[0], $content, postRequestElement($userIdColumn[0], $id));
+       } else {
+               sendAdminNotification($subject, 'admin_' . $mode . '_' . $tableName[0], $content, postRequestElement($userIdColumn[0], $id));
+       }
+}
+
 // ----------------------------------------------------------------------------
 //                           Template helper functions
 // ----------------------------------------------------------------------------