One more underscore to make it more readable
[mailer.git] / inc / libs / network_functions.php
index db3196125f93239771b5a5c9632c0917c7a7e4a8..3e03193f13607976c293c4b38bf4e23d089a1fd5 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -50,129 +50,202 @@ function getCurrentNetworkId () {
        return $GLOBALS['current_network_id'];
 }
 
-// Handle a (maybe) sent form here
-function doNetworkHandleForm () {
-       // Was the form sent?
-       if ((isFormSent()) || (isFormSent('edit')) || (isFormSent('delete')) || (isFormSent('do_edit')) || (isFormSent('do_delete'))) {
-               // Do we have a 'do'?
-               if (isGetRequestElementSet('do')) {
-                       // Process the request
-                       doAdminNetworkProcessForm();
-               } else {
-                       // No 'do' found
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}');
-               }
+// Checks whether the current network id is set
+function isCurrentNetworkIdSet () {
+       // So is it there?
+       return isset($GLOBALS['current_network_id']);
+}
+
+// Getter for network_form_name
+function getNetworkFormName () {
+       return $GLOBALS['network_form_name'];
+}
+
+// Setter for network_form_name
+function setNetworkFormName ($networkFormName) {
+       $GLOBALS['network_form_name'] = (string) $networkFormName;
+}
+
+// Detects if a supported form has been sent
+function detectNetworkProcessForm () {
+       // 'do' must be provided in URL
+       if (!isGetRequestElementSet('do')) {
+               // Not provided!
+               reportBug(__FUNCTION__, __LINE__, 'No "do" has been provided. Please fix your templates.');
+       } // END - if
+
+       // Default is invalid
+       setNetworkFormName('invalid');
+
+       // Now search all valid
+       foreach (array('save_config', 'add', 'edit', 'delete', 'do_edit', 'do_delete') as $formName) {
+               // Is it detected
+               if (isFormSent($formName)) {
+                       // Use this form name
+                       setNetworkFormName($formName);
+
+                       // Remove it generically here
+                       unsetPostRequestElement($formName);
+
+                       // Abort loop
+                       break;
+               } // END - if
+       } // END - foreach
+
+       // Has the form being detected?
+       if (getNetworkFormName() == 'invalid') {
+               // Not supported
+               reportBug(__FUNCTION__, __LINE__, 'POST form could not be detected, postData=<pre>' . print_r(postRequestArray(), TRUE));
        } // END - if
 }
 
-// Processes an admin form
-function doAdminNetworkProcessForm () {
-       // Form really sent?
-       if ((!isFormSent()) && (!isFormSent('edit')) && (!isFormSent('delete')) && (!isFormSent('do_edit')) && (!isFormSent('do_delete'))) {
-               // Abort here
-               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_FORM_NOT_SENT--}');
-               return;
+// Handle a (maybe) sent form here
+function doNetworkHandleForm () {
+       // Is there a form sent?
+       if (countRequestPost() > 0) {
+               // Detect sent POST form
+               detectNetworkProcessForm();
        } elseif (!isGetRequestElementSet('do')) {
-               // No 'do' found
-               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}');
+               // Skip any further requests
+               return;
+       } elseif ((getHttpRequestMethod() != 'POST') && (getRequestElement('do') != 'export')) {
+               // Do not process non-POST requests that are not 'do=export'
                return;
        }
 
+       // Process the request
+       doAdminNetworkProcessForm();
+}
+
+// Processes an admin form
+function doAdminNetworkProcessForm () {
        // Create function name
        $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(getRequestElement('do')));
 
        // Is the function valid?
        if (!function_exists($functionName)) {
                // Invalid function name
-               debug_report_bug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', false);
+               reportBug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', FALSE);
        } // END - if
 
+       // Init global arrays
+       $GLOBALS['network_types_disabled'] = array();
+
        // Call-back the method handling our request
        call_user_func($functionName);
 }
 
-// Checks wether the (short) network name is already used (valid)
+// Checks whether the (short) network name is already used (valid)
 function isNetworkNameValid ($name) {
-       // Query for it
-       $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
-               array($name), __FUNCTION__, __LINE__);
-
-       // Does it exist?
-       $isValid = (SQL_NUMROWS($result) == 1);
-
-       // Free result
-       SQL_FREERESULT($result);
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$name])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$name] = (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', TRUE) == 1);
+       } // END - if
 
        // Return result
-       return $isValid;
+       return $GLOBALS[__FUNCTION__][$name];
 }
 
-// Checks wether the given network type is already used (valid)
-function isNetworkTypeHandleValid ($type, $networkId) {
-       // Query for it
-       $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handle`='%s' LIMIT 1",
-               array($networkId, $type), __FUNCTION__, __LINE__);
+// Checks whether the (short) named network is activated
+function isNetworkActiveByShortName ($name) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$name])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$name] = ((isNetworkNameValid($name)) && (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', TRUE, " AND `network_active`='Y'") == 1));
+       } // END - if
 
-       // Does it exist?
-       $isValid = (SQL_NUMROWS($result) == 1);
+       // Return result
+       return $GLOBALS[__FUNCTION__][$name];
+}
 
-       // Free result
-       SQL_FREERESULT($result);
+// Checks whether the network by given id is activated
+function isNetworkActiveById ($networkId) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(bigintval($networkId), 'network_data', 'network_id', 'network_id', TRUE, " AND `network_active`='Y'") == 1);
+       } // END - if
 
        // Return result
-       return $isValid;
+       return $GLOBALS[__FUNCTION__][$networkId];
 }
 
-// Checks wether the given network request parameter is already used (valid)
-function isNetworkRequestElementValid ($key, $type, $networkId) {
-       // Query for it
-       $result = SQL_QUERY_ESC("SELECT `network_param_id` FROM `{?_MYSQL_PREFIX?}_network_request_params` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_request_param_key`='%s' LIMIT 1",
-               array($networkId, $type, $key), __FUNCTION__, __LINE__);
+// "Getter" for 'network_activated' column depending on current administrator's expert setting
+function getNetworkActivatedColumn ($whereAnd = 'WHERE', $table = '') {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$whereAnd][$table])) {
+               // Default is exclude deactivated networks
+               $GLOBALS[__FUNCTION__][$whereAnd][$table] = ' ' . $whereAnd . ' ' . $table . "`network_active`='Y'";
+
+               // Is the export setting on and debug mode enabled?
+               if ((isAdminsExpertSettingEnabled()) && (isDebugModeEnabled())) {
+                       // Then allow all networks
+                       $GLOBALS[__FUNCTION__][$whereAnd][$table] = '';
+               } // END - if
+       } // END - if
 
-       // Does it exist?
-       $isValid = (SQL_NUMROWS($result) == 1);
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$whereAnd][$table];
+}
 
-       // Free result
-       SQL_FREERESULT($result);
+// Checks whether the given network type is already used (valid)
+function isNetworkTypeHandleValid ($type, $networkId) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId][$type])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$networkId][$type] = (countSumTotalData(bigintval($networkId), 'network_types', 'network_type_id', 'network_id', TRUE, sprintf(" AND `network_type_handler`='%s'", SQL_ESCAPE($type))) == 1);
+       } // END - if
 
        // Return result
-       return $isValid;
+       return $GLOBALS[__FUNCTION__][$networkId][$type];
 }
 
-// Checks wether the given network API array translation
-function isNetworkApiTranslationValid ($key, $type, $networkId) {
-       // Query for it
-       $result = SQL_QUERY_ESC("SELECT `network_api_id` FROM `{?_MYSQL_PREFIX?}_network_api_translation` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_api_index`='%s' LIMIT 1",
-               array($networkId, $type, $key), __FUNCTION__, __LINE__);
+// Checks whether the given network request parameter is already used (valid)
+function isNetworkRequestElementValid ($key, $networkTypeId, $networkId) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key] = (countSumTotalData(bigintval($networkId), 'network_request_params', 'network_request_param_id', 'network_id', TRUE, sprintf(" AND `network_type_id`=%s AND `network_request_param_key`='%s'", bigintval($networkTypeId), SQL_ESCAPE($key))) == 1);
+       } // END - if
 
-       // Does it exist?
-       $isValid = (SQL_NUMROWS($result) == 1);
+       // Return result
+       return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key];
+}
 
-       // Free result
-       SQL_FREERESULT($result);
+// Checks whether the given network API array translation
+function isNetworkArrayTranslationValid ($key, $networkTypeId, $networkId) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key] = (countSumTotalData(bigintval($networkId), 'network_array_translation', 'network_array_id', 'network_id', TRUE, sprintf(" AND `network_type_id`=%s AND `network_array_index`='%s'", bigintval($networkTypeId), SQL_ESCAPE($key))) == 1);
+       } // END - if
 
        // Return result
-       return $isValid;
+       return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId][$key];
 }
 
 // "Getter" for a network's data by provided id number
