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 (!defined('__SECURITY')) {
35 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
37 } elseif ((!EXT_IS_ACTIVE("sponsor"))) {
39 addFatalMessage(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "sponsor"));
41 addFatalMessage(EXTENSION_PROBLEM_EXT_INACTIVE, "sponsor");
46 // Add description as navigation point
47 ADD_DESCR("guest", __FILE__);
49 // Create array for form errors (= missing data)
50 $FORM_ERRORS = array();
52 if (isset($_POST['ok'])) {
54 // Check submitted form data
56 // 1. Salutation / Surname / family name
57 if (empty($_POST['gender'])) {
59 $FORM_ERRORS[] = SPONSOR_NO_GENDER_SELECTED;
62 if (empty($_POST['surname'])) {
64 $FORM_ERRORS[] = SPONSOR_SURNAME_IS_EMPTY;
67 if (empty($_POST['family'])) {
69 $FORM_ERRORS[] = SPONSOR_FAMILY_IS_EMPTY;
73 // 012 3 32 23 4 43 3 4 4321 12 3 32 2 3 3210
74 if (((empty($_POST['company'])) && ((!empty($_POST['tax_ident'])) || (!empty($_POST['position'])))) || ((!empty($_POST['company'])) && (empty($_POST['tax_ident'])))) {
75 if (empty($_POST['company'])) {
76 // Company name is empty
77 $FORM_ERRORS[] = SPONSOR_COMPANY_IS_EMPTY;
78 } elseif (empty($_POST['tax_ident'])) {
79 // Tax ident number name is empty
80 $FORM_ERRORS[] = SPONSOR_TAX_IDENT_IS_EMPTY;
83 if (empty($_POST['position'])) {
84 // Not fatal but not nice: position in company is empty
85 $FORM_ERRORS[] = SPONSOR_POSITION_IS_EMPTY;
89 // 3. Street and number
90 if (empty($_POST['street_nr1'])) {
91 // Street name and house number are empty
92 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY;
93 } elseif ((!empty($_POST['street_nr2'])) && (empty($_POST['street_nr1']))) {
94 // 1st line for street is empty, but 2nd line not
95 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY_2_NOT;
99 if (empty($_POST['country'])) {
100 // Country code is empty
101 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_EMPTY;
102 } elseif (strlen($_POST['country']) != 2) {
103 // Country code is invalid
104 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_INVALID;
108 if (empty($_POST['zip'])) {
110 $FORM_ERRORS[] = SPONSOR_ZIP_IS_EMPTY;
111 } elseif (bigintval($_POST['zip']) != $_POST['zip']) {
113 $FORM_ERRORS[] = SPONSOR_ZIP_IS_INVALID;
118 if (empty($_POST['city'])) {
120 $FORM_ERRORS[] = SPONSOR_CITY_IS_EMPTY;
124 if (empty($_POST['phone'])) {
126 $FORM_ERRORS[] = SPONSOR_PHONE_IS_EMPTY;
130 if (empty($_POST['url'])) {
131 // Homepage URL is empty
132 $FORM_ERRORS[] = SPONSOR_URL_IS_EMPTY;
133 } elseif (!VALIDATE_URL($_POST['url'])) {
134 // Homepage URL is invalid
135 $FORM_ERRORS[] = SPONSOR_URL_IS_INVALID;
139 // 7. Light validation of email address
140 if ((empty($_POST['email'])) || ($_POST['email'] == "@")) {
141 // Email is invalid/empty
142 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_INVALID;
143 } elseif (SPONSOR_FOUND_EMAIL_DB($_POST['email'])) {
144 // Email already found in database!
145 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_ALREADY_REGISTERED;
146 $_POST['email'] = "";
148 // 8. Pay type selected?
149 if (empty($_POST['pay_type']))
151 // Not pay type selected
152 $FORM_ERRORS[] = SPONSOR_NO_PAYTYPE_SELECTED;
154 // 9. Interval of mails
155 if (empty($_POST['warning_interval']))
157 // No warning interval selected
158 $FORM_ERRORS[] = SPONSOR_NO_WARNING_INTERVAL_SELECTED;
160 // 10. Mail notifications disabled/enabled
161 if (empty($_POST['receive_warnings']))
163 // Option not selected!
164 $FORM_ERRORS[] = SPONSOR_NO_RECEIVE_WARNINGS_SELECTED;
166 // Did he enter his password twice?
167 if (((empty($_POST['pass1'])) || (empty($_POST['pass2']))) || (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2']))))
169 if (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2'])))
171 // Passwords missmatch
172 $FORM_ERRORS[] = SPONSOR_PASSWORDS_MISMATCH;
176 if (empty($_POST['pass1']))
178 // Password 1 is empty
179 $FORM_ERRORS[] = SPONSOR_PASSWORD1_EMPTY;
181 if (empty($_POST['pass2']))
183 // Password 2 is empty
184 $FORM_ERRORS[] = SPONSOR_PASSWORD2_EMPTY;
188 // Is the password long enough?
189 elseif (strlen($_POST['pass1']) < getConfig('pass_len'))
192 $FORM_ERRORS[] = SPONSOR_PASSWORD_TOO_SHORT;
195 // Check if he has accepted the terms&conditions
196 if (empty($_POST['terms'])) {
197 // Homepage URL is empty
198 $FORM_ERRORS[] = SPONSOR_TERMS_NOT_ACCEPTED;
201 // If there is something wrong/missing stop registration
202 if (count($FORM_ERRORS) > 0) unset($_POST['ok']);
205 if ((isset($_POST['ok'])) && (count($FORM_ERRORS) == 0)) {
206 // Generate message array
208 'failed' => SPONSOR_REGISTRATION_FAILED,
209 'added' => SPONSOR_REGISTRATION_COMPLETED,
213 $result = SQL_QUERY_ESC("SELECT (pay_rate * pay_min_count) AS points, pay_min_count AS pay, pay_currency AS curr
214 FROM "._MYSQL_PREFIX."_sponsor_paytypes
215 WHERE id='%s' LIMIT 1", array($_POST['pay_type']), __FILE__, __LINE__);
216 list($points, $pay, $curr) = SQL_FETCHROW($result);
219 SQL_FREERESULT($result);
221 // Add points to array
222 $_POST['points_amount'] = $points;
223 $_POST['points_used'] = "0.00000";
224 $_POST['last_pay'] = $pay;
225 $_POST['last_curr'] = $curr;
227 // Register sponsor but never ever update here!
228 $STATUS = SPONSOR_HANDLE_SPONSOR($_POST, true, $MSGs, true);
230 // Check the status of the registration process
233 case "added": // Sponsor successfully added with account status = UNCONFIRMED!
234 // Check for his ID number
235 $result = SQL_QUERY_ESC("SELECT id, hash FROM "._MYSQL_PREFIX."_sponsor_data WHERE email='%s' LIMIT 1",
236 array($_POST['email']), __FILE__, __LINE__);
237 if (SQL_NUMROWS($result) == 1)
239 // ID found so let's load it for the confirmation email
240 list($id, $hash) = SQL_FETCHROW($result);
242 // Prepare data for the email template
243 define('__ID' , $id);
244 define('__HASH' , $hash);
245 define('__EMAIL' , $_POST['email']);
246 define('__SURNAME' , $_POST['surname']);
247 define('__FAMILY' , $_POST['family']);
248 define('__GENDER' , TRANSLATE_GENDER($_POST['gender']));
249 define('__TIMESTAMP', MAKE_DATETIME(time(), 0));
250 define('__PASSWORD' , $_POST['pass1']);
252 // Generate email and send it to the new sponsor
253 $EMAIL_MSG = LOAD_EMAIL_TEMPLATE("sponsor_confirm", $hash);
254 SEND_EMAIL($_POST['email'], SPONSOR_PLEASE_CONFIRM_SUBJ, $EMAIL_MSG);
256 // Send mail to admin
257 SEND_ADMIN_NOTIFICATION(ADMIN_NEW_SPONSOR, "admin_sponsor_reg", $hash);
259 // Output message: DONE
260 $MSG = $MSGs['added'];
264 // Sponsor account not found???
265 $MSG = SPONSOR_EMAIL_404_1.$_POST['email'].SPONSOR_EMAIL_404_2;
269 SQL_FREERESULT($result);
273 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $STATUS));
275 // Message for testing admin
276 $MSG = ADMIN_SPONSOR_UNKOWN_STATUS_1.$STATUS.ADMIN_SPONSOR_UNKOWN_STATUS_2;
278 // Message for the guest
279 $MSG = SPONSOR_UNKOWN_STATUS_1.$STATUS.SPONSOR_UNKOWN_STATUS_2;
285 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
287 // Check for payment types
288 $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_currency, pay_min_count
289 FROM "._MYSQL_PREFIX."_sponsor_paytypes
290 ORDER BY pay_name", __FILE__, __LINE__);
291 if (SQL_NUMROWS($result) > 0) {
293 $OUT = "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
295 while(list($id, $name, $rate, $curr, $min) = SQL_FETCHROW($result))
298 <TD class=\"bottom2 switch_sw".$SW."\" height=\"50\" style=\"padding-left: 2px; padding-right: 2px\">
299 <INPUT type=\"radio\" name=\"pay_type\" class=\"guest_normal\" value=\"".bigintval($id)."\"> ".$name."<br />
300 <div align=\"right\">(".$min." ".$curr." = ".TRANSLATE_COMMA($rate * $min)." ".POINTS.")</div>
305 $OUT .= "</TABLE>\n";
306 define('__PAYMENT_LIST', $OUT);
307 SQL_FREERESULT($result);
309 // Check for invalid entries
310 if (count($FORM_ERRORS) > 0)
313 define('__COMPANY' , COMPILE_CODE($_POST['company']));
314 define('__POSITION' , COMPILE_CODE($_POST['position']));
315 define('__TAX_IDENT', COMPILE_CODE($_POST['tax_ident']));
316 define('__SURNAME' , COMPILE_CODE($_POST['surname']));
317 define('__FAMILY' , COMPILE_CODE($_POST['family']));
318 define('__STREET1' , COMPILE_CODE($_POST['street_nr1']));
319 define('__STREET2' , COMPILE_CODE($_POST['street_nr2']));
320 define('__COUNTRY' , COMPILE_CODE($_POST['country']));
321 define('__ZIP' , COMPILE_CODE($_POST['zip']));
322 define('__CITY' , COMPILE_CODE($_POST['city']));
323 define('__PHONE' , COMPILE_CODE($_POST['phone']));
324 define('__FAX' , COMPILE_CODE($_POST['fax']));
325 define('__CELL' , COMPILE_CODE($_POST['cell']));
326 define('__EMAIL' , COMPILE_CODE($_POST['email']));
327 define('__URL' , COMPILE_CODE($_POST['url']));
329 // Check for gender selection
330 switch ($_POST['gender'])
333 define('__GENDER_M' , " selected=\"selected\"");
334 define('__GENDER_F' , "");
335 define('__GENDER_C' , "");
339 define('__GENDER_M' , "");
340 define('__GENDER_F' , " selected=\"selected\"");
341 define('__GENDER_C' , "");
345 define('__GENDER_M' , "");
346 define('__GENDER_F' , "");
347 define('__GENDER_C' , " selected=\"selected\"");
351 // Check for receive_warnings
352 switch ($_POST['receive_warnings'])
355 define('__REC_Y' , " selected=\"selected\"");
356 define('__REC_N' , "");
360 define('__REC_Y' , "");
361 define('__REC_N' , " selected=\"selected\"");
366 $OUT = "<P align=\"center\">
367 <strong><div class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</div></strong><br />
370 foreach ($FORM_ERRORS as $error) {
371 $OUT .= "<li>".$error."</li>\n";
374 $OUT .= "</ol><br />\n";
375 define('__SPONSOR_FORM_ERRORS', $OUT);
376 define('__SPONSOR_REFID', $_POST['refid']);
378 // None found, first call
379 define('__COMPANY' , "");
380 define('__POSITION' , "");
381 define('__TAX_IDENT', "");
382 define('__GENDER_M' , "");
383 define('__GENDER_F' , "");
384 define('__GENDER_C' , "");
385 define('__SURNAME' , "");
386 define('__FAMILY' , "");
387 define('__STREET1' , "");
388 define('__STREET2' , "");
389 define('__COUNTRY' , "");
390 define('__ZIP' , "");
391 define('__CITY' , "");
392 define('__PHONE' , "");
393 define('__FAX' , "");
394 define('__CELL' , "");
395 define('__EMAIL' , "");
396 define('__URL' , "");
397 define('__REC_Y' , "");
398 define('__REC_N' , "");
400 // No errors found so far
401 define('__SPONSOR_FORM_ERRORS', "");
404 // Prepare referal things
405 if (!isset($_GET['refid'])) {
407 define('__SPONSOR_REFID', "0");
409 // Referal ID transmitted, we don't care here if it is right or not
410 define('__SPONSOR_REFID', bigintval($_GET['refid']));
413 // Display registration form
414 LOAD_TEMPLATE("guest_sponsor_reg");
416 // Nothing added so far
417 LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_PAYMENT_LIST_IS_EMPTY);
421 SQL_FREERESULT($result);