]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/sponsor_functions.php
Mailer project rwritten:
[mailer.git] / inc / libs / sponsor_functions.php
index 3e5909476677b783bf26173550e8b80e698556aa..5e20e785c67d941876596340e745c91f13d9b3ab 100644 (file)
@@ -43,10 +43,10 @@ if (!defined('__SECURITY')) {
 //
 function handleSponsorRequest ($postData, $update=false, $messageArray = array(), $RET_STATUS=false) {
        // Init a lot variables
-       $SAVE = true;
-       $UPDATE = false;
-       $skip = false;
-       $ALREADY = false;
+       $SAVE = TRUE;
+       $UPDATE = FALSE;
+       $skip = FALSE;
+       $ALREADY = FALSE;
        $ret = 'unused';
 
        // Skip these entries
@@ -66,10 +66,10 @@ function handleSponsorRequest ($postData, $update=false, $messageArray = array()
                                // Check only posted input entries not the submit button
                                switch ($k) {
                                        case 'email':
-                                               $ALREADY = false;
+                                               $ALREADY = FALSE;
                                                if (!isEmailValid($v)) {
                                                        // Email address is not valid
-                                                       $SAVE = false;
+                                                       $SAVE = FALSE;
                                                } else {
                                                        // Add a new sponsor or update his data?
                                                        $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE email='%s' LIMIT 1",
@@ -80,10 +80,10 @@ function handleSponsorRequest ($postData, $update=false, $messageArray = array()
                                                                // Yes, he is!
                                                                if ((getWhat() == 'add_sponsor') || ($update)) {
                                                                        // Already found
-                                                                       $ALREADY = true;
+                                                                       $ALREADY = TRUE;
                                                                } else {
                                                                        // Update his data
-                                                                       $UPDATE = true;
+                                                                       $UPDATE = TRUE;
                                                                }
                                                        }
 
@@ -92,18 +92,18 @@ function handleSponsorRequest ($postData, $update=false, $messageArray = array()
                                                }
                                                break;
 
-                                       case 'pass1':
+                                       case 'password1':
                                                $k = ''; $v = '';
                                                break;
 
-                                       case 'pass2':
+                                       case 'password2':
                                                $k = 'password'; $v = md5($v);
                                                break;
 
                                        case 'url':
                                                if (!isUrlValid($v)) {
                                                        // Don't save the URL
-                                                       $SAVE = false;
+                                                       $SAVE = FALSE;
                                                } // END - if
                                                break;
 
@@ -113,7 +113,7 @@ function handleSponsorRequest ($postData, $update=false, $messageArray = array()
                                                break;
                                } // END - switch
 
-                               if ((!empty($k)) && ($skip == false)) {
+                               if ((!empty($k)) && ($skip == FALSE)) {
                                        // Add data
                                        array_push($DATA['keys']  , $k);
                                        array_push($DATA['values'], $v);
@@ -122,7 +122,7 @@ function handleSponsorRequest ($postData, $update=false, $messageArray = array()
                } // END - foreach
 
                // Save sponsor?
-               if ($SAVE === true) {
+               if ($SAVE === TRUE) {
                        // Default is no force even when a guest want to abuse this force switch
                        if ((empty($postData['force'])) || (!isAdmin())) $postData['force'] = '0';
 
@@ -144,10 +144,10 @@ function handleSponsorRequest ($postData, $update=false, $messageArray = array()
                                // Generate message
                                $message = getMessageFromIndexedArray('{--ADMIN_SPONSOR_UPDATED--}', 'updated', $messageArray);
                                $ret = 'updated';
-                       } elseif (($ALREADY === false) || (($postData['force'] == 1) && (isAdmin()))) {
+                       } elseif (($ALREADY === FALSE) || (($postData['force'] == 1) && (isAdmin()))) {
                                // Add new sponsor, first add more data
                                array_push($DATA['keys'], 'status');
-                               if (($update === true) && (isAdmin()) && (getWhat() == 'add_sponsor')) {
+                               if (($update === TRUE) && (isAdmin()) && (getWhat() == 'add_sponsor')) {
                                        // Only allowed for admin
                                        array_push($DATA['values'], 'PENDING');
 
@@ -174,7 +174,7 @@ function handleSponsorRequest ($postData, $update=false, $messageArray = array()
                                unset($DATA['values'][$key]);
 
                                // Implode all data into strings
-                               $keyArray   = implode('`,`'  , $DATA['keys']);
+                               $keyArray   = implode('`, `'  , $DATA['keys']);
                                $valueArray = str_repeat("%s', '", count($DATA['values']) - 1);
 
                                // Generate string
@@ -183,7 +183,7 @@ function handleSponsorRequest ($postData, $update=false, $messageArray = array()
                                // Generate message
                                $message = getMessageFromIndexedArray('{--ADMIN_SPONSOR_ADDED--}', 'added', $messageArray);
                                $ret = 'added';
-                       } elseif (($update === true) && (isAdmin())) {
+                       } elseif (($update === TRUE) && (isAdmin())) {
                                // Add all data as hidden data
                                $OUT = '';
                                foreach ($postData as $k => $v) {
@@ -198,7 +198,7 @@ function handleSponsorRequest ($postData, $update=false, $messageArray = array()
                                $content['email']  = $postData['email'];
 
                                // Ask for adding a sponsor with same email address
-                               loadTemplate('admin_add_sponsor_already', false, $content);
+                               loadTemplate('admin_add_sponsor_already', FALSE, $content);
                                return;
                        } else {
                                // Already added!
@@ -243,7 +243,7 @@ function translateSponsorStatus ($status) {
 // Search for an email address in the database
 function isSponsorRegisteredWithEmail ($email) {
        // Is there already the provided email address in database?
-       $ret = (countSumTotalData($email, 'sponsor_data', 'id', 'email', true) == 1);
+       $ret = (countSumTotalData($email, 'sponsor_data', 'id', 'email', TRUE) == 1);
 
        // Return result
        return $ret;
@@ -252,7 +252,7 @@ function isSponsorRegisteredWithEmail ($email) {
 // Wether the current user is a sponsor
 function isSponsor () {
        // Failed is default
-       $ret = false;
+       $ret = FALSE;
 
        // Determine it
        $ret = (
@@ -307,17 +307,17 @@ ORDER BY
                                        if ($current == $content2['sub_what']) $content2['sub_title'] = '<strong>' . $content2['sub_title'] . '</strong>';
 
                                        // Load row template
-                                       $SUB .= loadTemplate('sponsor_what', true, $content2);
+                                       $SUB .= loadTemplate('sponsor_what', TRUE, $content2);
                                } // END - while
 
                                // Prepare data for the main template
                                $content['menu'] = $SUB;
 
                                // Load menu template
-                               $OUT .= loadTemplate('sponsor_action', true, $content);
+                               $OUT .= loadTemplate('sponsor_action', TRUE, $content);
                        } else {
                                // No sub menus active
-                               $OUT .= displayMessage('{--SPONSOR_NO_SUB_MENUS_ACTIVE--}', true);
+                               $OUT .= displayMessage('{--SPONSOR_NO_SUB_MENUS_ACTIVE--}', TRUE);
                        }
 
                        // Free memory
@@ -325,7 +325,7 @@ ORDER BY
                } // END - while
        } else {
                // No main menus active
-               $OUT .= displayMessage('{--SPONSOR_NO_MAIN_MENUS_ACTIVE--}', true);
+               $OUT .= displayMessage('{--SPONSOR_NO_MAIN_MENUS_ACTIVE--}', TRUE);
        }
 
        // Free memory
@@ -347,7 +347,7 @@ function addSponsorContent ($what) {
                loadIncludeOnce($INC);
        } else {
                // File not found
-               $GLOBALS['sponsor_output'] .= displayMessage('{%message,SPONSOR_CONTENT_404=' . $what . '%}', true);
+               $GLOBALS['sponsor_output'] .= displayMessage('{%message,SPONSOR_CONTENT_404=' . $what . '%}', TRUE);
        }
 
        // Return content
@@ -357,7 +357,7 @@ function addSponsorContent ($what) {
 //
 function updateSponsorLogin () {
        // Failed by default
-       $login = false;
+       $login = FALSE;
 
        // Is sponsor?
        if (isSponsor()) {
@@ -385,22 +385,22 @@ LIMIT 1",
 
 // Saves sponsor's data
 function saveSponsorData ($postData, $content) {
-       $EMAIL = false;
+       $EMAIL = FALSE;
 
        // Unsecure data which we don't want
        $UNSAFE = array('password', 'id', 'remote_addr', 'sponsor_created', 'last_online', 'status', 'ref_count',
                        'points_amount', 'points_used', 'refid', 'hash', 'last_payment', 'last_currency',
-                       'pass_old', 'ok', 'pass1', 'pass2');
+                       'pass_old', 'ok', 'password1', 'password2');
 
        // Set default message ("not saved")
        $message = '{--SPONSOR_ACCOUNT_DATA_NOT_SAVED--}';
 
        // Check for submitted passwords
-       if ((!empty($postData['pass1'])) && (!empty($postData['pass2']))) {
+       if ((!empty($postData['password1'])) && (!empty($postData['password2']))) {
                // Are both passwords the same?
-               if ($postData['pass1'] == $postData['pass2']) {
-                       // Okay, then set password and remove pass1 and pass2
-                       $postData['password'] = md5($postData['pass1']);
+               if ($postData['password1'] == $postData['password2']) {
+                       // Okay, then set password and remove password1 and password2
+                       $postData['password'] = md5($postData['password1']);
                } // END - if
        } // END - if
 
@@ -427,7 +427,7 @@ function saveSponsorData ($postData, $content) {
        if ((!empty($content['email'])) && (!empty($postData['email']))) {
                if ($content['email'] != $postData['email']) {
                        // Change email address
-                       $EMAIL = true;
+                       $EMAIL = TRUE;
 
                        // Okay, has changed then add status with UNCONFIRMED and new hash code
                        $sql .= " `status`='EMAIL',`hash`='%s',";
@@ -451,7 +451,7 @@ function saveSponsorData ($postData, $content) {
        // Saving data was completed... ufff...
        switch (getWhat()) {
                case 'account': // Change account data
-                       if ($EMAIL === true) {
+                       if ($EMAIL === TRUE) {
                                $message = '{--SPONSOR_ACCOUNT_EMAIL_CHANGED--}';
                                $templ   = 'admin_sponsor_change_email';
                                $subject    = '{--ADMIN_SPONSOR_ACC_EMAIL_SUBJECT--}';
@@ -503,7 +503,7 @@ function saveSponsorData ($postData, $content) {
                                                $email_msg = loadEmailTemplate('sponsor_change_data', $content);
                                                sendEmail($content['email'], '{--SPONSOR_ACC_DATA_SUBJECT--}', $email_msg);
 
-                                               if ($EMAIL === true) {
+                                               if ($EMAIL === TRUE) {
                                                        // Add hash code to content array
                                                        $content['hash'] = $HASH;
 
@@ -565,7 +565,7 @@ function doProcessSponsorFormRequest ($messageArray = array()) {
        $message = '';
 
        // Handle the request
-       $status = handleSponsorRequest(postRequestArray(), true, $messageArray, true);
+       $status = handleSponsorRequest(postRequestArray(), TRUE, $messageArray, TRUE);
 
        // Check the status of the registration process
        switch ($status) {
@@ -584,7 +584,7 @@ function doProcessSponsorFormRequest ($messageArray = array()) {
                                $content['surname']   = postRequestElement('surname');
                                $content['family']    = postRequestElement('family');
                                $content['timestamp'] = generateDateTime(time(), 0);
-                               $content['password']  = postRequestElement('pass1');
+                               $content['password']  = postRequestElement('password1');
 
                                // Generate email and send it to the new sponsor
                                $message = loadEmailTemplate('sponsor_confirm', $content, $id);
@@ -667,20 +667,20 @@ function fetchSponsorData ($sponsor_id, $column = 'id') {
                setCurrentSponsorId($sponsor_id);
 
                // Don't look for invalid sponsor_ids...
-               if (!isValidUserId($sponsor_id)) {
+               if (!isValidId($sponsor_id)) {
                        // Invalid, so abort here
                        reportBug(__FUNCTION__, __LINE__, 'Sponsor id ' . $sponsor_id . ' is invalid.');
                } elseif (isSponsorDataValid()) {
                        // Use cache, so it is fine
-                       return true;
+                       return TRUE;
                }
        } elseif (isSponsorDataValid()) {
                // Use cache, so it is fine
-               return true;
+               return TRUE;
        }
 
        // By default none was found
-       $found = false;
+       $found = FALSE;
 
        // Extra statements
        $ADD = '';
@@ -750,7 +750,7 @@ function getFetchedSponsorData ($keyColumn, $sponsor_id, $valueColumn) {
                $data = '';
 
                // Can we fetch the sponsor data?
-               if ((isValidSponsorId($sponsor_id)) && (fetchSponsorData($sponsor_id, $keyColumn))) {
+               if ((isValidId($sponsor_id)) && (fetchSponsorData($sponsor_id, $keyColumn))) {
                        // Now get the data back
                        $data = getSponsorData($valueColumn);
                } // END - if
@@ -768,7 +768,7 @@ function getFetchedSponsorData ($keyColumn, $sponsor_id, $valueColumn) {
 // in, but you should use isMember() if you want to find that out.
 function isSponsorDataValid () {
        // Sponsor id should not be zero so abort here
-       if (!isCurrentSponsorIdSet()) return false;
+       if (!isCurrentSponsorIdSet()) return FALSE;
 
        // Is it cached?
        if (!isset($GLOBALS['is_sponsor_data_valid'][getCurrentSponsorId()])) {
@@ -803,25 +803,13 @@ function getCurrentSponsorId () {
 
 // Checks if current sponsor_id is set
 function isCurrentSponsorIdSet () {
-       return ((isset($GLOBALS['current_sponsor_id'])) && (isValidSponsorId($GLOBALS['current_sponsor_id'])));
-}
-
-// Is given sponsor_id valid?
-function isValidSponsorId ($sponsor_id) {
-       // Is there cache?
-       if (!isset($GLOBALS[__FUNCTION__][$sponsor_id])) {
-               // Check it out
-               $GLOBALS[__FUNCTION__][$sponsor_id] = ((!is_null($sponsor_id)) && (!empty($sponsor_id)) && ($sponsor_id > 0));
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__][$sponsor_id];
+       return ((isset($GLOBALS['current_sponsor_id'])) && (isValidId($GLOBALS['current_sponsor_id'])));
 }
 
 // Getter for sponsor data
 function getSponsorData ($column) {
        // Sponsor id should not be zero
-       if (!isValidUserId(getCurrentSponsorId())) {
+       if (!isValidId(getCurrentSponsorId())) {
                reportBug(__FUNCTION__, __LINE__, 'Sponsor id is zero.');
        } // END - if