Some missing brackes added, sponsor guest modules now depends on extension
[mailer.git] / inc / modules / guest / what-sponsor_login.php
index d224bc3672420452e58905266fdc58b0f7d08a14..3586e33e88658a1e87de0f0b9cb69969777dec71 100644 (file)
 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()) {
+               ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "sponsor"));
+       } else {
+               ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "sponsor");
+       }
+       return;
 }
 
 // Add description as navigation point
 ADD_DESCR("guest", __FILE__);
 
 $MODE = "";
-if (!empty($_GET['mode']))
-{
+if (!empty($_GET['mode'])) {
        // A "special" mode of the login system was requested
        switch ($_GET['mode'])
        {
                case "activate" : $MODE = "activate";  break; // Activation link requested
                case "lost_pass": $MODE = "lost_pass"; break; // Request new password
        }
-}
+} // END - if
 
 // Check if hash for confirmation of email address is given...
-if (!empty($_GET['hash']))
-{
+if (!empty($_GET['hash'])) {
        // Lookup sponsor
        $result = SQL_QUERY_ESC("SELECT id, status, gender, surname, family,
 company, position, tax_ident,
@@ -61,8 +66,7 @@ points_amount AS points, last_pay AS pay, last_curr AS curr
 FROM "._MYSQL_PREFIX."_sponsor_data
 WHERE hash='%s' AND (status='UNCONFIRMED' OR status='EMAIL')
 LIMIT 1", array($_GET['hash']), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 1)
-       {
+       if (SQL_NUMROWS($result) == 1) {
                // Sponsor found, load his data...
                $SPONSOR = SQL_FETCHARRAY($result);
 
@@ -72,16 +76,14 @@ LIMIT 1", array($_GET['hash']), __FILE__, __LINE__);
                $SPONSOR['pay']    = TRANSLATE_COMMA($SPONSOR['pay']);
 
                // Unconfirmed account or changed email address?
-               if ($SPONSOR['status'] == "UNCONFIRMED")
-               {
+               if ($SPONSOR['status'] == "UNCONFIRMED") {
                        // Set account to pending
                        $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data SET status='PENDING'
 WHERE id='%s' AND hash='%s' AND status='UNCONFIRMED' LIMIT 1",
  array(bigintval($SPONSOR['id']), $_GET['hash']), __FILE__, __LINE__);
 
-                       // Check on success 
-                       if (SQL_AFFECTEDROWS() == 1)
-                       {
+                       // Check on success
+                       if (SQL_AFFECTEDROWS() == 1) {
                                // Prepare mail and send it to the sponsor
                                $MSG = LOAD_EMAIL_TEMPLATE("sponsor_pending", $SPONSOR);
                                SEND_EMAIL($SPONSOR['email'], SPONSOR_ACCOUNT_PENDING_SUBJ, $MSG);
@@ -91,65 +93,51 @@ WHERE id='%s' AND hash='%s' AND status='UNCONFIRMED' LIMIT 1",
 
                                // Sponsor account set to pending
                                LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_ACCOUNT_IS_PENDING);
-                       }
-                        else
-                       {
+                       } else {
                                // Could not unlock account!
                                LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_ACCOUNT_PENDING_FAILED);
                        }
-               }
-                elseif ($SPONSOR['status'] == "EMAIL")
-               {
+               } elseif ($SPONSOR['status'] == "EMAIL") {
                        // Changed email adress need to be confirmed
                        $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data SET status='CONFIRMED'
 WHERE id='%s' AND hash='%s' AND status='EMAIL' LIMIT 1",
  array(bigintval($SPONSOR['id']), $_GET['hash']), __FILE__, __LINE__);
 
                        // Check on success 
-                       if (SQL_AFFECTEDROWS() == 1)
-                       {
+                       if (SQL_AFFECTEDROWS() == 1) {
                                // Sponsor account is unlocked again
                                LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_ACCOUNT_IS_CONFIRMED_AGAIN);
-                       }
-                        else
-                       {
+                       } else {
                                // Could not unlock account!
                                LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_ACCOUNT_EMAIL_FAILED);
                        }
-               }
-                else
-               {
+               } else {
                        /// ??? Other status?
                        LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_ACCOUNT_STATUS_FAILED);
                }
-       }
-        else
-       {
+       } else {
                // No sponsor found
                LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_ACCOUNT_404);
        }
 
        // Free memory
        SQL_FREERESULT($result);
