]> git.mxchange.org Git - mailer.git/blob - inc/modules/guest/what-sponsor_reg.php
473e09125457d3d73ef2444068f6a8b1a4b6de50
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software. You can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License.       *
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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
35 {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("guest", basename(__FILE__));
42
43 // Create array for form errors (= missing data)
44 $FORM_ERRORS = array();
45
46 if (isset($HTTP_POST_VARS['ok']))
47 {
48         //
49         // Check submitted form data
50         //
51         // 1. Salutation / Surname / family name
52         if (empty($HTTP_POST_VARS['salut']))
53         {
54                 // Surname is empty
55                 $FORM_ERRORS[] = SPONSOR_NO_SALUT_SELECTED;
56         }
57         if (empty($HTTP_POST_VARS['surname']))
58         {
59                 // Surname is empty
60                 $FORM_ERRORS[] = SPONSOR_SURNAME_IS_EMPTY;
61         }
62         if (empty($HTTP_POST_VARS['family']))
63         {
64                 // Surname is empty
65                 $FORM_ERRORS[] = SPONSOR_FAMILY_IS_EMPTY;
66         }
67         // 2. Company name
68         // 012     3                          32    23      4                            43    3      4                           4321    12      3                          32    2     3                            3210
69         if (((empty($HTTP_POST_VARS['company'])) && ((!empty($HTTP_POST_VARS['tax_ident'])) || (!empty($HTTP_POST_VARS['position'])))) || ((!empty($HTTP_POST_VARS['company'])) && (empty($HTTP_POST_VARS['tax_ident']))))
70         {
71                 if (empty($HTTP_POST_VARS['company']))
72                 {
73                         // Company name is empty
74                         $FORM_ERRORS[] = SPONSOR_COMPANY_IS_EMPTY;
75                 }
76                  elseif (empty($HTTP_POST_VARS['tax_ident']))
77                 {
78                         // Tax ident number name is empty
79                         $FORM_ERRORS[] = SPONSOR_TAX_IDENT_IS_EMPTY;
80                 }
81                 if (empty($HTTP_POST_VARS['position']))
82                 {
83                         // Not fatal but not nice: position in company is empty
84                         $FORM_ERRORS[] = SPONSOR_POSITION_IS_EMPTY;
85                 }
86         }
87         // 3. Street and number
88         if (empty($HTTP_POST_VARS['street_nr1']))
89         {
90                 // Street name and house number are empty
91                 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY;
92         }
93          elseif ((!empty($HTTP_POST_VARS['street_nr2'])) && (empty($HTTP_POST_VARS['street_nr1'])))
94         {
95                 // 1st line for street is empty, but 2nd line not
96                 $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY_2_NOT;
97         }
98         // 4. Country code
99         if (empty($HTTP_POST_VARS['country']))
100         {
101                 // Country code is empty
102                 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_EMPTY;
103         }
104          elseif (strlen($HTTP_POST_VARS['country']) != 2)
105         {
106                 // Country code is invalid
107                 $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_INVALID;
108         }
109         // 3. ZIP code
110         if (empty($HTTP_POST_VARS['zip']))
111         {
112                 // ZIP code is empty
113                 $FORM_ERRORS[] = SPONSOR_ZIP_IS_EMPTY;
114         }
115          elseif (bigintval($HTTP_POST_VARS['zip']) != $HTTP_POST_VARS['zip'])
116         {
117                 // ZIP is invalid
118                 $FORM_ERRORS[] = SPONSOR_ZIP_IS_INVALID;
119                 $HTTP_POST_VARS['zip'] = "";
120         }
121         // 4. City
122         if (empty($HTTP_POST_VARS['city']))
123         {
124                 // City is empty
125                 $FORM_ERRORS[] = SPONSOR_CITY_IS_EMPTY;
126         }
127         // 5. Phone number
128         if (empty($HTTP_POST_VARS['phone']))
129         {
130                 // City is empty
131                 $FORM_ERRORS[] = SPONSOR_PHONE_IS_EMPTY;
132         }
133         // 6. Homepage URL
134         if (empty($HTTP_POST_VARS['url']))
135         {
136                 // Homepage URL is empty
137                 $FORM_ERRORS[] = SPONSOR_URL_IS_EMPTY;
138         }
139          elseif (!VALIDATE_URL($HTTP_POST_VARS['url']))
140         {
141                 // Homepage URL is invalid
142                 $FORM_ERRORS[] = SPONSOR_URL_IS_INVALID;
143                 $HTTP_POST_VARS['url'] = "";
144         }
145         // 7. Light validation of email address
146         if ((empty($HTTP_POST_VARS['email'])) || ($HTTP_POST_VARS['email'] == "@"))
147         {
148                 // Email is invalid/empty
149                 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_INVALID;
150         }
151          elseif (SPONSOR_FOUND_EMAIL_DB($HTTP_POST_VARS['email']))
152         {
153                 // Email already found in database!
154                 $FORM_ERRORS[] = SPONSOR_EMAIL_IS_ALREADY_REGISTERED;
155                 $HTTP_POST_VARS['email'] = "";
156         }
157         // 8. Pay type selected?
158         if (empty($HTTP_POST_VARS['pay_type']))
159         {
160                 // Not pay type selected
161                 $FORM_ERRORS[] = SPONSOR_NO_PAYTYPE_SELECTED;
162         }
163         // 9. Interval of mails
164         if (empty($HTTP_POST_VARS['warning_interval']))
165         {
166                 // No warning interval selected
167                 $FORM_ERRORS[] = SPONSOR_NO_WARNING_INTERVAL_SELECTED;
168         }
169         // 10. Mail notifications disabled/enabled
170         if (empty($HTTP_POST_VARS['receive_warnings']))
171         {
172                 // Option not selected!
173                 $FORM_ERRORS[] = SPONSOR_NO_RECEIVE_WARNINGS_SELECTED;
174         }
175         // Did he enter his password twice?
176         if (((empty($HTTP_POST_VARS['pass1'])) || (empty($HTTP_POST_VARS['pass2']))) || (($HTTP_POST_VARS['pass1'] != $HTTP_POST_VARS['pass2']) && (!empty($HTTP_POST_VARS['pass1'])) && (!empty($HTTP_POST_VARS['pass2']))))
177         {
178                 if (($HTTP_POST_VARS['pass1'] != $HTTP_POST_VARS['pass2']) && (!empty($HTTP_POST_VARS['pass1'])) && (!empty($HTTP_POST_VARS['pass2'])))
179                 {
180                         // Passwords missmatch
181                         $FORM_ERRORS[] = SPONSOR_PASSWORDS_MISMATCH;
182                 }
183                  else
184                 {
185                         if (empty($HTTP_POST_VARS['pass1']))
186                         {
187                                 // Password 1 is empty
188                                 $FORM_ERRORS[] = SPONSOR_PASSWORD1_EMPTY;
189                         }
190                         if (empty($HTTP_POST_VARS['pass2']))
191                         {
192                                 // Password 2 is empty
193                                 $FORM_ERRORS[] = SPONSOR_PASSWORD2_EMPTY;
194                         }
195                 }
196         }
197         // Is the password long enough?
198          elseif (strlen($HTTP_POST_VARS['pass1']) < $CONFIG['pass_len'])
199         {
200                 // Too short!
201                 $FORM_ERRORS[] = SPONSOR_PASSWORD_TOO_SHORT;
202         }
203
204         // Check if he has accepted the terms&conditions
205         if (empty($HTTP_POST_VARS['terms']))
206         {
207                 // Homepage URL is empty
208                 $FORM_ERRORS[] = SPONSOR_TERMS_NOT_ACCEPTED;
209         }
210         
211         // If there is something wrong/missing stop registration
212         if (count($FORM_ERRORS) > 0) unset($HTTP_POST_VARS['ok']);
213 }
214
215 if ((isset($HTTP_POST_VARS['ok'])) && (count($FORM_ERRORS) == 0))
216 {
217         // Generate message array
218         $MSGs = array(
219                 'failed' => SPONSOR_REGISTRATION_FAILED,
220                 'added'  => SPONSOR_REGISTRATION_COMPLETED,
221         );
222
223         // Calulate points
224         $result = SQL_QUERY_ESC("SELECT (pay_rate * pay_min_count) AS points, pay_min_count AS pay, pay_currency AS curr
225 FROM "._MYSQL_PREFIX."_sponsor_paytypes
226 WHERE id='%s' LIMIT 1", array($HTTP_POST_VARS['pay_type']), __FILE__, __LINE__);
227         list($points, $pay, $curr) = SQL_FETCHROW($result);
228
229         // Free memory
230         SQL_FREERESULT($result);
231
232         // Add points to array
233         $HTTP_POST_VARS['points_amount'] = $points;
234         $HTTP_POST_VARS['points_used']   = "0.00000";
235         $HTTP_POST_VARS['last_pay']      = $pay;
236         $HTTP_POST_VARS['last_curr']     = $curr;
237
238         // Register sponsor but never ever update here!
239         $STATUS = SPONSOR_HANDLE_SPONSOR($HTTP_POST_VARS, true, $MSGs, true);
240
241         // Check the status of the registration process
242         switch ($STATUS)
243         {
244         case "added": // Sponsor successfully added with account status = UNCONFIRMED!
245                 // Check for his ID number
246                 $result = SQL_QUERY_ESC("SELECT id, hash FROM "._MYSQL_PREFIX."_sponsor_data WHERE email='%s' LIMIT 1",
247                  array($HTTP_POST_VARS['email']), __FILE__, __LINE__);
248                 if (SQL_NUMROWS($result) == 1)
249                 {
250                         // ID found so let's load it for the confirmation email
251                         list($id, $hash) = SQL_FETCHROW($result);
252
253                         // Prepare data for the email template
254                         define('__ID'       , $id);
255                         define('__HASH'     , $hash);
256                         define('__EMAIL'    , $HTTP_POST_VARS['email']);
257                         define('__SURNAME'  , $HTTP_POST_VARS['surname']);
258                         define('__FAMILY'   , $HTTP_POST_VARS['family']);
259                         define('__SALUT'    , TRANSLATE_SEX($HTTP_POST_VARS['salut']));
260                         define('__TIMESTAMP', MAKE_DATETIME(time(), 0));
261                         define('__PASSWORD' , $HTTP_POST_VARS['pass1']);
262
263                         // Generate email and send it to the new sponsor
264                         $EMAIL_MSG = LOAD_EMAIL_TEMPLATE("sponsor_confirm", $hash);
265                         SEND_EMAIL($HTTP_POST_VARS['email'], SPONSOR_PLEASE_CONFIRM_SUBJ, $EMAIL_MSG);
266
267                         // Send mail to admin
268                         if (GET_EXT_VERSION("admins") >= "0.4.1")
269                         {
270                                 // Use new system
271                                 SEND_ADMIN_EMAILS_PRO(ADMIN_NEW_SPONSOR, "admin_sponsor_reg", $hash);
272                         }
273                          else
274                         {
275                                 // Send over old system
276                                 $msg_admin = LOAD_EMAIL_TEMPLATE("admin_sponsor_reg", $hash);
277                                 SEND_ADMIN_EMAILS (ADMIN_NEW_SPONSOR, $msg_admin);
278                         }
279
280                         // Output message: DONE
281                         $MSG = $MSGs['added'];
282                 }
283                  else
284                 {
285                         // Sponsor account not found???
286                         $MSG = SPONSOR_EMAIL_404_1.$HTTP_POST_VARS['email'].SPONSOR_EMAIL_404_2;
287                 }
288
289                 // Free memory
290                 SQL_FREERESULT($result);
291                 break;
292
293         default:
294                 if (!IS_ADMIN())
295                 {
296                         // Message for testing admin
297                         $MSG = ADMIN_SPONSOR_UNKOWN_STATUS_1.$STATUS.ADMIN_SPONSOR_UNKOWN_STATUS_2;
298                 }
299                  else
300                 {
301                         // Message for the guest
302                         $MSG = SPONSOR_UNKOWN_STATUS_1.$STATUS.SPONSOR_UNKOWN_STATUS_2;
303                 }
304                 break;
305         }
306
307         // Display message
308         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
309 }
310  else
311 {
312         // Check for payment types
313         $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_currency, pay_min_count
314 FROM "._MYSQL_PREFIX."_sponsor_paytypes
315 ORDER BY pay_name", __FILE__, __LINE__);
316         if (SQL_NUMROWS($result) > 0)
317         {
318                 // Load all types...
319                 $OUT = "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
320                 $SW = 2;
321                 while(list($id, $name, $rate, $curr, $min) = SQL_FETCHROW($result))
322                 {
323                         $OUT .= "<TR>
324   <TD class=\"bottom2 switch_sw".$SW."\" height=\"50\" style=\"padding-left: 2px; padding-right: 2px\">
325     <INPUT type=\"radio\" name=\"pay_type\" class=\"guest_normal\" value=\"".bigintval($id)."\">&nbsp;".$name."<BR>
326     <DIV align=\"right\">(".$min." ".$curr." = ".TRANSLATE_COMMA($rate * $min)." ".POINTS.")</DIV>
327   </TD>
328 </TR>\n";
329                         $SW = 3 - $SW;
330                 }
331                 $OUT .= "</TABLE>\n";
332                 define('__PAYMENT_LIST', $OUT);
333                 SQL_FREERESULT($result);
334
335                 // Check for invalid entries
336                 if (count($FORM_ERRORS) > 0)
337                 {
338                         // Some found... :-(
339                         define('__COMPANY'  , COMPILE_CODE($HTTP_POST_VARS['company']));
340                         define('__POSITION' , COMPILE_CODE($HTTP_POST_VARS['position']));
341                         define('__TAX_IDENT', COMPILE_CODE($HTTP_POST_VARS['tax_ident']));
342                         define('__SURNAME'  , COMPILE_CODE($HTTP_POST_VARS['surname']));
343                         define('__FAMILY'   , COMPILE_CODE($HTTP_POST_VARS['family']));
344                         define('__STREET1'  , COMPILE_CODE($HTTP_POST_VARS['street_nr1']));
345                         define('__STREET2'  , COMPILE_CODE($HTTP_POST_VARS['street_nr2']));
346                         define('__COUNTRY'  , COMPILE_CODE($HTTP_POST_VARS['country']));
347                         define('__ZIP'      , COMPILE_CODE($HTTP_POST_VARS['zip']));
348                         define('__CITY'     , COMPILE_CODE($HTTP_POST_VARS['city']));
349                         define('__PHONE'    , COMPILE_CODE($HTTP_POST_VARS['phone']));
350                         define('__FAX'      , COMPILE_CODE($HTTP_POST_VARS['fax']));
351                         define('__CELL'     , COMPILE_CODE($HTTP_POST_VARS['cell']));
352                         define('__EMAIL'    , COMPILE_CODE($HTTP_POST_VARS['email']));
353                         define('__URL'      , COMPILE_CODE($HTTP_POST_VARS['url']));
354
355                         // Check for salutation selection
356                         switch ($HTTP_POST_VARS['salut'])
357                         {
358                         case "M": // Male
359                                 define('__SALUT_M'  , " selected");
360                                 define('__SALUT_F'  , "");
361                                 define('__SALUT_C'  , "");
362                                 break;
363
364                         case "F": // Female
365                                 define('__SALUT_M'  , "");
366                                 define('__SALUT_F'  , " selected");
367                                 define('__SALUT_C'  , "");
368                                 break;
369
370                         case "C": // Company
371                                 define('__SALUT_M'  , "");
372                                 define('__SALUT_F'  , "");
373                                 define('__SALUT_C'  , " selected");
374                                 break;
375                         }
376
377                         // Check for receive_warnings
378                         switch ($HTTP_POST_VARS['receive_warnings'])
379                         {
380                         case "Y":
381                                 define('__REC_Y'    , " selected");
382                                 define('__REC_N'    , "");
383                                 break;
384
385                         case "N":
386                                 define('__REC_Y'    , "");
387                                 define('__REC_N'    , " selected");
388                                 break;
389                         }
390
391                         // Errors found
392                         $OUT = "<P align=\"center\">
393   <STRONG><FONT class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</FONT></STRONG><BR>
394 </P>
395 <OL>\n";
396                         foreach ($FORM_ERRORS as $error)
397                         {
398                                 $OUT .= "<LI>".$error."</LI>\n";
399                         }
400                         $OUT .= "</OL><BR>\n";
401                         define('__SPONSOR_FORM_ERRORS', $OUT);
402                         define('__SPONSOR_REFID', $HTTP_POST_VARS['refid']);
403                 }
404                  else
405                 {
406                         // None found, first call
407                         define('__COMPANY'  , "");
408                         define('__POSITION' , "");
409                         define('__TAX_IDENT', "");
410                         define('__SALUT_M'  , "");
411                         define('__SALUT_F'  , "");
412                         define('__SALUT_C'  , "");
413                         define('__SURNAME'  , "");
414                         define('__FAMILY'   , "");
415                         define('__STREET1'  , "");
416                         define('__STREET2'  , "");
417                         define('__COUNTRY'  , "");
418                         define('__ZIP'      , "");
419                         define('__CITY'     , "");
420                         define('__PHONE'    , "");
421                         define('__FAX'      , "");
422                         define('__CELL'     , "");
423                         define('__EMAIL'    , "");
424                         define('__URL'      , "");
425                         define('__REC_Y'    , "");
426                         define('__REC_N'    , "");
427
428                         // No errors found so far
429                         define('__SPONSOR_FORM_ERRORS', "");
430                 }
431
432                 // Prepare referral things
433                 if (!isset($HTTP_GET_VARS['refid']))
434                 {
435                         // No referral link
436                         define('__SPONSOR_REFID', "0");
437                 }
438                  else
439                 {
440                         // Referral ID transmitted, we don't care here if it is right or not
441                         define('__SPONSOR_REFID', $HTTP_GET_VARS['refid']);
442                 }
443
444                 // Display registration form
445                 LOAD_TEMPLATE("guest_sponsor_reg");
446         }
447          else
448         {
449                 // Nothing added so far
450                 LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_PAYMENT_LIST_IS_EMPTY);
451         }
452
453         // Free memory
454         SQL_FREERESULT($result);
455 }
456
457 //
458 ?>