Lock reason now saved in DB, deleted accounts shall be locked for re-registering...
[mailer.git] / inc / modules / guest / what-register.php
index 9b5d88cd0450f0523cd4f9628d789b9cd9692a9c..c38e2e5bb5676d069c12a2f56a91a9c81e320308 100644 (file)
@@ -32,7 +32,7 @@
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
+if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 } elseif ((!EXT_IS_ACTIVE("register"))) {
@@ -45,7 +45,7 @@ if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
 }
 
 // Add description as navigation point
-ADD_DESCR("guest", basename(__FILE__));
+ADD_DESCR("guest", __FILE__);
 
 global $_CONFIG, $DATA;
 
@@ -68,33 +68,47 @@ if (empty($_POST['city']))         $_POST['city']         = "";
 if (empty($_POST['cntry']))        $_POST['cntry']        = "";
 if (empty($_POST['country_code'])) $_POST['country_code'] = "1";
 
-if (isset($_POST['ok']))
-{
+// Default refid is zero
+$_POST['refid'] = 0;
+if ($GLOBALS['refid'] > 0) {
+       // Test if the refid is valid
+       $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
+               array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
+
+       // Userid found?
+       //* DEBUG: */ die("refid={$GLOBALS['refid']}/numRows=".SQL_NUMROWS($result)."");
+       if (SQL_NUMROWS($result) == 0) {
+               // Not found so we set your refid!
+               $_POST['refid'] = $_CONFIG['def_refid'];
+               set_session('refid', $_CONFIG['def_refid']);
+       } else {
+               // Use the refid here
+               $_POST['refid'] = $GLOBALS['refid'];
+       }
+} // END - if
+
+if (isset($_POST['ok'])) {
        // First we only check the submitted data then we continue... :)
        //
        // Did he agree to our Terms Of Usage?
-       if ($_POST['agree'] != "Y")
-       {
+       if ($_POST['agree'] != "Y") {
                $_POST['agree'] = "!";
                $FAILED = true;
        }
 
        // Did he enter a valid email address? (we really don't care about
        // that, he has to click on a confirmation link :P )
-       if ((empty($_POST['addy'])) || (!VALIDATE_EMAIL($_POST['addy'])))
-       {
+       if ((empty($_POST['addy'])) || (!VALIDATE_EMAIL($_POST['addy']))) {
                $_POST['addy'] = "!";
                $FAILED = true;
        }
 
        // And what about surname and family's name?
-       if (empty($_POST['surname']))
-       {
+       if (empty($_POST['surname'])) {
                $_POST['surname'] = "!";
                $FAILED = true;
        }
-       if (empty($_POST['family_name']))
-       {
+       if (empty($_POST['family_name'])) {
                $_POST['family_name'] = "!";
                $FAILED = true;
        }
@@ -145,9 +159,8 @@ if (isset($_POST['ok']))
        }
 
        // Check his IP number
-       $to = bigintval(time() - $_CONFIG['ip_timeout']);
-       $result = SQL_QUERY_ESC("SELECT joined, last_update FROM "._MYSQL_PREFIX."_user_data WHERE REMOTE_ADDR='%s' AND (joined > %s OR last_update > %s) LIMIT 1",
-        array(getenv('REMOTE_ADDR'), $to, $to), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT joined, last_update FROM "._MYSQL_PREFIX."_user_data WHERE REMOTE_ADDR='%s' AND (joined > (UNIX_TIMESTAMP() - %s) OR last_update > (UNIX_TIMESTAMP() - %s)) LIMIT 1",
+        array(GET_REMOTE_ADDR(), $_CONFIG['ip_timeout'], $_CONFIG['ip_timeout']), __FILE__, __LINE__);
        if ((SQL_NUMROWS($result) == 1) && (!IS_ADMIN()))
        {
                // Same IP in timeout range and different email address entered... Eat this, faker! ;-)
@@ -156,128 +169,124 @@ if (isset($_POST['ok']))
                $FAILED = true;
        }
 
-       // Test the refid (because some strange hackers... :-P)
-       $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
-        array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 0)
-       {
-               // Not found so we set your refid!
-               $_POST['refid'] = $_CONFIG['def_refid'];
-               set_session("refid", $_CONFIG['def_refid']);
-       }
-
        // Free memory
        SQL_FREERESULT($result);
 }
 
-if ((isset($_POST['ok'])) && (!$FAILED))
-{
-       // Save the registration
+if ((isset($_POST['ok'])) && (!$FAILED)) {
+       // Prepapre month and day of birth
        if (strlen($_POST['day'])   == 1) $_POST['day']   = "0".$_POST['day'];
        if (strlen($_POST['month']) == 1) $_POST['month'] = "0".$_POST['month'];
 
-       // Hash = MM-DD-YYYY:IP:USER_AGENT:TIMEMARK
-       $hash = generateHash($_POST['month']."-".$_POST['day']."-".$_POST['year'].":".getenv('SERVER_NAME').":".getenv('REMOTE_ADDR').":".getenv('HTTP_USER_AGENT').":".time());
+       // Get total ...
+       // ... confirmed, ...
+       $confirmedUsers   = GET_TOTAL_DATA("CONFIRMED", "user_data", "userid", "status", true);
+       // ... unconfirmed ...
+       $unconfirmedUsers = GET_TOTAL_DATA("UNCONFIRMED", "user_data", "userid", "status", true);
+       // ... and locked users!
+       $lockedUsers      = GET_TOTAL_DATA("LOCKED", "user_data", "userid", "status", true);
+
+       // Generate hash which will be inserted into confirmation mail
+       $hash = generateHash(sha1($confirmedUsers.":".$unconfirmedUsers.":".$lockedUsers.":".$_POST['month']."-".$_POST['day']."-".$_POST['year'].":".getenv('SERVER_NAME').":".GET_REMOTE_ADDR().":".GET_USER_AGENT()."/".SITE_KEY."/".DATE_KEY."/".RAND_NUMBER));
 
        // Add design when extension sql_patches is v0.2.7 or greater
        $ADD1 = ""; $ADD2 = "";
-       if (GET_EXT_VERSION("sql_patches") >= "0.2.7")
-       {
+       if (GET_EXT_VERSION("sql_patches") >= "0.2.7") {
                // Okay, add design here
                $ADD1 = ", curr_theme";
                $ADD2 = ", '".GET_CURR_THEME()."'";
-       }
+       } // END - if
 
        // Check if I shall disable sending mail to newly registered members out about active/begging rallye
        //
        // First comes first: begging rallye
-       if (GET_EXT_VERSION("beg") >= "0.1.7")
-       {
+       if (GET_EXT_VERSION("beg") >= "0.1.7") {
                // Okay, shall I disable now?
-               if ($_CONFIG['beg_new_mem_notify'] == "N")
-               {
+               if ($_CONFIG['beg_new_mem_notify'] == "N") {
                        $ADD1 .= ", beg_ral_notify, beg_ral_en_notify";
                        $ADD2 .= ", UNIX_TIMESTAMP(), UNIX_TIMESTAMP()";
-               }
-       }
+               } // END - if
+       } // END - if
 
        // Second: active rallye
-       if (GET_EXT_VERSION("bonus") >= "0.7.7")
-       {
+       if (GET_EXT_VERSION("bonus") >= "0.7.7") {
                // Okay, shall I disable now?
-               if ($_CONFIG['bonus_new_mem_notify'] == "N")
-               {
+               if ($_CONFIG['bonus_new_mem_notify'] == "N") {
                        $ADD1 .= ", bonus_ral_notify, bonus_ral_en_notify";
                        $ADD2 .= ", UNIX_TIMESTAMP(), UNIX_TIMESTAMP()";
-               }
-       }
+               } // END - if
+       } // END - if
 
        // Write user data to table
-       if (EXT_IS_ACTIVE("country"))
-       {
+       if (EXT_IS_ACTIVE("country")) {
                // Save with new selectable country code
                $countryRow = "country_code";
                $countryData = bigintval($_POST['country_code']);
-       }
-        else
-       {
+       } else {
                // Old way with enterable two-char-code
                $countryRow = "country";
-               $countryData = addslashes(substr($_POST['cntry'], 0, 2));
+               $countryData = substr($_POST['cntry'], 0, 2);
        }
 
        //////////////////////////////
        // Create user's account... //
        //////////////////////////////
        //
-       $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_data (sex, surname, family, street_nr, %s, zip, city, email, birth_day, birth_month, birth_year, password, max_mails, receive_mails, refid, status, user_hash, REMOTE_ADDR, joined, last_update".$ADD1.")
-VALUES ('%s', '%s', '%s', '%s', '%s', %s, '%s', '%s', %s, %s, %s, '%s', %s, %s, %s, 'UNCONFIRMED', '%s', '%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()".$ADD2.")",
-array(
-       $countryRow,
-       SQL_ESCAPE(substr($_POST['sex'], 0, 1)),
-       SQL_ESCAPE($_POST['surname']),
-       SQL_ESCAPE($_POST['family_name']),
-       SQL_ESCAPE($_POST['street_nr']),
-       $countryData,
-       bigintval($_POST['zip']),
-       SQL_ESCAPE($_POST['city']),
-       SQL_ESCAPE($_POST['addy']),
-       bigintval($_POST['day']),
-       bigintval($_POST['month']),
-       bigintval($_POST['year']),
-       generateHash($_POST['pass1']),
-       bigintval($_POST['max_mails']),
-       bigintval($_POST['max_mails']),
-       bigintval($_POST['refid']),
-       $hash,
-       getenv('REMOTE_ADDR'),
-), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_data (gender, surname, family, street_nr,%s, zip, city, email, birth_day, birth_month, birth_year, password, max_mails, receive_mails, refid, status, user_hash, REMOTE_ADDR, joined, last_update".$ADD1.")
+VALUES ('%s','%s','%s','%s','%s',%s,'%s','%s',%s, %s,%s,'%s',%s, %s,'%s','UNCONFIRMED','%s','%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()".$ADD2.")",
+       array(
+               $countryRow,
+               substr($_POST['gender'], 0, 1),
+               $_POST['surname'],
+               $_POST['family_name'],
+               $_POST['street_nr'],
+               $countryData,
+               bigintval($_POST['zip']),
+               $_POST['city'],
+               $_POST['addy'],
+               bigintval($_POST['day']),
+               bigintval($_POST['month']),
+               bigintval($_POST['year']),
+               generateHash($_POST['pass1']),
+               bigintval($_POST['max_mails']),
+               bigintval($_POST['max_mails']),
+               bigintval($_POST['refid']),
+               $hash,
+               GET_REMOTE_ADDR(),
+       ), __FILE__, __LINE__);
 
        // Get his userid
-       $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE user_hash='%s' LIMIT 1",
-        array($hash), __FILE__, __LINE__);
-       list($userid) = SQL_FETCHROW($result);
+       $userid = SQL_INSERTID();
+
+       // Did this work?
+       if ($userid == 0) {
+               // Something bad happened!
+               LOAD_TEMPLATE("admin_settings_saved", false, USER_NOT_REGISTERED);
+               return;
+       } // END - if
 
-       // Secure userid (we have a little paranoia ;-) )
-       $userid = bigintval($userid);
+       // Is the refback extension there?
+       if (EXT_IS_ACTIVE("refback")) {
+               // Update refback table
+               UPDATE_REFBACK_TABLE($userid);
+       } // END - if
 
        // Write his welcome-points
        $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_points WHERE userid=%s AND ref_depth=0 LIMIT 1",
         array(bigintval($userid)), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 0)
-       {
+       if (SQL_NUMROWS($result) == 0) {
                // Add only when the line was not found (maybe some more secure?)
                $locked = "points";
                if ($_CONFIG['ref_payout'] > 0) $locked = "locked_points"; // Pay him later. First he has to confirm some mails!
-               $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid, ref_depth, ".$locked.") VALUES(%s, 0, '%s')",
+               $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid, ref_depth, ".$locked.") VALUES (%s,0,'%s')",
                 array(bigintval($userid), $_CONFIG['points_register']), __FILE__, __LINE__);
 
                // Update mediadata as well
                if ((GET_EXT_VERSION("mediadata") >= "0.0.4") && ($locked == "points")) {
                        // Update database
                        MEDIA_UPDATE_ENTRY(array("total_points"), "add", $_CONFIG['points_register']);
-               }
-       }
+               } // END - if
+       } // END - if
 
        // Write catgories
        if ((is_array($_POST['cat'])) && (count($_POST['cat']))) {
@@ -286,22 +295,22 @@ array(
                                // Insert category entry
                                $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_cats (userid, cat_id) VALUES (%s, %s)",
                                 array(bigintval($userid), bigintval($cat)), __FILE__, __LINE__);
-                       }
-               }
-       }
+                       } // END - if
+               } // END - foreach
+       } // END - if
 
