]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/member/what-transfer.php
Some more wrappers added, code cleanups:
[mailer.git] / inc / modules / member / what-transfer.php
index 122f0daa22fcf3f2024adfcdb86e56678d79d94b..85bff3a9f43dd243b03cd32f6cf0deff26d6b606 100644 (file)
@@ -62,7 +62,7 @@ if ((getUserData('opt_in') != 'Y') && ($mode == 'new')) $mode = '';
 switch ($mode) {
        case 'new': // Start new transfer
                // Get total points and subtract the balance amount from it = maximum transferable points
-               $total = countSumTotalData(getMemberId(), 'user_points', 'points')  - countSumTotalData(getMemberId(), 'user_data', 'used_points');
+               $total = getTotalPoints(getMemberId());
 
                // Remember maximum value for template
                $content['max_transferable'] = round($total - getConfig('transfer_balance') - 0.5);
@@ -88,7 +88,7 @@ switch ($mode) {
                        $valid_reason = (isPostRequestParameterSet('reason'));
 
                        // Test if a recipient is selected
-                       $valid_recipient = (postRequestParameter('to_userid') > 0);
+                       $valid_recipient = isValidUserId(postRequestParameter('to_userid'));
 
                        // Check for nickname extension and set additional data
                        // @TODO Rewrite this to a filter
@@ -120,10 +120,6 @@ switch ($mode) {
                                        $content['recipient']['nickname'] = '';
                                } // END - if
 
-                               // Translate some data
-                               $content['sender']['gender']    = translateGender($content['sender']['gender']);
-                               $content['recipient']['gender'] = translateGender($content['recipient']['gender']);
-
                                // Prepare variables for testing
                                $TEST_NICK_SENDER = $content['sender']['nickname'];
                                $TEST_NICK_REC    = $content['recipient']['nickname'];
@@ -165,18 +161,18 @@ switch ($mode) {
 
                                // First send email to recipient
                                $message = loadEmailTemplate('member_transfer_recipient', $content, postRequestParameter('to_userid'));
-                               sendEmail($content['recipient']['email'], getMessage('TRANSFER_MEMBER_RECIPIENT_SUBJ') . ': ' . $SENDER, $message);
+                               sendEmail($content['recipient']['email'], '{--TRANSFER_MEMBER_RECIPIENT_SUBJECT--}' . ': ' . $SENDER, $message);
 
                                // Second send email to sender
                                $message = loadEmailTemplate('member_transfer_sender', $content, getMemberId());
-                               sendEmail($content['sender']['email'], getMessage('TRANSFER_MEMBER_SENDER_SUBJ') . ': ' . $RECIPIENT, $message);
+                               sendEmail($content['sender']['email'], '{--TRANSFER_MEMBER_SENDER_SUBJECT--}' . ': ' . $RECIPIENT, $message);
 
                                // At last send admin mail(s)
-                               $adminSubject = sprintf("%s (%s->%s)", getMessage('TRANSFER_ADMIN_SUBJECT'), $SENDER, $RECIPIENT);
+                               $adminSubject = sprintf("%s (%s->%s)", '{--TRANSFER_ADMIN_SUBJECT--}', $SENDER, $RECIPIENT);
                                sendAdminNotification($adminSubject, 'admin_transfer_points', $content);
 
                                // Transfer is completed
-                               loadTemplate('admin_settings_saved', false, getMessage('TRANSFER_COMPLETED') . "<br /><a href=\"{%url=modules.php?module=login&amp;what=transfer%}\">{--TRANSFER_CONTINUE_OVERVIEW--}</a>");
+                               loadTemplate('admin_settings_saved', false, '{--TRANSFER_COMPLETED--}' . '<br /><a href="{%url=modules.php?module=login&amp;what=transfer%}">{--TRANSFER_CONTINUE_OVERVIEW--}</a>');
                        } elseif ($valid_code === false) {
                                // Invalid Touring code!
                                loadTemplate('admin_settings_saved', false, '<div class="member_note">{--TRANSFER_INVALID_CODE--}</div>');
@@ -219,15 +215,15 @@ switch ($mode) {
                                        array(getMemberId()), __FILE__, __LINE__);
                        }
 
-                       if (SQL_NUMROWS($result) > 0) {
+                       if (!SQL_HASZERONUMS($result)) {
                                // Load list
                                $OUT  = "<select name=\"to_userid\" size=\"1\" class=\"member_select\">
        <option value=\"0\">{--SELECT_NONE--}</option>\n";
                                // @TODO Try to rewrite his to $content = SQL_FETCHARRAY(), see some lines above for two different queries
                                while (list($userid, $nick) = SQL_FETCHROW($result)) {
                                        $OUT .= "       <option value=\"".$userid."\"";
-                                       if ((isPostRequestParameterSet(('to_userid'))) && (postRequestParameter('to_userid') == $userid)) $OUT .= ' selected="selected"';
-                                       $OUT .= ">";
+                                       if ((isPostRequestParameterSet('to_userid')) && (postRequestParameter('to_userid') == $userid)) $OUT .= ' selected="selected"';
+                                       $OUT .= '>';
                                        if (($nick != $userid) && (!empty($nick))) {
                                                // Output nickname
                                                $OUT .= $nick;
@@ -235,16 +231,16 @@ switch ($mode) {
                                                // Output userid
                                                $OUT .= $userid;
                                        }
-                                       $OUT .= "</option>\n";
+                                       $OUT .= '</option>';
                                }
-                               $OUT .= "</select>\n";
+                               $OUT .= '</select>';
                                $content['to_disabled'] = '';
 
                                // Free memory
                                SQL_FREERESULT($result);
                        } else {
                                // No one else is opt-in
-                               $OUT = loadTemplate('admin_settings_saved', true, getMessage('TRANSFER_NO_ONE_ELSE_OPT_IN'));
+                               $OUT = loadTemplate('admin_settings_saved', true, '{--TRANSFER_NO_ONE_ELSE_OPT_IN--}');
                                $content['to_disabled'] = ' disabled="disabled"';
                        }
 
@@ -259,7 +255,7 @@ switch ($mode) {
                                $content['captcha_code'] = '<input type="hidden" name="code_chk" value="' . $rand . '" /><input type="text" name="code" class="member_normal" size="5" maxlength="7"' . $content['to_disabled'] . ' />&nbsp;' . $img;
                        } else {
                                $code = '00000';
-                               $content['captcha_code'] = loadTemplate('admin_settings_saved', true, getMessage('TRANSFER_NO_CODE'));
+                               $content['captcha_code'] = loadTemplate('admin_settings_saved', true, '{--TRANSFER_NO_CODE--}');
                        }
 
                        // Init points/reason
@@ -267,15 +263,12 @@ switch ($mode) {
                        $content['reason'] = '';
 
                        // Transfer maybe already entered valued'
-                       if (isGetRequestParameterSet('ok')) {
+                       if (isPostRequestParameterSet('ok')) {
                                // Get values from form
-                               $content['points'] = bigintval(postRequestParameter('points'));
-                               $content['reason'] = secureString(postRequestParameter('reason'));
+                               $content['points'] = postRequestParameter('points');
+                               $content['reason'] = postRequestParameter('reason');
                        } // END - if
 
-                       // Translate some array elements for template
-                       $content['max_transferable'] = translateComma($content['max_transferable']);
-
                        // Output form
                        loadTemplate('member_transfer_new', false, $content);
                } // END - if
@@ -287,17 +280,17 @@ switch ($mode) {
                $nothingMessage = '';
                switch ($mode) {
                        case 'list_in':
-                               $sql = "SELECT `trans_id`, `from_userid` AS party_userid, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_in` WHERE `userid`=%s ORDER BY `time_trans` DESC LIMIT ".getConfig('transfer_max');
-                               $nothingMessage = getMessage('TRANSFER_NO_INCOMING_TRANSFERS');
-                               $content['balance'] = getMessage('TRANSFER_TOTAL_INCOMING');
-                               $content['title']   = getMessage('TRANSFER_LIST_INCOMING');
+                               $sql = "SELECT `trans_id`, `from_userid` AS party_userid, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_in` WHERE `userid`=%s ORDER BY `time_trans` DESC LIMIT {?transfer_max?}";
+                               $nothingMessage     = '{--TRANSFER_NO_INCOMING_TRANSFERS--}';
+                               $content['balance'] = '{--TRANSFER_TOTAL_INCOMING--}';
+                               $content['title']   = '{--TRANSFER_LIST_INCOMING--}';
                                break;
 
                        case 'list_out':
-                               $sql = "SELECT `trans_id`, `to_userid` AS party_userid, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE `userid`=%s ORDER BY `time_trans` DESC LIMIT ".getConfig('transfer_max');
-                               $nothingMessage = getMessage('TRANSFER_NO_OUTGOING_TRANSFERS');
-                               $content['balance'] = getMessage('TRANSFER_TOTAL_OUTGOING');
-                               $content['title']   = getMessage('TRANSFER_LIST_OUTGOING');
+                               $sql = "SELECT `trans_id`, `to_userid` AS party_userid, `points`, `reason`, `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE `userid`=%s ORDER BY `time_trans` DESC LIMIT {?transfer_max?}";
+                               $nothingMessage     = '{--TRANSFER_NO_OUTGOING_TRANSFERS--}';
+                               $content['balance'] = '{--TRANSFER_TOTAL_OUTGOING--}';
+                               $content['title']   = '{--TRANSFER_LIST_OUTGOING--}';
                                break;
                } // END - switch
 
@@ -306,8 +299,8 @@ switch ($mode) {
                $result = SQL_QUERY_ESC($sql, array(getMemberId()), __FILE__, __LINE__);
 
                // Do we have entries?
-               if (SQL_NUMROWS($result) > 0) {
-                       $OUT = ''; $SW = 2;
+               if (!SQL_HASZERONUMS($result)) {
+                       $OUT = '';
                        // @TODO This should be somehow rewritten to $row = SQL_FETCHARRAY(), see switch() block above for SQL queries
                        while (list($tid, $userid, $points, $reason, $stamp) = SQL_FETCHROW($result)) {
                                // Rewrite points
@@ -316,12 +309,11 @@ switch ($mode) {
                                // Prepare content for template
                                // @TODO Rewrite: tid->trans_id,stamp->time_trans
                                $row = array(
-                                       'sw'       => $SW,
                                        'trans_id' => $tid,
                                        'stamp'    => generateDateTime($stamp, 3),
                                        'userid'   => $userid,
                                        'reason'   => $reason,
-                                       'points'   => translateComma($points)
+                                       'points'   => $points
                                );
 
                                // Load row template
@@ -329,7 +321,6 @@ switch ($mode) {
 
                                // Add points and switch color
                                $totalPoints += $points;
-                               $SW = 3 - $SW;
                        } // END - while
 
                        // Free memory
@@ -375,7 +366,7 @@ KEY (`party_userid`)
                while ($DATA = SQL_FETCHROW($result)) {
                        $DATA[] = 'IN';
                        $DATA = implode("','", $DATA);
-                       $res_temp = SQL_QUERY("INSERT INTO `{?_MYSQL_PREFIX?}_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('".$DATA."')", __FILE__, __LINE__);
+                       $res_temp = SQL_QUERY("INSERT INTO `{?_MYSQL_PREFIX?}_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('" . $DATA . "')", __FILE__, __LINE__);
                } // END - while
 
                // Free memory
@@ -387,26 +378,25 @@ KEY (`party_userid`)
                while ($DATA = SQL_FETCHROW($result)) {
                        $DATA[] = 'OUT';
                        $DATA = implode("','", $DATA);
-                       $res_temp = SQL_QUERY("INSERT INTO `{?_MYSQL_PREFIX?}_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('".$DATA."')", __FILE__, __LINE__);
+                       $res_temp = SQL_QUERY("INSERT INTO `{?_MYSQL_PREFIX?}_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('" . $DATA . "')", __FILE__, __LINE__);
                } // END - while
 
                // Free memory
                SQL_FREERESULT($result);
 
                $total = '0';
-               if (SQL_NUMROWS($result) > 0) {
+               if (!SQL_HASZERONUMS($result)) {
                        // Search for entries
                        $result = SQL_QUERY("SELECT `party_userid`, `trans_id`, `points`, `reason`, `time_trans`, `trans_type` FROM `{?_MYSQL_PREFIX?}_transfers_tmp` ORDER BY `time_trans` DESC",
                                __FILE__, __LINE__);
 
                        // Output rows
-                       $OUT = ''; $SW = 2;
+                       $OUT = '';
                        while ($content = SQL_FETCHARRAY($result)) {
                                // Rewrite points
                                if ($content['trans_type'] == 'OUT') $content['points'] = '-'.$content['points']."";
 
                                // Prepare content for template
-                               $content['sw']     = $SW;
                                $content['time']   = generateDateTime($content['time_trans'], 3);
                                $content['points'] = translateComma($content['points']);
 
@@ -415,18 +405,17 @@ KEY (`party_userid`)
 
                                // Add points and switch color
                                $total += $content['points'];
-                               $SW = 3 - $SW;
                        } // END - while
 
                        // Free memory
                        SQL_FREERESULT($result);
                } else {
                        // Nothing for in and out
-                       $OUT = "<tr>
-  <td colspan=\"5\" align=\"center\" class=\"bottom\">
-    ".loadTemplate('admin_settings_saved', true, getMessage('TRANSFER_NO_INOUT_TRANSFERS'))."
+                       $OUT = '<tr>
+  <td colspan="5" align="center" class="bottom">
+    ' . loadTemplate('admin_settings_saved', true, '{--TRANSFER_NO_INOUT_TRANSFERS--}') . '
   </td>
-</tr>";
+</tr>';
                }
 
                // ... and add them to a constant for the template
@@ -436,10 +425,10 @@ KEY (`party_userid`)
                $content['total'] = translateComma($total);
 
                // Set title
-               $content['title'] = getMessage('TRANSFER_LIST_ALL');
+               $content['title'] = '{--TRANSFER_LIST_ALL--}';
 
                // Set "balance" word
-               $content['balance'] = getMessage('TRANSFER_TOTAL_BALANCE');
+               $content['balance'] = '{--TRANSFER_TOTAL_BALANCE--}';
 
                // At the end we don't need a temporary table in memory
                $result = SQL_QUERY("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_transfers_tmp`", __FILE__, __LINE__);
@@ -481,9 +470,6 @@ KEY (`party_userid`)
                        SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `opt_in`='%s' WHERE `userid`=%s LIMIT 1",
                                array(postRequestParameter('opt_in'), getMemberId()), __FILE__, __LINE__);
 
-                       // Rember for next switch() command
-                       getUserData('opt_in') = substr(postRequestParameter('opt_in'), 0, 1);
-
                        // "Settings saved..."
                        loadTemplate('admin_settings_saved', false, '<div class="member_done">{--SETTINGS_SAVED--}</div>');
                } // END - if
@@ -503,7 +489,7 @@ KEY (`party_userid`)
                                break;
 
                        case 'N':
-                               $content['new_link'] = getMessage('TRANSFER_PLEASE_ALLOW_OPT_IN');
+                               $content['new_link'] = '{--TRANSFER_PLEASE_ALLOW_OPT_IN--}';
                                break;
                } // END - switch