2 /************************************************************************
3 * MXChange v0.2.1 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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Add description as navigation point
45 addMenuDescription('guest', __FILE__);
47 if ((!isExtensionActive('sponsor'))) {
48 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('sponsor'));
52 // Create array for form errors (= missing data)
53 $FORM_ERRORS = array();
57 // Check submitted form data
59 // 1. Salutation / Surname / family name
60 if (!isPostRequestElementSet('gender')) {
62 $FORM_ERRORS[] = getMessage('SPONSOR_NO_GENDER_SELECTED');
65 if (!isPostRequestElementSet('surname')) {
67 $FORM_ERRORS[] = getMessage('SPONSOR_SURNAME_IS_EMPTY');
70 if (!isPostRequestElementSet('family')) {
72 $FORM_ERRORS[] = getMessage('SPONSOR_FAMILY_IS_EMPTY');
76 // 012 3 32 23 4 43 3 4 4321 12 3 32 2 3 3210
77 if (((!isPostRequestElementSet('company')) && ((isPostRequestElementSet('tax_ident')) || (isPostRequestElementSet('position')))) || ((isPostRequestElementSet('company')) && (!isPostRequestElementSet('tax_ident')))) {
78 if (!isPostRequestElementSet('company')) {
79 // Company name is empty
80 $FORM_ERRORS[] = getMessage('SPONSOR_COMPANY_IS_EMPTY');
81 } elseif (!isPostRequestElementSet('tax_ident')) {
82 // Tax ident number name is empty
83 $FORM_ERRORS[] = getMessage('SPONSOR_TAX_IDENT_IS_EMPTY');
86 if (!isPostRequestElementSet('position')) {
87 // Not fatal but not nice: position in company is empty
88 $FORM_ERRORS[] = getMessage('SPONSOR_POSITION_IS_EMPTY');
92 // 3. Street and number
93 if (!isPostRequestElementSet('street_nr1')) {
94 // Street name and house number are empty
95 $FORM_ERRORS[] = getMessage('SPONSOR_STREET_NR1_IS_EMPTY');
96 } elseif ((isPostRequestElementSet('street_nr2')) && (!isPostRequestElementSet('street_nr1'))) {
97 // 1st line for street is empty, but 2nd line not
98 $FORM_ERRORS[] = getMessage('SPONSOR_STREET_NR1_IS_EMPTY_2_NOT');
102 if (!isPostRequestElementSet('country')) {
103 // Country code is empty
104 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_EMPTY');
105 } elseif (strlen(postRequestElement('country')) != 2) {
106 // Country code is invalid
107 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_INVALID');
111 if (!isPostRequestElementSet('zip')) {
113 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_EMPTY');
114 } elseif (bigintval(postRequestElement('zip')) != postRequestElement('zip')) {
116 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_INVALID');
117 setRequestPostElement('zip', '');
121 if (!isPostRequestElementSet('city')) {
123 $FORM_ERRORS[] = getMessage('SPONSOR_CITY_IS_EMPTY');
127 if (!isPostRequestElementSet('phone')) {
129 $FORM_ERRORS[] = getMessage('SPONSOR_PHONE_IS_EMPTY');
133 if (!isPostRequestElementSet('url')) {
134 // Homepage URL is empty
135 $FORM_ERRORS[] = getMessage('SPONSOR_URL_IS_EMPTY');
136 } elseif (!isUrlValid(postRequestElement('url'))) {
137 // Homepage URL is invalid
138 $FORM_ERRORS[] = getMessage('SPONSOR_URL_IS_INVALID');
139 setRequestPostElement('url', '');
142 // 7. Light validation of email address
143 if ((!isPostRequestElementSet('email')) || (postRequestElement('email') == '@')) {
144 // Email is invalid/empty
145 $FORM_ERRORS[] = getMessage('SPONSOR_EMAIL_IS_INVALID');
146 } elseif (isSponsorRegisteredWithEmail(postRequestElement('email'))) {
147 // Email already found in database!
148 $FORM_ERRORS[] = getMessage('SPONSOR_EMAIL_IS_ALREADY_REGISTERED');
149 setRequestPostElement('email', '');
152 // 8. Pay type selected?
153 if (!isPostRequestElementSet('pay_type')) {
154 // Not pay type selected
155 $FORM_ERRORS[] = getMessage('SPONSOR_NO_PAYTYPE_SELECTED');
158 // 9. Interval of mails
159 if (!isPostRequestElementSet('warning_interval')) {
160 // No warning interval selected
161 $FORM_ERRORS[] = getMessage('SPONSOR_NO_WARNING_INTERVAL_SELECTED');
164 // 10. Mail notifications disabled/enabled
165 if (!isPostRequestElementSet('receive_warnings')) {
166 // Option not selected!
167 $FORM_ERRORS[] = getMessage('SPONSOR_NO_RECEIVE_WARNINGS_SELECTED');
170 // Did he enter his password twice?
171 if (((!isPostRequestElementSet('pass1')) || (!isPostRequestElementSet('pass2'))) || ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2')))) {
172 if ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2'))) {
173 // Passwords missmatch
174 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORDS_MISMATCH');
176 if (!isPostRequestElementSet('pass1')) {
177 // Password 1 is empty
178 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD1_EMPTY');
181 if (!isPostRequestElementSet('pass2')) {
182 // Password 2 is empty
183 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD2_EMPTY');
186 } elseif (strlen(postRequestElement('pass1')) < getConfig('pass_len')) {
187 // Password is to short!
188 $FORM_ERRORS[] = sprintf(getMessage('SPONSOR_PASSWORD_TOO_SHORT'), getConfig('pass_len'));
191 // Check if he has accepted the terms&conditions
192 if (!isPostRequestElementSet('terms')) {
193 // Homepage URL is empty
194 $FORM_ERRORS[] = getMessage('SPONSOR_TERMS_NOT_ACCEPTED');
197 // If there is something wrong/missing stop registration
198 if (count($FORM_ERRORS) > 0) unsetPostRequestElement('ok');
201 if ((isFormSent()) && (count($FORM_ERRORS) == 0)) {
202 // Generate message array
203 $messageArray = array(
204 'failed' => getMessage('SPONSOR_REGISTRATION_FAILED'),
205 'added' => getMessage('SPONSOR_REGISTRATION_COMPLETED'),
209 $result = SQL_QUERY_ESC("SELECT (`pay_rate` * `pay_min_count`) AS points, `pay_min_count` AS pay, `pay_currency` AS curr
210 FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes`
211 WHERE `id`='%s' LIMIT 1",
212 array(postRequestElement('pay_type')), __FILE__, __LINE__);
213 list($points, $pay, $curr) = SQL_FETCHROW($result);
216 SQL_FREERESULT($result);
218 // Add points to array
219 postRequestElement('points_amount', $points);
220 postRequestElement('points_used' , '0.00000');
221 postRequestElement('last_pay' , $pay);
222 postRequestElement('last_curr' , $curr);
224 // Register sponsor but never ever update here!
225 $STATUS = handlSponsorRequest(postRequestArray(), true, $messageArray, true);
227 // Check the status of the registration process
229 case 'added': // Sponsor successfully added with account status = UNCONFIRMED!
230 // Check for his ID number
231 $result = SQL_QUERY_ESC("SELECT `id`, `hash` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `email`='%s' LIMIT 1",
232 array(postRequestElement('email')), __FILE__, __LINE__);
233 if (SQL_NUMROWS($result) == 1) {
234 // ID found so let's load it for the confirmation email
235 list($id, $hash) = SQL_FETCHROW($result);
237 // Prepare data for the email template
238 $content['id'] = $id;
239 $content['hash'] = $hash;
240 $content['email'] = secureString(postRequestElement('email'));
241 $content['surname'] = secureString(postRequestElement('surname'));
242 $content['family'] = secureString(postRequestElement('family'));
243 $content['gender'] = translateGender(postRequestElement('gender'));
244 $content['timestamp'] = generateDateTime(time(), 0);
245 $content['password'] = secureString(postRequestElement('pass1'));
247 // Generate email and send it to the new sponsor
248 $message = loadEmailTemplate('sponsor_confirm', $hash);
249 sendEmail(postRequestElement('email'), getMessage('SPONSOR_PLEASE_CONFIRM_SUBJ'), $message);
251 // Send mail to admin
252 sendAdminNotification(getMessage('ADMIN_NEW_SPONSOR'), 'admin_sponsor_reg', $hash);
254 // Output message: DONE
255 $message = $messageArray['added'];
257 // Sponsor account not found???
258 $message = sprintf(getMessage('SPONSOR_EMAIL_404'), postRequestElement('email'));
262 SQL_FREERESULT($result);
266 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $STATUS));
268 // Message for testing admin
269 $message = sprintf(getMessage('ADMIN_SPONSOR_UNKNOWN_STATUS'), $STATUS);
271 // Message for the guest
272 $message = sprintf(getMessage('SPONSOR_UNKNOWN_STATUS'), $STATUS);
278 loadTemplate('admin_settings_saved', false, $message);
280 // Check for payment types
281 $result = SQL_QUERY("SELECT `id`, `pay_name`, `pay_rate`, `pay_currency`, `pay_min_count`
282 FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes`
283 ORDER BY `pay_name`", __FILE__, __LINE__);
284 if (SQL_NUMROWS($result) > 0) {
286 // @TODO Swap this HTML code to templates
287 $OUT = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
289 while ($content = SQL_FETCHARRAY($result)) {
290 // Prepare content for output
291 $content['sw'] = $SW;
292 $content['res'] = translateComma($content['pay_rate'] * $content['pay_min_count']);
294 // Load row template and switch color
295 $OUT .= loadTemplate('guest_sponsor_payment_row', false, $content);
298 $OUT .= "</table>\n";
300 // Remember the list in table
301 $content['payment_list'] = $OUT;
303 // Init a lot array elements
304 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) {
305 $content[$entry] = '';
308 // Check for invalid entries
309 if (count($FORM_ERRORS) > 0) {
311 foreach (array('company','position','tax_ident','surname','family','street_nr1','street_nr2','country','zip','city','phone','fix','cell','email','url') as $entry) {
312 $content[$entry] = secureString(postRequestElement($entry));
316 foreach (array('m', 'f', 'c') as $gender) {
317 $content['gender_' . $gender] = '';
320 // Check for gender selection
321 $content['gender_' . strtolower(postRequestElement('gender'))] = ' selected="selected"';
323 // Init receive selection
324 $content['rec_y'] = '';
325 $content['rec_n'] = '';
327 // Check for receive_warnings
328 $content['rec_' . strtolower(postRequestElement('receive_warnings'))] = ' selected="selected"';
332 if (count($FORM_ERRORS) > 0) {
333 $OUT = "<div align=\"center\">
334 <strong><div class=\"guest_failed\">".getMessage('SPONSOR_REGISTER_SOMETHING_MISSING').":</div></strong><br />
337 foreach ($FORM_ERRORS as $error) {
338 $OUT .= "<li>".$error."</li>\n";
341 $OUT .= "</ol><br />\n";
344 $content['form_errors'] = $OUT;
345 $content['refid'] = bigintval(postRequestElement('refid'));
348 // Prepare referal things
349 if (isGetRequestElementSet('refid')) {
350 // Referal ID transmitted, we don't care here if it is right or not
351 $content['refid'] = bigintval(getRequestElement('refid'));
354 $content['refid'] = 0;
357 // Display registration form
358 loadTemplate('guest_sponsor_reg', false, $content);
360 // Nothing added so far
361 loadTemplate('admin_settings_saved', false, getMessage('SPONSOR_PAYMENT_LIST_IS_EMPTY'));
365 SQL_FREERESULT($result);