]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/sponsor_functions.php
Numerous ext-sponsor fixes and HTML rewrites (sorry for lame description)
[mailer.git] / inc / libs / sponsor_functions.php
index 99e88565e9076ff14fbd40fbd68f171dc4b64aa0..b4e78c2ae79908e69933c8073766fb723fb3fda3 100644 (file)
@@ -18,6 +18,7 @@
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -42,7 +43,7 @@ if (!defined('__SECURITY')) {
 }
 
 //
-function handlSponsorRequest (&$postData, $update=false, $messageArray=array(), $RET_STATUS=false) {
+function handleSponsorRequest ($postData, $update=false, $messageArray=array(), $RET_STATUS=false) {
        // Init a lot variables
        $SAVE = true;
        $UPDATE = false;
@@ -140,8 +141,8 @@ function handlSponsorRequest (&$postData, $update=false, $messageArray=array(),
                                $DATA['values'][] = bigintval(getRequestParameter('id'));
 
                                // Generate message
-                               $message = getMessageFromIndexedArray(getMessage('ADMIN_SPONSOR_UPDATED'), 'updated', $messageArray);
-                               $ret = "updated";
+                               $message = getMessageFromIndexedArray('{--ADMIN_SPONSOR_UPDATED--}', 'updated', $messageArray);
+                               $ret = 'updated';
                        } elseif (($ALREADY === false) || (($postData['force'] == 1) && (isAdmin()))) {
                                // Add new sponsor, first add more data
                                $DATA['keys'][] = 'sponsor_created'; $DATA['values'][] = time();
@@ -161,14 +162,14 @@ function handlSponsorRequest (&$postData, $update=false, $messageArray=array(),
                                }
 
                                // Implode all data into strings
-                               $KEYS   = implode("`, `"  , $DATA['keys']);
-                               $valueS = str_repeat("%s', '", count($DATA['values']) - 1);
+                               $keyArray   = implode('`, `'  , $DATA['keys']);
+                               $valueArray = str_repeat("%s', '", count($DATA['values']) - 1);
 
                                // Generate string
-                               $sql = "INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_data` (`".$KEYS."`) VALUES ('".$valueS."%s')";
+                               $sql = 'INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_data` (`' . $keyArray . "`) VALUES ('" . $valueArray . "%s')";
 
                                // Generate message
-                               $message = getMessageFromIndexedArray(getMessage('ADMIN_SPONSOR_ADDED'), "added", $messageArray);
+                               $message = getMessageFromIndexedArray('{--ADMIN_SPONSOR_ADDED--}', 'added', $messageArray);
                                $ret = 'added';
                        } elseif (($update === true) && (isAdmin())) {
                                // Add all data as hidden data
@@ -204,7 +205,7 @@ function handlSponsorRequest (&$postData, $update=false, $messageArray=array(),
                        } // END - if
                } else {
                        // Error found!
-                       $message = getMessageFromIndexedArray(getMessage('SPONSOR_DATA_NOT_SAVED'), 'failed', $messageArray);
+                       $message = getMessageFromIndexedArray('{--SPONSOR_DATA_NOT_SAVED--}', 'failed', $messageArray);
                        loadTemplate('admin_settings_saved', false, $message);
                }
 
@@ -215,16 +216,16 @@ function handlSponsorRequest (&$postData, $update=false, $messageArray=array(),
 //
 function sponsorTranslateUserStatus ($status) {
        // Construct constant name
-       $constantName = sprintf("ACCOUNT_%s", $status);
+       $constantName = sprintf("ACCOUNT_STATUS_%s", $status);
 
        // Is the constant there?
-       if (defined($constantName)) {
+       if (isMessageIdValid($constantName)) {
                // Then use it
-               $ret = constant($constantName);
+               $ret = getMessage($constantName);
        } else {
                // Not found!
                logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status));
-               $ret = getMaskedMessage('UNKNOWN_STATUS', $status);
+               $ret = getMaskedMessage('ACCOUNT_STATUS_UNKNOWN_STATUS', $status);
        }
        return $ret;
 }
@@ -242,7 +243,7 @@ function isSponsorRegisteredWithEmail ($email) {
 function isSponsor () {
        // Failed...
        $ret = false;
-       if ((isSessionVariableSet('sponsorid')) && (isSessionVariableSet('sponsorpass'))) {
+       if ((isSessionVariableSet('sponsor_id')) && (isSessionVariableSet('sponsorpass'))) {
                // Check cookies against database records...
                $result = SQL_QUERY_ESC("SELECT
        `id`
@@ -252,7 +253,7 @@ WHERE
        `id`='%s' AND `password`='%s' AND `status`='CONFIRMED'
 LIMIT 1",
                        array(
-                               bigintval(getSession('sponsorid')),
+                               bigintval(getSession('sponsor_id')),
                                getSession('sponsorpass')
                        ), __FUNCTION__, __LINE__);
                if (SQL_NUMROWS($result) == 1) {
@@ -271,22 +272,36 @@ LIMIT 1",
 //
 function addSponsorMenu ($current) {
        $OUT = '';
-       $WHERE = " AND active='Y'";
+       $WHERE = " AND `active`='Y'";
        if (isAdmin()) $WHERE = '';
 
        // Load main menu entries
-       $result_main = SQL_QUERY("SELECT action AS main_action, title AS main_title FROM `{?_MYSQL_PREFIX?}_sponsor_menu`
-WHERE (`what`='' OR `what` IS NULL) ".$WHERE."
-ORDER BY `sort`", __FUNCTION__, __LINE__);
-       if (SQL_NUMROWS($result_main) > 0) {
+       $result_main = SQL_QUERY("SELECT
+       `action` AS `main_action`, `title` AS `main_title`
+FROM
+       `{?_MYSQL_PREFIX?}_sponsor_menu`
+WHERE
+       (`what`='' OR `what` IS NULL)
+       " . $WHERE . "
+ORDER BY
+       `sort` ASC", __FUNCTION__, __LINE__);
+       if (!SQL_HASZERONUMS($result_main)) {
                // Load every menu and it's sub menus
                while ($content = SQL_FETCHARRAY($result_main)) {
                        // Load sub menus
-                       $result_sub = SQL_QUERY_ESC("SELECT what AS sub_what, title AS sub_title FROM `{?_MYSQL_PREFIX?}_sponsor_menu`
-WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$WHERE."
-ORDER BY `sort`",
+                       $result_sub = SQL_QUERY_ESC("SELECT
+       `what` AS `sub_what`, `title` AS `sub_title`
+FROM
+       `{?_MYSQL_PREFIX?}_sponsor_menu`
+WHERE
+       `action`='%s' AND
+       `what` != '' AND
+       `what` IS NOT NULL
+       " . $WHERE . "
+ORDER BY
+       `sort` ASC",
                        array($content['main_action']), __FUNCTION__, __LINE__);
-                       if (SQL_NUMROWS($result_sub) > 0) {
+                       if (!SQL_HASZERONUMS($result_sub)) {
                                // Load sub menus
                                $SUB = '';
                                while ($content2 = SQL_FETCHARRAY($result_sub)) {
@@ -294,7 +309,7 @@ ORDER BY `sort`",
                                        $content = merge_array($content, $content2);
 
                                        // Check if current selected menu is matching the loaded one
-                                       if ($current == $content['sub_what']) $content['sub_title'] = "<strong>".$content['sub_title']."</strong>";
+                                       if ($current == $content['sub_what']) $content['sub_title'] = '<strong>' . $content['sub_title'] . '</strong>';
 
                                        // Prepare data for the sub template
                                        $content = array(
@@ -316,7 +331,7 @@ ORDER BY `sort`",
                                $OUT .= loadTemplate('sponsor_action', true, $content);
                        } else {
                                // No sub menus active
-                               $OUT .= loadTemplate('admin_settings_saved', true, getMessage('SPONSOR_NO_SUB_MENUS_ACTIVE'));
+                               $OUT .= loadTemplate('admin_settings_saved', true, '{--SPONSOR_NO_SUB_MENUS_ACTIVE--}');
                        }
 
                        // Free memory
@@ -324,7 +339,7 @@ ORDER BY `sort`",
                }
        } else {
                // No main menus active
-               $OUT .= loadTemplate('admin_settings_saved', true, getMessage('SPONSOR_NO_MAIN_MENUS_ACTIVE'));
+               $OUT .= loadTemplate('admin_settings_saved', true, '{--SPONSOR_NO_MAIN_MENUS_ACTIVE--}');
        }
 
        // Free memory
@@ -362,7 +377,7 @@ function updateSponsorLogin () {
 SET `last_online`=UNIX_TIMESTAMP()
 WHERE `id`='%s' AND `password`='%s' LIMIT 1",
                        array(
-                               bigintval(getSession('sponsorid')),
+                               bigintval(getSession('sponsor_id')),
                                getSession('sponsorpass')
                        ), __FUNCTION__, __LINE__);
 
@@ -384,7 +399,7 @@ function saveSponsorData ($postData, $content) {
                        'ok', 'pass1', 'pass2');
 
        // Set default message ("not saved")
-       $message = getMessage('SPONSOR_ACCOUNT_DATA_NOT_SAVED');
+       $message = '{--SPONSOR_ACCOUNT_DATA_NOT_SAVED--}';
 
        // Check for submitted passwords
        if ((!empty($postData['pass1'])) && (!empty($postData['pass2']))) {
@@ -408,7 +423,7 @@ function saveSponsorData ($postData, $content) {
        $sql = "UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET";
        foreach ($postData as $key => $value) {
                // Mmmmm, too less security here???
-               $sql   .= " `".secureString($key)."`='%s',";
+               $sql   .= " `" . secureString($key) . "`='%s',";
 
                // We will secure this later inside the SQL_QUERY_ESC() function
                $DATA[] = secureString($value);
@@ -433,44 +448,42 @@ function saveSponsorData ($postData, $content) {
        $sql = substr($sql, 0, -1);
 
        // Add SQL tail data
-       $sql .= " WHERE `id`='%s' AND password='%s' LIMIT 1";
-       $DATA[] = bigintval(getSession('sponsorid'));
+       $sql .= " WHERE `id`=%s AND `password`='%s' LIMIT 1";
+       $DATA[] = bigintval(getSession('sponsor_id'));
        $DATA[] = getSession('sponsorpass');
 
        // Saving data was completed... ufff...
-       switch (getWhat())
-       {
+       switch (getWhat()) {
                case 'account': // Change account data
                        if ($EMAIL === true) {
-                               $message   = getMessage('SPONSOR_ACCOUNT_EMAIL_CHANGED');
-                               $templ = 'admin_sponsor_change_email';
-                               $subj  = getMessage('ADMIN_SPONSOR_ACC_EMAIL_SUBJ');
+                               $message = '{--SPONSOR_ACCOUNT_EMAIL_CHANGED--}';
+                               $templ   = 'admin_sponsor_change_email';
+                               $subj    = '{--ADMIN_SPONSOR_ACC_EMAIL_SUBJECT--}';
                        } else {
-                               $message   = getMessage('SPONSOR_ACCOUNT_DATA_SAVED');
-                               $templ = 'admin_sponsor_change_data';
-                               $subj  = getMessage('ADMIN_SPONSOR_ACC_DATA_SUBJ');
+                               $message = '{--SPONSOR_ACCOUNT_DATA_SAVED--}';
+                               $templ   = 'admin_sponsor_change_data';
+                               $subj    = '{--ADMIN_SPONSOR_ACC_DATA_SUBJECT--}';
                        }
                        break;
 
                case 'settings': // Change settings
-                       // Translate some data
-                       $content['receive']  = translateYesNo($content['receive_warnings']);
-                       $content['interval'] = createFancyTime($content['warning_interval']);
-
                        // Set message template and subject for admin
-                       $message   = getMessage('SPONSOR_SETTINGS_SAVED');
-                       $templ = 'admin_sponsor_settings';
-                       $subj  = getMessage('ADMIN_SPONSOR_SETTINGS_SUBJ');
+                       $message = '{--SPONSOR_SETTINGS_SAVED--}';
+                       $templ   = 'admin_sponsor_settings';
+                       $subj    = '{--ADMIN_SPONSOR_SETTINGS_SUBJECT--}';
                        break;
 
                default: // Unknown sponsor what value!
                        logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown sponsor module (what) %s detected.", getWhat()));
                        $message = getMaskedMessage('SPONSOR_UNKNOWN_WHAT', getWhat());
-                       $templ = ''; $subj = '';
+                       $templ   = '';
+                       $subj    = '';
                        break;
-       }
+       } // END - switch
 
+       // Has an entry updated?
        if (SQL_AFFECTEDROWS() == 1) {
+               // Template and subject are set?
                if (!empty($templ) && !empty($subj)) {
                        // Run SQL command and check for success
                        $result = SQL_QUERY_ESC($sql, $DATA, __FUNCTION__, __LINE__);
@@ -478,26 +491,21 @@ function saveSponsorData ($postData, $content) {
                        // Add all data to content
                        $content['new_data'] = $postData;
 
-                       // Change some data
-                       if (isset($content['gender']))             $content['gender']                  = translateGender($content['gender']);
-                       if (isset($content['new_data']['gender'])) $content['new_data']['gender']      = translateGender($content['new_data']['gender']);
-                       if (isset($content['receive_warnings']))   $content['new_data']['receive']     = translateYesNo($content['new_data']['receive_warnings']);
-                       if (isset($content['warning_interval']))   $content['new_data']['interval']    = createFancyTime($content['new_data']['warning_interval']);
-
                        // Send email to admins
                        sendAdminNotification($subj, $templ, $content);
 
                        // Shall we send mail to the sponsor's new email address?
                        if ($content['receive_warnings'] == 'Y') {
-                               // Okay send email with confirmation link to new address and with no confirmation link
-                               // to the old address
+                               /*
+                                * Okay send email with confirmation link to new address and with no confirmation link
+                                * to the old address.
+                                */
 
                                // First to old address
-                               switch (getWhat())
-                               {
+                               switch (getWhat()) {
                                        case 'account': // Change account data
                                                $email_msg = loadEmailTemplate('sponsor_change_data', $content);
-                                               sendEmail($content['email'], getMessage('SPONSOR_ACC_DATA_SUBJ'), $email_msg);
+                                               sendEmail($content['email'], '{--SPONSOR_ACC_DATA_SUBJECT--}', $email_msg);
 
                                                if ($EMAIL === true) {
                                                        // Add hash code to content array
@@ -505,16 +513,16 @@ function saveSponsorData ($postData, $content) {
 
                                                        // Second mail goes to the new address
                                                        $email_msg = loadEmailTemplate('sponsor_change_email', $content);
-                                                       sendEmail($content['email'], getMessage('SPONSOR_ACC_EMAIL_SUBJ'), $email_msg);
-                                               }
+                                                       sendEmail($content['email'], '{--SPONSOR_ACC_EMAIL_SUBJECT--}', $email_msg);
+                                               } // END - if
                                                break;
 
                                        case 'settings': // Change settings
                                                // Send email
                                                $email_msg = loadEmailTemplate('sponsor_settings', $content);
-                                               sendEmail($content['email'], getMessage('SPONSOR_SETTINGS_SUBJ'), $email_msg);
+                                               sendEmail($content['email'], '{--SPONSOR_SETTINGS_SUBJECT--}', $email_msg);
                                                break;
-                               }
+                               } // END - switch
                        } // END - if
                } // END - if
        } // END - if