]> git.mxchange.org Git - mailer.git/blob - inc/modules/guest/what-sponsor_reg.php
Continued:
[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  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
14  * Copyright (c) 2009 - 2016 by Mailer Developer Team                   *
15  * For more information visit: http://mxchange.org                      *
16  *                                                                      *
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.                                  *
21  *                                                                      *
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.                         *
26  *                                                                      *
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,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
35         exit();
36 } // END - if
37
38 // Add description as navigation point
39 addYouAreHereLink('guest', __FILE__);
40
41 if ((!isExtensionActive('sponsor'))) {
42         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=sponsor%}');
43         return;
44 } // END - if
45
46 // Create array for form errors (= missing data)
47 $formErrors = [];
48
49 if (isFormSent()) {
50         //
51         // Check submitted form data
52         //
53         // 1. Salutation / Surname / family name
54         if (!isPostRequestElementSet('sex')) {
55                 // Surname is empty
56                 array_push($formErrors, '{--SPONSOR_NO_SEX_SELECTED--}');
57         } // END - if
58
59         if (!isPostRequestElementSet('surname')) {
60                 // Surname is empty
61                 array_push($formErrors, '{--SPONSOR_SURNAME_EMPTY--}');
62         } // END - if
63
64         if (!isPostRequestElementSet('family')) {
65                 // Surname is empty
66                 array_push($formErrors, '{--SPONSOR_FAMILY_EMPTY--}');
67         } // END - if
68
69         // 2. Company name
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--}');
78                 }
79
80                 if (!isPostRequestElementSet('position')) {
81                         // Not fatal but not nice: position in company is empty
82                         array_push($formErrors, '{--SPONSOR_POSITION_EMPTY--}');
83                 } // END - if
84         } // END - if
85
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--}');
93         }
94
95         // 4. Country code
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--}');
102         }
103
104         // 3. ZIP code
105         if (!isPostRequestElementSet('zip')) {
106                 // ZIP code is empty
107                 array_push($formErrors, '{--SPONSOR_ZIP_EMPTY--}');
108         } elseif (bigintval(postRequestElement('zip')) != postRequestElement('zip')) {
109                 // ZIP is invalid
110                 array_push($formErrors, '{--SPONSOR_ZIP_IS_INVALID--}');
111                 setPostRequestElement('zip', '');
112         }
113
114         // 4. City
115         if (!isPostRequestElementSet('city')) {
116                 // City is empty
117                 array_push($formErrors, '{--SPONSOR_CITY_EMPTY--}');
118         } // END - if
119
120         // 5. Phone number
121         if (!isPostRequestElementSet('phone')) {
122                 // City is empty
123                 array_push($formErrors, '{--SPONSOR_PHONE_EMPTY--}');
124         } // END - if
125
126         // 6. Homepage URL
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', '');
134         }
135
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', '');
144         }
145
146         // 8. Pay type selected?
147         if (!isPostRequestElementSet('pay_type')) {
148                 // Not pay type selected
149                 array_push($formErrors, '{--SPONSOR_NO_PAYTYPE_SELECTED--}');
150         } // END - if
151
152         // 9. Interval of mails
153         if (!isPostRequestElementSet('warning_interval')) {
154                 // No warning interval selected
155                 array_push($formErrors, '{--SPONSOR_NO_WARNING_INTERVAL_SELECTED--}');
156         } // END - if
157
158         // 10. Mail notifications disabled/enabled
159         if (!isPostRequestElementSet('receive_warnings')) {
160                 // Option not selected!
161                 array_push($formErrors, '{--SPONSOR_NO_RECEIVE_WARNINGS_SELECTED--}');
162         } // END - if
163
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--}');
169                 } else {
170                         if (!isPostRequestElementSet('password1')) {
171                                 // Password 1 is empty
172                                 array_push($formErrors, '{--SPONSOR_PASSWORD1_EMPTY--}');
173                         }
174
175                         if (!isPostRequestElementSet('password2')) {
176                                 // Password 2 is empty
177                                 array_push($formErrors, '{--SPONSOR_PASSWORD2_EMPTY--}');
178                         }
179                 }
180         } elseif (strlen(postRequestElement('password1')) < getMinPasswordLength()) {
181                 // Password is to short!
182                 array_push($formErrors, '{--SPONSOR_PASSWORD_TOO_SHORT--}');
183         }
184
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--}');
189         } // END - if
190
191         // If there is something wrong/missing stop registration
192         if (isFilledArray($formErrors)) unsetPostRequestElement('ok');
193 } // END - if
194
195 if ((isFormSent()) && (!isFilledArray($formErrors))) {
196         // Generate message array
197         $messageArray = array(
198                 'failed' => '{--SPONSOR_REGISTRATION_FAILED--}',
199                 'added'  => '{--SPONSOR_REGISTRATION_COMPLETED--}',
200         );
201
202         // Calulate points
203         $result = sqlQueryEscaped('SELECT
204         (`pay_rate` * `pay_min_count`) AS `points`,
205         `pay_min_count`,
206         `pay_currency`
207 FROM
208         `{?_MYSQL_PREFIX?}_sponsor_paytypes`
209 WHERE
210         `id`=%s
211 LIMIT 1',
212                 array(postRequestElement('pay_type')), __FILE__, __LINE__);
213         list($points, $pay, $curr) = sqlFetchRow($result);
214
215         // Free memory
216         sqlFreeResult($result);
217
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);
223
224         // Register sponsor but never ever update here!
225         $message = doProcessSponsorFormRequest($messageArray);
226
227         // Display message
228         displayMessage($message);
229 } else {
230         // Check for payment types
231         $result = sqlQuery('SELECT
232         `id`,
233         `pay_name`,
234         `pay_rate`,
235         `pay_currency`,
236         `pay_min_count`
237 FROM
238         `{?_MYSQL_PREFIX?}_sponsor_paytypes`
239 ORDER BY
240         `pay_name` ASC', __FILE__, __LINE__);
241
242         if (!ifSqlHasZeroNumRows($result)) {
243                 // Load all types...
244                 $OUT = '';
245                 while ($content = sqlFetchArray($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','sex_m','sex_f','sex_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 (isFilledArray($formErrors)) {
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 (isFilledArray($formErrors)) {
278                                 $OUT = returnMessage('{--SPONSOR_REGISTER_SOMETHING_MISSING--}');
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 referral id?
290                         $content['refid'] = NULL;
291
292                         // Is the referral id valid?
293                         if ((isPostRequestElementSet('refid')) && (isValidId(postRequestElement('refid')))) {
294                                 // Transfer referral 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         sqlFreeResult($result);
308 }
309
310 // [EOF]
311 ?>