Extension ext-network continued:
authorRoland Häder <roland@mxchange.org>
Thu, 11 Aug 2011 23:28:51 +0000 (23:28 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 11 Aug 2011 23:28:51 +0000 (23:28 +0000)
- Saving of network API configuration data basicly finished
- Function getUpdateSqlFromArray() introduced which "converts" an array (both
  one- and two-dimensional) into an SQL query for updating database tables
- TODOs.txt updated

DOCS/TODOs.txt
inc/language/network_de.php
inc/libs/admins_functions.php
inc/libs/network_functions.php
inc/mysql-manager.php
inc/sql-functions.php
templates/de/html/admin/admin_config_network.tpl

index 01cc2f6b5b7cec0a6b89da41262e4ce5ac8ca76e..3bcfe9778d4f446af26386721b4ca7d86085ff71 100644 (file)
@@ -63,7 +63,7 @@
 ./inc/language/rallye_de.php:13: * @TODO Naming convention not applied for language strings             *
 ./inc/language/refback_de.php:53:      // @TODO Rewrite these constants to one
 ./inc/language/sponsor_de.php:117:// @TODO Rewrite these four constants to one and use sprintf()
-./inc/libs/admins_functions.php:508:           // @TODO This can be, somehow, rewritten
+./inc/libs/admins_functions.php:486:           // @TODO This can be, somehow, rewritten
 ./inc/libs/bonus_functions.php:194:            // @TODO Move this HTML to a template
 ./inc/libs/doubler_functions.php:44:// @TODO Lame description
 ./inc/libs/doubler_functions.php:93:                   // @TODO Can't this be moved into EL?
index 7ce05cb335e58d46ed442d9218fcd405b63e1158..6d1b077da8ebaf297b0f44f4ad0c5a1cc792c7e5 100644 (file)
@@ -210,6 +210,8 @@ addMessages(array(
        'ADMIN_CONFIG_NETWORK_TITLE' => "Einrichtung des API-Zugangs zum Werbenetzwerk <span class=\"data\">%s</span>:",
        'ADMIN_CONFIG_NETWORK_SAVE_BUTTON' => "API-Konfiguration speichern",
        'ADMIN_CONFIG_NETWORK_NOTE' => "Tragen Sie hier Ihre Interface-Zugangsdaten zum angzeigten Werbenetzwerk ein.",
+       'ADMIN_NETWORK_API_CONFIG_SAVED' => "API-Konfiguration gespeichert.",
+       'ADMIN_NETWORK_API_CONFIG_NOT_SAVED' => "API-Konfiguration NICHT gespeichert (keine &Auml;nderungen).",
        // Error codes
        'ADMIN_NETWORK_AFF_ID_PASS_WRONG_ERROR_CODE' => "Affiliate-Id oder -Passwort falsch",
        'ADMIN_NETWORK_SITE_ID_NOT_ASSIGNED_ERROR_CODE' => "Seiten-Id nicht zugewiesen/ung&uuml;ltig",
index 407308222aa1bd1ef4551b88dd9f13fe86f263a8..0fad9b6657952468158c087573f4c07313a7635f 100644 (file)
@@ -277,28 +277,7 @@ LIMIT 1",
                        }
                } else {
                        // Update whole array
-                       $SQL = 'UPDATE `{?_MYSQL_PREFIX?}_admins` SET ';
-                       foreach ($postData as $entry => $value) {
-                               // Skip login/id entry
-                               if (in_array($entry, array('login', 'id'))) {
-                                       continue;
-                               } // END - if
-
-                               // Do we have a non-string (e.g. number, NULL, NOW() or back-tick at the beginning?
-                               if (is_null($value[$id])) {
-                                       // NULL detected
-                                       $SQL .= '`' . $entry . '`=NULL, ';
-                               } elseif ((bigintval($value[$id], true, false) === $value[$id]) || ($value[$id] == 'NOW()') || (substr($value[$id], 0, 1) == '`'))  {
-                                       // No need for ticks (')
-                                       $SQL .= '`' . $entry . '`=' . $value[$id] . ', ';
-                               } else {
-                                       // Strings need ticks (') around them
-                                       $SQL .= '`' . $entry . "`='" . SQL_ESCAPE($value[$id]) . "', ";
-                               }
-                       } // END - foreach
-
-                       // Remove last 2 chars and finish query
-                       $SQL = substr($SQL, 0, -2) . ' WHERE `id`=%s LIMIT 1';
+                       $SQL = getUpdateSqlFromArray($postData, 'admins', 'id', '%s', array('login', 'id'), $id);
 
                        // Run it
                        SQL_QUERY_ESC($SQL, array(bigintval($id)), __FUNCTION__, __LINE__);
@@ -314,11 +293,10 @@ LIMIT 1",
                }
        } // END - foreach
 
