Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / member / what-transfer.php
index 618030fdd579f3ca54fc972a44416a415e2705b8..884e31b08df41383e8980ef408d08033f931768d 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -94,20 +94,20 @@ switch ($mode) {
                        $valid_recipient = isValidId(postRequestElement('to_userid'));
 
                        // Re-check receivers and own personal data
-                       $result = SQL_QUERY_ESC("SELECT `userid`, `gender`, `surname`, `family`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid` IN ('%s','%s') AND `status`='CONFIRMED'" . runFilterChain('user_exclusion_sql', ' ') . " LIMIT 2",
+                       $result = sqlQueryEscaped("SELECT `userid`, `gender`, `surname`, `family`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid` IN ('%s','%s') AND `status`='CONFIRMED'" . runFilterChain('user_exclusion_sql', ' ') . " LIMIT 2",
                                array(
                                        getMemberId(),
                                        bigintval(postRequestElement('to_userid'))
                                ), __FILE__, __LINE__);
 
                        // Is there two entries?
-                       $valid_data = (SQL_NUMROWS($result) == 2);
+                       $valid_data = (sqlNumRows($result) == 2);
 
                        // Final check if all is fine
                        if ($valid_code && $valid_data && $valid_pass && $valid_amount && $valid_reason && $valid_recipient) {
                                // Let's start the transfer and load user data
-                               $content['sender']    = SQL_FETCHARRAY($result);
-                               $content['recipient'] = SQL_FETCHARRAY($result);
+                               $content['sender']    = sqlFetchArray($result);
+                               $content['recipient'] = sqlFetchArray($result);
 
                                // Is the nickname extension not installed?
                                if (!isExtensionActive('nickname')) {
@@ -143,7 +143,7 @@ switch ($mode) {
                                $content['trans_id'] = bigintval(generateRandomCode('10', getRandomTan(), getMemberId(), postRequestElement('reason')));
 
                                // Add entries to both tables
-                               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_transfers_in` (`userid`, `from_userid`, `points`, `reason`, `time_trans`, `trans_id`) VALUES (%s,%s,%s,'%s', UNIX_TIMESTAMP(),%s)",
+                               sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_transfers_in` (`userid`, `from_userid`, `points`, `reason`, `time_trans`, `trans_id`) VALUES (%s,%s,%s,'%s', UNIX_TIMESTAMP(),%s)",
                                        array(
                                                bigintval(postRequestElement('to_userid')),
                                                getMemberId(),
@@ -151,7 +151,7 @@ switch ($mode) {
                                                postRequestElement('reason'),
                                                $content['trans_id']
                                        ), __FILE__, __LINE__);
-                               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_transfers_out` (`userid`, `to_userid`, `points`, `reason`, `time_trans`, `trans_id`) VALUES (%s,%s,%s,'%s', UNIX_TIMESTAMP(),%s)",
+                               sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_transfers_out` (`userid`, `to_userid`, `points`, `reason`, `time_trans`, `trans_id`) VALUES (%s,%s,%s,'%s', UNIX_TIMESTAMP(),%s)",
                                        array(
                                                getMemberId(),
                                                bigintval(postRequestElement('to_userid')),
@@ -176,7 +176,7 @@ switch ($mode) {
                                sendEmail($content['sender']['userid'], '{--TRANSFER_MEMBER_SENDER_SUBJECT--}' . ': ' . $RECIPIENT, $message);
 
                                // At last send admin mail(s)
-                               $adminSubject = sprintf("%s (%s->%s)", '{--ADMIN_TRANSFER_SUBJECT--}', $SENDER, $RECIPIENT);
+                               $adminSubject = sprintf('%s (%s->%s)', '{--ADMIN_TRANSFER_SUBJECT--}', $SENDER, $RECIPIENT);
                                sendAdminNotification($adminSubject, 'admin_transfer_points', $content);
 
                                // Transfer is completed
@@ -208,19 +208,19 @@ switch ($mode) {
                        }
 
                        // Free result
-                       SQL_FREERESULT($result);
+                       sqlFreeResult($result);
                } // END - if
 
                if (!isFormSent()) {
                        // Load member list
-                       $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED'" . runFilterChain('user_exclusion_sql', ' ') . " AND `opt_in`='Y' AND `userid` != '%s' ORDER BY `userid` ASC",
+                       $result = sqlQueryEscaped("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED'" . runFilterChain('user_exclusion_sql', ' ') . " AND `opt_in`='Y' AND `userid` != '%s' ORDER BY `userid` ASC",
                                array(getMemberId()), __FILE__, __LINE__);
 
-                       if (!SQL_HASZERONUMS($result)) {
+                       if (!ifSqlHasZeroNumRows($result)) {
                                // Load list
                                $OUT  = '<select name="to_userid" size="1" class="form_select">
        <option value="0">{--SELECT_NONE--}</option>';
-                               while (list($userid) = SQL_FETCHROW($result)) {
+                               while (list($userid) = sqlFetchRow($result)) {
                                        $OUT .= '       <option value="' . $userid . '"';
                                        if ((isPostRequestElementSet('to_userid')) && (postRequestElement('to_userid') == $userid)) {
                                                $OUT .= ' selected="selected"';
@@ -231,10 +231,10 @@ switch ($mode) {
                                $content['to_disabled'] = '';
 
                                // Free memory
-                               SQL_FREERESULT($result);
+                               sqlFreeResult($result);
                        } else {
                                // No one else is opt-in
-                               $OUT = displayMessage('{--MEMBER_TRANSFER_NO_ONE_ELSE_OPT_IN--}', TRUE);
+                               $OUT = returnMessage('{--MEMBER_TRANSFER_NO_ONE_ELSE_OPT_IN--}');
                                $content['to_disabled'] = ' disabled="disabled"';
                        }
 
@@ -256,7 +256,7 @@ switch ($mode) {
                                $content['captcha_code'] = '<input type="hidden" name="code_chk" value="' . $rand . '" /><input type="text" name="code" class="form_field" size="5" maxlength="7"' . $content['to_disabled'] . ' />&nbsp;' . $img;
                        } else {
                                $code = '00000';
-                               $content['captcha_code'] = displayMessage('{--MEMBER_TRANSFER_NO_CODE--}', TRUE);
+                               $content['captcha_code'] = returnMessage('{--MEMBER_TRANSFER_NO_CODE--}');
                        }
 
                        // Init points/reason
@@ -297,12 +297,12 @@ switch ($mode) {
 
                // Run the SQL command and set total points to zero
                $totalPoints = '0';
-               $result = SQL_QUERY_ESC($sql, array(getMemberId()), __FILE__, __LINE__);
+               $result = sqlQueryEscaped($sql, array(getMemberId()), __FILE__, __LINE__);
 
                // Are there entries?
-               if (!SQL_HASZERONUMS($result)) {
+               if (!ifSqlHasZeroNumRows($result)) {
                        $OUT = '';
-                       while ($content = SQL_FETCHARRAY($result)) {
+                       while ($content = sqlFetchArray($result)) {
                                // Rewrite points, out is subtracted
                                if ($type == 'OUT') {
                                        $content['points'] = $content['points'] * -1;
@@ -319,7 +319,7 @@ switch ($mode) {
                        } // END - while
 
                        // Free memory
-                       SQL_FREERESULT($result);
+                       sqlFreeResult($result);
                } else {
                        // Nothing for in or out
                        $OUT = '<tr>
@@ -347,7 +347,7 @@ switch ($mode) {
                 */
 
                // First of all create the per-user temporary table
-               $result = SQL_QUERY_ESC("CREATE TEMPORARY TABLE `{?_MYSQL_PREFIX?}_%s_transfers_tmp` (
+               $result = sqlQueryEscaped("CREATE TEMPORARY TABLE `{?_MYSQL_PREFIX?}_%s_transfers_tmp` (
 `trans_id` VARCHAR(12) NOT NULL DEFAULT '',
 `party_userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
 `points` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
@@ -358,38 +358,38 @@ INDEX (`party_userid`)
 ) ENGINE = HEAP COMMENT = 'Temporary transfer table'", array(getMemberId()), __FILE__, __LINE__);
 
                // Let's begin with the incoming list
-               $result = SQL_QUERY_ESC("SELECT `trans_id`, `from_userid`, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_in` WHERE `userid`=%s ORDER BY `id` ASC LIMIT {?transfer_max?}",
+               $result = sqlQueryEscaped("SELECT `trans_id`, `from_userid`, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_in` WHERE `userid`=%s ORDER BY `id` ASC LIMIT {?transfer_max?}",
                        array(getMemberId()), __FILE__, __LINE__);
-               while ($content = SQL_FETCHROW($result)) {
+               while ($content = sqlFetchRow($result)) {
                        array_push($content, 'IN');
                        $content = implode("','", $content);
-                       $res_temp = SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_%s_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('" . $content . "')", array(getMemberId()), __FILE__, __LINE__);
+                       $res_temp = sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_%s_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('" . $content . "')", array(getMemberId()), __FILE__, __LINE__);
                } // END - while
 
                // Free memory
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // As the last table transfer data from outgoing table to temporary
-               $result = SQL_QUERY_ESC("SELECT `trans_id`, `to_userid`, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE `userid`=%s ORDER BY `id` LIMIT {?transfer_max?}",
+               $result = sqlQueryEscaped("SELECT `trans_id`, `to_userid`, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE `userid`=%s ORDER BY `id` LIMIT {?transfer_max?}",
                        array(getMemberId()), __FILE__, __LINE__);
-               while ($content = SQL_FETCHROW($result)) {
+               while ($content = sqlFetchRow($result)) {
                        array_push($content, 'OUT');
                        $content = implode("','", $content);
-                       $res_temp = SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_%s_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('" . $content . "')", array(getMemberId()), __FILE__, __LINE__);
+                       $res_temp = sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_%s_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('" . $content . "')", array(getMemberId()), __FILE__, __LINE__);
                } // END - while
 
                // Free memory
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Search for entries
-               $result = SQL_QUERY_ESC("SELECT `party_userid`, `trans_id`, `points`, `reason`, `time_trans`, `trans_type` FROM `{?_MYSQL_PREFIX?}_%s_transfers_tmp` ORDER BY `time_trans` DESC",
+               $result = sqlQueryEscaped("SELECT `party_userid`, `trans_id`, `points`, `reason`, `time_trans`, `trans_type` FROM `{?_MYSQL_PREFIX?}_%s_transfers_tmp` ORDER BY `time_trans` DESC",
                        array(getMemberId()), __FILE__, __LINE__);
 
                $total = '0';
-               if (!SQL_HASZERONUMS($result)) {
+               if (!ifSqlHasZeroNumRows($result)) {
                        // Output rows
                        $OUT = '';
-                       while ($content = SQL_FETCHARRAY($result)) {
+                       while ($content = sqlFetchArray($result)) {
                                // Rewrite points if OUT
                                if ($content['trans_type'] == 'OUT') {
                                        $content['points'] = $content['points'] * -1;
@@ -414,7 +414,7 @@ INDEX (`party_userid`)
                }
 
                // Free memory
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // ... and add them to a constant for the template
                $content['rows'] = $OUT;
@@ -429,13 +429,13 @@ INDEX (`party_userid`)
                $content['balance'] = '{--TRANSFER_TOTAL_BALANCE--}';
 
                // At the end we don't need a temporary table in memory
-               $result = SQL_QUERY_ESC("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_%s_transfers_tmp`", array(getMemberId()), __FILE__, __LINE__);
+               $result = sqlQueryEscaped("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_%s_transfers_tmp`", array(getMemberId()), __FILE__, __LINE__);
 
                // Load final template
                loadTemplate('member_transfer_list', FALSE, $content);
 
                // Free some memory...
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
                break;
 
        default: // Overview page
@@ -465,7 +465,7 @@ INDEX (`party_userid`)
 
                if (isFormSent()) {
                        // Save settings
-                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `opt_in`='%s' WHERE `userid`=%s LIMIT 1",
+                       sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `opt_in`='%s' WHERE `userid`=%s LIMIT 1",
                                array(postRequestElement('opt_in'), getMemberId()), __FILE__, __LINE__);
 
                        // "Settings saved..."
@@ -492,7 +492,7 @@ INDEX (`party_userid`)
                } // END - switch
 
                // Check for latest out-transfers
-               $result = SQL_QUERY_ESC("SELECT
+               $result = sqlQueryEscaped("SELECT
        `time_trans`
 FROM
        `{?_MYSQL_PREFIX?}_user_transfers_out`
@@ -507,9 +507,9 @@ LIMIT 1",
                        ), __FILE__, __LINE__);
 
                // Is there an entry?
-               if (SQL_NUMROWS($result) == 1) {
+               if (sqlNumRows($result) == 1) {
                        // Load newest transaction
-                       list($newest) = SQL_FETCHROW($result);
+                       list($newest) = sqlFetchRow($result);
                        $content['settings'] = '{%message,MEMBER_TRANSFER_LATEST_IS=' . generateDateTime($newest, '3') . '%}';
                } else {
                        // Load template
@@ -517,7 +517,7 @@ LIMIT 1",
                }
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Load template
                loadTemplate('member_transfer_overview', FALSE, $content);