More HTML rewrites
[mailer.git] / doubler.php
index 1f854569042b9ec3dadb39a7ae9e6276cdacbf6c..590af15e0ad424177d56fd9a18f28d88acab023c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 02/13/2005 *
- * ===============                              Last change: 02/13/2005 *
+ * Mailer v0.2.1-FINAL                                Start: 02/13/2005 *
+ * ===================                          Last change: 02/13/2005 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : doubler.php                                      *
@@ -44,7 +44,7 @@ $GLOBALS['startTime'] = microtime(true);
 
 // Set module
 $GLOBALS['module'] = 'doubler';
-$GLOBALS['output_mode'] = 0;
+$GLOBALS['output_mode'] = '0';
 
 // Load the required file(s)
 require('inc/config-global.php');
@@ -55,40 +55,6 @@ setContentType('text/html');
 // Is the 'doubler' extension active?
 redirectOnUninstalledExtension('doubler');
 
-// Probe for referal id
-if (isGetRequestElementSet('refid')) $GLOBALS['refid'] = getRequestElement('refid');
-
-// Only check this if refid is provided!
-if (determineReferalId() > 0) {
-       // Do we have nickname or userid set?
-       if (isNicknameUsed(determineReferalId())) {
-               // Nickname in URL, so load the id
-               $result = SQL_QUERY_ESC("SELECT `userid`, `status` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `nickname`='%s' LIMIT 1",
-                       array(determineReferalId()), __FILE__, __LINE__);
-       } else {
-               // Direct userid entered
-               $result = SQL_QUERY_ESC("SELECT `userid`, `status` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
-                       array(determineReferalId()), __FILE__, __LINE__);
-       }
-
-       // Load data
-       list($rid, $status_ref) = SQL_FETCHROW($result);
-       $GLOBALS['refid'] = bigintval($rid);
-
-       // Free memory
-       SQL_FREERESULT($result);
-} // END - if
-
-// Init userid
-$userid = 0;
-
-// If no account was found set default refid and status to CONFIRMED
-if (empty($GLOBALS['refid'])) {
-       // Determine referal id again
-       $GLOBALS['refid'] = determineReferalId();
-       $status = 'CONFIRMED';
-} // END - if
-
 // Init content array
 $content = array(
        'message' => '',
@@ -104,20 +70,17 @@ if (isFormSent()) {
                // Probe for nickname extension and if a nickname was entered
                if (isNickNameUsed(postRequestElement('userid'))) {
                        // Nickname in URL, so load the id
-                       $result = SQL_QUERY_ESC("SELECT `userid`, `status`, `password` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `nickname`='%s' LIMIT 1",
-                               array(postRequestElement('userid')), __FILE__, __LINE__);
+                       fetchUserData(postRequestElement('userid'), 'nickname');
                } else {
                        // Direct userid entered
-                       $result = SQL_QUERY_ESC("SELECT `userid`, `status, `password` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
-                               array(bigintval(postRequestElement('userid'))), __FILE__, __LINE__);
+                       fetchUserData(postRequestElement('userid'));
                }
 
-               // Load data
-               list($userid, $status, $password) = SQL_FETCHROW($result);
-               $userid = bigintval($userid);
-
-               // Free result
-               SQL_FREERESULT($result);
+               // Is the data valid?
+               if (!isUserDataValid()) {
+                       // Output message that the userid is not okay
+                       loadTemplate('admin_settings_saved', false, getMessage('DOUBLER_USERID_INVALID'));
+               } // END - if
 
                // Remove any dots and unwanted chars from the points
                setRequestPostElement('points', bigintval(round(convertCommaToDot(postRequestElement('points')))));
@@ -126,22 +89,22 @@ if (isFormSent()) {
                $probe_points = ((postRequestElement('points') >= getConfig('doubler_min')) && (postRequestElement('points') <= getConfig('doubler_max')));
 
                // Check all together
-               if ((!empty($userid)) && ($password == generateHash(postRequestElement('pass'), substr($password, 0, -40))) && ($status == 'CONFIRMED') && ($probe_points)) {
+               if ((isUserDataValid()) && (getUserData('password') == generateHash(postRequestElement('pass'), substr(getUserData('password'), 0, -40))) && (getUserData('status') == 'CONFIRMED') && ($probe_points)) {
                        // Nickname resolved to a unique userid or direct userid entered by the member
-                       $GLOBALS['doubler_userid'] = $userid;
+                       $GLOBALS['doubler_userid'] = getUserData('userid');
 
                        // Calulcate points
-                       $points = countSumTotalData($userid, 'user_points', 'points') - countSumTotalData($userid, 'user_data', 'used_points');
+                       $points = countSumTotalData(getUserData('userid'), 'user_points', 'points') - countSumTotalData(getUserData('userid'), 'user_data', 'used_points');
 
                        // So let's continue with probing his points amount
                        if (($points - getConfig('doubler_left') - postRequestElement('points') * getConfig('doubler_charge')) >= 0) {
                                // Enough points are left so let's continue with the doubling process
                                // Create doubling "account" width *DOUBLED* points
                                SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES ('%s','%s','%s','".detectRemoteAddr()."', UNIX_TIMESTAMP(), 'N','N')",
-                                       array($userid, determineReferalId(), bigintval(postRequestElement('points') * 2)), __FILE__, __LINE__);
+                                       array(getUserData('userid'), determineReferalId(), bigintval(postRequestElement('points') * 2)), __FILE__, __LINE__);
 
                                // Subtract entered points
-                               subtractPoints('doubler', $userid, postRequestElement('points'));
+                               subtractPoints('doubler', getUserData('userid'), postRequestElement('points'));
 
                                // Add points to "total payed" including charge
                                $points = postRequestElement('points') - postRequestElement('points') * getConfig('doubler_charge');
@@ -149,7 +112,7 @@ if (isFormSent()) {
                                incrementConfigEntry('doubler_points', $points);
 
                                // Add second line for the referal but only when userid != refid
-                               if ((determineReferalId() > 0) && (determineReferalId() != $userid)) {
+                               if ((determineReferalId() > 0) && (determineReferalId() != getUserData('userid'))) {
                                        // Okay add a refid line and apply refid percents
                                        SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES ('%s',0,'%s','".detectRemoteAddr()."',UNIX_TIMESTAMP(),'N','Y')",
                                                array(
@@ -169,13 +132,13 @@ if (isFormSent()) {
                                // Not enougth points left
                                $content['message'] = getMessage('DOUBLER_FORM_NO_POINTS_LEFT');
                        }
-               } elseif ($status == 'CONFIRMED') {
+               } elseif (getUserData('status') == 'CONFIRMED') {
                        // Account is unconfirmed!
                        $content['message'] = getMessage('DOUBLER_FORM_WRONG_PASS');
-               } elseif ($status == 'UNCONFIRMED') {
+               } elseif (getUserData('status') == 'UNCONFIRMED') {
                        // Account is unconfirmed!
                        $content['message'] = getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED');
-               } elseif ($status == 'LOCKED') {
+               } elseif (getUserData('status') == 'LOCKED') {
                        // Account is locked by admin / holiday!
                        $content['message'] = getMessage('DOUBLER_FORM_STATUS_LOCKED');
                } elseif (postRequestElement('points') < getConfig('doubler_min')) {
@@ -201,7 +164,7 @@ if (isFormSent()) {
                // points not entered
                $content['message'] = getMessage('DOUBLER_FORM_404_POINTS');
        }
-}
+} // END - if (isFormSet())
 
 // Shall I check for points immediately?
 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/mails/doubler_mails.php');
@@ -216,9 +179,9 @@ $content['banner'] = loadTemplate('doubler_banner', true);
 $content['header'] = loadTemplate('doubler_header', true);
 $content['footer'] = loadTemplate('doubler_footer', true);
 
-if (!empty($userid)) {
+if (isUserDataValid()) {
        // Transfer userid/nickname to constant
-       $content['refid'] = $userid;
+       $content['refid'] = getUserData('userid');
 } else {
        // Transfer userid/nickname to constant
        $content['refid'] = determineReferalId();