-       // Rewrite sex
-       $sex = TRANSLATE_SEX($_POST['sex']);
+       // Rewrite gender
+       $gender = TRANSLATE_GENDER($_POST['gender']);
 
-       // ... rewrite a zero referral ID to the main title
+       // ... rewrite a zero referal ID to the main title
        if ($_POST['refid'] == "0") $_POST['refid'] = MAIN_TITLE;
 
        // Prepare data array for the email template
-       // Start with the salutation...
+       // Start with the gender...
        $DATA = array(
                'hash'    => $hash,
                'uid'     => $userid,
-               'salut'   => $sex,
+               'gender'  => $gender,
                'surname' => SQL_ESCAPE($_POST['surname']),
                'family'  => SQL_ESCAPE($_POST['family_name']),
                'email'   => SQL_ESCAPE($_POST['addy']),
@@ -338,57 +347,48 @@ array(
 
        // Output success registration
        LOAD_TEMPLATE("admin_settings_saved", false, REGISTRATION_DONE);
-}
- else
-{
-       if ($_POST['agree'] == "!")
-       {
+} else {
+       if ($_POST['agree'] == "!") {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".HAVE_TO_AGREE."</SPAN></STRONG><br /><br />");
-       }
-       if ($_POST['addy'] == "!")
-       {
+       } // END - if
+
+       if ($_POST['addy'] == "!") {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_EMAIL."</SPAN></STRONG><br /><br />");
                $_POST['addy'] = "";
-       }
-        elseif ($_POST['addy'] == "?")
-       {
+       } elseif ($_POST['addy'] == "?") {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".EMAIL_ALREADY_DB."</SPAN></STRONG><br /><br />");
                $_POST['addy'] = "";
        }
-       if ($_POST['surname'] == "!")
-       {
+
+       if ($_POST['surname'] == "!") {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_SURNAME."</SPAN></STRONG><br /><br />");
                $_POST['surname'] = "";
-       }
-       if ($_POST['family_name'] == "!")
-       {
+       } // END - if
+
+       if ($_POST['family_name'] == "!") {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_FAMILY."</SPAN></STRONG><br /><br />");
                $_POST['family_name'] = "";
-       }
-       if (($_POST['pass1'] == "!") && ($_POST['pass2'] == "!"))
-       {
+       } // END - if
+
+       if (($_POST['pass1'] == "!") && ($_POST['pass2'] == "!")) {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_BOTH_PASSWORDS."</SPAN></STRONG><br /><br />");
-       }
-        elseif ($_POST['pass1'] == "!")
-       {
+       } elseif ($_POST['pass1'] == "!") {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_PASS1."</SPAN></STRONG><br /><br />");
-       }
-        elseif ($_POST['pass2'] == "!")
-       {
+       } elseif ($_POST['pass2'] == "!") {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_PASS2."</SPAN></STRONG><br /><br />");
        }
