Required fix for NULL vs. 0 in user_points
[mailer.git] / inc / functions.php
index f081487413227ab8189e5ac200a387235e8d91da..333de57fec72d155269ce177afa46889ae7a78b7 100644 (file)
@@ -85,23 +85,21 @@ function getTotalFatalErrors () {
 // Send mail out to an email address
 function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '') {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'toEmail=' . $toEmail . ',subject=' . $subject . ',isHtml=' . $isHtml);
+       // Empty parameters should be avoided, so we need to find them
+       if (empty($isHtml)) {
+               // isHtml is empty
+               debug_report_bug(__FUNCTION__, __LINE__, 'isHtml is empty.');
+       } // END - if
 
        // Set from header
        if ((!isInStringIgnoreCase('@', $toEmail)) && ($toEmail > 0)) {
-               // Value detected, is the message extension installed?
-               // @TODO Extension 'msg' does not exist
-               if (isExtensionActive('msg')) {
-                       ADD_MESSAGE_TO_BOX($toEmail, $subject, $message, $isHtml);
-                       return;
+               // Does the user exist?
+               if ((isExtensionActive('user')) && (fetchUserData($toEmail))) {
+                       // Get the email
+                       $toEmail = getUserData('email');
                } else {
-                       // Does the user exist?
-                       if (fetchUserData($toEmail)) {
-                               // Get the email
-                               $toEmail = getUserData('email');
-                       } else {
-                               // Set webmaster
-                               $toEmail = getWebmaster();
-                       }
+                       // Set webmaster
+                       $toEmail = getWebmaster();
                }
        } elseif ($toEmail == '0') {
                // Is the webmaster!
@@ -130,11 +128,6 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
                }
        } // END - if
 
-       // Fix HTML parameter (default is no!)
-       if (empty($isHtml)) {
-               $isHtml = 'N';
-       } // 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
@@ -273,7 +266,7 @@ function generatePassword ($length = '0', $exclude =  array()) {
 // Generates a human-readable timestamp from the Uni* stamp
 function generateDateTime ($time, $mode = '0') {
        // If the stamp is zero it mostly didn't "happen"
-       if ($time == '0') {
+       if (($time == '0') || (is_null($time))) {
                // Never happend
                return '{--NEVER_HAPPENED--}';
        } // END - if
@@ -945,7 +938,7 @@ function scrambleString ($str) {
        // Init
        $scrambled = '';
 
-       // Final check, in case of failture it will return unscrambled string
+       // Final check, in case of failure it will return unscrambled string
        if (strlen($str) > 40) {
                // The string is to long
                return $str;
@@ -2158,18 +2151,18 @@ function handleFieldWithBraces ($field) {
 }
 
 // Converts a userid so it can be used in SQL queries
-function makeDatabaseUserId ($userid) {
+function makeZeroToNull ($number) {
        // Is it a valid username?
-       if (isValidUserId($userid)) {
+       if ((!is_null($number)) && ($number > 0)) {
                // Always secure it
-               $userid = bigintval($userid);
+               $number = bigintval($number);
        } else {
                // Is not valid or zero
-               $userid = 'NULL';
+               $number = 'NULL';
        }
 
        // Return it
-       return $userid;
+       return $number;
 }
 
 // Capitalizes a string with underscores, e.g.: some_foo_string will become SomeFooString
@@ -2367,6 +2360,37 @@ function getReferalId () {
        return $GLOBALS['refid'];
 }
 
+// Converts a boolean variable into 'Y' for true and 'N' for false
+function convertBooleanToYesNo ($boolean) {
+       // Default is 'N'
+       $converted = 'N';
+       if ($boolean === true) {
+               // Set 'Y'
+               $converted = 'Y';
+       } // END - if
+
+       // Return it
+       return $converted;
+}
+
+// Translates task type to a human-readable version
+function translateTaskType ($taskType) {
+       // Construct message id
+       $messageId = 'ADMIN_TASK_TYPE_' . strtoupper($taskType) . '';
+
+       // Is the message id there?
+       if (isMessageIdValid($messageId)) {
+               // Then construct message
+               $message = '{--' . $messageId . '--}';
+       } else {
+               // Else it is an unknown task type
+               $message = '{%message,ADMIN_TASK_TYPE_UNKNOWN=' . $taskType . '%}';
+       } // END - if
+
+       // Return message
+       return $message;
+}
+
 //-----------------------------------------------------------------------------
 // Automatically re-created functions, all taken from user comments on www.php.net
 //-----------------------------------------------------------------------------