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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif ((!EXT_IS_ACTIVE("register"))) {
40 ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "register"));
42 ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "register");
47 // Add description as navigation point
48 ADD_DESCR("guest", basename(__FILE__));
50 global $_CONFIG, $DATA;
52 // Initialize variables
53 $FAILED = false; $SHORT_PASS = false; $cats = 0; $IP_TIMEOUT = false;
54 if (!isset($_POST['ok'])) unset($_POST['ok']);
55 if (empty($_POST['agree'])) $_POST['agree'] = "";
56 if (empty($_POST['addy'])) $_POST['addy'] = "";
57 if (empty($_POST['surname'])) $_POST['surname'] = "";
58 if (empty($_POST['family_name'])) $_POST['family_name'] = "";
59 if (empty($_POST['pass1'])) $_POST['pass1'] = "";
60 if (empty($_POST['pass2'])) $_POST['pass2'] = "";
61 if (empty($_POST['day'])) $_POST['day'] = "";
62 if (empty($_POST['month'])) $_POST['month'] = "";
63 if (empty($_POST['year'])) $_POST['year'] = "";
64 if (empty($_POST['max_mails'])) $_POST['max_mails'] = "";
65 if (empty($_POST['street_nr'])) $_POST['street_nr'] = "";
66 if (empty($_POST['zip'])) $_POST['zip'] = "";
67 if (empty($_POST['city'])) $_POST['city'] = "";
68 if (empty($_POST['cntry'])) $_POST['cntry'] = "";
69 if (empty($_POST['country_code'])) $_POST['country_code'] = "1";
71 if (isset($_POST['ok']))
73 // First we only check the submitted data then we continue... :)
75 // Did he agree to our Terms Of Usage?
76 if ($_POST['agree'] != "Y")
78 $_POST['agree'] = "!";
82 // Did he enter a valid email address? (we really don't care about
83 // that, he has to click on a confirmation link :P )
84 if ((empty($_POST['addy'])) || (!VALIDATE_EMAIL($_POST['addy'])))
90 // And what about surname and family's name?
91 if (empty($_POST['surname']))
93 $_POST['surname'] = "!";
96 if (empty($_POST['family_name']))
98 $_POST['family_name'] = "!";
102 // Check for required fields
103 if (!$FAILED) $FAILED = REGISTER_CHECK_REQUIRED_FIELDS($_POST);
105 // Did he enter his password twice?
106 if (((empty($_POST['pass1'])) || (empty($_POST['pass2']))) || (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2']))))
108 if (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2'])))
110 $_POST['pass1'] = "!";
111 $_POST['pass2'] = "!";
115 if (empty($_POST['pass1'])) { $_POST['pass1'] = "!"; } else { $_POST['pass1'] = ""; }
116 if (empty($_POST['pass2'])) { $_POST['pass2'] = "!"; } else { $_POST['pass2'] = ""; }
120 // Is the password long enouth?
121 if ((strlen($_POST['pass1']) < $_CONFIG['pass_len']) && (!$FAILED) && (!IS_ADMIN()))
126 // Did he select enougth categories?
129 // Do this check only when no admin is logged in
130 foreach ($_POST['cat'] as $id => $answer)
132 if ($answer == "Y") $cats++;
134 if ($cats < $_CONFIG['least_cats'])
140 if (($_POST['addy'] != "!") && ($_CONFIG['check_double_email'] == "Y") && (!IS_ADMIN()))
142 // Does the email address already exists in our database?
143 $CHK = SEARCH_EMAIL_USERTAB($_POST['addy']);
144 if ($CHK) { $_POST['addy'] = "?"; $FAILED = true; }
147 // Check his IP number
148 $to = bigintval(time() - $_CONFIG['ip_timeout']);
149 $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",
150 array(getenv('REMOTE_ADDR'), $to, $to), __FILE__, __LINE__);
151 if ((SQL_NUMROWS($result) == 1) && (!IS_ADMIN()))
153 // Same IP in timeout range and different email address entered... Eat this, faker! ;-)
154 // But admins are allowed to fake their own exchange service.
159 // Test the refid (because some strange hackers... :-P)
160 $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
161 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
162 if (SQL_NUMROWS($result) == 0)
164 // Not found so we set your refid!
165 $_POST['refid'] = $_CONFIG['def_refid'];
166 set_session("refid", $_CONFIG['def_refid']);
170 SQL_FREERESULT($result);
173 if ((isset($_POST['ok'])) && (!$FAILED))
175 // Save the registration
176 if (strlen($_POST['day']) == 1) $_POST['day'] = "0".$_POST['day'];
177 if (strlen($_POST['month']) == 1) $_POST['month'] = "0".$_POST['month'];
179 // Hash = MM-DD-YYYY:IP:USER_AGENT:TIMEMARK
180 $hash = generateHash($_POST['month']."-".$_POST['day']."-".$_POST['year'].":".getenv('SERVER_NAME').":".getenv('REMOTE_ADDR').":".getenv('HTTP_USER_AGENT').":".time());
182 // Add design when extension sql_patches is v0.2.7 or greater
183 $ADD1 = ""; $ADD2 = "";
184 if (GET_EXT_VERSION("sql_patches") >= "0.2.7")
186 // Okay, add design here
187 $ADD1 = ", curr_theme";
188 $ADD2 = ", '".GET_CURR_THEME()."'";
191 // Check if I shall disable sending mail to newly registered members out about active/begging rallye
193 // First comes first: begging rallye
194 if (GET_EXT_VERSION("beg") >= "0.1.7")
196 // Okay, shall I disable now?
197 if ($_CONFIG['beg_new_mem_notify'] == "N")
199 $ADD1 .= ", beg_ral_notify, beg_ral_en_notify";
200 $ADD2 .= ", UNIX_TIMESTAMP(), UNIX_TIMESTAMP()";
204 // Second: active rallye
205 if (GET_EXT_VERSION("bonus") >= "0.7.7")
207 // Okay, shall I disable now?
208 if ($_CONFIG['bonus_new_mem_notify'] == "N")
210 $ADD1 .= ", bonus_ral_notify, bonus_ral_en_notify";
211 $ADD2 .= ", UNIX_TIMESTAMP(), UNIX_TIMESTAMP()";
215 // Write user data to table
216 if (EXT_IS_ACTIVE("country"))
218 // Save with new selectable country code
219 $countryRow = "country_code";
220 $countryData = bigintval($_POST['country_code']);
224 // Old way with enterable two-char-code
225 $countryRow = "country";
226 $countryData = addslashes(substr($_POST['cntry'], 0, 2));
229 //////////////////////////////
230 // Create user's account... //
231 //////////////////////////////
233 $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.")
234 VALUES ('%s', '%s', '%s', '%s', '%s', %s, '%s', '%s', %s, %s, %s, '%s', %s, %s, %s, 'UNCONFIRMED', '%s', '%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()".$ADD2.")",
237 SQL_ESCAPE(substr($_POST['gender'], 0, 1)),
238 SQL_ESCAPE($_POST['surname']),
239 SQL_ESCAPE($_POST['family_name']),
240 SQL_ESCAPE($_POST['street_nr']),
242 bigintval($_POST['zip']),
243 SQL_ESCAPE($_POST['city']),
244 SQL_ESCAPE($_POST['addy']),
245 bigintval($_POST['day']),
246 bigintval($_POST['month']),
247 bigintval($_POST['year']),
248 generateHash($_POST['pass1']),
249 bigintval($_POST['max_mails']),
250 bigintval($_POST['max_mails']),
251 bigintval($_POST['refid']),
253 getenv('REMOTE_ADDR'),
254 ), __FILE__, __LINE__);
257 $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE user_hash='%s' LIMIT 1",
258 array($hash), __FILE__, __LINE__);
259 list($userid) = SQL_FETCHROW($result);
261 // Secure userid (we have a little paranoia ;-) )
262 $userid = bigintval($userid);
264 // Write his welcome-points
265 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_points WHERE userid=%s AND ref_depth=0 LIMIT 1",
266 array(bigintval($userid)), __FILE__, __LINE__);
267 if (SQL_NUMROWS($result) == 0)
269 // Add only when the line was not found (maybe some more secure?)
271 if ($_CONFIG['ref_payout'] > 0) $locked = "locked_points"; // Pay him later. First he has to confirm some mails!
272 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid, ref_depth, ".$locked.") VALUES(%s, 0, '%s')",
273 array(bigintval($userid), $_CONFIG['points_register']), __FILE__, __LINE__);
275 // Update mediadata as well
276 if ((GET_EXT_VERSION("mediadata") >= "0.0.4") && ($locked == "points")) {
278 MEDIA_UPDATE_ENTRY(array("total_points"), "add", $_CONFIG['points_register']);
283 if ((is_array($_POST['cat'])) && (count($_POST['cat']))) {
284 foreach ($_POST['cat'] as $cat => $joined) {
285 if ($joined == "Y") {
286 // Insert category entry
287 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_cats (userid, cat_id) VALUES (%s, %s)",
288 array(bigintval($userid), bigintval($cat)), __FILE__, __LINE__);
294 $gender = TRANSLATE_GENDER($_POST['gender']);
296 // ... rewrite a zero referral ID to the main title
297 if ($_POST['refid'] == "0") $_POST['refid'] = MAIN_TITLE;
299 // Prepare data array for the email template
300 // Start with the gender...
305 'surname' => SQL_ESCAPE($_POST['surname']),
306 'family' => SQL_ESCAPE($_POST['family_name']),
307 'email' => SQL_ESCAPE($_POST['addy']),
308 'street' => SQL_ESCAPE($_POST['street_nr']),
309 'city' => SQL_ESCAPE($_POST['city']),
310 'zip' => bigintval($_POST['zip']),
311 'country' => $countryData,
312 'refid' => SQL_ESCAPE($_POST['refid']),
313 'pass' => SQL_ESCAPE($_POST['pass1']),
316 // Continue with birthday...
317 switch (GET_LANGUAGE())
320 $DATA['birthday'] = bigintval($_POST['day']).".".bigintval($_POST['month']).".".bigintval($_POST['year']);
324 $DATA['birthday'] = bigintval($_POST['month'])."/".bigintval($_POST['day'])."/".bigintval($_POST['year']);
328 // Display information to the user that he got mail and send it away
329 $msg_guest = LOAD_EMAIL_TEMPLATE("register-member", $DATA, $userid);
331 // Send mail to user (confirmation link!)
332 $EMAIL = $DATA['email'];
333 SEND_EMAIL ($DATA['email'], GUEST_CONFIRM_LINK, $msg_guest);
334 $DATA['email'] = $EMAIL;
336 // Send mail to admin
337 SEND_ADMIN_NOTIFICATION(ADMIN_NEW_ACCOUNT, "register-admin", $DATA, $userid);
339 // Output success registration
340 LOAD_TEMPLATE("admin_settings_saved", false, REGISTRATION_DONE);
344 if ($_POST['agree'] == "!")
346 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".HAVE_TO_AGREE."</SPAN></STRONG><br /><br />");
348 if ($_POST['addy'] == "!")
350 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_EMAIL."</SPAN></STRONG><br /><br />");
353 elseif ($_POST['addy'] == "?")
355 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".EMAIL_ALREADY_DB."</SPAN></STRONG><br /><br />");
358 if ($_POST['surname'] == "!")
360 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_SURNAME."</SPAN></STRONG><br /><br />");
361 $_POST['surname'] = "";
363 if ($_POST['family_name'] == "!")
365 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_FAMILY."</SPAN></STRONG><br /><br />");
366 $_POST['family_name'] = "";
368 if (($_POST['pass1'] == "!") && ($_POST['pass2'] == "!"))
370 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_BOTH_PASSWORDS."</SPAN></STRONG><br /><br />");
372 elseif ($_POST['pass1'] == "!")
374 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_PASS1."</SPAN></STRONG><br /><br />");
376 elseif ($_POST['pass2'] == "!")
378 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".ENTER_PASS2."</SPAN></STRONG><br /><br />");
382 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".SHORT_PASS.": ".$_CONFIG['pass_len']."</SPAN></STRONG><br /><br />");
386 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".REMOTE_ADDR_TIMEOUT."</SPAN></STRONG><br /><br />");
388 if ((!empty($cats)) && ($cats < $_CONFIG['least_cats']))
390 OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".CATS_LEAST.": ".$_CONFIG['least_cats']."</SPAN></STRONG><br /><br />");
393 // Generate birthday selection
394 switch (GET_LANGUAGE())
396 case "de": // German date format
397 define('BIRTHDAY_SELECTION', ADD_SELECTION("day", $_POST['day']).ADD_SELECTION("month", $_POST['month']).ADD_SELECTION("year", $_POST['year']));
400 default: // Default is the US date format... :)
404 // Adds a table for the guests with all visible categories
405 define('CATEGORY_SELECTION', REGISTER_ADD_CATEGORY_TABLE("guest", true));
407 // Adds maximum receiveable mails list... :)
408 define('MAX_RECEIVE_LIST', ADD_MAX_RECEIVE_LIST("guest", "", true));
410 // Check if nickname extension is active and get state if nickname is selected or userid
412 if (EXT_IS_ACTIVE("nickname")) $nick = NICKNAME_IS_ACTIVE($GLOBALS['refid']);
414 // Is the nickname valid?
417 if (GET_EXT_VERSION("sql_patches") != '') {
419 $GLOBALS['refid'] = $_CONFIG['def_refid'];
422 $GLOBALS['refid'] = 0;
426 // Shall I display the refid or shall I make it editable?
427 if ($_CONFIG['display_refid'] == "Y") {
428 // Load template to enter it
429 define('REFID_CONTENT', LOAD_TEMPLATE("guest_register_refid", true, $GLOBALS['refid']));
431 // Load "hide" form template
432 define('REFID_CONTENT', LOAD_TEMPLATE("guest_register_refid_hide", true, $GLOBALS['refid']));
435 // You may want to modify the register_header.tpl.xx file and not this script when you add your scripts etc. :-)
436 define('REGISTER_HEADER_CONTENT', LOAD_TEMPLATE("register_header", true));
438 // Please select at least x categories
439 define('LEAST_CATS_VALUE', $_CONFIG['least_cats']);
442 define('__SURNAME', $_POST['surname']); define('__FAMILY', $_POST['family_name']);
443 define('__STREET', $_POST['street_nr']); define('__COUNTRY', $_POST['cntry']);
444 define('__ZIP', $_POST['zip']); define('__CITY', $_POST['city']);
445 define('__ADDY', $_POST['addy']);
447 // Shall I add a counrty selection box or the old input box?
448 if (EXT_IS_ACTIVE("country"))
450 // New variant, good!
451 $OUT = "<SELECT name=\"country_code\" class=\"guest_select\" size=\"1\">\n";
452 $whereStatement = "WHERE is_active='Y'";
453 if (IS_ADMIN()) $whereStatement = "";
454 $OUT .= ADD_OPTION_LINES("countries", "id", "descr", $_POST['country_code'], "code", $whereStatement);
456 define('__COUNTRY_CONTENT', $OUT);
460 // Old out-dated variant
461 define('__COUNTRY_CONTENT', "<INPUT type=\"text\" name=\"cntry\" class=\"guest_normal\" size=\"2\" maxlength=\"3\" value=\"".__COUNTRY."\">");
464 // Set MUST_??? constants
465 if ((EXT_IS_ACTIVE("register")) && (GET_EXT_VERSION("register") > "0.0")) REGISTER_FILL_MUST_CONSTANTS();
467 // Display registration form
468 LOAD_TEMPLATE("guest_register");