X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodules%2Fmember%2Fwhat-transfer.php;h=8a472a61291bbaddbd302252407587b0e9958ea5;hb=e6d0294f587cab6b74f689ecdf2ebb3cf2b09e25;hp=0e9c148ae811478d6e9b9e6793f8583905bdb465;hpb=822c2dd5a7962a2c841bc25d83ac05f370a226e8;p=mailer.git
diff --git a/inc/modules/member/what-transfer.php b/inc/modules/member/what-transfer.php
index 0e9c148ae8..8a472a6129 100644
--- a/inc/modules/member/what-transfer.php
+++ b/inc/modules/member/what-transfer.php
@@ -10,9 +10,14 @@
* -------------------------------------------------------------------- *
* Kurzbeschreibung : Punktetransfers *
* -------------------------------------------------------------------- *
- * *
+ * $Revision:: $ *
+ * $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 - 2008 by Roland Haeder *
+ * Copyright (c) 2003 - 2009 by Roland Haeder *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -32,580 +37,515 @@
************************************************************************/
// Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
- $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
- require($INC);
-} elseif (!IS_MEMBER()) {
- LOAD_URL("modules.php?module=index");
-} elseif ((!EXT_IS_ACTIVE("transfer")) && (!IS_ADMIN())) {
- ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "transfer");
- return;
+if (!defined('__SECURITY')) {
+ die();
+} elseif (!isMember()) {
+ redirectToIndexMemberOnlyModule();
}
// Add description as navigation point
-ADD_DESCR("member", basename(__FILE__));
+addMenuDescription('member', __FILE__);
+
+if ((!isExtensionActive('transfer')) && (!isAdmin())) {
+ loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('transfer'));
+ return;
+} // END - if
// Load data
-$result = SQL_QUERY_ESC("SELECT opt_in FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
- array($GLOBALS['userid']), __FILE__, __LINE__);
+$result = SQL_QUERY_ESC("SELECT `opt_in` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(getUserId()), __FILE__, __LINE__);
list($opt_in) = SQL_FETCHROW($result);
// Free memory
SQL_FREERESULT($result);
-$MODE = "";
-if (!empty($_GET['mode'])) $MODE = $_GET['mode'];
+// Check for mode in GET
+$mode = '';
+if (isGetRequestElementSet('mode')) $mode = getRequestElement('mode');
// Check for "faker"
-if (($opt_in == "N") && ($MODE == "new")) $MODE = "";
-
-switch ($MODE)
-{
-case "new": // Start new transfer
- // Get total points and subtract the balance amount from it = maximum transferable points
- $result = SQL_QUERY_ESC("SELECT SUM(points) FROM "._MYSQL_PREFIX."_user_points WHERE userid=%s AND points > 0",
- array($GLOBALS['userid']), __FILE__, __LINE__);
- list($total) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
-
- // Get totally used points and password
- $result = SQL_QUERY_ESC("SELECT used_points, password FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
- array($GLOBALS['userid']), __FILE__, __LINE__);
- list($used, $pass) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
-
- // Remember maximum value for template
- define('__TRANSFER_MAX_VALUE', round($total - $used - $_CONFIG['transfer_balance'] - 0.5));
-
- if (isset($_POST['ok']))
- {
- // Add new transfer
- if ($_CONFIG['transfer_code'] > 0)
- {
- // Check for code
- $code = GEN_RANDOM_CODE($_CONFIG['transfer_code'], $_POST['code_chk'], $GLOBALS['userid'], __TRANSFER_MAX_VALUE);
- $valid_code = ($code == $_POST['code']);
- }
- else
- {
- // Zero length (= disabled) is always valid!
- $valid_code = true;
- }
+if (($opt_in != 'Y') && ($mode == 'new')) $mode = '';
+
+switch ($mode) {
+ case 'new': // Start new transfer
+ // Get total points and subtract the balance amount from it = maximum transferable points
+ $total = countSumTotalData(getUserId(), 'user_points', 'points') - countSumTotalData(getUserId(), 'user_data', 'used_points');
+
+ // Remember maximum value for template
+ $content['max_transferable'] = round($total - getConfig('transfer_balance') - 0.5);
+
+ if (isFormSent()) {
+ // Add new transfer
+ if (getConfig('transfer_code') > 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($_POST['password'], $pass));
+ // Test password
+ $valid_pass = ($pass == generateHash(postRequestElement('password'), $pass));
- // Test transfer amount
- $valid_amount = ((!empty($_POST['points'])) && ($_POST['points'] <= __TRANSFER_MAX_VALUE));
+ // Test transfer amount
+ $valid_amount = ((isPostRequestElementSet('points')) && (postRequestElement('points') <= $content['max_transferable']));
- // Test reason for transfer
- $valid_reason = (!empty($_POST['reason']));
+ // Test reason for transfer
+ $valid_reason = (isPostRequestElementSet('reason'));
- // Test if a recipient is selected
- $valid_recipient = ($_POST['to_uid'] > 0);
+ // Test if a recipient is selected
+ $valid_recipient = (postRequestElement('to_userid') > 0);
- // 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, sex, surname, family, email".$ADD." FROM "._MYSQL_PREFIX."_user_data WHERE userid IN ('%s', '%s') AND status='CONFIRMED' ORDER BY userid LIMIT 2",
- array($GLOBALS['userid'], bigintval($_POST['to_uid'])), __FILE__, __LINE__);
- $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, $sex1, $sname1, $fname1, $email1, $nick1) = SQL_FETCHROW($result);
- list($uid2, $sex2, $sname2, $fname2, $email2, $nick2) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
- if ($uid1 == $GLOBALS['userid'])
- {
- // Data row 1 is sender's data
- define('__SENDER_SEX' , TRANSLATE_SEX($sex1));
- 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_SEX' , TRANSLATE_SEX($sex2));
- define('__RECIPIENT_NICK' , $nick2);
- define('__RECIPIENT_SNAME', $sname2);
- define('__RECIPIENT_FNAME', $fname2);
- define('__RECIPIENT_EMAIL', $email2);
+ // 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 = $nick1;
- $TEST_NICK_REC = $nick2;
+ $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');
}
- else
- {
- // Data row 2 is sender's data
- define('__SENDER_SEX' , TRANSLATE_SEX($sex2));
- 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_SEX' , TRANSLATE_SEX($sex1));
- define('__RECIPIENT_NICK' , $nick1);
- define('__RECIPIENT_SNAME', $sname1);
- define('__RECIPIENT_FNAME', $fname1);
- define('__RECIPIENT_EMAIL', $email1);
- // Prepare variables for testing
- $TEST_NICK_SENDER = $nick2;
- $TEST_NICK_REC = $nick1;
+ // 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__);
}
- // Sender's UID is always currently stored in cookie userid...
- define('__SENDER_UID' , $GLOBALS['userid']);
- define('__RECIPIENT_UID' , $_POST['to_uid']);
-
- $SENDER = __SENDER_UID;
- $RECIPIENT = __RECIPIENT_UID;
- if ($nick)
- {
- if (($TEST_NICK_SENDER != __SENDER_UID) && (!empty($TEST_NICK_SENDER)))
- {
- $SENDER = __SENDER_NICK;
- }
- if (($TEST_NICK_REC != __RECIPIENT_UID) && (!empty($TEST_NICK_REC)))
- {
- $RECIPIENT = __RECIPIENT_NICK;
+
+ if (SQL_NUMROWS($result) > 0) {
+ // Load list
+ $OUT = "