+ // Is the data valid?
+ if (!isValidUserData()) {
+ // Output message that the userid is not okay
+ displayMessage('{--DOUBLER_USERID_INVALID--}');
+ } // END - if
+
+ // Remove any dots and unwanted chars from the points
+ setPostRequestElement('points', bigintval(round(convertCommaToDot(postRequestElement('points')))));
+
+ // Probe for enough points
+ $probe_points = ((postRequestElement('points') >= getDoublerMin()) && (postRequestElement('points') <= getDoublerMax()));
+
+ // Check all together
+ if ((isValidUserData()) && (getUserData('password') == generateHash(postRequestElement('password'), substr(getUserData('password'), 0, -40))) && (getUserData('status') == 'CONFIRMED') && ($probe_points)) {
+ // Nickname resolved to a unique userid or direct userid entered by the member
+ $GLOBALS['local_doubler_userid'] = getUserData('userid');
+
+ // Calulcate points
+ $points = getTotalPoints(getUserData('userid'));
+
+ // So let's continue with probing his points amount
+ if (($points - getConfig('doubler_left') - postRequestElement('points') * getDoublerCharge() / 100) >= 0) {
+ // Enough points are left so let's continue with the doubling process
+ // Create doubling "account" with *DOUBLED* points
+ sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES (%s,%s,%s,'%s', UNIX_TIMESTAMP(), 'N','N')",
+ array(
+ getUserData('userid'),
+ convertZeroToNull(determineReferralId()),
+ bigintval(postRequestElement('points') * 2),
+ determineRealRemoteAddress()
+ ), __FILE__, __LINE__);
+
+ // Subtract entered points and ignore return status
+ subtractPoints('doubler', getUserData('userid'), postRequestElement('points'));
+
+ // Add points to "total payed" including charge
+ $points = postRequestElement('points') - postRequestElement('points') * getDoublerCharge() / 100;
+ updateConfiguration('doubler_points', $points, '+');
+ incrementConfigEntry('doubler_points', $points);
+
+ // Add second line for the referral but only when userid != refid
+ if ((isValidId(determineReferralId())) && (determineReferralId() != getUserData('userid'))) {
+ // Okay add a refid line and apply refid percents
+ sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES (%s,0,%s,'%s',UNIX_TIMESTAMP(),'N','Y')",
+ array(
+ convertZeroToNull(determineReferralId()),
+ (postRequestElement('points') * 2 * getDoublerRef() / 100),
+ determineRealRemoteAddress()
+ ), __FILE__, __LINE__);
+
+ // And that's why we don't want to you more than one referral level of doubler-points. ^^^
+ } // END - if
+
+ // Update usage counter
+ updateConfiguration('doubler_counter', 1, '+');
+
+ // Set constant
+ $content['message'] = loadTemplate('doubler_reflink', TRUE, postRequestElement('userid'));
+ } else {
+ // Not enougth points left
+ $content['message'] = '{--DOUBLER_FORM_NO_POINTS_LEFT--}';