-function getNetworkDataById ($networkId, $column = '') {
+function getNetworkDataFromId ($networkId, $column = '') {
        // Ids lower one are not accepted
-       if ($networkId < 1) {
+       if (!isValidId($networkId)) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
-       } // END - if
+               reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
+       } elseif ((!isNetworkActiveById($networkId)) && (!isAdminsExpertSettingEnabled())) {
+               // Do not load inactive network data
+               reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is not active.');
+       }
 
        // Set current network id
        setCurrentNetworkId($networkId);
 
        // Is it cached?
        if (!isset($GLOBALS['network_data'][$networkId])) {
-               // By default we have no data
+               // By default there is no data
                $GLOBALS['network_data'][$networkId] = array();
 
                // Query for the network data
-               $result = SQL_QUERY_ESC("SELECT
+               $result = SQL_QUERY_ESC('SELECT
        `network_id`,
        `network_short_name`,
        `network_title`,
@@ -187,10 +260,10 @@ FROM
        `{?_MYSQL_PREFIX?}_network_data`
 WHERE
        `network_id`=%s
-LIMIT 1",
+LIMIT 1',
                        array(bigintval($networkId)), __FUNCTION__, __LINE__);
 
-               // Do we have an entry?
+               // Is there an entry?
                if (SQL_NUMROWS($result) == 1) {
                        // Then get it
                        $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
@@ -201,62 +274,65 @@ LIMIT 1",
        } // END - if
 
        // Return result
-       if (empty($column)) {
+       if ((empty($column)) && (isset($GLOBALS['network_data'][$networkId]))) {
                // Return array
                return $GLOBALS['network_data'][$networkId];
-       } else {
+       } elseif (isset($GLOBALS['network_data'][$networkId][$column])) {
                // Return column
                return $GLOBALS['network_data'][$networkId][$column];
        }
+
+       // Return NULL
+       return NULL;
 }
 
 // "Getter" for a network's data by provided type id number
-function getNetworkDataByTypeId ($networkId, $column = '') {
+function getNetworkDataByTypeId ($networkTypeId, $column = '') {
        // Ids lower one are not accepted
-       if ($networkId < 1) {
+       if (!isValidId($networkTypeId)) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
+               reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
        } // END - if
 
-       // Set current network id
-       setCurrentNetworkId($networkId);
-
        // Is it cached?
-       if (!isset($GLOBALS['network_data'][$networkId])) {
-               // By default we have no data
-               $GLOBALS['network_data'][$networkId] = array();
+       if (!isset($GLOBALS['network_type_data'][$networkTypeId])) {
+               // By default there is no data
+               $GLOBALS['network_type_data'][$networkTypeId] = array();
 
                // Query for the network data
-               $result = SQL_QUERY_ESC("SELECT
-       d.`network_id`,
-       d.`network_short_name`,
-       d.`network_title`,
-       d.`network_reflink`,
-       d.`network_data_separator`,
-       d.`network_row_separator`,
-       d.`network_request_type`,
-       d.`network_charset`,
-       d.`network_require_id_card`,
-       d.`network_query_amount`,
-       t.`network_type_handle`,
-       t.`network_type_api_url`,
-       t.`network_type_click_url`,
-       t.`network_type_banner_url`
+               $result = SQL_QUERY_ESC('SELECT
+       `d`.`network_id`,
+       `d`.`network_short_name`,
+       `d`.`network_title`,
+       `d`.`network_reflink`,
+       `d`.`network_data_separator`,
+       `d`.`network_row_separator`,
+       `d`.`network_request_type`,
+       `d`.`network_charset`,
+       `d`.`network_require_id_card`,
+       `d`.`network_query_amount`,
+       `d`.`network_active`,
+       `t`.`network_type_id`,
+       `t`.`network_type_handler`,
+       `t`.`network_type_api_url`,
+       `t`.`network_type_click_url`,
+       `t`.`network_type_banner_url`,
+       `t`.`network_text_encoding`
 FROM
-       `{?_MYSQL_PREFIX?}_network_data` AS d
+       `{?_MYSQL_PREFIX?}_network_data` AS `d`
 LEFT JOIN
-       `{?_MYSQL_PREFIX?}_network_types` AS t
+       `{?_MYSQL_PREFIX?}_network_types` AS `t`
 ON
-       d.`network_id`=t.`network_id`
+       `d`.`network_id`=`t`.`network_id`
 WHERE
-       t.`network_type_id`=%s
-LIMIT 1",
-                       array(bigintval($networkId)), __FUNCTION__, __LINE__);
+       `t`.`network_type_id`=%s
+LIMIT 1',
+                       array(bigintval($networkTypeId)), __FUNCTION__, __LINE__);
 
-               // Do we have an entry?
+               // Is there an entry?
                if (SQL_NUMROWS($result) == 1) {
                        // Then get it
-                       $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
+                       $GLOBALS['network_type_data'][$networkTypeId] = SQL_FETCHARRAY($result);
                } // END - if
 
                // Free result
@@ -264,31 +340,36 @@ LIMIT 1",
        } // END - if
 
        // Return result
-       if (empty($column)) {
+       if (!isset($GLOBALS['network_type_data'][$networkTypeId])) {
+               // Not found
+               return NULL;
+       } elseif (empty($column)) {
                // Return array
-               return $GLOBALS['network_data'][$networkId];
+               return $GLOBALS['network_type_data'][$networkTypeId];
        } else {
                // Return column
-               return $GLOBALS['network_data'][$networkId][$column];
+               return $GLOBALS['network_type_data'][$networkTypeId][$column];
        }
 }
 
 // "Getter" for a network type data by provided id number
-function getNetworkTypeDataById ($networkId) {
+function getNetworkTypeDataByTypeId ($networkTypeId) {
        // Ids lower one are not accepted
-       if ($networkId < 1) {
+       if (!isValidId($networkTypeId)) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
+               reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
        } // END - if
 
-       // By default we have no data
-       $GLOBALS['network_type_data'][$networkId] = array();
+       // Is it set?
+       if (!isset($GLOBALS['network_type_data'][$networkTypeId])) {
+               // By default there is no data
+               $GLOBALS['network_type_data'][$networkTypeId] = array();
 
-       // Query for the network data
-       $result = SQL_QUERY_ESC("SELECT
-       `network_type_id`
+               // Query for the network data
+               $result = SQL_QUERY_ESC('SELECT
+       `network_type_id`,
        `network_id`,
-       `network_type_handle`,
+       `network_type_handler`,
        `network_type_api_url`,
        `network_type_click_url`,
        `network_type_banner_url`
@@ -296,36 +377,83 @@ FROM
        `{?_MYSQL_PREFIX?}_network_types`
 WHERE
        `network_type_id`=%s
-LIMIT 1",
-               array(bigintval($networkId)), __FUNCTION__, __LINE__);
+LIMIT 1',
+                       array(bigintval($networkTypeId)), __FUNCTION__, __LINE__);
 
-       // Do we have an entry?
-       if (SQL_NUMROWS($result) == 1) {
-               // Then get it
-               $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
+               // Is there an entry?
+               if (SQL_NUMROWS($result) == 1) {
+                       // Then get it
+                       $GLOBALS['network_type_data'][$networkTypeId] = SQL_FETCHARRAY($result);
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result);
        } // END - if
 
-       // Free result
-       SQL_FREERESULT($result);
+       // Return result
+       return $GLOBALS['network_type_data'][$networkTypeId];
+}
+
+// "Getter" for all network type data by provided id number
+function getNetworkTypeDataFromId ($networkId) {
+       // Ids lower one are not accepted
+       if (!isValidId($networkId)) {
+               // Not good, should be fixed
+               reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
+       } // END - if
+
+       // Is it set?
+       if (!isset($GLOBALS['network_types'][$networkId])) {
+               // By default there is no data
+               $GLOBALS['network_types'][$networkId] = array();
+
+               // Query for the network data
+               $result = SQL_QUERY_ESC('SELECT
+       `network_type_id`,
+       `network_id`,
+       `network_type_handler`,
+       `network_type_api_url`,
+       `network_type_click_url`,
+       `network_type_banner_url`
+FROM
+       `{?_MYSQL_PREFIX?}_network_types`
+WHERE
+       `network_id`=%s
+ORDER BY
+       `network_type_id` ASC',
+                       array(bigintval($networkId)), __FUNCTION__, __LINE__);
+
+               // Is there an entry?
+               if (!SQL_HASZERONUMS($result)) {
+                       // Then add all
+                       while ($row = SQL_FETCHARRAY($result)) {
+                               // Add it with new index as it is no longer required
+                               $GLOBALS['network_types'][$networkId][] = $row;
+                       } // END - if
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result);
+       } // END - if
 
        // Return result
-       return $GLOBALS['network_type_data'][$networkId];
+       return $GLOBALS['network_types'][$networkId];
 }
 
 // "Getter" for a network request parameter data by provided id number
-function getNetworkRequestParamsDataById ($networkId) {
+function getNetworkRequestParamsDataFromId ($networkRequestId) {
        // Ids lower one are not accepted
-       if ($networkId < 1) {
+       if (!isValidId($networkRequestId)) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
+               reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkRequestId . ' is smaller than 1.');
        } // END - if
 
-       // By default we have no data
+       // By default there is no data
        $networkRequestData = array();
 
        // Query for the network data
-       $result = SQL_QUERY_ESC("SELECT
-       `network_param_id`,
+       $result = SQL_QUERY_ESC('SELECT
+       `network_request_param_id`,
        `network_id`,
        `network_type_id`,
        `network_request_param_key`,
@@ -334,11 +462,11 @@ function getNetworkRequestParamsDataById ($networkId) {
 FROM
        `{?_MYSQL_PREFIX?}_network_request_params`
 WHERE
-       `network_param_id`=%s
-LIMIT 1",
-               array(bigintval($networkId)), __FUNCTION__, __LINE__);
+       `network_request_param_id`=%s
+LIMIT 1',
+               array(bigintval($networkRequestId)), __FUNCTION__, __LINE__);
 
-       // Do we have an entry?
+       // Is there an entry?
        if (SQL_NUMROWS($result) == 1) {
                // Then get it
                $networkRequestData = SQL_FETCHARRAY($result);
@@ -351,54 +479,174 @@ LIMIT 1",
        return $networkRequestData;
 }
 
-// Updates given network (id) with data from array
-function doNetworkUpdateDataByArray ($networkId, $networkData) {
+// "Getter" for a network array translation data by provided id number
+function getNetworkArrayTranslationsDataFromId ($networkTranslationId) {
        // Ids lower one are not accepted
-       if ($networkId < 1) {
+       if (!isValidId($networkTranslationId)) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
+               reportBug(__FUNCTION__, __LINE__, 'Network array translation id ' . $networkTranslationId . ' is smaller than 1.');
        } // END - if
 
-       // Just call our inner method
-       return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
+       // By default there is no data
+       $networkTranslationData = array();
+
+       // Query for the network data
+       $result = SQL_QUERY_ESC('SELECT
+       `network_array_id`,
+       `network_id`,
+       `network_type_id`,
+       `network_array_index`,
+       `network_array_sort`
+FROM
+       `{?_MYSQL_PREFIX?}_network_array_translation`
+WHERE
+       `network_array_id`=%s
+LIMIT 1',
+               array(bigintval($networkTranslationId)), __FUNCTION__, __LINE__);
+
+       // Is there an entry?
+       if (SQL_NUMROWS($result) == 1) {
+               // Then get it
+               $networkTranslationData = SQL_FETCHARRAY($result);
+       } // END - if
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Return result
+       return $networkTranslationData;
 }
 
-// Updates given network type handler (id) with data from array
-function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
+// "Getter" for network query request parameters
+function getNetworkRequestParametersByTypeId ($networkTypeId) {
        // Ids lower one are not accepted
-       if ($networkId < 1) {
+       if (!isValidId($networkTypeId)) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' is smaller than 1.');
+               reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
        } // END - if
 
-       // Just call our inner method
-       return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
+       // Is it cached?
+       if (!isset($GLOBALS['network_request_parameters'][$networkTypeId])) {
+               // By default there is no data
+               $GLOBALS['network_request_parameters'][$networkTypeId] = array();
+
+               // Search for all
+               $result = SQL_QUERY_ESC('SELECT
+       `network_id`,
+       `network_type_id`,
+       `network_request_param_key`,
+       `network_request_param_value`,
+       `network_request_param_default`
+FROM
+       `{?_MYSQL_PREFIX?}_network_request_params`
+WHERE
+       `network_type_id`=%s
+ORDER BY
+       `network_request_param_id` ASC',
+               array(
+                       bigintval($networkTypeId)
+               ), __FUNCTION__, __LINE__);
+
+               // Are there records?
+               if (!SQL_HASZERONUMS($result)) {
+                       // Load all but make new indexes as the old are not required
+                       while ($row = SQL_FETCHARRAY($result)) {
+                               // Add it
+                               $GLOBALS['network_request_parameters'][$networkTypeId][] = $row;
+                       } // END - while
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result);
+       } // END - if
+
+       // Return "cached" values
+       return $GLOBALS['network_request_parameters'][$networkTypeId];
 }
 
-// Updates given network request parameters (id) with data from array
-function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
+// "Getter" for network configuration + handler config for given network type handler id
+function getFullNetworkConfigurationByTypeId ($networkTypeId) {
        // Ids lower one are not accepted
-       if ($networkId < 1) {
+       if (!isValidId($networkTypeId)) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
+               reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkTypeId . ' is smaller than 1.');
        } // END - if
 
-       // Just call our inner method
-       return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_param_id`=%s", bigintval($networkId)), array(), false, false);
+       // Is it cached?
+       if (!isset($GLOBALS['network_full_config'][$networkTypeId])) {
+               // By default there is no data
+               $GLOBALS['network_full_config'][$networkTypeId] = array();
+
+               // Search for all
+               $result = SQL_QUERY_ESC('SELECT
+       `nac`.`network_id`,
+       `ntc`.`network_type_id`,
+       `nac`.`network_api_affiliate_id`,
+       `nac`.`network_api_password`,
+       `nac`.`network_api_site_id`,
+       `nac`.`network_api_active`,
+       `nac`.`network_api_referral_link`,
+       `nac`.`network_api_referral_button`,
+       `nac`.`network_api_remaining_requests`,
+       `nac`.`network_api_visual_pay_check`,
+       `nts`.`network_type_reload_time_unit`,
+       `ntc`.`network_max_reload_time`,
+       `ntc`.`network_min_waiting_time`,
+       `ntc`.`network_max_waiting_time`,
+       `ntc`.`network_min_remain_clicks`,
+       `ntc`.`network_min_remain_budget`,
+       `ntc`.`network_min_payment`,
+       `ntc`.`network_allow_erotic`,
+       `ntc`.`network_media_size`,
+       `ntc`.`network_media_output`
+FROM
+       `{?_MYSQL_PREFIX?}_network_api_config` AS `nac`
+INNER JOIN
+       `{?_MYSQL_PREFIX?}_network_handler_config` AS `ntc`
+ON
+       `nac`.`network_id`=`ntc`.`network_id`
+INNER JOIN
+       `{?_MYSQL_PREFIX?}_network_types` AS `nts`
+ON
+       `ntc`.`network_type_id`=`nts`.`network_type_id`
+WHERE
+       `ntc`.`network_type_id`=%s
+LIMIT 1',
+               array(
+                       bigintval($networkTypeId)
+               ), __FUNCTION__, __LINE__);
+
+               // Is there one entry?
+               if (SQL_NUMROWS($result) == 1) {
+                       // Load it
+                       $GLOBALS['network_full_config'][$networkTypeId] = SQL_FETCHARRAY($result);
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result);
+       } // END - if
+
+       // Return "cached" values
+       return $GLOBALS['network_full_config'][$networkTypeId];
 }
 
 // Removes given network entry
-function doAdminRemoveNetworkEntry ($table, $column, $networkId, $limit = 1) {
+function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
        // Remove the entry
        SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
-               array($table, $column, $networkId, $limit), __FUNCTION__, __LINE__);
+               array(
+                       $table,
+                       $column,
+                       $id,
+                       $limit
+               ), __FUNCTION__, __LINE__);
 
        // Return affected rows
        return SQL_AFFECTEDROWS();
 }
 
 // Generates a list of networks for given script and returns it
-function generateAdminNetworkList () {
+function generateAdminNetworkList ($separated = FALSE, $includeConfigured = TRUE, $includeUnconfigured = TRUE, $extraName = '', $addSql = '') {
        // Init output
        $content = '';
 
@@ -406,29 +654,66 @@ function generateAdminNetworkList () {
        $result = SQL_QUERY('SELECT
        `network_id`,
        `network_short_name`,
-       `network_title`
+       `network_title`,
+       `network_request_type`,
+       `network_charset`,
+       `network_require_id_card`,
+       `network_query_amount`,
+       `network_active`
 FROM
        `{?_MYSQL_PREFIX?}_network_data`
+' . getNetworkActivatedColumn('WHERE') . '
 ORDER BY
        `network_short_name` ASC', __FUNCTION__, __LINE__);
 
-       // Do we have entries?
+       // Are there entries?
        if (!SQL_HASZERONUMS($result)) {
                // List all entries
                $rows = array();
                while ($row = SQL_FETCHARRAY($result)) {
                        // Is this valid, then add it
                        if ((is_array($row)) && (isset($row['network_id']))) {
+                               // Exclude configured and is it configured or same for unconfired but only if not separated lists?
+                               if (((($includeConfigured === FALSE) && (isNetworkApiConfigured($row['network_id']))) || (($includeUnconfigured === FALSE) && (!isNetworkApiConfigured($row['network_id'])))) && ($separated === FALSE)) {
+                                       // Skip this entry
+                                       continue;
+                               // @TODO Unfinished: } elseif ((!empty($addSql)) && (
+                               } // END - if
+
                                // Add entry
                                $rows[$row['network_id']] = $row;
                        } // END - if
                } // END - while
 
-               // Generate the selection box
-               $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
+               // Nothing found?
+               if (count($rows) == 0) {
+                       // Then return nothing ... ;-)
+                       return '';
+               } // END - if
+
+               // Do separated?
+               if ($separated === FALSE) {
+                       // Exclude un-/configured?
+                       if ($includeConfigured === FALSE) {
+                               // Exclude configured, so only unconfigured
+                               $extraName = '_unconfigured';
+                       } elseif ($includeUnconfigured === FALSE) {
+                               // Exclude unconfigured, so only configured
+                               $extraName = '_configured';
+                       }
+
+                       // Generate the big selection box
+                       $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', $extraName, 'network');
+               } else {
+                       // Generate two small, first configured
+                       $content = generateAdminNetworkList(FALSE, TRUE, FALSE, '_configured', $addSql);
+
+                       // Then add unconfigured
+                       $content .= generateAdminNetworkList(FALSE, FALSE, TRUE, '_unconfigured', $addSql);
+               }
        } else {
                // Nothing selected
-               $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
+               $content = displayErrorMessage('{--ADMIN_ENTRIES_404--}');
        }
 
        // Free the result
@@ -444,19 +729,21 @@ function generateAdminNetworkTypeList ($networkId) {
        $content = '';
 
        // Query all types of this network
-       $result = SQL_QUERY_ESC("SELECT
-       `network_type_id`,`network_type_handle`
+       $result = SQL_QUERY_ESC('SELECT
+       `network_type_id`,
+       `network_type_handler`
 FROM
        `{?_MYSQL_PREFIX?}_network_types`
 WHERE
        `network_id`=%s
+       ' . getNetworkActivatedColumn('AND') . '
 ORDER BY
-       `network_type_handle` ASC",
+       `network_type_handler` ASC',
                array(
                        bigintval($networkId)
                ), __FUNCTION__, __LINE__);
 
-       // Do we have entries?
+       // Are there entries?
        if (!SQL_HASZERONUMS($result)) {
                // List all entries
                $rows = array();
@@ -472,7 +759,7 @@ ORDER BY
                $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
        } else {
                // Nothing selected
-               $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
+               $content = displayErrorMessage('{--ADMIN_ENTRIES_404--}');
        }
 
        // Free the result
@@ -489,18 +776,21 @@ function generateAdminDistinctNetworkTypeList () {
 
        // Query all types of this network
        $result = SQL_QUERY('SELECT
-       t.`network_type_id`, t.`network_type_handle`, d.`network_title`
+       `t`.`network_type_id`,
+       `t`.`network_type_handler`,
+       `d`.`network_title`
 FROM
-       `{?_MYSQL_PREFIX?}_network_types` AS t
+       `{?_MYSQL_PREFIX?}_network_types` AS `t`
 LEFT JOIN
-       `{?_MYSQL_PREFIX?}_network_data` AS d
+       `{?_MYSQL_PREFIX?}_network_data` AS `d`
 ON
-       t.`network_id`=d.`network_id`
+       `t`.`network_id`=`d`.`network_id`
+' . getNetworkActivatedColumn('WHERE', 'd') . '
 ORDER BY
-       d.`network_short_name` ASC,
-       t.`network_type_handle` ASC', __FUNCTION__, __LINE__);
+       `d`.`network_short_name` ASC,
+       `t`.`network_type_handler` ASC', __FUNCTION__, __LINE__);
 
-       // Do we have entries?
+       // Are there entries?
        if (!SQL_HASZERONUMS($result)) {
                // List all entries
                $rows = array();
@@ -516,7 +806,7 @@ ORDER BY
                $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
        } else {
                // Nothing selected
-               $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
+               $content = displayErrorMessage('{--ADMIN_ENTRIES_404--}');
        }
 
        // Free the result
@@ -531,20 +821,21 @@ ORDER BY
 function generateNetworkTypeOptions ($networkId) {
        // Is this an array, then we just came back from edit/delete actions
        if (is_array($networkId)) {
+               // Set it as empty string
                $networkId = '';
        } // END - if
 
        // Is this cached?
        if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
                // Generate output and cache it
-               $GLOBALS[__FUNCTION__][$networkId] = generateOptionList(
+               $GLOBALS[__FUNCTION__][$networkId] = generateOptions(
                        'network_types',
                        'network_type_id',
-                       'network_type_handle',
+                       'network_type_handler',
                        $networkId,
                        '',
                        sprintf(
-                               "WHERE `network_id`=%s",
+                               "WHERE `network_id`=%s" . getNetworkActivatedColumn('AND'),
                                bigintval(getRequestElement('network_id'))
                        ),
                        '',
@@ -557,11 +848,11 @@ function generateNetworkTypeOptions ($networkId) {
 }
 
 // Generates an options list of all available (hard-coded) handlers
-function generateNetworkTypesAvailableOptions () {
+function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
        // Is it cached?
-       if (!isset($GLOBALS[__FUNCTION__])) {
+       if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
                // Generate list
-               $GLOBALS[__FUNCTION__] = generateOptionList(
+               $GLOBALS[__FUNCTION__][$defaultType] = generateOptions(
                        '/ARRAY/',
                        array(
                                'banner',
@@ -573,14 +864,20 @@ function generateNetworkTypesAvailableOptions () {
                                'surfbar',
                                'surfbar_click',
                                'surfbar_view',
-                               'forcedbanner',
-                               'forcedtextlink',
+                               'forced_banner',
+                               'forced_button',
+                               'forced_half_banner',
+                               'forced_skyscraper',
+                               'forced_textlink',
                                'textlink',
                                'textlink_click',
                                'textlink_view',
-                               'skybanner',
-                               'skybanner_click',
-                               'skybanner_view',
+                               'skyscraper',
+                               'skyscraper_click',
+                               'skyscraper_view',
+                               'half_banner',
+                               'half_banner_click',
+                               'half_banner_view',
                                'layer',
                                'layer_click',
                                'layer_view',
@@ -590,12 +887,18 @@ function generateNetworkTypesAvailableOptions () {
                                'htmlmail',
                                'lead',
                                'sale',
+                               'lead_sale',
                                'payperactive',
                                'pagepeel',
-                               'traffic'
+                               'pagepeel_click',
+                               'pagepeel_view',
+                               'traffic',
+                               'signature',
+                               'signature_click',
+                               'signature_view',
                        ),
                        array(),
-                       '',
+                       $defaultType,
                        '', '',
                        $GLOBALS['network_types_disabled'],
                        'translateNetworkTypeHandler'
@@ -603,19 +906,42 @@ function generateNetworkTypesAvailableOptions () {
        } // END - if
 
        // Return content
-       return $GLOBALS[__FUNCTION__];
+       return $GLOBALS[__FUNCTION__][$defaultType];
+}
+
+// Generates an options list of all available (hard-coded) text encoders
+function generateNetworkTextEncodingAvailableOptions ($defaultEncoding = NULL) {
+       // Is it cached?
+       if (!isset($GLOBALS[__FUNCTION__][$defaultEncoding])) {
+               // Generate list
+               $GLOBALS[__FUNCTION__][$defaultEncoding] = generateOptions(
+                       '/ARRAY/',
+                       array(
+                               'NONE',
+                               'BASE64',
+                       ),
+                       array(),
+                       $defaultEncoding,
+                       '', '',
+                       array(),
+                       'translateNetworkTextEncoding'
+               );
+       } // END - if
+
+       // Return content
+       return $GLOBALS[__FUNCTION__][$defaultEncoding];
 }
 
-// Generates an options list (somewhat getter) ofr request keys
+// Generates an options list (somewhat getter) for request keys
 function generateNetworkRequestKeyOptions () {
        // Is it cached?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Generate and cache it
-               $GLOBALS[__FUNCTION__] = generateOptionList(
+               $GLOBALS[__FUNCTION__] = generateOptions(
                        '/ARRAY/',
                        array(
-                               'id',
-                               'sid',
+                               'affiliate_id',
+                               'site_id',
                                'hash',
                                'password',
                                'reload',
@@ -623,7 +949,8 @@ function generateNetworkRequestKeyOptions () {
                                'minimum_stay',
                                'currency',
                                'type',
-                               'remain',
+                               'remain_budget',
+                               'remain_clicks',
                                'reward',
                                'size',
                                'erotic',
@@ -633,8 +960,8 @@ function generateNetworkRequestKeyOptions () {
                        array(),
                        '',
                        '', '',
-                       $GLOBALS['network_params_disabled'],
-                       'translateNetworkRequestElement'
+                       $GLOBALS['network_request_params_disabled'],
+                       'translateNetworkRequestParameterKey'
                );
        } // END - if
 
@@ -647,14 +974,14 @@ function generateNetworkTranslationOptions ($default = '') {
        // Is it cached?
        if (!isset($GLOBALS[__FUNCTION__][$default])) {
                // Generate and cache it
-               $GLOBALS[__FUNCTION__][$default] = generateOptionList(
+               $GLOBALS[__FUNCTION__][$default] = generateOptions(
                        'network_translations',
                        'network_translation_id',
                        'network_translation_name',
                        $default,
                        '',
                        '',
-                       $GLOBALS['network_translation_disabled'],
+                       $GLOBALS['network_array_translation_disabled'],
                        'translateNetworkTranslationName'
                );
        } // END - if
@@ -665,10 +992,10 @@ function generateNetworkTranslationOptions ($default = '') {
 
 // Generates an option list of request types
 function generateNetworkRequestTypeOptions ($default = '') {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$default])) {
                // Generate the list
-               $GLOBALS[__FUNCTION__][$default] = generateOptionList(
+               $GLOBALS[__FUNCTION__][$default] = generateOptions(
                        '/ARRAY/',
                        array(
                                'GET',
@@ -688,65 +1015,408 @@ function generateNetworkRequestTypeOptions ($default = '') {
 
 // Generates an option list of network_api_active
 function generateNetworkApiActiveOptions ($default = '') {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$default])) {
                // Generate the list
-               $GLOBALS[__FUNCTION__][$default] = generateYesNoOptionList($default);
+               $GLOBALS[__FUNCTION__][$default] = generateYesNoOptions($default);
        } // END - if
 
        // Return cache
        return $GLOBALS[__FUNCTION__][$default];
 }
 
-// Translates 'translate_name' for e.g. templates
-function translateNetworkTranslationName ($name) {
-       // Get the message id
-       return '{--ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME--}';
-}
+// Generator (somewhat getter) for network type options
+function generateNetworkMediaOutputOptions ($mediaOutput) {
+       // Is this an array, then we just came back from edit/delete actions
+       if (is_array($mediaOutput)) {
+               // Set it as empty string
+               $mediaOutput = '';
+       } // END - if
 
-// Translates the network type handler (e.g. banner, paidmail) for templates
-function translateNetworkTypeHandler ($type) {
-       // Get the message id
-       return '{--ADMIN_NETWORK_TYPES_' . strtoupper($type) . '--}';
-}
+       // Is this cached?
+       if (!isset($GLOBALS[__FUNCTION__][$mediaOutput])) {
+               // Generate output and cache it
+               $GLOBALS[__FUNCTION__][$mediaOutput] = generateOptions(
+                       '/ARRAY/',
+                       array(
+                               '',
+                               'banner',
+                               'html_email',
+                               'layer',
+                               'pagepeel',
+                               'popup',
+                               'popdown',
+                               'text_email',
+                               'textlink'
+                       ),
+                       array(
+                               '{--ADMIN_NETWORK_MEDIA_OUTPUT_NONE--}',
+                               '{--ADMIN_NETWORK_MEDIA_OUTPUT_BANNER--}',
+                               '{--ADMIN_NETWORK_MEDIA_OUTPUT_HTML_EMAIL--}',
+                               '{--ADMIN_NETWORK_MEDIA_OUTPUT_LAYER--}',
+                               '{--ADMIN_NETWORK_MEDIA_OUTPUT_PAGEPEEL--}',
+                               '{--ADMIN_NETWORK_MEDIA_OUTPUT_POPUP--}',
+                               '{--ADMIN_NETWORK_MEDIA_OUTPUT_POPDOWN--}',
+                               '{--ADMIN_NETWORK_MEDIA_OUTPUT_TEXT_EMAIL--}',
+                               '{--ADMIN_NETWORK_MEDIA_OUTPUT_TEXTLINK--}'
+                       ),
+                       $mediaOutput,
+                       'translateNetworkMediaOutputType'
+               );
+       } // END - if
 
-// Translates request type
-function translateNetworkRequestType ($type) {
-       // Get the message id
-       return '{--ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '--}';
+       // Return content
+       return $GLOBALS[__FUNCTION__][$mediaOutput];
 }
 
-// Translates request parameter
-function translateNetworkRequestElement ($param) {
-       // Get the message id
-       return '{--ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '--}';
+// Checks if the given network is configured by looking its API configuration entry up
+function isNetworkApiConfigured ($networkId, $addSql = '') {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
+               // Check for an entry in network_api_config
+               $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
+                       bigintval($networkId),
+                       'network_api_config',
+                       'network_id',
+                       'network_id',
+                       true
+               ) == 1);
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$networkId];
 }
 
-// Translates API index
-function translateNetworkApiIndex ($index) {
-       // Do we have cache?
-       if (!isset($GLOBALS['network_api_index'])) {
+// Checks whether the given network type handler is configured
+function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
+                       bigintval($networkTypeId),
+                       'network_handler_config',
+                       'network_data_id',
+                       'network_type_id',
+                       true,
+                       sprintf(' AND `network_id`=%s', bigintval($networkId))
+               ) == 1);
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
+}
+
+// Handles the network-payment-check request
+function handleNetworkPaymentCheckRequest () {
+       // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
+       reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
+}
+
+// Handles the network-delete-url request
+function handleNetworkDeleteUrlRequest () {
+       // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
+       reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
+}
+
+// Handle a single request parameter key by given network type handler id and "internal" key
+function handleRequestParameterKey ($networkTypeId, $networkRequestKey) {
+       // Construct call-back function name
+       $callbackName = 'doHandleNetworkRequest' . capitalizeUnderscoreString($networkRequestKey) . 'Key';
+
+       // Is the function there?
+       if (!function_exists($callbackName)) {
+               // Call-back function does not exist
+               reportBug(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' does not exist. networkTypeId=' . $networkTypeId . ',networkRequestKey=' . $networkRequestKey);
+       } // END - if
+
+       // Call it with network type id
+       return call_user_func_array($callbackName, array($networkTypeId));
+}
+
+// Handle all keys given request parameter array loaded by getNetworkRequestParametersByTypeId()
+function handleNetworkRequestParameterKeys (&$requestParams) {
+       // Simple check for validity
+       assert(isset($requestParams[0]['network_request_param_key']));
+
+       // "Walk" through all
+       foreach ($requestParams as $key => $params) {
+               // Is the default value not set?
+               if (empty($params['network_request_param_default'])) {
+                       // This key needs to be handled, so call it
+                       $requestParams[$key]['network_request_param_default'] = handleRequestParameterKey($params['network_type_id'], $params['network_request_param_key']);
+               } // END - if
+       } // END - foreach
+}
+
+/**
+ * Logs given HTTP headers to database for debugging purposes.
+ *
+ * @param      $networkId              Network's id number
+ * @param      $networkTypeId  Network type handler's id number
+ * @param      $headers                All HTTP headers
+ * @param      $type                   Can be only one of 'MANUAL' or 'CRON'
+ * @return     void
+ */
+function logNetworkResponseHeaders ($networkId, $networkTypeId, $headers, $type) {
+       // Make sure type is valid
+       assert(in_array($type, array('MANUAL', 'CRON')));
+
+       // Is debug logging enabled or status code not 200 OK?
+       if ((getConfig('network_logging_debug') == 'Y') || (!isHttpStatusOkay($headers[0]))) {
+               // Add entry
+               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_network_header_logging` (`network_id`, `network_type_id`, `network_http_status_code`, `network_http_headers`, `network_logging_type`) VALUES(%s, %s, '%s', '%s', '%s')",
+                       array(
+                               bigintval($networkId),
+                               bigintval($networkTypeId),
+                               trim($headers[0]),
+                               serialize($headers),
+                               $type
+                       ), __FUNCTION__, __LINE__);
+       } // END - if
+}
+
+/**
+ * Caches given reponse body from API into cache, updates existing cache if
+ * found. This function does the charset-convertion, so you don't have to do it
+ * again if you use this cached data.
+ *
+ * @param      $networkId              Network's id number
+ * @param      $networkTypeId  Network type handler's id number
+ * @param      $responseBody   Response body (string)
+ * @param      $networkData    Network + type handler data as array
+ * @param      $type                   Can be only one of 'MANUAL' or 'CRON'
+ * @return     void
+ */
+function saveNetworkResponseBodyInCache ($networkId, $networkTypeId, $responseBody, $networkData, $type) {
+       // Make sure the body is not larger than this value
+       assert(strlen($responseBody) <= 16777215);
+       assert(in_array($type, array('MANUAL', 'CRON')));
+
+       // So is there cache?
+       if (countSumTotalData($networkId, 'network_cache', 'network_cache_id', 'network_id', TRUE, ' AND `network_type_id`=' . bigintval($networkTypeId)) == 1) {
+               // Entry found, so update it
+               SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_network_cache`
+SET
+       `network_cache_data`='%s',
+       `network_cache_body`='%s',
+       `network_cache_type`='%s',
+       `network_cache_admin_id`=%s,
+       `network_cache_updated`=NOW()
+WHERE
+       `network_id`=%s AND
+       `network_type_id`=%s
+LIMIT 1",
+                       array(
+                               serialize($networkData),
+                               compress(convertCharsetToUtf8($responseBody, $networkData['network_charset'])),
+                               $type,
+                               convertZeroToNull(getCurrentAdminId()),
+                               bigintval($networkId),
+                               bigintval($networkTypeId)
+                       ), __FUNCTION__, __LINE__);
+       } else {
+               // Add entry
+               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_network_cache` (`network_id`, `network_type_id`, `network_cache_data`, `network_cache_body`, `network_cache_type`, `network_cache_admin_id`) VALUES(%s, %s, '%s', '%s', '%s', %s)",
+                       array(
+                               bigintval($networkId),
+                               bigintval($networkTypeId),
+                               serialize($networkData),
+                               compress(convertCharsetToUtf8($responseBody, $networkData['network_charset'])),
+                               $type,
+                               convertZeroToNull(getCurrentAdminId())
+                       ), __FUNCTION__, __LINE__);
+       }
+}
+
+// Queries network API with given network data and request data
+function queryNetworkApi ($networkData, $requestData) {
+       // Query it
+       $response = sendHttpRequest($networkData['network_request_type'], $networkData['network_type_api_url'], $requestData, FALSE, FALSE);
+
+       // Did all went fine? (also a 403 is considered as "okay" here)
+       if (count($response) > 3) {
+               // Save response body, remove last empty line if really empty
+               $responseBody = (string) trim($response[count($response) - 1]);
+               unset($response[count($response) - 1]);
+               assert(empty($response[count($response)]));
+               unset($response[count($response) - 1]);
+
+               // Register all HTTP headers for debugging purposes
+               logNetworkResponseHeaders($networkData['network_id'], postRequestElement('network_type_id'), $response, 'MANUAL');
+
+               // Is all fine?
+               if (isHttpStatusOkay($response[0])) {
+                       // Count API request
+                       countNetworkApiRequest($networkData);
+
+                       // Save response in cache
+                       saveNetworkResponseBodyInCache($networkData['network_id'], postRequestElement('network_type_id'), $responseBody, $networkData, 'MANUAL');
+               } // END - if
+       } // END - if
+
+       // Return the response
+       return $response;
+}
+
+/**
+ * Counts API request from given network data generated by getNetworkDataByTypeId()
+ *
+ * @param      $networkData    Array with network data
+ * @return     $affectedRows   Affected rows (always one or FALSE if unlimited/depleted)
+ */
+function countNetworkApiRequest ($networkData) {
+       // Get API config
+       $apiConfig = getFullNetworkConfigurationByTypeId($networkData['network_type_id']);
+
+       // Is the daily or remaining free amount zero?
+       if (($networkData['network_query_amount'] == 0) || ($apiConfig['network_api_remaining_requests'] == 0)) {
+               // Then abort here
+               return FALSE;
+       } // END - if
+
+       // Okay, so update database
+       $result = SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_network_api_config` SET `network_api_remaining_requests`=`network_api_remaining_requests`-1 WHERE `network_id`=%s LIMIT 1",
+               array(
+                       bigintval($networkData['network_id'])
+               ), __FUNCTION__, __LINE__);
+
+       // Return affected rows
+       return SQL_AFFECTEDROWS();
+}
+
+/**
+ * Generates a referral link for given network id (including HTML)
+ *
+ * @param      $networkId      Network id to generate link for
+ * @return     $output         "Rendered" output
+ */
+function generateMetworkReferralLinkById ($networkId) {
+       // Simple output (no need for template!)
+       $output = '<a href="{%network,getNetworkDataFromId,network_reflink=' . $networkId . '%}" target="_blank" title="{%network,getNetworkDataFromId,network_title=' . $networkId . '%}">{%network,getNetworkDataFromId,network_title=' . $networkId . '%}</a>';
+
+       // Return it
+       return $output;
+}
+
+//------------------------------------------------------------------------------
+//               "Translation" functions (can be used in EL code)
+//------------------------------------------------------------------------------
+
+// Translates 'translate_name' for e.g. templates
+function translateNetworkTranslationName ($name) {
+       // Return message id
+       return translateGeneric('ADMIN_NETWORK_TRANSLATE', $name, '_NAME');
+}
+
+// Translates the network type id to a handler
+function translateNetworkTypeHandlerByTypeId ($typeId) {
+       // Get the data
+       $data = getNetworkDataByTypeId($typeId, 'network_type_handler');
+
+       // Is data found?
+       if (is_null($data)) {
+               // Not found
+               return translateNetworkTypeHandler('UNKNOWN');
+       } // END - if
+
+       // Return actual translation
+       return translateNetworkTypeHandler($data);
+}
+
+// "Translates" give network media output (type)
+function translateNetworkMediaOutputType ($mediaOutput) {
+       // Return message id
+       return translateGeneric('ADMIN_NETWORK_MEDIA_OUTPUT', $mediaOutput);
+}
+
+// Translates the network type handler (e.g. banner, paidmail) for templates
+function translateNetworkTypeHandler ($type) {
+       // Generate id
+       $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
+
+       // Is the message id there?
+       if (!isMessageIdValid($messageId)) {
+               // Not valid type
+               reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
+       } // END - if
+
+       // Return message id
+       return '{--' . $messageId . '--}';
+}
+
+// Translates request type
+function translateNetworkRequestType ($type) {
+       // Generate id
+       $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
+
+       // Is the message id there?
+       if (!isMessageIdValid($messageId)) {
+               // Not valid type
+               reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
+       } // END - if
+
+       // Return message id
+       return '{--' . $messageId . '--}';
+}
+
+// Translates request parameter
+function translateNetworkRequestParameterKey ($param) {
+       // Generate id
+       $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
+
+       // Is the message id there?
+       if (!isMessageIdValid($messageId)) {
+               // Not valid param
+               reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
+       } // END - if
+
+       // Return message id
+       return '{--' . $messageId . '--}';
+}
+
+// Translate text-encoding
+function translateNetworkTextEncoding ($encoding) {
+       // Generate id
+       $messageId = 'ADMIN_NETWORK_TYPE_TEXT_ENCODING_' . strtoupper($encoding) . '';
+
+       // Is the message id there?
+       if (!isMessageIdValid($messageId)) {
+               // Not valid encoding
+               reportBug(__FUNCTION__, __LINE__, 'encoding=' . $encoding . ' is invalid.');
+       } // END - if
+
+       // Return message id
+       return '{--' . $messageId . '--}';
+}
+
+// Translates API index
+function translateNetworkApiIndex ($index) {
+       // Is there cache?
+       if (!isset($GLOBALS['network_array_index'])) {
                // Get an array of all API array indexes
-               $GLOBALS['network_api_index'] = array();
+               $GLOBALS['network_array_index'] = array();
 
                // Get all entries
                $result = SQL_QUERY('SELECT
-       `network_api_id`,`network_api_index`,`network_translation_name`
+       `network_array_id`,
+       `network_array_index`,
+       `network_translation_name`
 FROM
-       `{?_MYSQL_PREFIX?}_network_api_translation`
+       `{?_MYSQL_PREFIX?}_network_array_translation`
 INNER JOIN
        `{?_MYSQL_PREFIX?}_network_translations`
 ON
-       `network_api_index`=`network_translation_id`
+       `network_array_index`=`network_translation_id`
 ORDER BY
-       `sort` ASC', __FUNCTION__, __LINE__);
+       `network_array_sort` ASC', __FUNCTION__, __LINE__);
 
-               // Do we have entries?
+               // Are there entries?
                if (!SQL_HASZERONUMS($result)) {
                        // Get all entries
                        while ($row = SQL_FETCHARRAY($result)) {
                                // Add it to our global array
-                               $GLOBALS['network_api_index'][$row['network_api_index']] = $row;
+                               $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
                        } // END - while
                } // END - if
 
@@ -758,9 +1428,9 @@ ORDER BY
        $name = 'unknown';
 
        // Is the entry there?
-       if (isset($GLOBALS['network_api_index'][$index])) {
+       if (isset($GLOBALS['network_array_index'][$index])) {
                // Then get the name
-               $name = $GLOBALS['network_api_index'][$index]['network_translation_name'];
+               $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
        } // END - if
 
        // Return translation
@@ -769,13 +1439,16 @@ ORDER BY
 
 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
 function translateNetworkApiConfiguredStatusById ($networkId) {
-       // Do we have cache?
+       // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
                // By default it is not configured
                $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
 
                // So is it configured?
-               if (isNetworkApiConfigured($networkId)) {
+               if (!isNetworkActiveById($networkId)) {
+                       // Network is not active
+                       $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_ACTIVE--}';
+               } elseif (isNetworkApiConfigured($networkId)) {
                        // Yes, it is
                        $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
                } // END - if
@@ -785,45 +1458,360 @@ function translateNetworkApiConfiguredStatusById ($networkId) {
        return $GLOBALS[__FUNCTION__][$networkId];
 }
 
-// Checks if the given network is configured by looking its API configuration entry up
-function isNetworkApiConfigured ($networkId) {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
-               // Check for an entry in network_api_config
-               $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
-                       bigintval($networkId),
-                       'network_api_config',
-                       'network_id',
-                       'network_id',
-                       true
-               ) == 1);
+/**
+ * "Translates" given amount of queries; 0 = unlimited
+ *
+ * @param      $amount                 Amount of free queries
+ * @return     $translated             "Translated" value; 0 = unlimited
+ */
+function translateNetworkQueryAmount ($amount) {
+       // Default is unlimited (good! ;-) )
+       $translated = '{--UNLIMITED--}';
+
+       // Is the amount larger zero?
+       if ($amount > 0) {
+               // Then translate it
+               $translated = translateComma($amount);
        } // END - if
 
-       // Return cache
-       return $GLOBALS[__FUNCTION__][$networkId];
+       // Return translated value
+       return $translated;
 }
 
-// Checks wether the given network type handler is configured
-function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
-       // Do we have cache?
-       if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
-                       bigintval($networkTypeId),
-                       'network_types_config',
-                       'network_data_id',
-                       'network_type_id',
-                       true,
-                       sprintf(' AND `network_id`=%s', bigintval($networkId))
-               ) == 1);
+/**
+ * "Translates given status (Y/N) to "de-/activated" but only if expert and
+ * debug mode are enabled.
+ *
+ * @param      $status                 Can be one of Y/N
+ * @return     $translated             "Translated" status
+ */
+function translateNetworkActivationStatus ($status) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$status])) {
+               // Default is not enabled
+               $GLOBALS[__FUNCTION__][$status] = '';
+
+               // Is expert + debug mode enabled?
+               if ((isAdminsExpertSettingEnabled()) && (isDebugModeEnabled())) {
+                       // Then "translate" it
+                       $GLOBALS[__FUNCTION__][$status] = translateActivationStatus($status);
+               } // END - if
        } // END - if
 
-       // Return cache
-       return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
+       // Return "translation"
+       return $GLOBALS[__FUNCTION__][$status];
+}
+
+//------------------------------------------------------------------------------
+//               Wrapper functions to save data to network tables
+//------------------------------------------------------------------------------
+
+// Updates given network (id) with data from array
+function doNetworkUpdateDataByArray ($networkId, $networkData) {
+       // Ids lower one are not accepted
+       if (!isValidId($networkId)) {
+               // Not good, should be fixed
+               reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
+       } // END - if
+
+       // Just call our inner method
+       return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), FALSE, FALSE);
+}
+
+// Updates given network type handler (id) with data from array
+function doNetworkUpdateTypeByArray ($networkTypeId, $networkTypeData) {
+       // Ids lower one are not accepted
+       if (!isValidId($networkTypeId)) {
+               // Not good, should be fixed
+               reportBug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkTypeId . ' is smaller than 1.');
+       } // END - if
+
+       // Just call our inner method
+       return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkTypeId)), array(), FALSE, FALSE);
+}
+
+// Updates given network request parameters (id) with data from array
+function doNetworkUpdateParamsByArray ($networkParamsId, $networkParamsData) {
+       // Ids lower one are not accepted
+       if (!isValidId($networkParamsId)) {
+               // Not good, should be fixed
+               reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkParamsId . ' is smaller than 1.');
+       } // END - if
+
+       // Just call our inner method
+       return adminSaveSettings($networkParamsData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkParamsId)), array(), FALSE, FALSE);
+}
+
+// Updates given network array translations (id) with data from array
+function doNetworkUpdateArrayTranslationsByArray ($networkTranslationsId, $networkTranslationsData) {
+       // Ids lower one are not accepted
+       if (!isValidId($networkTranslationsId)) {
+               // Not good, should be fixed
+               reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkTranslationsId . ' is smaller than 1.');
+       } // END - if
+
+       // Just call our inner method
+       return adminSaveSettings($networkTranslationsData, '_network_array_translation', sprintf("`network_array_id`=%s", bigintval($networkTranslationsId)), array(), FALSE, FALSE);
+}
+
+//------------------------------------------------------------------------------
+//                 Call-back functions for request parameter keys
+//------------------------------------------------------------------------------
+
+// ----------------------- Table: network_api_config -----------------------
+
+// Handles affiliate id
+function doHandleNetworkRequestAffiliateIdKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       } elseif (empty($configData['network_api_affiliate_id'])) {
+               // Required element is not set
+               reportBug(__FUNCTION__, __LINE__, 'network_api_affiliate_id for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+       }
+
+       // Return configured value
+       return $configData['network_api_affiliate_id'];
+}
+
+// Handles site id
+function doHandleNetworkRequestSiteIdKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       } elseif (empty($configData['network_api_site_id'])) {
+               // Required element is not set
+               reportBug(__FUNCTION__, __LINE__, 'network_api_site_id for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+       }
+
+       // Return configured value
+       return $configData['network_api_site_id'];
+}
+
+// Handles interface password
+function doHandleNetworkRequestPasswordKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       } elseif (empty($configData['network_api_password'])) {
+               // Required element is not set
+               reportBug(__FUNCTION__, __LINE__, 'network_api_password for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+       }
+
+       // Return configured value
+       return $configData['network_api_password'];
+}
+
+// ----------------------- Table: network_handler_config -----------------------
+
+// Handles reload lock
+function doHandleNetworkRequestReloadKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       }
+
+       // Return configured value
+       return caluculateTimeUnitValue($configData['network_max_reload_time'], $configData['network_type_reload_time_unit']);
+}
+
+// Handles minimum stay
+function doHandleNetworkRequestMinimumStayKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       }
+
+       // Return configured value
+       return $configData['network_min_waiting_time'];
+}
+
+// Handles maximum stay
+function doHandleNetworkRequestMaximumStayKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       }
+
+       // Return configured value
+       return $configData['network_max_waiting_time'];
+}
+
+// Handles remaining clicks
+function doHandleNetworkRequestRemainClicksKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       }
+
+       // Return configured value
+       return $configData['network_min_remain_clicks'];
+}
+
+// Handles remaining budget
+function doHandleNetworkRequestRemainBudgetKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       }
+
+       // Return configured value
+       return $configData['network_min_remain_budget'];
+}
+
+// Handles reward (payment)
+function doHandleNetworkRequestRewardKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       } elseif (empty($configData['network_min_payment'])) {
+               // Required element is not set
+               reportBug(__FUNCTION__, __LINE__, 'network_min_payment for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+       }
+
+       // Return configured value
+       return $configData['network_min_payment'];
+}
+
+// Handles media size
+function doHandleNetworkRequestSizeKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       } elseif (empty($configData['network_media_size'])) {
+               // Required element is not set
+               reportBug(__FUNCTION__, __LINE__, 'network_media_size for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+       }
+
+       // Return configured value
+       return $configData['network_media_size'];
+}
+
+// Handles media output (type)
+function doHandleNetworkRequestTypeKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       }
+
+       // Return configured value
+       return $configData['network_media_output'];
+}
+
+// Handles erotic
+function doHandleNetworkRequestEroticKey ($networkTypeId) {
+       // It is assumed that the network + type handler are both configured
+       // Load full config data (this will be "cached"!)
+       $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+       // Is the network activated?
+       if (!isset($configData['network_api_active'])) {
+               // Configuration could not be loaded
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+       } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+               // Is not activated, so don't handle it in non-debug mode
+               reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+       } elseif (empty($configData['network_allow_erotic'])) {
+               // Required element is not set
+               reportBug(__FUNCTION__, __LINE__, 'network_allow_erotic for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+       }
+
+       // Return configured value
+       return $configData['network_allow_erotic'];
 }
 
+// ----------------------- Table: network_request_params -----------------------
+
 //------------------------------------------------------------------------------
-//                             Call-back functions
+//                       Call-back functions for admin area
 //------------------------------------------------------------------------------
 
 // Callback function to add new network
@@ -831,32 +1819,29 @@ function doAdminNetworkProcessAddNetwork () {
        // We can say here, the form is sent, so check if the network is already added
        if (isNetworkNameValid(postRequestElement('network_short_name'))) {
                // Already there
-               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
-               return false;
+               displayErrorMessage('{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
+               return FALSE;
        } // END - if
 
-       // Remove the 'ok' part
-       unsetPostRequestElement('ok');
-
        // Add the whole request to database
        SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
 
        // Add the id for output only
-       setPostRequestElement('network_id', SQL_INSERTID());
+       setPostRequestElement('network_id', SQL_INSERT_ID());
 
        // Output message
        if (!SQL_HASZEROAFFECTED()) {
                // Successfully added
-               loadTemplate('admin_network_added', false, postRequestArray());
+               loadTemplate('admin_network_added', FALSE, postRequestArray());
        } else {
                // Not added
-               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
+               displayErrorMessage('{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
        }
 }
 
 // Displays selected networks for editing
-function doAdminNetworkProcessHandleNetwork () {
-       // Do we have selections?
+function doAdminNetworkProcessHandleNetworks () {
+       // Is there selections?
        if (ifPostContainsSelections()) {
                // Something has been selected, so start displaying one by one
                $OUT = '';
@@ -864,51 +1849,41 @@ function doAdminNetworkProcessHandleNetwork () {
                        // Is this selected?
                        if ($sel == 1) {
                                // Load this network's data
-                               $networkData = getNetworkDataById($networkId);
+                               $networkData = getNetworkDataFromId($networkId);
 
-                               // Do we have found the network?
+                               // Is there found the network?
                                if (count($networkData) > 0) {
-                                       if (isFormSent('edit')) {
-                                               // Add row template for editing
-                                               $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
-                                       } elseif (isFormSent('delete')) {
-                                               // Add row template for deleting
-                                               $OUT .= loadTemplate('admin_delete_networks_row', true, $networkData);
-                                       } else {
-                                               // Problem!
-                                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
-                                       }
+                                       // Add row template with given form name
+                                       $OUT .= loadTemplate('admin_' . getNetworkFormName() . '_networks_row', TRUE, $networkData);
                                } // END - if
                        } // END - if
                } // END - foreach
 
-               // If we have no rows, we don't need to display the edit form
+               // If there are no rows, we don't need to display the edit form
                if (!empty($OUT)) {
+                       // Init array with generic element
+                       $content = array(
+                               'rows' => $OUT
+                       );
+
                        // Output main template
-                       if (isFormSent('edit')) {
-                               loadTemplate('admin_edit_networks', false, $OUT);
-                       } elseif (isFormSent('delete')) {
-                               loadTemplate('admin_delete_networks', false, $OUT);
-                       } else {
-                               // Problem!
-                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
-                       }
+                       loadTemplate('admin_' . getNetworkFormName() . '_networks', FALSE, $content);
 
                        // Don't display the list/add new form
-                       $GLOBALS['network_display'] = false;
+                       $GLOBALS['network_display'] = FALSE;
                } else {
                        // Nothing selected/found
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
+                       displayErrorMessage('{--ADMIN_NETWORK_NOTHING_FOUND--}');
                }
        } // END - if
 }
 
 // Handle network type form
-function doAdminNetworkProcessHandleNetworkType () {
-       // Do we have selections?
+function doAdminNetworkProcessHandleNetworkTypes () {
+       // Is there selections?
        if (ifPostContainsSelections()) {
                // Load network data
-               $networkData = getNetworkDataById(getRequestElement('network_id'));
+               $networkData = getNetworkDataFromId(getRequestElement('network_id'));
 
                // Something has been selected, so start displaying one by one
                $OUT = '';
@@ -916,54 +1891,60 @@ function doAdminNetworkProcessHandleNetworkType () {
                        // Is this selected?
                        if ($sel == 1) {
                                // Load this network's data
-                               $networkTypeData = getNetworkTypeDataById($networkId);
+                               $networkTypeData = getNetworkTypeDataByTypeId($networkId);
 
-                               // Do we have found the network?
+                               // Is there found the network?
                                if (count($networkTypeData) > 0) {
-                                       if (isFormSent('edit')) {
+                                       if (getNetworkFormName() == 'edit') {
                                                // Add row template for deleting
-                                               $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
-                                       } elseif (isFormSent('delete')) {
+                                               $OUT .= loadTemplate('admin_edit_network_types_row', TRUE, $networkTypeData);
+                                       } elseif (getNetworkFormName() == 'delete') {
                                                // Add row template for deleting
-                                               $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
+                                               $OUT .= loadTemplate('admin_delete_network_types_row', TRUE, $networkTypeData);
                                        } else {
                                                // Problem!
-                                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                                               reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
                                        }
                                } // END - if
                        } // END - if
                } // END - foreach
 
-               // If we have no rows, we don't need to display the edit form
+               // If there are no rows, we don't need to display the edit form
                if (!empty($OUT)) {
+                       // Prepare array with generic elements
+                       $content = array(
+                               'rows'       => $OUT,
+                               'network_id' => bigintval(getRequestElement('network_id'))
+                       );
+
                        // Output main template
-                       if (isFormSent('edit')) {
-                               loadTemplate('admin_edit_network_types', false, $OUT);
-                       } elseif (isFormSent('delete')) {
-                               loadTemplate('admin_delete_network_types', false, $OUT);
+                       if (getNetworkFormName() == 'edit') {
+                               loadTemplate('admin_edit_network_types', FALSE, $content);
+                       } elseif (getNetworkFormName() == 'delete') {
+                               loadTemplate('admin_delete_network_types', FALSE, $content);
                        } else {
                                // Problem!
-                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                               reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
                        }
 
                        // Don't display the list/add new form
-                       $GLOBALS['network_display'] = false;
+                       $GLOBALS['network_display'] = FALSE;
                } else {
                        // Nothing selected/found
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_FOUND--}');
+                       displayErrorMessage('{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
                }
        } // END - if
 }
 
 // Handle network request parameter form
 function doAdminNetworkProcessHandleRequestParams () {
-       // Do we have selections?
+       // Is there selections?
        if (ifPostContainsSelections()) {
                // Init cache array
-               $GLOBALS['network_params_disabled'] = array();
+               $GLOBALS['network_request_params_disabled'] = array();
 
                // Load network data
-               $networkData = getNetworkDataById(getRequestElement('network_id'));
+               $networkData = getNetworkDataFromId(getRequestElement('network_id'));
 
                // Something has been selected, so start displaying one by one
                $OUT = '';
@@ -971,51 +1952,57 @@ function doAdminNetworkProcessHandleRequestParams () {
                        // Is this selected?
                        if ($sel == 1) {
                                // Load this network's data
-                               $networkRequestData = getNetworkRequestParamsDataById($networkId);
+                               $networkRequestData = getNetworkRequestParamsDataFromId($networkId);
 
-                               // Do we have found the network?
+                               // Is there found the network?
                                if (count($networkRequestData) > 0) {
-                                       if (isFormSent('edit')) {
+                                       if (getNetworkFormName() == 'edit') {
                                                // Add row template for deleting
-                                               $OUT .= loadTemplate('admin_edit_network_params_row', true, $networkRequestData);
-                                       } elseif (isFormSent('delete')) {
+                                               $OUT .= loadTemplate('admin_edit_network_request_params_row', TRUE, $networkRequestData);
+                                       } elseif (getNetworkFormName() == 'delete') {
                                                // Get type data
-                                               $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
+                                               $networkRequestData['network_type_data'] = getNetworkTypeDataByTypeId($networkRequestData['network_type_id']);
 
                                                // Add row template for deleting
-                                               $OUT .= loadTemplate('admin_delete_network_params_row', true, $networkRequestData);
+                                               $OUT .= loadTemplate('admin_delete_network_request_params_row', TRUE, $networkRequestData);
                                        } else {
                                                // Problem!
-                                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                                               reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
                                        }
                                } // END - if
                        } // END - if
                } // END - foreach
 
-               // If we have no rows, we don't need to display the edit form
+               // If there are no rows, we don't need to display the edit form
                if (!empty($OUT)) {
+                       // Prepare array with generic elements
+                       $content = array(
+                               'rows'       => $OUT,
+                               'network_id' => bigintval(getRequestElement('network_id'))
+                       );
+
                        // Output main template
-                       if (isFormSent('edit')) {
-                               loadTemplate('admin_edit_network_params', false, $OUT);
-                       } elseif (isFormSent('delete')) {
-                               loadTemplate('admin_delete_network_params', false, $OUT);
+                       if (getNetworkFormName() == 'edit') {
+                               loadTemplate('admin_edit_network_request_params', FALSE, $content);
+                       } elseif (getNetworkFormName() == 'delete') {
+                               loadTemplate('admin_delete_network_request_params', FALSE, $content);
                        } else {
                                // Problem!
-                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                               reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
                        }
 
                        // Don't display the list/add new form
-                       $GLOBALS['network_display'] = false;
+                       $GLOBALS['network_display'] = FALSE;
                } else {
                        // Nothing selected/found
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
+                       displayErrorMessage('{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
                }
        } // END - if
 }
 
 // Changes given networks
-function doAdminNetworkProcessChangeNetwork () {
-       // Do we have selections?
+function doAdminNetworkProcessChangeNetworks () {
+       // Is there selections?
        if (ifPostContainsSelections()) {
                // By default nothing is updated
                $updated = 0;
@@ -1034,10 +2021,10 @@ function doAdminNetworkProcessChangeNetwork () {
                                                continue;
                                        } // END - if
 
-                                       // Do we have this enty?
+                                       // Is there this enty?
                                        if (!isset($entry[$networkId])) {
                                                // Not found, needs fixing
-                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
+                                               reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
                                        } // END - if
 
                                        // Add this entry
@@ -1049,20 +2036,20 @@ function doAdminNetworkProcessChangeNetwork () {
                        } // END - if
                } // END - foreach
 
-               // Do we have updates?
+               // Is there updates?
                if ($updated > 0) {
                        // Updates done
                        displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
                } else {
                        // Nothing changed
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
+                       displayErrorMessage('{--ADMIN_NETWORK_NOTHING_CHANGED--}');
                }
        } // END - if
 }
 
 // Removes given networks
-function doAdminNetworkProcessRemoveNetwork () {
-       // Do we have selections?
+function doAdminNetworkProcessRemoveNetworks () {
+       // Is there selections?
        if (ifPostContainsSelections()) {
                // By default nothing is removed
                $removed = 0;
@@ -1076,13 +2063,13 @@ function doAdminNetworkProcessRemoveNetwork () {
                        } // END - if
                } // END - foreach
 
-               // Do we have removes?
+               // Is there removes?
                if ($removed > 0) {
                        // Removals done
                        displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
                } else {
                        // Nothing removed
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
+                       displayErrorMessage('{--ADMIN_NETWORK_NOTHING_REMOVED--}');
                }
        } // END - if
 }
@@ -1090,22 +2077,25 @@ function doAdminNetworkProcessRemoveNetwork () {
 // Add a network type handler if not yet found
 function doAdminNetworkProcessAddNetworkType () {
        // Is the network type handle already used with given network?
-       if (isNetworkTypeHandleValid(postRequestElement('network_type_handle'), getRequestElement('network_id'))) {
+       if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
                // Already added
-               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED=' . postRequestElement('network_type_handle') . '%}');
+               displayErrorMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
 
                // ... so abort here
-               return false;
+               return FALSE;
        } // END - if
 
-       // Remove the 'ok' part
-       unsetPostRequestElement('ok');
-
        // Add id
        setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
 
+       // Is network_type_click_url set?
+       if (!isPostRequestElementSet('network_type_click_url')) {
+               // Remove empty value to get a NULL for an optional entry
+               unsetPostRequestElement('network_type_click_url');
+       } // END - if
+
        // Is network_type_banner_url set?
-       if (postRequestElement('network_type_banner_url') == '') {
+       if (!isPostRequestElementSet('network_type_banner_url')) {
                // Remove empty value to get a NULL for an optional entry
                unsetPostRequestElement('network_type_banner_url');
        } // END - if
@@ -1116,16 +2106,16 @@ function doAdminNetworkProcessAddNetworkType () {
        // Output message
        if (!SQL_HASZEROAFFECTED()) {
                // Successfully added
-               loadTemplate('admin_network_type_added', false, postRequestArray());
+               loadTemplate('admin_network_type_added', FALSE, postRequestArray());
        } else {
                // Not added
-               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_NOT_ADDED=' . postRequestElement('network_type_handle') . '%}');
+               displayErrorMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
        }
 }
 
 // Changes given network type handlers
-function doAdminNetworkProcessChangeNetworkType () {
-       // Do we have selections?
+function doAdminNetworkProcessChangeHandlerTypes () {
+       // Is there selections?
        if (ifPostContainsSelections()) {
                // By default nothing is updated
                $updated = 0;
@@ -1144,14 +2134,14 @@ function doAdminNetworkProcessChangeNetworkType () {
                                                continue;
                                        } // END - if
 
-                                       // Do we have this enty?
+                                       // Is there this enty?
                                        if (!isset($entry[$networkId])) {
                                                // Not found, needs fixing
-                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
+                                               reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
                                        } // END - if
 
-                                       // Fix empty network_type_banner_url to NULL
-                                       if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
+                                       // Fix empty network_type_click/banner_url to NULL
+                                       if ((in_array($key, array('network_type_click_url', 'network_type_banner_url'))) && (trim($entry[$networkId]) == '')) {
                                                // Set it to NULL
                                                $entry[$networkId] = NULL;
                                        } // END - if
@@ -1165,20 +2155,20 @@ function doAdminNetworkProcessChangeNetworkType () {
                        } // END - if
                } // END - foreach
 
-               // Do we have updates?
+               // Is there updates?
                if ($updated > 0) {
                        // Updates done
-                       displayMessage('{%message,ADMIN_NETWORK_TYPES_UPDATED=' . $updated . '%}');
+                       displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
                } else {
                        // Nothing changed
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_CHANGED--}');
+                       displayErrorMessage('{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
                }
        } // END - if
 }
 
 // Changes given network request parameters
-function doAdminNetworkProcessChangeNetworkParam () {
-       // Do we have selections?
+function doAdminNetworkProcessChangeRequestParams () {
+       // Is there selections?
        if (ifPostContainsSelections()) {
                // By default nothing is updated
                $updated = 0;
@@ -1197,10 +2187,10 @@ function doAdminNetworkProcessChangeNetworkParam () {
                                                continue;
                                        } // END - if
 
-                                       // Do we have this enty?
+                                       // Is there this enty?
                                        if (!isset($entry[$networkId])) {
                                                // Not found, needs fixing
-                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
+                                               reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
                                        } // END - if
 
                                        // Fix empty network_request_param_default to NULL
@@ -1218,90 +2208,167 @@ function doAdminNetworkProcessChangeNetworkParam () {
                        } // END - if
                } // END - foreach
 
-               // Do we have updates?
+               // Is there updates?
                if ($updated > 0) {
                        // Updates done
                        displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
                } else {
                        // Nothing changed
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
+                       displayErrorMessage('{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
                }
        } // END - if
 }
 
-// Removes given network type handlers
-function doAdminNetworkProcessRemoveNetworkType () {
-       // Do we have selections?
+// Changes given network array translations
+function doAdminNetworkProcessChangeArrayTranslation () {
+       // Is there selections?
        if (ifPostContainsSelections()) {
-               // By default nothing is removed
-               $removed = 0;
+               // By default nothing is updated
+               $updated = 0;
 
                // Something has been selected, so start updating them
                foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Update this entry?
                        if ($sel == 1) {
-                               // Remove this entry
-                               $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
-                       } // END - if
-               } // END - foreach
-
-               // Do we have removes?
-               if ($removed > 0) {
-                       // Removals done
-                       displayMessage('{%message,ADMIN_NETWORK_TYPES_REMOVED=' . $removed . '%}');
-               } else {
-                       // Nothing removed
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_REMOVED--}');
-               }
-       } // END - if
-}
+                               // Init data array
+                               $networkTranslationsData = array();
 
-// Removes given network request parameters
-function doAdminNetworkProcessRemoveNetworkParam () {
-       // Do we have selections?
-       if (ifPostContainsSelections()) {
-               // By default nothing is removed
-               $removed = 0;
+                               // Transfer whole array, except 'sel'
+                               foreach (postRequestArray() as $key => $entry) {
+                                       // Skip 'sel' and submit button
+                                       if (in_array($key, array('sel', 'do_edit'))) {
+                                               continue;
+                                       } // END - if
 
-               // Something has been selected, so start updating them
+                                       // Is there this enty?
+                                       if (!isset($entry[$networkId])) {
+                                               // Not found, needs fixing
+                                               reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
+                                       } // END - if
+
+                                       // Fix empty network_request_param_default to NULL
+                                       if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
+                                               // Set it to NULL
+                                               $entry[$networkId] = NULL;
+                                       } // END - if
+
+                                       // Add this entry
+                                       $networkTranslationsData[$key] = $entry[$networkId];
+                               } // END - foreach
+
+                               // Update the network data
+                               $updated += doNetworkUpdateArrayTranslationsByArray($networkId, $networkTranslationsData);
+                       } // END - if
+               } // END - foreach
+
+               // Is there updates?
+               if ($updated > 0) {
+                       // Updates done
+                       displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_UPDATED=' . $updated . '%}');
+               } else {
+                       // Nothing changed
+                       displayErrorMessage('{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_CHANGED--}');
+               }
+       } // END - if
+}
+
+// Removes given network type handlers
+function doAdminNetworkProcessRemoveNetworkTypes () {
+       // Is there selections?
+       if (ifPostContainsSelections()) {
+               // By default nothing is removed
+               $removed = 0;
+
+               // Something has been selected, so start updating them
                foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Update this entry?
                        if ($sel == 1) {
                                // Remove this entry
-                               $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $networkId);
+                               $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
                        } // END - if
                } // END - foreach
 
-               // Do we have removes?
+               // Is there removes?
+               if ($removed > 0) {
+                       // Removals done
+                       displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
+               } else {
+                       // Nothing removed
+                       displayErrorMessage('{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
+               }
+       } // END - if
+}
+
+// Removes given network request parameters
+function doAdminNetworkProcessRemoveNetworkRequestParams () {
+       // Is there selections?
+       if (ifPostContainsSelections()) {
+               // By default nothing is removed
+               $removed = 0;
+
+               // Something has been selected, so start updating them
+               foreach (postRequestElement('sel') as $networkId => $sel) {
+                       // Update this entry?
+                       if ($sel == 1) {
+                               // Remove this entry
+                               $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
+                       } // END - if
+               } // END - foreach
+
+               // Is there removes?
                if ($removed > 0) {
                        // Removals done
                        displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
                } else {
                        // Nothing removed
-                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
+                       displayErrorMessage('{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
+               }
+       } // END - if
+}
+
+// Removes given network array translations
+function doAdminNetworkProcessRemoveNetworkArrayTranslation () {
+       // Is there selections?
+       if (ifPostContainsSelections()) {
+               // By default nothing is removed
+               $removed = 0;
+
+               // Something has been selected, so start updating them
+               foreach (postRequestElement('sel') as $networkId => $sel) {
+                       // Update this entry?
+                       if ($sel == 1) {
+                               // Remove this entry
+                               $removed += doAdminRemoveNetworkEntry('array_translation', 'network_array_id', $networkId);
+                       } // END - if
+               } // END - foreach
+
+               // Is there removes?
+               if ($removed > 0) {
+                       // Removals done
+                       displayMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_REMOVED=' . $removed . '%}');
+               } else {
+                       // Nothing removed
+                       displayErrorMessage('{--ADMIN_NETWORK_ARRAY_TRANSLATION_NOTHING_REMOVED--}');
                }
        } // END - if
 }
 
 // Adds a request parameter to given network and type
-function doAdminNetworkProcessAddNetworkParam () {
+function doAdminNetworkProcessAddRequestParam () {
        // Is the request parameter already used with given network?
        if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
                // Already added
-               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
+               displayErrorMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
 
                // ... so abort here
-               return false;
+               return FALSE;
        } // END - if
 
-       // Remove the 'ok' part
-       unsetPostRequestElement('ok');
-
        // Add id
        setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
 
        // Is network_request_param_default set?
-       if (postRequestElement('network_request_param_default') == '') {
+       if (!isPostRequestElementSet('network_request_param_default')) {
                // Remove empty value to get a NULL for an optional entry
                unsetPostRequestElement('network_request_param_default');
        } // END - if
@@ -1312,66 +2379,127 @@ function doAdminNetworkProcessAddNetworkParam () {
        // Output message
        if (!SQL_HASZEROAFFECTED()) {
                // Successfully added
-               loadTemplate('admin_network_network_request_param_added', false, postRequestArray());
+               loadTemplate('admin_network_request_param_added', FALSE, postRequestArray());
        } else {
                // Not added
-               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
+               displayErrorMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
        }
 }
 
 // Adds a API response array entry
-function doAdminNetworkProcessAddNetworkApiTranslation () {
+function doAdminNetworkProcessAddNetworkArrayTranslation () {
        // Is the request parameter already used with given network?
-       if (isNetworkApiTranslationValid(postRequestElement('network_api_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
+       if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
                // Already added
-               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_api_index') . '%}');
+               displayErrorMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
 
                // ... so abort here
-               return false;
+               return FALSE;
        } // END - if
 
-       // Remove the 'ok' part
-       unsetPostRequestElement('ok');
-
        // Add id
        setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
 
        // Add sorting
-       setPostRequestElement('sort', (countSumTotalData(
+       setPostRequestElement('network_array_sort', (countSumTotalData(
                bigintval(postRequestElement('network_id')),
-               'network_api_translation',
-               'network_api_id',
+               'network_array_translation',
+               'network_array_id',
                'network_id',
                true,
                sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
        ) + 1));
 
        // Add the whole request to database
-       SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_api_translation'), __FUNCTION__, __LINE__);
+       SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
 
        // Output message
        if (!SQL_HASZEROAFFECTED()) {
                // Successfully added
-               loadTemplate('admin_network_api_translation_added', false, postRequestArray());
+               loadTemplate('admin_network_array_translation_added', FALSE, postRequestArray());
        } else {
                // Not added
-               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_NOT_ADDED=' . postRequestElement('network_api_index') . '%}');
+               displayErrorMessage('{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
        }
 }
 
+// Handle network array translation form
+function doAdminNetworkProcessHandleArrayTranslations () {
+       // Is there selections?
+       if (ifPostContainsSelections()) {
+               // Init cache array
+               $GLOBALS['network_array_translation_disabled'] = array();
+
+               // Load network data
+               $networkData = getNetworkDataFromId(getRequestElement('network_id'));
+
+               // Something has been selected, so start displaying one by one
+               $OUT = '';
+               foreach (postRequestElement('sel') as $networkId => $sel) {
+                       // Is this selected?
+                       if ($sel == 1) {
+                               // Load this network's data
+                               $networkTranslationsData = getNetworkArrayTranslationsDataFromId($networkId);
+
+                               // Is there found the network?
+                               if (count($networkTranslationsData) > 0) {
+                                       if (getNetworkFormName() == 'edit') {
+                                               // Add row template for deleting
+                                               $OUT .= loadTemplate('admin_edit_network_array_translation_row', TRUE, $networkTranslationsData);
+                                       } elseif (getNetworkFormName() == 'delete') {
+                                               // Get type data
+                                               $networkTranslationsData['network_type_data'] = getNetworkTypeDataByTypeId($networkTranslationsData['network_type_id']);
+
+                                               // Add row template for deleting
+                                               $OUT .= loadTemplate('admin_delete_network_array_translation_row', TRUE, $networkTranslationsData);
+                                       } else {
+                                               // Problem!
+                                               reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
+                                       }
+                               } // END - if
+                       } // END - if
+               } // END - foreach
+
+               // If there are no rows, we don't need to display the edit form
+               if (!empty($OUT)) {
+                       // Prepare array with generic elements
+                       $content = array(
+                               'rows'       => $OUT,
+                               'network_id' => bigintval(getRequestElement('network_id'))
+                       );
+
+                       // Output main template
+                       if (getNetworkFormName() == 'edit') {
+                               loadTemplate('admin_edit_network_array_translation', FALSE, $content);
+                       } elseif (getNetworkFormName() == 'delete') {
+                               loadTemplate('admin_delete_network_array_translation', FALSE, $content);
+                       } else {
+                               // Problem!
+                               reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/delete. data=<pre>' . print_r(postRequestArray(), TRUE) . '</pre>');
+                       }
+
+                       // Don't display the list/add new form
+                       $GLOBALS['network_display'] = FALSE;
+               } else {
+                       // Nothing selected/found
+                       displayErrorMessage('{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
+               }
+       } // END - if
+}
+
 // Adds/update network API configuration
 function doAdminNetworkProcessNetworkApiConfig () {
-       // Remove the 'ok' part
-       unsetPostRequestElement('ok');
-
        // Add id
        setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
 
-       // Is network_api_referral_button set?
-       if (postRequestElement('network_api_referral_button') == '') {
-               // Remove empty value to get a NULL for an optional entry
-               unsetPostRequestElement('network_api_referral_button');
-       } // END - if
+       // NULL empty values
+       foreach (array('network_api_site_id', 'network_api_referral_button', 'network_api_visual_pay_check') as $key) {
+               // Is it set?
+               if (!isPostRequestElementSet($key)) {
+                       // Remove empty value to get a NULL for an optional entry
+                       unsetPostRequestElement($key);
+               } // END - if
+       } // END - foreach
 
        // Is there already an entry?
        if (isNetworkApiConfigured(getRequestElement('network_id'))) {
@@ -1391,63 +2519,203 @@ function doAdminNetworkProcessNetworkApiConfig () {
                displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
        } else {
                // Not added
-               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
+               displayErrorMessage('{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
        }
 }
 
 // Only adds network type configuration if not yet present
-function doAdminNetworkProcessAddNetworkTypesConfig () {
-       // Remove the 'ok' part
-       unsetPostRequestElement('ok');
-
+function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = TRUE, $convertComma = TRUE) {
        // Add both ids
        setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
        setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
 
+       // Convert comma to dot?
+       if ($convertComma === TRUE) {
+               // Translate German comma to dot
+               convertCommaToDotInPostData('network_min_payment');
+               convertCommaToDotInPostData('network_min_remain_budget');
+               convertCommaToDotInPostData('network_min_remain_clicks');
+       } // END - if
+
        /*
         * Some parameters are optional, at least one must be given so check a bunch
         * of parameters.
         */
-       foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
+       foreach (array('network_min_waiting_time', 'network_max_waiting_time', 'network_min_remain_budget', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic', 'network_media_size', 'network_media_output') as $element) {
                // Is this element empty?
-               if (postRequestElement($element) == '') {
+               if (!isPostRequestElementSet($element)) {
                        // Then unset it to get a NULL for optional parameter
                        unsetPostRequestElement($element);
                } // END - if
        } // END - foreach
 
-       // Initialize variables
-       $content = array();
-       $id = 'network_max_reload_time_ye';
-       $skip = false;
-       $postData = postRequestArray();
-
-       // Convert "reload time selections"
-       convertSelectionsToEpocheTime($postData, $content, $id, $skip);
-
-       // Set the POST array back
-       setPostRequestArray($postData);
+       // Convert data in POST array
+       convertSelectionsToEpocheTimeInPostData('network_max_reload_time_ye');
 
        // Is there already an entry?
        if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
                // This network type handler is already configured
-               displayMessage('{--ADMIN_NETWORK_TYPE_HANDLER_ALREADY_CONFIGURED--}');
+               displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
                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');
+
+       // 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__);
+
+               // Are there entries?
+               if (SQL_HASZERONUMS($result)) {
+                       // No, then abort here
+                       displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
+                       return;
+               } // END - if
 
-       // Run the query
-       SQL_QUERY($SQL, __FUNCTION__, __LINE__);
+               // Init number of rows
+               $numRows = 0;
 
-       // Output message
-       if (!SQL_HASZEROAFFECTED()) {
-               // Successfully added
-               displayMessage('{--ADMIN_NETWORK_TYPE_HANDLER_CONFIG_SAVED--}');
+               // 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, 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
+                       displayErrorMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
+               }
        } else {
-               // Not added
-               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_CONFIG_NOT_SAVED--}');
+               // Get SQL query for new entry
+               $SQL = getInsertSqlFromArray(postRequestArray(), 'network_handler_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
+                               displayErrorMessage('{--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 ($displayMessage = TRUE, $convertComma = TRUE) {
+       // Convert comma to dot?
+       if ($convertComma === TRUE) {
+               // Translate German comma to dot
+               convertCommaToDotInPostData('network_min_payment');
+               convertCommaToDotInPostData('network_min_remain_budget');
+               convertCommaToDotInPostData('network_min_remain_clicks');
+       } // END - if
+
+       /*
+        * Some parameters are optional, at least one must be given so check a bunch
+        * of parameters.
+        */
+       foreach (array('network_min_waiting_time', 'network_max_waiting_time', 'network_min_remain_budget', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic', 'network_media_size', 'network_media_output') as $element) {
+               // Is this element empty?
+               if (!isPostRequestElementSet($element)) {
+                       // Then unset it to get a NULL for optional parameter
+                       unsetPostRequestElement($element);
+               } // END - if
+       } // END - foreach
+
+       // Convert time selections in POST data
+       convertSelectionsToEpocheTimeInPostData('network_max_reload_time_ye');
+
+       // Is there already an entry?
+       if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
+               // This network type handler is not configured
+               displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
+               return;
+       } // END - if
+
+       // Copy 'set all' and remove it from POST data
+       $setAll = (postRequestElement('set_all') === 'Y');
+       unsetPostRequestElement('set_all');
+
+       // Shall we set for all?
+       if ($setAll === TRUE) {
+               // Get all data entries
+               $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_handler_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
+                       array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
+
+               // Are there 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, 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
+                       displayErrorMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
+               }
+       } else {
+               // Get SQL query for new entry
+               $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_handler_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
+                               displayErrorMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
+                       }
+               } else {
+                       // Return amount of affected rows (1 or 2)
+                       return SQL_AFFECTEDROWS();
+               }
        }
 }
 
@@ -1461,8 +2729,23 @@ function doExpressionNetwork ($data) {
                $data['extra_func']
        );
 
-       // Replace %network_id% with the current network id
-       $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
+       // Check matches[2] as it might contain more clues to look for
+       $moreData = explode(',', $data['matches'][2][$data['key']]);
+
+       // First must be 'network' so unshift it
+       shift_array($moreData, 'network');
+
+       // The second element must be a callable function
+       if (!is_callable($moreData[0])) {
+               // Is not callable!
+               reportBug(__FUNCTION__, __LINE__, 'Call-back function ' . $moreData[0] . ' cannot be called.');
+       } // END - if
+
+       // Is the current network id set?
+       if (isCurrentNetworkIdSet()) {
+               // Replace %network_id% with the current network id
+               $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
+       } // END - if
 
        // Replace the code
        $code = replaceExpressionCode($data, $replacer);
@@ -1471,5 +2754,371 @@ function doExpressionNetwork ($data) {
        return $code;
 }
 
+// ----------------------------------------------------------------------------
+//                     Call-back functions for exporting data
+// ----------------------------------------------------------------------------
+
+// Callback function to export network tables
+function doAdminNetworkProcessExport () {
+       // Init table with all valid what->table entries
+       $validExports = array(
+               // General network data
+               'list_network_data'              => 'data',
+               // Network type handler
+               'list_network_types'             => 'types',
+               // Network request parameter
+               'list_network_request_params'    => 'request_params',
+               // Network API response array index translation
+               'list_network_array_translation' => 'array_translation',
+       );
+
+       // Is the 'what' key valid?
+       if (!isset($validExports[getWhat()])) {
+               // Not valid
+               reportBug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
+       } // END - if
+
+       // Generate call-back, some tables require to export not all columns
+       $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
+
+       // Is the call-back function there?
+       if (!function_exists($callbackName)) {
+               // No, this is really bad
+               reportBug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
+       } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
+               // Already called!
+               reportBug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
+       }
+
+       // Call the function
+       call_user_func($callbackName);
+
+       // Mark it as called
+       $GLOBALS[__FUNCTION__][$callbackName] = TRUE;
+
+       // Don't display the list/add new form
+       $GLOBALS['network_display'] = FALSE;
+}
+
+// Exports (and displays) the table 'network_data'
+function doAdminNetworkExportData () {
+       // Query for all networks
+       $result = SQL_QUERY('SELECT
+       `network_short_name`,
+       `network_title`,
+       `network_reflink`,
+       `network_data_separator`,
+       `network_row_separator`,
+       `network_request_type`,
+       `network_charset`,
+       `network_require_id_card`,
+       `network_query_amount`,
+       `network_active`
+FROM
+       `{?_MYSQL_PREFIX?}_network_data`
+ORDER BY
+       `network_id` ASC',
+               __FUNCTION__, __LINE__);
+
+       // Start an empty SQL query
+       $SQL = 'INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_data` (`network_short_name`, `network_title`, `network_reflink`, `network_data_separator`, `network_row_separator`, `network_request_type`, `network_charset`, `network_require_id_card`, `network_query_amount`, `network_active`) VALUES' . PHP_EOL;
+
+       // Load all entries
+       while ($content = SQL_FETCHARRAY($result)) {
+               // Add row
+               $SQL .= "('" .
+                       $content['network_short_name'] . "', '" .
+                       $content['network_title'] . "', '" .
+                       $content['network_reflink'] . "', '" .
+                       $content['network_data_separator'] . "', '" .
+                       $content['network_row_separator'] . "', '" .
+                       $content['network_request_type'] . "', '" .
+                       $content['network_charset'] . "', '" .
+                       $content['network_require_id_card'] . "', " .
+                       $content['network_query_amount'] . ", '" .
+                       $content['network_active'] . "'),\n";
+       } // END - while
+
+       // Remove last commata and close braces
+       $SQL = substr($SQL, 0, -2);
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Output the SQL query
+       loadTemplate('admin_export_network_data', FALSE, $SQL);
+}
+
+// Exports (and displays) the table 'network_types'
+function doAdminNetworkExportTypes () {
+       // 'network_id' must be set
+       if (!isGetRequestElementSet('network_id')) {
+               // Only network handlers of one network will be exported per time
+               reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
+       } // END - if
+
+       // Get all network types of given network
+       $result = SQL_QUERY_ESC('SELECT
+       `network_type_id`,
+       `network_id`,
+       `network_type_handler`,
+       `network_type_api_url`,
+       `network_type_click_url`,
+       `network_type_banner_url`,
+       `network_type_reload_time_unit`,
+       `network_text_encoding`
+FROM
+       `{?_MYSQL_PREFIX?}_network_types`
+WHERE
+       `network_id`=%s
+ORDER BY
+       `network_type_id` ASC',
+               array(
+                       bigintval(getRequestElement('network_id'))
+               ), __FUNCTION__, __LINE__);
+
+       // Start an empty SQL query
+       $SQL = 'INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_types` (`network_type_id`, `network_id`, `network_type_handler`, `network_type_api_url`, `network_type_click_url`, `network_type_banner_url`, `network_type_reload_time_unit`, `network_text_encoding`) VALUES' . PHP_EOL;
+
+       // Load all entries
+       while ($content = SQL_FETCHARRAY($result)) {
+               // Add row
+               $SQL .= '(' .
+                       $content['network_type_id'] . ', ' .
+                       $content['network_id'] . ", '" .
+                       $content['network_type_handler'] . "', '" .
+                       $content['network_type_api_url'] . "', ";
+
+               // Is the column NULL?
+               if ((is_null($content['network_type_click_url'])) || (empty($content['network_type_click_url']))) {
+                       // Column is NULL
+                       $SQL .= 'NULL, ';
+               } else {
+                       // Column is set
+                       $SQL .= chr(39) . $content['network_type_click_url'] . chr(39) . ', ';
+               }
+
+               // Is the column NULL?
+               if ((is_null($content['network_type_banner_url'])) || (empty($content['network_type_banner_url']))) {
+                       // Column is NULL
+                       $SQL .= 'NULL, ';
+               } else {
+                       // Column is set
+                       $SQL .= chr(39) . $content['network_type_banner_url'] . chr(39) . ', ';
+               }
+
+               // Add more
+               $SQL .= chr(39) . $content['network_type_reload_time_unit'] . "','" . $content['network_text_encoding'] . "'),\n";
+       } // END - while
+
+       // Remove last commata and close braces
+       $SQL = substr($SQL, 0, -2);
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Output the SQL query
+       loadTemplate('admin_export_network_types', FALSE, $SQL);
+}
+
+// Exports (and displays) the table 'network_request_params'
+function doAdminNetworkExportRequestParams () {
+       // 'network_id' must be set
+       if (!isGetRequestElementSet('network_id')) {
+               // Only network request parameters of one network will be exported per time
+               reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
+       } // END - if
+
+       // Get all network types of given network
+       $result = SQL_QUERY_ESC('SELECT
+       `network_id`,
+       `network_type_id`,
+       `network_request_param_key`,
+       `network_request_param_value`,
+       `network_request_param_default`
+FROM
+       `{?_MYSQL_PREFIX?}_network_request_params`
+WHERE
+       `network_id`=%s
+ORDER BY
+       `network_type_id` ASC ,
+       `network_request_param_id` ASC',
+               array(
+                       bigintval(getRequestElement('network_id'))
+               ), __FUNCTION__, __LINE__);
+
+       // Start an empty SQL query
+       $SQL = 'INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_request_params` (`network_id`, `network_type_id`, `network_request_param_key`, `network_request_param_value`, `network_request_param_default`) VALUES' . PHP_EOL;
+
+       // Load all entries
+       while ($content = SQL_FETCHARRAY($result)) {
+               // Add row
+               $SQL .= '(' .
+                       $content['network_id'] . ', ' .
+                       $content['network_type_id'] . ", '" .
+                       $content['network_request_param_key'] . "', '" .
+                       $content['network_request_param_value'] . "', ";
+               
+               // Is the column NULL?
+               if (is_null($content['network_request_param_default'])) {
+                       // Column is NULL
+                       $SQL .= "NULL),\n";
+               } else {
+                       // Column is set
+                       $SQL .= chr(39) . $content['network_request_param_default'] . "'),\n";
+               }
+       } // END - while
+
+       // Remove last commata and close braces
+       $SQL = substr($SQL, 0, -2);
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Output the SQL query
+       loadTemplate('admin_export_network_request_params', FALSE, $SQL);
+}
+
+// Exports (and displays) the table 'network_array_translation'
+function doAdminNetworkExportArrayTranslation () {
+       // 'network_id' must be set
+       if (!isGetRequestElementSet('network_id')) {
+               // Only network API array index translations of one network will be exported per time
+               reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
+       } // END - if
+
+       // Get all network types of given network
+       $result = SQL_QUERY_ESC('SELECT
+       `network_id`,
+       `network_type_id`,
+       `network_array_index`,
+       `network_array_sort`
+FROM
+       `{?_MYSQL_PREFIX?}_network_array_translation`
+WHERE
+       `network_id`=%s
+ORDER BY
+       `network_type_id` ASC,
+       `network_array_sort` ASC',
+               array(
+                       bigintval(getRequestElement('network_id'))
+               ), __FUNCTION__, __LINE__);
+
+       // Start an empty SQL query
+       $SQL = 'INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_array_translation` (`network_id`, `network_type_id`, `network_array_index`, `network_array_sort`) VALUES' . PHP_EOL;
+
+       // Load all entries
+       while ($content = SQL_FETCHARRAY($result)) {
+               // Add row
+               $SQL .= '(' .
+                       $content['network_id'] . ', ' .
+                       $content['network_type_id'] . ', ' .
+                       $content['network_array_index'] . ', ' .
+                       $content['network_array_sort'] . "),\n";
+       } // END - while
+
+       // Remove last commata and close braces
+       $SQL = substr($SQL, 0, -2);
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Output the SQL query
+       loadTemplate('admin_export_network_array_translation', FALSE, $SQL);
+}
+
+// ----------------------------------------------------------------------------
+//                     Call-back functions for AJAX requests
+// ----------------------------------------------------------------------------
+
+// AJAX call-back function for quering a single API
+function doAjaxAdminNetworkQuerySingleApi () {
+       // This must be be done only by admins
+       if (!isAdmin()) {
+               // Only allowed for admins
+               reportBug(__FUNCTION__, __LINE__, 'Only allowed for admins.');
+       } elseif (!isPostRequestElementSet('network_type_id')) {
+               // Required POST field 'network_type_id' is not there
+               reportBug(__FUNCTION__, __LINE__, 'Required POST field &quot;network_type_id&quot; is missing.');
+       }
+
+       // Get network + type handler data
+       $networkData = getNetworkDataByTypeId(postRequestElement('network_type_id'));
+
+       // Is it set?
+       if (is_null($networkData)) {
+               // Provided type id is not found
+               reportBug(__FUNCTION__, __LINE__, 'Requested network type id ' . postRequestElement('network_type_id') . ' does not exist.');
+       } elseif ((!isDebugModeEnabled()) && ($networkData['network_active'] == 'N')) {
+               // Network not active
+               reportBug(__FUNCTION__, __LINE__, 'Network ' . $networkData['network_title'] . ' is not active. network_id=' . $networkData['network_id'] . ',network_type_id=' . postRequestElement('network_type_id'));
+       } elseif (!isNetworkApiConfigured($networkData['network_id'])) {
+               // Network not configured
+               reportBug(__FUNCTION__, __LINE__, 'Network ' . $networkData['network_title'] . ' is not configured yet. network_id=' . $networkData['network_id'] . ',network_type_id=' . postRequestElement('network_type_id'));
+       } elseif (!isNetworkTypeHandlerConfigured($networkData['network_id'], postRequestElement('network_type_id'))) {
+               // Network type handler not configured
+               reportBug(__FUNCTION__, __LINE__, 'Network type handler ' . $networkData['network_type_handler'] . ' for network ' . $networkData['network_title'] . ' is not configured yet. network_id=' . $networkData['network_id'] . ',network_type_id=' . postRequestElement('network_type_id'));
+       }
+
+       // Now load request parameters
+       $requestParams = getNetworkRequestParametersByTypeId(postRequestElement('network_type_id'));
+
+       // Is there at least one entry?
+       if (count($requestParams) == 0) {
+               // No entry found, please setup some first
+               reportBug(__FUNCTION__, __LINE__, 'Network ' . $networkData['network_title'] . ' with id ' . $networkData['network_id'] . ' has no request parameters.');
+       } // END - if
+
+       // Handle all keys
+       handleNetworkRequestParameterKeys($requestParams);
+
+       /*
+        * Array element network_request_param_value contains the request parameter
+        * keys, network_request_param_default contains values. Now the request can
+        * be build.
+        */
+       $requestData = array();
+       foreach ($requestParams as $key => $params) {
+               // Add id
+               $requestData[$params['network_request_param_value']] = $params['network_request_param_default'];
+       } // END - foreach
+
+       // Everything is setup and ready to send out to the affiliate network's API
+       $response = queryNetworkApi($networkData, $requestData);
+
+       // Is the returned HTTP status '200 OK'?
+       if (!isHttpStatusOkay($response[0])) {
+               // Not HTTP/1.x 200 OK
+               reportBug(__FUNCTION__, __LINE__, 'HTTP response code is not 200 OK, have: ' . $response[0]);
+       } // END - if
+
+       // Load "success" message
+       setAjaxReplyContent('{%message,ADMIN_NETWORK_QUERY_TYPE_OKAY=' . $networkData['network_title'] . '%}');
+
+       // All fine
+       setHttpStatus('200 OK');
+}
+
+// AJAX call-back function to return a JSON with all network type handler ids
+function doAjaxAdminNetworkListById () {
+       // This must be be done only by admins
+       if (!isAdmin()) {
+               // Only allowed for admins
+               reportBug(__FUNCTION__, __LINE__, 'Only allowed for admins.');
+       } elseif (!isPostRequestElementSet('network_id')) {
+               // Required POST field 'network_id' is not there
+               reportBug(__FUNCTION__, __LINE__, 'Required POST field &quot;network_id&quot; is missing.');
+       }
+
+       // Load all network type handlers by given network id and extract only network_type_id
+       $networkTypes = getArrayFromArrayIndex(getNetworkTypeDataFromId(postRequestElement('network_id')), 'network_type_id');
+
+       // Set generated array
+       setAjaxReplyContent(encodeJson($networkTypes));
+
+       // All fine
+       setHttpStatus('200 OK');
+}
+
 // [EOF]
 ?>