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 - 2012 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 array_push($formErrors, '{--SPONSOR_NO_GENDER_SELECTED--}');
64 if (!isPostRequestElementSet('surname')) {
66 array_push($formErrors, '{--SPONSOR_SURNAME_EMPTY--}');
69 if (!isPostRequestElementSet('family')) {
71 array_push($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 array_push($formErrors, '{--SPONSOR_COMPANY_EMPTY--}');
80 } elseif (!isPostRequestElementSet('tax_ident')) {
81 // Tax ident number name is empty
82 array_push($formErrors, '{--SPONSOR_TAX_IDENT_EMPTY--}');
85 if (!isPostRequestElementSet('position')) {
86 // Not fatal but not nice: position in company is empty
87 array_push($formErrors, '{--SPONSOR_POSITION_EMPTY--}');
91 // 3. Street and number
92 if (!isPostRequestElementSet('street_nr1')) {
93 // Street name and house number are empty
94 array_push($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 array_push($formErrors, '{--SPONSOR_STREET_NR1_EMPTY_2_NOT--}');
101 if (!isPostRequestElementSet('country')) {
102 // Country code is empty
103 array_push($formErrors, '{--kSPONSOR_COUNTRY_EMPTY--}');
104 } elseif (strlen(postRequestElement('country')) != 2) {
105 // Country code is invalid
106 array_push($formErrors, '{--SPONSOR_COUNTRY_IS_INVALID--}');
110 if (!isPostRequestElementSet('zip')) {
112 array_push($formErrors, '{--SPONSOR_ZIP_EMPTY--}');
113 } elseif (bigintval(postRequestElement('zip')) != postRequestElement('zip')) {
115 array_push($formErrors, '{--SPONSOR_ZIP_IS_INVALID--}');
116 setPostRequestElement('zip', '');
120 if (!isPostRequestElementSet('city')) {
122 array_push($formErrors, '{--SPONSOR_CITY_EMPTY--}');
126 if (!isPostRequestElementSet('phone')) {
128 array_push($formErrors, '{--SPONSOR_PHONE_EMPTY--}');
132 if (!isPostRequestElementSet('url')) {
133 // Homepage URL is empty
134 array_push($formErrors, '{--SPONSOR_URL_EMPTY--}');
135 } elseif (!isUrlValid(postRequestElement('url'))) {
136 // Homepage URL is invalid
137 array_push($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 array_push($formErrors, '{--SPONSOR_EMAIL_IS_INVALID--}');
145 } elseif (isSponsorRegisteredWithEmail(postRequestElement('email'))) {
146 // Email already found in database!
147 array_push($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 array_push($formErrors, '{--SPONSOR_NO_PAYTYPE_SELECTED--}');
157 // 9. Interval of mails
158 if (!isPostRequestElementSet('warning_interval')) {
159 // No warning interval selected
160 array_push($formErrors, '{--SPONSOR_NO_WARNING_INTERVAL_SELECTED--}');
163 // 10. Mail notifications disabled/enabled
164 if (!isPostRequestElementSet('receive_warnings')) {
165 // Option not selected!
166 array_push($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 array_push($formErrors, '{--SPONSOR_PASSWORDS_MISMATCH--}');
175 if (!isPostRequestElementSet('pass1')) {
176 // Password 1 is empty
177 array_push($formErrors, '{--SPONSOR_PASSWORD1_EMPTY--}');
180 if (!isPostRequestElementSet('pass2')) {
181 // Password 2 is empty
182 array_push($formErrors, '{--SPONSOR_PASSWORD2_EMPTY--}');
185 } elseif (strlen(postRequestElement('pass1')) < getPassLen()) {
186 // Password is to short!
187 array_push($formErrors, '{--SPONSOR_PASSWORD_TOO_SHORT--}');
190 // Check if he has accepted the terms&conditions
191 if (!isPostRequestElementSet('terms')) {
192 // Homepage URL is empty
193 array_push($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
243 `{?_MYSQL_PREFIX?}_sponsor_paytypes`
245 `pay_name` ASC', __FILE__, __LINE__);
246 if (!SQL_HASZERONUMS($result)) {
249 while ($content = SQL_FETCHARRAY($result)) {
250 // Prepare content for output
251 $content['res'] = translateComma($content['pay_rate'] * $content['pay_min_count']);
253 // Load row template and switch color
254 $OUT .= loadTemplate('guest_sponsor_payment_row', TRUE, $content);
257 // Remember the list in table
258 $content['payment_list'] = loadTemplate('guest_sponsor_payment', TRUE, $OUT);
260 // Init a lot array elements
261 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) {
262 $content[$entry] = '';
265 // Check for invalid entries
266 if (count($formErrors) > 0) {
268 foreach (array('company','position','tax_ident','surname','family','street_nr1','street_nr2','country','zip','city','phone','fax','cell','email','url') as $entry) {
269 $content[$entry] = postRequestElement($entry);
272 // Init receive selection
273 $content['receive_warnings_y'] = '';
274 $content['receive_warnings_n'] = '';
276 // Check for receive_warnings
277 $content['receive_warnings_' . strtolower(postRequestElement('receive_warnings'))] = ' selected="selected"';
281 if (count($formErrors) > 0) {
282 $OUT = displayMessage('{--SPONSOR_REGISTER_SOMETHING_MISSING--}', TRUE);
284 foreach ($formErrors as $error) {
285 $OUT .= '<li>' . $error . '</li>';
291 $content['form_errors'] = $OUT;
293 // @TODO Maybe a default referral id?
294 $content['refid'] = 0;
296 // Is the referral id valid?
297 if ((isPostRequestElementSet('refid')) && (isValidUserId(postRequestElement('refid')))) {
298 // Transfer referral id
299 $content['refid'] = bigintval(postRequestElement('refid'));
303 // Display registration form
304 loadTemplate('guest_sponsor_reg', FALSE, $content);
306 // Nothing added so far
307 displayMessage('{--SPONSOR_PAYMENT_LIST_EMPTY--}');
311 SQL_FREERESULT($result);