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 38fbc33..ae1d890 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 bb4e920..e6276a9 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 7f5a297..a3b5af0 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 51dd55f..c46e47b 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 5526567..0744b6b 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 7712f5f..b9a65e4 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 fe7baa7..f3465c2 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 23cdb66..96f23cf 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 7318e7b..59b6081 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 661dd3f..9667e9b 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 63a5ed5..209ad00 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 b856528..0e0fb43 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 cff7b3f..a4b75fd 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 c839732..e678d58 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));