]> git.mxchange.org Git - mailer.git/commitdiff
isEmailTaken() now relaxes if e.g. the current user just changed other data
authorRoland Häder <roland@mxchange.org>
Mon, 15 Aug 2011 11:43:04 +0000 (11:43 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 15 Aug 2011 11:43:04 +0000 (11:43 +0000)
inc/mysql-manager.php

index c2387e336dad3eaef53316d07a6f4acb002eb7eb..a836da97b41a42ca7edd20f597e140d45faf0807 100644 (file)
@@ -660,21 +660,40 @@ function addMaxReceiveList ($mode, $default = '', $return = false) {
 
 // Checks wether the given email address is used.
 function isEmailTaken ($email) {
+       // Default is no userid
+       $useridSql = ' IS NOT NULL';
+
+       // Is a member logged in?
+       if (isMember()) {
+               // Get userid
+               $useridSql = '!= ' . bigintval(getMemberId());
+       } // END - if
+
        // Replace dot with {DOT}
        $email = str_replace('.', '{DOT}', $email);
 
        // Query the database
-       $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `email` LIKE '%%%s%%' LIMIT 1",
-               array($email), __FUNCTION__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT
+       COUNT(`userid`) AS `cnt`
+FROM
+       `{?_MYSQL_PREFIX?}_user_data`
+WHERE
+       REGEX '%s' `email` AND
+       `userid` %s
+LIMIT 1",
+               array(
+                       $email,
+                       $useridSql
+               ), __FUNCTION__, __LINE__);
 
        // Is the email there?
-       $isTaken = (SQL_NUMROWS($result) == 1);
+       list($count) = SQL_FETCHROW($result);
 
        // Free the result
        SQL_FREERESULT($result);
 
        // Return result
-       return $isTaken;
+       return ($count == 1);
 }
 
 // Validate the given menu action
@@ -897,7 +916,7 @@ function getPaymentPoints ($pid, $lookFor = 'price') {
 }
 
 // Remove a receiver's id from $receivers and add a link for him to confirm
-function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = 0, $isBonusMail = false) {
+function removeReceiver (&$receivers, $key, $userid, $poolId, $statsId = 0, $isBonusMail = false) {
        // Default is not removed
        $ret = 'failed';
 
@@ -907,7 +926,7 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = 0, $i
                unset($receivers[$key]);
 
                // Is there already a line for this user available?
-               if ($stats_id > 0) {
+               if ($statsId > 0) {
                        // Default is 'normal' mail
                        $type = 'NORMAL';
                        $rowName = 'stats_id';
@@ -919,20 +938,30 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = 0, $i
                        } // END - if
 
                        // Try to look the entry up
-                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE %s='%s' AND `userid`=%s AND link_type='%s' LIMIT 1",
-                               array($rowName, $stats_id, bigintval($userid), $type), __FUNCTION__, __LINE__);
+                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s AND `userid`=%s AND link_type='%s' LIMIT 1",
+                               array(
+                                       $rowName,
+                                       bigintval($statsId),
+                                       bigintval($userid),
+                                       $type
+                               ), __FUNCTION__, __LINE__);
 
                        // Was it *not* found?
                        if (SQL_HASZERONUMS($result)) {
                                // So we add one!
                                SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_links` (`%s`,`userid`,`link_type`) VALUES ('%s','%s','%s')",
-                                       array($rowName, $stats_id, bigintval($userid), $type), __FUNCTION__, __LINE__);
+                                       array(
+                                               $rowName,
+                                               bigintval($statsId),
+                                               bigintval($userid),
+                                               $type
+                                       ), __FUNCTION__, __LINE__);
 
                                // Update 'mails_sent' if sql_patches is updated
                                if (isExtensionInstalledAndNewer('sql_patches', '0.7.4')) {
                                        // Update the pool
                                        SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `mails_sent`=`mails_sent`+1 WHERE `id`=%s LIMIT 1",
-                                               array(bigintval($pool_id)), __FUNCTION__, __LINE__);
+                                               array(bigintval($poolId)), __FUNCTION__, __LINE__);
                                } // END - if
                                $ret = 'done';
                        } else {