2 /************************************************************************
3 * MXChange v0.2.1 Start: 06/10/2005 *
4 * =============== Last change: 05/18/2008 *
6 * -------------------------------------------------------------------- *
7 * File : what-sponsor_reg.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Sponsor's registration form *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Anmeldeformular fuer Sponsoren *
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. *
22 * This program is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25 * GNU General Public License for more details. *
27 * You should have received a copy of the GNU General Public License *
28 * along with this program; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
31 ************************************************************************/
33 // Some security stuff...
34 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
35 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
39 // Add description as navigation point
40 ADD_DESCR("guest", basename(__FILE__));
42 // Create array for form errors (= missing data)
43 $FORM_ERRORS = array();
45 if (isset($_POST['ok'])) {
47 // Check submitted form data
49 // 1. Salutation / Surname / family name
50 if (empty($_POST['salut']))
53 $FORM_ERRORS[] = SPONSOR_NO_SALUT_SELECTED;
55 if (empty($_POST['surname']))
58 $FORM_ERRORS[] = SPONSOR_SURNAME_IS_EMPTY;
60 if (empty($_POST['family']))
63 $FORM_ERRORS[] = SPONSOR_FAMILY_IS_EMPTY;
66 // 012 3 32 23 4 43 3 4 4321 12 3 32 2 3 3210
67 if (((empty($_POST['company'])) && ((!empty($_POST['tax_ident'])) || (!empty($_POST['position'])))) || ((!empty($_POST['company'])) && (empty($_POST['tax_ident']))))
69 if (empty($_POST['company']))
71 // Company name is empty
72 $FORM_ERRORS[] = SPONSOR_COMPANY_IS_EMPTY;
74 elseif (empty($_POST['tax_ident']))
76 // Tax ident number name is empty
77 $FORM_ERRORS[] = SPONSOR_TAX_IDENT_IS_EMPTY;
79 if (empty($_POST['position']))
81 // Not fatal but not nice: position in company is empty
82 $FORM_ERRORS[] = SPONSOR_POSITION_IS_EMPTY;
85 // 3. Street and number
86 if (empty($_POST['street_nr1']))
88 // Street name and house number are empty
89 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY;
91 elseif ((!empty($_POST['street_nr2'])) && (empty($_POST['street_nr1'])))
93 // 1st line for street is empty, but 2nd line not
94 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY_2_NOT;
97 if (empty($_POST['country']))
99 // Country code is empty
100 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_EMPTY;
102 elseif (strlen($_POST['country']) != 2)
104 // Country code is invalid
105 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_INVALID;
108 if (empty($_POST['zip']))
111 $FORM_ERRORS[] = SPONSOR_ZIP_IS_EMPTY;
113 elseif (bigintval($_POST['zip']) != $_POST['zip'])
116 $FORM_ERRORS[] = SPONSOR_ZIP_IS_INVALID;
120 if (empty($_POST['city']))
123 $FORM_ERRORS[] = SPONSOR_CITY_IS_EMPTY;
126 if (empty($_POST['phone']))
129 $FORM_ERRORS[] = SPONSOR_PHONE_IS_EMPTY;
132 if (empty($_POST['url']))
134 // Homepage URL is empty
135 $FORM_ERRORS[] = SPONSOR_URL_IS_EMPTY;
137 elseif (!VALIDATE_URL($_POST['url']))
139 // Homepage URL is invalid
140 $FORM_ERRORS[] = SPONSOR_URL_IS_INVALID;
143 // 7. Light validation of email address
144 if ((empty($_POST['email'])) || ($_POST['email'] == "@"))
146 // Email is invalid/empty
147 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_INVALID;
149 elseif (SPONSOR_FOUND_EMAIL_DB($_POST['email']))
151 // Email already found in database!
152 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_ALREADY_REGISTERED;
153 $_POST['email'] = "";
155 // 8. Pay type selected?
156 if (empty($_POST['pay_type']))
158 // Not pay type selected
159 $FORM_ERRORS[] = SPONSOR_NO_PAYTYPE_SELECTED;
161 // 9. Interval of mails
162 if (empty($_POST['warning_interval']))
164 // No warning interval selected
165 $FORM_ERRORS[] = SPONSOR_NO_WARNING_INTERVAL_SELECTED;
167 // 10. Mail notifications disabled/enabled
168 if (empty($_POST['receive_warnings']))
170 // Option not selected!
171 $FORM_ERRORS[] = SPONSOR_NO_RECEIVE_WARNINGS_SELECTED;
173 // Did he enter his password twice?
174 if (((empty($_POST['pass1'])) || (empty($_POST['pass2']))) || (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2']))))
176 if (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2'])))
178 // Passwords missmatch
179 $FORM_ERRORS[] = SPONSOR_PASSWORDS_MISMATCH;
183 if (empty($_POST['pass1']))
185 // Password 1 is empty
186 $FORM_ERRORS[] = SPONSOR_PASSWORD1_EMPTY;
188 if (empty($_POST['pass2']))
190 // Password 2 is empty
191 $FORM_ERRORS[] = SPONSOR_PASSWORD2_EMPTY;
195 // Is the password long enough?
196 elseif (strlen($_POST['pass1']) < $CONFIG['pass_len'])
199 $FORM_ERRORS[] = SPONSOR_PASSWORD_TOO_SHORT;
202 // Check if he has accepted the terms&conditions
203 if (empty($_POST['terms']))
205 // Homepage URL is empty
206 $FORM_ERRORS[] = SPONSOR_TERMS_NOT_ACCEPTED;
209 // If there is something wrong/missing stop registration
210 if (count($FORM_ERRORS) > 0) unset($_POST['ok']);
213 if ((isset($_POST['ok'])) && (count($FORM_ERRORS) == 0))
215 // Generate message array
217 'failed' => SPONSOR_REGISTRATION_FAILED,
218 'added' => SPONSOR_REGISTRATION_COMPLETED,
222 $result = SQL_QUERY_ESC("SELECT (pay_rate * pay_min_count) AS points, pay_min_count AS pay, pay_currency AS curr
223 FROM "._MYSQL_PREFIX."_sponsor_paytypes
224 WHERE id='%s' LIMIT 1", array($_POST['pay_type']), __FILE__, __LINE__);
225 list($points, $pay, $curr) = SQL_FETCHROW($result);
228 SQL_FREERESULT($result);
230 // Add points to array
231 $_POST['points_amount'] = $points;
232 $_POST['points_used'] = "0.00000";
233 $_POST['last_pay'] = $pay;
234 $_POST['last_curr'] = $curr;
236 // Register sponsor but never ever update here!
237 $STATUS = SPONSOR_HANDLE_SPONSOR($_POST, true, $MSGs, true);
239 // Check the status of the registration process
242 case "added": // Sponsor successfully added with account status = UNCONFIRMED!
243 // Check for his ID number
244 $result = SQL_QUERY_ESC("SELECT id, hash FROM "._MYSQL_PREFIX."_sponsor_data WHERE email='%s' LIMIT 1",
245 array($_POST['email']), __FILE__, __LINE__);
246 if (SQL_NUMROWS($result) == 1)
248 // ID found so let's load it for the confirmation email
249 list($id, $hash) = SQL_FETCHROW($result);
251 // Prepare data for the email template
252 define('__ID' , $id);
253 define('__HASH' , $hash);
254 define('__EMAIL' , $_POST['email']);
255 define('__SURNAME' , $_POST['surname']);
256 define('__FAMILY' , $_POST['family']);
257 define('__SALUT' , TRANSLATE_SEX($_POST['salut']));
258 define('__TIMESTAMP', MAKE_DATETIME(time(), 0));
259 define('__PASSWORD' , $_POST['pass1']);
261 // Generate email and send it to the new sponsor
262 $EMAIL_MSG = LOAD_EMAIL_TEMPLATE("sponsor_confirm", $hash);
263 SEND_EMAIL($_POST['email'], SPONSOR_PLEASE_CONFIRM_SUBJ, $EMAIL_MSG);
265 // Send mail to admin
266 SEND_ADMIN_NOTIFICATION(ADMIN_NEW_SPONSOR, "admin_sponsor_reg", $hash);
268 // Output message: DONE
269 $MSG = $MSGs['added'];
273 // Sponsor account not found???
274 $MSG = SPONSOR_EMAIL_404_1.$_POST['email'].SPONSOR_EMAIL_404_2;
278 SQL_FREERESULT($result);
284 // Message for testing admin
285 $MSG = ADMIN_SPONSOR_UNKOWN_STATUS_1.$STATUS.ADMIN_SPONSOR_UNKOWN_STATUS_2;
289 // Message for the guest
290 $MSG = SPONSOR_UNKOWN_STATUS_1.$STATUS.SPONSOR_UNKOWN_STATUS_2;
296 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
300 // Check for payment types
301 $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_currency, pay_min_count
302 FROM "._MYSQL_PREFIX."_sponsor_paytypes
303 ORDER BY pay_name", __FILE__, __LINE__);
304 if (SQL_NUMROWS($result) > 0)
307 $OUT = "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
309 while(list($id, $name, $rate, $curr, $min) = SQL_FETCHROW($result))
312 <TD class=\"bottom2 switch_sw".$SW."\" height=\"50\" style=\"padding-left: 2px; padding-right: 2px\">
313 <INPUT type=\"radio\" name=\"pay_type\" class=\"guest_normal\" value=\"".bigintval($id)."\"> ".$name."<BR>
314 <DIV align=\"right\">(".$min." ".$curr." = ".TRANSLATE_COMMA($rate * $min)." ".POINTS.")</DIV>
319 $OUT .= "</TABLE>\n";
320 define('__PAYMENT_LIST', $OUT);
321 SQL_FREERESULT($result);
323 // Check for invalid entries
324 if (count($FORM_ERRORS) > 0)
327 define('__COMPANY' , COMPILE_CODE($_POST['company']));
328 define('__POSITION' , COMPILE_CODE($_POST['position']));
329 define('__TAX_IDENT', COMPILE_CODE($_POST['tax_ident']));
330 define('__SURNAME' , COMPILE_CODE($_POST['surname']));
331 define('__FAMILY' , COMPILE_CODE($_POST['family']));
332 define('__STREET1' , COMPILE_CODE($_POST['street_nr1']));
333 define('__STREET2' , COMPILE_CODE($_POST['street_nr2']));
334 define('__COUNTRY' , COMPILE_CODE($_POST['country']));
335 define('__ZIP' , COMPILE_CODE($_POST['zip']));
336 define('__CITY' , COMPILE_CODE($_POST['city']));
337 define('__PHONE' , COMPILE_CODE($_POST['phone']));
338 define('__FAX' , COMPILE_CODE($_POST['fax']));
339 define('__CELL' , COMPILE_CODE($_POST['cell']));
340 define('__EMAIL' , COMPILE_CODE($_POST['email']));
341 define('__URL' , COMPILE_CODE($_POST['url']));
343 // Check for salutation selection
344 switch ($_POST['salut'])
347 define('__SALUT_M' , " selected");
348 define('__SALUT_F' , "");
349 define('__SALUT_C' , "");
353 define('__SALUT_M' , "");
354 define('__SALUT_F' , " selected");
355 define('__SALUT_C' , "");
359 define('__SALUT_M' , "");
360 define('__SALUT_F' , "");
361 define('__SALUT_C' , " selected");
365 // Check for receive_warnings
366 switch ($_POST['receive_warnings'])
369 define('__REC_Y' , " selected");
370 define('__REC_N' , "");
374 define('__REC_Y' , "");
375 define('__REC_N' , " selected");
380 $OUT = "<P align=\"center\">
381 <STRONG><FONT class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</FONT></STRONG><BR>
384 foreach ($FORM_ERRORS as $error)
386 $OUT .= "<LI>".$error."</LI>\n";
388 $OUT .= "</OL><BR>\n";
389 define('__SPONSOR_FORM_ERRORS', $OUT);
390 define('__SPONSOR_REFID', $_POST['refid']);
394 // None found, first call
395 define('__COMPANY' , "");
396 define('__POSITION' , "");
397 define('__TAX_IDENT', "");
398 define('__SALUT_M' , "");
399 define('__SALUT_F' , "");
400 define('__SALUT_C' , "");
401 define('__SURNAME' , "");
402 define('__FAMILY' , "");
403 define('__STREET1' , "");
404 define('__STREET2' , "");
405 define('__COUNTRY' , "");
406 define('__ZIP' , "");
407 define('__CITY' , "");
408 define('__PHONE' , "");
409 define('__FAX' , "");
410 define('__CELL' , "");
411 define('__EMAIL' , "");
412 define('__URL' , "");
413 define('__REC_Y' , "");
414 define('__REC_N' , "");
416 // No errors found so far
417 define('__SPONSOR_FORM_ERRORS', "");
420 // Prepare referral things
421 if (!isset($_GET['refid']))
424 define('__SPONSOR_REFID', "0");
428 // Referral ID transmitted, we don't care here if it is right or not
429 define('__SPONSOR_REFID', bigintval($_GET['refid']));
432 // Display registration form
433 LOAD_TEMPLATE("guest_sponsor_reg");
437 // Nothing added so far
438 LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_PAYMENT_LIST_IS_EMPTY);
442 SQL_FREERESULT($result);