From: Roland Häder Date: Sun, 14 Feb 2010 12:20:43 +0000 (+0000) Subject: Rewrites/fixes for while() loops with merge_array() and SQL_FETCHARRAY() usage X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=aa1fa67e62e0d175d5d801becaea4362a5b50e2a;p=mailer.git Rewrites/fixes for while() loops with merge_array() and SQL_FETCHARRAY() usage --- diff --git a/inc/autopurge/purge-inact.php b/inc/autopurge/purge-inact.php index 38fbc334cc..ae1d8907b5 100644 --- a/inc/autopurge/purge-inact.php +++ b/inc/autopurge/purge-inact.php @@ -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'].", "; diff --git a/inc/autopurge/purge-unconfirmed.php b/inc/autopurge/purge-unconfirmed.php index bb4e920ab0..e6276a98ce 100644 --- a/inc/autopurge/purge-unconfirmed.php +++ b/inc/autopurge/purge-unconfirmed.php @@ -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'] . ', '; diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 7f5a297c64..a3b5af0dd2 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -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; } } diff --git a/inc/language/holiday_de.php b/inc/language/holiday_de.php index 51dd55fdae..c46e47b49c 100644 --- a/inc/language/holiday_de.php +++ b/inc/language/holiday_de.php @@ -81,8 +81,9 @@ addMessages(array( 'HOLIDAY_ADMIN_MODE' => "Zeitpunkt der Abarbeitung der Urlaubsschaltungen", 'HOLIDAY_ADMIN_MODE_RESET' => "Am täglichen Reset um 00:00 Uhr", 'HOLIDAY_ADMIN_MODE_DIRECT' => "Sofort nach Beantragung prüfen", + 'HOLIDAY_MEMBER_NOT_STOPPED_404' => "Beim Beenden Ihres Urlaubes ist ein unerwarteter Fehler aufgetreten: Mitglieder-Id %s 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", diff --git a/inc/libs/rallye_functions.php b/inc/libs/rallye_functions.php index 5526567afe..0744b6b32c 100644 --- a/inc/libs/rallye_functions.php +++ b/inc/libs/rallye_functions.php @@ -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 diff --git a/inc/mails/beg_mails.php b/inc/mails/beg_mails.php index 7712f5fb57..b9a65e462f 100644 --- a/inc/mails/beg_mails.php +++ b/inc/mails/beg_mails.php @@ -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` diff --git a/inc/modules/admin/what-add_points.php b/inc/modules/admin/what-add_points.php index fe7baa722f..f3465c2301 100644 --- a/inc/modules/admin/what-add_points.php +++ b/inc/modules/admin/what-add_points.php @@ -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... diff --git a/inc/modules/admin/what-list_cats.php b/inc/modules/admin/what-list_cats.php index 23cdb66c6b..96f23cf486 100644 --- a/inc/modules/admin/what-list_cats.php +++ b/inc/modules/admin/what-list_cats.php @@ -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; diff --git a/inc/modules/admin/what-list_refs.php b/inc/modules/admin/what-list_refs.php index 7318e7b92a..59b6081579 100644 --- a/inc/modules/admin/what-list_refs.php +++ b/inc/modules/admin/what-list_refs.php @@ -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 diff --git a/inc/modules/admin/what-sub_points.php b/inc/modules/admin/what-sub_points.php index 661dd3ff4d..9667e9be6a 100644 --- a/inc/modules/admin/what-sub_points.php +++ b/inc/modules/admin/what-sub_points.php @@ -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')); diff --git a/inc/modules/member/what-holiday.php b/inc/modules/member/what-holiday.php index 63a5ed54b2..209ad00787 100644 --- a/inc/modules/member/what-holiday.php +++ b/inc/modules/member/what-holiday.php @@ -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&what=holiday'); return; } + + // Free result + SQL_FREERESULT($result); break; case 'N': // Display activation form diff --git a/inc/modules/order.php b/inc/modules/order.php index b856528aa3..0e0fb4341d 100644 --- a/inc/modules/order.php +++ b/inc/modules/order.php @@ -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 diff --git a/inc/reset/reset_100_bonus.php b/inc/reset/reset_100_bonus.php index cff7b3f84f..a4b75fd4ef 100644 --- a/inc/reset/reset_100_bonus.php +++ b/inc/reset/reset_100_bonus.php @@ -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__); diff --git a/inc/reset/reset_holiday.php b/inc/reset/reset_holiday.php index c8397325c6..e678d58808 100644 --- a/inc/reset/reset_holiday.php +++ b/inc/reset/reset_holiday.php @@ -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));