Rewrites/fixes for while() loops with merge_array() and SQL_FETCHARRAY() usage
authorRoland Häder <roland@mxchange.org>
Sun, 14 Feb 2010 12:20:43 +0000 (12:20 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 14 Feb 2010 12:20:43 +0000 (12:20 +0000)
14 files changed:
inc/autopurge/purge-inact.php
inc/autopurge/purge-unconfirmed.php
inc/db/lib-mysql3.php
inc/language/holiday_de.php
inc/libs/rallye_functions.php
inc/mails/beg_mails.php
inc/modules/admin/what-add_points.php
inc/modules/admin/what-list_cats.php
inc/modules/admin/what-list_refs.php
inc/modules/admin/what-sub_points.php
inc/modules/member/what-holiday.php
inc/modules/order.php
inc/reset/reset_100_bonus.php
inc/reset/reset_holiday.php

index 38fbc334cce7affbf04def7a52f54531c5acfc72..ae1d8907b5bcc9bc898b9959f12e79cf6fb9c4b3 100644 (file)
@@ -96,7 +96,10 @@ ORDER BY
                $content['time']  = (getConfig('ap_inactive_time')  / 60 / 60);
 
                // Mark found accounts as inactive and send an email
-               while ($content = merge_array($content, SQL_FETCHARRAY($result_inactive))) {
+               while ($row = SQL_FETCHARRAY($result_inactive)) {
+                       // Merge both arrays
+                       $content = merge_array($content, $row);
+
                        // Remember userids for the admin
                        $useridsContent .= $content['userid'].", ";
 
index bb4e920ab0bf366407497ff88d162de9b67acdda..e6276a98ce45b01d22bdb21a140312622d31029e 100644 (file)
@@ -65,7 +65,10 @@ ORDER BY
                $content['time'] = (getConfig('ap_unconfirmed_time')  / 60 / 60);
 
                // Delete inactive accounts
-               while ($content = merge_array($content, SQL_FETCHARRAY($result_uncon))) {
+               while ($row = SQL_FETCHARRAY($result_uncon)) {
+                       // Merge both arrays
+                       $content = merge_array($content, $row);
+
                        // Remember userids for the admin
                        $userids .= $content['userid'] . ', ';
 
index 7f5a297c64642679265ab14be06f0452a9861131..a3b5af0dd2bd8c8c9879f84ef051f17255253e85 100644 (file)
@@ -201,7 +201,7 @@ function SQL_FETCHARRAY ($res, $nr=0, $remove_numerical=true) {
                // Return row
                return $row;
        } else {
-               // Return a false here...
+               // Return a false, else some loops would go endless...
                return false;
        }
 }
index 51dd55fdaee9b701d023f1a6946b2e3c7ca286b8..c46e47b49c5ce627caf929815a55ac1db75ebce5 100644 (file)
@@ -81,8 +81,9 @@ addMessages(array(
        'HOLIDAY_ADMIN_MODE' => "Zeitpunkt der Abarbeitung der Urlaubsschaltungen",
        'HOLIDAY_ADMIN_MODE_RESET' => "Am t&auml;glichen Reset um 00:00 Uhr",
        'HOLIDAY_ADMIN_MODE_DIRECT' => "Sofort nach Beantragung pr&uuml;fen",
+       'HOLIDAY_MEMBER_NOT_STOPPED_404' => "Beim Beenden Ihres Urlaubes ist ein unerwarteter Fehler aufgetreten: Mitglieder-Id <span class=\"data\">%s</span> nicht gefunden.",
 
-// Subject lines
+       // Subject lines
        'HOLIDAY_MEMBER_SUBJECT' => "[HINWEIS:] Ihre Urlaubsanfrage",
        'HOLIDAY_ADMIN_SUBJECT' => "Urlaubsanfrage in Ihrem {?mt_word?}",
        'HOLIDAY_MEMBER_UNLOCK_SUBJ' => "[HINWEIS:] Beendigung Ihres Urlaubes",
index 5526567afe1615b3510e381820f45065b1963dfb..0744b6b32c535c3083d4084007623ebc4d669a5a 100644 (file)
@@ -73,7 +73,10 @@ function autostartReferalRallyes ($result) {
        $result_user = SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' ORDER BY `userid` ASC", __FUNCTION__, __LINE__);
 
        // Let's begin with the userids...
-       while ($content = merge_array($content, SQL_FETCHARRAY($result_user))) {
+       while ($row = SQL_FETCHARRAY($result_user)) {
+               // Merge both arrays
+               $content = merge_array($content, $row);
+
                $un = false;
 
                // Get refs by userid
index 7712f5fb574aa6ca74659634c337bd8fa02950a4..b9a65e462f446f22abd062ef175723a3f375a6a2 100644 (file)
@@ -103,7 +103,10 @@ if (!empty($sql)) {
                $receiver = ''; $userids = array();
 
                // Okay lets notify all users!
-               while ($content = merge_array($content, SQL_FETCHARRAY($result_main))) {
+               while ($row = SQL_FETCHARRAY($result_main)) {
+                       // Merge arrays
+                       $content = merge_array($content, $row);
+
                        // Update account
                        SQL_QUERY_ESC("UPDATE
        `{?_MYSQL_PREFIX?}_user_data`
index fe7baa722f4d9aa524005eb7766b5242867ff2c8..f3465c23017eb1cecaa1e8dada4eecba212d2638 100644 (file)
@@ -56,7 +56,10 @@ if (getRequestParameter('userid') == 'all') {
                        __FILE__, __LINE__);
 
                // Process all entries
-               while ($content = merge_array($content, SQL_FETCHARRAY($result_main))) {
+               while ($row = SQL_FETCHARRAY($result_main)) {
+                       // Merge both arrays
+                       $content = merge_array($content, $row);
+
                        // Remove depth to prevent booking errors. This is a bad coding
                        // practice, thats also why we need to write this project from
                        // scratch...
index 23cdb66c6b232c3c165c4527ac0854d48c8e9147..96f23cf4860a4718dbe7098bb7a6460b320f0d90 100644 (file)
@@ -64,7 +64,10 @@ if (isGetRequestParameterSet('userid')) {
                if (SQL_NUMROWS($result_cats) > 0) {
                        // List categories
                        $cnt = 1; $OUT = ''; $SW = 2;
-                       while ($content = merge_array($content, SQL_FETCHARRAY($result_cats))) {
+                       while ($row = SQL_FETCHARRAY($result_cats)) {
+                               // Merge both arrays
+                               $content = merge_array($content, $row);
+
                                // Check user's selection
                                $result_user = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1",
                                        array(bigintval(getRequestParameter('userid')), bigintval($content['id'])), __FILE__, __LINE__);
@@ -84,7 +87,7 @@ if (isGetRequestParameterSet('userid')) {
                        } // END - while
 
                        // Free memory
-                       SQL_FREERESULT($result);
+                       SQL_FREERESULT($result_cats);
 
                        // Remember all rows in the array
                        $content['rows'] = $OUT;
index 7318e7b92a04a2ebc990bf3a9df211b642d67a83..59b60815796002e38f98f86a5ffb574dc47b932d 100644 (file)
@@ -60,7 +60,7 @@ if (isGetRequestParameterSet('userid')) {
                $menge_lck = countSumTotalData($userid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
 
                // Output info message
-               loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_USER_TOTAL_REFS', generateUserProfileLink(getRequestParameter('userid')), $menge, $menge_lck));
+               loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink(getRequestParameter('userid')), $menge, $menge_lck));
 
                // Load all referal levels
                $result_levels = SQL_QUERY("SELECT
@@ -137,7 +137,7 @@ ORDER BY
                                                } // END - while
                                        } else {
                                                // Output info message
-                                               $levels['info'] = getMaskedMessage('ADMIN_USER_TOTAL_REFS', generateUserProfileLink($userid), 0, 0);
+                                               $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($userid), 0, 0);
 
                                                // No refs found
                                                $levels['rows'] = loadTemplate('admin_list_refs_norefs', true, array('userid' => $userid));
@@ -178,8 +178,8 @@ ORDER BY
 
                        // Prepare content
                        $content = array(
-                               'rows' => $OUT,
-                               'userid'  => generateUserProfileLink(getRequestParameter('userid'))
+                               'rows'   => $OUT,
+                               'userid' => generateUserProfileLink(getRequestParameter('userid'))
                        );
 
                        // Load main template
index 661dd3ff4dd601f941974601881df09c2e7efb14..9667e9be6a20fc4f173d29470c3394ac31898085 100644 (file)
@@ -46,14 +46,18 @@ if ((!defined('__SECURITY')) || (!isAdmin())) {
 addMenuDescription('admin', __FILE__);
 
 if (getRequestParameter('userid') == 'all') {
-       // Add points to all accounts
-       $content['points'] = bigintval(postRequestParameter('points'));
-
        // Is the form sent?
        if ((isFormSent()) && (postRequestParameter('points') > 0)) {
+               // Add points to all accounts
+               $content['points'] = bigintval(postRequestParameter('points'));
+
+               // Load userid
                $result_main = SQL_QUERY("SELECT userid, email FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' ORDER BY `userid` ASC",
                        __FILE__, __LINE__);
-               while ($content = merge_array($content, SQL_FETCHARRAY($result_main))) {
+               while ($row = SQL_FETCHARRAY($result_main)) {
+                       // Merge both arrays
+                       $content = merge_array($content, $row);
+
                        // Ok, add points to used points and send an email to him...
                        subtractPoints('admin_all', $content['userid'], postRequestParameter('points'));
 
index 63a5ed54b22720520a0d29b06ce106adb06e0740..209ad00787beb478c9d39f52260ac0e82ec1ea6f 100644 (file)
@@ -168,58 +168,70 @@ FROM
 WHERE
        `userid`=%s
 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
-       $content = merge_array($content, SQL_FETCHARRAY($result));
-       SQL_FREERESULT($result);
 
-       if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + getConfig('holiday_lock')) < time())) {
-               // Load data
-               $result = SQL_QUERY_ESC("SELECT
+       // Do we have an entry?
+       if (SQL_NUMROWS($result) == 1) {
+               // Merge arrays
+               $content = merge_array($content, SQL_FETCHARRAY($result));
+
+               if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + getConfig('holiday_lock')) < time())) {
+                       // Load data
+                       $result2 = SQL_QUERY_ESC("SELECT
        `holiday_start`, `holiday_end`
 FROM
        `{?_MYSQL_PREFIX?}_user_holidays`
 WHERE
        `userid`=%s
 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) == 1) {
-                       // Data was found
-                       $content = merge_array($content, SQL_FETCHARRAY($result));
-                       SQL_FREERESULT($result);
+                       if (SQL_NUMROWS($result2) == 1) {
+                               // Data was found so merge it
+                               $content = merge_array($content, SQL_FETCHARRAY($result2));
 
-                       // Prepare it for the template
-                       $content['start'] = generateDateTime($content['holiday_start'], 3);
-                       $content['end']   = generateDateTime($content['holiday_end']  , 3);
+                               // Prepare it for the template
+                               $content['start'] = generateDateTime($content['holiday_start'], 3);
+                               $content['end']   = generateDateTime($content['holiday_end']  , 3);
 
-                       // Deactivate it now
-                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data`
+                               // Deactivate it now
+                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data`
 SET
        `holiday_active`='N',
        `holiday_activated`=0
 WHERE
        `userid`=%s
 LIMIT 1",
-                               array(getMemberId()), __FILE__, __LINE__);
+                                       array(getMemberId()), __FILE__, __LINE__);
 
-                       // Remove entry
-                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM
+                               // Remove entry
+                               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM
        `{?_MYSQL_PREFIX?}_user_holidays`
 WHERE
        `userid`=%s
 LIMIT 1",
-                               array(getMemberId()), __FILE__, __LINE__);
-
-                       // Send email to admin
-                       sendAdminNotification(getMessage('HOLIDAY_ADMIN_DEAC_SUBJ'), 'admin_holiday_deactivated', $content, getMemberId());
-
-                       // Display message to user
-                       loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_DEACTIVATED_NOW'));
-               } else {
-                       // Display message to user
-                       loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_CANNOT_DEACTIVATE'));
+                                       array(getMemberId()), __FILE__, __LINE__);
+
+                               // Send email to admin
+                               sendAdminNotification(getMessage('HOLIDAY_ADMIN_DEAC_SUBJ'), 'admin_holiday_deactivated', $content, getMemberId());
+
+                               // Display message to user
+                               loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_DEACTIVATED_NOW'));
+                       } else {
+                               // Display message to user
+                               loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_CANNOT_DEACTIVATE'));
+                       }
+
+                       // Free result
+                       SQL_FREERESULT($result2);
+               } elseif ($content['holiday_active'] == 'Y') {
+                       // To fast!
+                       loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));
                }
-       } elseif ($content['holiday_active'] == 'Y') {
-               // To fast!
-               loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));
+       } else {
+               // User not found
+               loadTemplate('admin_settings_saved', false, getMaskedMessage('HOLIDAY_MEMBER_NOT_STOPPED_404', getMemberId()));
        }
+
+       // Free result
+       SQL_FREERESULT($result);
 } // END - if
 
 // If something is wrong or link in menu is just clicked display form
@@ -250,9 +262,8 @@ WHERE
        `userid`=%s
 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
                                if (SQL_NUMROWS($result) == 1) {
-                                       // Data was found
+                                       // Data was found so merge it
                                        $content = merge_array($content, SQL_FETCHARRAY($result));
-                                       SQL_FREERESULT($result);
 
                                        // Prepare it for the template
                                        $content['start'] = generateDateTime($content['holiday_start'] , 3);
@@ -276,6 +287,9 @@ LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
                                        redirectToUrl('modules.php?module=login&amp;what=holiday');
                                        return;
                                }
+
+                               // Free result
+                               SQL_FREERESULT($result);
                                break;
 
                        case 'N': // Display activation form
index b856528aa3b49fbc6e5af8db05381d5eebad1720..0e0fb4341d77e20deef9288d97a8f94425ddfaea 100644 (file)
@@ -77,8 +77,14 @@ if (empty($URL)) {
                // Load mail again...              0         1          2             3            4         5       6            7
                $result = SQL_QUERY_ESC("SELECT `subject`, `text`, `receivers`, `payment_id`, `timestamp`, `url`, `cat_id`, `target_send` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s AND `sender`=%s LIMIT 1",
                        array(bigintval(getRequestParameter('order')), getMemberId()), __FILE__, __LINE__);
+
+               // Merge arrays
                $content = merge_array($content, SQL_FETCHARRAY($result));
+
+               // Free result
                SQL_FREERESULT($result);
+
+               // Fix empty subject line
                if (empty($content['subject'])) $content['subject'] = getMessage('DEFAULT_SUBJECT_LINE');
 
                // Calculate used points
index cff7b3f84f2c08002b12a612735efbfce6050dbe..a4b75fd4ef538a9ec82a9c786241e8b92633aa02 100644 (file)
@@ -62,7 +62,7 @@ ORDER BY
 
 if (SQL_NUMROWS($result_bonus) > 0) {
        // We found some mail orders...
-       while ($content = merge_array($content, SQL_FETCHARRAY($result_bonus))) {
+       while ($content = SQL_FETCHARRAY($result_bonus)) {
                // Add points
                SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_stats`=`bonus_stats`+{?bonus_stats?} WHERE `userid`=%s LIMIT 1",
                        array(bigintval($content['userid'])), __FILE__, __LINE__);
index c8397325c613ee3716e7896af4cb2fb542cc254e..e678d588086df6a3359c6d8149943f939309d256 100644 (file)
@@ -78,7 +78,9 @@ WHERE
        `holiday_start` <= UNIX_TIMESTAMP() AND
        `holiday_end` > UNIX_TIMESTAMP()
 LIMIT 1",
-               array(bigintval($content['userid'])), __FILE__, __LINE__);
+                       array(bigintval($content['userid'])), __FILE__, __LINE__);
+
+               // Do we have an entry?
                if (SQL_NUMROWS($result_holiday) == 1) {
                        // Okay, this user can be send away to holiday...
                        $content = merge_array($content, SQL_FETCHARRAY($result_holiday));