-       // Display message
-       if (!empty($message)) {
-               if ($displayMessage === true) {
-                       displayMessage($message);
-               } // END - if
+       // Display message if not empty and allowed
+       if ((!empty($message)) && ($displayMessage === true)) {
+               // Display it
+               displayMessage($message);
        } // END - if
 
        // Remove cache file
index f57c5831a77c2db32d66616b5744c6d309054b49..60e4740d89f1023004747954a756cb5a007ec008 100644 (file)
@@ -1268,7 +1268,7 @@ function doAdminNetworkProcessAddNetworkApiTranslation () {
 
        // Add sorting
        setPostRequestElement('sort', (countSumTotalData(
-               postRequestElement('network_id'),
+               bigintval(postRequestElement('network_id')),
                'network_api_translation',
                'network_api_id',
                'network_id',
@@ -1295,6 +1295,51 @@ function doAdminNetworkProcessAddNetworkApiTranslation () {
        }
 }
 
+// Adds/update network API configuration
+function doAdminNetworkProcessConfigNetwork () {
+       // Check for an entry in network_config
+       $entryCount = countSumTotalData(
+               bigintval(getRequestElement('network')),
+               'network_config',
+               'network_id',
+               'network_id',
+               true
+       );
+
+       // Remove the 'ok' part
+       unsetPostRequestElement('ok');
+
+       // Add id
+       setPostRequestElement('network_id', bigintval(getRequestElement('network')));
+
+       // Is there already an entry?
+       if ($entryCount == 1) {
+               // Generate SQL query
+               $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_config', 'network_id', postRequestElement('network_id'), array('network_id'));
+       } else {
+               // Insert new entry
+               $SQL = 'INSERT INTO
+       `{?_MYSQL_PREFIX?}_network_config`
+(
+       `' . implode('`,`', array_keys(postRequestArray())) . "`
+) VALUES (
+       '" . implode("','", array_values(postRequestArray())) . "'
+)";
+       }
+
+       // Run the query
+       SQL_QUERY($SQL, __FUNCTION__, __LINE__);
+
+       // Output message
+       if (!SQL_HASZEROAFFECTED()) {
+               // Successfully added
+               displayMessage('{--ADMIN_NETWORK_API_CONFIG_SAVED--}');
+       } else {
+               // Not added
+               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_API_CONFIG_NOT_SAVED--}');
+       }
+}
+
 // Do expression code for this extension
 function doExpressionNetwork ($data) {
        // Construct replacer
index a9733b4ec1489db3e08ea1f4dbba5cdd434320e9..ea9b13067156df3c932a3cc407b376441c618014 100644 (file)
@@ -959,14 +959,14 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
                // Count or sum whole table?
                if ($countRows === true) {
                        // Count whole table
-                       $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`".$add,
+                       $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`" . $add . ' LIMIT 1',
                                array(
                                        $lookFor,
                                        $tableName
                                ), __FUNCTION__, __LINE__);
                } else {
                        // Sum whole table
-                       $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`".$add,
+                       $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`" . $add . ' LIMIT 1',
                                array(
                                        $lookFor,
                                        $tableName
@@ -975,7 +975,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
        } elseif (($countRows === true) || ($lookFor == 'userid')) {
                // Count rows
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'COUNT!');
-               $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'".$add,
+               $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'" . $add . ' LIMIT 1',
                        array(
                                $lookFor,
                                $tableName,
@@ -986,7 +986,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
        } else {
                // Add all rows
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SUM!');
-               $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'".$add,
+               $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'" . $add . ' LIMIT 1',
                        array(
                                $lookFor,
                                $tableName,
index 6e6e3bd28dfb5953fdb58ab75b157e791df9ed81..6298ed43f4efc2bd3569d26379773302e4fc7766 100644 (file)
@@ -124,5 +124,52 @@ function isSqlsValid () {
        );
 }
 
+// Generates an updating SQL query from given array
+function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $excludedFields, $multiDimId = NULL) {
+       // Begin SQL query
+       $SQL = 'UPDATE `{?_MYSQL_PREFIX?}_' . $tableName . '` SET ';
+
+       // Insert all data
+       foreach ($array as $entry => $value) {
+               // Skip login/id entry
+               if (in_array($entry, $excludedFields)) {
+                       continue;
+               } // END - if
+
+               // Do we have a non-string (e.g. number, NULL, NOW() or back-tick at the beginning?
+               if (is_null($multiDimId)) {
+                       // Handle one-dimensional data
+                       if (is_null($value)) {
+                               // NULL detected
+                               $SQL .= '`' . $entry . '`=NULL, ';
+                       } elseif ((bigintval($value, true, false) === $value) || ($value == 'NOW()') || (substr($value, 0, 1) == '`'))  {
+                               // No need for ticks (')
+                               $SQL .= '`' . $entry . '`=' . $value . ', ';
+                       } else {
+                               // Strings need ticks (') around them
+                               $SQL .= '`' . $entry . "`='" . SQL_ESCAPE($value) . "', ";
+                       }
+               } else {
+                       // Handle multi-dimensional data
+                       if (is_null($value[$multiDimId])) {
+                               // NULL detected
+                               $SQL .= '`' . $entry . '`=NULL, ';
+                       } elseif ((bigintval($value[$multiDimId], true, false) === $value[$multiDimId]) || ($value[$multiDimId] == 'NOW()') || (substr($value[$multiDimId], 0, 1) == '`'))  {
+                               // No need for ticks (')
+                               $SQL .= '`' . $entry . '`=' . $value[$multiDimId] . ', ';
+                       } else {
+                               // Strings need ticks (') around them
+                               $SQL .= '`' . $entry . "`='" . SQL_ESCAPE($value[$multiDimId]) . "', ";
+                       }
+               }
+       } // END - foreach
+
+       // Remove last 2 chars and finish query
+       $SQL = substr($SQL, 0, -2) . ' WHERE `' . $whereColumn . '`=' . $whereData . ' LIMIT 1';
+
+       // Return SQL query
+       return $SQL;
+}
+
 // [EOF]
 ?>
index 7e5997d0ef1593ecce9141bdc3232d34455271cd..c959ac5bb7244b2422b6e3ec1190606938435f52 100644 (file)
@@ -1,5 +1,5 @@
 <div align="center">
-<form accept-charset="UTF-8" action="{%url=modules.php?module=admin&amp;what=config_networks&amp;do=config_network%}" method="post">
+<form accept-charset="UTF-8" action="{%url=modules.php?module=admin&amp;what=config_networks&amp;do=config_network&amp;network=$content[network_id]%}" method="post">
 <table border="0" cellspacing="0" cellpadding="0" class="table dashed">
 <tr>
        <td class="table_header bottom" colspan="2" align="center">