Fixes for wrong tewmplate names, new network added:
[mailer.git] / inc / libs / network_functions.php
index 818af211e33f6d9c84bf20ce0738c317956a659e..ae47871fa8b25d058b8dfc3603d721258facfe6f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 11/04/2009 *
- * ===============                              Last change: 11/04/2009 *
+ * Mailer v0.2.1-FINAL                                Start: 11/04/2009 *
+ * ===================                          Last change: 11/04/2009 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : network_functions.php                            *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Funktionen fuer ext-network                      *
  * -------------------------------------------------------------------- *
- * $Revision:: 1194                                                   $ *
- * $Date:: 2009-10-27 18:24:18 +0100 (Tue, 27 Oct 2009)               $ *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
- * $Author:: quix0r                                                   $ *
+ * $Author::                                                          $ *
  * Needs to be in all Files and every File needs "svn propset           *
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -41,26 +42,51 @@ if (!defined('__SECURITY')) {
        die();
 } // END - if
 
+// Private setter for current network id
+function setCurrentNetworkId ($id) {
+       $GLOBALS['current_network_id'] = bigintval($id);
+}
+
+// Private getter for current network id
+function getCurrentNetworkId () {
+       return $GLOBALS['current_network_id'];
+}
+
+// Handle a (maybe) sent form here
+function doNetworkHandleForm () {
+       // Was the form sent?
+       if ((isFormSent()) || (isFormSent('edit')) || (isFormSent('del')) || (isFormSent('change')) || (isFormSent('remove'))) {
+               // Do we have a 'do'?
+               if (isGetRequestParameterSet('do')) {
+                       // Process the request
+                       doAdminNetworkProcessForm();
+               } else {
+                       // No 'do' found
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}');
+               }
+       } // END - if
+}
+
 // Processes an admin form
 function doAdminNetworkProcessForm () {
        // Form really sent?
-       if ((!isFormSent()) && (!isPostRequestElementSet('edit')) && (!isPostRequestElementSet('del')) && (!isPostRequestElementSet('change')) && (!isPostRequestElementSet('remove'))) {
+       if ((!isFormSent()) && (!isFormSent('edit')) && (!isFormSent('del')) && (!isFormSent('change')) && (!isFormSent('remove'))) {
                // Abort here
-               loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_FORM_NOT_SENT'));
+               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_FORM_NOT_SENT--}');
                return;
-       } elseif (!isGetRequestElementSet('do')) {
+       } elseif (!isGetRequestParameterSet('do')) {
                // No 'do' found
-               loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_DO_404'));
+               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}');
                return;
        }
 
        // Create function name
-       $functionName = sprintf("doAdminNetworkProcess%sForm", ucfirst(strtolower(getRequestElement('do'))));
+       $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(getRequestParameter('do')));
 
        // Is the function valid?
        if (!function_exists($functionName)) {
                // Invalid function name
-               debug_report_bug('Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestParameter('do') . ', function ' . $functionName .' does not exist.', false);
        } // END - if
 
        // Call-back the method handling our request
@@ -83,38 +109,617 @@ function isNetworkNameValid ($name) {
        return $isValid;
 }
 
+// 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__);
+
+       // Does it exist?
+       $isValid = (SQL_NUMROWS($result) == 1);
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Return result
+       return $isValid;
+}
+
+// Checks wether the given network request parameter is already used (valid)
+function isNetworkRequestParameterValid ($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 `request_param_key`='%s' LIMIT 1",
+               array($networkId, $type, $key), __FUNCTION__, __LINE__);
+
+       // Does it exist?
+       $isValid = (SQL_NUMROWS($result) == 1);
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Return result
+       return $isValid;
+}
+
+// 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__);
+
+       // Does it exist?
+       $isValid = (SQL_NUMROWS($result) == 1);
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Return result
+       return $isValid;
+}
+
 // "Getter" for a network's data by provided id number
