X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodules%2Fmember%2Fwhat-transfer.php;h=cd9e8a25edae03538bbafb524c4b5ea6df90eabf;hb=97702d59eb179b54690f9ccc18df66cd981ab0df;hp=3d023aee084521c473118dc9f39148c6fa1076b9;hpb=508228c85fba8448d00865b1639cb8cd7a69e457;p=mailer.git
diff --git a/inc/modules/member/what-transfer.php b/inc/modules/member/what-transfer.php
index 3d023aee08..cd9e8a25ed 100644
--- a/inc/modules/member/what-transfer.php
+++ b/inc/modules/member/what-transfer.php
@@ -1,7 +1,7 @@
0) {
- // Check for code
- $code = generateRandomCodde(getConfig('transfer_code'), REQUEST_POST('code_chk'), getUserId(), constant('__TRANSFER_MAX_VALUE'));
- $valid_code = ($code == REQUEST_POST('code'));
- } else {
- // Zero length (= disabled) is always valid!
- $valid_code = true;
- }
+if ((getUserData('opt_in') != 'Y') && ($mode == 'new')) {
+ $mode = '';
+} // END - if
+
+switch ($mode) {
+ case 'new': // Start new transfer
+ // Get total points and subtract the balance amount from it = maximum transferable points
+ $total = getTotalPoints(getMemberId());
+
+ // Remember maximum value for template
+ $content['max_transferable'] = round($total - getConfig('transfer_balance') - 0.5);
+
+ if (isFormSent()) {
+ // Add new transfer
+ if (getTransferCode() > 0) {
+ // Check for code
+ $code = generateRandomCode(getTransferCode(), postRequestParameter('code_chk'), getMemberId(), $content['max_transferable']);
+ $valid_code = ($code == postRequestParameter('code'));
+ } else {
+ // Zero length (= disabled) is always valid!
+ $valid_code = true;
+ }
- // Test password
- $valid_pass = ($pass == generateHash(REQUEST_POST('password'), $pass));
+ // Test password
+ $valid_pass = ($pass == generateHash(postRequestParameter('password'), $pass));
- // Test transfer amount
- $valid_amount = ((REQUEST_ISSET_POST(('points'))) && (REQUEST_POST('points') <= constant('__TRANSFER_MAX_VALUE')));
+ // Test transfer amount
+ $valid_amount = ((isPostRequestParameterSet('points')) && (postRequestParameter('points') <= $content['max_transferable']));
- // Test reason for transfer
- $valid_reason = (REQUEST_ISSET_POST(('reason')));
+ // Test reason for transfer
+ $valid_reason = (isPostRequestParameterSet('reason'));
- // Test if a recipient is selected
- $valid_recipient = (REQUEST_POST('to_uid') > 0);
+ // Test if a recipient is selected
+ $valid_recipient = isValidUserId(postRequestParameter('to_userid'));
- // Check for nickname extension and set additional data
- $nick = false; $ADD = ", userid";
- if (EXT_IS_ACTIVE("nickname")) {
- $ADD = ", nickname";
- $nick = true;
- }
+ // Re-check receivers and own personal data
+ $result = SQL_QUERY_ESC("SELECT `userid`,`gender`,`surname`,`family`,`email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid` IN ('%s','%s') AND `status`='CONFIRMED' LIMIT 2",
+ array(
+ getMemberId(),
+ bigintval(postRequestParameter('to_userid'))
+ ), __FILE__, __LINE__);
- // 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' ORDER BY userid LIMIT 2",
- array(getUserId(), bigintval(REQUEST_POST('to_uid'))), __FILE__, __LINE__);
- $valid_data = (SQL_NUMROWS($result) == 2);
+ // Do we have two entries?
+ $valid_data = (SQL_NUMROWS($result) == 2);
- if ($valid_code && $valid_pass && $valid_amount && $valid_reason && $valid_recipient) {
- // Let's start the transfer and load user data
- list($uid1, $gender1, $sname1, $fname1, $email1, $nick1) = SQL_FETCHROW($result);
- list($uid2, $gender2, $sname2, $fname2, $email2, $nick2) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
- // @TODO Rewrite all these constants to array elements
- if ($uid1 == getUserId()) {
- // Data row 1 is sender's data
- define('__SENDER_GENDER' , TRANSLATE_GENDER($gender1));
- define('__SENDER_NICK' , $nick1);
- define('__SENDER_SNAME' , $sname1);
- define('__SENDER_FNAME' , $fname1);
- define('__SENDER_EMAIL' , $email1);
- // Data row 2 is recpient's data
- define('__RECIPIENT_GENDER', TRANSLATE_GENDER($gender2));
- define('__RECIPIENT_NICK' , $nick2);
- define('__RECIPIENT_SNAME' , $sname2);
- define('__RECIPIENT_FNAME' , $fname2);
- define('__RECIPIENT_EMAIL' , $email2);
+ // 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);
- // Prepare variables for testing
- $TEST_NICK_SENDER = $nick1;
- $TEST_NICK_REC = $nick2;
- } else {
- // Data row 2 is sender's data
- define('__SENDER_GENDER' , TRANSLATE_GENDER($gender2));
- define('__SENDER_NICK' , $nick2);
- define('__SENDER_SNAME' , $sname2);
- define('__SENDER_FNAME' , $fname2);
- define('__SENDER_EMAIL' , $email2);
- // Data row 1 is recpient's data
- define('__RECIPIENT_GENDER', TRANSLATE_GENDER($gender1));
- define('__RECIPIENT_NICK' , $nick1);
- define('__RECIPIENT_SNAME' , $sname1);
- define('__RECIPIENT_FNAME' , $fname1);
- define('__RECIPIENT_EMAIL' , $email1);
+ // 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 = $nick2;
- $TEST_NICK_REC = $nick1;
+ $TEST_NICK_SENDER = $content['sender']['nickname'];
+ $TEST_NICK_REC = $content['recipient']['nickname'];
+
+ // Default is userids for subject line
+ $SENDER = getMemberId();
+ $RECIPIENT = bigintval(postRequestParameter('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 != postRequestParameter('to_userid')) && (!empty($TEST_NICK_REC))) {
+ $RECIPIENT = $content['recipient']['nickname'];
+ } // END - if
+ } // END - if
+
+ // 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)",
+ 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)",
+ array(
+ getMemberId(),
+ bigintval(postRequestParameter('to_userid')),
+ bigintval(postRequestParameter('points')),
+ postRequestParameter('reason'),
+ $content['trans_id']
+ ), __FILE__, __LINE__);
+
+ // Add points to account *directly* ...
+ initReferalSystem();
+ addPointsThroughReferalSystem('transfer', bigintval(postRequestParameter('to_userid')), bigintval(postRequestParameter('points')));
+
+ // ... and add it to current user's used points and ignore return status
+ subtractPoints('transfer', getMemberId(), postRequestParameter('points'));
+
+ // First send email to recipient
+ $message = loadEmailTemplate('member_transfer_recipient', $content, postRequestParameter('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)", '{--TRANSFER_ADMIN_SUBJECT--}', $SENDER, $RECIPIENT);
+ sendAdminNotification($adminSubject, 'admin_transfer_points', $content);
+
+ // Transfer is completed
+ displayMessage('
{--TRANSFER_COMPLETED--}' . '
');
+ } elseif ($valid_code === false) {
+ // Invalid Touring code!
+ loadTemplate('admin_settings_unsaved', false, '{--TRANSFER_INVALID_CODE--}');
+ unsetPostRequestParameter('ok');
+ } elseif ($valid_pass === false) {
+ // Wrong password entered
+ loadTemplate('admin_settings_unsaved', false, '{--TRANSFER_INVALID_PASSWORD--}');
+ unsetPostRequestParameter('ok');
+ } elseif ($valid_amount === false) {
+ // Too much points entered
+ loadTemplate('admin_settings_unsaved', false, '{--TRANSFER_INVALID_POINTS--}');
+ unsetPostRequestParameter('ok');
+ } elseif ($valid_reason === false) {
+ // No transfer reason entered
+ loadTemplate('admin_settings_unsaved', false, '{--TRANSFER_INVALID_REASON--}');
+ unsetPostRequestParameter('ok');
+ } elseif ($valid_recipient === false) {
+ // No recipient selected
+ loadTemplate('admin_settings_unsaved', false, '{--TRANSFER_INVALID_RECIPIENT--}');
+ unsetPostRequestParameter('ok');
+ } elseif ($valid_data === false) {
+ // No recipient/sender selected
+ loadTemplate('admin_settings_unsaved', false, '{--TRANSFER_INVALID_DATA--}');
+ unsetPostRequestParameter('ok');
}
- // Sender's UID is always currently stored in cookie userid...
- define('__SENDER_UID' , getUserId());
- define('__RECIPIENT_UID' , REQUEST_POST('to_uid'));
+ // Free result
+ SQL_FREERESULT($result);
+ } // END - if
+
+ if (!isFormSent()) {
+ // Load member list
+ $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' AND `opt_in`='Y' AND `userid` != '%s' ORDER BY `userid` ASC",
+ array(getMemberId()), __FILE__, __LINE__);
+
+ if (!SQL_HASZERONUMS($result)) {
+ // Load list
+ $OUT = '
+ {--SELECT_NONE--} ';
+ while (list($userid) = SQL_FETCHROW($result)) {
+ $OUT .= ' ';
+ } // END - while
+ $OUT .= ' ';
+ $content['to_disabled'] = '';
+
+ // Free memory
+ SQL_FREERESULT($result);
+ } else {
+ // No one else is opt-in
+ $OUT = displayMessage('{--TRANSFER_NO_ONE_ELSE_OPT_IN--}', true);
+ $content['to_disabled'] = ' disabled="disabled"';
+ }
- $SENDER = constant('__SENDER_UID');
- $RECIPIENT = constant('__RECIPIENT_UID');
- if ($nick) {
- if (($TEST_NICK_SENDER != constant('__SENDER_UID')) && (!empty($TEST_NICK_SENDER))) {
- $SENDER = constant('__SENDER_NICK');
- }
+ // Transfer output to constant for the template
+ $content['userid_selection'] = $OUT;
- if (($TEST_NICK_REC != constant('__RECIPIENT_UID')) && (!empty($TEST_NICK_REC))) {
- $RECIPIENT = constant('__RECIPIENT_NICK');
- }
- }
+ // Generate Code
+ if (getTransferCode() > 0) {
+ // Generate random number
+ $rand = mt_rand(0, 99999);
- // Remember transfer reason and fancy date/time in constants
- define('__TRANSFER_REASON', REQUEST_POST('reason'));
- define('__TRANSFER_EXPIRES', CREATE_FANCY_TIME(getConfig('transfer_age')));
-
- // Generate tranafer id
- define('__TRANS_ID', bigintval(generateRandomCodde("10", mt_rand(0, 99999), getUserId(), REQUEST_POST('reason'))));
-
- // Add entries to both tables
- SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_transfers_in` (userid, from_uid, points, reason, time_trans, trans_id) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP(),'%s')",
- array(bigintval(REQUEST_POST('to_uid')), getUserId(), bigintval(REQUEST_POST('points')), REQUEST_POST('reason'), __TRANS_ID),
- __FILE__, __LINE__);
- SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_transfers_out` (userid, to_uid, points, reason, time_trans, trans_id) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP(),'%s')",
- array(getUserId(), bigintval(REQUEST_POST('to_uid')), bigintval(REQUEST_POST('points')), REQUEST_POST('reason'), __TRANS_ID),
- __FILE__, __LINE__);
-
- // Add points to account *directly* ...
- ADD_POINTS_REFSYSTEM("member_transfer", bigintval(REQUEST_POST('to_uid')), bigintval(REQUEST_POST('points')), false, "0", false, "direct");
-
- // ... and add it to current user's used points
- SUB_POINTS("transfer", getUserId(), REQUEST_POST('points'));
-
- // First send email to recipient
- $msg = LOAD_EMAIL_TEMPLATE("member_transfer_recipient", "", constant('__RECIPIENT_UID'));
- SEND_EMAIL(constant('__RECIPIENT_EMAIL'), getMessage('TRANSFER_MEMBER_RECIPIENT_SUBJ').": ".$SENDER, $msg);
-
- // Second send email to sender
- $msg = LOAD_EMAIL_TEMPLATE("member_transfer_sender", "", constant('__SENDER_UID'));
- SEND_EMAIL(constant('__SENDER_EMAIL'), getMessage('TRANSFER_MEMBER_SENDER_SUBJ').": ".$RECIPIENT, $msg);
-
- // At last send admin mail(s)
- $ADMIN_SUBJ = sprintf("%s (%s->%s)", getMessage('TRANSFER_ADMIN_SUBJECT'), $SENDER, $RECIPIENT);
- SEND_ADMIN_NOTIFICATION($ADMIN_SUBJ, "admin_transfer_points");
-
- // Transfer is completed
- LOAD_TEMPLATE("admin_settings_saved", false, getMessage('TRANSFER_COMPLETED')."{--TRANSFER_CONTINUE_OVERVIEW--} ");
- } elseif (!$valid_code) {
- // Invalid Touring code!
- LOAD_TEMPLATE("admin_settings_saved", false, "{--TRANSFER_INVALID_CODE--}
");
- REQUEST_UNSET_POST('ok');
- } elseif (!$valid_pass) {
- // Wrong password entered
- LOAD_TEMPLATE("admin_settings_saved", false, "{--TRANSFER_INVALID_PASSWORD--}
");
- REQUEST_UNSET_POST('ok');
- } elseif (!$valid_amount) {
- // Too much points entered
- LOAD_TEMPLATE("admin_settings_saved", false, "{--TRANSFER_INVALID_POINTS--}
");
- REQUEST_UNSET_POST('ok');
- } elseif (!$valid_reason) {
- // No transfer reason entered
- LOAD_TEMPLATE("admin_settings_saved", false, "{--TRANSFER_INVALID_REASON--}
");
- REQUEST_UNSET_POST('ok');
- } elseif (!$valid_recipient) {
- // No recipient selected
- LOAD_TEMPLATE("admin_settings_saved", false, "{--TRANSFER_INVALID_RECIPIENT--}
");
- REQUEST_UNSET_POST('ok');
- } elseif (!$valid_data) {
- // No recipient selected
- LOAD_TEMPLATE("admin_settings_saved", false, "{--TRANSFER_INVALID_DATA--}
");
- REQUEST_UNSET_POST('ok');
- }
- }
-
- if (!IS_FORM_SENT()) {
- // Load member list
- if (EXT_IS_ACTIVE("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",
- 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",
- array(getUserId()), __FILE__, __LINE__);
- }
+ // Generate CAPTCHA code
+ $code = generateRandomCode(getTransferCode(), $rand, getMemberId(), $content['max_transferable']);
+
+ // Generate image (HTML code)
+ $img = generateImageOrCode($code, false);
- if (SQL_NUMROWS($result) > 0) {
- // Load list
- $OUT = "
- {--SELECT_NONE--} \n";
- // @TODO Try to rewrite his to $content = SQL_FETCHARRAY(), see some lines above for two different queries
- while (list($uid, $nick) = SQL_FETCHROW($result)) {
- $OUT .= " ' . $img;
+ } else {
+ $code = '00000';
+ $content['captcha_code'] = displayMessage('{--TRANSFER_NO_CODE--}', true);
}
- $OUT .= " \n";
- define('__TRANSFER_TO_DISABLED', "");
+
+ // Init points/reason
+ $content['points'] = '';
+ $content['reason'] = '';
+
+ // Transfer maybe already entered valued'
+ if (isPostRequestParameterSet('ok')) {
+ // Get values from form
+ $content['points'] = postRequestParameter('points');
+ $content['reason'] = postRequestParameter('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 = '{--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?}';
+ $nothingMessage = '{--TRANSFER_NO_OUTGOING_TRANSFERS--}';
+ $content['balance'] = '{--TRANSFER_TOTAL_OUTGOING--}';
+ $content['title'] = '{--TRANSFER_LIST_OUTGOING--}';
+ break;
+ } // END - switch
+
+ // Run the SQL command and set total points to zero
+ $totalPoints = '0';
+ $result = SQL_QUERY_ESC($sql, array(getMemberId()), __FILE__, __LINE__);
+
+ // Do we have entries?
+ if (!SQL_HASZERONUMS($result)) {
+ $OUT = '';
+ while ($content = SQL_FETCHARRAY($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
SQL_FREERESULT($result);
} else {
- // No one else is opt-in
- $OUT = getMessage('TRANSFER_NO_ONE_ELSE_OPT_IN');
- define('__TRANSFER_TO_DISABLED', " disabled");
+ // Nothing for in or out
+ $OUT = '
+
+ ' . displayMessage($nothingMessage, true) . '
+
+ ';
}
- // Transfer output to constant for the template
- define('__TRANSFER_USERID_SELECTION', $OUT);
+ // ... and add them to a constant for the template
+ $content['rows'] = $OUT;
- // Generate Code
- if (getConfig('transfer_code') > 0) {
- $rand = mt_rand(0, 99999);
- $code = generateRandomCodde(getConfig('transfer_code'), $rand, getUserId(), constant('__TRANSFER_MAX_VALUE'));
- $img = GENERATE_IMAGE($code, false);
- define('__TRANSFER_IMAGE_INPUT', " ".$img);
- } else {
- $code = "00000";
- define('__TRANSFER_IMAGE_INPUT', getMessage('TRANSFER_NO_CODE'));
- }
+ // Remeber total amount
+ $content['total_points'] = $totalPoints;
- // Transfer maybe already entered valued'
- if (REQUEST_ISSET_GET('ok')) {
- // Get values from form
- define('__TRANSFER_POINTS_VALUE', bigintval(REQUEST_POST('points')));
- define('__TRANSFER_REASON_VALUE', strip_tags(REQUEST_POST('reason')));
- } else {
- // Set empty values
- define('__TRANSFER_POINTS_VALUE', "");
- define('__TRANSFER_REASON_VALUE', "");
- }
-
- // Output form
- LOAD_TEMPLATE("member_transfer_new");
- }
- 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
- switch ($MODE)
- {
- case "list_in":
- $sql = "SELECT trans_id, from_uid, points, reason, time_trans FROM `{!_MYSQL_PREFIX!}_user_transfers_in` WHERE userid=%s ORDER BY time_trans DESC LIMIT ".getConfig('transfer_max');
- // @TODO Rewrite these constants
- $NOTHING = getMessage('TRANSFER_NO_INCOMING_TRANSFERS');
- define('__TRANSFER_SUM', getMessage('TRANSFER_TOTAL_INCOMING'));
- define('__TRANSFER_TITLE', getMessage('TRANSFER_LIST_INCOMING'));
+ // Load final template
+ loadTemplate('member_transfer_list', false, $content);
break;
- case "list_out":
- $sql = "SELECT trans_id, to_uid, points, reason, time_trans FROM `{!_MYSQL_PREFIX!}_user_transfers_out` WHERE userid=%s ORDER BY time_trans DESC LIMIT ".getConfig('transfer_max');
- // @TODO Rewrite these constants
- $NOTHING = getMessage('TRANSFER_NO_OUTGOING_TRANSFERS');
- define('__TRANSFER_SUM', getMessage('TRANSFER_TOTAL_OUTGOING'));
- define('__TRANSFER_TITLE', getMessage('TRANSFER_LIST_OUTGOING'));
- break;
- }
-
- // Run the SQL command
- $total = 0;
- $result = SQL_QUERY_ESC($sql, array(getUserId()), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) > 0) {
- $OUT = ""; $SW = 2;
- // @TODO This should be somehow rewritten to $content = SQL_FETCHARRAY(), see switch() block above for SQL queries
- while (list($tid, $uid, $points, $reason, $stamp) = SQL_FETCHROW($result)) {
- // Rewrite points
- if ($type == "OUT") $points = $points."-";
-
- // Prepare content for template
- $content = array(
- 'sw' => $SW,
- 'tid' => $id,
- 'stamp' => MAKE_DATETIME($stamp, "3"),
- 'uid' => $uid,
- 'reason' => $reason,
- 'points' => TRANSLATE_COMMA($points)
- );
-
- // Load row template
- $OUT .= LOAD_TEMPLATE("member_transfer_row2", true, $content);
-
- // Add points and switch color
- $total += $points;
- $SW = 3 - $SW;
- }
+ 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 = 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,
+`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 = 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?}",
+ array(getMemberId()), __FILE__, __LINE__);
+ while ($content = SQL_FETCHROW($result)) {
+ $content[] = 'IN';
+ $content = implode("','", $content);
+ $res_temp = SQL_QUERY_ESC("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
SQL_FREERESULT($result);
- } else {
- // Nothing for in or out
- $OUT = "
-
- ".LOAD_TEMPLATE("admin_settings_saved", true, $NOTHING)."
-
- ";
- }
-
- // ... and add them to a constant for the template
- // @TODO Rewrite these constants
- define('__TRANSFER_ROWS', $OUT);
-
- // Remeber total amount
- define('__TRANSFER_TOTAL_VALUE', $total);
-
- // Load final template
- LOAD_TEMPLATE("member_transfer_list");
- 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_uid 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_uid)
-) TYPE=HEAP", __FILE__, __LINE__);
-
- // Let's begin with the incoming list
- $result = SQL_QUERY_ESC("SELECT trans_id, from_uid, points, reason, time_trans FROM `{!_MYSQL_PREFIX!}_user_transfers_in` WHERE userid=%s ORDER BY `id` 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_uid, points, reason, time_trans, trans_type) VALUES ('".$DATA."')", __FILE__, __LINE__);
- }
-
- // Free memory
- SQL_FREERESULT($result);
-
- // As the last table transfer data from outgoing table to temporary
- $result = SQL_QUERY_ESC("SELECT trans_id, to_uid, 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_uid, points, reason, time_trans, trans_type) VALUES ('".$DATA."')", __FILE__, __LINE__);
- }
-
- // Free memory
- SQL_FREERESULT($result);
-
- $total = 0;
- if (SQL_NUMROWS($result) > 0) {
+
+ // 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 {?transfer_max?}",
+ array(getMemberId()), __FILE__, __LINE__);
+ while ($content = SQL_FETCHROW($result)) {
+ $content[] = 'OUT';
+ $content = implode("','", $content);
+ $res_temp = SQL_QUERY_ESC("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
+ SQL_FREERESULT($result);
+
// Search for entries
- $result = SQL_QUERY("SELECT party_uid, 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'] = MAKE_DATETIME($content['time_trans'], "3");
- $content['points'] = TRANSLATE_COMMA($content['points']);
-
- // Load row template
- $OUT .= LOAD_TEMPLATE("member_transfer_row", true, $content);
-
- // Add points and switch color
- $total += $content['points'];
- $SW = 3 - $SW;
+ $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)) {
+ // Output rows
+ $OUT = '';
+ while ($content = SQL_FETCHARRAY($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
SQL_FREERESULT($result);
- } else {
- // Nothing for in and out
- $OUT = "
-
- ".LOAD_TEMPLATE("admin_settings_saved", true, getMessage('TRANSFER_NO_INOUT_TRANSFERS'))."
-
- ";
- }
-
- // ... and add them to a constant for the template
- // @TODO Rewrite all these constants
- define('__TRANSFER_ROWS', $OUT);
-
- // Remeber total amount
- define('__TRANSFER_TOTAL_VALUE', $total);
-
- // Set title
- define('__TRANSFER_TITLE', getMessage('TRANSFER_LIST_ALL'));
-
- // Set "balance" word
- define('__TRANSFER_SUM', getMessage('TRANSFER_TOTAL_BALANCE'));
-
- // Load final template
- LOAD_TEMPLATE("member_transfer_list");
-
- // 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__);
-
- // Free some memory...
- SQL_FREERESULT($result);
- break;
-
-case "": // Overview page
- // Check incoming transfers
- $result = SQL_QUERY_ESC("SELECT COUNT(id) FROM `{!_MYSQL_PREFIX!}_user_transfers_in` WHERE userid=%s", array(getUserId()), __FILE__, __LINE__);
- list($dmy) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
-
- $total=$dmy;
- if ($dmy > 0) {
- define('__TRANSFER_IN_LINK', "".$dmy." ");
- } else {
- define('__TRANSFER_IN_LINK', $dmy);
- }
-
- // Check outgoing transfers
- $result = SQL_QUERY_ESC("SELECT COUNT(id) FROM `{!_MYSQL_PREFIX!}_user_transfers_out` WHERE userid=%s", array(getUserId()), __FILE__, __LINE__);
- list($dmy) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
-
- $total+=$dmy;
- if ($dmy > 0) {
- define('__TRANSFER_OUT_LINK', "".$dmy." ");
- } else {
- define('__TRANSFER_OUT_LINK', $dmy);
- }
-
- // Total transactions
- if ($total > 0) {
- define('__TRANSFER_ALL_LINK', "".$total." ");
- } else {
- define('__TRANSFER_ALL_LINK', $total);
- }
-
- if (IS_FORM_SENT()) {
- // Save settings
- SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET opt_in='%s' WHERE userid=%s LIMIT 1",
- array(REQUEST_POST('opt_in'), getUserId()), __FILE__, __LINE__);
-
- // Rember for next switch() command
- $opt_in = REQUEST_POST('opt_in');
-
- // "Settings saved..."
- LOAD_TEMPLATE("admin_settings_saved", false, "{--SETTINGS_SAVED--}
");
- }
-
- switch ($opt_in)
- {
- case "Y":
- define('__TRANSFER_ALLOW_Y', " checked=\"checked\"");
- define('__TRANSFER_ALLOW_N', "");
- define('__TRANSFER_NEW_LINK', "{--TRANSFER_NOW_LINK--} ");
- break;
- case "N":
- define('__TRANSFER_ALLOW_Y', "");
- define('__TRANSFER_ALLOW_N', " checked=\"checked\"");
- define('__TRANSFER_NEW_LINK', getMessage('TRANSFER_PLEASE_ALLOW_OPT_IN'));
+ // ... 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 = 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);
+
+ // Free some memory...
+ SQL_FREERESULT($result);
break;
- }
-
- // 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__);
- if (SQL_NUMROWS($result) == 0) {
- // Load template
- define('__TRANSFER_SETTINGS_CONTENT', LOAD_TEMPLATE("member_transfer_settings", true));
- } else {
- // Load newest transaction
- list($newest) = SQL_FETCHROW($result);
+
+ 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
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `opt_in`='%s' WHERE `userid`=%s LIMIT 1",
+ array(postRequestParameter('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'] = '{--TRANSFER_NOW_LINK--} ';
+ break;
+
+ case 'N':
+ $content['new_link'] = '{--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
+ (UNIX_TIMESTAMP() - `time_trans`) >= {?transfer_timeout?} AND
+ `userid`=%s
+ORDER BY
+ `time_trans` DESC
+LIMIT 1",
+ array(
+ getMemberId()
+ ), __FILE__, __LINE__);
+
+ // Do we have an entry?
+ if (SQL_NUMROWS($result) == 1) {
+ // Load newest transaction
+ list($newest) = SQL_FETCHROW($result);
+ $content['settings'] = '{%message,TRANSFER_LATEST_IS=' . generateDateTime($newest, '3') . '%}';
+ } else {
+ // Load template
+ $content['settings'] = loadTemplate('member_transfer_settings', true, $content);
+ }
+
+ // Free result
SQL_FREERESULT($result);
- define('__TRANSFER_SETTINGS_CONTENT', sprintf(getMessage('TRANSFER_LATEST_IS'), MAKE_DATETIME($newest, "3")));
- }
- // Load template
- LOAD_TEMPLATE("member_transfer_overview");
- break;
-}
-//
+ // Load template
+ loadTemplate('member_transfer_overview', false, $content);
+ break;
+} // END - switch
+
+// [EOF]
?>