2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/10/2003 *
4 * =============== Last change: 11/26/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-register.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Registration form *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Anmeldeformular *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif ((!EXT_IS_ACTIVE("register"))) {
39 addFatalMessage(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "register");
43 // Add description as navigation point
44 ADD_DESCR("guest", __FILE__);
48 // Initialize variables
49 $FAILED = false; $SHORT_PASS = false; $cats = 0; $IP_TIMEOUT = false;
50 if (!isset($_POST['ok'])) unset($_POST['ok']);
51 if (empty($_POST['agree'])) $_POST['agree'] = "";
52 if (empty($_POST['addy'])) $_POST['addy'] = "";
53 if (empty($_POST['surname'])) $_POST['surname'] = "";
54 if (empty($_POST['family_name'])) $_POST['family_name'] = "";
55 if (empty($_POST['pass1'])) $_POST['pass1'] = "";
56 if (empty($_POST['pass2'])) $_POST['pass2'] = "";
57 if (empty($_POST['day'])) $_POST['day'] = "";
58 if (empty($_POST['month'])) $_POST['month'] = "";
59 if (empty($_POST['year'])) $_POST['year'] = "";
60 if (empty($_POST['max_mails'])) $_POST['max_mails'] = "";
61 if (empty($_POST['street_nr'])) $_POST['street_nr'] = "";
62 if (empty($_POST['zip'])) $_POST['zip'] = "";
63 if (empty($_POST['city'])) $_POST['city'] = "";
64 if (empty($_POST['cntry'])) $_POST['cntry'] = "";
65 if (empty($_POST['country_code'])) $_POST['country_code'] = "1";
67 // Default refid is zero
69 if ($GLOBALS['refid'] > 0) {
70 // Test if the refid is valid
71 $result = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
72 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
75 //* DEBUG: */ die("refid={$GLOBALS['refid']}/numRows=".SQL_NUMROWS($result)."");
76 if (SQL_NUMROWS($result) == 0) {
77 // Not found so we set your refid!
78 $_POST['refid'] = getConfig('def_refid');
79 set_session('refid', getConfig('def_refid'));
82 $_POST['refid'] = $GLOBALS['refid'];
86 if (isset($_POST['ok'])) {
87 // First we only check the submitted data then we continue... :)
89 // Did he agree to our Terms Of Usage?
90 if ($_POST['agree'] != "Y") {
91 $_POST['agree'] = "!";
95 // Did he enter a valid email address? (we really don't care about
96 // that, he has to click on a confirmation link :P )
97 if ((empty($_POST['addy'])) || (!VALIDATE_EMAIL($_POST['addy']))) {
102 // And what about surname and family's name?
103 if (empty($_POST['surname'])) {
104 $_POST['surname'] = "!";
107 if (empty($_POST['family_name'])) {
108 $_POST['family_name'] = "!";
112 // Check for required fields
113 if (!$FAILED) $FAILED = REGISTER_CHECK_REQUIRED_FIELDS($_POST);
115 // Did he enter his password twice?
116 if (((empty($_POST['pass1'])) || (empty($_POST['pass2']))) || (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2'])))) {
117 if (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2']))) {
118 $_POST['pass1'] = "!";
119 $_POST['pass2'] = "!";
121 if (empty($_POST['pass1'])) { $_POST['pass1'] = "!"; } else { $_POST['pass1'] = ""; }
122 if (empty($_POST['pass2'])) { $_POST['pass2'] = "!"; } else { $_POST['pass2'] = ""; }
127 // Is the password long enouth?
128 if ((strlen($_POST['pass1']) < getConfig('pass_len')) && (!$FAILED)) {
133 // No admin? Admins can always register!
135 // Do this check only when no admin is logged in
136 foreach ($_POST['cat'] as $id => $answer) {
137 if ($answer == "Y") $cats++;
140 if ($cats < getConfig('least_cats')) {
146 if (($_POST['addy'] != "!") && (getConfig('check_double_email') == "Y")) {
147 // Does the email address already exists in our database?
148 $CHK = SEARCH_EMAIL_USERTAB($_POST['addy']);
149 if ($CHK) { $_POST['addy'] = "?"; $FAILED = true; }
152 // Check for IP timeout?
153 if (getConfig('ip_timeout') > 0) {
154 // Check his IP number
155 $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",
156 array(GET_REMOTE_ADDR(), getConfig('ip_timeout'), getConfig('ip_timeout')), __FILE__, __LINE__);
157 if (SQL_NUMROWS($result) == 1) {
158 // Same IP in timeout range and different email address entered... Eat this, faker! ;-)
159 // But admins are allowed to fake their own exchange service.
166 SQL_FREERESULT($result);
169 if ((isset($_POST['ok'])) && ((!$FAILED) || (IS_ADMIN()))) {
170 // Prepapre month and day of birth
171 if (strlen($_POST['day']) == 1) $_POST['day'] = "0".$_POST['day'];
172 if (strlen($_POST['month']) == 1) $_POST['month'] = "0".$_POST['month'];
175 // ... confirmed, ...
176 $confirmedUsers = GET_TOTAL_DATA("CONFIRMED", "user_data", "userid", "status", true);
177 // ... unconfirmed ...
178 $unconfirmedUsers = GET_TOTAL_DATA("UNCONFIRMED", "user_data", "userid", "status", true);
179 // ... and locked users!
180 $lockedUsers = GET_TOTAL_DATA("LOCKED", "user_data", "userid", "status", true);
182 // Generate hash which will be inserted into confirmation mail
183 $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));
185 // Add design when extension sql_patches is v0.2.7 or greater
186 $ADD1 = ""; $ADD2 = "";
187 if (GET_EXT_VERSION("sql_patches") >= "0.2.7") {
188 // Okay, add design here
189 $ADD1 = ", curr_theme";
190 $ADD2 = ", '".GET_CURR_THEME()."'";
193 // Check if I shall disable sending mail to newly registered members out about active/begging rallye
194 // @TODO Rewrite this to a single filter
196 // First comes first: begging rallye
197 if (GET_EXT_VERSION("beg") >= "0.1.7") {
198 // Okay, shall I disable now?
199 if (getConfig('beg_new_mem_notify') != "Y") {
200 $ADD1 .= ", beg_ral_notify, beg_ral_en_notify";
201 $ADD2 .= ", UNIX_TIMESTAMP(), UNIX_TIMESTAMP()";
205 // Second: active rallye
206 if (GET_EXT_VERSION("bonus") >= "0.7.7") {
207 // Okay, shall I disable now?
208 if (getConfig('bonus_new_mem_notify') != "Y") {
209 $ADD1 .= ", bonus_ral_notify, bonus_ral_en_notify";
210 $ADD2 .= ", UNIX_TIMESTAMP(), UNIX_TIMESTAMP()";
214 // Write user data to table
215 if (EXT_IS_ACTIVE("country")) {
216 // Save with new selectable country code
217 $countryRow = "country_code";
218 $countryData = bigintval($_POST['country_code']);
220 // Old way with enterable two-char-code
221 $countryRow = "country";
222 $countryData = substr($_POST['cntry'], 0, 2);
225 //////////////////////////////
226 // Create user's account... //
227 //////////////////////////////
229 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.")
230 VALUES ('%s','%s','%s','%s','%s',%s,'%s','%s',%s, %s,%s,'%s',%s, %s,'%s','UNCONFIRMED','%s','%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()".$ADD2.")",
233 substr($_POST['gender'], 0, 1),
235 $_POST['family_name'],
238 bigintval($_POST['zip']),
241 bigintval($_POST['day']),
242 bigintval($_POST['month']),
243 bigintval($_POST['year']),
244 generateHash($_POST['pass1']),
245 bigintval($_POST['max_mails']),
246 bigintval($_POST['max_mails']),
247 bigintval($_POST['refid']),
250 ), __FILE__, __LINE__);
253 $userid = SQL_INSERTID();
257 // Something bad happened!
258 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('USER_NOT_REGISTERED'));
262 // Is the refback extension there?
263 if (EXT_IS_ACTIVE("refback")) {
264 // Update refback table
265 UPDATE_REFBACK_TABLE($userid);
268 // Write his welcome-points
269 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_points` WHERE userid=%s AND ref_depth=0 LIMIT 1",
270 array(bigintval($userid)), __FILE__, __LINE__);
271 if (SQL_NUMROWS($result) == 0) {
272 // Add only when the line was not found (maybe some more secure?)
274 if (getConfig('ref_payout') > 0) $locked = "locked_points"; // Pay him later. First he has to confirm some mails!
275 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_points` (userid, ref_depth, ".$locked.") VALUES (%s,0,'%s')",
276 array(bigintval($userid), getConfig('points_register')), __FILE__, __LINE__);
278 // Update mediadata as well
279 if ((GET_EXT_VERSION("mediadata") >= "0.0.4") && ($locked == "points")) {
281 MEDIA_UPDATE_ENTRY(array("total_points"), "add", getConfig('points_register'));
286 if ((is_array($_POST['cat'])) && (count($_POST['cat']))) {
287 foreach ($_POST['cat'] as $cat => $joined) {
288 if ($joined == "Y") {
289 // Insert category entry
290 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_cats` (userid, cat_id) VALUES (%s, %s)",
291 array(bigintval($userid), bigintval($cat)), __FILE__, __LINE__);
297 $gender = TRANSLATE_GENDER($_POST['gender']);
299 // ... rewrite a zero referal ID to the main title
300 if ($_POST['refid'] == "0") $_POST['refid'] = constant('MAIN_TITLE');
303 if (!empty($_POST['zip'])) {
304 // Prepare data array for the email template
305 // Start with the gender...
310 'surname' => SQL_ESCAPE($_POST['surname']),
311 'family' => SQL_ESCAPE($_POST['family_name']),
312 'email' => SQL_ESCAPE($_POST['addy']),
313 'street' => SQL_ESCAPE($_POST['street_nr']),
314 'city' => SQL_ESCAPE($_POST['city']),
315 'zip' => bigintval($_POST['zip']),
316 'country' => $countryData,
317 'refid' => SQL_ESCAPE($_POST['refid']),
318 'pass' => SQL_ESCAPE($_POST['pass1']),
321 // No ZIP code entered
326 'surname' => SQL_ESCAPE($_POST['surname']),
327 'family' => SQL_ESCAPE($_POST['family_name']),
328 'email' => SQL_ESCAPE($_POST['addy']),
329 'street' => SQL_ESCAPE($_POST['street_nr']),
330 'city' => SQL_ESCAPE($_POST['city']),
332 'country' => $countryData,
333 'refid' => SQL_ESCAPE($_POST['refid']),
334 'pass' => SQL_ESCAPE($_POST['pass1']),
338 // Continue with birthday...
339 switch (GET_LANGUAGE())
342 $DATA['birthday'] = bigintval($_POST['day']).".".bigintval($_POST['month']).".".bigintval($_POST['year']);
346 $DATA['birthday'] = bigintval($_POST['month'])."/".bigintval($_POST['day'])."/".bigintval($_POST['year']);
350 // Display information to the user that he got mail and send it away
351 $msg_guest = LOAD_EMAIL_TEMPLATE("register-member", $DATA, $userid);
353 // Send mail to user (confirmation link!)
354 $EMAIL = $DATA['email'];
355 SEND_EMAIL ($DATA['email'], getMessage('GUEST_CONFIRM_LINK'), $msg_guest);
356 $DATA['email'] = $EMAIL;
358 // Send mail to admin
359 SEND_ADMIN_NOTIFICATION(getMessage('ADMIN_NEW_ACCOUNT'), "register-admin", $DATA, $userid);
361 // Output success registration
362 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('REGISTRATION_DONE'));
364 if ($_POST['agree'] == "!") {
365 OUTPUT_HTML("<div class=\"register_failed\">{--HAVE_TO_AGREE--}</div>");
368 if ($_POST['addy'] == "!") {
369 OUTPUT_HTML("<div class=\"register_failed\">{--ENTER_EMAIL--}</div>");
371 } elseif ($_POST['addy'] == "?") {
372 OUTPUT_HTML("<div class=\"register_failed\">{--EMAIL_ALREADY_DB--}</div>");
376 if ($_POST['surname'] == "!") {
377 OUTPUT_HTML("<div class=\"register_failed\">{--ENTER_SURNAME--}</div>");
378 $_POST['surname'] = "";
381 if ($_POST['family_name'] == "!") {
382 OUTPUT_HTML("<div class=\"register_failed\">{--ENTER_FAMILY--}</div>");
383 $_POST['family_name'] = "";
386 if (($_POST['pass1'] == "!") && ($_POST['pass2'] == "!")) {
387 OUTPUT_HTML("<div class=\"register_failed\">{--ENTER_BOTH_PASSWORDS--}</div>");
388 } elseif ($_POST['pass1'] == "!") {
389 OUTPUT_HTML("<div class=\"register_failed\">{--ENTER_PASS1--}</div>");
390 } elseif ($_POST['pass2'] == "!") {
391 OUTPUT_HTML("<div class=\"register_failed\">{--ENTER_PASS2--}</div>");
394 if ($SHORT_PASS === true) {
395 OUTPUT_HTML("<div class=\"register_failed\">{--SHORT_PASS--}: ".getConfig('pass_len')."</div>");
398 if ($IP_TIMEOUT === true) {
399 OUTPUT_HTML("<div class=\"register_failed\">{--REMOTE_ADDR_TIMEOUT--}</div>");
402 if ((!empty($cats)) && ($cats < getConfig('least_cats'))) {
403 OUTPUT_HTML("<div class=\"register_failed\">{--CATS_LEAST--}: ".getConfig('least_cats')."</div>");
406 // Generate birthday selection
407 switch (GET_LANGUAGE())
409 case "de": // German date format
410 define('BIRTHDAY_SELECTION', ADD_SELECTION("day", $_POST['day']).ADD_SELECTION("month", $_POST['month']).ADD_SELECTION("year", $_POST['year']));
413 default: // Default is the US date format... :)
414 define('BIRTHDAY_SELECTION', ADD_SELECTION("month", $_POST['month']).ADD_SELECTION("day", $_POST['day']).ADD_SELECTION("year", $_POST['year']));
418 // Adds a table for the guests with all visible categories
419 define('CATEGORY_SELECTION', REGISTER_ADD_CATEGORY_TABLE("guest", true));
421 // Adds maximum receiveable mails list... :)
422 define('MAX_RECEIVE_LIST', ADD_MAX_RECEIVE_LIST("guest", "", true));
424 // Shall I display the refid or shall I make it editable?
425 if (getConfig('display_refid') == "Y") {
426 // Load "hide" form template
427 define('REFID_CONTENT', LOAD_TEMPLATE("guest_register_refid_hide", true, $GLOBALS['refid']));
429 // Load template to enter it
430 define('REFID_CONTENT', LOAD_TEMPLATE("guest_register_refid", true, $GLOBALS['refid']));
433 // You may want to modify the register_header.tpl.xx file and not this script when you add your scripts etc. :-)
434 define('REGISTER_HEADER_CONTENT', LOAD_TEMPLATE("register_header", true));
436 // Please select at least x categories
437 define('LEAST_CATS_VALUE', getConfig('least_cats'));
440 define('__SURNAME', SQL_ESCAPE($_POST['surname']));
441 define('__FAMILY', SQL_ESCAPE($_POST['family_name']));
442 define('__STREET', SQL_ESCAPE($_POST['street_nr']));
443 define('__COUNTRY', SQL_ESCAPE($_POST['cntry']));
444 if (!empty($_POST['zip'])) {
445 define('__ZIP', bigintval($_POST['zip']));
449 define('__CITY', SQL_ESCAPE($_POST['city']));
450 define('__ADDY', SQL_ESCAPE($_POST['addy']));
452 // Shall I add a counrty selection box or the old input box?
453 if (EXT_IS_ACTIVE("country")) {
454 // New variant, good!
455 $OUT = "<select name=\"country_code\" class=\"guest_select\" size=\"1\">\n";
456 $whereStatement = "WHERE is_active='Y'";
457 if (IS_ADMIN()) $whereStatement = "";
458 $OUT .= ADD_OPTION_LINES("countries", "id", "descr", $_POST['country_code'], "code", $whereStatement);
460 define('__COUNTRY_CONTENT', $OUT);
462 // Old out-dated variant
463 define('__COUNTRY_CONTENT', "<input type=\"text\" name=\"cntry\" class=\"guest_normal\" size=\"2\" maxlength=\"3\" value=\"{!__COUNTRY!}\" />");
466 // Set MUST_??? constants
467 if ((EXT_IS_ACTIVE("register")) && (GET_EXT_VERSION("register") > "0.0")) REGISTER_FILL_MUST_CONSTANTS();
469 // Display registration form
470 LOAD_TEMPLATE("guest_register");