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 * 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 - 2009 by Roland Haeder *
21 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
45 // Add description as navigation point
46 addMenuDescription('guest', __FILE__);
48 if ((!isExtensionActive('sponsor'))) {
49 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('sponsor'));
53 // Create array for form errors (= missing data)
54 $FORM_ERRORS = array();
58 // Check submitted form data
60 // 1. Salutation / Surname / family name
61 if (!isPostRequestParameterSet('gender')) {
63 $FORM_ERRORS[] = '{--SPONSOR_NO_GENDER_SELECTED--}';
66 if (!isPostRequestParameterSet('surname')) {
68 $FORM_ERRORS[] = '{--SPONSOR_SURNAME_IS_EMPTY--}';
71 if (!isPostRequestParameterSet('family')) {
73 $FORM_ERRORS[] = '{--SPONSOR_FAMILY_IS_EMPTY--}';
77 // 012 3 32 23 4 43 3 4 4321 12 3 32 2 3 3210
78 if (((!isPostRequestParameterSet('company')) && ((isPostRequestParameterSet('tax_ident')) || (isPostRequestParameterSet('position')))) || ((isPostRequestParameterSet('company')) && (!isPostRequestParameterSet('tax_ident')))) {
79 if (!isPostRequestParameterSet('company')) {
80 // Company name is empty
81 $FORM_ERRORS[] = '{--SPONSOR_COMPANY_IS_EMPTY--}';
82 } elseif (!isPostRequestParameterSet('tax_ident')) {
83 // Tax ident number name is empty
84 $FORM_ERRORS[] = '{--SPONSOR_TAX_IDENT_IS_EMPTY--}';
87 if (!isPostRequestParameterSet('position')) {
88 // Not fatal but not nice: position in company is empty
89 $FORM_ERRORS[] = '{--SPONSOR_POSITION_IS_EMPTY--}';
93 // 3. Street and number
94 if (!isPostRequestParameterSet('street_nr1')) {
95 // Street name and house number are empty
96 $FORM_ERRORS[] = '{--SPONSOR_STREET_NR1_IS_EMPTY--}';
97 } elseif ((isPostRequestParameterSet('street_nr2')) && (!isPostRequestParameterSet('street_nr1'))) {
98 // 1st line for street is empty, but 2nd line not
99 $FORM_ERRORS[] = '{--SPONSOR_STREET_NR1_IS_EMPTY_2_NOT--}';
103 if (!isPostRequestParameterSet('country')) {
104 // Country code is empty
105 $FORM_ERRORS[] = '{--kSPONSOR_COUNTRY_IS_EMPTY--}';
106 } elseif (strlen(postRequestParameter('country')) != 2) {
107 // Country code is invalid
108 $FORM_ERRORS[] = '{--SPONSOR_COUNTRY_IS_INVALID--}';
112 if (!isPostRequestParameterSet('zip')) {
114 $FORM_ERRORS[] = '{--SPONSOR_ZIP_IS_EMPTY--}';
115 } elseif (bigintval(postRequestParameter('zip')) != postRequestParameter('zip')) {
117 $FORM_ERRORS[] = '{--SPONSOR_ZIP_IS_INVALID--}';
118 setPostRequestParameter('zip', '');
122 if (!isPostRequestParameterSet('city')) {
124 $FORM_ERRORS[] = '{--SPONSOR_CITY_IS_EMPTY--}';
128 if (!isPostRequestParameterSet('phone')) {
130 $FORM_ERRORS[] = '{--SPONSOR_PHONE_IS_EMPTY--}';
134 if (!isPostRequestParameterSet('url')) {
135 // Homepage URL is empty
136 $FORM_ERRORS[] = '{--SPONSOR_URL_IS_EMPTY--}';
137 } elseif (!isUrlValid(postRequestParameter('url'))) {
138 // Homepage URL is invalid
139 $FORM_ERRORS[] = '{--SPONSOR_URL_IS_INVALID--}';
140 setPostRequestParameter('url', '');
143 // 7. Light validation of email address
144 if ((!isPostRequestParameterSet('email')) || (postRequestParameter('email') == '@')) {
145 // Email is invalid/empty
146 $FORM_ERRORS[] = '{--SPONSOR_EMAIL_IS_INVALID--}';
147 } elseif (isSponsorRegisteredWithEmail(postRequestParameter('email'))) {
148 // Email already found in database!
149 $FORM_ERRORS[] = '{--SPONSOR_EMAIL_IS_ALREADY_REGISTERED--}';
150 setPostRequestParameter('email', '');
153 // 8. Pay type selected?
154 if (!isPostRequestParameterSet('pay_type')) {
155 // Not pay type selected
156 $FORM_ERRORS[] = '{--SPONSOR_NO_PAYTYPE_SELECTED--}';
159 // 9. Interval of mails
160 if (!isPostRequestParameterSet('warning_interval')) {
161 // No warning interval selected
162 $FORM_ERRORS[] = '{--SPONSOR_NO_WARNING_INTERVAL_SELECTED--}';
165 // 10. Mail notifications disabled/enabled
166 if (!isPostRequestParameterSet('receive_warnings')) {
167 // Option not selected!
168 $FORM_ERRORS[] = '{--SPONSOR_NO_RECEIVE_WARNINGS_SELECTED--}';
171 // Did he enter his password twice?
172 if (((!isPostRequestParameterSet('pass1')) || (!isPostRequestParameterSet('pass2'))) || ((postRequestParameter('pass1') != postRequestParameter('pass2')) && (isPostRequestParameterSet('pass1')) && (isPostRequestParameterSet('pass2')))) {
173 if ((postRequestParameter('pass1') != postRequestParameter('pass2')) && (isPostRequestParameterSet('pass1')) && (isPostRequestParameterSet('pass2'))) {
174 // Passwords missmatch
175 $FORM_ERRORS[] = '{--SPONSOR_PASSWORDS_MISMATCH--}';
177 if (!isPostRequestParameterSet('pass1')) {
178 // Password 1 is empty
179 $FORM_ERRORS[] = '{--SPONSOR_PASSWORD1_EMPTY--}';
182 if (!isPostRequestParameterSet('pass2')) {
183 // Password 2 is empty
184 $FORM_ERRORS[] = '{--SPONSOR_PASSWORD2_EMPTY--}';
187 } elseif (strlen(postRequestParameter('pass1')) < getConfig('pass_len')) {
188 // Password is to short!
189 $FORM_ERRORS[] = '{--SPONSOR_PASSWORD_TOO_SHORT--}';
192 // Check if he has accepted the terms&conditions
193 if (!isPostRequestParameterSet('terms')) {
194 // Homepage URL is empty
195 $FORM_ERRORS[] = '{--SPONSOR_TERMS_NOT_ACCEPTED--}';
198 // If there is something wrong/missing stop registration
199 if (count($FORM_ERRORS) > 0) unsetPostRequestParameter('ok');
202 if ((isFormSent()) && (count($FORM_ERRORS) == 0)) {
203 // Generate message array
204 $messageArray = array(
205 'failed' => '{--SPONSOR_REGISTRATION_FAILED--}',
206 'added' => '{--SPONSOR_REGISTRATION_COMPLETED--}',
210 $result = SQL_QUERY_ESC("SELECT
211 (`pay_rate` * `pay_min_count`) AS points, `pay_min_count` AS pay, `pay_currency` AS curr
213 `{?_MYSQL_PREFIX?}_sponsor_paytypes`
217 array(postRequestParameter('pay_type')), __FILE__, __LINE__);
218 list($points, $pay, $curr) = SQL_FETCHROW($result);
221 SQL_FREERESULT($result);
223 // Add points to array
224 postRequestParameter('points_amount', $points);
225 postRequestParameter('points_used' , '0.00000');
226 postRequestParameter('last_pay' , $pay);
227 postRequestParameter('last_curr' , $curr);
229 // Register sponsor but never ever update here!
230 $message = doProcessSponsorFormRequest($messageArray);
233 loadTemplate('admin_settings_saved', false, $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($FORM_ERRORS) > 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] = secureString(postRequestParameter($entry));
269 foreach (array('m', 'f', 'c') as $gender) {
270 $content['gender_' . $gender] = '';
273 // Check for gender selection
274 $content['gender_' . strtolower(postRequestParameter('gender'))] = ' selected="selected"';
276 // Init receive selection
277 $content['receive_warnings_y'] = '';
278 $content['receive_warnings_n'] = '';
280 // Check for receive_warnings
281 $content['receive_warnings_' . strtolower(postRequestParameter('receive_warnings'))] = ' selected="selected"';
285 if (count($FORM_ERRORS) > 0) {
286 $OUT = loadTemplate('admin_settings_saved', true, '{--SPONSOR_REGISTER_SOMETHING_MISSING--}');
288 foreach ($FORM_ERRORS as $error) {
289 $OUT .= '<li>' . $error . '</li>';
295 $content['form_errors'] = $OUT;
296 $content['refid'] = bigintval(postRequestParameter('refid'));
299 // Display registration form
300 loadTemplate('guest_sponsor_reg', false, $content);
302 // Nothing added so far
303 loadTemplate('admin_settings_saved', false, '{--SPONSOR_PAYMENT_LIST_IS_EMPTY--}');
307 SQL_FREERESULT($result);