Some SQL queries improved, sponsor registration fixed:
authorRoland Häder <roland@mxchange.org>
Fri, 23 Jul 2010 05:13:27 +0000 (05:13 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 23 Jul 2010 05:13:27 +0000 (05:13 +0000)
- Some SQL queries improved by removed single quotes around data that are
  numbers. This may help MySQL to improve speed of the query
- Sponsor registration from admin (and possibly guest) area was broken
- TODOs.txt updated

14 files changed:
DOCS/TODOs.txt
inc/language/de.php
inc/language/sponsor_de.php
inc/libs/sponsor_functions.php
inc/modules/admin/what-del_sponsor.php
inc/modules/admin/what-edit_sponsor.php
inc/modules/admin/what-list_sponsor.php
inc/modules/admin/what-list_sponsor_pay.php
inc/modules/admin/what-list_sponsor_pays.php
inc/modules/admin/what-lock_sponsor.php
inc/modules/admin/what-unlock_sponsor.php
inc/modules/guest/what-sponsor_login.php
inc/modules/sponsor/account.php
templates/de/html/admin/admin_list_sponsor.tpl

index fd9e0f4c99ce604f362a111cb03c6bdb99df7a4d..4ad4a8c4051930eb9aad12576556ecc3397ce56e 100644 (file)
 ./inc/functions.php:2251:      // @TODO This is still very static, rewrite it somehow
 ./inc/gen_sql_patches.php:96:// @TODO Rewrite this to a filter
 ./inc/install-functions.php:59:        // @TODO DEACTIVATED: changeDataInFile(getCachePath() . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0);
-./inc/language/de.php:1118:// @TODO Rewrite these two constants
-./inc/language/de.php:1133:// @TODO Rewrite these three constants
+./inc/language/de.php:1119:// @TODO Rewrite these two constants
+./inc/language/de.php:1134:// @TODO Rewrite these three constants
 ./inc/language/de.php:300:     // @TODO Following two are unused?
-./inc/language/de.php:810:// @TODO Are these constants longer used?
+./inc/language/de.php:811:// @TODO Are these constants longer used?
 ./inc/language-functions.php:234:      // @TODO These are all valid languages, again hard-coded
 ./inc/language-functions.php:46:// @TODO Rewrite all language constants to this function.
 ./inc/language/rallye_de.php:13: * @TODO Naming convention not applied for language strings             *
 ./inc/modules/member/what-unconfirmed.php:143: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
 ./inc/modules/order.php:76:            // @TODO Unused: 2,4
 ./inc/monthly/monthly_bonus.php:69:    // @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1171:  // @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1418:                  // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
-./inc/mysql-manager.php:1516:  // @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1883:                  // @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1927:// @TODO Fix inconsistency between last_module and getWhat()
+./inc/mysql-manager.php:1170:  // @TODO Rewrite this to a filter
+./inc/mysql-manager.php:1417:                  // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
+./inc/mysql-manager.php:1515:  // @TODO Rewrite this to a filter
+./inc/mysql-manager.php:1882:                  // @TODO Rewrite this to a filter
+./inc/mysql-manager.php:1926:// @TODO Fix inconsistency between last_module and getWhat()
 ./inc/mysql-manager.php:370:   // @TODO Try to rewrite this to one or more functions
 ./inc/mysql-manager.php:46:// @TODO Can we cache this?
 ./inc/reset/reset_beg.php:51:// @TODO This should be converted in a daily beg rallye
index 8009cd2560b44134da16de62fd76201fcbf011b9..0a5a11b69f36a170ef173abd94a6053106444497 100644 (file)
@@ -489,6 +489,7 @@ addMessages(array(
        'ACCOUNT_STATUS_CONFIRMED' => "<span class=\"admin_green\">Best&auml;tigt</span>",
        'ACCOUNT_STATUS_LOCKED' => "<span class=\"admin_failed\">Gesperrt</span>",
        'ACCOUNT_STATUS_DELETED' => "<span class=\"admin_failed\">Gel&ouml;scht</span>",
+       'ACCOUNT_STATUS_PENDING' => "<span class=\"admin_failed\">Wartend</span>",
        'ADMIN_ALL_ACCOUNTS' => "Alle Mitglieder-Accounts auflisten",
        'ADMIN_NO_NONE_REGISTERED' => "Ihre Suchkriterieren ergaben keine Treffer in der Mitgliederliste. ",
        'ADMIN_MEMBER_404' => "Mitglieds-Account <span class=\"data\">%s</span> existiert nicht.",
index e46519d769ed1dc4956fc6ac8772fc1218a85416..ffeceaf3187590553e8c576f23dbd91cac2c397f 100644 (file)
@@ -136,6 +136,7 @@ addMessages(array(
        'GUEST_SPONSOR_RECEIVE_WARNINGS' => "Bei Daten&auml;nderung eine Best&auml;tigung per Mail erhalten?",
        'SPONSOR_ACCEPT_TERMS' => "Ich/wir habe/n die [<strong><a href=\"{%url=modules.php?module=index&amp;what=sponsor_agb%}\" target=\"_blank\">AGBs</a></strong>] gelesen und akzeptiert.",
        'SPONSOR_TERMS_HEADER' => "Allgemeine Gesch&auml;ftsbedingungen",
+       'ADMIN_SPONSOR_ACCOUNT_404_ALREADY_CONFIRMED' => "Das von Ihnen angegebene Sponsoraccount <span class=\"data\">%s</span> konnte entweder nicht gefunden werden, oder ist bereits freigegeben.",
 
 // Add payment types
        'ADMIN_SPONSOR_NO_PAYTYPES' => "Noch keine Buchungspakete eingerichtet.",
index a625a5517e9fca8dc6f41e5a69917d8ef8d4f9c7..46e4a13b0f7c3541ae61fb1429bf914551ef35a2 100644 (file)
@@ -137,7 +137,7 @@ function handleSponsorRequest ($postData, $update=false, $messageArray=array(),
                                }
 
                                // Remove last ", " from SQL string
-                               $sql = substr($sql, 0, -2)." WHERE `id`='%s' LIMIT 1";
+                               $sql = substr($sql, 0, -2)." WHERE `id`=%s LIMIT 1";
                                $DATA['values'][] = bigintval(getRequestParameter('id'));
 
                                // Generate message
@@ -259,7 +259,7 @@ function isSponsor () {
 FROM
        `{?_MYSQL_PREFIX?}_sponsor_data`
 WHERE
-       `id`='%s' AND `password`='%s' AND `status`='CONFIRMED'
+       `id`=%s AND `password`='%s' AND `status`='CONFIRMED'
 LIMIT 1",
                        array(
                                bigintval(getSession('sponsor_id')),
@@ -382,9 +382,14 @@ function updateSponsorLogin () {
        // Is sponsor?
        if (isSponsor()) {
                // Update last online timestamp
-               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data`
-SET `last_online`=UNIX_TIMESTAMP()
-WHERE `id`='%s' AND `password`='%s' LIMIT 1",
+               SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_sponsor_data`
+SET
+       `last_online`=UNIX_TIMESTAMP()
+WHERE
+       `id`=%s AND
+       `password`='%s'
+LIMIT 1",
                        array(
                                bigintval(getSession('sponsor_id')),
                                getSession('sponsorpass')
index 633a7c79bc637c90df3fdce967f1ab11f655294b..f54fd3141b1a41fa7a6f76ffec77f7b325f96b32 100644 (file)
@@ -47,7 +47,7 @@ addMenuDescription('admin', __FILE__);
 
 if (isGetRequestParameterSet('id')) {
        // Check for selected sponsor
-       $result = SQL_QUERY_ESC("SELECT email, gender, surname, family FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`='%s' LIMIT 1",
+       $result = SQL_QUERY_ESC("SELECT `id`, `email`, `gender`, `surname`, `family` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`=%s LIMIT 1",
                array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) == 1) {
                // Remove sponsor
@@ -64,7 +64,7 @@ if (isGetRequestParameterSet('id')) {
                        sendEmail($content['email'], '{--ADMIN_SPONSOR_DELETE_SUBJECT--}', $message);
 
                        // Remove account
-                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`='%s' LIMIT 1",
+                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`=%s LIMIT 1",
                                array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
 
                        // Remove orders
index 88625c21bac22317cb1e70ca0d8f352d1fa3f0c2..04707bc3c13dd5e7644ee9d67d67394eba9f9dc3 100644 (file)
@@ -40,7 +40,7 @@
 // Some security stuff...
 if ((!defined('__SECURITY')) || (!isAdmin())) {
        die();
-}
+} // END - if
 
 // Add description as navigation point
 addMenuDescription('admin', __FILE__);
@@ -48,14 +48,14 @@ addMenuDescription('admin', __FILE__);
 if ((isGetRequestParameterSet('id')) && (isGetRequestParameterSet('mode'))) {
        // Check for selected sponsor
        $result_main = SQL_QUERY_ESC("SELECT
-       `company`, `position`, `gender`, `surname`, `family`,
+       `id`, `company`, `position`, `gender`, `surname`, `family`,
        `street_nr1`, `street_nr2`, `zip`, `city`, `country`,
        `phone`, `fax`, `cell`, `email`, `url`, `tax_ident`,
        `receive_warnings`, `warning_interval`
 FROM
        `{?_MYSQL_PREFIX?}_sponsor_data`
 WHERE
-       `id`='%s'
+       `id`=%s
 LIMIT 1",
                array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
        if (SQL_NUMROWS($result_main) == 1) {
@@ -63,9 +63,6 @@ LIMIT 1",
                $content = SQL_FETCHARRAY($result_main);
 
                // Prepare all data for the template
-               //  Sponsor's id
-               $content['id'] = bigintval(getRequestParameter('id'));
-
                // Init gender
                foreach (array('m', 'f', 'c') as $gender) {
                        $content['gender_' . $gender] = '';
@@ -92,7 +89,7 @@ LIMIT 1",
                                                $points = bigintval(convertCommaToDot(postRequestParameter('points')));
 
                                                // Add points to account
-                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_amount`=`points_amount`+%s WHERE `id`='%s' LIMIT 1",
+                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_amount`=`points_amount`+%s WHERE `id`=%s LIMIT 1",
                                                        array($points, bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
 
                                                // Remember points /reason for the template
@@ -115,7 +112,7 @@ LIMIT 1",
                                                $points = bigintval(convertCommaToDot(postRequestParameter('points')));
 
                                                // Add points to account
-                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_used`=`points_used`+%s WHERE `id`='%s' LIMIT 1",
+                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_used`=`points_used`+%s WHERE `id`=%s LIMIT 1",
                                                        array($points, bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
 
                                                // Remember points /reason for the template
@@ -171,10 +168,10 @@ LIMIT 1",
                        } // END - if
                } elseif (isFileReadable(sprintf("%stemplates/%s/html/admin/%s.tpl", getPath(), getLanguage(), $TPL))) {
                        // Create mailto link
-                       $content['contact'] = '<a href="' . generateEmailLink($content['email'], 'sponsor_data') . '">' . $content['surname'] . ' ' . $content['family'] . '</a>';
+                       $content['contact'] = '<a href="' . generateSponsorEmailLink($content['email'], 'sponsor_data') . '">' . $content['surname'] . ' ' . $content['family'] . '</a>';
 
                        // Load mode template
-                       loadTemplate($TPL);
+                       loadTemplate($TPL, false, $content);
                } else {
                        // Template not found!
                        loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_MODUS_TPL_404', getRequestParameter('mode')));
index 86e1357a62eccc108fcb7a4ed00890c5f8c87bab..864e6fe6fdbdd50371159856e85019ba915c6d2c 100644 (file)
@@ -90,7 +90,7 @@ WHERE
        SQL_FREERESULT($result);
 } elseif (isGetRequestParameterSet('refid')) {
        // Search for sponsor
-       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`='%s' LIMIT 1",
+       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`=%s LIMIT 1",
                array(bigintval(getRequestParameter('refid'))), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) == 1) {
                // Free memory
index dee8f22e8c23bfecee08533590b697127b7622c3..75dea69fb2d7431f5321fd923c246d5dcdcbb86b 100644 (file)
@@ -80,7 +80,7 @@ SET
        `pay_min_count`='%s',
        `pay_currency`='%s'
 WHERE
-       `id`='%s'
+       `id`=%s
 LIMIT 1",
                        array(
                                postRequestParameter('name', $id),
@@ -97,7 +97,7 @@ LIMIT 1",
                // Remove entries here...
                foreach (postRequestParameter('id') as $id => $sel) {
                        // Remove entry
-                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `id`='%s' LIMIT 1",
+                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_sponsor_paytypes` WHERE `id`=%s LIMIT 1",
                                array(bigintval($id)), __FILE__, __LINE__);
                }
 
index c9d3dc3c10783d15bb6c3cb3f4aee4ed6fda1078..71df7ec45504b37c4060694a1310798827a8c2ed 100644 (file)
@@ -47,7 +47,7 @@ addMenuDescription('admin', __FILE__);
 
 if (isGetRequestParameterSet('id')) {
        // Check for selected sponsor
-       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`='%s' LIMIT 1",
+       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`=%s LIMIT 1",
        array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) == 1) {
                // ...
index b62ee795c8e7ef91a9d5fd9c33f31319cb3d21a9..92487401521b161fecb0027c49caf872613bb19c 100644 (file)
@@ -48,7 +48,7 @@ $message = '';
 
 if (isGetRequestParameterSet('id')) {
        // Check for selected sponsor
-       $result_sponsor = SQL_QUERY_ESC("SELECT `gender`, `surname`, `family`, `email`, `status` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`='%s' LIMIT 1",
+       $result_sponsor = SQL_QUERY_ESC("SELECT `gender`, `surname`, `family`, `email`, `status` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`=%s LIMIT 1",
                array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
        if (SQL_NUMROWS($result_sponsor) == 1) {
                // Get sponsor's current status and let only confirmed and locked status pass
@@ -80,7 +80,7 @@ if (isGetRequestParameterSet('id')) {
                                sendEmail($content['email'], $subject, $message);
 
                                // Update sponsor's account
-                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `status`='%s' WHERE `id`='%s' LIMIT 1",
+                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `status`='%s' WHERE `id`=%s LIMIT 1",
                                        array($content['status'], bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
                        } elseif (isPostRequestParameterSet('no')) {
                                // No don't lock / unlock now!
index 3bff5d845507dca7938ad6947a2e7e8355720a55..f1ec7f1407b60895eca708a3b8ef32bcf6c6da8b 100644 (file)
@@ -59,19 +59,23 @@ if (isFormSent()) {
 
                        // Load his personal data
                        $result_main = SQL_QUERY_ESC("SELECT
-       `gender`, `surname`, `family`, `email`, `remote_addr`, `sponsor_created`, `points_amount`, `refid`
+       `id`, `gender`, `surname`, `family`, `email`, `remote_addr`, `sponsor_created`, `points_amount`, `points_used`, `refid`
 FROM
        `{?_MYSQL_PREFIX?}_sponsor_data`
 WHERE
-       `status`='PENDING' AND
+       `status` IN('PENDING','UNCONFIRMED') AND
        `id`=%s
 LIMIT 1",
                        array($content['id']), __FILE__, __LINE__);
 
+                       /// Is there an entry?
                        if (SQL_NUMROWS($result_main) == 1) {
                                // Load data
                                $content = SQL_FETCHARRAY($result_main);
 
+                               // Add total amount
+                               $content['points'] = ($content['points_amount'] - $content['points_used']);
+
                                // Check for open payments and close them
                                $result = SQL_QUERY_ESC("SELECT
        so.admin_id, so.pay_count, so.pay_ordered, so.pay_status,
@@ -118,6 +122,10 @@ ORDER BY
 
                                // Free memory
                                SQL_FREERESULT($result);
+                       } else {
+                               // Not found
+                               loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_ACCOUNT_404_ALREADY_CONFIRMED', $content['id']));
+                               return;
                        }
 
                        // Free memory
@@ -130,7 +138,7 @@ SET
        `status`='CONFIRMED'
 WHERE
        `id`=%s AND
-       `status`='PENDING'
+       `status` IN('PENDING','UNCONFIRMED')
 LIMIT 1",
                        array($content['id']), __FILE__, __LINE__);
 
@@ -189,7 +197,7 @@ $result = SQL_QUERY("SELECT
 FROM
        `{?_MYSQL_PREFIX?}_sponsor_data`
 WHERE
-       `status`='PENDING' OR `status`='UNCONFIRMED'
+       `status` IN('PENDING','UNCONFIRMED')
 ORDER BY
        `id`", __FILE__, __LINE__);
 
index f93c825652987f2ef015a1e1b8b59fbb6ac2c8db..54fa6cd0d43dc2eb275fcd74bf04f0572b2f9db3 100644 (file)
@@ -115,7 +115,7 @@ LIMIT 1",
 SET
        `status`='CONFIRMED'
 WHERE
-       `id`='%s' AND
+       `id`=%s AND
        `hash`='%s' AND
        `status`='EMAIL'
 LIMIT 1",
@@ -194,9 +194,15 @@ WHERE email='%s' AND (`status`='UNCONFIRMED' OR `status`='EMAIL') LIMIT 1",
 
        if (isFormSent()) {
                // 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",
+               $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(postRequestParameter('email'), bigintval(postRequestParameter('id'))), __FILE__, __LINE__);
 
                // Entry found?
index 84204e4336aa0b25a1d9d5348700fb7a1a40e55b..e76cdacf095c69993abaa7387b61877576e9805d 100644 (file)
@@ -58,7 +58,7 @@ $result = SQL_QUERY_ESC("SELECT
 FROM
        `{?_MYSQL_PREFIX?}_sponsor_data`
 WHERE
-       `id`='%s' AND
+       `id`=%s AND
        `password`='%s'
 LIMIT 1",
        array(
index bc2f9e28168e5dc5cd97a37d2082f23ecfff2edd..ca46e83b1e95c7ef94c4ba5ab796db78296b33ec 100644 (file)
@@ -1,3 +1,4 @@
+<div align="center">
 <form accept-charset="utf-8" action="{%url=modules.php?module=admin&amp;what=list_sponsor%}" method="post">
 <table border="0" cellspacing="0" cellpadding="0" class="admin_table dashed" align="center">
 <tr>
@@ -13,3 +14,4 @@ $content
 </tr>
 </table>
 </form>
+</div>