X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodules%2Fmember%2Fwhat-transfer.php;h=b535b08da2b5d221aa5556052c2877c02baa576a;hb=180f978ebe21d5fcec3a51be8405028e7523e6a9;hp=b080851b85a29c6751f1d77a16d675529fd4e003;hpb=c8d76610eb94093d4eed4fcd8a6cb72e74c8f6d8;p=mailer.git diff --git a/inc/modules/member/what-transfer.php b/inc/modules/member/what-transfer.php index b080851b85..b535b08da2 100644 --- a/inc/modules/member/what-transfer.php +++ b/inc/modules/member/what-transfer.php @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009, 2010 by Mailer Developer Team * + * Copyright (c) 2009 - 2011 by Mailer Developer Team * * For more information visit: http://www.mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -43,19 +43,23 @@ if (!defined('__SECURITY')) { } // Add description as navigation point -addMenuDescription('member', __FILE__); +addYouAreHereLink('member', __FILE__); if ((!isExtensionActive('transfer')) && (!isAdmin())) { - loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('transfer')); + displayMessage(generateExtensionInactiveNotInstalledMessage('transfer')); return; } // END - if // 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 @@ -67,9 +71,9 @@ switch ($mode) { if (isFormSent()) { // Add new transfer - if (getConfig('transfer_code') > 0) { + if (getTransferCode() > 0) { // Check for code - $code = generateRandomCode(getConfig('transfer_code'), postRequestParameter('code_chk'), getMemberId(), $content['max_transferable']); + $code = generateRandomCode(getTransferCode(), postRequestParameter('code_chk'), getMemberId(), $content['max_transferable']); $valid_code = ($code == postRequestParameter('code')); } else { // Zero length (= disabled) is always valid! @@ -123,7 +127,7 @@ switch ($mode) { $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 @@ -131,28 +135,27 @@ switch ($mode) { 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')); + // Remember transfer reason + $content['reason'] = postRequestParameter('reason'); // 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')); @@ -170,7 +173,7 @@ switch ($mode) { sendAdminNotification($adminSubject, 'admin_transfer_points', $content); // Transfer is completed - loadTemplate('admin_settings_saved', false, '
{--TRANSFER_COMPLETED--}' . '
{--TRANSFER_CONTINUE_OVERVIEW--}
'); + displayMessage('
{--TRANSFER_COMPLETED--}' . '
{--TRANSFER_CONTINUE_OVERVIEW--}
'); } elseif ($valid_code === false) { // Invalid Touring code! loadTemplate('admin_settings_unsaved', false, '{--TRANSFER_INVALID_CODE--}'); @@ -238,7 +241,7 @@ switch ($mode) { SQL_FREERESULT($result); } else { // No one else is opt-in - $OUT = loadTemplate('admin_settings_saved', true, '{--TRANSFER_NO_ONE_ELSE_OPT_IN--}'); + $OUT = displayMessage('{--TRANSFER_NO_ONE_ELSE_OPT_IN--}', true); $content['to_disabled'] = ' disabled="disabled"'; } @@ -246,14 +249,21 @@ switch ($mode) { $content['userid_selection'] = $OUT; // Generate Code - if (getConfig('transfer_code') > 0) { + if (getTransferCode() > 0) { + // Generate random number $rand = mt_rand(0, 99999); - $code = generateRandomCode(getConfig('transfer_code'), $rand, getMemberId(), $content['max_transferable']); + + // 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'] = loadTemplate('admin_settings_saved', true, '{--TRANSFER_NO_CODE--}'); + $content['captcha_code'] = displayMessage('{--TRANSFER_NO_CODE--}', true); } // Init points/reason @@ -278,14 +288,14 @@ 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 {?transfer_max?}"; + $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 {?transfer_max?}"; + $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--}'; @@ -299,26 +309,20 @@ switch ($mode) { // 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 @@ -327,7 +331,7 @@ switch ($mode) { // Nothing for in or out $OUT = ' - ' . loadTemplate('admin_settings_saved', true, $nothingMessage) . ' + ' . displayMessage($nothingMessage, true) . ' '; } @@ -336,19 +340,21 @@ switch ($mode) { $content['rows'] = $OUT; // Remeber total amount - $content['total'] = translateComma($totalPoints); + $content['total_points'] = $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, @@ -356,7 +362,7 @@ switch ($mode) { `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 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?}", @@ -364,7 +370,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_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 @@ -376,27 +382,28 @@ 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_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); @@ -404,23 +411,23 @@ KEY (`party_userid`) // Add points and switch color $total += $content['points']; } // END - while - - // Free memory - SQL_FREERESULT($result); } else { // Nothing for in and out $OUT = ' - ' . loadTemplate('admin_settings_saved', true, '{--TRANSFER_NO_INOUT_TRANSFERS--}') . ' + ' . displayMessage('{--TRANSFER_NO_INOUT_TRANSFERS--}', true) . ' '; } + // 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_points'] = $total; // Set title $content['title'] = '{--TRANSFER_LIST_ALL--}'; @@ -429,7 +436,7 @@ KEY (`party_userid`) $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); @@ -440,27 +447,27 @@ KEY (`party_userid`) 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'] = '' . $total . ''; + $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 - $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'] = '' . $dmy . ''; + $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'] = '' . $total . ''; + $content['all_link'] = '{%pipe,translateComma=' . $total . '%}'; } // END - if if (isFormSent()) { @@ -469,7 +476,7 @@ KEY (`party_userid`) array(postRequestParameter('opt_in'), getMemberId()), __FILE__, __LINE__); // "Settings saved..." - loadTemplate('admin_settings_saved', false, '{--SETTINGS_SAVED--}'); + displayMessage('{--SETTINGS_SAVED--}'); } // END - if // Init entries @@ -497,12 +504,12 @@ KEY (`party_userid`) FROM `{?_MYSQL_PREFIX?}_user_transfers_out` WHERE - `time_trans` > (UNIX_TIMESTAMP() - %s) AND `userid`=%s + (UNIX_TIMESTAMP() - `time_trans`) >= {?transfer_timeout?} AND + `userid`=%s ORDER BY `time_trans` DESC LIMIT 1", array( - getConfig('transfer_timeout'), getMemberId() ), __FILE__, __LINE__);