]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/register_functions.php
Renamed function, used more "pool functions":
[mailer.git] / inc / libs / register_functions.php
index 0b8f952157f535e8a1e5fea182c7d0e0a05a1aab..2d6c8e719eb6647449807a168632aa4dad4910ca 100644 (file)
@@ -187,19 +187,19 @@ function isRegistrationDataComplete () {
        setPostRequestArray($postArray);
 
        // Are both passwords zero length?
-       if ((strlen(postRequestElement('pass1')) == 0) && (strlen(postRequestElement('pass2')) == 0) && ($isOkay === TRUE)) {
+       if ((strlen(postRequestElement('password1')) == 0) && (strlen(postRequestElement('password2')) == 0) && ($isOkay === TRUE)) {
                // Is the extension 'register' newer or equal 0.5.5?
                if ((isExtensionInstalledAndNewer('register', '0.5.5')) && (isRegisterGeneratePasswordEmptyEnabled())) {
                        // Generate a random password
                        $randomPassword = generatePassword();
 
                        // Set it in both entries
-                       setPostRequestElement('pass1', $randomPassword);
-                       setPostRequestElement('pass2', $randomPassword);
+                       setPostRequestElement('password1', $randomPassword);
+                       setPostRequestElement('password2', $randomPassword);
                } else {
                        // Not allowed or no recent extension version
-                       setPostRequestElement('pass1', '!');
-                       setPostRequestElement('pass2', '!');
+                       setPostRequestElement('password1', '!');
+                       setPostRequestElement('password2', '!');
 
                        // ... which is both not okay
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Random password generation not possible, isExtensionInstalledAndNewer(register, 0.5.5)=' . intval(isExtensionInstalledAndNewer('register', '0.5.5')) . ',isRegisterGeneratePasswordEmptyEnabled()=' . intval(isRegisterGeneratePasswordEmptyEnabled()));
@@ -208,35 +208,35 @@ function isRegistrationDataComplete () {
        } // END - if
 
        // Did he enter his password twice?
-       if (((!isPostRequestElementSet('pass1')) || (!isPostRequestElementSet('pass2'))) || ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2')))) {
-               if ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2'))) {
+       if (((!isPostRequestElementSet('password1')) || (!isPostRequestElementSet('password2'))) || ((postRequestElement('password1') != postRequestElement('password2')) && (isPostRequestElementSet('password1')) && (isPostRequestElementSet('password2')))) {
+               if ((postRequestElement('password1') != postRequestElement('password2')) && (isPostRequestElementSet('password1')) && (isPostRequestElementSet('password2'))) {
                        // Both passwords did not match
-                       setPostRequestElement('pass1', '!');
-                       setPostRequestElement('pass2', '!');
+                       setPostRequestElement('password1', '!');
+                       setPostRequestElement('password2', '!');
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'User did not enter same passwords.');
                } else {
-                       if (!isPostRequestElementSet('pass1')) {
+                       if (!isPostRequestElementSet('password1')) {
                                // Password 1 is empty
-                               setPostRequestElement('pass1', '!');
-                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'User did not enter pass1.');
+                               setPostRequestElement('password1', '!');
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'User did not enter password1.');
                        } else {
                                // Password 2 is empty
-                               setPostRequestElement('pass1', '');
+                               setPostRequestElement('password1', '');
                        }
-                       if (!isPostRequestElementSet('pass2')) {
+                       if (!isPostRequestElementSet('password2')) {
                                // Password 2 is empty
-                               setPostRequestElement('pass2', '!');
-                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'User did not enter pass2.');
+                               setPostRequestElement('password2', '!');
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'User did not enter password2.');
                        } else {
                                // Password 1 is empty
-                               setPostRequestElement('pass2', '');
+                               setPostRequestElement('password2', '');
                        }
                }
                $isOkay = FALSE;
        } // END - if
 
        // Is the password long enouth?
-       if ((strlen(postRequestElement('pass1')) < getPassLen()) && ($isOkay === TRUE)) {
+       if ((strlen(postRequestElement('password1')) < getPassLen()) && ($isOkay === TRUE)) {
                $GLOBALS['registration_short_password'] = TRUE;
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'User did enter a short password.');
                $isOkay = FALSE;
@@ -257,13 +257,12 @@ function isRegistrationDataComplete () {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isOkay=' . intval($isOkay) . ',selected=' . $GLOBALS['registration_selected_cats'] . '/' . getLeastCats());
        $isOkay = (($isOkay) && ($GLOBALS['registration_selected_cats'] >= getLeastCats()));
 
-       if ((postRequestElement('email') != '!') && (isCheckDoubleEmailEnabled())) {
-               // Does the email address already exists in our database?
-               if ((isEmailTaken(postRequestElement('email'))) && (!isAdmin())) {
-                       setPostRequestElement('email', '?');
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'User did enter a already used email address.');
-                       $isOkay = FALSE;
-               } // END - if
+       // Check if email is taken, if configured
+       if ((isExtensionInstalledAndNewer('other', '0.3.0')) && (isCheckDoubleEmailEnabled()) && (postRequestElement('email') != '!') && (isEmailTaken(postRequestElement('email'))) && (!isAdmin())) {
+               // Is already used
+               setPostRequestElement('email', '?');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'User did enter a already used email address.');
+               $isOkay = FALSE;
        } // END - if
 
        // Check for IP timeout?
@@ -291,7 +290,8 @@ function doUserRegistration () {
        // Init filter data
        $filterData = array(
                // Initialization not done by default
-               'init_done' => FALSE
+               'init_done' => FALSE,
+               'post_data' => postRequestArray(),
        );
 
        // Init extra SQL data
@@ -372,7 +372,7 @@ function doUserRegistration () {
                bigintval(postRequestElement('day')),
                bigintval(postRequestElement('month')),
                bigintval(postRequestElement('year')),
-               generateHash(postRequestElement('pass1')),
+               generateHash(postRequestElement('password1')),
                bigintval(postRequestElement('max_mails')),
                bigintval(postRequestElement('max_mails')),
                convertZeroToNull(postRequestElement('refid')),
@@ -381,10 +381,10 @@ function doUserRegistration () {
        ), __FUNCTION__, __LINE__);
 
        // Get his userid
-       $filterData['register_insert_id'] = bigintval(SQL_INSERTID());
+       $filterData['register_insert_id'] = SQL_INSERT_ID();
 
        // Did this work?
-       if (!isValidUserId($filterData['register_insert_id'])) {
+       if (!isValidId($filterData['register_insert_id'])) {
                // Something bad happened!
                displayMessage('{--USER_NOT_REGISTERED--}');
 
@@ -406,9 +406,9 @@ function doUserRegistration () {
        addPointsThroughReferralSystem(
                // Subject
                'register_welcome',
-               // New user's id
+               // User's id number
                $filterData['register_insert_id'],
-               // Points
+               // Points to add
                getPointsRegister(),
                // Referral id (or NULL if none set)
                convertZeroToNull(postRequestElement('refid'))
@@ -416,18 +416,20 @@ function doUserRegistration () {
 
        // Write catgories
        if (ifPostContainsSelections('cat')) {
+               // Init SQL
+               $sql = 'INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`, `cat_id`) VALUES';
+
                // Write all entries
                foreach (postRequestElement('cat') as $categoryId => $joined) {
                        // "Join" this group?
                        if ($joined == 'Y') {
                                // Insert category entry
-                               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`, `cat_id`) VALUES (%s, %s)",
-                                       array(
-                                               $filterData['register_insert_id'],
-                                               bigintval($categoryId)
-                                       ), __FUNCTION__, __LINE__);
+                               $sql .= ' (' . $filterData['register_insert_id'] . ', ' . bigintval($categoryId) . '),';
                        } // END - if
                } // END - foreach
+
+               // Run SQL without last commata
+               SQL_QUERY(substr($sql, 0, -1), __FUNCTION__, __LINE__);
        } // END - if
 
        // Registration phase is done here, so for tester accounts we end here
@@ -437,14 +439,13 @@ function doUserRegistration () {
        } // END - if
 
        // ... rewrite a zero referral id to the main title
-       if (!isValidUserId(postRequestElement('refid'))) {
+       if (!isValidId(postRequestElement('refid'))) {
                setPostRequestElement('refid', getMainTitle());
        } // END - if
 
        // Is ZIP code set?
        if (isPostRequestElementSet('zip')) {
                // Prepare data array for the email template
-               // Start with the gender...
                $content = array(
                        'hash'     => $GLOBALS['register_confirm_hash'],
                        'userid'   => $filterData['register_insert_id'],
@@ -457,7 +458,7 @@ function doUserRegistration () {
                        'zip'      => bigintval(postRequestElement('zip')),
                        'country'  => $GLOBALS['register_country_data'],
                        'refid'    => SQL_ESCAPE(postRequestElement('refid')),
-                       'password' => SQL_ESCAPE(postRequestElement('pass1')),
+                       'password' => SQL_ESCAPE(postRequestElement('password1')),
                );
        } else {
                // No ZIP code entered
@@ -473,7 +474,7 @@ function doUserRegistration () {
                        'zip'      => '',
                        'country'  => $GLOBALS['register_country_data'],
                        'refid'    => SQL_ESCAPE(postRequestElement('refid')),
-                       'password' => SQL_ESCAPE(postRequestElement('pass1')),
+                       'password' => SQL_ESCAPE(postRequestElement('password1')),
                );
        }
 
@@ -535,7 +536,7 @@ function getDisplayRefid () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// Checks whether 'display_refid' is "YES"
+// Checks whether 'display_refid' is "Y"
 function isDisplayRefidEnabled () {
        // Is the cache entry set?
        if (!isset($GLOBALS[__FUNCTION__])) {
@@ -607,6 +608,18 @@ function isRegisterGeneratePasswordEmptyEnabled () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// "Getter" for least_cats
+function getLeastCats () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('least_cats');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // ----------------------------------------------------------------------------
 //                            Template helper functions
 // ----------------------------------------------------------------------------