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"))) {
38 addFatalMessage(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "sponsor");
42 // Add description as navigation point
43 ADD_DESCR("guest", __FILE__);
45 // Create array for form errors (= missing data)
46 $FORM_ERRORS = array();
48 if (isset($_POST['ok'])) {
50 // Check submitted form data
52 // 1. Salutation / Surname / family name
53 if (empty($_POST['gender'])) {
55 $FORM_ERRORS[] = SPONSOR_NO_GENDER_SELECTED;
58 if (empty($_POST['surname'])) {
60 $FORM_ERRORS[] = SPONSOR_SURNAME_IS_EMPTY;
63 if (empty($_POST['family'])) {
65 $FORM_ERRORS[] = SPONSOR_FAMILY_IS_EMPTY;
69 // 012 3 32 23 4 43 3 4 4321 12 3 32 2 3 3210
70 if (((empty($_POST['company'])) && ((!empty($_POST['tax_ident'])) || (!empty($_POST['position'])))) || ((!empty($_POST['company'])) && (empty($_POST['tax_ident'])))) {
71 if (empty($_POST['company'])) {
72 // Company name is empty
73 $FORM_ERRORS[] = SPONSOR_COMPANY_IS_EMPTY;
74 } elseif (empty($_POST['tax_ident'])) {
75 // Tax ident number name is empty
76 $FORM_ERRORS[] = SPONSOR_TAX_IDENT_IS_EMPTY;
79 if (empty($_POST['position'])) {
80 // Not fatal but not nice: position in company is empty
81 $FORM_ERRORS[] = SPONSOR_POSITION_IS_EMPTY;
85 // 3. Street and number
86 if (empty($_POST['street_nr1'])) {
87 // Street name and house number are empty
88 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY;
89 } elseif ((!empty($_POST['street_nr2'])) && (empty($_POST['street_nr1']))) {
90 // 1st line for street is empty, but 2nd line not
91 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY_2_NOT;
95 if (empty($_POST['country'])) {
96 // Country code is empty
97 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_EMPTY;
98 } elseif (strlen($_POST['country']) != 2) {
99 // Country code is invalid
100 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_INVALID;
104 if (empty($_POST['zip'])) {
106 $FORM_ERRORS[] = SPONSOR_ZIP_IS_EMPTY;
107 } elseif (bigintval($_POST['zip']) != $_POST['zip']) {
109 $FORM_ERRORS[] = SPONSOR_ZIP_IS_INVALID;
114 if (empty($_POST['city'])) {
116 $FORM_ERRORS[] = SPONSOR_CITY_IS_EMPTY;
120 if (empty($_POST['phone'])) {
122 $FORM_ERRORS[] = SPONSOR_PHONE_IS_EMPTY;
126 if (empty($_POST['url'])) {
127 // Homepage URL is empty
128 $FORM_ERRORS[] = SPONSOR_URL_IS_EMPTY;
129 } elseif (!VALIDATE_URL($_POST['url'])) {
130 // Homepage URL is invalid
131 $FORM_ERRORS[] = SPONSOR_URL_IS_INVALID;
135 // 7. Light validation of email address
136 if ((empty($_POST['email'])) || ($_POST['email'] == "@")) {
137 // Email is invalid/empty
138 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_INVALID;
139 } elseif (SPONSOR_FOUND_EMAIL_DB($_POST['email'])) {
140 // Email already found in database!
141 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_ALREADY_REGISTERED;
142 $_POST['email'] = "";
144 // 8. Pay type selected?
145 if (empty($_POST['pay_type']))
147 // Not pay type selected
148 $FORM_ERRORS[] = SPONSOR_NO_PAYTYPE_SELECTED;
150 // 9. Interval of mails
151 if (empty($_POST['warning_interval']))
153 // No warning interval selected
154 $FORM_ERRORS[] = SPONSOR_NO_WARNING_INTERVAL_SELECTED;
156 // 10. Mail notifications disabled/enabled
157 if (empty($_POST['receive_warnings']))
159 // Option not selected!
160 $FORM_ERRORS[] = SPONSOR_NO_RECEIVE_WARNINGS_SELECTED;
162 // Did he enter his password twice?
163 if (((empty($_POST['pass1'])) || (empty($_POST['pass2']))) || (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2']))))
165 if (($_POST['pass1'] != $_POST['pass2']) && (!empty($_POST['pass1'])) && (!empty($_POST['pass2'])))
167 // Passwords missmatch
168 $FORM_ERRORS[] = SPONSOR_PASSWORDS_MISMATCH;
172 if (empty($_POST['pass1']))
174 // Password 1 is empty
175 $FORM_ERRORS[] = SPONSOR_PASSWORD1_EMPTY;
177 if (empty($_POST['pass2']))
179 // Password 2 is empty
180 $FORM_ERRORS[] = SPONSOR_PASSWORD2_EMPTY;
184 // Is the password long enough?
185 elseif (strlen($_POST['pass1']) < getConfig('pass_len'))
188 $FORM_ERRORS[] = SPONSOR_PASSWORD_TOO_SHORT;
191 // Check if he has accepted the terms&conditions
192 if (empty($_POST['terms'])) {
193 // Homepage URL is empty
194 $FORM_ERRORS[] = SPONSOR_TERMS_NOT_ACCEPTED;
197 // If there is something wrong/missing stop registration
198 if (count($FORM_ERRORS) > 0) unset($_POST['ok']);
201 if ((isset($_POST['ok'])) && (count($FORM_ERRORS) == 0)) {
202 // Generate message array
204 'failed' => SPONSOR_REGISTRATION_FAILED,
205 'added' => SPONSOR_REGISTRATION_COMPLETED,
209 $result = SQL_QUERY_ESC("SELECT (pay_rate * pay_min_count) AS points, pay_min_count AS pay, pay_currency AS curr
210 FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes`
211 WHERE id='%s' LIMIT 1", array($_POST['pay_type']), __FILE__, __LINE__);
212 list($points, $pay, $curr) = SQL_FETCHROW($result);
215 SQL_FREERESULT($result);
217 // Add points to array
218 $_POST['points_amount'] = $points;
219 $_POST['points_used'] = "0.00000";
220 $_POST['last_pay'] = $pay;
221 $_POST['last_curr'] = $curr;
223 // Register sponsor but never ever update here!
224 $STATUS = SPONSOR_HANDLE_SPONSOR($_POST, true, $MSGs, true);
226 // Check the status of the registration process
229 case "added": // Sponsor successfully added with account status = UNCONFIRMED!
230 // Check for his ID number
231 $result = SQL_QUERY_ESC("SELECT id, hash FROM `{!_MYSQL_PREFIX!}_sponsor_data` WHERE email='%s' LIMIT 1",
232 array($_POST['email']), __FILE__, __LINE__);
233 if (SQL_NUMROWS($result) == 1)
235 // ID found so let's load it for the confirmation email
236 list($id, $hash) = SQL_FETCHROW($result);
238 // Prepare data for the email template
239 define('__ID' , $id);
240 define('__HASH' , $hash);
241 define('__EMAIL' , $_POST['email']);
242 define('__SURNAME' , $_POST['surname']);
243 define('__FAMILY' , $_POST['family']);
244 define('__GENDER' , TRANSLATE_GENDER($_POST['gender']));
245 define('__TIMESTAMP', MAKE_DATETIME(time(), 0));
246 define('__PASSWORD' , $_POST['pass1']);
248 // Generate email and send it to the new sponsor
249 $EMAIL_MSG = LOAD_EMAIL_TEMPLATE("sponsor_confirm", $hash);
250 SEND_EMAIL($_POST['email'], SPONSOR_PLEASE_CONFIRM_SUBJ, $EMAIL_MSG);
252 // Send mail to admin
253 SEND_ADMIN_NOTIFICATION(ADMIN_NEW_SPONSOR, "admin_sponsor_reg", $hash);
255 // Output message: DONE
256 $MSG = $MSGs['added'];
260 // Sponsor account not found???
261 $MSG = SPONSOR_EMAIL_404_1.$_POST['email'].SPONSOR_EMAIL_404_2;
265 SQL_FREERESULT($result);
269 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $STATUS));
271 // Message for testing admin
272 $MSG = ADMIN_SPONSOR_UNKOWN_STATUS_1.$STATUS.ADMIN_SPONSOR_UNKOWN_STATUS_2;
274 // Message for the guest
275 $MSG = SPONSOR_UNKOWN_STATUS_1.$STATUS.SPONSOR_UNKOWN_STATUS_2;
281 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
283 // Check for payment types
284 $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_currency, pay_min_count
285 FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes`
286 ORDER BY pay_name", __FILE__, __LINE__);
287 if (SQL_NUMROWS($result) > 0) {
289 $OUT = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
291 while (list($id, $name, $rate, $curr, $min) = SQL_FETCHROW($result))
294 <td class=\"bottom2 switch_sw".$SW."\" height=\"50\" style=\"padding-left: 2px; padding-right: 2px\">
295 <input type=\"radio\" name=\"pay_type\" class=\"guest_normal\" value=\"".bigintval($id)."\" /> ".$name."<br />
296 <div align=\"right\">(".$min." ".$curr." = ".TRANSLATE_COMMA($rate * $min)." {!POINTS!})</div>
301 $OUT .= "</table>\n";
302 define('__PAYMENT_LIST', $OUT);
303 SQL_FREERESULT($result);
305 // Check for invalid entries
306 if (count($FORM_ERRORS) > 0)
309 define('__COMPANY' , COMPILE_CODE($_POST['company']));
310 define('__POSITION' , COMPILE_CODE($_POST['position']));
311 define('__TAX_IDENT', COMPILE_CODE($_POST['tax_ident']));
312 define('__SURNAME' , COMPILE_CODE($_POST['surname']));
313 define('__FAMILY' , COMPILE_CODE($_POST['family']));
314 define('__STREET1' , COMPILE_CODE($_POST['street_nr1']));
315 define('__STREET2' , COMPILE_CODE($_POST['street_nr2']));
316 define('__COUNTRY' , COMPILE_CODE($_POST['country']));
317 define('__ZIP' , COMPILE_CODE($_POST['zip']));
318 define('__CITY' , COMPILE_CODE($_POST['city']));
319 define('__PHONE' , COMPILE_CODE($_POST['phone']));
320 define('__FAX' , COMPILE_CODE($_POST['fax']));
321 define('__CELL' , COMPILE_CODE($_POST['cell']));
322 define('__EMAIL' , COMPILE_CODE($_POST['email']));
323 define('__URL' , COMPILE_CODE($_POST['url']));
325 // Check for gender selection
326 switch ($_POST['gender'])
329 define('__GENDER_M' , " selected=\"selected\"");
330 define('__GENDER_F' , "");
331 define('__GENDER_C' , "");
335 define('__GENDER_M' , "");
336 define('__GENDER_F' , " selected=\"selected\"");
337 define('__GENDER_C' , "");
341 define('__GENDER_M' , "");
342 define('__GENDER_F' , "");
343 define('__GENDER_C' , " selected=\"selected\"");
347 // Check for receive_warnings
348 switch ($_POST['receive_warnings'])
351 define('__REC_Y' , " selected=\"selected\"");
352 define('__REC_N' , "");
356 define('__REC_Y' , "");
357 define('__REC_N' , " selected=\"selected\"");
362 $OUT = "<P align=\"center\">
363 <strong><div class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</div></strong><br />
366 foreach ($FORM_ERRORS as $error) {
367 $OUT .= "<li>".$error."</li>\n";
370 $OUT .= "</ol><br />\n";
371 define('__SPONSOR_FORM_ERRORS', $OUT);
372 define('__SPONSOR_REFID', $_POST['refid']);
374 // None found, first call
375 define('__COMPANY' , "");
376 define('__POSITION' , "");
377 define('__TAX_IDENT', "");
378 define('__GENDER_M' , "");
379 define('__GENDER_F' , "");
380 define('__GENDER_C' , "");
381 define('__SURNAME' , "");
382 define('__FAMILY' , "");
383 define('__STREET1' , "");
384 define('__STREET2' , "");
385 define('__COUNTRY' , "");
386 define('__ZIP' , "");
387 define('__CITY' , "");
388 define('__PHONE' , "");
389 define('__FAX' , "");
390 define('__CELL' , "");
391 define('__EMAIL' , "");
392 define('__URL' , "");
393 define('__REC_Y' , "");
394 define('__REC_N' , "");
396 // No errors found so far
397 define('__SPONSOR_FORM_ERRORS', "");
400 // Prepare referal things
401 if (!isset($_GET['refid'])) {
403 define('__SPONSOR_REFID', "0");
405 // Referal ID transmitted, we don't care here if it is right or not
406 define('__SPONSOR_REFID', bigintval($_GET['refid']));
409 // Display registration form
410 LOAD_TEMPLATE("guest_sponsor_reg");
412 // Nothing added so far
413 LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_PAYMENT_LIST_IS_EMPTY);
417 SQL_FREERESULT($result);