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(__FILE__, __LINE__, 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();
50 // Check submitted form data
52 // 1. Salutation / Surname / family name
53 if (!REQUEST_ISSET_POST(('gender'))) {
55 $FORM_ERRORS[] = getMessage('SPONSOR_NO_GENDER_SELECTED');
58 if (!REQUEST_ISSET_POST(('surname'))) {
60 $FORM_ERRORS[] = getMessage('SPONSOR_SURNAME_IS_EMPTY');
63 if (!REQUEST_ISSET_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 (((!REQUEST_ISSET_POST(('company'))) && ((REQUEST_ISSET_POST(('tax_ident'))) || (REQUEST_ISSET_POST(('position'))))) || ((REQUEST_ISSET_POST(('company'))) && (!REQUEST_ISSET_POST(('tax_ident'))))) {
71 if (!REQUEST_ISSET_POST(('company'))) {
72 // Company name is empty
73 $FORM_ERRORS[] = getMessage('SPONSOR_COMPANY_IS_EMPTY');
74 } elseif (!REQUEST_ISSET_POST(('tax_ident'))) {
75 // Tax ident number name is empty
76 $FORM_ERRORS[] = getMessage('SPONSOR_TAX_IDENT_IS_EMPTY');
79 if (!REQUEST_ISSET_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 (!REQUEST_ISSET_POST(('street_nr1'))) {
87 // Street name and house number are empty
88 $FORM_ERRORS[] = getMessage('SPONSOR_STREET_NR1_IS_EMPTY');
89 } elseif ((REQUEST_ISSET_POST(('street_nr2'))) && (!REQUEST_ISSET_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 (!REQUEST_ISSET_POST(('country'))) {
96 // Country code is empty
97 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_EMPTY');
98 } elseif (strlen(REQUEST_POST('country')) != 2) {
99 // Country code is invalid
100 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_INVALID');
104 if (!REQUEST_ISSET_POST(('zip'))) {
106 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_EMPTY');
107 } elseif (bigintval(REQUEST_POST('zip')) != REQUEST_POST('zip')) {
109 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_INVALID');
110 REQUEST_SET_POST('zip', "");
114 if (!REQUEST_ISSET_POST(('city'))) {
116 $FORM_ERRORS[] = getMessage('SPONSOR_CITY_IS_EMPTY');
120 if (!REQUEST_ISSET_POST(('phone'))) {
122 $FORM_ERRORS[] = getMessage('SPONSOR_PHONE_IS_EMPTY');
126 if (!REQUEST_ISSET_POST(('url'))) {
127 // Homepage URL is empty
128 $FORM_ERRORS[] = getMessage('SPONSOR_URL_IS_EMPTY');
129 } elseif (!VALIDATE_URL(REQUEST_POST('url'))) {
130 // Homepage URL is invalid
131 $FORM_ERRORS[] = getMessage('SPONSOR_URL_IS_INVALID');
132 REQUEST_SET_POST('url', "");
135 // 7. Light validation of email address
136 if ((!REQUEST_ISSET_POST(('email'))) || (REQUEST_POST('email') == "@")) {
137 // Email is invalid/empty
138 $FORM_ERRORS[] = getMessage('SPONSOR_EMAIL_IS_INVALID');
139 } elseif (SPONSOR_FOUND_EMAIL_DB(REQUEST_POST('email'))) {
140 // Email already found in database!
141 $FORM_ERRORS[] = getMessage('SPONSOR_EMAIL_IS_ALREADY_REGISTERED');
142 REQUEST_SET_POST('email', "");
145 // 8. Pay type selected?
146 if (!REQUEST_ISSET_POST(('pay_type'))) {
147 // Not pay type selected
148 $FORM_ERRORS[] = getMessage('SPONSOR_NO_PAYTYPE_SELECTED');
151 // 9. Interval of mails
152 if (!REQUEST_ISSET_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 (!REQUEST_ISSET_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 (((!REQUEST_ISSET_POST(('pass1'))) || (!REQUEST_ISSET_POST(('pass2')))) || ((REQUEST_POST('pass1') != REQUEST_POST('pass2')) && (REQUEST_ISSET_POST(('pass1'))) && (REQUEST_ISSET_POST(('pass2'))))) {
165 if ((REQUEST_POST('pass1') != REQUEST_POST('pass2')) && (REQUEST_ISSET_POST(('pass1'))) && (REQUEST_ISSET_POST(('pass2')))) {
166 // Passwords missmatch
167 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORDS_MISMATCH');
169 if (!REQUEST_ISSET_POST(('pass1'))) {
170 // Password 1 is empty
171 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD1_EMPTY');
174 if (!REQUEST_ISSET_POST(('pass2'))) {
175 // Password 2 is empty
176 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD2_EMPTY');
179 } elseif (strlen(REQUEST_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 (!REQUEST_ISSET_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) REQUEST_UNSET_POST('ok');
194 if ((IS_FORM_SENT()) && (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(REQUEST_POST('pay_type')), __FILE__, __LINE__);
205 list($points, $pay, $curr) = SQL_FETCHROW($result);
208 SQL_FREERESULT($result);
210 // Add points to array
211 REQUEST_POST('points_amount', $points);
212 REQUEST_POST('points_used' , "0.00000");
213 REQUEST_POST('last_pay' , $pay);
214 REQUEST_POST('last_curr' , $curr);
216 // Register sponsor but never ever update here!
217 $STATUS = SPONSOR_HANDLE_SPONSOR(REQUEST_POST_ARRAY(), 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(REQUEST_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' , REQUEST_POST('email'));
234 define('__SURNAME' , REQUEST_POST('surname'));
235 define('__FAMILY' , REQUEST_POST('family'));
236 define('__GENDER' , TRANSLATE_GENDER(REQUEST_POST('gender')));
237 define('__TIMESTAMP', MAKE_DATETIME(time(), 0));
238 define('__PASSWORD' , REQUEST_POST('pass1'));
240 // Generate email and send it to the new sponsor
241 $EMAIL_MSG = LOAD_EMAIL_TEMPLATE("sponsor_confirm", $hash);
242 SEND_EMAIL(REQUEST_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'), REQUEST_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 ($content = SQL_FETCHARRAY($result)) {
283 // Prepare content for output
284 $content['sw'] = $SW;
285 $content['res'] = TRANSLATE_COMMA($content['pay_rate'] * $content['pay_min_count']);
287 // Load row template and switch color
288 $OUT .= LOAD_TEMPLATE("guest_sponsor_payment_row", false, $content);
291 $OUT .= "</table>\n";
293 // @TODO Rewrite this constant
294 define('__PAYMENT_LIST', $OUT);
296 // Check for invalid entries
297 if (count($FORM_ERRORS) > 0) {
299 // @TODO Rewrite these constants
300 define('__COMPANY' , COMPILE_CODE(REQUEST_POST('company')));
301 define('__POSITION' , COMPILE_CODE(REQUEST_POST('position')));
302 define('__TAX_IDENT', COMPILE_CODE(REQUEST_POST('tax_ident')));
303 define('__SURNAME' , COMPILE_CODE(REQUEST_POST('surname')));
304 define('__FAMILY' , COMPILE_CODE(REQUEST_POST('family')));
305 define('__STREET1' , COMPILE_CODE(REQUEST_POST('street_nr1')));
306 define('__STREET2' , COMPILE_CODE(REQUEST_POST('street_nr2')));
307 define('__COUNTRY' , COMPILE_CODE(REQUEST_POST('country')));
308 define('__ZIP' , COMPILE_CODE(REQUEST_POST('zip')));
309 define('__CITY' , COMPILE_CODE(REQUEST_POST('city')));
310 define('__PHONE' , COMPILE_CODE(REQUEST_POST('phone')));
311 define('__FAX' , COMPILE_CODE(REQUEST_POST('fax')));
312 define('__CELL' , COMPILE_CODE(REQUEST_POST('cell')));
313 define('__EMAIL' , COMPILE_CODE(REQUEST_POST('email')));
314 define('__URL' , COMPILE_CODE(REQUEST_POST('url')));
316 // Check for gender selection
317 switch (REQUEST_POST('gender'))
320 define('__GENDER_M' , " selected=\"selected\"");
321 define('__GENDER_F' , "");
322 define('__GENDER_C' , "");
326 define('__GENDER_M' , "");
327 define('__GENDER_F' , " selected=\"selected\"");
328 define('__GENDER_C' , "");
332 define('__GENDER_M' , "");
333 define('__GENDER_F' , "");
334 define('__GENDER_C' , " selected=\"selected\"");
338 // Check for receive_warnings
339 switch (REQUEST_POST('receive_warnings'))
342 define('__REC_Y' , " selected=\"selected\"");
343 define('__REC_N' , "");
347 define('__REC_Y' , "");
348 define('__REC_N' , " selected=\"selected\"");
353 $OUT = "<P align=\"center\">
354 <strong><div class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</div></strong><br />
357 foreach ($FORM_ERRORS as $error) {
358 $OUT .= "<li>".$error."</li>\n";
361 $OUT .= "</ol><br />\n";
362 define('__SPONSOR_FORM_ERRORS', $OUT);
363 define('__SPONSOR_REFID', REQUEST_POST('refid'));
365 // None found, first call
366 define('__COMPANY' , "");
367 define('__POSITION' , "");
368 define('__TAX_IDENT', "");
369 define('__GENDER_M' , "");
370 define('__GENDER_F' , "");
371 define('__GENDER_C' , "");
372 define('__SURNAME' , "");
373 define('__FAMILY' , "");
374 define('__STREET1' , "");
375 define('__STREET2' , "");
376 define('__COUNTRY' , "");
377 define('__ZIP' , "");
378 define('__CITY' , "");
379 define('__PHONE' , "");
380 define('__FAX' , "");
381 define('__CELL' , "");
382 define('__EMAIL' , "");
383 define('__URL' , "");
384 define('__REC_Y' , "");
385 define('__REC_N' , "");
387 // No errors found so far
388 define('__SPONSOR_FORM_ERRORS', "");
391 // Prepare referal things
392 if (!REQUEST_ISSET_GET(('refid'))) {
394 define('__SPONSOR_REFID', "0");
396 // Referal ID transmitted, we don't care here if it is right or not
397 define('__SPONSOR_REFID', bigintval(REQUEST_GET('refid')));
400 // Display registration form
401 LOAD_TEMPLATE("guest_sponsor_reg");
403 // Nothing added so far
404 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SPONSOR_PAYMENT_LIST_IS_EMPTY'));
408 SQL_FREERESULT($result);