]> git.mxchange.org Git - mailer.git/blob - inc/modules/guest/what-sponsor_reg.php
ace46f1b4056bcdb244ca37c2493b5f480feab16
[mailer.git] / inc / modules / guest / what-sponsor_reg.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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:: 856                                                    $ *
14  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009)              $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author:: stelzi                                                   $ *
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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
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.       *
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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
41         require($INC);
42 } elseif ((!EXT_IS_ACTIVE("sponsor"))) {
43         addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "sponsor");
44         return;
45 }
46
47 // Add description as navigation point
48 ADD_DESCR("guest", __FILE__);
49
50 // Create array for form errors (= missing data)
51 $FORM_ERRORS = array();
52
53 if (IS_FORM_SENT()) {
54         //
55         // Check submitted form data
56         //
57         // 1. Salutation / Surname / family name
58         if (!REQUEST_ISSET_POST(('gender'))) {
59                 // Surname is empty
60                 $FORM_ERRORS[] = getMessage('SPONSOR_NO_GENDER_SELECTED');
61         }
62
63         if (!REQUEST_ISSET_POST(('surname'))) {
64                 // Surname is empty
65                 $FORM_ERRORS[] = getMessage('SPONSOR_SURNAME_IS_EMPTY');
66         }
67
68         if (!REQUEST_ISSET_POST(('family'))) {
69                 // Surname is empty
70                 $FORM_ERRORS[] = getMessage('SPONSOR_FAMILY_IS_EMPTY');
71         }
72
73         // 2. Company name
74         // 012     3                 32    23      4                   43    3      4                  4321    12      3                 32    2     3                   3210
75         if (((!REQUEST_ISSET_POST(('company'))) && ((REQUEST_ISSET_POST(('tax_ident'))) || (REQUEST_ISSET_POST(('position'))))) || ((REQUEST_ISSET_POST(('company'))) && (!REQUEST_ISSET_POST(('tax_ident'))))) {
76                 if (!REQUEST_ISSET_POST(('company'))) {
77                         // Company name is empty
78                         $FORM_ERRORS[] = getMessage('SPONSOR_COMPANY_IS_EMPTY');
79                 } elseif (!REQUEST_ISSET_POST(('tax_ident'))) {
80                         // Tax ident number name is empty
81                         $FORM_ERRORS[] = getMessage('SPONSOR_TAX_IDENT_IS_EMPTY');
82                 }
83
84                 if (!REQUEST_ISSET_POST(('position'))) {
85                         // Not fatal but not nice: position in company is empty
86                         $FORM_ERRORS[] = getMessage('SPONSOR_POSITION_IS_EMPTY');
87                 }
88         }
89
90         // 3. Street and number
91         if (!REQUEST_ISSET_POST(('street_nr1'))) {
92                 // Street name and house number are empty
93                 $FORM_ERRORS[] = getMessage('SPONSOR_STREET_NR1_IS_EMPTY');
94         } elseif ((REQUEST_ISSET_POST(('street_nr2'))) && (!REQUEST_ISSET_POST(('street_nr1')))) {
95                 // 1st line for street is empty, but 2nd line not
96                 $FORM_ERRORS[] = getMessage('SPONSOR_STREET_NR1_IS_EMPTY_2_NOT');
97         }
98
99         // 4. Country code
100         if (!REQUEST_ISSET_POST(('country'))) {
101                 // Country code is empty
102                 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_EMPTY');
103         } elseif (strlen(REQUEST_POST('country')) != 2) {
104                 // Country code is invalid
105                 $FORM_ERRORS[] = getMessage('SPONSOR_COUNTRY_IS_INVALID');
106         }
107
108         // 3. ZIP code
109         if (!REQUEST_ISSET_POST(('zip'))) {
110                 // ZIP code is empty
111                 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_EMPTY');
112         } elseif (bigintval(REQUEST_POST('zip')) != REQUEST_POST('zip')) {
113                 // ZIP is invalid
114                 $FORM_ERRORS[] = getMessage('SPONSOR_ZIP_IS_INVALID');
115                 REQUEST_SET_POST('zip', "");
116         }
117
118         // 4. City
119         if (!REQUEST_ISSET_POST(('city'))) {
120                 // City is empty
121                 $FORM_ERRORS[] = getMessage('SPONSOR_CITY_IS_EMPTY');
122         }
123
124         // 5. Phone number
125         if (!REQUEST_ISSET_POST(('phone'))) {
126                 // City is empty
127                 $FORM_ERRORS[] = getMessage('SPONSOR_PHONE_IS_EMPTY');
128         }
129
130         // 6. Homepage URL
131         if (!REQUEST_ISSET_POST(('url'))) {
132                 // Homepage URL is empty
133                 $FORM_ERRORS[] = getMessage('SPONSOR_URL_IS_EMPTY');
134         } elseif (!VALIDATE_URL(REQUEST_POST('url'))) {
135                 // Homepage URL is invalid
136                 $FORM_ERRORS[] = getMessage('SPONSOR_URL_IS_INVALID');
137                 REQUEST_SET_POST('url', "");
138         }
139
140         // 7. Light validation of email address
141         if ((!REQUEST_ISSET_POST(('email'))) || (REQUEST_POST('email') == "@")) {
142                 // Email is invalid/empty
143                 $FORM_ERRORS[] = getMessage('SPONSOR_EMAIL_IS_INVALID');
144         } elseif (SPONSOR_FOUND_EMAIL_DB(REQUEST_POST('email'))) {
145                 // Email already found in database!
146                 $FORM_ERRORS[] = getMessage('SPONSOR_EMAIL_IS_ALREADY_REGISTERED');
147                 REQUEST_SET_POST('email', "");
148         }
149
150         // 8. Pay type selected?
151         if (!REQUEST_ISSET_POST(('pay_type'))) {
152                 // Not pay type selected
153                 $FORM_ERRORS[] = getMessage('SPONSOR_NO_PAYTYPE_SELECTED');
154         }
155
156         // 9. Interval of mails
157         if (!REQUEST_ISSET_POST(('warning_interval'))) {
158                 // No warning interval selected
159                 $FORM_ERRORS[] = getMessage('SPONSOR_NO_WARNING_INTERVAL_SELECTED');
160         }
161
162         // 10. Mail notifications disabled/enabled
163         if (!REQUEST_ISSET_POST(('receive_warnings'))) {
164                 // Option not selected!
165                 $FORM_ERRORS[] = getMessage('SPONSOR_NO_RECEIVE_WARNINGS_SELECTED');
166         }
167
168         // Did he enter his password twice?
169         if (((!REQUEST_ISSET_POST(('pass1'))) || (!REQUEST_ISSET_POST(('pass2')))) || ((REQUEST_POST('pass1') != REQUEST_POST('pass2')) && (REQUEST_ISSET_POST(('pass1'))) && (REQUEST_ISSET_POST(('pass2'))))) {
170                 if ((REQUEST_POST('pass1') != REQUEST_POST('pass2')) && (REQUEST_ISSET_POST(('pass1'))) && (REQUEST_ISSET_POST(('pass2')))) {
171                         // Passwords missmatch
172                         $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORDS_MISMATCH');
173                 } else {
174                         if (!REQUEST_ISSET_POST(('pass1'))) {
175                                 // Password 1 is empty
176                                 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD1_EMPTY');
177                         }
178
179                         if (!REQUEST_ISSET_POST(('pass2'))) {
180                                 // Password 2 is empty
181                                 $FORM_ERRORS[] = getMessage('SPONSOR_PASSWORD2_EMPTY');
182                         }
183                 }
184         } elseif (strlen(REQUEST_POST('pass1')) < getConfig('pass_len')) {
185                 // Password is to short!
186                 $FORM_ERRORS[] = sprintf(getMessage('SPONSOR_PASSWORD_TOO_SHORT'), getConfig('pass_len'));
187         }
188
189         // Check if he has accepted the terms&conditions
190         if (!REQUEST_ISSET_POST(('terms'))) {
191                 // Homepage URL is empty
192                 $FORM_ERRORS[] = getMessage('SPONSOR_TERMS_NOT_ACCEPTED');
193         }
194         
195         // If there is something wrong/missing stop registration
196         if (count($FORM_ERRORS) > 0) REQUEST_UNSET_POST('ok');
197 }
198
199 if ((IS_FORM_SENT()) && (count($FORM_ERRORS) == 0)) {
200         // Generate message array
201         $MSGs = array(
202                 'failed' => getMessage('SPONSOR_REGISTRATION_FAILED'),
203                 'added'  => getMessage('SPONSOR_REGISTRATION_COMPLETED'),
204         );
205
206         // Calulate points
207         $result = SQL_QUERY_ESC("SELECT (pay_rate * pay_min_count) AS points, pay_min_count AS pay, pay_currency AS curr
208 FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes`
209 WHERE id='%s' LIMIT 1", array(REQUEST_POST('pay_type')), __FILE__, __LINE__);
210         list($points, $pay, $curr) = SQL_FETCHROW($result);
211
212         // Free memory
213         SQL_FREERESULT($result);
214
215         // Add points to array
216         REQUEST_POST('points_amount', $points);
217         REQUEST_POST('points_used'  , "0.00000");
218         REQUEST_POST('last_pay'     , $pay);
219         REQUEST_POST('last_curr'    , $curr);
220
221         // Register sponsor but never ever update here!
222         $STATUS = SPONSOR_HANDLE_SPONSOR(REQUEST_POST_ARRAY(), true, $MSGs, true);
223
224         // Check the status of the registration process
225         switch ($STATUS)
226         {
227         case "added": // Sponsor successfully added with account status = UNCONFIRMED!
228                 // Check for his ID number
229                 $result = SQL_QUERY_ESC("SELECT id, hash FROM `{!_MYSQL_PREFIX!}_sponsor_data` WHERE email='%s' LIMIT 1",
230                         array(REQUEST_POST('email')), __FILE__, __LINE__);
231                 if (SQL_NUMROWS($result) == 1) {
232                         // ID found so let's load it for the confirmation email
233                         list($id, $hash) = SQL_FETCHROW($result);
234
235                         // Prepare data for the email template
236                         define('__ID'       , $id);
237                         define('__HASH'     , $hash);
238                         define('__EMAIL'    , REQUEST_POST('email'));
239                         define('__SURNAME'  , REQUEST_POST('surname'));
240                         define('__FAMILY'   , REQUEST_POST('family'));
241                         define('__GENDER'    , TRANSLATE_GENDER(REQUEST_POST('gender')));
242                         define('__TIMESTAMP', MAKE_DATETIME(time(), 0));
243                         define('__PASSWORD' , REQUEST_POST('pass1'));
244
245                         // Generate email and send it to the new sponsor
246                         $EMAIL_MSG = LOAD_EMAIL_TEMPLATE("sponsor_confirm", $hash);
247                         SEND_EMAIL(REQUEST_POST('email'), getMessage('SPONSOR_PLEASE_CONFIRM_SUBJ'), $EMAIL_MSG);
248
249                         // Send mail to admin
250                         SEND_ADMIN_NOTIFICATION(getMessage('ADMIN_NEW_SPONSOR'), "admin_sponsor_reg", $hash);
251
252                         // Output message: DONE
253                         $MSG = $MSGs['added'];
254                 } else {
255                         // Sponsor account not found???
256                         $MSG = sprintf(getMessage('SPONSOR_EMAIL_404'), REQUEST_POST('email'));
257                 }
258
259                 // Free memory
260                 SQL_FREERESULT($result);
261                 break;
262
263         default:
264                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $STATUS));
265                 if (!IS_ADMIN()) {
266                         // Message for testing admin
267                         $MSG = sprintf(getMessage('ADMIN_SPONSOR_UNKNOWN_STATUS'), $STATUS);
268                 } else {
269                         // Message for the guest
270                         $MSG = sprintf(getMessage('SPONSOR_UNKNOWN_STATUS'), $STATUS);
271                 }
272                 break;
273         }
274
275         // Display message
276         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
277 } else {
278         // Check for payment types
279         $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_currency, pay_min_count
280 FROM `{!_MYSQL_PREFIX!}_sponsor_paytypes`
281 ORDER BY pay_name", __FILE__, __LINE__);
282         if (SQL_NUMROWS($result) > 0) {
283                 // Load all types...
284                 // @TODO Swap this HTML code to templates
285                 $OUT = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
286                 $SW = 2;
287                 while ($content = SQL_FETCHARRAY($result)) {
288                         // Prepare content for output
289                         $content['sw']  = $SW;
290                         $content['res'] = TRANSLATE_COMMA($content['pay_rate'] * $content['pay_min_count']);
291
292                         // Load row template and switch color
293                         $OUT .= LOAD_TEMPLATE("guest_sponsor_payment_row", false, $content);
294                         $SW = 3 - $SW;
295                 }
296                 $OUT .= "</table>\n";
297
298                 // @TODO Rewrite this constant
299                 define('__PAYMENT_LIST', $OUT);
300
301                 // Check for invalid entries
302                 if (count($FORM_ERRORS) > 0) {
303                         // Some found... :-(
304                         // @TODO Rewrite these constants
305                         define('__COMPANY'  , COMPILE_CODE(REQUEST_POST('company')));
306                         define('__POSITION' , COMPILE_CODE(REQUEST_POST('position')));
307                         define('__TAX_IDENT', COMPILE_CODE(REQUEST_POST('tax_ident')));
308                         define('__SURNAME'  , COMPILE_CODE(REQUEST_POST('surname')));
309                         define('__FAMILY'   , COMPILE_CODE(REQUEST_POST('family')));
310                         define('__STREET1'  , COMPILE_CODE(REQUEST_POST('street_nr1')));
311                         define('__STREET2'  , COMPILE_CODE(REQUEST_POST('street_nr2')));
312                         define('__COUNTRY'  , COMPILE_CODE(REQUEST_POST('country')));
313                         define('__ZIP'      , COMPILE_CODE(REQUEST_POST('zip')));
314                         define('__CITY'     , COMPILE_CODE(REQUEST_POST('city')));
315                         define('__PHONE'    , COMPILE_CODE(REQUEST_POST('phone')));
316                         define('__FAX'      , COMPILE_CODE(REQUEST_POST('fax')));
317                         define('__CELL'     , COMPILE_CODE(REQUEST_POST('cell')));
318                         define('__EMAIL'    , COMPILE_CODE(REQUEST_POST('email')));
319                         define('__URL'      , COMPILE_CODE(REQUEST_POST('url')));
320
321                         // Check for gender selection
322                         switch (REQUEST_POST('gender'))
323                         {
324                         case "M": // Male
325                                 define('__GENDER_M'  , " selected=\"selected\"");
326                                 define('__GENDER_F'  , "");
327                                 define('__GENDER_C'  , "");
328                                 break;
329
330                         case "F": // Female
331                                 define('__GENDER_M'  , "");
332                                 define('__GENDER_F'  , " selected=\"selected\"");
333                                 define('__GENDER_C'  , "");
334                                 break;
335
336                         case "C": // Company
337                                 define('__GENDER_M'  , "");
338                                 define('__GENDER_F'  , "");
339                                 define('__GENDER_C'  , " selected=\"selected\"");
340                                 break;
341                         }
342
343                         // Check for receive_warnings
344                         switch (REQUEST_POST('receive_warnings'))
345                         {
346                         case "Y":
347                                 define('__REC_Y'    , " selected=\"selected\"");
348                                 define('__REC_N'    , "");
349                                 break;
350
351                         case "N":
352                                 define('__REC_Y'    , "");
353                                 define('__REC_N'    , " selected=\"selected\"");
354                                 break;
355                         }
356
357                         // Errors found
358                         $OUT = "<P align=\"center\">
359   <strong><div class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</div></strong><br />
360 </P>
361 <ol>\n";
362                         foreach ($FORM_ERRORS as $error) {
363                                 $OUT .= "<li>".$error."</li>\n";
364                         } // END - if
365
366                         $OUT .= "</ol><br />\n";
367                         define('__SPONSOR_FORM_ERRORS', $OUT);
368                         define('__SPONSOR_REFID', REQUEST_POST('refid'));
369                 } else {
370                         // None found, first call
371                         define('__COMPANY'  , "");
372                         define('__POSITION' , "");
373                         define('__TAX_IDENT', "");
374                         define('__GENDER_M'  , "");
375                         define('__GENDER_F'  , "");
376                         define('__GENDER_C'  , "");
377                         define('__SURNAME'  , "");
378                         define('__FAMILY'   , "");
379                         define('__STREET1'  , "");
380                         define('__STREET2'  , "");
381                         define('__COUNTRY'  , "");
382                         define('__ZIP'      , "");
383                         define('__CITY'     , "");
384                         define('__PHONE'    , "");
385                         define('__FAX'      , "");
386                         define('__CELL'     , "");
387                         define('__EMAIL'    , "");
388                         define('__URL'      , "");
389                         define('__REC_Y'    , "");
390                         define('__REC_N'    , "");
391
392                         // No errors found so far
393                         define('__SPONSOR_FORM_ERRORS', "");
394                 }
395
396                 // Prepare referal things
397                 if (!REQUEST_ISSET_GET(('refid'))) {
398                         // No referal link
399                         define('__SPONSOR_REFID', "0");
400                 } else  {
401                         // Referal ID transmitted, we don't care here if it is right or not
402                         define('__SPONSOR_REFID', bigintval(REQUEST_GET('refid')));
403                 }
404
405                 // Display registration form
406                 LOAD_TEMPLATE("guest_sponsor_reg");
407         } else {
408                 // Nothing added so far
409                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SPONSOR_PAYMENT_LIST_IS_EMPTY'));
410         }
411
412         // Free memory
413         SQL_FREERESULT($result);
414 }
415
416 //
417 ?>