X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Fuser_functions.php;h=c405600bdccd6e302640225d407d07677592e8a1;hb=e4bb9dcc763483e7cc6a11d57cad79cf2425cc6d;hp=b4fefbb35d5de0499468da2f06fac8c2b8f7652f;hpb=e46fa203829954370ce793156c78ce5c4600d020;p=mailer.git diff --git a/inc/libs/user_functions.php b/inc/libs/user_functions.php index b4fefbb35d..c405600bdc 100644 --- a/inc/libs/user_functions.php +++ b/inc/libs/user_functions.php @@ -14,11 +14,9 @@ * $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 - 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 * @@ -125,7 +123,7 @@ function addSortLinks ($letter, $sortby, $colspan, $return=false) { } // END - foreach // Add list and colspan - $content['list'] = substr($OUT, 0, -13); + $content['list'] = substr($OUT, 0, -1); $content['colspan2'] = $colspan; // Load template @@ -200,7 +198,7 @@ function addPageNavigation ($numPages, $offset, $showForm, $colspan, $return=fal } // Create email link to user's account -function generateUserEmailLink($email, $mod = 'admin') { +function generateUserEmailLink ($email, $mod = 'admin') { // Show contact link only if user is confirmed by default $locked = " AND `status`='CONFIRMED'"; @@ -234,7 +232,7 @@ LIMIT 1", // @TODO Double-check configuration entry here function determineRandomReferalId () { // Default is zero refid - $refid = '0'; + $refid = null; // Is the extension version fine? if (isExtensionInstalledAndNewer('user', '0.3.4')) { @@ -255,8 +253,8 @@ function determineRandomReferalId () { // Use that userid as new referal id list($refid) = SQL_FETCHROW($result); - // Reset this user's counter - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=0 WHERE `userid`=%s LIMIT 1", + // Reset all users, this makes this random referal id more challenging + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=0", array($refid), __FUNCTION__, __LINE__); } // END - if @@ -341,7 +339,9 @@ function doUserLogin ($userid, $passwd, $successUrl = '', $errorUrl = 'modules.p $GLOBALS['bonus_payed'] = true; // Subtract login bonus from userid's account or jackpot - if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getConfig('bonus_mode') != 'ADD')) handleBonusPoints('login_bonus'); + if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getBonusMode() != 'ADD')) { + handleBonusPoints('login_bonus'); + } // END - if } // END - if // @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON)); @@ -355,7 +355,7 @@ function doUserLogin ($userid, $passwd, $successUrl = '', $errorUrl = 'modules.p // Update database records SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `total_logins`=`total_logins`+1" . $add . " WHERE `userid`=%s LIMIT 1", array($userid), __FUNCTION__, __LINE__); - if (SQL_AFFECTEDROWS() == 1) { + if (!SQL_HASZEROAFFECTED()) { // Is a success URL set? if (empty($successUrl)) { // Procedure to checking for login data @@ -393,7 +393,7 @@ function doUserLogin ($userid, $passwd, $successUrl = '', $errorUrl = 'modules.p // Set userid in session setSession('current_userid', getUserData('userid')); } elseif (!isUserDataValid()) { - // User id not found! + // User id not found $errorCode = getCode('WRONG_ID'); } else { // Unknown error @@ -467,7 +467,7 @@ function doNewUserPassword ($email, $userid) { } } else { // id or email is wrong - loadTemplate('admin_settings_saved', false, '{--GUEST_WRONG_ID_EMAIL--}'); + loadTemplate('admin_settings_saved', false, '{--GUEST_WRONG_ID_EMAIL--}'); } // Return the error code @@ -542,6 +542,170 @@ function insertUserStatsRecord ($userid, $statsType, $statsData) { } } +// Confirms a user account +function doConfirmUserAccount ($hash) { + // Init content + $content = array( + 'message' => '{--GUEST_CONFIRMED_FAILED--}', + 'userid' => 0, + ); + + // Initialize the user id + $userid = '0'; + + // Search for an unconfirmed or confirmed account + $result = SQL_QUERY_ESC("SELECT `userid`, `email`, `refid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `user_hash`='%s' AND (`status`='UNCONFIRMED' OR `status`='CONFIRMED') LIMIT 1", + array($hash), __FILE__, __LINE__); + if (SQL_NUMROWS($result) == 1) { + // Ok, he want's to confirm now so we load some data + list($userid, $email, $refid) = SQL_FETCHROW($result); + + // Fetch user data + if (!fetchUserData($userid)) { + // Not found, should not happen + debug_report_bug(__FILE__, __LINE__, 'User account ' . $userid . ' not found.'); + } // END - if + + // Load all data and add points + $content = getUserDataArray(); + + // Unlock his account (but only when it is on UNCONFIRMED!) + SQL_QUERY_ESC("UPDATE + `{?_MYSQL_PREFIX?}_user_data` +SET + `status`='CONFIRMED', + `ref_payout`={?ref_payout?}, + `user_hash`=NULL +WHERE + `user_hash`='%s' AND + `status`='UNCONFIRMED' +LIMIT 1", + array($hash), __FILE__, __LINE__); + + // Was it updated? + if (!SQL_HASZEROAFFECTED()) { + // Send email if updated + $message = loadEmailTemplate('confirm-member', $content, bigintval($userid)); + + // And send him right away the confirmation mail + sendEmail($email, '{--GUEST_THANX_CONFIRM--}', $message); + + // Maybe he got "referaled"? + if (($refid > 0) && ($refid != $userid)) { + // Select the referal userid + if (fetchUserData($refid)) { + // Update ref counter... + updateReferalCounter($refid); + + // If version matches add ref bonus to refid's account + if ((isExtensionInstalledAndNewer('bonus', '0.4.4')) && (isBonusRallyeActive())) { + // Add points (directly only!) + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_ref`=`bonus_ref`+{?bonus_ref?} WHERE `userid`=%s LIMIT 1", + array(bigintval($refid)), __FILE__, __LINE__); + + // Subtract points from system + handleBonusPoints(getConfig('bonus_ref')); + } // END - if + + // Add one-time referal bonus over referal system or directly + // @TODO Try to rewrite the following unset() + unset($GLOBALS['ref_level']); + addPointsThroughReferalSystem('referal_bonus', $refid, getPointsRef(), true, bigintval($userid), getConfig('reg_points_mode')); + } // END - if + } // END - if + + if (isExtensionActive('rallye')) { + // Add user to rallye (or not?) + addUserToReferalRallye(bigintval($userid)); + } // END - if + + // Account confirmed! + if (isExtensionActive('lead')) { + // Set special lead cookie + setSession('lead_userid', bigintval($userid)); + + // Lead-Code mode enabled + redirectToUrl('lead-confirm.php'); + } else { + $content['message'] = '{--GUEST_CONFIRMED_DONE--}'; + $content['userid'] = bigintval($userid); + } + } elseif (isExtensionActive('lead')) { + // Set special lead cookie + setSession('lead_userid', bigintval($userid)); + + // Lead-Code mode enabled + redirectToUrl('lead-confirm.php'); + } else { + // Nobody was found unter this hash key... or our new member want's to confirm twice? + $content['message'] = '{--GUEST_CONFIRMED_TWICE--}'; + } + } else { + // Nobody was found unter this hash key... or our new member want's to confirm twice? + $content['message'] = '{--GUEST_CONFIRMED_TWICE--}'; + } + + // Load template + loadTemplate('admin_settings_saved', false, $content['message']); +} + +// Does resend the user's confirmation link for given email address +function doResendUserConfirmationLink ($email) { + // Email address not registered is default message + $message = '{--EMAIL_404--}'; + + // Confirmation link requested + if (fetchUserData($email, 'email')) { + // Email address found + $content = getUserDataArray(); + + // Is the account unconfirmed? + if ($content['status'] == 'UNCONFIRMED') { + // Load email template + $message = loadEmailTemplate('guest_request_confirm', array('hash' => $content['user_hash']), $content['userid']); + + // Send email + sendEmail($email, '{--GUEST_REQUEST_CONFIRM_LINK_SUBJECT--}', $message); + } // END - if + + // Create message based on the status + $message = getConfirmationMessageFromUserStatus($content['status']); + } // END - if + + // Output message + loadTemplate('admin_settings_saved', false, $message); +} + +// Get a message (somewhat translation) from user status for confirmation link. +// This is different to translateUserStatus() in text messages. +function getConfirmationMessageFromUserStatus ($status) { + // Default is 'UNKNOWN' + $message = getMaskedMessage('GUEST_LOGIN_ID_UNKNOWN_STATUS', $status); + + // Which status is it? + switch ($status) { + case 'UNCONFIRMED': // Account is unconfirmed + // And set message + $message = '{--GUEST_CONFIRM_LINK_SENT--}'; + break; + + case 'CONFIRMED': // Account already confirmed + $message = '{--GUEST_LOGIN_ID_CONFIRMED--}'; + break; + + case 'LOCKED': // Account is locked + $message = '{--GUEST_LOGIN_ID_LOCKED--}'; + break; + + default: // This should not happen + debug_report_bug(__FUNCTION__, __LINE__, 'Unknown user status ' . $status . ' detected.'); + break; + } // END - switch + + // Return message + return $message; +} + // Expression call-back function for fetching user data function doExpressionUser ($data) { // Use current userid by default