2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
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')) {
43 // Add description as navigation point
44 addYouAreHereLink('guest', __FILE__);
46 if ((!isExtensionActive('sponsor'))) {
47 displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=sponsor%}');
51 // Create array for form errors (= missing data)
52 $formErrors = array();
56 // Check submitted form data
58 // 1. Salutation / Surname / family name
59 if (!isPostRequestElementSet('gender')) {
61 $formErrors[] = '{--SPONSOR_NO_GENDER_SELECTED--}';
64 if (!isPostRequestElementSet('surname')) {
66 $formErrors[] = '{--SPONSOR_SURNAME_EMPTY--}';
69 if (!isPostRequestElementSet('family')) {
71 $formErrors[] = '{--SPONSOR_FAMILY_EMPTY--}';
75 // 012 3 32 23 4 43 3 4 4321 12 3 32 2 3 3210
76 if (((!isPostRequestElementSet('company')) && ((isPostRequestElementSet('tax_ident')) || (isPostRequestElementSet('position')))) || ((isPostRequestElementSet('company')) && (!isPostRequestElementSet('tax_ident')))) {
77 if (!isPostRequestElementSet('company')) {
78 // Company name is empty
79 $formErrors[] = '{--SPONSOR_COMPANY_EMPTY--}';
80 } elseif (!isPostRequestElementSet('tax_ident')) {
81 // Tax ident number name is empty
82 $formErrors[] = '{--SPONSOR_TAX_IDENT_EMPTY--}';
85 if (!isPostRequestElementSet('position')) {
86 // Not fatal but not nice: position in company is empty
87 $formErrors[] = '{--SPONSOR_POSITION_EMPTY--}';
91 // 3. Street and number
92 if (!isPostRequestElementSet('street_nr1')) {
93 // Street name and house number are empty
94 $formErrors[] = '{--SPONSOR_STREET_NR1_EMPTY--}';
95 } elseif ((isPostRequestElementSet('street_nr2')) && (!isPostRequestElementSet('street_nr1'))) {
96 // 1st line for street is empty, but 2nd line not
97 $formErrors[] = '{--SPONSOR_STREET_NR1_EMPTY_2_NOT--}';
101 if (!isPostRequestElementSet('country')) {
102 // Country code is empty
103 $formErrors[] = '{--kSPONSOR_COUNTRY_EMPTY--}';
104 } elseif (strlen(postRequestElement('country')) != 2) {
105 // Country code is invalid
106 $formErrors[] = '{--SPONSOR_COUNTRY_IS_INVALID--}';
110 if (!isPostRequestElementSet('zip')) {
112 $formErrors[] = '{--SPONSOR_ZIP_EMPTY--}';
113 } elseif (bigintval(postRequestElement('zip')) != postRequestElement('zip')) {
115 $formErrors[] = '{--SPONSOR_ZIP_IS_INVALID--}';
116 setPostRequestElement('zip', '');
120 if (!isPostRequestElementSet('city')) {
122 $formErrors[] = '{--SPONSOR_CITY_EMPTY--}';
126 if (!isPostRequestElementSet('phone')) {
128 $formErrors[] = '{--SPONSOR_PHONE_EMPTY--}';
132 if (!isPostRequestElementSet('url')) {
133 // Homepage URL is empty
134 $formErrors[] = '{--SPONSOR_URL_EMPTY--}';
135 } elseif (!isUrlValid(postRequestElement('url'))) {
136 // Homepage URL is invalid
137 $formErrors[] = '{--SPONSOR_URL_IS_INVALID--}';
138 setPostRequestElement('url', '');
141 // 7. Light validation of email address
142 if ((!isPostRequestElementSet('email')) || (postRequestElement('email') == '@')) {
143 // Email is invalid/empty
144 $formErrors[] = '{--SPONSOR_EMAIL_IS_INVALID--}';
145 } elseif (isSponsorRegisteredWithEmail(postRequestElement('email'))) {
146 // Email already found in database!
147 $formErrors[] = '{--SPONSOR_EMAIL_IS_ALREADY_REGISTERED--}';
148 setPostRequestElement('email', '');
151 // 8. Pay type selected?
152 if (!isPostRequestElementSet('pay_type')) {
153 // Not pay type selected
154 $formErrors[] = '{--SPONSOR_NO_PAYTYPE_SELECTED--}';
157 // 9. Interval of mails
158 if (!isPostRequestElementSet('warning_interval')) {
159 // No warning interval selected
160 $formErrors[] = '{--SPONSOR_NO_WARNING_INTERVAL_SELECTED--}';
163 // 10. Mail notifications disabled/enabled
164 if (!isPostRequestElementSet('receive_warnings')) {
165 // Option not selected!
166 $formErrors[] = '{--SPONSOR_NO_RECEIVE_WARNINGS_SELECTED--}';
169 // Did he enter his password twice?
170 if (((!isPostRequestElementSet('pass1')) || (!isPostRequestElementSet('pass2'))) || ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2')))) {
171 if ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2'))) {
172 // Passwords missmatch
173 $formErrors[] = '{--SPONSOR_PASSWORDS_MISMATCH--}';
175 if (!isPostRequestElementSet('pass1')) {
176 // Password 1 is empty
177 $formErrors[] = '{--SPONSOR_PASSWORD1_EMPTY--}';
180 if (!isPostRequestElementSet('pass2')) {
181 // Password 2 is empty
182 $formErrors[] = '{--SPONSOR_PASSWORD2_EMPTY--}';
185 } elseif (strlen(postRequestElement('pass1')) < getPassLen()) {
186 // Password is to short!
187 $formErrors[] = '{--SPONSOR_PASSWORD_TOO_SHORT--}';
190 // Check if he has accepted the terms&conditions
191 if (!isPostRequestElementSet('terms')) {
192 // Homepage URL is empty
193 $formErrors[] = '{--SPONSOR_TERMS_NOT_ACCEPTED--}';
196 // If there is something wrong/missing stop registration
197 if (count($formErrors) > 0) unsetPostRequestElement('ok');
200 if ((isFormSent()) && (count($formErrors) == 0)) {
201 // Generate message array
202 $messageArray = array(
203 'failed' => '{--SPONSOR_REGISTRATION_FAILED--}',
204 'added' => '{--SPONSOR_REGISTRATION_COMPLETED--}',
208 $result = SQL_QUERY_ESC('SELECT
209 (`pay_rate` * `pay_min_count`) AS `points`,
213 `{?_MYSQL_PREFIX?}_sponsor_paytypes`
217 array(postRequestElement('pay_type')), __FILE__, __LINE__);
218 list($points, $pay, $curr) = SQL_FETCHROW($result);
221 SQL_FREERESULT($result);
223 // Add points to array
224 postRequestElement('points_amount', $points);
225 postRequestElement('points_used' , '0.00000');
226 postRequestElement('last_payment' , $pay);
227 postRequestElement('last_currency', $curr);
229 // Register sponsor but never ever update here!
230 $message = doProcessSponsorFormRequest($messageArray);
233 displayMessage($message);
235 // Check for payment types
236 $result = SQL_QUERY('SELECT
237 `id`,`pay_name`,`pay_rate`,`pay_currency`,`pay_min_count`
239 `{?_MYSQL_PREFIX?}_sponsor_paytypes`
241 `pay_name` ASC', __FILE__, __LINE__);
242 if (!SQL_HASZERONUMS($result)) {
245 while ($content = SQL_FETCHARRAY($result)) {
246 // Prepare content for output
247 $content['res'] = translateComma($content['pay_rate'] * $content['pay_min_count']);
249 // Load row template and switch color
250 $OUT .= loadTemplate('guest_sponsor_payment_row', true, $content);
253 // Remember the list in table
254 $content['payment_list'] = loadTemplate('guest_sponsor_payment', true, $OUT);
256 // Init a lot array elements
257 foreach (array('company','position','tax_ident','gender_m','gender_f','gender_c','surname','family','street_nr1','street_nr2','country','zip','city','phone','fax','cell','email','url','receive_warnings_y','receive_warnings_n','form_errors','refid') as $entry) {
258 $content[$entry] = '';
261 // Check for invalid entries
262 if (count($formErrors) > 0) {
264 foreach (array('company','position','tax_ident','surname','family','street_nr1','street_nr2','country','zip','city','phone','fax','cell','email','url') as $entry) {
265 $content[$entry] = postRequestElement($entry);
268 // Init receive selection
269 $content['receive_warnings_y'] = '';
270 $content['receive_warnings_n'] = '';
272 // Check for receive_warnings
273 $content['receive_warnings_' . strtolower(postRequestElement('receive_warnings'))] = ' selected="selected"';
277 if (count($formErrors) > 0) {
278 $OUT = displayMessage('{--SPONSOR_REGISTER_SOMETHING_MISSING--}', true);
280 foreach ($formErrors as $error) {
281 $OUT .= '<li>' . $error . '</li>';
287 $content['form_errors'] = $OUT;
289 // @TODO Maybe a default referal id?
290 $content['refid'] = 0;
292 // Is the referal id valid?
293 if ((isPostRequestElementSet('refid')) && (isValidUserId(postRequestElement('refid')))) {
294 // Transfer referal id
295 $content['refid'] = bigintval(postRequestElement('refid'));
299 // Display registration form
300 loadTemplate('guest_sponsor_reg', false, $content);
302 // Nothing added so far
303 displayMessage('{--SPONSOR_PAYMENT_LIST_EMPTY--}');
307 SQL_FREERESULT($result);