-function getNetworkDataById ($id) {
+function getNetworkDataById ($id, $column = '') {
        // Ids lower one are not accepted
        if ($id < 1) {
                // Not good, should be fixed
-               debug_report_bug('Network id ' . $id . ' is smaller than 1.');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.');
        } // END - if
 
-       // By default we have no data
-       $networkData = array();
+       // Set current network id
+       setCurrentNetworkId($id);
 
-       // Query for the network data
-       $result = SQL_QUERY_ESC("SELECT
+       // Is it cached?
+       if (!isset($GLOBALS['network_data'][$id])) {
+               // By default we have no data
+               $GLOBALS['network_data'][$id] = array();
+
+               // Query for the network data
+               $result = SQL_QUERY_ESC("SELECT
        `network_id`, `network_short_name`, `network_title`, `network_reflink`, `network_data_seperator`, `network_row_seperator`, `network_request_type`, `network_charset`
 FROM
        `{?_MYSQL_PREFIX?}_network_data`
 WHERE
        `network_id`=%s
+LIMIT 1",
+                       array(bigintval($id)), __FUNCTION__, __LINE__);
+
+               // Do we have an entry?
+               if (SQL_NUMROWS($result) == 1) {
+                       // Then get it
+                       $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result);
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result);
+       } // END - if
+
+       // Return result
+       if (empty($column)) {
+               // Return array
+               return $GLOBALS['network_data'][$id];
+       } else {
+               // Return column
+               return $GLOBALS['network_data'][$id][$column];
+       }
+}
+
+// "Getter" for a network's data by provided type id number
+function getNetworkDataByTypeId ($id, $column = '') {
+       // Ids lower one are not accepted
+       if ($id < 1) {
+               // Not good, should be fixed
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.');
+       } // END - if
+
+       // Set current network id
+       setCurrentNetworkId($id);
+
+       // Is it cached?
+       if (!isset($GLOBALS['network_data'][$id])) {
+               // By default we have no data
+               $GLOBALS['network_data'][$id] = 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_seperator`, d.`network_row_seperator`, d.`network_request_type`, d.`network_charset`,
+       t.`network_type_handle`, t.`network_type_api_url`, t.`network_type_click_url`, t.`network_type_banner_url`
+FROM
+       `{?_MYSQL_PREFIX?}_network_data` AS d
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_network_types` AS t
+ON
+       d.`network_id`=t.`network_id`
+WHERE
+       t.`network_type_id`=%s
+LIMIT 1",
+                       array(bigintval($id)), __FUNCTION__, __LINE__);
+
+               // Do we have an entry?
+               if (SQL_NUMROWS($result) == 1) {
+                       // Then get it
+                       $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result);
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result);
+       } // END - if
+
+       // Return result
+       if (empty($column)) {
+               // Return array
+               return $GLOBALS['network_data'][$id];
+       } else {
+               // Return column
+               return $GLOBALS['network_data'][$id][$column];
+       }
+}
+
+// "Getter" for a network type data by provided id number
+function getNetworkTypeDataById ($id) {
+       // Ids lower one are not accepted
+       if ($id < 1) {
+               // Not good, should be fixed
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.');
+       } // END - if
+
+       // By default we have no data
+       $GLOBALS['network_type_data'][$id] = array();
+
+       // Query for the network data
+       $result = SQL_QUERY_ESC("SELECT
+       `network_type_id`, `network_id`, `network_type_handle`, `network_type_api_url`, `network_type_click_url`, `network_type_banner_url`
+FROM
+       `{?_MYSQL_PREFIX?}_network_types`
+WHERE
+       `network_type_id`=%s
+LIMIT 1",
+               array(bigintval($id)), __FUNCTION__, __LINE__);
+
+       // Do we have an entry?
+       if (SQL_NUMROWS($result) == 1) {
+               // Then get it
+               $GLOBALS['network_type_data'][$id] = SQL_FETCHARRAY($result);
+       } // END - if
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Return result
+       return $GLOBALS['network_type_data'][$id];
+}
+
+// "Getter" for a network request parameter data by provided id number
+function getNetworkRequestParamsDataById ($id) {
+       // Ids lower one are not accepted
+       if ($id < 1) {
+               // Not good, should be fixed
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.');
+       } // END - if
+
+       // By default we have no data
+       $networkRequestData = array();
+
+       // Query for the network data
+       $result = SQL_QUERY_ESC("SELECT
+       `network_param_id`, `network_id`, `network_type_id`, `request_param_key`, `request_param_value`, `request_param_default`
+FROM
+       `{?_MYSQL_PREFIX?}_network_request_params`
+WHERE
+       `network_param_id`=%s
 LIMIT 1",
                array(bigintval($id)), __FUNCTION__, __LINE__);
 
        // Do we have an entry?
        if (SQL_NUMROWS($result) == 1) {
                // Then get it
-               $networkData = SQL_FETCHARRAY($result);
+               $networkRequestData = SQL_FETCHARRAY($result);
        } // END - if
 
        // Free result
        SQL_FREERESULT($result);
 
        // Return result
-       return $networkData;
+       return $networkRequestData;
+}
+
+// Updates given network (id) with data from array
+function doNetworkUpdateDataByArray ($id, $networkData) {
+       // Ids lower one are not accepted
+       if ($id < 1) {
+               // Not good, should be fixed
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.');
+       } // END - if
+
+       // Just call our inner method
+       return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($id)), array(), false, false);
+}
+
+// Updates given network type handler (id) with data from array
+function doNetworkUpdateTypeByArray ($id, $networkTypeData) {
+       // Ids lower one are not accepted
+       if ($id < 1) {
+               // Not good, should be fixed
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $id . ' is smaller than 1.');
+       } // END - if
+
+       // Just call our inner method
+       return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($id)), array(), false, false);
+}
+
+// Updates given network request parameters (id) with data from array
+function doNetworkUpdateParamsByArray ($id, $networkParamData) {
+       // Ids lower one are not accepted
+       if ($id < 1) {
+               // Not good, should be fixed
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.');
+       } // END - if
+
+       // Just call our inner method
+       return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_param_id`=%s", bigintval($id)), array(), false, false);
+}
+
+// Removes given network entry
+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, $id, $limit), __FUNCTION__, __LINE__);
+
+       // Return affected rows
+       return SQL_AFFECTEDROWS();
+}
+
+// Generates a list of networks for given script and returns it
+function generateAdminNetworkList () {
+       // Init output
+       $content = '';
+
+       // Query for all networks
+       $result = SQL_QUERY('SELECT
+       `network_id`, `network_short_name`, `network_title`
+FROM
+       `{?_MYSQL_PREFIX?}_network_data`
+ORDER BY
+       `network_short_name` ASC', __FUNCTION__, __LINE__);
+
+       // Do we have 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']))) {
+                               // Add entry
+                               $rows[$row['network_id']] = $row;
+                       } // END - if
+               } // END - while
+
+               // Generate the selection box
+               $content = generateSelectionBoxFromArray($rows, 'network', 'network_id');
+       } else {
+               // Nothing selected
+               $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
+       }
+
+       // Free the result
+       SQL_FREERESULT($result);
+
+       // Return the list
+       return $content;
+}
+
+// Generator (somewhat getter) for a list of network types for given network id
+function generateAdminNetworkTypeList ($networkId) {
+       // Init content
+       $content = '';
+
+       // Query all types of this network
+       $result = SQL_QUERY_ESC("SELECT
+       `network_type_id`, `network_type_handle`
+FROM
+       `{?_MYSQL_PREFIX?}_network_types`
+WHERE
+       `network_id`=%s
+ORDER BY
+       `network_type_handle` ASC",
+               array(
+                       bigintval($networkId)
+               ), __FUNCTION__, __LINE__);
+
+       // Do we have 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_type_id']))) {
+                               // Add entry
+                               $rows[$row['network_type_id']] = $row;
+                       } // END - if
+               } // END - while
+
+               // Generate the selection box
+               $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
+       } else {
+               // Nothing selected
+               $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
+       }
+
+       // Free the result
+       SQL_FREERESULT($result);
+
+       // Return content
+       return $content;
+}
+
+// Generator (somewhat getter) for a list of network types for all types
+function generateAdminDistinctNetworkTypeList () {
+       // Init content
+       $content = '';
+
+       // Query all types of this network
+       $result = SQL_QUERY('SELECT
+       t.`network_type_id`, t.`network_type_handle`, d.`network_title`
+FROM
+       `{?_MYSQL_PREFIX?}_network_types` AS t
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_network_data` AS d
+ON
+       t.`network_id`=d.`network_id`
+ORDER BY
+       d.`network_short_name` ASC,
+       t.`network_type_handle` ASC', __FUNCTION__, __LINE__);
+
+       // Do we have 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_type_id']))) {
+                               // Add entry
+                               $rows[$row['network_type_id']] = $row;
+                       } // END - if
+               } // END - while
+
+               // Generate the selection box
+               $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
+       } else {
+               // Nothing selected
+               $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
+       }
+
+       // Free the result
+       SQL_FREERESULT($result);
+       //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
+
+       // Return content
+       return $content;
+}
+
+// Generator (somewhat getter) for network type options
+function generateNetworkTypeOptions ($id) {
+       // Is this an array, then we just came back from edit/delete actions
+       if (is_array($id)) $id = '';
+
+       // Is this cached?
+       if (!isset($GLOBALS[__FUNCTION__][$id])) {
+               // Generate output and cache it
+               $GLOBALS[__FUNCTION__][$id] = generateOptionList(
+                       'network_types',
+                       'network_type_id',
+                       'network_type_handle',
+                       $id,
+                       '',
+                       sprintf(
+                               "WHERE `network_id`=%s",
+                               bigintval(getRequestParameter('network'))
+                       ),
+                       '',
+                       'translateNetworkTypeHandler'
+               );
+       } // END - if
+
+       // Return content
+       return $GLOBALS[__FUNCTION__][$id];
+}
+
+// Generates an options list of all available (hard-coded) handlers
+function generateNetworkTypesAvailableOptions () {
+       // Is it cached?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Generate list
+               $GLOBALS[__FUNCTION__] = generateOptionList(
+                       '/ARRAY/',
+                       array(
+                               'banner',
+                               'banner_click',
+                               'banner_view',
+                               'button',
+                               'button_click',
+                               'button_view',
+                               'surfbar',
+                               'surfbar_click',
+                               'surfbar_view',
+                               'forcedbanner',
+                               'forcedtextlink',
+                               'textlink',
+                               'textlink_click',
+                               'textlink_view',
+                               'skybanner',
+                               'skybanner_click',
+                               'skybanner_view',
+                               'layer',
+                               'layer_click',
+                               'layer_view',
+                               'popup',
+                               'popdown',
+                               'textmail',
+                               'htmlmail',
+                               'lead',
+                               'sale',
+                               'payperactive',
+                               'pagepeel',
+                               'traffic'
+                       ),
+                       array(),
+                       '',
+                       '', '',
+                       $GLOBALS['network_types_disabled'],
+                       'translateNetworkTypeHandler'
+               );
+       } // END - if
+
+       // Return content
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Generates an options list (somewhat getter) ofr request keys
+function generateNetworkRequestKeyOptions () {
+       // Is it cached?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Generate and cache it
+               $GLOBALS[__FUNCTION__] = generateOptionList(
+                       '/ARRAY/',
+                       array(
+                               'id',
+                               'sid',
+                               'hash',
+                               'password',
+                               'reload',
+                               'maximum_stay',
+                               'minimum_stay',
+                               'currency',
+                               'type',
+                               'remain',
+                               'reward',
+                               'size',
+                               'erotic',
+                               'extra',
+                               'country'
+                       ),
+                       array(),
+                       '',
+                       '', '',
+                       $GLOBALS['network_params_disabled'],
+                       'translateNetworkRequestParameter'
+               );
+       } // END - if
+
+       // Return content
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Generator (somewhat getter) for (return) array translation
+function generateNetworkTranslationOptions ($default = '') {
+       // Is it cached?
+       if (!isset($GLOBALS[__FUNCTION__][$default])) {
+               // Generate and cache it
+               $GLOBALS[__FUNCTION__][$default] = generateOptionList(
+                       'network_translations',
+                       'network_translation_id',
+                       'network_translation_name',
+                       $default,
+                       '',
+                       '',
+                       $GLOBALS['network_translation_disabled'],
+                       'translateNetworkTranslationName'
+               );
+       } // END - if
+
+       // Return content
+       return $GLOBALS[__FUNCTION__][$default];
+}
+
+// Generates an option list of request types
+function generateNetworkRequestTypeOptions ($default = '') {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__][$default])) {
+               // Generate the list
+               $GLOBALS[__FUNCTION__][$default] = generateOptionList(
+                       '/ARRAY/',
+                       array(
+                               'GET',
+                               'POST'
+                       ),
+                       array(
+                               '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
+                               '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
+                       ),
+                       $default
+               );
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$default];
+}
+
+// Translates 'translate_name' for e.g. templates
+function translateNetworkTranslationName ($name) {
+       // Get the message id
+       return getMessage('ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME');
+}
+
+// Translates the network type handler (e.g. banner, paidmail) for templates
+function translateNetworkTypeHandler ($type) {
+       // Get the message id
+       return getMessage('ADMIN_NETWORK_TYPES_' . strtoupper($type) . '');
+}
+
+// Translates request type
+function translateNetworkRequestType ($type) {
+       // Get the message id
+       return getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '');
+}
+
+// Translates request parameter
+function translateNetworkRequestParameter ($param) {
+       // Get the message id
+       return getMessage('ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '');
+}
+
+// Translates API index
+function translateNetworkApiIndex ($index) {
+       // Do we have cache?
+       if (!isset($GLOBALS['network_api_index'])) {
+               // Get an array of all API array indexes
+               $GLOBALS['network_api_index'] = array();
+
+               // Get all entries
+               $result = SQL_QUERY('SELECT
+       `network_api_id`, `network_api_index`, `network_translation_name`
+FROM
+       `{?_MYSQL_PREFIX?}_network_api_translation`
+INNER JOIN
+       `{?_MYSQL_PREFIX?}_network_translations`
+ON
+       `network_api_index`=`network_translation_id`
+ORDER BY
+       `sort` ASC', __FUNCTION__, __LINE__);
+
+               // Do we have entries?
+               if (SQL_NUMROWS($result) > 0) {
+                       // Get all entries
+                       while ($row = SQL_FETCHARRAY($result)) {
+                               // Add it to our global array
+                               $GLOBALS['network_api_index'][$row['network_api_index']] = $row;
+                       } // END - while
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result);
+       } // END - if
+
+       // Default name is unknown
+       $name = 'unknown';
+
+       // Is the entry there?
+       if (isset($GLOBALS['network_api_index'][$index])) {
+               // Then get the name
+               $name = $GLOBALS['network_api_index'][$index]['network_translation_name'];
+       } // END - if
+
+       // Return translation
+       return translateNetworkTranslationName($name);
 }
 
 //------------------------------------------------------------------------------
@@ -122,28 +727,28 @@ LIMIT 1",
 //------------------------------------------------------------------------------
 
 // Callback function to add new network
-function doAdminNetworkProcessAddnetworkForm () {
+function doAdminNetworkProcessAddNetwork () {
        // We can say here, the form is sent, so check if the network is already added
-       if (isNetworkNameValid(postRequestElement('network_short_name'))) {
+       if (isNetworkNameValid(postRequestParameter('network_short_name'))) {
                // Already there
-               loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_ALREADY_ADDED'), postRequestElement('network_short_name')));
-               return;
+               loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_ALREADY_ADDED', postRequestParameter('network_short_name')));
+               return false;
        } // END - if
 
        // Remove the 'ok' part
-       unsetPostRequestElement('ok');
+       unsetPostRequestParameter('ok');
 
        // Add the whole request to database
-       SQL_QUERY("INSERT INTO
+       SQL_QUERY('INSERT INTO
        `{?_MYSQL_PREFIX?}_network_data`
 (
-       `" . implode('`,`', array_keys(postRequestArray())) . "`
+       `' . implode('`,`', array_keys(postRequestArray())) . "`
 ) VALUES (
        '" . implode("','", array_values(postRequestArray())) . "'
 )", __FUNCTION__, __LINE__);
 
        // Add the id for output only
-       setRequestPostElement('network_id', SQL_INSERTID());
+       setPostRequestParameter('network_id', SQL_INSERTID());
 
        // Output message
        if (SQL_AFFECTEDROWS() == 1) {
@@ -151,17 +756,17 @@ function doAdminNetworkProcessAddnetworkForm () {
                loadTemplate('admin_network_added', false, postRequestArray());
        } else {
                // Not added
-               loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_DATA_NOT_ADDED'), postRequestElement('network_short_name')));
+               loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_DATA_NOT_ADDED', postRequestParameter('network_short_name')));
        }
 }
 
 // Displays selected networks for editing
-function doAdminNetworkProcessHandlenetworkForm () {
+function doAdminNetworkProcessHandleNetwork () {
        // Do we have selections?
-       if (countPostSelection() > 0) {
+       if (ifPostContainsSelections()) {
                // Something has been selected, so start displaying one by one
-               $SW = 2; $OUT = '';
-               foreach (postRequestElement('sel') as $id=>$sel) {
+               $OUT = '';
+               foreach (postRequestParameter('sel') as $id => $sel) {
                        // Is this selected?
                        if ($sel == 1) {
                                // Load this network's data
@@ -169,20 +774,16 @@ function doAdminNetworkProcessHandlenetworkForm () {
 
                                // Do we have found the network?
                                if (count($networkData) > 0) {
-                                       // Add color
-                                       $networkData['sw'] = $SW;
-
-                                       // Make selection box for network_request_type
-                                       $networkData['network_request_type'] = generateOptionList(
-                                               '/ARRAY/',
-                                               array('GET','POST'),
-                                               array(getMessage('ADMIN_NETWORK_REQUEST_TYPE_GET'), getMessage('ADMIN_NETWORK_REQUEST_TYPE_POST')),
-                                               $networkData['network_request_type']
-                                       );
-
-                                       // Add row template and switch color
-                                       $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
-                                       $SW = 3 - $SW;
+                                       if (isFormSent('edit')) {
+                                               // Add row template for editing
+                                               $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
+                                       } elseif (isFormSent('del')) {
+                                               // Add row template for deleting
+                                               $OUT .= loadTemplate('admin_del_networks_row', true, $networkData);
+                                       } else {
+                                               // Problem!
+                                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                                       }
                                } // END - if
                        } // END - if
                } // END - foreach
@@ -190,16 +791,511 @@ function doAdminNetworkProcessHandlenetworkForm () {
                // If we have no rows, we don't need to display the edit form
                if (!empty($OUT)) {
                        // Output main template
-                       loadTemplate('admin_edit_networks', false, $OUT);
+                       if (isFormSent('edit')) {
+                               loadTemplate('admin_edit_networks', false, $OUT);
+                       } elseif (isFormSent('del')) {
+                               loadTemplate('admin_del_networks', false, $OUT);
+                       } else {
+                               // Problem!
+                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                       }
 
                        // Don't display the list/add new form
                        $GLOBALS['network_display'] = false;
                } else {
                        // Nothing selected/found
-                       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_NOTHING_FOUND'));
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
                }
        } // END - if
 }
 
+// Handle network type form
+function doAdminNetworkProcessHandleNetworkType () {
+       // Do we have selections?
+       if (ifPostContainsSelections()) {
+               // Load network data
+               $networkData = getNetworkDataById(getRequestParameter('network'));
+
+               // Something has been selected, so start displaying one by one
+               $OUT = '';
+               foreach (postRequestParameter('sel') as $id => $sel) {
+                       // Is this selected?
+                       if ($sel == 1) {
+                               // Load this network's data
+                               $networkTypeData = getNetworkTypeDataById($id);
+
+                               // Do we have found the network?
+                               if (count($networkTypeData) > 0) {
+                                       if (isFormSent('edit')) {
+                                               // Add row template for deleting
+                                               $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
+                                       } elseif (isFormSent('del')) {
+                                               // Add row template for deleting
+                                               $OUT .= loadTemplate('admin_del_network_types_row', true, $networkTypeData);
+                                       } else {
+                                               // Problem!
+                                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                                       }
+                               } // END - if
+                       } // END - if
+               } // END - foreach
+
+               // If we have no rows, we don't need to display the edit form
+               if (!empty($OUT)) {
+                       // Output main template
+                       if (isFormSent('edit')) {
+                               loadTemplate('admin_edit_network_types', false, $OUT);
+                       } elseif (isFormSent('del')) {
+                               loadTemplate('admin_del_network_types', false, $OUT);
+                       } else {
+                               // Problem!
+                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                       }
+
+                       // Don't display the list/add new form
+                       $GLOBALS['network_display'] = false;
+               } else {
+                       // Nothing selected/found
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_FOUND--}');
+               }
+       } // END - if
+}
+
+// Handle network request parameter form
+function doAdminNetworkProcessHandleRequestParams () {
+       // Do we have selections?
+       if (ifPostContainsSelections()) {
+               // Init cache array
+               $GLOBALS['network_params_disabled'] = array();
+
+               // Load network data
+               $networkData = getNetworkDataById(getRequestParameter('network'));
+
+               // Something has been selected, so start displaying one by one
+               $OUT = '';
+               foreach (postRequestParameter('sel') as $id => $sel) {
+                       // Is this selected?
+                       if ($sel == 1) {
+                               // Load this network's data
+                               $networkRequestData = getNetworkRequestParamsDataById($id);
+
+                               // Do we have found the network?
+                               if (count($networkRequestData) > 0) {
+                                       if (isFormSent('edit')) {
+                                               // Add row template for deleting
+                                               $OUT .= loadTemplate('admin_edit_network_params_row', true, $networkRequestData);
+                                       } elseif (isFormSent('del')) {
+                                               // Get type data
+                                               $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
+
+                                               // Add row template for deleting
+                                               $OUT .= loadTemplate('admin_del_network_params_row', true, $networkRequestData);
+                                       } else {
+                                               // Problem!
+                                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                                       }
+                               } // END - if
+                       } // END - if
+               } // END - foreach
+
+               // If we have no rows, we don't need to display the edit form
+               if (!empty($OUT)) {
+                       // Output main template
+                       if (isFormSent('edit')) {
+                               loadTemplate('admin_edit_network_params', false, $OUT);
+                       } elseif (isFormSent('del')) {
+                               loadTemplate('admin_del_network_params', false, $OUT);
+                       } else {
+                               // Problem!
+                               debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
+                       }
+
+                       // Don't display the list/add new form
+                       $GLOBALS['network_display'] = false;
+               } else {
+                       // Nothing selected/found
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
+               }
+       } // END - if
+}
+
+// Changes given networks
+function doAdminNetworkProcessChangeNetwork () {
+       // Do we have selections?
+       if (ifPostContainsSelections()) {
+               // By default nothing is updated
+               $updated = 0;
+
+               // Something has been selected, so start updating them
+               foreach (postRequestParameter('sel') as $id => $sel) {
+                       // Update this entry?
+                       if ($sel == 1) {
+                               // Init data array
+                               $networkData = array();
+
+                               // Transfer whole array, except 'sel'
+                               foreach (postRequestArray() as $key => $entry) {
+                                       // Skip 'sel' and submit button
+                                       if (in_array($key, array('sel', 'change'))) continue;
+
+                                       // Do we have this enty?
+                                       if (!isset($entry[$id])) {
+                                               // Not found, needs fixing
+                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
+                                       } // END - if
+
+                                       // Add this entry
+                                       $networkData[$key] = $entry[$id];
+                               } // END - foreach
+
+                               // Update the network data
+                               $updated += doNetworkUpdateDataByArray($id, $networkData);
+                       } // END - if
+               } // END - foreach
+
+               // Do we have updates?
+               if ($updated > 0) {
+                       // Updates done
+                       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_UPDATED', $updated));
+               } else {
+                       // Nothing changed
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
+               }
+       } // END - if
+}
+
+// Removes given networks
+function doAdminNetworkProcessRemoveNetwork () {
+       // Do we have selections?
+       if (ifPostContainsSelections()) {
+               // By default nothing is removed
+               $removed = 0;
+
+               // Something has been selected, so start updating them
+               foreach (postRequestParameter('sel') as $id => $sel) {
+                       // Update this entry?
+                       if ($sel == 1) {
+                               // Remove this entry
+                               $removed += doAdminRemoveNetworkEntry('data', 'network_id', $id);
+                       } // END - if
+               } // END - foreach
+
+               // Do we have removes?
+               if ($removed > 0) {
+                       // Removals done
+                       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REMOVED', $removed));
+               } else {
+                       // Nothing removed
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
+               }
+       } // END - if
+}
+
+// Add a network type handler if not yet found
+function doAdminNetworkProcessAddNetworkType () {
+       // Is the network type handle already used with given network?
+       if (isNetworkTypeHandleValid(postRequestParameter('network_type_handle'), getRequestParameter('network'))) {
+               // Already added
+               loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED', postRequestParameter('network_type_handle')));
+
+               // ... so abort here
+               return false;
+       } // END - if
+
+       // Remove the 'ok' part
+       unsetPostRequestParameter('ok');
+
+       // Add id
+       setPostRequestParameter('network_id', bigintval(getRequestParameter('network')));
+
+       // Is network_type_banner_url set?
+       if (postRequestParameter('network_type_banner_url') == '') {
+               // Remove empty value to get a NULL for an optional entry
+               unsetPostRequestParameter('network_type_banner_url');
+       } // END - if
+
+       // Add the whole request to database
+       SQL_QUERY('INSERT INTO
+       `{?_MYSQL_PREFIX?}_network_types`
+(
+       `' . implode('`,`', array_keys(postRequestArray())) . "`
+) VALUES (
+       '" . implode("','", array_values(postRequestArray())) . "'
+)", __FUNCTION__, __LINE__);
+
+       // Output message
+       if (SQL_AFFECTEDROWS() == 1) {
+               // Successfully added
+               loadTemplate('admin_network_type_added', false, postRequestArray());
+       } else {
+               // Not added
+               loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_NOT_ADDED', postRequestParameter('network_type_handle')));
+       }
+}
+
+// Changes given network type handlers
+function doAdminNetworkProcessChangeNetworkType () {
+       // Do we have selections?
+       if (ifPostContainsSelections()) {
+               // By default nothing is updated
+               $updated = 0;
+
+               // Something has been selected, so start updating them
+               foreach (postRequestParameter('sel') as $id => $sel) {
+                       // Update this entry?
+                       if ($sel == 1) {
+                               // Init data array
+                               $networkTypeData = array();
+
+                               // Transfer whole array, except 'sel'
+                               foreach (postRequestArray() as $key => $entry) {
+                                       // Skip 'sel' and submit button
+                                       if (in_array($key, array('sel', 'change'))) continue;
+
+                                       // Do we have this enty?
+                                       if (!isset($entry[$id])) {
+                                               // Not found, needs fixing
+                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
+                                       } // END - if
+
+                                       // Fix empty network_type_banner_url to NULL
+                                       if (($key == 'network_type_banner_url') && (trim($entry[$id]) == '')) {
+                                               // Set it to NULL
+                                               $entry[$id] = null;
+                                       } // END - if
+
+                                       // Add this entry
+                                       $networkTypeData[$key] = $entry[$id];
+                               } // END - foreach
+
+                               // Update the network data
+                               $updated += doNetworkUpdateTypeByArray($id, $networkTypeData);
+                       } // END - if
+               } // END - foreach
+
+               // Do we have updates?
+               if ($updated > 0) {
+                       // Updates done
+                       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_UPDATED', $updated));
+               } else {
+                       // Nothing changed
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_CHANGED--}');
+               }
+       } // END - if
+}
+
+// Changes given network request parameters
+function doAdminNetworkProcessChangeNetworkParam () {
+       // Do we have selections?
+       if (ifPostContainsSelections()) {
+               // By default nothing is updated
+               $updated = 0;
+
+               // Something has been selected, so start updating them
+               foreach (postRequestParameter('sel') as $id => $sel) {
+                       // Update this entry?
+                       if ($sel == 1) {
+                               // Init data array
+                               $networkParamsData = array();
+
+                               // Transfer whole array, except 'sel'
+                               foreach (postRequestArray() as $key => $entry) {
+                                       // Skip 'sel' and submit button
+                                       if (in_array($key, array('sel', 'change'))) continue;
+
+                                       // Do we have this enty?
+                                       if (!isset($entry[$id])) {
+                                               // Not found, needs fixing
+                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
+                                       } // END - if
+
+                                       // Fix empty request_param_default to NULL
+                                       if (($key == 'request_param_default') && (trim($entry[$id]) == '')) {
+                                               // Set it to NULL
+                                               $entry[$id] = null;
+                                       } // END - if
+
+                                       // Add this entry
+                                       $networkParamsData[$key] = $entry[$id];
+                               } // END - foreach
+
+                               // Update the network data
+                               $updated += doNetworkUpdateParamsByArray($id, $networkParamsData);
+                       } // END - if
+               } // END - foreach
+
+               // Do we have updates?
+               if ($updated > 0) {
+                       // Updates done
+                       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED', $updated));
+               } else {
+                       // Nothing changed
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
+               }
+       } // END - if
+}
+
+// Removes given network type handlers
+function doAdminNetworkProcessRemoveNetworkType () {
+       // Do we have selections?
+       if (ifPostContainsSelections()) {
+               // By default nothing is removed
+               $removed = 0;
+
+               // Something has been selected, so start updating them
+               foreach (postRequestParameter('sel') as $id => $sel) {
+                       // Update this entry?
+                       if ($sel == 1) {
+                               // Remove this entry
+                               $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $id);
+                       } // END - if
+               } // END - foreach
+
+               // Do we have removes?
+               if ($removed > 0) {
+                       // Removals done
+                       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_REMOVED', $removed));
+               } else {
+                       // Nothing removed
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_REMOVED--}');
+               }
+       } // END - if
+}
+
+// Removes given network request parameters
+function doAdminNetworkProcessRemoveNetworkParam () {
+       // Do we have selections?
+       if (ifPostContainsSelections()) {
+               // By default nothing is removed
+               $removed = 0;
+
+               // Something has been selected, so start updating them
+               foreach (postRequestParameter('sel') as $id => $sel) {
+                       // Update this entry?
+                       if ($sel == 1) {
+                               // Remove this entry
+                               $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $id);
+                       } // END - if
+               } // END - foreach
+
+               // Do we have removes?
+               if ($removed > 0) {
+                       // Removals done
+                       loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED', $removed));
+               } else {
+                       // Nothing removed
+                       loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
+               }
+       } // END - if
+}
+
+// Adds a request parameter to given network and type
+function doAdminNetworkProcessAddNetworkParam () {
+       // Is the request parameter already used with given network?
+       if (isNetworkRequestParameterValid(postRequestParameter('request_param_key'), postRequestParameter('network_type_id'), getRequestParameter('network'))) {
+               // Already added
+               loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED', postRequestParameter('request_param_key')));
+
+               // ... so abort here
+               return false;
+       } // END - if
+
+       // Remove the 'ok' part
+       unsetPostRequestParameter('ok');
+
+       // Add id
+       setPostRequestParameter('network_id', bigintval(getRequestParameter('network')));
+
+       // Is request_param_default set?
+       if (postRequestParameter('request_param_default') == '') {
+               // Remove empty value to get a NULL for an optional entry
+               unsetPostRequestParameter('request_param_default');
+       } // END - if
+
+       // Add the whole request to database
+       SQL_QUERY('INSERT INTO
+       `{?_MYSQL_PREFIX?}_network_request_params`
+(
+       `' . implode('`,`', array_keys(postRequestArray())) . "`
+) VALUES (
+       '" . implode("','", array_values(postRequestArray())) . "'
+)", __FUNCTION__, __LINE__);
+
+       // Output message
+       if (SQL_AFFECTEDROWS() == 1) {
+               // Successfully added
+               loadTemplate('admin_network_request_param_added', false, postRequestArray());
+       } else {
+               // Not added
+               loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED', postRequestParameter('request_param_key')));
+       }
+}
+
+// Adds a API response array entry
+function doAdminNetworkProcessAddNetworkApiTranslation () {
+       // Is the request parameter already used with given network?
+       if (isNetworkApiTranslationValid(postRequestParameter('network_api_index'), postRequestParameter('network_type_id'), getRequestParameter('network'))) {
+               // Already added
+               loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_API_TRANSLATION_ALREADY_ADDED', postRequestParameter('network_api_index')));
+
+               // ... so abort here
+               return false;
+       } // END - if
+
+       // Remove the 'ok' part
+       unsetPostRequestParameter('ok');
+
+       // Add id
+       setPostRequestParameter('network_id', bigintval(getRequestParameter('network')));
+
+       // Add sorting
+       setPostRequestParameter('sort', (countSumTotalData(
+               postRequestParameter('network_id'),
+               'network_api_translation',
+               'network_api_id',
+               'network_id',
+               true,
+               sprintf(" AND `network_type_id`=%s", bigintval(postRequestParameter('network_type_id')))
+       ) + 1));
+
+       // Add the whole request to database
+       SQL_QUERY('INSERT INTO
+       `{?_MYSQL_PREFIX?}_network_api_translation`
+(
+       `' . implode('`,`', array_keys(postRequestArray())) . "`
+) VALUES (
+       '" . implode("','", array_values(postRequestArray())) . "'
+)", __FUNCTION__, __LINE__);
+
+       // Output message
+       if (SQL_AFFECTEDROWS() == 1) {
+               // Successfully added
+               loadTemplate('admin_network_api_translation_added', false, postRequestArray());
+       } else {
+               // Not added
+               loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_API_TRANSLATION_NOT_ADDED', postRequestParameter('network_api_index')));
+       }
+}
+
+// Do expression code for this extension
+function doExpressionNetwork ($data) {
+       // Construct replacer
+       $replacer = sprintf(
+               "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
+               $data['callback'],
+               $data['matches'][4][$data['key']],
+               $data['extra_func']
+       );
+
+       // Replace %network% with the current network id
+       $replacer = str_replace('%network%', getCurrentNetworkId(), $replacer);
+
+       // Replace the code
+       $code = replaceExpressionCode($data, $replacer);
+
+       // Return it
+       return $code;
+}
+
 // [EOF]
 ?>