]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/network_functions.php
Extension ext-network continued:
[mailer.git] / inc / libs / network_functions.php
index 46df1e13f1bcc4e48fd473b6f9064d5db007e1f2..0c71a5269b071282c9a52cb1054abee17311d5cf 100644 (file)
@@ -41,8 +41,8 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Private setter for current network id
-function setCurrentNetworkId ($id) {
-       $GLOBALS['current_network_id'] = bigintval($id);
+function setCurrentNetworkId ($networkId) {
+       $GLOBALS['current_network_id'] = bigintval($networkId);
 }
 
 // Private getter for current network id
@@ -126,7 +126,7 @@ function isNetworkTypeHandleValid ($type, $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 `request_param_key`='%s' LIMIT 1",
+       $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__);
 
        // Does it exist?
@@ -156,35 +156,44 @@ function isNetworkApiTranslationValid ($key, $type, $networkId) {
 }
 
 // "Getter" for a network's data by provided id number
-function getNetworkDataById ($id, $column = '') {
+function getNetworkDataById ($networkId, $column = '') {
        // Ids lower one are not accepted
-       if ($id < 1) {
+       if ($networkId < 1) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
        } // END - if
 
        // Set current network id
-       setCurrentNetworkId($id);
+       setCurrentNetworkId($networkId);
 
        // Is it cached?
-       if (!isset($GLOBALS['network_data'][$id])) {
+       if (!isset($GLOBALS['network_data'][$networkId])) {
                // By default we have no data
-               $GLOBALS['network_data'][$id] = array();
+               $GLOBALS['network_data'][$networkId] = 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`
+       `network_id`,
+       `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`
 FROM
        `{?_MYSQL_PREFIX?}_network_data`
 WHERE
        `network_id`=%s
 LIMIT 1",
-                       array(bigintval($id)), __FUNCTION__, __LINE__);
+                       array(bigintval($networkId)), __FUNCTION__, __LINE__);
 
                // Do we have an entry?
                if (SQL_NUMROWS($result) == 1) {
                        // Then get it
-                       $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result);
+                       $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
                } // END - if
 
                // Free result
@@ -194,33 +203,45 @@ LIMIT 1",
        // Return result
        if (empty($column)) {
                // Return array
-               return $GLOBALS['network_data'][$id];
+               return $GLOBALS['network_data'][$networkId];
        } else {
                // Return column
-               return $GLOBALS['network_data'][$id][$column];
+               return $GLOBALS['network_data'][$networkId][$column];
        }
 }
 
 // "Getter" for a network's data by provided type id number
-function getNetworkDataByTypeId ($id, $column = '') {
+function getNetworkDataByTypeId ($networkId, $column = '') {
        // Ids lower one are not accepted
-       if ($id < 1) {
+       if ($networkId < 1) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
        } // END - if
 
        // Set current network id
-       setCurrentNetworkId($id);
+       setCurrentNetworkId($networkId);
 
        // Is it cached?
-       if (!isset($GLOBALS['network_data'][$id])) {
+       if (!isset($GLOBALS['network_data'][$networkId])) {
                // By default we have no data
-               $GLOBALS['network_data'][$id] = array();
+               $GLOBALS['network_data'][$networkId] = 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`
+       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`
 FROM
        `{?_MYSQL_PREFIX?}_network_data` AS d
 LEFT JOIN
@@ -230,12 +251,12 @@ ON
 WHERE
        t.`network_type_id`=%s
 LIMIT 1",
-                       array(bigintval($id)), __FUNCTION__, __LINE__);
+                       array(bigintval($networkId)), __FUNCTION__, __LINE__);
 
                // Do we have an entry?
                if (SQL_NUMROWS($result) == 1) {
                        // Then get it
-                       $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result);
+                       $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
                } // END - if
 
                // Free result
@@ -245,53 +266,58 @@ LIMIT 1",
        // Return result
        if (empty($column)) {
                // Return array
-               return $GLOBALS['network_data'][$id];
+               return $GLOBALS['network_data'][$networkId];
        } else {
                // Return column
-               return $GLOBALS['network_data'][$id][$column];
+               return $GLOBALS['network_data'][$networkId][$column];
        }
 }
 
 // "Getter" for a network type data by provided id number
-function getNetworkTypeDataById ($id) {
+function getNetworkTypeDataById ($networkId) {
        // Ids lower one are not accepted
-       if ($id < 1) {
+       if ($networkId < 1) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
        } // END - if
 
        // By default we have no data
-       $GLOBALS['network_type_data'][$id] = array();
+       $GLOBALS['network_type_data'][$networkId] = 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`
+       `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__);
+               array(bigintval($networkId)), __FUNCTION__, __LINE__);
 
        // Do we have an entry?
        if (SQL_NUMROWS($result) == 1) {
                // Then get it
-               $GLOBALS['network_type_data'][$id] = SQL_FETCHARRAY($result);
+               $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
        } // END - if
 
        // Free result
        SQL_FREERESULT($result);
 
        // Return result
-       return $GLOBALS['network_type_data'][$id];
+       return $GLOBALS['network_type_data'][$networkId];
 }
 
 // "Getter" for a network request parameter data by provided id number
-function getNetworkRequestParamsDataById ($id) {
+function getNetworkRequestParamsDataById ($networkId) {
        // Ids lower one are not accepted
-       if ($id < 1) {
+       if ($networkId < 1) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
        } // END - if
 
        // By default we have no data
@@ -299,13 +325,18 @@ function getNetworkRequestParamsDataById ($id) {
 
        // 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`
+       `network_param_id`,
+       `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_param_id`=%s
 LIMIT 1",
-               array(bigintval($id)), __FUNCTION__, __LINE__);
+               array(bigintval($networkId)), __FUNCTION__, __LINE__);
 
        // Do we have an entry?
        if (SQL_NUMROWS($result) == 1) {
@@ -321,46 +352,46 @@ LIMIT 1",
 }
 
 // Updates given network (id) with data from array
-function doNetworkUpdateDataByArray ($id, $networkData) {
+function doNetworkUpdateDataByArray ($networkId, $networkData) {
        // Ids lower one are not accepted
-       if ($id < 1) {
+       if ($networkId < 1) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.');
+               debug_report_bug(__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($id)), array(), false, false);
+       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 ($id, $networkTypeData) {
+function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
        // Ids lower one are not accepted
-       if ($id < 1) {
+       if ($networkId < 1) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $id . ' is smaller than 1.');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' 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);
+       return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
 }
 
 // Updates given network request parameters (id) with data from array
-function doNetworkUpdateParamsByArray ($id, $networkParamData) {
+function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
        // Ids lower one are not accepted
-       if ($id < 1) {
+       if ($networkId < 1) {
                // Not good, should be fixed
-               debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' 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);
+       return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_param_id`=%s", bigintval($networkId)), array(), false, false);
 }
 
 // Removes given network entry
-function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
+function doAdminRemoveNetworkEntry ($table, $column, $networkId, $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__);
+               array($table, $column, $networkId, $limit), __FUNCTION__, __LINE__);
 
        // Return affected rows
        return SQL_AFFECTEDROWS();
@@ -373,7 +404,9 @@ function generateAdminNetworkList () {
 
        // Query for all networks
        $result = SQL_QUERY('SELECT
-       `network_id`,`network_short_name`,`network_title`
+       `network_id`,
+       `network_short_name`,
+       `network_title`
 FROM
        `{?_MYSQL_PREFIX?}_network_data`
 ORDER BY
@@ -392,7 +425,7 @@ ORDER BY
                } // END - while
 
                // Generate the selection box
-               $content = generateSelectionBoxFromArray($rows, 'network', 'network_id');
+               $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
        } else {
                // Nothing selected
                $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
@@ -495,24 +528,24 @@ ORDER BY
 }
 
 // Generator (somewhat getter) for network type options
-function generateNetworkTypeOptions ($id) {
+function generateNetworkTypeOptions ($networkId) {
        // Is this an array, then we just came back from edit/delete actions
-       if (is_array($id)) {
-               $id = '';
+       if (is_array($networkId)) {
+               $networkId = '';
        } // END - if
 
        // Is this cached?
-       if (!isset($GLOBALS[__FUNCTION__][$id])) {
+       if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
                // Generate output and cache it
-               $GLOBALS[__FUNCTION__][$id] = generateOptionList(
+               $GLOBALS[__FUNCTION__][$networkId] = generateOptionList(
                        'network_types',
                        'network_type_id',
                        'network_type_handle',
-                       $id,
+                       $networkId,
                        '',
                        sprintf(
                                "WHERE `network_id`=%s",
-                               bigintval(getRequestElement('network'))
+                               bigintval(getRequestElement('network_id'))
                        ),
                        '',
                        'translateNetworkTypeHandler'
@@ -520,7 +553,7 @@ function generateNetworkTypeOptions ($id) {
        } // END - if
 
        // Return content
-       return $GLOBALS[__FUNCTION__][$id];
+       return $GLOBALS[__FUNCTION__][$networkId];
 }
 
 // Generates an options list of all available (hard-coded) handlers
@@ -734,6 +767,42 @@ ORDER BY
        return translateNetworkTranslationName($name);
 }
 
+// Translates network API configuration status (see function isNetworkApiConfigured()) by given id
+function translateNetworkApiConfiguredStatusById ($networkId) {
+       // Do we have 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)) {
+                       // Yes, it is
+                       $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
+               } // END - if
+       } // END - if
+
+       // Return cache
+       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);
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$networkId];
+}
+
 //------------------------------------------------------------------------------
 //                             Call-back functions
 //------------------------------------------------------------------------------
@@ -751,13 +820,7 @@ function doAdminNetworkProcessAddNetwork () {
        unsetPostRequestElement('ok');
 
        // Add the whole request to database
-       SQL_QUERY('INSERT INTO
-       `{?_MYSQL_PREFIX?}_network_data`
-(
-       `' . implode('`,`', array_keys(postRequestArray())) . "`
-) VALUES (
-       '" . implode("','", array_values(postRequestArray())) . "'
-)", __FUNCTION__, __LINE__);
+       SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
 
        // Add the id for output only
        setPostRequestElement('network_id', SQL_INSERTID());
@@ -778,11 +841,11 @@ function doAdminNetworkProcessHandleNetwork () {
        if (ifPostContainsSelections()) {
                // Something has been selected, so start displaying one by one
                $OUT = '';
-               foreach (postRequestElement('sel') as $id => $sel) {
+               foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Is this selected?
                        if ($sel == 1) {
                                // Load this network's data
-                               $networkData = getNetworkDataById($id);
+                               $networkData = getNetworkDataById($networkId);
 
                                // Do we have found the network?
                                if (count($networkData) > 0) {
@@ -826,15 +889,15 @@ function doAdminNetworkProcessHandleNetworkType () {
        // Do we have selections?
        if (ifPostContainsSelections()) {
                // Load network data
-               $networkData = getNetworkDataById(getRequestElement('network'));
+               $networkData = getNetworkDataById(getRequestElement('network_id'));
 
                // Something has been selected, so start displaying one by one
                $OUT = '';
-               foreach (postRequestElement('sel') as $id => $sel) {
+               foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Is this selected?
                        if ($sel == 1) {
                                // Load this network's data
-                               $networkTypeData = getNetworkTypeDataById($id);
+                               $networkTypeData = getNetworkTypeDataById($networkId);
 
                                // Do we have found the network?
                                if (count($networkTypeData) > 0) {
@@ -881,15 +944,15 @@ function doAdminNetworkProcessHandleRequestParams () {
                $GLOBALS['network_params_disabled'] = array();
 
                // Load network data
-               $networkData = getNetworkDataById(getRequestElement('network'));
+               $networkData = getNetworkDataById(getRequestElement('network_id'));
 
                // Something has been selected, so start displaying one by one
                $OUT = '';
-               foreach (postRequestElement('sel') as $id => $sel) {
+               foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Is this selected?
                        if ($sel == 1) {
                                // Load this network's data
-                               $networkRequestData = getNetworkRequestParamsDataById($id);
+                               $networkRequestData = getNetworkRequestParamsDataById($networkId);
 
                                // Do we have found the network?
                                if (count($networkRequestData) > 0) {
@@ -939,7 +1002,7 @@ function doAdminNetworkProcessChangeNetwork () {
                $updated = 0;
 
                // Something has been selected, so start updating them
-               foreach (postRequestElement('sel') as $id => $sel) {
+               foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Update this entry?
                        if ($sel == 1) {
                                // Init data array
@@ -953,17 +1016,17 @@ function doAdminNetworkProcessChangeNetwork () {
                                        } // END - if
 
                                        // Do we have this enty?
-                                       if (!isset($entry[$id])) {
+                                       if (!isset($entry[$networkId])) {
                                                // Not found, needs fixing
-                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
+                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
                                        } // END - if
 
                                        // Add this entry
-                                       $networkData[$key] = $entry[$id];
+                                       $networkData[$key] = $entry[$networkId];
                                } // END - foreach
 
                                // Update the network data
-                               $updated += doNetworkUpdateDataByArray($id, $networkData);
+                               $updated += doNetworkUpdateDataByArray($networkId, $networkData);
                        } // END - if
                } // END - foreach
 
@@ -986,11 +1049,11 @@ function doAdminNetworkProcessRemoveNetwork () {
                $removed = 0;
 
                // Something has been selected, so start updating them
-               foreach (postRequestElement('sel') as $id => $sel) {
+               foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Update this entry?
                        if ($sel == 1) {
                                // Remove this entry
-                               $removed += doAdminRemoveNetworkEntry('data', 'network_id', $id);
+                               $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
                        } // END - if
                } // END - foreach
 
@@ -1008,7 +1071,7 @@ 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'))) {
+       if (isNetworkTypeHandleValid(postRequestElement('network_type_handle'), getRequestElement('network_id'))) {
                // Already added
                loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED=' . postRequestElement('network_type_handle') . '%}');
 
@@ -1020,7 +1083,7 @@ function doAdminNetworkProcessAddNetworkType () {
        unsetPostRequestElement('ok');
 
        // Add id
-       setPostRequestElement('network_id', bigintval(getRequestElement('network')));
+       setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
 
        // Is network_type_banner_url set?
        if (postRequestElement('network_type_banner_url') == '') {
@@ -1029,13 +1092,7 @@ function doAdminNetworkProcessAddNetworkType () {
        } // 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__);
+       SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
 
        // Output message
        if (!SQL_HASZEROAFFECTED()) {
@@ -1055,7 +1112,7 @@ function doAdminNetworkProcessChangeNetworkType () {
                $updated = 0;
 
                // Something has been selected, so start updating them
-               foreach (postRequestElement('sel') as $id => $sel) {
+               foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Update this entry?
                        if ($sel == 1) {
                                // Init data array
@@ -1069,23 +1126,23 @@ function doAdminNetworkProcessChangeNetworkType () {
                                        } // END - if
 
                                        // Do we have this enty?
-                                       if (!isset($entry[$id])) {
+                                       if (!isset($entry[$networkId])) {
                                                // Not found, needs fixing
-                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
+                                               debug_report_bug(__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[$id]) == '')) {
+                                       if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
                                                // Set it to NULL
-                                               $entry[$id] = NULL;
+                                               $entry[$networkId] = NULL;
                                        } // END - if
 
                                        // Add this entry
-                                       $networkTypeData[$key] = $entry[$id];
+                                       $networkTypeData[$key] = $entry[$networkId];
                                } // END - foreach
 
                                // Update the network data
-                               $updated += doNetworkUpdateTypeByArray($id, $networkTypeData);
+                               $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
                        } // END - if
                } // END - foreach
 
@@ -1108,7 +1165,7 @@ function doAdminNetworkProcessChangeNetworkParam () {
                $updated = 0;
 
                // Something has been selected, so start updating them
-               foreach (postRequestElement('sel') as $id => $sel) {
+               foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Update this entry?
                        if ($sel == 1) {
                                // Init data array
@@ -1122,23 +1179,23 @@ function doAdminNetworkProcessChangeNetworkParam () {
                                        } // END - if
 
                                        // Do we have this enty?
-                                       if (!isset($entry[$id])) {
+                                       if (!isset($entry[$networkId])) {
                                                // Not found, needs fixing
-                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.');
+                                               debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
                                        } // END - if
 
-                                       // Fix empty request_param_default to NULL
-                                       if (($key == 'request_param_default') && (trim($entry[$id]) == '')) {
+                                       // Fix empty network_request_param_default to NULL
+                                       if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
                                                // Set it to NULL
-                                               $entry[$id] = NULL;
+                                               $entry[$networkId] = NULL;
                                        } // END - if
 
                                        // Add this entry
-                                       $networkParamsData[$key] = $entry[$id];
+                                       $networkParamsData[$key] = $entry[$networkId];
                                } // END - foreach
 
                                // Update the network data
-                               $updated += doNetworkUpdateParamsByArray($id, $networkParamsData);
+                               $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
                        } // END - if
                } // END - foreach
 
@@ -1161,11 +1218,11 @@ function doAdminNetworkProcessRemoveNetworkType () {
                $removed = 0;
 
                // Something has been selected, so start updating them
-               foreach (postRequestElement('sel') as $id => $sel) {
+               foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Update this entry?
                        if ($sel == 1) {
                                // Remove this entry
-                               $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $id);
+                               $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
                        } // END - if
                } // END - foreach
 
@@ -1188,11 +1245,11 @@ function doAdminNetworkProcessRemoveNetworkParam () {
                $removed = 0;
 
                // Something has been selected, so start updating them
-               foreach (postRequestElement('sel') as $id => $sel) {
+               foreach (postRequestElement('sel') as $networkId => $sel) {
                        // Update this entry?
                        if ($sel == 1) {
                                // Remove this entry
-                               $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $id);
+                               $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $networkId);
                        } // END - if
                } // END - foreach
 
@@ -1210,9 +1267,9 @@ function doAdminNetworkProcessRemoveNetworkParam () {
 // Adds a request parameter to given network and type
 function doAdminNetworkProcessAddNetworkParam () {
        // Is the request parameter already used with given network?
-       if (isNetworkRequestElementValid(postRequestElement('request_param_key'), postRequestElement('network_type_id'), getRequestElement('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('request_param_key') . '%}');
+               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
 
                // ... so abort here
                return false;
@@ -1222,37 +1279,31 @@ function doAdminNetworkProcessAddNetworkParam () {
        unsetPostRequestElement('ok');
 
        // Add id
-       setPostRequestElement('network_id', bigintval(getRequestElement('network')));
+       setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
 
-       // Is request_param_default set?
-       if (postRequestElement('request_param_default') == '') {
+       // Is network_request_param_default set?
+       if (postRequestElement('network_request_param_default') == '') {
                // Remove empty value to get a NULL for an optional entry
-               unsetPostRequestElement('request_param_default');
+               unsetPostRequestElement('network_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__);
+       SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
 
        // Output message
        if (!SQL_HASZEROAFFECTED()) {
                // Successfully added
-               loadTemplate('admin_network_request_param_added', false, postRequestArray());
+               loadTemplate('admin_network_network_request_param_added', false, postRequestArray());
        } else {
                // Not added
-               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('request_param_key') . '%}');
+               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
        }
 }
 
 // Adds a API response array entry
 function doAdminNetworkProcessAddNetworkApiTranslation () {
        // Is the request parameter already used with given network?
-       if (isNetworkApiTranslationValid(postRequestElement('network_api_index'), postRequestElement('network_type_id'), getRequestElement('network'))) {
+       if (isNetworkApiTranslationValid(postRequestElement('network_api_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') . '%}');
 
@@ -1264,7 +1315,7 @@ function doAdminNetworkProcessAddNetworkApiTranslation () {
        unsetPostRequestElement('ok');
 
        // Add id
-       setPostRequestElement('network_id', bigintval(getRequestElement('network')));
+       setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
 
        // Add sorting
        setPostRequestElement('sort', (countSumTotalData(
@@ -1277,13 +1328,7 @@ function doAdminNetworkProcessAddNetworkApiTranslation () {
        ) + 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__);
+       SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_api_translation'), __FUNCTION__, __LINE__);
 
        // Output message
        if (!SQL_HASZEROAFFECTED()) {
@@ -1296,35 +1341,26 @@ function doAdminNetworkProcessAddNetworkApiTranslation () {
 }
 
 // Adds/update network API configuration
-function doAdminNetworkProcessConfigNetwork () {
-       // Check for an entry in network_api_config
-       $entryCount = countSumTotalData(
-               bigintval(getRequestElement('network')),
-               'network_api_config',
-               'network_id',
-               'network_id',
-               true
-       );
-
+function doAdminNetworkProcessNetworkApiConfig () {
        // Remove the 'ok' part
        unsetPostRequestElement('ok');
 
        // Add id
-       setPostRequestElement('network_id', bigintval(getRequestElement('network')));
+       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
 
        // Is there already an entry?
-       if ($entryCount == 1) {
+       if (isNetworkApiConfigured(getRequestElement('network_id'))) {
                // Generate SQL query
                $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
        } else {
                // Insert new entry
-               $SQL = 'INSERT INTO
-       `{?_MYSQL_PREFIX?}_network_api_config`
-(
-       `' . implode('`,`', array_keys(postRequestArray())) . "`
-) VALUES (
-       '" . implode("','", array_values(postRequestArray())) . "'
-)";
+               $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
        }
 
        // Run the query
@@ -1333,10 +1369,10 @@ function doAdminNetworkProcessConfigNetwork () {
        // Output message
        if (!SQL_HASZEROAFFECTED()) {
                // Successfully added
-               displayMessage('{--ADMIN_NETWORK_API_CONFIG_SAVED--}');
+               displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
        } else {
                // Not added
-               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_API_CONFIG_NOT_SAVED--}');
+               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
        }
 }