-       if ($SHORT_PASS)
-       {
+
+       if ($SHORT_PASS) {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".SHORT_PASS.": ".$_CONFIG['pass_len']."</SPAN></STRONG><br /><br />");
-       }
-       if ($IP_TIMEOUT)
-       {
+       } // END - if
+
+       if ($IP_TIMEOUT) {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".REMOTE_ADDR_TIMEOUT."</SPAN></STRONG><br /><br />");
-       }
-       if ((!empty($cats)) && ($cats < $_CONFIG['least_cats']))
-       {
+       } // END - if
+
+       if ((!empty($cats)) && ($cats < $_CONFIG['least_cats'])) {
                OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".CATS_LEAST.": ".$_CONFIG['least_cats']."</SPAN></STRONG><br /><br />");
-       }
+       } // END - if
 
        // Generate birthday selection
        switch (GET_LANGUAGE())
@@ -407,29 +407,13 @@ array(
        // Adds maximum receiveable mails list... :)
        define('MAX_RECEIVE_LIST', ADD_MAX_RECEIVE_LIST("guest", "", true));
 
-       // Check if nickname extension is active and get state if nickname is selected or userid
-       $nick = false;
-       if (EXT_IS_ACTIVE("nickname")) $nick = NICKNAME_IS_ACTIVE($GLOBALS['refid']);
-
-       // Is the nickname valid?
-       if (!$nick) {
-               // Nope, disable it
-               if (GET_EXT_VERSION("sql_patches") != '') {
-                       // Use default refid
-                       $GLOBALS['refid'] = $_CONFIG['def_refid'];
-               } else {
-                       // Set zero
-                       $GLOBALS['refid'] = 0;
-               }
-       }
-
        // Shall I display the refid or shall I make it editable?
        if ($_CONFIG['display_refid'] == "Y") {
-               // Load template to enter it
-               define('REFID_CONTENT', LOAD_TEMPLATE("guest_register_refid", true, $GLOBALS['refid']));
-       } else {
                // Load "hide" form template
                define('REFID_CONTENT', LOAD_TEMPLATE("guest_register_refid_hide", true, $GLOBALS['refid']));
+       } else {
+               // Load template to enter it
+               define('REFID_CONTENT', LOAD_TEMPLATE("guest_register_refid", true, $GLOBALS['refid']));
        }
 
        // You may want to modify the register_header.tpl.xx file and not this script when you add your scripts etc. :-)
@@ -439,14 +423,16 @@ array(
        define('LEAST_CATS_VALUE', $_CONFIG['least_cats']);
 
        // Other values
-       define('__SURNAME', $_POST['surname']);   define('__FAMILY',  $_POST['family_name']);
-       define('__STREET',  $_POST['street_nr']); define('__COUNTRY', $_POST['cntry']);
-       define('__ZIP',     $_POST['zip']);       define('__CITY',    $_POST['city']);
-       define('__ADDY',    $_POST['addy']);
+       define('__SURNAME', SQL_ESCAPE($_POST['surname']));
+       define('__FAMILY',  SQL_ESCAPE($_POST['family_name']));
+       define('__STREET',  SQL_ESCAPE($_POST['street_nr']));
+       define('__COUNTRY', SQL_ESCAPE($_POST['cntry']));
+       define('__ZIP',     bigintval($_POST['zip']));
+       define('__CITY',    SQL_ESCAPE($_POST['city']));
+       define('__ADDY',    SQL_ESCAPE($_POST['addy']));
 
        // Shall I add a counrty selection box or the old input box?
-       if (EXT_IS_ACTIVE("country"))
-       {
+       if (EXT_IS_ACTIVE("country")) {
                // New variant, good!
                $OUT  = "<SELECT name=\"country_code\" class=\"guest_select\" size=\"1\">\n";
                $whereStatement = "WHERE is_active='Y'";
@@ -454,9 +440,7 @@ array(
                $OUT .= ADD_OPTION_LINES("countries", "id", "descr", $_POST['country_code'], "code", $whereStatement);
                $OUT .= "</SELECT>";
                define('__COUNTRY_CONTENT', $OUT);
-       }
-        else
-       {
+       } else {
                // Old out-dated variant
                define('__COUNTRY_CONTENT', "<INPUT type=\"text\" name=\"cntry\" class=\"guest_normal\" size=\"2\" maxlength=\"3\" value=\"".__COUNTRY."\">");
        }