Extension ext-earning introduced (unfinished), renamings:
[mailer.git] / inc / modules / guest / what-sponsor_reg.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/10/2005 *
4  * ===================                          Last change: 05/18/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-sponsor_reg.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Sponsor's registration form                      *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Anmeldeformular fuer Sponsoren                   *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('guest', __FILE__);
45
46 if ((!isExtensionActive('sponsor'))) {
47         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=sponsor%}');
48         return;
49 } // END - if
50
51 // Create array for form errors (= missing data)
52 $formErrors = array();
53
54 if (isFormSent()) {
55         //
56         // Check submitted form data
57         //
58         // 1. Salutation / Surname / family name
59         if (!isPostRequestElementSet('gender')) {
60                 // Surname is empty
61                 $formErrors[] = '{--SPONSOR_NO_GENDER_SELECTED--}';
62         } // END - if
63
64         if (!isPostRequestElementSet('surname')) {
65                 // Surname is empty
66                 $formErrors[] = '{--SPONSOR_SURNAME_EMPTY--}';
67         } // END - if
68
69         if (!isPostRequestElementSet('family')) {
70                 // Surname is empty
71                 $formErrors[] = '{--SPONSOR_FAMILY_EMPTY--}';
72         } // END - if
73
74         // 2. Company name
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                         $formErrors[] = '{--SPONSOR_COMPANY_EMPTY--}';
80                 } elseif (!isPostRequestElementSet('tax_ident')) {
81                         // Tax ident number name is empty
82                         $formErrors[] = '{--SPONSOR_TAX_IDENT_EMPTY--}';
83                 }
84
85                 if (!isPostRequestElementSet('position')) {
86                         // Not fatal but not nice: position in company is empty
87                         $formErrors[] = '{--SPONSOR_POSITION_EMPTY--}';
88                 } // END - if
89         } // END - if
90
91         // 3. Street and number
92         if (!isPostRequestElementSet('street_nr1')) {
93                 // Street name and house number are empty
94                 $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                 $formErrors[] = '{--SPONSOR_STREET_NR1_EMPTY_2_NOT--}';
98         }
99
100         // 4. Country code
101         if (!isPostRequestElementSet('country')) {
102                 // Country code is empty
103                 $formErrors[] = '{--kSPONSOR_COUNTRY_EMPTY--}';
104         } elseif (strlen(postRequestElement('country')) != 2) {
105                 // Country code is invalid
106                 $formErrors[] = '{--SPONSOR_COUNTRY_IS_INVALID--}';
107         }
108
109         // 3. ZIP code
110         if (!isPostRequestElementSet('zip')) {
111                 // ZIP code is empty
112                 $formErrors[] = '{--SPONSOR_ZIP_EMPTY--}';
113         } elseif (bigintval(postRequestElement('zip')) != postRequestElement('zip')) {
114                 // ZIP is invalid
115                 $formErrors[] = '{--SPONSOR_ZIP_IS_INVALID--}';
116                 setPostRequestElement('zip', '');
117         }
118
119         // 4. City
120         if (!isPostRequestElementSet('city')) {
121                 // City is empty
122                 $formErrors[] = '{--SPONSOR_CITY_EMPTY--}';
123         } // END - if
124
125         // 5. Phone number
126         if (!isPostRequestElementSet('phone')) {
127                 // City is empty
128                 $formErrors[] = '{--SPONSOR_PHONE_EMPTY--}';
129         } // END - if
130
131         // 6. Homepage URL
132         if (!isPostRequestElementSet('url')) {
133                 // Homepage URL is empty
134                 $formErrors[] = '{--SPONSOR_URL_EMPTY--}';
135         } elseif (!isUrlValid(postRequestElement('url'))) {
136                 // Homepage URL is invalid
137                 $formErrors[] = '{--SPONSOR_URL_IS_INVALID--}';
138                 setPostRequestElement('url', '');
139         }
140
141         // 7. Light validation of email address
142         if ((!isPostRequestElementSet('email')) || (postRequestElement('email') == '@')) {
143                 // Email is invalid/empty
144                 $formErrors[] = '{--SPONSOR_EMAIL_IS_INVALID--}';
145         } elseif (isSponsorRegisteredWithEmail(postRequestElement('email'))) {
146                 // Email already found in database!
147                 $formErrors[] = '{--SPONSOR_EMAIL_IS_ALREADY_REGISTERED--}';
148                 setPostRequestElement('email', '');
149         }
150
151         // 8. Pay type selected?
152         if (!isPostRequestElementSet('pay_type')) {
153                 // Not pay type selected
154                 $formErrors[] = '{--SPONSOR_NO_PAYTYPE_SELECTED--}';
155         } // END - if
156
157         // 9. Interval of mails
158         if (!isPostRequestElementSet('warning_interval')) {
159                 // No warning interval selected
160                 $formErrors[] = '{--SPONSOR_NO_WARNING_INTERVAL_SELECTED--}';
161         } // END - if
162
163         // 10. Mail notifications disabled/enabled
164         if (!isPostRequestElementSet('receive_warnings')) {
165                 // Option not selected!
166                 $formErrors[] = '{--SPONSOR_NO_RECEIVE_WARNINGS_SELECTED--}';
167         } // END - if
168
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                         $formErrors[] = '{--SPONSOR_PASSWORDS_MISMATCH--}';
174                 } else {
175                         if (!isPostRequestElementSet('pass1')) {
176                                 // Password 1 is empty
177                                 $formErrors[] = '{--SPONSOR_PASSWORD1_EMPTY--}';
178                         }
179
180                         if (!isPostRequestElementSet('pass2')) {
181                                 // Password 2 is empty
182                                 $formErrors[] = '{--SPONSOR_PASSWORD2_EMPTY--}';
183                         }
184                 }
185         } elseif (strlen(postRequestElement('pass1')) < getPassLen()) {
186                 // Password is to short!
187                 $formErrors[] = '{--SPONSOR_PASSWORD_TOO_SHORT--}';
188         }
189
190         // Check if he has accepted the terms&conditions
191         if (!isPostRequestElementSet('terms')) {
192                 // Homepage URL is empty
193                 $formErrors[] = '{--SPONSOR_TERMS_NOT_ACCEPTED--}';
194         } // END - if
195
196         // If there is something wrong/missing stop registration
197         if (count($formErrors) > 0) unsetPostRequestElement('ok');
198 } // END - if
199
200 if ((isFormSent()) && (count($formErrors) == 0)) {
201         // Generate message array
202         $messageArray = array(
203                 'failed' => '{--SPONSOR_REGISTRATION_FAILED--}',
204                 'added'  => '{--SPONSOR_REGISTRATION_COMPLETED--}',
205         );
206
207         // Calulate points
208         $result = SQL_QUERY_ESC('SELECT
209         (`pay_rate` * `pay_min_count`) AS `points`,
210         `pay_min_count`,
211         `pay_currency`
212 FROM
213         `{?_MYSQL_PREFIX?}_sponsor_paytypes`
214 WHERE
215         `id`=%s
216 LIMIT 1',
217                 array(postRequestElement('pay_type')), __FILE__, __LINE__);
218         list($points, $pay, $curr) = SQL_FETCHROW($result);
219
220         // Free memory
221         SQL_FREERESULT($result);
222
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);
228
229         // Register sponsor but never ever update here!
230         $message = doProcessSponsorFormRequest($messageArray);
231
232         // Display message
233         displayMessage($message);
234 } else {
235         // Check for payment types
236         $result = SQL_QUERY('SELECT
237         `id`,`pay_name`,`pay_rate`,`pay_currency`,`pay_min_count`
238 FROM
239         `{?_MYSQL_PREFIX?}_sponsor_paytypes`
240 ORDER BY 
241         `pay_name` ASC', __FILE__, __LINE__);
242         if (!SQL_HASZERONUMS($result)) {
243                 // Load all types...
244                 $OUT = '';
245                 while ($content = SQL_FETCHARRAY($result)) {
246                         // Prepare content for output
247                         $content['res'] = translateComma($content['pay_rate'] * $content['pay_min_count']);
248
249                         // Load row template and switch color
250                         $OUT .= loadTemplate('guest_sponsor_payment_row', true, $content);
251                 } // END - while
252
253                 // Remember the list in table
254                 $content['payment_list'] = loadTemplate('guest_sponsor_payment', true, $OUT);
255
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]   = '';
259                 } // END - foreach
260
261                 // Check for invalid entries
262                 if (count($formErrors) > 0) {
263                         // Some found... :-(
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]    = postRequestElement($entry);
266                         } // END - foreach
267
268                         // Init receive selection
269                         $content['receive_warnings_y'] = '';
270                         $content['receive_warnings_n'] = '';
271
272                         // Check for receive_warnings
273                         $content['receive_warnings_' . strtolower(postRequestElement('receive_warnings'))] = ' selected="selected"';
274                         $OUT = '';
275
276                         // Errors found?
277                         if (count($formErrors) > 0) {
278                                 $OUT = displayMessage('{--SPONSOR_REGISTER_SOMETHING_MISSING--}', true);
279                                 $OUT .= '<ol>';
280                                 foreach ($formErrors as $error) {
281                                         $OUT .= '<li>' . $error . '</li>';
282                                 } // END - foreach
283
284                                 $OUT .= '</ol>';
285                         } // END - if
286
287                         $content['form_errors'] = $OUT;
288
289                         // @TODO Maybe a default referal id?
290                         $content['refid'] = 0;
291
292                         // Is the referal id valid?
293                         if ((isPostRequestElementSet('refid')) && (isValidUserId(postRequestElement('refid')))) {
294                                 // Transfer referal id
295                                 $content['refid'] = bigintval(postRequestElement('refid'));
296                         } // END - if
297                 } // END - if
298
299                 // Display registration form
300                 loadTemplate('guest_sponsor_reg', false, $content);
301         } else {
302                 // Nothing added so far
303                 displayMessage('{--SPONSOR_PAYMENT_LIST_EMPTY--}');
304         }
305
306         // Free memory
307         SQL_FREERESULT($result);
308 }
309
310 // [EOF]
311 ?>