Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / libs / register_functions.php
index 7cf34d913ea4497fa3562807eca489b23ace236a..d4db9cc067579c853e3c018a0cdc4180fcffd490 100644 (file)
@@ -18,6 +18,7 @@
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -47,8 +48,10 @@ function ifRequiredRegisterFieldsAreSet (&$array) {
        $ret = true;
        foreach ($array as $key => $value) {
                // Check all fields that must register
-               $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_must_register` WHERE `field_name`='".$key."' AND `field_required`='Y' LIMIT 1",
-                       __FUNCTION__, __LINE__);
+               $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_must_register` WHERE `field_name`='%s' AND `field_required`='Y' LIMIT 1",
+                       array($key), __FUNCTION__, __LINE__);
+
+               // Entry found?
                if (SQL_NUMROWS($result) == 1) {
                        // Check if extension country is not found (you have to enter the 2-chars long country code) or
                        // if extensions is present check if country code was selected
@@ -222,12 +225,19 @@ function isRegistrationDataComplete () {
        } // END - if
 
        // Do this check only when no admin is logged in
-       foreach (postRequestParameter('cat') as $id => $answer) {
-               if ($answer == 'Y') $GLOBALS['register_selected_cats']++;
-       } // END - foreach
+       if (is_array(postRequestParameter('cat'))) {
+               // Only continue with array
+               foreach (postRequestParameter('cat') as $id => $answer) {
+                       // Is this category choosen?
+                       if ($answer == 'Y') {
+                               $GLOBALS['register_selected_cats']++;
+                       } // END - if
+               } // END - foreach
+       } // END - if
 
        // Enougth categories selected?
-       $isOkay = (($isOkay) && ($GLOBALS['register_selected_cats'] < getConfig('least_cats')));
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isOkay='.intval($isOkay).',selected='.$GLOBALS['register_selected_cats'].'/'.getConfig('least_cats'));
+       $isOkay = (($isOkay) && ($GLOBALS['register_selected_cats'] >= getConfig('least_cats')));
 
        if ((postRequestParameter('email') != '!') && (getConfig('check_double_email') == 'Y')) {
                // Does the email address already exists in our database?
@@ -238,13 +248,16 @@ function isRegistrationDataComplete () {
        } // END - if
 
        // Check for IP timeout?
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isOkay='.intval($isOkay));
        if ((!isAdmin()) && (getConfig('ip_timeout') > 0)) {
                // Check his IP number
-               $GLOBALS['registration_ip_timeout'] = (countSumTotalData(detectRemoteAddr()  , 'user_data', 'userid', 'REMOTE_ADDR', true, " AND (`joined` > (UNIX_TIMESTAMP() - {?ip_timeout?}) OR `last_update` > (UNIX_TIMESTAMP() - {?ip_timeout?}))") == 1);
-               $isOkay = false;
+               $GLOBALS['registration_ip_timeout'] = (countSumTotalData(detectRemoteAddr()  , 'user_data', 'userid', 'REMOTE_ADDR', true, " AND ((UNIX_TIMESTAMP() - `joined`) < {?ip_timeout?} OR (UNIX_TIMESTAMP() - `last_update`) < {?ip_timeout?}) LIMIT 1") == 1);
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isOkay='.intval($isOkay).',timeout='.intval($GLOBALS['registration_ip_timeout']));
+               $isOkay = (($isOkay) && (!$GLOBALS['registration_ip_timeout']));
        } // END - if
 
        // Return result
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isOkay='.intval($isOkay));
        return $isOkay;
 }
 
@@ -370,7 +383,7 @@ VALUES ('%s','%s','%s','%s','%s',%s,'%s','%s',%s, %s,%s,'%s',%s, %s,'%s','UNCONF
        // @TODO Wether the registration bonus should only be added to user directly or through referal system should be configurable
        $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`=0 LIMIT 1",
                array($userid), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == '0') {
+       if (SQL_HASZERONUMS($result)) {
                // Add only when the line was not found (maybe some more secure?)
                $locked = 'points';