* $Date:: $ *
* $Tag:: 0.2.1-FINAL $ *
* $Author:: $ *
- * Needs to be in all Files and every File needs "svn propset *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
* -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
* Copyright (c) 2009, 2010 by Mailer Developer Team *
// Check for mode in GET
$mode = '';
-if (isGetRequestParameterSet('mode')) $mode = getRequestParameter('mode');
+if (isGetRequestParameterSet('mode')) {
+ $mode = getRequestParameter('mode');
+} // END - if
// Check for "faker"
-if ((getUserData('opt_in') != 'Y') && ($mode == 'new')) $mode = '';
+if ((getUserData('opt_in') != 'Y') && ($mode == 'new')) {
+ $mode = '';
+} // END - if
switch ($mode) {
case 'new': // Start new transfer
$TEST_NICK_REC = $content['recipient']['nickname'];
// Default is userids for subject line
- $SENDER = getMemberId();
+ $SENDER = getMemberId();
$RECIPIENT = bigintval(postRequestParameter('to_userid'));
// If nickname is installed we can set the nickname
if (isExtensionActive('nickname')) {
if (($TEST_NICK_SENDER != getMemberId()) && (!empty($TEST_NICK_SENDER))) {
$SENDER = $content['sender']['nickname'];
- }
+ } // END - if
if (($TEST_NICK_REC != postRequestParameter('to_userid')) && (!empty($TEST_NICK_REC))) {
$RECIPIENT = $content['recipient']['nickname'];
- }
+ } // END - if
} // END - if
// Remember transfer reason and fancy date/time in constants
$content['reason'] = secureString(postRequestParameter('reason'));
- $content['expires'] = createFancyTime(getConfig('transfer_age'));
+ $content['expires'] = '{%config,createFancyTime=transfer_age%}';
// Generate tranafer id
$content['trans_id'] = bigintval(generateRandomCode('10', mt_rand(0, 99999), getMemberId(), postRequestParameter('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')",
+ 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(postRequestParameter('to_userid')), getMemberId(), bigintval(postRequestParameter('points')), postRequestParameter('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')",
+ 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(getMemberId(), bigintval(postRequestParameter('to_userid')), bigintval(postRequestParameter('points')), postRequestParameter('reason'), $content['trans_id']), __FILE__, __LINE__);
// Add points to account *directly* ...
- addPointsDirectly('member_transfer', bigintval(postRequestParameter('to_userid')), bigintval(postRequestParameter('points')));
+ addPointsDirectly('transfer', bigintval(postRequestParameter('to_userid')), bigintval(postRequestParameter('points')));
// ... and add it to current user's used points
subtractPoints('transfer', getMemberId(), postRequestParameter('points'));
// Generate Code
if (getConfig('transfer_code') > 0) {
+ // Generate random number
$rand = mt_rand(0, 99999);
+
+ // Generate CAPTCHA code
$code = generateRandomCode(getConfig('transfer_code'), $rand, getMemberId(), $content['max_transferable']);
+
+ // Generate image (HTML code)
$img = generateImageOrCode($code, false);
+
+ // Add all and hidden field
$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'] . ' /> ' . $img;
} else {
$code = '00000';
// Do we have entries?
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
- if ($type == 'OUT') $points = $points . '-';
+ while ($content = SQL_FETCHARRAY($result)) {
+ // Rewrite points, out is subtracted
+ if ($type == 'OUT') {
+ $content['points'] = $content['points'] * -1;
+ } // END - if
// Prepare content for template
- // @TODO Rewrite: tid->trans_id,stamp->time_trans
- $row = array(
- 'trans_id' => $tid,
- 'stamp' => generateDateTime($stamp, 3),
- 'userid' => $userid,
- 'reason' => $reason,
- 'points' => $points
- );
+ $$content['time_trans'] = generateDateTime($content['time_trans'], 3);
// Load row template
- $OUT .= loadTemplate('member_transfer_row2', true, $row);
+ $OUT .= loadTemplate('member_transfer_row2', true, $content);
// Add points and switch color
- $totalPoints += $points;
+ $totalPoints += $content['points'];
} // END - while
// Free memory
$content['rows'] = $OUT;
// Remeber total amount
- $content['total'] = translateComma($totalPoints);
+ $content['total'] = $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` (
+ /*
+ * 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 = SQL_QUERY_ESC("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,
`time_trans` VARCHAR(10) NOT NULL DEFAULT 0,
`trans_type` ENUM('IN','OUT') NOT NULL DEFAULT 'IN',
KEY (`party_userid`)
-) TYPE=HEAP", __FILE__, __LINE__);
+) TYPE=HEAP", 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?}",
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_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_%s_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('" . $DATA . "')", array(getMemberId()), __FILE__, __LINE__);
} // END - while
// Free memory
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_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_%s_transfers_tmp` (`trans_id`, `party_userid`, `points`, `reason`, `time_trans`, `trans_type`) VALUES ('" . $DATA . "')", array(getMemberId()), __FILE__, __LINE__);
} // END - while
// Free memory
SQL_FREERESULT($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",
+ array(getMemberId()), __FILE__, __LINE__);
+
$total = '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 = '';
while ($content = SQL_FETCHARRAY($result)) {
- // Rewrite points
- if ($content['trans_type'] == 'OUT') $content['points'] = '-'.$content['points']."";
+ // 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);
- $content['points'] = translateComma($content['points']);
// Load row template
$OUT .= loadTemplate('member_transfer_row', true, $content);
// Add points and switch color
$total += $content['points'];
} // END - while
-
- // Free memory
- SQL_FREERESULT($result);
} else {
// Nothing for in and out
$OUT = '<tr>
</tr>';
}
+ // Free memory
+ SQL_FREERESULT($result);
+
// ... and add them to a constant for the template
$content['rows'] = $OUT;
// Remeber total amount
- $content['total'] = translateComma($total);
+ $content['total'] = $total;
// Set title
$content['title'] = '{--TRANSFER_LIST_ALL--}';
$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__);
+ $result = SQL_QUERY_ESC("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_%s_transfers_tmp`", array(getMemberId()), __FILE__, __LINE__);
// Load final template
loadTemplate('member_transfer_list', false, $content);
default: // Overview page
// Check incoming transfers
- $total = countSumTotalData(getMemberId(), 'user_transfers_in', 'id', 'userid', true);
- $content['in_link'] = $total;
- if ($total > 0) {
- $content['in_link'] = '<a href="{%url=modules.php?module=login&what=transfer&mode=list_in%}">' . $total . '</a>';
+ $totalIn = countSumTotalData(getMemberId(), 'user_transfers_in', 'id', 'userid', true);
+ $content['in_link'] = $totalIn;
+ if ($totalIn > 0) {
+ $content['in_link'] = '<a href="{%url=modules.php?module=login&what=transfer&mode=list_in%}">' . $totalIn . '</a>';
} // END - if
// Check outgoing transfers
- $dmy = countSumTotalData(getMemberId(), 'user_transfers_out', 'id', 'userid', true);
+ $totalOut = countSumTotalData(getMemberId(), 'user_transfers_out', 'id', 'userid', true);
- // Add to total amount
- $total += $dmy;
-
- $content['out_link'] = $dmy;
- if ($dmy > 0) {
- $content['out_link'] = '<a href="{%url=modules.php?module=login&what=transfer&mode=list_out%}">' . $dmy . '</a>';
+ $content['out_link'] = $totalOut;
+ if ($totalOut > 0) {
+ $content['out_link'] = '<a href="{%url=modules.php?module=login&what=transfer&mode=list_out%}">' . $totalOut . '</a>';
} // END - if
+ // Add all to total amount
+ $total = $totalIn + $totalOut;
+
// Total transactions
$content['all_link'] = $total;
if ($total > 0) {
- $content['all_link'] = '<a href="{%url=modules.php?module=login&what=transfer&mode=list_all%}">' . $total . '</a>';
+ $content['all_link'] = '<a href="{%url=modules.php?module=login&what=transfer&mode=list_all%}">{%pipe,translateComma=' . $total . '%}</a>';
} // END - if
if (isFormSent()) {
FROM
`{?_MYSQL_PREFIX?}_user_transfers_out`
WHERE
- `time_trans` > (UNIX_TIMESTAMP() - %s) AND `userid`=%s
+ `time_trans` > (UNIX_TIMESTAMP() - {?transfer_timeout?}) AND
+ `userid`=%s
ORDER BY
`time_trans` DESC
LIMIT 1",
array(
- getConfig('transfer_timeout'),
getMemberId()
), __FILE__, __LINE__);