-}
- elseif ($MODE == "activate")
-{
+} elseif ($MODE == "activate") {
        // Send activation link again
-       if (isset($_POST['ok']))
-       {
+       if (isset($_POST['ok'])) {
                // Check submitted data
                if (empty($_POST['email'])) unset($_POST['ok']);
        }
 
-       if (isset($_POST['ok']))
-       {
+       if (isset($_POST['ok'])) {
                // Check email
                $result = SQL_QUERY_ESC("SELECT id, hash, status, remote_addr, gender, surname, family, sponsor_created
 FROM "._MYSQL_PREFIX."_sponsor_data
 WHERE email='%s' AND (status='UNCONFIRMED' OR status='EMAIL') LIMIT 1",
- array($_POST['email']), __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) == 1)
-               {
+                       array($_POST['email']), __FILE__, __LINE__);
+
+               // Entry found?
+               if (SQL_NUMROWS($result) == 1) {
                        // Unconfirmed sponsor account found so let's load the requested data
                        $SPONSOR = SQL_FETCHARRAY($result);
 
@@ -158,13 +146,10 @@ WHERE email='%s' AND (status='UNCONFIRMED' OR status='EMAIL') LIMIT 1",
                        $SPONSOR['sponsor_created'] = MAKE_DATETIME($SPONSOR['sponsor_created']);
 
                        // Prepare email and send it to the sponsor
-                       if ($SPONSOR['status'] == "UNCONFIRMED")
-                       {
+                       if ($SPONSOR['status'] == "UNCONFIRMED") {
                                // Unconfirmed accounts
                                $msg_sponsor = LOAD_EMAIL_TEMPLATE("sponsor_activate", $SPONSOR);
-                       }
-                        else
-                       {
+                       } else {
                                // Confirmed email address
                                $msg_sponsor = LOAD_EMAIL_TEMPLATE("sponsor_email", $SPONSOR);
                        }
@@ -172,40 +157,32 @@ WHERE email='%s' AND (status='UNCONFIRMED' OR status='EMAIL') LIMIT 1",
 
                        // Output message
                        LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_ACTIVATION_LINK_SENT);
-               }
-                else
-               {
+               } else {
                        // No account found or not UNCONFIRMED
                        LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_ACTIVATION_LINK_404);
                }
 
                // Free memory
                SQL_FREERESULT($result);
-       }
-        else
-       {
+       } else {
                // Load form
                LOAD_TEMPLATE("guest_sponsor_activate");
        }
-}
- elseif ($MODE == "lost_pass")
-{
+} elseif ($MODE == "lost_pass") {
        // Send new password
-       if (isset($_POST['ok']))
-       {
+       if (isset($_POST['ok'])) {
                // Check submitted data
                if (empty($_POST['email'])) unset($_POST['ok']);
-       }
+       } // END - if
 
-       if (isset($_POST['ok']))
-       {
+       if (isset($_POST['ok'])) {
                // Check email
                $result = SQL_QUERY_ESC("SELECT id, hash, remote_addr, gender, surname, family, sponsor_created
 FROM "._MYSQL_PREFIX."_sponsor_data
 WHERE email='%s' AND id='%s' AND status='CONFIRMED' LIMIT 1",
- array($_POST['email'], bigintval($_POST['id'])), __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) == 1)
-               {
                      array($_POST['email'], bigintval($_POST['id'])), __FILE__, __LINE__);
+               // Entry found?
+               if (SQL_NUMROWS($result) == 1) {
                        // Unconfirmed sponsor account found so let's load the requested data
                        $SPONSOR = SQL_FETCHARRAY($result);
 
@@ -227,34 +204,26 @@ WHERE id='%s' LIMIT 1",
 
                        // Output message
                        LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_LOST_PASSWORD_SENT);
-               }
-                else
-               {
+               } else {
                        // No account found or not UNCONFIRMED
                        LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_LOST_PASSWORD_404);
                }
 
                // Free memory
                SQL_FREERESULT($result);
-       }
-        else
-       {
+       } else {
                // Load form
                LOAD_TEMPLATE("guest_sponsor_lost");
        }
-}
- elseif (isset($_POST['ok']))
-{
+} elseif (isset($_POST['ok'])) {
        // Check status and login data ...
        $result = SQL_QUERY_ESC("SELECT status FROM "._MYSQL_PREFIX."_sponsor_data
 WHERE id='%s' AND password='%s' LIMIT 1",
  array(bigintval($_POST['sponsorid']), md5($_POST['pass'])), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 1)
-       {
+       if (SQL_NUMROWS($result) == 1) {
                // Okay, first login data check passed, now has he/she an approved (CONFIRMED) account?
                list($status) = SQL_FETCHROW($result);
-               if ($status == "CONFIRMED")
-               {
+               if ($status == "CONFIRMED") {
                        // Calculate cookie lifetime, maybe we have to change this so the admin can setup a
                        // seperate timeout for these two cookies?
                        $life = (time() + $_CONFIG['online_timeout']);
@@ -263,13 +232,10 @@ WHERE id='%s' AND password='%s' LIMIT 1",
                        $login = ((setcookie("sponsorid"  , bigintval($_POST['sponsorid']), $life, COOKIE_PATH)) &&
                                  (setcookie("sponsorpass", md5($_POST['pass'])           , $life, COOKIE_PATH)));
 
-                       if ($login)
-                       {
+                       if ($login) {
                                // Cookie setup successfull so we can forward to sponsor area
                                LOAD_URL(URL."/modules.php?module=sponsor");
-                       }
-                        else
-                       {
+                       } else {
                                // Cookie setup failed!
                                LOAD_TEMPLATE("admin_settings_saved", false, SPONSPOR_COOKIE_SETUP_FAILED);
                                OUTPUT_HTML("<br />");
@@ -277,9 +243,7 @@ WHERE id='%s' AND password='%s' LIMIT 1",
                                // Login formular and other links
                                LOAD_TEMPLATE("guest_sponsor_login");
                        }
-               }
-                else
-               {
+               } else {
                        // Status is not fine
                        $content = constant('SPONSOR_LOGIN_FAILED_'.strtoupper($status).'');
                        LOAD_TEMPLATE("admin_settings_saved", false, $content);
@@ -288,9 +252,7 @@ WHERE id='%s' AND password='%s' LIMIT 1",
                        // Login formular and other links
                        LOAD_TEMPLATE("guest_sponsor_login");
                }
-       }
-        else
-       {
+       } else {
                // Account missing or wrong pass! We shall not find this out for the "hacker folks"...
                LOAD_TEMPLATE("admin_settings_saved", false, SPONSOR_LOGIN_FAILED_404_WRONG_PASS);
                OUTPUT_HTML("<br />");
@@ -301,9 +263,7 @@ WHERE id='%s' AND password='%s' LIMIT 1",
 
        // Free memory
        SQL_FREERESULT($result);
-}
- else
-{
+} else {
        // Login formular and other links
        LOAD_TEMPLATE("guest_sponsor_login");
 }