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[] = getMessage('SPONSOR_NO_GENDER_SELECTED');
58 if (empty($_POST['surname'])) {
60 $FORM_ERRORS[] = getMessage('SPONSOR_SURNAME_IS_EMPTY');
63 if (empty($_POST['family'])) {
65 $FORM_ERRORS[] = getMessage('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[] = getMessage('SPONSOR_COMPANY_IS_EMPTY');
74 } elseif (empty($_POST['tax_ident'])) {
75 // Tax ident number name is empty
76 $FORM_ERRORS[] = getMessage('SPONSOR_TAX_IDENT_IS_EMPTY');
79 if (empty($_POST['position'])) {
80 // Not fatal but not nice: position in company is empty
81 $FORM_ERRORS[] = getMessage('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[] = getMessage('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[] = getMessage('SPONSOR_STREET_NR1_IS_EMPTY_2_NOT');
95 if (empty($_POST['country'])) {
96 // Country code is empty
97 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_EMPTY');
98 } elseif (strlen($_POST['country']) != 2) {
99 // Country code is invalid
100 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_INVALID');
104 if (empty($_POST['zip'])) {
106 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_EMPTY');
107 } elseif (bigintval($_POST['zip']) != $_POST['zip']) {
109 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_INVALID');
114 if (empty($_POST['city'])) {
116 $FORM_ERRORS[] = getMessage('SPONSOR_CITY_IS_EMPTY');
120 if (empty($_POST['phone'])) {
122 $FORM_ERRORS[] = getMessage('SPONSOR_PHONE_IS_EMPTY');
126 if (empty($_POST['url'])) {
127 // Homepage URL is empty
128 $FORM_ERRORS[] = getMessage('SPONSOR_URL_IS_EMPTY');
129 } elseif (!VALIDATE_URL($_POST['url'])) {
130 // Homepage URL is invalid
131 $FORM_ERRORS[] = getMessage('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[] = getMessage('SPONSOR_EMAIL_IS_INVALID');
139 } elseif (SPONSOR_FOUND_EMAIL_DB($_POST['email'])) {
140 // Email already found in database!
141 $FORM_ERRORS[] = getMessage('SPONSOR_EMAIL_IS_ALREADY_REGISTERED');
142 $_POST['email'] = "";
145 // 8. Pay type selected?
146 if (empty($_POST['pay_type'])) {
147 // Not pay type selected
148 $FORM_ERRORS[] = getMessage('SPONSOR_NO_PAYTYPE_SELECTED');
151 // 9. Interval of mails
152 if (empty($_POST['warning_interval'])) {
153 // No warning interval selected
154 $FORM_ERRORS[] = getMessage('SPONSOR_NO_WARNING_INTERVAL_SELECTED');
157 // 10. Mail notifications disabled/enabled
158 if (empty($_POST['receive_warnings'])) {
159 // Option not selected!
160 $FORM_ERRORS[] = getMessage('SPONSOR_NO_RECEIVE_WARNINGS_SELECTED');
163 // Did he enter his password twice?
164 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']))) {
166 // Passwords missmatch
167 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORDS_MISMATCH');
169 if (empty($_POST['pass1'])) {
170 // Password 1 is empty
171 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD1_EMPTY');
174 if (empty($_POST['pass2'])) {
175 // Password 2 is empty
176 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD2_EMPTY');
179 } elseif (strlen($_POST['pass1']) < getConfig('pass_len')) {
180 // Password is to short!
181 $FORM_ERRORS[] = sprintf(getMessage('SPONSOR_PASSWORD_TOO_SHORT'), getConfig('pass_len'));
184 // Check if he has accepted the terms&conditions
185 if (empty($_POST['terms'])) {
186 // Homepage URL is empty
187 $FORM_ERRORS[] = getMessage('SPONSOR_TERMS_NOT_ACCEPTED');
190 // If there is something wrong/missing stop registration
191 if (count($FORM_ERRORS) > 0) unset($_POST['ok']);
194 if ((isset($_POST['ok'])) && (count($FORM_ERRORS) == 0)) {
195 // Generate message array
197 'failed' => getMessage('SPONSOR_REGISTRATION_FAILED'),
198 'added' => getMessage('SPONSOR_REGISTRATION_COMPLETED'),
202 $result = SQL_QUERY_ESC("SELECT (pay_rate * pay_min_count) AS points, pay_min_count AS pay, pay_currency AS curr
203 FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes`
204 WHERE id='%s' LIMIT 1", array($_POST['pay_type']), __FILE__, __LINE__);
205 list($points, $pay, $curr) = SQL_FETCHROW($result);
208 SQL_FREERESULT($result);
210 // Add points to array
211 $_POST['points_amount'] = $points;
212 $_POST['points_used'] = "0.00000";
213 $_POST['last_pay'] = $pay;
214 $_POST['last_curr'] = $curr;
216 // Register sponsor but never ever update here!
217 $STATUS = SPONSOR_HANDLE_SPONSOR($_POST, true, $MSGs, true);
219 // Check the status of the registration process
222 case "added": // Sponsor successfully added with account status = UNCONFIRMED!
223 // Check for his ID number
224 $result = SQL_QUERY_ESC("SELECT id, hash FROM `{!_MYSQL_PREFIX!}_sponsor_data` WHERE email='%s' LIMIT 1",
225 array($_POST['email']), __FILE__, __LINE__);
226 if (SQL_NUMROWS($result) == 1) {
227 // ID found so let's load it for the confirmation email
228 list($id, $hash) = SQL_FETCHROW($result);
230 // Prepare data for the email template
231 define('__ID' , $id);
232 define('__HASH' , $hash);
233 define('__EMAIL' , $_POST['email']);
234 define('__SURNAME' , $_POST['surname']);
235 define('__FAMILY' , $_POST['family']);
236 define('__GENDER' , TRANSLATE_GENDER($_POST['gender']));
237 define('__TIMESTAMP', MAKE_DATETIME(time(), 0));
238 define('__PASSWORD' , $_POST['pass1']);
240 // Generate email and send it to the new sponsor
241 $EMAIL_MSG = LOAD_EMAIL_TEMPLATE("sponsor_confirm", $hash);
242 SEND_EMAIL($_POST['email'], getMessage('SPONSOR_PLEASE_CONFIRM_SUBJ'), $EMAIL_MSG);
244 // Send mail to admin
245 SEND_ADMIN_NOTIFICATION(getMessage('ADMIN_NEW_SPONSOR'), "admin_sponsor_reg", $hash);
247 // Output message: DONE
248 $MSG = $MSGs['added'];
250 // Sponsor account not found???
251 $MSG = sprintf(getMessage('SPONSOR_EMAIL_404'), $_POST['email']);
255 SQL_FREERESULT($result);
259 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $STATUS));
261 // Message for testing admin
262 $MSG = sprintf(getMessage('ADMIN_SPONSOR_UNKNOWN_STATUS'), $STATUS);
264 // Message for the guest
265 $MSG = sprintf(getMessage('SPONSOR_UNKNOWN_STATUS'), $STATUS);
271 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
273 // Check for payment types
274 $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_currency, pay_min_count
275 FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes`
276 ORDER BY pay_name", __FILE__, __LINE__);
277 if (SQL_NUMROWS($result) > 0) {
279 // @TODO Swap this HTML code to templates
280 $OUT = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
282 while (list($id, $name, $rate, $curr, $min) = SQL_FETCHROW($result)) {
284 <td class=\"bottom2 switch_sw".$SW."\" height=\"50\" style=\"padding-left: 2px; padding-right: 2px\">
285 <input type=\"radio\" name=\"pay_type\" class=\"guest_normal\" value=\"".bigintval($id)."\" /> ".$name."<br />
286 <div align=\"right\">(".$min." ".$curr." = ".TRANSLATE_COMMA($rate * $min)." {!POINTS!})</div>
291 $OUT .= "</table>\n";
292 define('__PAYMENT_LIST', $OUT);
293 SQL_FREERESULT($result);
295 // Check for invalid entries
296 if (count($FORM_ERRORS) > 0)
299 define('__COMPANY' , COMPILE_CODE($_POST['company']));
300 define('__POSITION' , COMPILE_CODE($_POST['position']));
301 define('__TAX_IDENT', COMPILE_CODE($_POST['tax_ident']));
302 define('__SURNAME' , COMPILE_CODE($_POST['surname']));
303 define('__FAMILY' , COMPILE_CODE($_POST['family']));
304 define('__STREET1' , COMPILE_CODE($_POST['street_nr1']));
305 define('__STREET2' , COMPILE_CODE($_POST['street_nr2']));
306 define('__COUNTRY' , COMPILE_CODE($_POST['country']));
307 define('__ZIP' , COMPILE_CODE($_POST['zip']));
308 define('__CITY' , COMPILE_CODE($_POST['city']));
309 define('__PHONE' , COMPILE_CODE($_POST['phone']));
310 define('__FAX' , COMPILE_CODE($_POST['fax']));
311 define('__CELL' , COMPILE_CODE($_POST['cell']));
312 define('__EMAIL' , COMPILE_CODE($_POST['email']));
313 define('__URL' , COMPILE_CODE($_POST['url']));
315 // Check for gender selection
316 switch ($_POST['gender'])
319 define('__GENDER_M' , " selected=\"selected\"");
320 define('__GENDER_F' , "");
321 define('__GENDER_C' , "");
325 define('__GENDER_M' , "");
326 define('__GENDER_F' , " selected=\"selected\"");
327 define('__GENDER_C' , "");
331 define('__GENDER_M' , "");
332 define('__GENDER_F' , "");
333 define('__GENDER_C' , " selected=\"selected\"");
337 // Check for receive_warnings
338 switch ($_POST['receive_warnings'])
341 define('__REC_Y' , " selected=\"selected\"");
342 define('__REC_N' , "");
346 define('__REC_Y' , "");
347 define('__REC_N' , " selected=\"selected\"");
352 $OUT = "<P align=\"center\">
353 <strong><div class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</div></strong><br />
356 foreach ($FORM_ERRORS as $error) {
357 $OUT .= "<li>".$error."</li>\n";
360 $OUT .= "</ol><br />\n";
361 define('__SPONSOR_FORM_ERRORS', $OUT);
362 define('__SPONSOR_REFID', $_POST['refid']);
364 // None found, first call
365 define('__COMPANY' , "");
366 define('__POSITION' , "");
367 define('__TAX_IDENT', "");
368 define('__GENDER_M' , "");
369 define('__GENDER_F' , "");
370 define('__GENDER_C' , "");
371 define('__SURNAME' , "");
372 define('__FAMILY' , "");
373 define('__STREET1' , "");
374 define('__STREET2' , "");
375 define('__COUNTRY' , "");
376 define('__ZIP' , "");
377 define('__CITY' , "");
378 define('__PHONE' , "");
379 define('__FAX' , "");
380 define('__CELL' , "");
381 define('__EMAIL' , "");
382 define('__URL' , "");
383 define('__REC_Y' , "");
384 define('__REC_N' , "");
386 // No errors found so far
387 define('__SPONSOR_FORM_ERRORS', "");
390 // Prepare referal things
391 if (!isset($_GET['refid'])) {
393 define('__SPONSOR_REFID', "0");
395 // Referal ID transmitted, we don't care here if it is right or not
396 define('__SPONSOR_REFID', bigintval($_GET['refid']));
399 // Display registration form
400 LOAD_TEMPLATE("guest_sponsor_reg");
402 // Nothing added so far
403 LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_PAYMENT_LIST_IS_EMPTY);
407 SQL_FREERESULT($result);