HTML->XHTML preparation (still *A LOT* to convert
[mailer.git] / inc / modules / guest / what-sponsor_reg.php
index bed8a6149f81c2ac5cf69ef3b3ab4db2288fb4e7..3de41a33a0d4ddf2d72433eb01bf9ed4406767ba 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
+if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
        require($INC);
+} elseif ((!EXT_IS_ACTIVE("sponsor"))) {
+       if (IS_ADMIN()) {
+               addFatalMessage(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "sponsor"));
+       } else {
+               addFatalMessage(EXTENSION_PROBLEM_EXT_INACTIVE, "sponsor");
+       }
+       return;
 }
 
 // Add description as navigation point
-ADD_DESCR("guest", basename(__FILE__));
+ADD_DESCR("guest", __FILE__);
 
 // Create array for form errors (= missing data)
 $FORM_ERRORS = array();
@@ -47,107 +54,93 @@ if (isset($_POST['ok'])) {
        // Check submitted form data
        //
        // 1. Salutation / Surname / family name
-       if (empty($_POST['gender']))
-       {
+       if (empty($_POST['gender'])) {
                // Surname is empty
                $FORM_ERRORS[] = SPONSOR_NO_GENDER_SELECTED;
        }
-       if (empty($_POST['surname']))
-       {
+
+       if (empty($_POST['surname'])) {
                // Surname is empty
                $FORM_ERRORS[] = SPONSOR_SURNAME_IS_EMPTY;
        }
-       if (empty($_POST['family']))
-       {
+
+       if (empty($_POST['family'])) {
                // Surname is empty
                $FORM_ERRORS[] = SPONSOR_FAMILY_IS_EMPTY;
        }
+
        // 2. Company name
-       // 012     3                          32    23      4                            43    3      4                           4321    12      3                          32    2     3                            3210
-       if (((empty($_POST['company'])) && ((!empty($_POST['tax_ident'])) || (!empty($_POST['position'])))) || ((!empty($_POST['company'])) && (empty($_POST['tax_ident']))))
-       {
-               if (empty($_POST['company']))
-               {
+       // 012     3                 32    23      4                   43    3      4                  4321    12      3                 32    2     3                   3210
+       if (((empty($_POST['company'])) && ((!empty($_POST['tax_ident'])) || (!empty($_POST['position'])))) || ((!empty($_POST['company'])) && (empty($_POST['tax_ident'])))) {
+               if (empty($_POST['company'])) {
                        // Company name is empty
                        $FORM_ERRORS[] = SPONSOR_COMPANY_IS_EMPTY;
-               }
-                elseif (empty($_POST['tax_ident']))
-               {
+               } elseif (empty($_POST['tax_ident'])) {
                        // Tax ident number name is empty
                        $FORM_ERRORS[] = SPONSOR_TAX_IDENT_IS_EMPTY;
                }
-               if (empty($_POST['position']))
-               {
+
+               if (empty($_POST['position'])) {
                        // Not fatal but not nice: position in company is empty
                        $FORM_ERRORS[] = SPONSOR_POSITION_IS_EMPTY;
                }
        }
+
        // 3. Street and number
-       if (empty($_POST['street_nr1']))
-       {
+       if (empty($_POST['street_nr1'])) {
                // Street name and house number are empty
                $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY;
-       }
-        elseif ((!empty($_POST['street_nr2'])) && (empty($_POST['street_nr1'])))
-       {
+       } elseif ((!empty($_POST['street_nr2'])) && (empty($_POST['street_nr1']))) {
                // 1st line for street is empty, but 2nd line not
                $FORM_ERRORS[] = SPONSOR_STREET_NR1_IS_EMPTY_2_NOT;
        }
+
        // 4. Country code
-       if (empty($_POST['country']))
-       {
+       if (empty($_POST['country'])) {
                // Country code is empty
                $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_EMPTY;
-       }
-        elseif (strlen($_POST['country']) != 2)
-       {
+       } elseif (strlen($_POST['country']) != 2) {
                // Country code is invalid
                $FORM_ERRORS[] = SPONSOR_COUNTRY_IS_INVALID;
        }
+
        // 3. ZIP code
-       if (empty($_POST['zip']))
-       {
+       if (empty($_POST['zip'])) {
                // ZIP code is empty
                $FORM_ERRORS[] = SPONSOR_ZIP_IS_EMPTY;
-       }
-        elseif (bigintval($_POST['zip']) != $_POST['zip'])
-       {
+       } elseif (bigintval($_POST['zip']) != $_POST['zip']) {
                // ZIP is invalid
                $FORM_ERRORS[] = SPONSOR_ZIP_IS_INVALID;
                $_POST['zip'] = "";
        }
+
        // 4. City
-       if (empty($_POST['city']))
-       {
+       if (empty($_POST['city'])) {
                // City is empty
                $FORM_ERRORS[] = SPONSOR_CITY_IS_EMPTY;
        }
+
        // 5. Phone number
-       if (empty($_POST['phone']))
-       {
+       if (empty($_POST['phone'])) {
                // City is empty
                $FORM_ERRORS[] = SPONSOR_PHONE_IS_EMPTY;
        }
+
        // 6. Homepage URL
-       if (empty($_POST['url']))
-       {
+       if (empty($_POST['url'])) {
                // Homepage URL is empty
                $FORM_ERRORS[] = SPONSOR_URL_IS_EMPTY;
-       }
-        elseif (!VALIDATE_URL($_POST['url']))
-       {
+       } elseif (!VALIDATE_URL($_POST['url'])) {
                // Homepage URL is invalid
                $FORM_ERRORS[] = SPONSOR_URL_IS_INVALID;
                $_POST['url'] = "";
        }
+
        // 7. Light validation of email address
-       if ((empty($_POST['email'])) || ($_POST['email'] == "@"))
-       {
+       if ((empty($_POST['email'])) || ($_POST['email'] == "@")) {
                // Email is invalid/empty
                $FORM_ERRORS[] = SPONSOR_EMAIL_IS_INVALID;
-       }
-        elseif (SPONSOR_FOUND_EMAIL_DB($_POST['email']))
-       {
+       } elseif (SPONSOR_FOUND_EMAIL_DB($_POST['email'])) {
                // Email already found in database!
                $FORM_ERRORS[] = SPONSOR_EMAIL_IS_ALREADY_REGISTERED;
                $_POST['email'] = "";
@@ -193,15 +186,14 @@ if (isset($_POST['ok'])) {
                }
        }
        // Is the password long enough?
-        elseif (strlen($_POST['pass1']) < $_CONFIG['pass_len'])
+        elseif (strlen($_POST['pass1']) < getConfig('pass_len'))
        {
                // Too short!
                $FORM_ERRORS[] = SPONSOR_PASSWORD_TOO_SHORT;
        }
 
        // Check if he has accepted the terms&conditions
-       if (empty($_POST['terms']))
-       {
+       if (empty($_POST['terms'])) {
                // Homepage URL is empty
                $FORM_ERRORS[] = SPONSOR_TERMS_NOT_ACCEPTED;
        }
@@ -210,8 +202,7 @@ if (isset($_POST['ok'])) {
        if (count($FORM_ERRORS) > 0) unset($_POST['ok']);
 }
 
-if ((isset($_POST['ok'])) && (count($FORM_ERRORS) == 0))
-{
+if ((isset($_POST['ok'])) && (count($FORM_ERRORS) == 0)) {
        // Generate message array
        $MSGs = array(
                'failed' => SPONSOR_REGISTRATION_FAILED,
@@ -279,13 +270,11 @@ WHERE id='%s' LIMIT 1", array($_POST['pay_type']), __FILE__, __LINE__);
                break;
 
        default:
-               if (!IS_ADMIN())
-               {
+               DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s detected.", $STATUS));
+               if (!IS_ADMIN()) {
                        // Message for testing admin
                        $MSG = ADMIN_SPONSOR_UNKOWN_STATUS_1.$STATUS.ADMIN_SPONSOR_UNKOWN_STATUS_2;
-               }
-                else
-               {
+               } else {
                        // Message for the guest
                        $MSG = SPONSOR_UNKOWN_STATUS_1.$STATUS.SPONSOR_UNKOWN_STATUS_2;
                }
@@ -294,15 +283,12 @@ WHERE id='%s' LIMIT 1", array($_POST['pay_type']), __FILE__, __LINE__);
 
        // Display message
        LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
-}
- else
-{
+} else {
        // Check for payment types
        $result = SQL_QUERY("SELECT id, pay_name, pay_rate, pay_currency, pay_min_count
 FROM "._MYSQL_PREFIX."_sponsor_paytypes
 ORDER BY pay_name", __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) > 0)
-       {
+       if (SQL_NUMROWS($result) > 0) {
                // Load all types...
                $OUT = "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"300\" class=\"left2 right2 top2\">\n";
                $SW = 2;
@@ -311,7 +297,7 @@ ORDER BY pay_name", __FILE__, __LINE__);
                        $OUT .= "<TR>
   <TD class=\"bottom2 switch_sw".$SW."\" height=\"50\" style=\"padding-left: 2px; padding-right: 2px\">
     <INPUT type=\"radio\" name=\"pay_type\" class=\"guest_normal\" value=\"".bigintval($id)."\">&nbsp;".$name."<br />
-    <DIV align=\"right\">(".$min." ".$curr." = ".TRANSLATE_COMMA($rate * $min)." ".POINTS.")</DIV>
+    <div align=\"right\">(".$min." ".$curr." = ".TRANSLATE_COMMA($rate * $min)." ".POINTS.")</div>
   </TD>
 </TR>\n";
                        $SW = 3 - $SW;
@@ -344,21 +330,21 @@ ORDER BY pay_name", __FILE__, __LINE__);
                        switch ($_POST['gender'])
                        {
                        case "M": // Male
-                               define('__GENDER_M'  , " selected");
+                               define('__GENDER_M'  , " selected=\"selected\"");
                                define('__GENDER_F'  , "");
                                define('__GENDER_C'  , "");
                                break;
 
                        case "F": // Female
                                define('__GENDER_M'  , "");
-                               define('__GENDER_F'  , " selected");
+                               define('__GENDER_F'  , " selected=\"selected\"");
                                define('__GENDER_C'  , "");
                                break;
 
                        case "C": // Company
                                define('__GENDER_M'  , "");
                                define('__GENDER_F'  , "");
-                               define('__GENDER_C'  , " selected");
+                               define('__GENDER_C'  , " selected=\"selected\"");
                                break;
                        }
 
@@ -366,31 +352,29 @@ ORDER BY pay_name", __FILE__, __LINE__);
                        switch ($_POST['receive_warnings'])
                        {
                        case "Y":
-                               define('__REC_Y'    , " selected");
+                               define('__REC_Y'    , " selected=\"selected\"");
                                define('__REC_N'    , "");
                                break;
 
                        case "N":
                                define('__REC_Y'    , "");
-                               define('__REC_N'    , " selected");
+                               define('__REC_N'    , " selected=\"selected\"");
                                break;
                        }
 
                        // Errors found
                        $OUT = "<P align=\"center\">
-  <STRONG><FONT class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</FONT></STRONG><br />
+  <strong><div class=\"guest_failed\">".SPONSOR_REGISTER_SOMETHING_MISSING.":</div></strong><br />
 </P>
-<OL>\n";
-                       foreach ($FORM_ERRORS as $error)
-                       {
-                               $OUT .= "<LI>".$error."</LI>\n";
-                       }
-                       $OUT .= "</OL><br />\n";
+<ol>\n";
+                       foreach ($FORM_ERRORS as $error) {
+                               $OUT .= "<li>".$error."</li>\n";
+                       } // END - if
+
+                       $OUT .= "</ol><br />\n";
                        define('__SPONSOR_FORM_ERRORS', $OUT);
                        define('__SPONSOR_REFID', $_POST['refid']);
-               }
-                else
-               {
+               } else {
                        // None found, first call
                        define('__COMPANY'  , "");
                        define('__POSITION' , "");
@@ -417,23 +401,18 @@ ORDER BY pay_name", __FILE__, __LINE__);
                        define('__SPONSOR_FORM_ERRORS', "");
                }
 
-               // Prepare referral things
-               if (!isset($_GET['refid']))
-               {
-                       // No referral link
+               // Prepare referal things
+               if (!isset($_GET['refid'])) {
+                       // No referal link
                        define('__SPONSOR_REFID', "0");
-               }
-                else
-               {
-                       // Referral ID transmitted, we don't care here if it is right or not
+               } else  {
+                       // Referal ID transmitted, we don't care here if it is right or not
                        define('__SPONSOR_REFID', bigintval($_GET['refid']));
                }
 
                // Display registration form
                LOAD_TEMPLATE("guest_sponsor_reg");
-       }
-        else
-       {
+       } else {
                // Nothing added so far
                LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_PAYMENT_LIST_IS_EMPTY);
        }