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 (`pay_rate` * `pay_min_count`) AS points, `pay_min_count` AS pay, `pay_currency` AS curr
211 FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes`
212 WHERE `id`='%s' LIMIT 1",
213 array(postRequestParameter('pay_type')), __FILE__, __LINE__);
214 list($points, $pay, $curr) = SQL_FETCHROW($result);
217 SQL_FREERESULT($result);
219 // Add points to array
220 postRequestParameter('points_amount', $points);
221 postRequestParameter('points_used' , '0.00000');
222 postRequestParameter('last_pay' , $pay);
223 postRequestParameter('last_curr' , $curr);
225 // Register sponsor but never ever update here!
226 $STATUS = handlSponsorRequest(postRequestArray(), true, $messageArray, true);
228 // Check the status of the registration process
230 case 'added': // Sponsor successfully added with account status = UNCONFIRMED!
231 // Check for his id number
232 $result = SQL_QUERY_ESC("SELECT `id`, `hash` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `email`='%s' LIMIT 1",
233 array(postRequestParameter('email')), __FILE__, __LINE__);
234 if (SQL_NUMROWS($result) == 1) {
235 // id found so let's load it for the confirmation email
236 list($id, $hash) = SQL_FETCHROW($result);
238 // Prepare data for the email template
239 $content['id'] = $id;
240 $content['hash'] = $hash;
241 $content['email'] = secureString(postRequestParameter('email'));
242 $content['surname'] = secureString(postRequestParameter('surname'));
243 $content['family'] = secureString(postRequestParameter('family'));
244 $content['gender'] = translateGender(postRequestParameter('gender'));
245 $content['timestamp'] = generateDateTime(time(), 0);
246 $content['password'] = secureString(postRequestParameter('pass1'));
248 // Generate email and send it to the new sponsor
249 $message = loadEmailTemplate('sponsor_confirm', $hash);
250 sendEmail(postRequestParameter('email'), '{--SPONSOR_PLEASE_CONFIRM_SUBJECT--}', $message);
252 // Send mail to admin
253 sendAdminNotification('{--ADMIN_NEW_SPONSOR--}', 'admin_sponsor_reg', $hash);
255 // Output message: DONE
256 $message = $messageArray['added'];
258 // Sponsor account not found???
259 $message = getMaskedMessage('SPONSOR_EMAIL_404', postRequestParameter('email'));
263 SQL_FREERESULT($result);
267 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $STATUS));
269 // Message for testing admin
270 $message = getMaskedMessage('ADMIN_SPONSOR_UNKNOWN_STATUS', $STATUS);
272 // Message for the guest
273 $message = getMaskedMessage('SPONSOR_UNKNOWN_STATUS', $STATUS);
279 loadTemplate('admin_settings_saved', false, $message);
281 // Check for payment types
282 $result = SQL_QUERY('SELECT
283 `id`, `pay_name`, `pay_rate`, `pay_currency`, `pay_min_count`
285 `{?_MYSQL_PREFIX?}_sponsor_paytypes`
287 pay_name` ASC', __FILE__, __LINE__);
288 if (SQL_NUMROWS($result) > 0) {
290 // @TODO Swap this HTML code to templates
291 $OUT = '<table border="0" cellspacing="0" cellpadding="0" width="300" class="left right top">';
292 while ($content = SQL_FETCHARRAY($result)) {
293 // Prepare content for output
294 $content['res'] = translateComma($content['pay_rate'] * $content['pay_min_count']);
296 // Load row template and switch color
297 $OUT .= loadTemplate('guest_sponsor_payment_row', false, $content);
301 // Remember the list in table
302 $content['payment_list'] = $OUT;
304 // Init a lot array elements
305 foreach (array('company','position','tax_ident','gender_m','gender_f','gender_c','surname','family','street_nr1','street_nr2','country','zip','city','phone','fix','cell','email','url','rec_y','rec_n','form_errors','refid') as $entry) {
306 $content[$entry] = '';
309 // Check for invalid entries
310 if (count($FORM_ERRORS) > 0) {
312 foreach (array('company','position','tax_ident','surname','family','street_nr1','street_nr2','country','zip','city','phone','fix','cell','email','url') as $entry) {
313 $content[$entry] = secureString(postRequestParameter($entry));
317 foreach (array('m', 'f', 'c') as $gender) {
318 $content['gender_' . $gender] = '';
321 // Check for gender selection
322 $content['gender_' . strtolower(postRequestParameter('gender'))] = ' selected="selected"';
324 // Init receive selection
325 $content['rec_y'] = '';
326 $content['rec_n'] = '';
328 // Check for receive_warnings
329 $content['rec_' . strtolower(postRequestParameter('receive_warnings'))] = ' selected="selected"';
333 if (count($FORM_ERRORS) > 0) {
334 $OUT = loadTemplate('admin_settings_saved', true, '{--SPONSOR_REGISTER_SOMETHING_MISSING--}');
336 foreach ($FORM_ERRORS as $error) {
337 $OUT .= '<li>' . $error . '</li>';
343 $content['form_errors'] = $OUT;
344 $content['refid'] = bigintval(postRequestParameter('refid'));
347 // Display registration form
348 loadTemplate('guest_sponsor_reg', false, $content);
350 // Nothing added so far
351 loadTemplate('admin_settings_saved', false, '{--SPONSOR_PAYMENT_LIST_IS_EMPTY--}');
355 SQL_FREERESULT($result);