From 3b712465a3f2b368ba8b74c39fed477de4278535 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 30 Aug 2011 22:46:09 +0000 Subject: [PATCH] Extension ext-network continued: - Added ability to set configuration for all network type handlers - Also data in 'cache_request' needs to be unset --- inc/language/network_de.php | 7 +- inc/libs/network_functions.php | 146 ++++++++++++++---- .../admin/what-config_network_types.php | 22 +-- inc/request-functions.php | 2 + .../admin_add_config_network_type_form.tpl | 6 +- .../admin_edit_config_network_type_form.tpl | 6 +- 6 files changed, 150 insertions(+), 39 deletions(-) diff --git a/inc/language/network_de.php b/inc/language/network_de.php index 534fa0dfbb..0ed7ddaf29 100644 --- a/inc/language/network_de.php +++ b/inc/language/network_de.php @@ -243,9 +243,12 @@ addMessages(array( 'ADMIN_CONFIG_NETWORK_HANDLER_TYPE_MIN_PAYMENT' => "Mindestvergütung (maximal fünf Stellen hinterm Komma):", 'ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALLOW_EROTIC' => "Wert für das Zulassen von Erotikkampagnen:", 'ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED' => "Werbeart-Handler wurde gespeichert und ist sofort gültig.", - 'ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED' => "Werbeart-Handler wurde NICHT gespeichert.", + 'ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED' => "Werbeart-Handler wurde(n) NICHT gespeichert.", 'ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED' => "Werart-Handler wurde noch nicht eingerichtet. Bitte verwenden Sie dazu das passende Formular.", - 'ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED' => "Werbeart-Handler wurde NICHT geändert.", + 'ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED' => "Werbeart-Handler wurde(n) NICHT geändert.", + 'ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL' => "Diese Einstellungen für alle Werbeart-Handler konfigurieren:", + 'ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404' => "Es wurde beim Übertragen der Einstellungen keine Werbeart-Handler gefunden.", + 'ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED' => "%s Werbeart-Handler wurden gespeichert.", // SQL export for all network tables 'ADMIN_EXPORT_NETWORK_NOTE' => "Verwenden Sie diesen SQL-Befehl nicht in phpMyAdmin oder anderen SQL-Clients, dieser SQL-Befehl ist zum Einfügen in das Script ext-network.php konzipiert.", 'ADMIN_EXPORT_ALL_NETWORK_DATA_LINK' => "Gesamte Tabelle network_data zum Einfügen in ext-network.php exportieren", diff --git a/inc/libs/network_functions.php b/inc/libs/network_functions.php index 90ad1a0efd..92174639ca 100644 --- a/inc/libs/network_functions.php +++ b/inc/libs/network_functions.php @@ -1464,7 +1464,7 @@ function doAdminNetworkProcessNetworkApiConfig () { } // Only adds network type configuration if not yet present -function doAdminNetworkProcessAddHandlerTypesConfig () { +function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = true) { // Remove the 'ok' part unsetPostRequestElement('ok'); @@ -1488,6 +1488,8 @@ function doAdminNetworkProcessAddHandlerTypesConfig () { $content = array(); $id = 'network_max_reload_time_ye'; $skip = false; + + // Get all POST data $postData = postRequestArray(); // Convert "reload time selections" @@ -1503,31 +1505,75 @@ function doAdminNetworkProcessAddHandlerTypesConfig () { return; } // END - if - // Get SQL query for new entry - $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config'); + // Copy 'set all' and remove it from POST data + $setAll = (postRequestElement('set_all') === 'Y'); + unsetPostRequestElement('set_all'); - // Run the query - SQL_QUERY($SQL, __FUNCTION__, __LINE__); + // Shall we set for all? + if ($setAll === true) { + // Get all handlers + $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC', + array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__); - // Output message - if (!SQL_HASZEROAFFECTED()) { - // Successfully added - displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}'); + // Do we have entries? + if (SQL_HASZERONUMS($result)) { + // No, then abort here + displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}'); + return; + } // END - if + + // Init number of rows + $numRows = 0; + + // Fetch all ids + while (list($typeId) = SQL_FETCHROW($result)) { + // Set it in GET data + setGetRequestElement('network_type_id', $typeId); + + // Call this function again + $numRows += doAdminNetworkProcessAddHandlerTypesConfig(false); + } // END - while + + // Free result + SQL_FREERESULT($result); + + // Output message + if ($numRows > 0) { + // Something has been updated + displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}'); + } else { + // Nothing has been saved + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}'); + } } else { - // Not added - loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}'); + // Get SQL query for new entry + $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config'); + + // Run the query + SQL_QUERY($SQL, __FUNCTION__, __LINE__); + + // Shall we display the message? + if ($displayMessage === true) { + // Output message + if (!SQL_HASZEROAFFECTED()) { + // Successfully added + displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}'); + } else { + // Not added + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}'); + } + } else { + // Return amount of affected rows (1 or 2) + return SQL_AFFECTEDROWS(); + } } } // Only changes network type configuration if not yet present -function doAdminNetworkProcessEditHandlerTypesConfig () { +function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = true) { // Remove the 'ok' part unsetPostRequestElement('ok'); - // Add both ids - setPostRequestElement('network_id', bigintval(getRequestElement('network_id'))); - setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id'))); - /* * Some parameters are optional, at least one must be given so check a bunch * of parameters. @@ -1559,19 +1605,67 @@ function doAdminNetworkProcessEditHandlerTypesConfig () { return; } // END - if - // Get SQL query for new entry - $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id')); + // Copy 'set all' and remove it from POST data + $setAll = (postRequestElement('set_all') === 'Y'); + unsetPostRequestElement('set_all'); - // Run the query - SQL_QUERY($SQL, __FUNCTION__, __LINE__); + // Shall we set for all? + if ($setAll === true) { + // Get all data entries + $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC', + array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__); - // Output message - if (!SQL_HASZEROAFFECTED()) { - // Successfully added - displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}'); + // Do we have entries? + if (SQL_HASZERONUMS($result)) { + // No, then abort here + displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}'); + return; + } // END - if + + // Init number of rows + $numRows = 0; + + // Fetch all ids + while (list($dataId) = SQL_FETCHROW($result)) { + // Set it in GET data + setPostRequestElement('network_data_id', $dataId); + + // Call this function again + $numRows += doAdminNetworkProcessEditHandlerTypesConfig(false); + } // END - while + + // Free result + SQL_FREERESULT($result); + + // Output message + if ($numRows > 0) { + // Something has been updated + displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}'); + } else { + // Nothing has been saved + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}'); + } } else { - // Not added - loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}'); + // Get SQL query for new entry + $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id')); + + // Run the query + SQL_QUERY($SQL, __FUNCTION__, __LINE__); + + // Shall we display the message? + if ($displayMessage === true) { + // Output message + if (!SQL_HASZEROAFFECTED()) { + // Successfully added + displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}'); + } else { + // Not added + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}'); + } + } else { + // Return amount of affected rows (1 or 2) + return SQL_AFFECTEDROWS(); + } } } diff --git a/inc/modules/admin/what-config_network_types.php b/inc/modules/admin/what-config_network_types.php index a18ae387c7..fd4efcfe2c 100644 --- a/inc/modules/admin/what-config_network_types.php +++ b/inc/modules/admin/what-config_network_types.php @@ -64,11 +64,11 @@ if (isGetRequestElementSet('network_id')) { if (isGetRequestElementSet('network_type_id')) { // Load data for given network $result = SQL_QUERY_ESC('SELECT - `network_id`, - `network_type_id`, - `network_type_handler`, - `network_type_reload_time_unit`, - `network_active`, + t.`network_id`, + t.`network_type_id`, + t.`network_type_handler`, + t.`network_type_reload_time_unit`, + d.`network_active`, NULL AS `network_data_id`, NULL AS `network_max_reload_time`, NULL AS `network_min_waiting_time`, @@ -76,10 +76,14 @@ if (isGetRequestElementSet('network_id')) { NULL AS `network_min_payment`, NULL AS `network_allow_erotic` FROM - `{?_MYSQL_PREFIX?}_network_types` + `{?_MYSQL_PREFIX?}_network_types` AS t +INNER JOIN + `{?_MYSQL_PREFIX?}_network_data` AS d +ON + d.network_id=t.network_id WHERE - `network_id`=%s AND - `network_type_id`=%s + t.`network_id`=%s AND + t.`network_type_id`=%s LIMIT 1', array( bigintval(getRequestElement('network_id')), @@ -142,7 +146,7 @@ LIMIT 1', return; } else { // No entry found - displayMessage('{%message,ADMIN_ADD_CONFIG_NETWORK_HANDLER_TYPE_404', bigintval(getRequestElement('network_id')) . '/' . bigintval(getRequestElement('network_type_id'))); + displayMessage('{%message,ADMIN_ADD_CONFIG_NETWORK_HANDLER_TYPE_404=' . bigintval(getRequestElement('network_id')) . '/' . bigintval(getRequestElement('network_type_id')) . '%}'); } // END - if // Free result diff --git a/inc/request-functions.php b/inc/request-functions.php index 8c49e180d4..4f48971f94 100644 --- a/inc/request-functions.php +++ b/inc/request-functions.php @@ -78,6 +78,7 @@ function isGetRequestElementSet ($element, $subElement = '') { // Removes an element from $_GET function unsetGetRequestElement ($element) { + unset($GLOBALS['cache_request']['get'][$element]); unset($GLOBALS['raw_request']['get'][$element]); } @@ -163,6 +164,7 @@ function isPostRequestElementSet ($element, $subElement = NULL) { // Removes an element from $_POST function unsetPostRequestElement ($element) { unset($GLOBALS['raw_request']['post'][$element]); + unset($GLOBALS['cache_request']['post'][$element]); } // Getter for whole $_POST array diff --git a/templates/de/html/admin/admin_add_config_network_type_form.tpl b/templates/de/html/admin/admin_add_config_network_type_form.tpl index 2d49193172..0cb2bb926c 100644 --- a/templates/de/html/admin/admin_add_config_network_type_form.tpl +++ b/templates/de/html/admin/admin_add_config_network_type_form.tpl @@ -9,6 +9,10 @@ ({%network,getNetworkDataById,network_title=%network_id%%}) +
+ {--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL--} + {%template,YesNoSelectionBox=set_all%} +
{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_MAX_RELOAD_TIME--} ({--TIME_UNIT--})
$content[network_max_reload_time] ({%pipe,translateTimeUnit=$content[network_type_reload_time_unit]%}) @@ -23,7 +27,7 @@
{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_MIN_PAYMENT--}
- +
{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALLOW_EROTIC--}
diff --git a/templates/de/html/admin/admin_edit_config_network_type_form.tpl b/templates/de/html/admin/admin_edit_config_network_type_form.tpl index 4994768c18..3987a5bcf0 100644 --- a/templates/de/html/admin/admin_edit_config_network_type_form.tpl +++ b/templates/de/html/admin/admin_edit_config_network_type_form.tpl @@ -9,6 +9,10 @@ ({%network,getNetworkDataById,network_title=%network_id%%})
+
+ {--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL--} + {%template,NoYesSelectionBox=set_all%} +
{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_MAX_RELOAD_TIME--} ({--TIME_UNIT--})
$content[network_max_reload_time] ({%pipe,translateTimeUnit=$content[network_type_reload_time_unit]%}) @@ -23,7 +27,7 @@
{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_MIN_PAYMENT--}
- +
{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALLOW_EROTIC--}
-- 2.39.5