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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software. You can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42 } elseif ((!EXT_IS_ACTIVE('sponsor'))) {
43 addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('sponsor'));
47 // Add description as navigation point
48 ADD_DESCR('guest', __FILE__);
50 // Create array for form errors (= missing data)
51 $FORM_ERRORS = array();
55 // Check submitted form data
57 // 1. Salutation / Surname / family name
58 if (!REQUEST_ISSET_POST('gender')) {
60 $FORM_ERRORS[] = getMessage('SPONSOR_NO_GENDER_SELECTED');
63 if (!REQUEST_ISSET_POST('surname')) {
65 $FORM_ERRORS[] = getMessage('SPONSOR_SURNAME_IS_EMPTY');
68 if (!REQUEST_ISSET_POST('family')) {
70 $FORM_ERRORS[] = getMessage('SPONSOR_FAMILY_IS_EMPTY');
74 // 012 3 32 23 4 43 3 4 4321 12 3 32 2 3 3210
75 if (((!REQUEST_ISSET_POST('company')) && ((REQUEST_ISSET_POST('tax_ident')) || (REQUEST_ISSET_POST('position')))) || ((REQUEST_ISSET_POST('company')) && (!REQUEST_ISSET_POST('tax_ident')))) {
76 if (!REQUEST_ISSET_POST('company')) {
77 // Company name is empty
78 $FORM_ERRORS[] = getMessage('SPONSOR_COMPANY_IS_EMPTY');
79 } elseif (!REQUEST_ISSET_POST('tax_ident')) {
80 // Tax ident number name is empty
81 $FORM_ERRORS[] = getMessage('SPONSOR_TAX_IDENT_IS_EMPTY');
84 if (!REQUEST_ISSET_POST('position')) {
85 // Not fatal but not nice: position in company is empty
86 $FORM_ERRORS[] = getMessage('SPONSOR_POSITION_IS_EMPTY');
90 // 3. Street and number
91 if (!REQUEST_ISSET_POST('street_nr1')) {
92 // Street name and house number are empty
93 $FORM_ERRORS[] = getMessage('SPONSOR_STREET_NR1_IS_EMPTY');
94 } elseif ((REQUEST_ISSET_POST('street_nr2')) && (!REQUEST_ISSET_POST('street_nr1'))) {
95 // 1st line for street is empty, but 2nd line not
96 $FORM_ERRORS[] = getMessage('SPONSOR_STREET_NR1_IS_EMPTY_2_NOT');
100 if (!REQUEST_ISSET_POST('country')) {
101 // Country code is empty
102 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_EMPTY');
103 } elseif (strlen(REQUEST_POST('country')) != 2) {
104 // Country code is invalid
105 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_INVALID');
109 if (!REQUEST_ISSET_POST('zip')) {
111 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_EMPTY');
112 } elseif (bigintval(REQUEST_POST('zip')) != REQUEST_POST('zip')) {
114 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_INVALID');
115 REQUEST_SET_POST('zip', '');
119 if (!REQUEST_ISSET_POST('city')) {
121 $FORM_ERRORS[] = getMessage('SPONSOR_CITY_IS_EMPTY');
125 if (!REQUEST_ISSET_POST('phone')) {
127 $FORM_ERRORS[] = getMessage('SPONSOR_PHONE_IS_EMPTY');
131 if (!REQUEST_ISSET_POST('url')) {
132 // Homepage URL is empty
133 $FORM_ERRORS[] = getMessage('SPONSOR_URL_IS_EMPTY');
134 } elseif (!isUrlValid(REQUEST_POST('url'))) {
135 // Homepage URL is invalid
136 $FORM_ERRORS[] = getMessage('SPONSOR_URL_IS_INVALID');
137 REQUEST_SET_POST('url', '');
140 // 7. Light validation of email address
141 if ((!REQUEST_ISSET_POST('email')) || (REQUEST_POST('email') == '@')) {
142 // Email is invalid/empty
143 $FORM_ERRORS[] = getMessage('SPONSOR_EMAIL_IS_INVALID');
144 } elseif (SPONSOR_FOUND_EMAIL_DB(REQUEST_POST('email'))) {
145 // Email already found in database!
146 $FORM_ERRORS[] = getMessage('SPONSOR_EMAIL_IS_ALREADY_REGISTERED');
147 REQUEST_SET_POST('email', '');
150 // 8. Pay type selected?
151 if (!REQUEST_ISSET_POST('pay_type')) {
152 // Not pay type selected
153 $FORM_ERRORS[] = getMessage('SPONSOR_NO_PAYTYPE_SELECTED');
156 // 9. Interval of mails
157 if (!REQUEST_ISSET_POST('warning_interval')) {
158 // No warning interval selected
159 $FORM_ERRORS[] = getMessage('SPONSOR_NO_WARNING_INTERVAL_SELECTED');
162 // 10. Mail notifications disabled/enabled
163 if (!REQUEST_ISSET_POST('receive_warnings')) {
164 // Option not selected!
165 $FORM_ERRORS[] = getMessage('SPONSOR_NO_RECEIVE_WARNINGS_SELECTED');
168 // Did he enter his password twice?
169 if (((!REQUEST_ISSET_POST('pass1')) || (!REQUEST_ISSET_POST('pass2'))) || ((REQUEST_POST('pass1') != REQUEST_POST('pass2')) && (REQUEST_ISSET_POST('pass1')) && (REQUEST_ISSET_POST('pass2')))) {
170 if ((REQUEST_POST('pass1') != REQUEST_POST('pass2')) && (REQUEST_ISSET_POST('pass1')) && (REQUEST_ISSET_POST('pass2'))) {
171 // Passwords missmatch
172 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORDS_MISMATCH');
174 if (!REQUEST_ISSET_POST('pass1')) {
175 // Password 1 is empty
176 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD1_EMPTY');
179 if (!REQUEST_ISSET_POST('pass2')) {
180 // Password 2 is empty
181 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD2_EMPTY');
184 } elseif (strlen(REQUEST_POST('pass1')) < getConfig('pass_len')) {
185 // Password is to short!
186 $FORM_ERRORS[] = sprintf(getMessage('SPONSOR_PASSWORD_TOO_SHORT'), getConfig('pass_len'));
189 // Check if he has accepted the terms&conditions
190 if (!REQUEST_ISSET_POST('terms')) {
191 // Homepage URL is empty
192 $FORM_ERRORS[] = getMessage('SPONSOR_TERMS_NOT_ACCEPTED');
195 // If there is something wrong/missing stop registration
196 if (count($FORM_ERRORS) > 0) REQUEST_UNSET_POST('ok');
199 if ((isFormSent()) && (count($FORM_ERRORS) == 0)) {
200 // Generate message array
201 $messageArray = array(
202 'failed' => getMessage('SPONSOR_REGISTRATION_FAILED'),
203 'added' => getMessage('SPONSOR_REGISTRATION_COMPLETED'),
207 $result = SQL_QUERY_ESC("SELECT (`pay_rate` * `pay_min_count`) AS points, `pay_min_count` AS pay, `pay_currency` AS curr
208 FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes`
209 WHERE `id`='%s' LIMIT 1",
210 array(REQUEST_POST('pay_type')), __FILE__, __LINE__);
211 list($points, $pay, $curr) = SQL_FETCHROW($result);
214 SQL_FREERESULT($result);
216 // Add points to array
217 REQUEST_POST('points_amount', $points);
218 REQUEST_POST('points_used' , '0.00000');
219 REQUEST_POST('last_pay' , $pay);
220 REQUEST_POST('last_curr' , $curr);
222 // Register sponsor but never ever update here!
223 $STATUS = SPONSOR_HANDLE_SPONSOR(REQUEST_POST_ARRAY(), true, $messageArray, true);
225 // Check the status of the registration process
227 case 'added': // Sponsor successfully added with account status = UNCONFIRMED!
228 // Check for his ID number
229 $result = SQL_QUERY_ESC("SELECT `id`, `hash` FROM `{!_MYSQL_PREFIX!}_sponsor_data` WHERE `email`='%s' LIMIT 1",
230 array(REQUEST_POST('email')), __FILE__, __LINE__);
231 if (SQL_NUMROWS($result) == 1) {
232 // ID found so let's load it for the confirmation email
233 list($id, $hash) = SQL_FETCHROW($result);
235 // Prepare data for the email template
236 define('__ID' , $id);
237 define('__HASH' , $hash);
238 define('__EMAIL' , REQUEST_POST('email'));
239 define('__SURNAME' , REQUEST_POST('surname'));
240 define('__FAMILY' , REQUEST_POST('family'));
241 define('__GENDER' , translateGender(REQUEST_POST('gender')));
242 define('__TIMESTAMP', generateDateTime(time(), 0));
243 define('__PASSWORD' , REQUEST_POST('pass1'));
245 // Generate email and send it to the new sponsor
246 $EMAIL_MSG = LOAD_EMAIL_TEMPLATE('sponsor_confirm', $hash);
247 sendEmail(REQUEST_POST('email'), getMessage('SPONSOR_PLEASE_CONFIRM_SUBJ'), $EMAIL_MSG);
249 // Send mail to admin
250 sendAdminNotification(getMessage('ADMIN_NEW_SPONSOR'), 'admin_sponsor_reg', $hash);
252 // Output message: DONE
253 $message = $messageArray['added'];
255 // Sponsor account not found???
256 $message = sprintf(getMessage('SPONSOR_EMAIL_404'), REQUEST_POST('email'));
260 SQL_FREERESULT($result);
264 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $STATUS));
266 // Message for testing admin
267 $message = sprintf(getMessage('ADMIN_SPONSOR_UNKNOWN_STATUS'), $STATUS);
269 // Message for the guest
270 $message = sprintf(getMessage('SPONSOR_UNKNOWN_STATUS'), $STATUS);
276 LOAD_TEMPLATE('admin_settings_saved', false, $message);
278 // Check for payment types
279 $result = SQL_QUERY("SELECT `id`, `pay_name`, `pay_rate`, `pay_currency`, `pay_min_count`
280 FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes`
281 ORDER BY `pay_name`", __FILE__, __LINE__);
282 if (SQL_NUMROWS($result) > 0) {
284 // @TODO Swap this HTML code to templates
285 $OUT = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
287 while ($content = SQL_FETCHARRAY($result)) {
288 // Prepare content for output
289 $content['sw'] = $SW;
290 $content['res'] = translateComma($content['pay_rate'] * $content['pay_min_count']);
292 // Load row template and switch color
293 $OUT .= LOAD_TEMPLATE('guest_sponsor_payment_row', false, $content);
296 $OUT .= "</table>\n";
298 // @TODO Rewrite this constant
299 define('__PAYMENT_LIST', $OUT);
301 // Check for invalid entries
302 if (count($FORM_ERRORS) > 0) {
304 // @TODO Rewrite these constants
305 define('__COMPANY' , COMPILE_CODE(REQUEST_POST('company')));
306 define('__POSITION' , COMPILE_CODE(REQUEST_POST('position')));
307 define('__TAX_IDENT', COMPILE_CODE(REQUEST_POST('tax_ident')));
308 define('__SURNAME' , COMPILE_CODE(REQUEST_POST('surname')));
309 define('__FAMILY' , COMPILE_CODE(REQUEST_POST('family')));
310 define('__STREET1' , COMPILE_CODE(REQUEST_POST('street_nr1')));
311 define('__STREET2' , COMPILE_CODE(REQUEST_POST('street_nr2')));
312 define('__COUNTRY' , COMPILE_CODE(REQUEST_POST('country')));
313 define('__ZIP' , COMPILE_CODE(REQUEST_POST('zip')));
314 define('__CITY' , COMPILE_CODE(REQUEST_POST('city')));
315 define('__PHONE' , COMPILE_CODE(REQUEST_POST('phone')));
316 define('__FAX' , COMPILE_CODE(REQUEST_POST('fax')));
317 define('__CELL' , COMPILE_CODE(REQUEST_POST('cell')));
318 define('__EMAIL' , COMPILE_CODE(REQUEST_POST('email')));
319 define('__URL' , COMPILE_CODE(REQUEST_POST('url')));
321 // Check for gender selection
322 switch (REQUEST_POST('gender')) {
324 define('__GENDER_M' , ' selected="selected"');
325 define('__GENDER_F' , '');
326 define('__GENDER_C' , '');
330 define('__GENDER_M' , '');
331 define('__GENDER_F' , ' selected="selected"');
332 define('__GENDER_C' , '');
336 define('__GENDER_M' , '');
337 define('__GENDER_F' , '');
338 define('__GENDER_C' , ' selected="selected"');
342 // Check for receive_warnings
343 switch (REQUEST_POST('receive_warnings')) {
345 define('__REC_Y' , ' selected="selected"');
346 define('__REC_N' , '');
350 define('__REC_Y' , '');
351 define('__REC_N' , ' selected="selected"');
356 $OUT = "<P align=\"center\">
357 <strong><div class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</div></strong><br />
360 foreach ($FORM_ERRORS as $error) {
361 $OUT .= "<li>".$error."</li>\n";
364 $OUT .= "</ol><br />\n";
365 define('__SPONSOR_FORM_ERRORS', $OUT);
366 define('__SPONSOR_REFID', REQUEST_POST('refid'));
368 // None found, first call
369 define('__COMPANY' , '');
370 define('__POSITION' , '');
371 define('__TAX_IDENT', '');
372 define('__GENDER_M' , '');
373 define('__GENDER_F' , '');
374 define('__GENDER_C' , '');
375 define('__SURNAME' , '');
376 define('__FAMILY' , '');
377 define('__STREET1' , '');
378 define('__STREET2' , '');
379 define('__COUNTRY' , '');
380 define('__ZIP' , '');
381 define('__CITY' , '');
382 define('__PHONE' , '');
383 define('__FAX' , '');
384 define('__CELL' , '');
385 define('__EMAIL' , '');
386 define('__URL' , '');
387 define('__REC_Y' , '');
388 define('__REC_N' , '');
390 // No errors found so far
391 define('__SPONSOR_FORM_ERRORS', '');
394 // Prepare referal things
395 if (!REQUEST_ISSET_GET('refid')) {
397 define('__SPONSOR_REFID', '0');
399 // Referal ID transmitted, we don't care here if it is right or not
400 define('__SPONSOR_REFID', bigintval(REQUEST_GET('refid')));
403 // Display registration form
404 LOAD_TEMPLATE('guest_sponsor_reg');
406 // Nothing added so far
407 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SPONSOR_PAYMENT_LIST_IS_EMPTY'));
411 SQL_FREERESULT($result);