Some SQLs rewritten, unneccessary parameter removed
authorRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2009 10:53:22 +0000 (10:53 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2009 10:53:22 +0000 (10:53 +0000)
16 files changed:
inc/autopurge/purge-general.php
inc/autopurge/purge-inact.php
inc/autopurge/purge-mails.php
inc/autopurge/purge-tsks.php
inc/autopurge/purge-unconfirmed.php
inc/extensions-functions.php
inc/extensions/ext-autopurge.php
inc/functions.php
inc/libs/bonus_functions.php
inc/libs/holiday_functions.php
inc/libs/rallye_functions.php
inc/libs/transfer_functions.php
inc/modules/admin/what-config_register.php
inc/modules/admin/what-list_bank_package.php
inc/modules/admin/what-list_links.php
inc/modules/guest/what-sponsor_login.php

index 3702659..9bb2cea 100644 (file)
@@ -113,7 +113,7 @@ ORDER BY
        // Is the 'bonus' extension installed and activated?
        if (isExtensionActive('bonus', true)) {
                // Check for bonus campaigns
-               $result = SQL_QUERY_ESC("SELECT `id`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `data_type`='SEND' AND timestamp <= %s ORDER BY `id`",
+               $result = SQL_QUERY_ESC("SELECT `id`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `data_type`='SEND' AND `timestamp` <= %s ORDER BY `id` ASC",
                        array(bigintval($PURGE)), __FILE__, __LINE__);
                if (SQL_NUMROWS($result) > 0) {
                        // Start deleting procedure
@@ -153,7 +153,7 @@ ORDER BY
        // Add points from deleted accounts to jackpot, but here just add to notify mail
        if ($admin_points > 0) {
                // Send mail to admin
-               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_SUBJECT'), 'admin_autopurge_points', translateComma($admin_points), 0);
+               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_SUBJECT'), 'admin_autopurge_points', translateComma($admin_points));
        } // END - if
 
        // Run all SQLs here
index eb5bc27..b4b9ae0 100644 (file)
@@ -114,7 +114,7 @@ ORDER BY
                $useridsContent = str_replace(', ', "\n", substr($useridsContent, 0, -2));
 
                // Send mail notification to admin
-               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_INACTIVE_SUBJECT'), 'admin_autopurge_inactive', $useridsContent, '');
+               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_INACTIVE_SUBJECT'), 'admin_autopurge_inactive', $useridsContent);
        } // END - if
 
        // Free memory
@@ -154,7 +154,7 @@ ORDER BY `userid` ASC",
 
                // Send mail notification to admin
                if (getConfig('ap_in_notify') == 'Y') {
-                       sendAdminNotification(getMessage('AUTOPURGE_ADMIN_DELETE_SUBJECT'), 'admin_autopurge_delete', $useridsContent, '');
+                       sendAdminNotification(getMessage('AUTOPURGE_ADMIN_DELETE_SUBJECT'), 'admin_autopurge_delete', $useridsContent);
                } // END - if
        } // END - if
 
index 29f1349..5236d22 100644 (file)
@@ -131,7 +131,7 @@ SQL_FREERESULT($result_mails);
 // Do we have deleted mails and the admin want's to receive a notification
 if (($deletedStats > 0) && (getConfig('ap_dm_notify') == 'Y')) {
        // Send out email to admin
-       sendAdminNotification(getMessage('AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT'), 'admin_autopurge_del_mails', $deletedStats, '');
+       sendAdminNotification(getMessage('AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT'), 'admin_autopurge_del_mails', $deletedStats);
 } // END - if
 
 //
index 708c880..40de412 100644 (file)
@@ -47,8 +47,8 @@ if ((!isExtensionActive('autopurge')) || (getConfig('auto_purge_active') != 'Y')
        return false;
 } // END - if
 
-// Check version (must be > 0.0)
-if ((isExtensionInstalledAndNewer('task') > '0.0') && (getConfig('autopurge_tasks') == 'Y')) {
+// Check version (must be >= 0.1.9)
+if ((isExtensionInstalledAndNewer('task', '0.1.9')) && (getConfig('autopurge_tasks') == 'Y')) {
        // Purge deleted tasks (no notification to admin)
        SQL_QUERY("DELETE LOW_PRIORITY
 FROM
@@ -63,7 +63,7 @@ WHERE
        // Do we need to send a notification?
        if (($deletedTasks > 0) && (getConfig('ap_tasks_notify') == 'Y')) {
                // Send out email to admin
-               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_TASKS_SUBJECT'), 'admin_autopurge_tsks', $deletedTasks, '');
+               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_TASKS_SUBJECT'), 'admin_autopurge_tsks', $deletedTasks);
        } // END - if
 } // END - if
 
index faa5b76..5957945 100644 (file)
@@ -80,7 +80,7 @@ ORDER BY
 
                // Send mail notification to admin
                if (getConfig('ap_un_notify') == 'Y') {
-                       sendAdminNotification(getMessage('AUTOPURGE_ADMIN_UNCONFIRMED_SUBJECT'), 'admin_autopurge_unconfirmed', $userids, '');
+                       sendAdminNotification(getMessage('AUTOPURGE_ADMIN_UNCONFIRMED_SUBJECT'), 'admin_autopurge_unconfirmed', $userids);
                } // END - if
        } // END - if
 
index b342187..001aee7 100644 (file)
@@ -866,7 +866,7 @@ function doDeactivateExtension($ext_name) {
 
                // Notify the admin
                sendAdminNotification(
-               getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
+                       getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
                        'admin_ext_deactivated',
                        array('ext_name' => $ext_name)
                );
index 49cd3b9..20aec9b 100644 (file)
@@ -80,13 +80,12 @@ switch (getExtensionMode()) {
                break;
 
        case 'update': // Update an extension
-               switch (getCurrentExtensionVersion())
-               {
+               switch (getCurrentExtensionVersion()) {
                        case '0.1.0': // SQL queries for v0.1
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD autopurge_inactive ENUM('Y','N') NOT NULL DEFAULT 'Y'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD autopurge_unconfirmed ENUM('Y','N') NOT NULL DEFAULT 'Y'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD ap_inactive_since BIGINT(20) UNSIGNED NOT NULL DEFAULT '2592000'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD ap_inactive_time BIGINT(20) UNSIGNED NOT NULL DEFAULT '25200'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `autopurge_inactive` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `autopurge_unconfirmed` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_inactive_since` BIGINT(20) UNSIGNED NOT NULL DEFAULT '2592000'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_inactive_time` BIGINT(20) UNSIGNED NOT NULL DEFAULT '25200'");
                                addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_unconfirmed_time` BIGINT(20) UNSIGNED NOT NULL DEFAULT '432000'");
                                addAdminMenuSql('setup','config_autopurge','Auto-L&ouml;schung','Automatisch inaktive oder nicht best&auml;tigte Accounts l&ouml;schen.',12);
                                addAdminMenuSql('user','list_autopurge','Inaktive finden','Lassen Sie sich vor dem t&auml;glichen Reset anzeigen, welche Mitglieder als inaktiv erkannt werden und welche gel&ouml;scht werden.',10);
@@ -128,17 +127,17 @@ switch (getExtensionMode()) {
                                break;
 
                        case '0.1.9': // SQL queries for v0.1.9
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD autopurge_tasks ENUM('Y','N') NOT NULL DEFAULT 'Y'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD ap_tasks_time BIGINT(20) UNSIGNED NOT NULL DEFAULT '".(getConfig('ONE_DAY')*7)."'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `autopurge_tasks` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_tasks_time` BIGINT(20) UNSIGNED NOT NULL DEFAULT '".(getConfig('ONE_DAY')*7)."'");
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Bereinigung von zu l&ouml;schenden Aufgaben klappt wieder. Zeitlimit f&uuml;r genanntes kann eingestellt werden (Default = 7 Tage).<br /><br /><u>Bitte aktualisieren Sie auch die Admin-Templates!</u>");
                                break;
 
                        case '0.2.0': // SQL queries for v0.2.0
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD ap_in_notify ENUM('Y','N') NOT NULL DEFAULT 'Y'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD ap_un_notify ENUM('Y','N') NOT NULL DEFAULT 'Y'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD ap_tasks_notify ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_in_notify` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_un_notify` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_tasks_notify` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Mail wird bei L&ouml;schung von Aufgaben ausgesendet.<br /><br /><u>Bitte aktualisieren Sie auch die Admin-Templates!</u>");
@@ -205,9 +204,9 @@ switch (getExtensionMode()) {
                                break;
 
                        case '0.3.3': // SQL queries for v0.3.3
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD ap_del_mails ENUM('Y','N') NOT NULL DEFAULT 'Y'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD ap_dm_notify ENUM('Y','N') NOT NULL DEFAULT 'Y'");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD ap_dm_timeout BIGINT(20) UNSIGNED NOT NULL DEFAULT '86400'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_del_mails` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_dm_notify` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `ap_dm_timeout` BIGINT(20) UNSIGNED NOT NULL DEFAULT '86400'");
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Von bereits gel&ouml;schten Mitgliedern die Mails l&ouml;schen integriert.");
index 80bdad0..f9bdf90 100644 (file)
@@ -3845,7 +3845,7 @@ function sendModeMails ($mod, $modes) {
                        $content = getMessage('CANNOT_SEND_ADMIN_MAILS');
                } else {
                        // No mail to admin
-                       $content = "<span class=\"member_done\">{--MYDATA_MAIL_SENT--}</span>";
+                       $content = '<span class="member_done">{--MYDATA_MAIL_SENT--}</span>';
                }
        } // END - if
 
index 2730199..74e1686 100644 (file)
@@ -280,7 +280,7 @@ function purgeExpiredTurboBonus() {
 
        if (SQL_AFFECTEDROWS() > 0) {
                // Send out email to admin
-               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_TURBO_SUBJECT'), 'admin_autopurge_turbo', SQL_AFFECTEDROWS(), '');
+               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_TURBO_SUBJECT'), 'admin_autopurge_turbo', SQL_AFFECTEDROWS());
        } // END - if
 }
 
index dd8a45b..90c119f 100644 (file)
@@ -90,7 +90,7 @@ LIMIT 1",
                } // END - if
 
                // Send mail to admins
-               sendAdminNotification(getMessage('HOLIDAY_ADMIN_UNLOCK_SUBJ'), 'admin_holiday_unlock', $admin, 0);
+               sendAdminNotification(getMessage('HOLIDAY_ADMIN_UNLOCK_SUBJ'), 'admin_holiday_unlock', $admin);
 
                // Run all SQLs
                runFilterChain('run_sqls');
index 84f3716..a804da7 100644 (file)
@@ -140,7 +140,7 @@ VALUES (%s, %s, %s, %s)",
        if ($notify == 'Y') $templ = 'admin_rallye_notify';
 
        // Send email to admin
-       sendAdminNotification(getMaskedMessage('RALLYE_ADMIN_NOTIFY', $title), $templ, $prices, 0);
+       sendAdminNotification(getMaskedMessage('RALLYE_ADMIN_NOTIFY', $title), $templ, $prices);
 
        // Free memory
        SQL_FREERESULT($result_user);
@@ -510,7 +510,7 @@ LIMIT 1",
        }
 
        // Send mail to admin
-       sendAdminNotification(getMaskedMessage('RALLYE_ADMIN_EXPIRED_SUBJ', $title), $templ, $cnt, 0);
+       sendAdminNotification(getMaskedMessage('RALLYE_ADMIN_EXPIRED_SUBJ', $title), $templ, $cnt);
 
        // Add task
        createNewTask('{--RALLYE_ADMIN_EXPIRED--}: ' . $title, '{--RALLYE_ADMIN_EXPIRED_TEXT--}', 'RALLYE_EXPIRED');
@@ -733,7 +733,7 @@ WHERE end_time <= (UNIX_TIMESTAMP() - {?ONE_DAY?} - %s) AND expired='Y'",
                        $content['now_time']    = generateDateTime(time(), 1);
 
                        // Send mail to admin
-                       sendAdminNotification(getMaskedMessage('RALLYE_ADMIN_PURGED_SUBJ', $content['title']), 'admin_rallye_purged', $content, 0);
+                       sendAdminNotification(getMaskedMessage('RALLYE_ADMIN_PURGED_SUBJ', $content['title']), 'admin_rallye_purged', $content);
 
                        // Purge whole rallye
                        addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_data` WHERE `id`=%s LIMIT 1",
index 54b7a17..c61e7a6 100644 (file)
 // Some security stuff...
 if (!defined('__SECURITY')) {
        die();
-}
+} // END - if
 
-//
-function autoPurgeTransfers($max, $age) {
+// Purge expired transfer entries
+function autoPurgeTransfers ($max, $age) {
        // First get total in-going lines
-       $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_transfers_in` ORDER BY `id`", __FUNCTION__, __LINE__);
+       $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_transfers_in` ORDER BY `id` ASC", __FUNCTION__, __LINE__);
        if (SQL_NUMROWS($result) > $max) {
                // Update overdue transfers
                $remove = SQL_NUMROWS($result) - $max;
 
                // This will make it really old, so the final removal query will find it
-               $result = SQL_QUERY("UPDATE `{?_MYSQL_PREFIX?}_user_transfers_in` SET `time_trans`=0 ORDER BY `id` LIMIT ".$remove, __FUNCTION__, __LINE__);
-       }
+               $result = SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_transfers_in` SET `time_trans`=0 ORDER BY `id` LIMIT %s"
+                       array($remove), __FUNCTION__, __LINE__);
+       } // END - if
 
        // Second get total out-going lines
-       $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` ORDER BY `id`", __FUNCTION__, __LINE__);
+       $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` ORDER BY `id` ASC", __FUNCTION__, __LINE__);
        if (SQL_NUMROWS($result) > $max) {
                // Update overdue transfers
                $remove = SQL_NUMROWS($result) - $max;
 
                // This will make it really old, so the final removal query will find it
-               $result = SQL_QUERY("UPDATE `{?_MYSQL_PREFIX?}_user_transfers_out` SET `time_trans`=0 ORDER BY `id` LIMIT ".$remove, __FUNCTION__, __LINE__);
-       }
+               $result = SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_transfers_out` SET `time_trans`=0 ORDER BY `id` LIMIT %s"
+                       array($remove), __FUNCTION__, __LINE__);
+       } // END - if
 
        // Remove old in-going transfers
-       $result = SQL_QUERY("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_transfers_in` WHERE time_trans < (UNIX_TIMESTAMP() - ".$age.")", __FUNCTION__, __LINE__);
-       $REMOVE = SQL_AFFECTEDROWS();
+       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_transfers_in` WHERE `time_trans` < (UNIX_TIMESTAMP() - %s)",
+               array($age), __FUNCTION__, __LINE__);
+       $removed = SQL_AFFECTEDROWS();
 
        // Remove old out-going transfers
-       $result = SQL_QUERY("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE time_trans < (UNIX_TIMESTAMP() - ".$age.")", __FUNCTION__, __LINE__);
-       $REMOVE += SQL_AFFECTEDROWS();
+       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE `time_trans` < (UNIX_TIMESTAMP() - %s)",
+               array($age), __FUNCTION__, __LINE__);
+       $removed += SQL_AFFECTEDROWS();
 
        // Only send email to admin(s) when we have removed entries
-       if ($REMOVE > 0) {
-               sendAdminNotification(TRANSFER_ADMIN_AUTOPURGE, "admin_transfer_ap", $REMOVE, 0);
-       }
+       if ($removed > 0) {
+               sendAdminNotification(getMessage('TRANSFER_ADMIN_AUTOPURGE'), 'admin_transfer_ap', $removed);
+       } // END - if
 }
-//
+
+// [EOF]
 ?>
index 2249983..41ab4b8 100644 (file)
@@ -54,7 +54,7 @@ if (isFormSent()) {
 }
 
 // List all register values
-$result = SQL_QUERY("SELECT id, field_name, field_required FROM `{?_MYSQL_PREFIX?}_must_register` ORDER BY `id`", __FILE__, __LINE__);
+$result = SQL_QUERY("SELECT id, field_name, field_required FROM `{?_MYSQL_PREFIX?}_must_register` ORDER BY `id` ASC", __FILE__, __LINE__);
 $OUT = ''; $SW = 2;
 while ($content = SQL_FETCHARRAY($result)) {
        // Get language string
index 66b701d..a5519e2 100644 (file)
@@ -80,7 +80,7 @@ if ($show === false) return;
 // Load all banking packages from DB
 $result = SQL_QUERY("SELECT id, title, description, account_fee AS 'fee', package_active AS 'active', interest_plus AS 'plus', interest_minus AS 'minus'
 FROM `{?_MYSQL_PREFIX?}_bank_packages`
-ORDER BY `id`", __FILE__, __LINE__);
+ORDER BY `id` ASC", __FILE__, __LINE__);
 
 // Is there at lease one package?
 if (SQL_NUMROWS($result) > 0) {
index cd186ce..513997d 100644 (file)
@@ -56,7 +56,7 @@ if (isGetRequestParameterSet('userid')) {
                // @TODO Try to rewrite this to a filter
                if (isExtensionActive('bonus')) {
                        // Load bonus id
-                       $result = SQL_QUERY_ESC("SELECT `stats_id`, `bonus_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `id`",
+                       $result = SQL_QUERY_ESC("SELECT `stats_id`, `bonus_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `id` ASC",
                                array(bigintval(getRequestParameter('userid'))), __FILE__, __LINE__);
                } else {
                        // Load stats id (2nd will be ignored later! But it is needed for the same fetchrow command)
index 3bfc7d1..dc7d228 100644 (file)
@@ -73,28 +73,28 @@ WHERE
 LIMIT 1", array(getRequestParameter('hash')), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) == 1) {
                // Sponsor found, load his data...
-               $SPONSOR = SQL_FETCHARRAY($result);
+               $data = SQL_FETCHARRAY($result);
 
                // Translate gender and comma
-               $SPONSOR['gender']  = translateGender($SPONSOR['gender']);
-               $SPONSOR['points'] = translateComma($SPONSOR['points']);
-               $SPONSOR['pay']    = translateComma($SPONSOR['pay']);
+               $data['gender']  = translateGender($data['gender']);
+               $data['points'] = translateComma($data['points']);
+               $data['pay']    = translateComma($data['pay']);
 
                // Unconfirmed account or changed email address?
-               if ($SPONSOR['status'] == 'UNCONFIRMED') {
+               if ($data['status'] == 'UNCONFIRMED') {
                        // Set account to pending
                        SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `status`='PENDING'
 WHERE `id`='%s' AND hash='%s' AND `status`='UNCONFIRMED' LIMIT 1",
-                       array(bigintval($SPONSOR['id']), getRequestParameter('hash')), __FILE__, __LINE__);
+                       array(bigintval($data['id']), getRequestParameter('hash')), __FILE__, __LINE__);
 
                        // Check on success
                        if (SQL_AFFECTEDROWS() == 1) {
                                // Prepare mail and send it to the sponsor
-                               $message = loadEmailTemplate('sponsor_pending', $SPONSOR);
-                               sendEmail($SPONSOR['email'], getMessage('SPONSOR_ACCOUNT_PENDING_SUBJ'), $message);
+                               $message = loadEmailTemplate('sponsor_pending', $data);
+                               sendEmail($data['email'], getMessage('SPONSOR_ACCOUNT_PENDING_SUBJ'), $message);
 
                                // Send email to admin
-                               sendAdminNotification(getMessage('ADMIN_NEW_SPONSOR'), 'admin_sponsor_pending', $SPONSOR);
+                               sendAdminNotification(getMessage('ADMIN_NEW_SPONSOR'), 'admin_sponsor_pending', $data);
 
                                // Sponsor account set to pending
                                loadTemplate('admin_settings_saved', false, getMessage('SPONSOR_ACCOUNT_IS_PENDING'));
@@ -102,11 +102,18 @@ WHERE `id`='%s' AND hash='%s' AND `status`='UNCONFIRMED' LIMIT 1",
                                // Could not unlock account!
                                loadTemplate('admin_settings_saved', false, getMessage('SPONSOR_ACCOUNT_PENDING_FAILED'));
                        }
-               } elseif ($SPONSOR['status'] == 'EMAIL') {
+               } elseif ($data['status'] == 'EMAIL') {
                        // Changed email adress need to be confirmed
-                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `status`='CONFIRMED'
-WHERE `id`='%s' AND hash='%s' AND `status`='EMAIL' LIMIT 1",
-                       array(bigintval($SPONSOR['id']), getRequestParameter('hash')), __FILE__, __LINE__);
+                       SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_sponsor_data`
+SET
+       `status`='CONFIRMED'
+WHERE
+       `id`='%s' AND
+       `hash`='%s' AND
+       `status`='EMAIL'
+LIMIT 1",
+                               array(bigintval($data['id']), getRequestParameter('hash')), __FILE__, __LINE__);
 
                        // Check on success
                        if (SQL_AFFECTEDROWS() == 1) {
@@ -144,19 +151,19 @@ WHERE email='%s' AND (`status`='UNCONFIRMED' OR `status`='EMAIL') LIMIT 1",
                // Entry found?
                if (SQL_NUMROWS($result) == 1) {
                        // Unconfirmed sponsor account found so let's load the requested data
-                       $SPONSOR = SQL_FETCHARRAY($result);
+                       $data = SQL_FETCHARRAY($result);
 
                        // Translate some data
-                       $SPONSOR['gender']           = translateGender($SPONSOR['gender']);
-                       $SPONSOR['sponsor_created'] = generateDateTime($SPONSOR['sponsor_created']);
+                       $data['gender']          = translateGender($data['gender']);
+                       $data['sponsor_created'] = generateDateTime($data['sponsor_created']);
 
                        // Prepare email and send it to the sponsor
-                       if ($SPONSOR['status'] == 'UNCONFIRMED') {
+                       if ($data['status'] == 'UNCONFIRMED') {
                                // Unconfirmed accounts
-                               $message_sponsor = loadEmailTemplate('sponsor_activate', $SPONSOR);
+                               $message_sponsor = loadEmailTemplate('sponsor_activate', $data);
                        } else {
                                // Confirmed email address
-                               $message_sponsor = loadEmailTemplate('sponsor_email', $SPONSOR);
+                               $message_sponsor = loadEmailTemplate('sponsor_email', $data);
                        }
                        sendEmail(postRequestParameter('email'), getMessage('SPONSOR_ACTIVATION_LINK_SUBJ'), $message_sponsor);
 
@@ -193,7 +200,7 @@ WHERE `email`='%s' AND `id`='%s' AND `status`='CONFIRMED' LIMIT 1",
                        $DATA = SQL_FETCHARRAY($result);
 
                        // Translate some data
-                       $DATA['gender']           = translateGender($DATA['gender']);
+                       $DATA['gender']          = translateGender($DATA['gender']);
                        $DATA['sponsor_created'] = generateDateTime($DATA['sponsor_created']);
 
                        // Generate password