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 * -------------------------------------------------------------------- *
13 * Copyright (c) 2003 - 2009 by Roland Haeder *
14 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
15 * For more information visit: http://mxchange.org *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
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')) {
38 // Add description as navigation point
39 addYouAreHereLink('guest', __FILE__);
41 if ((!isExtensionActive('sponsor'))) {
42 displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=sponsor%}');
46 // Create array for form errors (= missing data)
47 $formErrors = array();
51 // Check submitted form data
53 // 1. Salutation / Surname / family name
54 if (!isPostRequestElementSet('gender')) {
56 array_push($formErrors, '{--SPONSOR_NO_GENDER_SELECTED--}');
59 if (!isPostRequestElementSet('surname')) {
61 array_push($formErrors, '{--SPONSOR_SURNAME_EMPTY--}');
64 if (!isPostRequestElementSet('family')) {
66 array_push($formErrors, '{--SPONSOR_FAMILY_EMPTY--}');
70 // 012 3 32 23 4 43 3 4 4321 12 3 32 2 3 3210
71 if (((!isPostRequestElementSet('company')) && ((isPostRequestElementSet('tax_ident')) || (isPostRequestElementSet('position')))) || ((isPostRequestElementSet('company')) && (!isPostRequestElementSet('tax_ident')))) {
72 if (!isPostRequestElementSet('company')) {
73 // Company name is empty
74 array_push($formErrors, '{--SPONSOR_COMPANY_EMPTY--}');
75 } elseif (!isPostRequestElementSet('tax_ident')) {
76 // Tax ident number name is empty
77 array_push($formErrors, '{--SPONSOR_TAX_IDENT_EMPTY--}');
80 if (!isPostRequestElementSet('position')) {
81 // Not fatal but not nice: position in company is empty
82 array_push($formErrors, '{--SPONSOR_POSITION_EMPTY--}');
86 // 3. Street and number
87 if (!isPostRequestElementSet('street_nr1')) {
88 // Street name and house number are empty
89 array_push($formErrors, '{--SPONSOR_STREET_NR1_EMPTY--}');
90 } elseif ((isPostRequestElementSet('street_nr2')) && (!isPostRequestElementSet('street_nr1'))) {
91 // 1st line for street is empty, but 2nd line not
92 array_push($formErrors, '{--SPONSOR_STREET_NR1_EMPTY_2_NOT--}');
96 if (!isPostRequestElementSet('country')) {
97 // Country code is empty
98 array_push($formErrors, '{--kSPONSOR_COUNTRY_EMPTY--}');
99 } elseif (strlen(postRequestElement('country')) != 2) {
100 // Country code is invalid
101 array_push($formErrors, '{--SPONSOR_COUNTRY_IS_INVALID--}');
105 if (!isPostRequestElementSet('zip')) {
107 array_push($formErrors, '{--SPONSOR_ZIP_EMPTY--}');
108 } elseif (bigintval(postRequestElement('zip')) != postRequestElement('zip')) {
110 array_push($formErrors, '{--SPONSOR_ZIP_IS_INVALID--}');
111 setPostRequestElement('zip', '');
115 if (!isPostRequestElementSet('city')) {
117 array_push($formErrors, '{--SPONSOR_CITY_EMPTY--}');
121 if (!isPostRequestElementSet('phone')) {
123 array_push($formErrors, '{--SPONSOR_PHONE_EMPTY--}');
127 if (!isPostRequestElementSet('url')) {
128 // Homepage URL is empty
129 array_push($formErrors, '{--SPONSOR_URL_EMPTY--}');
130 } elseif (!isUrlValid(postRequestElement('url'))) {
131 // Homepage URL is invalid
132 array_push($formErrors, '{--SPONSOR_URL_IS_INVALID--}');
133 setPostRequestElement('url', '');
136 // 7. Light validation of email address
137 if ((!isPostRequestElementSet('email')) || (postRequestElement('email') == '@')) {
138 // Email is invalid/empty
139 array_push($formErrors, '{--SPONSOR_EMAIL_IS_INVALID--}');
140 } elseif (isSponsorRegisteredWithEmail(postRequestElement('email'))) {
141 // Email already found in database!
142 array_push($formErrors, '{--SPONSOR_EMAIL_IS_ALREADY_REGISTERED--}');
143 setPostRequestElement('email', '');
146 // 8. Pay type selected?
147 if (!isPostRequestElementSet('pay_type')) {
148 // Not pay type selected
149 array_push($formErrors, '{--SPONSOR_NO_PAYTYPE_SELECTED--}');
152 // 9. Interval of mails
153 if (!isPostRequestElementSet('warning_interval')) {
154 // No warning interval selected
155 array_push($formErrors, '{--SPONSOR_NO_WARNING_INTERVAL_SELECTED--}');
158 // 10. Mail notifications disabled/enabled
159 if (!isPostRequestElementSet('receive_warnings')) {
160 // Option not selected!
161 array_push($formErrors, '{--SPONSOR_NO_RECEIVE_WARNINGS_SELECTED--}');
164 // Did he enter his password twice?
165 if (((!isPostRequestElementSet('password1')) || (!isPostRequestElementSet('password2'))) || ((postRequestElement('password1') != postRequestElement('password2')) && (isPostRequestElementSet('password1')) && (isPostRequestElementSet('password2')))) {
166 if ((postRequestElement('password1') != postRequestElement('password2')) && (isPostRequestElementSet('password1')) && (isPostRequestElementSet('password2'))) {
167 // Passwords missmatch
168 array_push($formErrors, '{--SPONSOR_PASSWORDS_MISMATCH--}');
170 if (!isPostRequestElementSet('password1')) {
171 // Password 1 is empty
172 array_push($formErrors, '{--SPONSOR_PASSWORD1_EMPTY--}');
175 if (!isPostRequestElementSet('password2')) {
176 // Password 2 is empty
177 array_push($formErrors, '{--SPONSOR_PASSWORD2_EMPTY--}');
180 } elseif (strlen(postRequestElement('password1')) < getMinPasswordLength()) {
181 // Password is to short!
182 array_push($formErrors, '{--SPONSOR_PASSWORD_TOO_SHORT--}');
185 // Check if he has accepted the terms&conditions
186 if (!isPostRequestElementSet('terms')) {
187 // Homepage URL is empty
188 array_push($formErrors, '{--SPONSOR_TERMS_NOT_ACCEPTED--}');
191 // If there is something wrong/missing stop registration
192 if (isFilledArray($formErrors)) unsetPostRequestElement('ok');
195 if ((isFormSent()) && (!isFilledArray($formErrors))) {
196 // Generate message array
197 $messageArray = array(
198 'failed' => '{--SPONSOR_REGISTRATION_FAILED--}',
199 'added' => '{--SPONSOR_REGISTRATION_COMPLETED--}',
203 $result = sqlQueryEscaped('SELECT
204 (`pay_rate` * `pay_min_count`) AS `points`,
208 `{?_MYSQL_PREFIX?}_sponsor_paytypes`
212 array(postRequestElement('pay_type')), __FILE__, __LINE__);
213 list($points, $pay, $curr) = sqlFetchRow($result);
216 sqlFreeResult($result);
218 // Add points to array
219 postRequestElement('points_amount', $points);
220 postRequestElement('points_used' , '0.00000');
221 postRequestElement('last_payment' , $pay);
222 postRequestElement('last_currency', $curr);
224 // Register sponsor but never ever update here!
225 $message = doProcessSponsorFormRequest($messageArray);
228 displayMessage($message);
230 // Check for payment types
231 $result = sqlQuery('SELECT
238 `{?_MYSQL_PREFIX?}_sponsor_paytypes`
240 `pay_name` ASC', __FILE__, __LINE__);
241 if (!ifSqlHasZeroNums($result)) {
244 while ($content = sqlFetchArray($result)) {
245 // Prepare content for output
246 $content['res'] = translateComma($content['pay_rate'] * $content['pay_min_count']);
248 // Load row template and switch color
249 $OUT .= loadTemplate('guest_sponsor_payment_row', TRUE, $content);
252 // Remember the list in table
253 $content['payment_list'] = loadTemplate('guest_sponsor_payment', TRUE, $OUT);
255 // Init a lot array elements
256 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) {
257 $content[$entry] = '';
260 // Check for invalid entries
261 if (isFilledArray($formErrors)) {
263 foreach (array('company','position','tax_ident','surname','family','street_nr1','street_nr2','country','zip','city','phone','fax','cell','email','url') as $entry) {
264 $content[$entry] = postRequestElement($entry);
267 // Init receive selection
268 $content['receive_warnings_y'] = '';
269 $content['receive_warnings_n'] = '';
271 // Check for receive_warnings
272 $content['receive_warnings_' . strtolower(postRequestElement('receive_warnings'))] = ' selected="selected"';
276 if (isFilledArray($formErrors)) {
277 $OUT = returnMessage('{--SPONSOR_REGISTER_SOMETHING_MISSING--}');
279 foreach ($formErrors as $error) {
280 $OUT .= '<li>' . $error . '</li>';
286 $content['form_errors'] = $OUT;
288 // @TODO Maybe a default referral id?
289 $content['refid'] = NULL;
291 // Is the referral id valid?
292 if ((isPostRequestElementSet('refid')) && (isValidId(postRequestElement('refid')))) {
293 // Transfer referral id
294 $content['refid'] = bigintval(postRequestElement('refid'));
298 // Display registration form
299 loadTemplate('guest_sponsor_reg', FALSE, $content);
301 // Nothing added so far
302 displayMessage('{--SPONSOR_PAYMENT_LIST_EMPTY--}');
306 sqlFreeResult($result);