0) { // Check for code $code = generateRandomCode(getConfig('transfer_code'), postRequestElement('code_chk'), getUserId(), $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 = (postRequestElement('to_userid') > 0); // Check for nickname extension and set additional data // @TODO Rewrite this to a filter $add = ''; if (isExtensionActive('nickname')) { $add = ', `nickname`'; } // END - if // Re-check receivers and own personal data $result = SQL_QUERY_ESC("SELECT `userid`, `gender`, `surname`, `family`, `email`".$add." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid` IN ('%s','%s') AND `status`='CONFIRMED' LIMIT 2", array( getUserId(), bigintval(postRequestElement('to_userid')) ), __FILE__, __LINE__); // Do we have two entries? $valid_data = (SQL_NUMROWS($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); // Is the nickname extension not installed? if (!isExtensionActive('nickname')) { // Fix empty nicknames $content['sender']['nickname'] = ''; $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']; // Default is userids for subject line $SENDER = getUserId(); $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 != getUserId()) && (!empty($TEST_NICK_SENDER))) { $SENDER = $content['sender']['nickname']; } if (($TEST_NICK_REC != postRequestElement('to_userid')) && (!empty($TEST_NICK_REC))) { $RECIPIENT = $content['recipient']['nickname']; } } // END - if // Remember transfer reason and fancy date/time in constants $content['reason'] = secureString(postRequestElement('reason')); $content['expires'] = createFancyTime(getConfig('transfer_age')); // Generate tranafer id $content['trans_id'] = bigintval(generateRandomCode('10', mt_rand(0, 99999), getUserId(), 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')", array(bigintval(postRequestElement('to_userid')), getUserId(), bigintval(postRequestElement('points')), 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')", array(getUserId(), bigintval(postRequestElement('to_userid')), bigintval(postRequestElement('points')), postRequestElement('reason'), $content['trans_id']), __FILE__, __LINE__); // Add points to account *directly* ... addPointsDirectly('member_transfer', bigintval(postRequestElement('to_userid')), bigintval(postRequestElement('points'))); // ... and add it to current user's used points subtractPoints('transfer', getUserId(), postRequestElement('points')); // First send email to recipient $message = loadEmailTemplate('member_transfer_recipient', $content, postRequestElement('to_userid')); sendEmail($content['recipient']['email'], getMessage('TRANSFER_MEMBER_RECIPIENT_SUBJ') . ': ' . $SENDER, $message); // Second send email to sender $message = loadEmailTemplate('member_transfer_sender', $content, getUserId()); sendEmail($content['sender']['email'], getMessage('TRANSFER_MEMBER_SENDER_SUBJ') . ': ' . $RECIPIENT, $message); // At last send admin mail(s) $ADMIN_SUBJ = sprintf("%s (%s->%s)", getMessage('TRANSFER_ADMIN_SUBJECT'), $SENDER, $RECIPIENT); sendAdminNotification($ADMIN_SUBJ, 'admin_transfer_points', $content); // Transfer is completed loadTemplate('admin_settings_saved', false, getMessage('TRANSFER_COMPLETED') . "
{--TRANSFER_CONTINUE_OVERVIEW--}"); } elseif ($valid_code === false) { // Invalid Touring code! loadTemplate('admin_settings_saved', false, "
{--TRANSFER_INVALID_CODE--}
"); unsetPostRequestElement('ok'); } elseif ($valid_pass === false) { // Wrong password entered loadTemplate('admin_settings_saved', false, "
{--TRANSFER_INVALID_PASSWORD--}
"); unsetPostRequestElement('ok'); } elseif ($valid_amount === false) { // Too much points entered loadTemplate('admin_settings_saved', false, "
{--TRANSFER_INVALID_POINTS--}
"); unsetPostRequestElement('ok'); } elseif ($valid_reason === false) { // No transfer reason entered loadTemplate('admin_settings_saved', false, "
{--TRANSFER_INVALID_REASON--}
"); unsetPostRequestElement('ok'); } elseif ($valid_recipient === false) { // No recipient selected loadTemplate('admin_settings_saved', false, "
{--TRANSFER_INVALID_RECIPIENT--}
"); unsetPostRequestElement('ok'); } elseif ($valid_data === false) { // No recipient/sender selected loadTemplate('admin_settings_saved', false, "
{--TRANSFER_INVALID_DATA--}
"); unsetPostRequestElement('ok'); } // Free result SQL_FREERESULT($result); } // END - if if (!isFormSent()) { // Load member list if (isExtensionActive('nickname')) { // Load userid and nickname $result = SQL_QUERY_ESC("SELECT `userid`, `nickname` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' AND `opt_in`='Y' AND `userid` != '%s' ORDER BY `userid` ASC", array(getUserId()), __FILE__, __LINE__); } else { // Load only userid $result = SQL_QUERY_ESC("SELECT `userid`, `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' AND `opt_in`='Y' AND `userid` != '%s' ORDER BY `userid` ASC", array(getUserId()), __FILE__, __LINE__); } if (SQL_NUMROWS($result) > 0) { // Load list $OUT = " " . $img; } else { $code = '00000'; $content['captcha_code'] = loadTemplate('admin_settings_saved', true, getMessage('TRANSFER_NO_CODE')); } // Init points/reason $content['points'] = ''; $content['reason'] = ''; // Transfer maybe already entered valued' if (isGetRequestElementSet('ok')) { // Get values from form $content['points'] = bigintval(postRequestElement('points')); $content['reason'] = secureString(postRequestElement('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 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 ".getConfig('transfer_max'); $nothingMessage = getMessage('TRANSFER_NO_INCOMING_TRANSFERS'); $content['balance'] = getMessage('TRANSFER_TOTAL_INCOMING'); $content['title'] = getMessage('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'); break; } // END - switch // Run the SQL command and set total points to zero $totalPoints = 0; $result = SQL_QUERY_ESC($sql, array(getUserId()), __FILE__, __LINE__); // Do we have entries? if (SQL_NUMROWS($result) > 0) { $OUT = ''; $SW = 2; // @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 if ($type == 'OUT') $points = $points . '-'; // Prepare content for template // @TODO Rewrite: tid->trans_id,stamp->time_trans $row = array( 'sw' => $SW, 'tid' => $tid, 'stamp' => generateDateTime($stamp, 3), 'userid' => $userid, 'reason' => $reason, 'points' => translateComma($points) ); // Load row template $OUT .= loadTemplate('member_transfer_row2', true, $row); // Add points and switch color $totalPoints += $points; $SW = 3 - $SW; } // END - while // Free memory SQL_FREERESULT($result); } else { // Nothing for in or out $OUT = " ".loadTemplate('admin_settings_saved', true, $nothingMessage)." "; } // ... and add them to a constant for the template $content['rows'] = $OUT; // Remeber total amount $content['total'] = translateComma($totalPoints); // Load final template loadTemplate('member_transfer_list', false, $content); break; case 'list_all': // List all transactions // We fill a temporary table with data from both tables. This is much easier // to code and unstand 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 temporary table $result = SQL_QUERY("CREATE TEMPORARY TABLE `{?_MYSQL_PREFIX?}_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', KEY (`party_userid`) ) TYPE=HEAP", __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 %s", array(getUserId(), getConfig('transfer_max')), __FILE__, __LINE__); 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__); } // END - while // Free memory SQL_FREERESULT($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 %s", array(getUserId(), getConfig('transfer_max')), __FILE__, __LINE__); 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__); } // END - while // Free memory SQL_FREERESULT($result); $total = 0; if (SQL_NUMROWS($result) > 0) { // 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; 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']); // Load row template $OUT .= loadTemplate('member_transfer_row', true, $content); // 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 = " ".loadTemplate('admin_settings_saved', true, getMessage('TRANSFER_NO_INOUT_TRANSFERS'))." "; } // ... and add them to a constant for the template $content['rows'] = $OUT; // Remeber total amount $content['total'] = translateComma($total); // Set title $content['title'] = getMessage('TRANSFER_LIST_ALL'); // Set "balance" word $content['balance'] = getMessage('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__); // Load final template loadTemplate('member_transfer_list', false, $content); // Free some memory... SQL_FREERESULT($result); break; default: // Overview page // Check incoming transfers $total = countSumTotalData(getUserId(), 'user_transfers_in', 'id', 'userid', true); $content['in_link'] = $total; if ($total > 0) { $content['in_link'] = "".$total.""; } // END - if // Check outgoing transfers $dmy = countSumTotalData(getUserId(), 'user_transfers_out', 'id', 'userid', true); // Add to total amount $total += $dmy; $content['out_link'] = $dmy; if ($dmy > 0) { $content['out_link'] = "".$dmy.""; } // END - if // Total transactions $content['all_link'] = $total; if ($total > 0) { $content['all_link'] = "".$total.""; } // END - if if (isFormSent()) { // Save settings SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `opt_in`='%s' WHERE `userid`=%s LIMIT 1", array(postRequestElement('opt_in'), getUserId()), __FILE__, __LINE__); // Rember for next switch() command $opt_in = substr(postRequestElement('opt_in'), 0, 1); // "Settings saved..." loadTemplate('admin_settings_saved', false, "
{--SETTINGS_SAVED--}
"); } // END - if // Init entries foreach (array('allow_y','allow_n') as $entry) { $content[$entry] = ''; } // END - foreach // Set current selection $content['allow_' . strtolower($opt_in)] = ' checked="checked"'; // Set 'new transfer' link according to above option switch ($opt_in) { case 'Y': $content['new_link'] = "{--TRANSFER_NOW_LINK--}"; break; case 'N': $content['new_link'] = getMessage('TRANSFER_PLEASE_ALLOW_OPT_IN'); break; } // END - switch // Check for latest out-transfers $result = SQL_QUERY_ESC("SELECT `time_trans` FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE `time_trans` > (UNIX_TIMESTAMP() - %s) AND `userid`=%s ORDER BY `time_trans` DESC LIMIT 1", array( getConfig('transfer_timeout'), getUserId() ), __FILE__, __LINE__); // Do we have an entry? if (SQL_NUMROWS($result) == 1) { // Load newest transaction list($newest) = SQL_FETCHROW($result); $content['settings'] = sprintf(getMessage('TRANSFER_LATEST_IS'), generateDateTime($newest, 3)); } else { // Load template $content['settings'] = loadTemplate('member_transfer_settings', true); } // Free result SQL_FREERESULT($result); // Load template loadTemplate('member_transfer_overview', false, $content); break; } // END - switch // [EOF] ?>