More rewrites/fixes (not all is fixed) for ext-sponsor
[mailer.git] / inc / libs / sponsor_functions.php
index 46e4a13b0f7c3541ae61fb1429bf914551ef35a2..37c66b190c81df5ad65a370cc0d73da52859b12f 100644 (file)
@@ -250,29 +250,15 @@ function isSponsorRegisteredWithEmail ($email) {
 
 // Wether the current user is a sponsor
 function isSponsor () {
-       // Failed...
+       // Failed is default
        $ret = false;
-       if ((isSessionVariableSet('sponsor_id')) && (isSessionVariableSet('sponsorpass'))) {
-               // Check cookies against database records...
-               $result = SQL_QUERY_ESC("SELECT
-       `id`
-FROM
-       `{?_MYSQL_PREFIX?}_sponsor_data`
-WHERE
-       `id`=%s AND `password`='%s' AND `status`='CONFIRMED'
-LIMIT 1",
-                       array(
-                               bigintval(getSession('sponsor_id')),
-                               getSession('sponsorpass')
-                       ), __FUNCTION__, __LINE__);
-               if (SQL_NUMROWS($result) == 1) {
-                       // All is fine
-                       $ret = true;
-               } // END - if
 
-               // Free memory
-               SQL_FREERESULT($result);
-       } // END - if
+       // Determine it
+       $ret = (
+               (isSessionVariableSet('sponsor_id')) &&
+               (isSessionVariableSet('sponsorpass')) &&
+               (fetchSponsorData(getSession('sponsor_id')))
+       );
 
        // Return status
        return $ret;
@@ -331,10 +317,7 @@ ORDER BY
                                }
 
                                // Prepare data for the main template
-                               $content = array(
-                                       'title' => $content['main_title'],
-                                       'menu'  => $SUB
-                               );
+                               $content['menu'] = $SUB;
 
                                // Load menu template
                                $OUT .= loadTemplate('sponsor_action', true, $content);
@@ -360,18 +343,21 @@ ORDER BY
 
 //
 function addSponsorContent ($what) {
-       $OUT = '';
+       // Init sponsor content
+       $GLOBALS['sponsor_output'] = '';
+
+       // Generate IFN (Include FileName)
        $INC = sprintf("inc/modules/sponsor/%s.php", $what);
        if (isIncludeReadable($INC)) {
-               // Every sponsor action will output nothing directly. It will be written into $OUT!
+               // Every sponsor action will output nothing directly. It will be written into $GLOBALS['sponsor_output']!
                loadIncludeOnce($INC);
        } else {
                // File not found!
-               $OUT .= loadTemplate('admin_settings_saved', true, getMaskedMessage('SPONSOR_CONTENT_404', $what));
+               $GLOBALS['sponsor_output'] .= loadTemplate('admin_settings_saved', true, getMaskedMessage('SPONSOR_CONTENT_404', $what));
        }
 
        // Return content
-       return $OUT;
+       return $GLOBALS['sponsor_output'];
 }
 
 //
@@ -397,7 +383,7 @@ LIMIT 1",
 
                // This update went fine?
                $login = (SQL_AFFECTEDROWS() == 1);
-       }
+       } // END - if
 
        // Return status
        return $login;
@@ -844,5 +830,14 @@ function getSponsorData ($column) {
        return $GLOBALS['sponsor_data'][getCurrentSponsorId()][$column];
 }
 
+// Determines the country of the given sponsor id
+function determineSponsorCountry ($sponsor_id) {
+       // Then handle it over
+       $country = getSponsorData('country');
+
+       // Return it
+       return $country;
+}
+
 // [EOF]
 ?>