0) { // Check for code $code = generateRandomCode(getTransferCode(), postRequestElement('code_chk'), getMemberId(), $content['max_transferable']); $valid_code = ($code == postRequestElement('code')); } else { // Zero length (= disabled) is always valid! $valid_code = TRUE; } // Test password $valid_pass = ($pass == generateHash(postRequestElement('password'), $pass)); // Test transfer amount $valid_amount = ((isPostRequestElementSet('points')) && (postRequestElement('points') <= $content['max_transferable'])); // Test reason for transfer $valid_reason = (isPostRequestElementSet('reason')); // Test if a recipient is selected $valid_recipient = isValidId(postRequestElement('to_userid')); // Re-check receivers and own personal data $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 = (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'] = sqlFetchArray($result); $content['recipient'] = sqlFetchArray($result); // Is the nickname extension not installed? if (!isExtensionActive('nickname')) { // Fix empty nicknames $content['sender']['nickname'] = ''; $content['recipient']['nickname'] = ''; } // END - if // Prepare variables for testing $TEST_NICK_SENDER = $content['sender']['nickname']; $TEST_NICK_REC = $content['recipient']['nickname']; // Default is userids for subject line $SENDER = getMemberId(); $RECIPIENT = bigintval(postRequestElement('to_userid')); // If nickname is installed we can set the nickname // @TODO Rewrite this to a filter if (isExtensionActive('nickname')) { if (($TEST_NICK_SENDER != getMemberId()) && (!empty($TEST_NICK_SENDER))) { $SENDER = $content['sender']['nickname']; } // END - if if (($TEST_NICK_REC != postRequestElement('to_userid')) && (!empty($TEST_NICK_REC))) { $RECIPIENT = $content['recipient']['nickname']; } // END - if } // END - if // Remember transfer reason $content['reason'] = postRequestElement('reason'); // Generate tranafer id $content['trans_id'] = bigintval(generateRandomCode('10', getRandomTan(), getMemberId(), postRequestElement('reason'))); // Add entries to both tables 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(), bigintval(postRequestElement('points')), postRequestElement('reason'), $content['trans_id'] ), __FILE__, __LINE__); 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')), bigintval(postRequestElement('points')), postRequestElement('reason'), $content['trans_id'] ), __FILE__, __LINE__); // Add points to account *directly* ... initReferralSystem(); addPointsThroughReferralSystem('transfer', bigintval(postRequestElement('to_userid')), bigintval(postRequestElement('points'))); // ... and add it to current user's used points and ignore return status subtractPoints('transfer', getMemberId(), postRequestElement('points')); // First send email to recipient $message = loadEmailTemplate('member_transfer_recipient', $content, postRequestElement('to_userid')); sendEmail($content['recipient']['userid'], '{--TRANSFER_MEMBER_RECIPIENT_SUBJECT--}' . ': ' . $SENDER, $message); // Second send email to sender $message = loadEmailTemplate('member_transfer_sender', $content, getMemberId()); 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); sendAdminNotification($adminSubject, 'admin_transfer_points', $content); // Transfer is completed displayMessage('
{--MEMBER_TRANSFER_COMPLETED--}' . '
{--MEMBER_TRANSFER_CONTINUE_OVERVIEW--}
'); } elseif ($valid_code === FALSE) { // Invalid Touring code! displayErrorMessage('{--MEMBER_TRANSFER_INVALID_CODE--}'); unsetPostRequestElement('ok'); } elseif ($valid_pass === FALSE) { // Wrong password entered displayErrorMessage('{--MEMBER_TRANSFER_INVALID_PASSWORD--}'); unsetPostRequestElement('ok'); } elseif ($valid_amount === FALSE) { // Too much points entered displayErrorMessage('{--MEMBER_TRANSFER_INVALID_POINTS--}'); unsetPostRequestElement('ok'); } elseif ($valid_reason === FALSE) { // No transfer reason entered displayErrorMessage('{--MEMBER_TRANSFER_INVALID_REASON--}'); unsetPostRequestElement('ok'); } elseif ($valid_recipient === FALSE) { // No recipient selected displayErrorMessage('{--MEMBER_TRANSFER_INVALID_RECIPIENT--}'); unsetPostRequestElement('ok'); } elseif ($valid_data === FALSE) { // No recipient/sender selected displayErrorMessage('{--MEMBER_TRANSFER_INVALID_DATA--}'); unsetPostRequestElement('ok'); } // Free result sqlFreeResult($result); } // END - if if (!isFormSent()) { // Load member list $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 (!ifSqlHasZeroNumRows($result)) { // Load list $OUT = ''; $content['to_disabled'] = ''; // Free memory sqlFreeResult($result); } else { // No one else is opt-in $OUT = returnMessage('{--MEMBER_TRANSFER_NO_ONE_ELSE_OPT_IN--}'); $content['to_disabled'] = ' disabled="disabled"'; } // Transfer output to constant for the template $content['userid_selection'] = $OUT; // Generate Code if (getTransferCode() > 0) { // Generate random number $rand = getRandomTan(); // Generate CAPTCHA code $code = generateRandomCode(getTransferCode(), $rand, getMemberId(), $content['max_transferable']); // Generate image (HTML code) $img = generateImageOrCode($code, FALSE); // Add all and hidden field $content['captcha_code'] = ' ' . $img; } else { $code = '00000'; $content['captcha_code'] = returnMessage('{--MEMBER_TRANSFER_NO_CODE--}'); } // Init points/reason $content['points'] = ''; $content['reason'] = ''; // Transfer maybe already entered valued' if (isPostRequestElementSet('ok')) { // Get values from form $content['points'] = postRequestElement('points'); $content['reason'] = postRequestElement('reason'); } // END - if // Output form loadTemplate('member_transfer_new', FALSE, $content); } // END - if break; case 'list_in': // List only incoming transactions case 'list_out': // List only outgoing transactions // As you can see I put list_in and list_out together. I now do a switch() again on it for the right SQL command $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 {?transfer_max?}'; $nothingMessage = '{--MEMBER_TRANSFER_NO_INCOMING_TRANSFERS--}'; $content['balance'] = '{--MEMBER_TRANSFER_TOTAL_INCOMING--}'; $content['title'] = '{--MEMBER_LIST_INCOMING_TRANSFER_TITLE--}'; 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 {?transfer_max?}'; $nothingMessage = '{--MEMBER_TRANSFER_NO_OUTGOING_TRANSFERS--}'; $content['balance'] = '{--TRANSFER_TOTAL_OUTGOING--}'; $content['title'] = '{--MEMBER_LIST_OUTGOING_TRANSFER_TITLE--}'; break; } // END - switch // Run the SQL command and set total points to zero $totalPoints = '0'; $result = sqlQueryEscaped($sql, array(getMemberId()), __FILE__, __LINE__); // Are there entries? if (!ifSqlHasZeroNumRows($result)) { $OUT = ''; while ($content = sqlFetchArray($result)) { // Rewrite points, out is subtracted if ($type == 'OUT') { $content['points'] = $content['points'] * -1; } // END - if // Prepare content for template $$content['time_trans'] = generateDateTime($content['time_trans'], 3); // Load row template $OUT .= loadTemplate('member_transfer_row2', TRUE, $content); // Add points and switch color $totalPoints += $content['points']; } // END - while // Free memory sqlFreeResult($result); } else { // Nothing for in or out $OUT = ' ' . displayMessage($nothingMessage, TRUE) . ' '; } // ... and add them to a constant for the template $content['rows'] = $OUT; // Remeber total amount $content['total_points'] = $totalPoints; // Load final template loadTemplate('member_transfer_list', FALSE, $content); break; case 'list_all': // List all transactions /* * Fill a temporary table with data from both tables. This is much * easier to code and unstandable by you as sub-SELECT queries. I know * this is not the fastest way but it shall be fine for now. */ // First of all create the per-user temporary table $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, `reason` VARCHAR(255) NOT NULL DEFAULT '', `time_trans` VARCHAR(10) NOT NULL DEFAULT 0, `trans_type` ENUM('IN','OUT') NOT NULL DEFAULT 'IN', INDEX (`party_userid`) ) ENGINE = HEAP COMMENT = 'Temporary transfer table'", array(getMemberId()), __FILE__, __LINE__); // Let's begin with the incoming list $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 = sqlFetchRow($result)) { array_push($content, 'IN'); $content = implode("','", $content); $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 sqlFreeResult($result); // As the last table transfer data from outgoing table to temporary $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 = sqlFetchRow($result)) { array_push($content, 'OUT'); $content = implode("','", $content); $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 sqlFreeResult($result); // Search for entries $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 (!ifSqlHasZeroNumRows($result)) { // Output rows $OUT = ''; while ($content = sqlFetchArray($result)) { // Rewrite points if OUT if ($content['trans_type'] == 'OUT') { $content['points'] = $content['points'] * -1; } // END - if // Prepare content for template $content['time'] = generateDateTime($content['time_trans'], 3); // Load row template $OUT .= loadTemplate('member_transfer_row', TRUE, $content); // Add points and switch color $total += $content['points']; } // END - while } else { // Nothing for in and out $OUT = ' ' . displayMessage('{--TRANSFER_NO_INOUT_TRANSFERS--}', TRUE) . ' '; } // Free memory sqlFreeResult($result); // ... and add them to a constant for the template $content['rows'] = $OUT; // Remeber total amount $content['total_points'] = $total; // Set title $content['title'] = '{--TRANSFER_LIST_ALL--}'; // Set "balance" word $content['balance'] = '{--TRANSFER_TOTAL_BALANCE--}'; // At the end we don't need a temporary table in memory $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... sqlFreeResult($result); break; default: // Overview page // Check incoming transfers $totalIn = countSumTotalData(getMemberId(), 'user_transfers_in', 'id', 'userid', TRUE); $content['in_link'] = $totalIn; if ($totalIn > 0) { $content['in_link'] = '' . $totalIn . ''; } // END - if // Check outgoing transfers $totalOut = countSumTotalData(getMemberId(), 'user_transfers_out', 'id', 'userid', TRUE); $content['out_link'] = $totalOut; if ($totalOut > 0) { $content['out_link'] = '' . $totalOut . ''; } // END - if // Add all to total amount $total = $totalIn + $totalOut; // Total transactions $content['all_link'] = $total; if ($total > 0) { $content['all_link'] = '{%pipe,translateComma=' . $total . '%}'; } // END - if if (isFormSent()) { // Save settings sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `opt_in`='%s' WHERE `userid`=%s LIMIT 1", array(postRequestElement('opt_in'), getMemberId()), __FILE__, __LINE__); // "Settings saved..." displayMessage('{--SETTINGS_SAVED--}'); } // END - if // Init entries foreach (array('allow_y','allow_n') as $entry) { $content[$entry] = ''; } // END - foreach // Set current selection $content['allow_' . strtolower(getUserData('opt_in'))] = ' checked="checked"'; // Set 'new transfer' link according to above option switch (getUserData('opt_in')) { case 'Y': $content['new_link'] = '{--MEMBER_TRANSFER_NOW_LINK--}'; break; case 'N': $content['new_link'] = '{--MEMBER_PLEASE_ALLOW_TRANSFER_RECEIVE--}'; break; } // END - switch // Check for latest out-transfers $result = sqlQueryEscaped("SELECT `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE (UNIX_TIMESTAMP() - `time_trans`) >= {?transfer_timeout?} AND `userid`=%s ORDER BY `time_trans` DESC LIMIT 1", array( getMemberId() ), __FILE__, __LINE__); // Is there an entry? if (sqlNumRows($result) == 1) { // Load newest transaction list($newest) = sqlFetchRow($result); $content['settings'] = '{%message,MEMBER_TRANSFER_LATEST_IS=' . generateDateTime($newest, '3') . '%}'; } else { // Load template $content['settings'] = loadTemplate('member_transfer_settings', TRUE, $content); } // Free result sqlFreeResult($result); // Load template loadTemplate('member_transfer_overview', FALSE, $content); break; } // END - switch // [EOF] ?>