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']))
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
40 // Add description as navigation point
41 ADD_DESCR("guest", basename(__FILE__));
43 // Create array for form errors (= missing data)
44 $FORM_ERRORS = array();
46 if (isset($HTTP_POST_VARS['ok']))
49 // Check submitted form data
51 // 1. Salutation / Surname / family name
52 if (empty($HTTP_POST_VARS['salut']))
55 $FORM_ERRORS[] = SPONSOR_NO_SALUT_SELECTED;
57 if (empty($HTTP_POST_VARS['surname']))
60 $FORM_ERRORS[] = SPONSOR_SURNAME_IS_EMPTY;
62 if (empty($HTTP_POST_VARS['family']))
65 $FORM_ERRORS[] = SPONSOR_FAMILY_IS_EMPTY;
68 // 012 3 32 23 4 43 3 4 4321 12 3 32 2 3 3210
69 if (((empty($HTTP_POST_VARS['company'])) && ((!empty($HTTP_POST_VARS['tax_ident'])) || (!empty($HTTP_POST_VARS['position'])))) || ((!empty($HTTP_POST_VARS['company'])) && (empty($HTTP_POST_VARS['tax_ident']))))
71 if (empty($HTTP_POST_VARS['company']))
73 // Company name is empty
74 $FORM_ERRORS[] = SPONSOR_COMPANY_IS_EMPTY;
76 elseif (empty($HTTP_POST_VARS['tax_ident']))
78 // Tax ident number name is empty
79 $FORM_ERRORS[] = SPONSOR_TAX_IDENT_IS_EMPTY;
81 if (empty($HTTP_POST_VARS['position']))
83 // Not fatal but not nice: position in company is empty
84 $FORM_ERRORS[] = SPONSOR_POSITION_IS_EMPTY;
87 // 3. Street and number
88 if (empty($HTTP_POST_VARS['street_nr1']))
90 // Street name and house number are empty
91 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY;
93 elseif ((!empty($HTTP_POST_VARS['street_nr2'])) && (empty($HTTP_POST_VARS['street_nr1'])))
95 // 1st line for street is empty, but 2nd line not
96 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY_2_NOT;
99 if (empty($HTTP_POST_VARS['country']))
101 // Country code is empty
102 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_EMPTY;
104 elseif (strlen($HTTP_POST_VARS['country']) != 2)
106 // Country code is invalid
107 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_INVALID;
110 if (empty($HTTP_POST_VARS['zip']))
113 $FORM_ERRORS[] = SPONSOR_ZIP_IS_EMPTY;
115 elseif (bigintval($HTTP_POST_VARS['zip']) != $HTTP_POST_VARS['zip'])
118 $FORM_ERRORS[] = SPONSOR_ZIP_IS_INVALID;
119 $HTTP_POST_VARS['zip'] = "";
122 if (empty($HTTP_POST_VARS['city']))
125 $FORM_ERRORS[] = SPONSOR_CITY_IS_EMPTY;
128 if (empty($HTTP_POST_VARS['phone']))
131 $FORM_ERRORS[] = SPONSOR_PHONE_IS_EMPTY;
134 if (empty($HTTP_POST_VARS['url']))
136 // Homepage URL is empty
137 $FORM_ERRORS[] = SPONSOR_URL_IS_EMPTY;
139 elseif (!VALIDATE_URL($HTTP_POST_VARS['url']))
141 // Homepage URL is invalid
142 $FORM_ERRORS[] = SPONSOR_URL_IS_INVALID;
143 $HTTP_POST_VARS['url'] = "";
145 // 7. Light validation of email address
146 if ((empty($HTTP_POST_VARS['email'])) || ($HTTP_POST_VARS['email'] == "@"))
148 // Email is invalid/empty
149 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_INVALID;
151 elseif (SPONSOR_FOUND_EMAIL_DB($HTTP_POST_VARS['email']))
153 // Email already found in database!
154 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_ALREADY_REGISTERED;
155 $HTTP_POST_VARS['email'] = "";
157 // 8. Pay type selected?
158 if (empty($HTTP_POST_VARS['pay_type']))
160 // Not pay type selected
161 $FORM_ERRORS[] = SPONSOR_NO_PAYTYPE_SELECTED;
163 // 9. Interval of mails
164 if (empty($HTTP_POST_VARS['warning_interval']))
166 // No warning interval selected
167 $FORM_ERRORS[] = SPONSOR_NO_WARNING_INTERVAL_SELECTED;
169 // 10. Mail notifications disabled/enabled
170 if (empty($HTTP_POST_VARS['receive_warnings']))
172 // Option not selected!
173 $FORM_ERRORS[] = SPONSOR_NO_RECEIVE_WARNINGS_SELECTED;
175 // Did he enter his password twice?
176 if (((empty($HTTP_POST_VARS['pass1'])) || (empty($HTTP_POST_VARS['pass2']))) || (($HTTP_POST_VARS['pass1'] != $HTTP_POST_VARS['pass2']) && (!empty($HTTP_POST_VARS['pass1'])) && (!empty($HTTP_POST_VARS['pass2']))))
178 if (($HTTP_POST_VARS['pass1'] != $HTTP_POST_VARS['pass2']) && (!empty($HTTP_POST_VARS['pass1'])) && (!empty($HTTP_POST_VARS['pass2'])))
180 // Passwords missmatch
181 $FORM_ERRORS[] = SPONSOR_PASSWORDS_MISMATCH;
185 if (empty($HTTP_POST_VARS['pass1']))
187 // Password 1 is empty
188 $FORM_ERRORS[] = SPONSOR_PASSWORD1_EMPTY;
190 if (empty($HTTP_POST_VARS['pass2']))
192 // Password 2 is empty
193 $FORM_ERRORS[] = SPONSOR_PASSWORD2_EMPTY;
197 // Is the password long enough?
198 elseif (strlen($HTTP_POST_VARS['pass1']) < $CONFIG['pass_len'])
201 $FORM_ERRORS[] = SPONSOR_PASSWORD_TOO_SHORT;
204 // Check if he has accepted the terms&conditions
205 if (empty($HTTP_POST_VARS['terms']))
207 // Homepage URL is empty
208 $FORM_ERRORS[] = SPONSOR_TERMS_NOT_ACCEPTED;
211 // If there is something wrong/missing stop registration
212 if (count($FORM_ERRORS) > 0) unset($HTTP_POST_VARS['ok']);
215 if ((isset($HTTP_POST_VARS['ok'])) && (count($FORM_ERRORS) == 0))
217 // Generate message array
219 'failed' => SPONSOR_REGISTRATION_FAILED,
220 'added' => SPONSOR_REGISTRATION_COMPLETED,
224 $result = SQL_QUERY_ESC("SELECT (pay_rate * pay_min_count) AS points, pay_min_count AS pay, pay_currency AS curr
225 FROM "._MYSQL_PREFIX."_sponsor_paytypes
226 WHERE id='%s' LIMIT 1", array($HTTP_POST_VARS['pay_type']), __FILE__, __LINE__);
227 list($points, $pay, $curr) = SQL_FETCHROW($result);
230 SQL_FREERESULT($result);
232 // Add points to array
233 $HTTP_POST_VARS['points_amount'] = $points;
234 $HTTP_POST_VARS['points_used'] = "0.00000";
235 $HTTP_POST_VARS['last_pay'] = $pay;
236 $HTTP_POST_VARS['last_curr'] = $curr;
238 // Register sponsor but never ever update here!
239 $STATUS = SPONSOR_HANDLE_SPONSOR($HTTP_POST_VARS, true, $MSGs, true);
241 // Check the status of the registration process
244 case "added": // Sponsor successfully added with account status = UNCONFIRMED!
245 // Check for his ID number
246 $result = SQL_QUERY_ESC("SELECT id, hash FROM "._MYSQL_PREFIX."_sponsor_data WHERE email='%s' LIMIT 1",
247 array($HTTP_POST_VARS['email']), __FILE__, __LINE__);
248 if (SQL_NUMROWS($result) == 1)
250 // ID found so let's load it for the confirmation email
251 list($id, $hash) = SQL_FETCHROW($result);
253 // Prepare data for the email template
254 define('__ID' , $id);
255 define('__HASH' , $hash);
256 define('__EMAIL' , $HTTP_POST_VARS['email']);
257 define('__SURNAME' , $HTTP_POST_VARS['surname']);
258 define('__FAMILY' , $HTTP_POST_VARS['family']);
259 define('__SALUT' , TRANSLATE_SEX($HTTP_POST_VARS['salut']));
260 define('__TIMESTAMP', MAKE_DATETIME(time(), 0));
261 define('__PASSWORD' , $HTTP_POST_VARS['pass1']);
263 // Generate email and send it to the new sponsor
264 $EMAIL_MSG = LOAD_EMAIL_TEMPLATE("sponsor_confirm", $hash);
265 SEND_EMAIL($HTTP_POST_VARS['email'], SPONSOR_PLEASE_CONFIRM_SUBJ, $EMAIL_MSG);
267 // Send mail to admin
268 if (GET_EXT_VERSION("admins") >= "0.4.1")
271 SEND_ADMIN_EMAILS_PRO(ADMIN_NEW_SPONSOR, "admin_sponsor_reg", $hash);
275 // Send over old system
276 $msg_admin = LOAD_EMAIL_TEMPLATE("admin_sponsor_reg", $hash);
277 SEND_ADMIN_EMAILS (ADMIN_NEW_SPONSOR, $msg_admin);
280 // Output message: DONE
281 $MSG = $MSGs['added'];
285 // Sponsor account not found???
286 $MSG = SPONSOR_EMAIL_404_1.$HTTP_POST_VARS['email'].SPONSOR_EMAIL_404_2;
290 SQL_FREERESULT($result);
296 // Message for testing admin
297 $MSG = ADMIN_SPONSOR_UNKOWN_STATUS_1.$STATUS.ADMIN_SPONSOR_UNKOWN_STATUS_2;
301 // Message for the guest
302 $MSG = SPONSOR_UNKOWN_STATUS_1.$STATUS.SPONSOR_UNKOWN_STATUS_2;
308 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
312 // Check for payment types
313 $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_currency, pay_min_count
314 FROM "._MYSQL_PREFIX."_sponsor_paytypes
315 ORDER BY pay_name", __FILE__, __LINE__);
316 if (SQL_NUMROWS($result) > 0)
319 $OUT = "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
321 while(list($id, $name, $rate, $curr, $min) = SQL_FETCHROW($result))
324 <TD class=\"bottom2 switch_sw".$SW."\" height=\"50\" style=\"padding-left: 2px; padding-right: 2px\">
325 <INPUT type=\"radio\" name=\"pay_type\" class=\"guest_normal\" value=\"".bigintval($id)."\"> ".$name."<BR>
326 <DIV align=\"right\">(".$min." ".$curr." = ".TRANSLATE_COMMA($rate * $min)." ".POINTS.")</DIV>
331 $OUT .= "</TABLE>\n";
332 define('__PAYMENT_LIST', $OUT);
333 SQL_FREERESULT($result);
335 // Check for invalid entries
336 if (count($FORM_ERRORS) > 0)
339 define('__COMPANY' , COMPILE_CODE($HTTP_POST_VARS['company']));
340 define('__POSITION' , COMPILE_CODE($HTTP_POST_VARS['position']));
341 define('__TAX_IDENT', COMPILE_CODE($HTTP_POST_VARS['tax_ident']));
342 define('__SURNAME' , COMPILE_CODE($HTTP_POST_VARS['surname']));
343 define('__FAMILY' , COMPILE_CODE($HTTP_POST_VARS['family']));
344 define('__STREET1' , COMPILE_CODE($HTTP_POST_VARS['street_nr1']));
345 define('__STREET2' , COMPILE_CODE($HTTP_POST_VARS['street_nr2']));
346 define('__COUNTRY' , COMPILE_CODE($HTTP_POST_VARS['country']));
347 define('__ZIP' , COMPILE_CODE($HTTP_POST_VARS['zip']));
348 define('__CITY' , COMPILE_CODE($HTTP_POST_VARS['city']));
349 define('__PHONE' , COMPILE_CODE($HTTP_POST_VARS['phone']));
350 define('__FAX' , COMPILE_CODE($HTTP_POST_VARS['fax']));
351 define('__CELL' , COMPILE_CODE($HTTP_POST_VARS['cell']));
352 define('__EMAIL' , COMPILE_CODE($HTTP_POST_VARS['email']));
353 define('__URL' , COMPILE_CODE($HTTP_POST_VARS['url']));
355 // Check for salutation selection
356 switch ($HTTP_POST_VARS['salut'])
359 define('__SALUT_M' , " selected");
360 define('__SALUT_F' , "");
361 define('__SALUT_C' , "");
365 define('__SALUT_M' , "");
366 define('__SALUT_F' , " selected");
367 define('__SALUT_C' , "");
371 define('__SALUT_M' , "");
372 define('__SALUT_F' , "");
373 define('__SALUT_C' , " selected");
377 // Check for receive_warnings
378 switch ($HTTP_POST_VARS['receive_warnings'])
381 define('__REC_Y' , " selected");
382 define('__REC_N' , "");
386 define('__REC_Y' , "");
387 define('__REC_N' , " selected");
392 $OUT = "<P align=\"center\">
393 <STRONG><FONT class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</FONT></STRONG><BR>
396 foreach ($FORM_ERRORS as $error)
398 $OUT .= "<LI>".$error."</LI>\n";
400 $OUT .= "</OL><BR>\n";
401 define('__SPONSOR_FORM_ERRORS', $OUT);
402 define('__SPONSOR_REFID', $HTTP_POST_VARS['refid']);
406 // None found, first call
407 define('__COMPANY' , "");
408 define('__POSITION' , "");
409 define('__TAX_IDENT', "");
410 define('__SALUT_M' , "");
411 define('__SALUT_F' , "");
412 define('__SALUT_C' , "");
413 define('__SURNAME' , "");
414 define('__FAMILY' , "");
415 define('__STREET1' , "");
416 define('__STREET2' , "");
417 define('__COUNTRY' , "");
418 define('__ZIP' , "");
419 define('__CITY' , "");
420 define('__PHONE' , "");
421 define('__FAX' , "");
422 define('__CELL' , "");
423 define('__EMAIL' , "");
424 define('__URL' , "");
425 define('__REC_Y' , "");
426 define('__REC_N' , "");
428 // No errors found so far
429 define('__SPONSOR_FORM_ERRORS', "");
432 // Prepare referral things
433 if (!isset($HTTP_GET_VARS['refid']))
436 define('__SPONSOR_REFID', "0");
440 // Referral ID transmitted, we don't care here if it is right or not
441 define('__SPONSOR_REFID', $HTTP_GET_VARS['refid']);
444 // Display registration form
445 LOAD_TEMPLATE("guest_sponsor_reg");
449 // Nothing added so far
450 LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_PAYMENT_LIST_IS_EMPTY);
454 SQL_FREERESULT($result);