+// Generates an option list of request types
+function generateNetworkRequestTypeOptions ($default = '') {
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$default])) {
+ // Generate the list
+ $GLOBALS[__FUNCTION__][$default] = generateOptions(
+ '/ARRAY/',
+ array(
+ 'GET',
+ 'POST'
+ ),
+ array(
+ '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
+ '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
+ ),
+ $default
+ );
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$default];
+}
+
+// Generates an option list of network_api_active
+function generateNetworkApiActiveOptions ($default = '') {
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$default])) {
+ // Generate the list
+ $GLOBALS[__FUNCTION__][$default] = generateYesNoOptions($default);
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$default];
+}
+
+// Generator (somewhat getter) for network type options
+function generateNetworkMediaOutputOptions ($mediaOutput) {
+ // Is this an array, then we just came back from edit/delete actions
+ if (is_array($mediaOutput)) {
+ // Set it as empty string
+ $mediaOutput = '';
+ } // END - if
+
+ // Is this cached?
+ if (!isset($GLOBALS[__FUNCTION__][$mediaOutput])) {
+ // Generate output and cache it
+ $GLOBALS[__FUNCTION__][$mediaOutput] = generateOptions(
+ '/ARRAY/',
+ array(
+ '',
+ 'banner',
+ 'html_email',
+ 'layer',
+ 'pagepeel',
+ 'popup',
+ 'popdown',
+ 'text_email',
+ 'textlink'
+ ),
+ array(
+ '{--ADMIN_NETWORK_MEDIA_OUTPUT_NONE--}',
+ '{--ADMIN_NETWORK_MEDIA_OUTPUT_BANNER--}',
+ '{--ADMIN_NETWORK_MEDIA_OUTPUT_HTML_EMAIL--}',
+ '{--ADMIN_NETWORK_MEDIA_OUTPUT_LAYER--}',
+ '{--ADMIN_NETWORK_MEDIA_OUTPUT_PAGEPEEL--}',
+ '{--ADMIN_NETWORK_MEDIA_OUTPUT_POPUP--}',
+ '{--ADMIN_NETWORK_MEDIA_OUTPUT_POPDOWN--}',
+ '{--ADMIN_NETWORK_MEDIA_OUTPUT_TEXT_EMAIL--}',
+ '{--ADMIN_NETWORK_MEDIA_OUTPUT_TEXTLINK--}'
+ ),
+ $mediaOutput,
+ 'translateNetworkMediaOutputType'
+ );
+ } // END - if
+
+ // Return content
+ return $GLOBALS[__FUNCTION__][$mediaOutput];
+}
+
+// Checks if the given network is configured by looking its API configuration entry up
+function isNetworkApiConfigured ($networkId) {
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
+ // Check for an entry in network_api_config
+ $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
+ bigintval($networkId),
+ 'network_api_config',
+ 'network_id',
+ 'network_id',
+ true
+ ) == 1);
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$networkId];
+}
+
+// Checks whether the given network type handler is configured
+function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
+ // Determine it
+ $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
+ bigintval($networkTypeId),
+ 'network_handler_config',
+ 'network_data_id',
+ 'network_type_id',
+ true,
+ sprintf(' AND `network_id`=%s', bigintval($networkId))
+ ) == 1);
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
+}
+
+// Handles the network-payment-check request
+function handleNetworkPaymentCheckRequest () {
+ // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
+ reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
+}
+
+// Handles the network-delete-url request
+function handleNetworkDeleteUrlRequest () {
+ // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
+ reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
+}
+
+// Handle a single request parameter key by given network type handler id and "internal" key
+function handleRequestParameterKey ($networkTypeId, $networkRequestKey) {
+ // Construct call-back function name
+ $callbackName = 'doHandleNetworkRequest' . capitalizeUnderscoreString($networkRequestKey) . 'Key';
+
+ // Is the function there?
+ if (!function_exists($callbackName)) {
+ // Call-back function does not exist
+ reportBug(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' does not exist. networkTypeId=' . $networkTypeId . ',networkRequestKey=' . $networkRequestKey);
+ } // END - if
+
+ // Call it with network type id
+ return call_user_func_array($callbackName, array($networkTypeId));
+}
+
+// Handle all keys given request parameter array loaded by getNetworkRequestParametersByTypeId()
+function handleNetworkRequestParameterKeys (&$requestParams) {
+ // Simple check for validity
+ assert(isset($requestParams[0]['network_request_param_key']));
+
+ // "Walk" through all
+ foreach ($requestParams as $key => $params) {
+ // Is the default value not set?
+ if (empty($params['network_request_param_default'])) {
+ // This key needs to be handled, so call it
+ $requestParams[$key]['network_request_param_default'] = handleRequestParameterKey($params['network_type_id'], $params['network_request_param_key']);
+ } // END - if
+ } // END - foreach
+}
+
+/**
+ * Logs given HTTP headers to database for debugging purposes.
+ *
+ * @param $networkId Network's id number
+ * @param $networkTypeId Network type handler's id number
+ * @param $headers All HTTP headers
+ * @param $type Can be only one of 'MANUAL' or 'CRON'
+ * @return void
+ */
+function logNetworkResponseHeaders ($networkId, $networkTypeId, $headers, $type) {
+ // Make sure type is valid
+ assert(in_array($type, array('MANUAL', 'CRON')));
+
+ // Is debug logging enabled or status code not 200 OK?
+ if ((getConfig('network_logging_debug') == 'Y') || (!isHttpStatusOkay($headers[0]))) {
+ // Add entry
+ SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_network_header_logging` (`network_id`, `network_type_id`, `network_http_status_code`, `network_http_headers`, `network_logging_type`) VALUES(%s, %s, '%s', '%s', '%s')",
+ array(
+ bigintval($networkId),
+ bigintval($networkTypeId),
+ trim($headers[0]),
+ serialize($headers),
+ $type
+ ), __FUNCTION__, __LINE__);
+ } // END - if
+}
+
+/**
+ * Caches given reponse body from API into cache, updates existing cache if
+ * found. This function does the charset-convertion, so you don't have to do it
+ * again if you use this cached data.
+ *
+ * @param $networkId Network's id number
+ * @param $networkTypeId Network type handler's id number
+ * @param $responseBody Response body (string)
+ * @param $networkData Network + type handler data as array
+ * @param $type Can be only one of 'MANUAL' or 'CRON'
+ * @return void
+ */
+function saveNetworkResponseBodyInCache ($networkId, $networkTypeId, $responseBody, $networkData, $type) {
+ // Make sure the body is not larger than this value
+ assert(strlen($responseBody) <= 16777215);
+ assert(in_array($type, array('MANUAL', 'CRON')));
+
+ // So is there cache?
+ if (countSumTotalData($networkId, 'network_cache', 'network_cache_id', 'network_id', TRUE, ' AND `network_type_id`=' . bigintval($networkTypeId)) == 1) {
+ // Entry found, so update it
+ SQL_QUERY_ESC("UPDATE
+ `{?_MYSQL_PREFIX?}_network_cache`
+SET
+ `network_cache_data`='%s',
+ `network_cache_body`='%s',
+ `network_cache_type`='%s',
+ `network_cache_admin_id`=%s,
+ `network_cache_updated`=NOW()
+WHERE
+ `network_id`=%s AND
+ `network_type_id`=%s
+LIMIT 1",
+ array(
+ serialize($networkData),
+ compress(convertCharsetToUtf8($responseBody, $networkData['network_charset'])),
+ $type,
+ convertZeroToNull(getCurrentAdminId()),
+ bigintval($networkId),
+ bigintval($networkTypeId)
+ ), __FUNCTION__, __LINE__);
+ } else {
+ // Add entry
+ SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_network_cache` (`network_id`, `network_type_id`, `network_cache_data`, `network_cache_body`, `network_cache_type`, `network_cache_admin_id`) VALUES(%s, %s, '%s', '%s', '%s', %s)",
+ array(
+ bigintval($networkId),
+ bigintval($networkTypeId),
+ serialize($networkData),
+ compress(convertCharsetToUtf8($responseBody, $networkData['network_charset'])),
+ $type,
+ convertZeroToNull(getCurrentAdminId())
+ ), __FUNCTION__, __LINE__);
+ }
+}
+
+// Queries network API with given network data and request data
+function queryNetworkApi ($networkData, $requestData) {
+ // Query it
+ $response = sendHttpRequest($networkData['network_request_type'], $networkData['network_type_api_url'], $requestData, FALSE, FALSE);
+
+ // Did all went fine? (also a 403 is considered as "okay" here)
+ if (count($response) > 3) {
+ // Save response body, remove last empty line if really empty
+ $responseBody = (string) trim($response[count($response) - 1]);
+ unset($response[count($response) - 1]);
+ assert(empty($response[count($response)]));
+ unset($response[count($response) - 1]);
+
+ // Register all HTTP headers for debugging purposes
+ logNetworkResponseHeaders($networkData['network_id'], postRequestElement('network_type_id'), $response, 'MANUAL');
+
+ // Is all fine?
+ if (isHttpStatusOkay($response[0])) {
+ // Count API request
+ countNetworkApiRequest($networkData);
+
+ // Save response in cache
+ saveNetworkResponseBodyInCache($networkData['network_id'], postRequestElement('network_type_id'), $responseBody, $networkData, 'MANUAL');
+ } // END - if
+ } // END - if
+
+ // Return the response
+ return $response;
+}
+
+/**
+ * Counts API request from given network data generated by getNetworkDataByTypeId()
+ *
+ * @param $networkData Array with network data
+ * @return $affectedRows Affected rows (always one or FALSE if unlimited/depleted)
+ */
+function countNetworkApiRequest ($networkData) {
+ // Get API config
+ $apiConfig = getFullNetworkConfigurationByTypeId($networkData['network_type_id']);
+
+ // Is the daily or remaining free amount zero?
+ if (($networkData['network_query_amount'] == 0) || ($apiConfig['network_api_remaining_requests'] == 0)) {
+ // Then abort here
+ return FALSE;
+ } // END - if
+
+ // Okay, so update database
+ $result = SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_network_api_config` SET `network_api_remaining_requests`=`network_api_remaining_requests`-1 WHERE `network_id`=%s LIMIT 1",
+ array(
+ bigintval($networkData['network_id'])
+ ), __FUNCTION__, __LINE__);
+
+ // Return affected rows
+ return SQL_AFFECTEDROWS();
+}
+
+/**
+ * Generates a referral link for given network id (including HTML)
+ *
+ * @param $networkId Network id to generate link for
+ * @return $output "Rendered" output
+ */
+function generateMetworkReferralLinkById ($networkId) {
+ // Simple output (no need for template!)
+ $output = '<a href="{%network,getNetworkDataById,network_reflink=' . $networkId . '%}" target="_blank" title="{%network,getNetworkDataById,network_title=' . $networkId . '%}">{%network,getNetworkDataById,network_title=' . $networkId . '%}</a>';
+
+ // Return it
+ return $output;
+}
+
+//------------------------------------------------------------------------------
+// "Translation" functions (can be used in EL code)
+//------------------------------------------------------------------------------
+
+// Translates 'translate_name' for e.g. templates
+function translateNetworkTranslationName ($name) {
+ // Return message id
+ return translateGeneric('ADMIN_NETWORK_TRANSLATE', $name, '_NAME');
+}
+
+// Translates the network type id to a handler
+function translateNetworkTypeHandlerByTypeId ($typeId) {
+ // Get the data
+ $data = getNetworkDataByTypeId($typeId, 'network_type_handler');
+
+ // Is data found?
+ if (is_null($data)) {
+ // Not found
+ return translateNetworkTypeHandler('UNKNOWN');
+ } // END - if
+
+ // Return actual translation
+ return translateNetworkTypeHandler($data);
+}
+
+// "Translates" give network media output (type)
+function translateNetworkMediaOutputType ($mediaOutput) {
+ // Return message id
+ return translateGeneric('ADMIN_NETWORK_MEDIA_OUTPUT', $mediaOutput);
+}
+
+// Translates the network type handler (e.g. banner, paidmail) for templates
+function translateNetworkTypeHandler ($type) {
+ // Generate id
+ $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
+
+ // Is the message id there?
+ if (!isMessageIdValid($messageId)) {
+ // Not valid type
+ reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
+ } // END - if
+
+ // Return message id
+ return '{--' . $messageId . '--}';
+}
+
+// Translates request type
+function translateNetworkRequestType ($type) {
+ // Generate id
+ $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
+
+ // Is the message id there?
+ if (!isMessageIdValid($messageId)) {
+ // Not valid type
+ reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
+ } // END - if
+
+ // Return message id
+ return '{--' . $messageId . '--}';
+}
+
+// Translates request parameter
+function translateNetworkRequestParameterKey ($param) {
+ // Generate id
+ $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
+
+ // Is the message id there?
+ if (!isMessageIdValid($messageId)) {
+ // Not valid param
+ reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
+ } // END - if
+
+ // Return message id
+ return '{--' . $messageId . '--}';
+}
+
+// Translates vheck request parameter
+function translateNetworkVcheckParameterKey ($param) {
+ // Generate id
+ $messageId = 'ADMIN_NETWORK_VCHECK_PARAMETER_' . strtoupper($param) . '';
+
+ // Is the message id there?
+ if (!isMessageIdValid($messageId)) {
+ // Not valid param
+ reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
+ } // END - if
+
+ // Return message id
+ return '{--' . $messageId . '--}';
+}
+
+// Translate text-encoding
+function translateNetworkTextEncoding ($encoding) {
+ // Generate id
+ $messageId = 'ADMIN_NETWORK_TYPE_TEXT_ENCODING_' . strtoupper($encoding) . '';
+
+ // Is the message id there?
+ if (!isMessageIdValid($messageId)) {
+ // Not valid encoding
+ reportBug(__FUNCTION__, __LINE__, 'encoding=' . $encoding . ' is invalid.');
+ } // END - if
+
+ // Return message id
+ return '{--' . $messageId . '--}';
+}
+
+// Translates API index
+function translateNetworkApiIndex ($index) {
+ // Is there cache?
+ if (!isset($GLOBALS['network_array_index'])) {
+ // Get an array of all API array indexes
+ $GLOBALS['network_array_index'] = array();
+
+ // Get all entries
+ $result = SQL_QUERY('SELECT
+ `network_array_id`,
+ `network_array_index`,
+ `network_translation_name`
+FROM
+ `{?_MYSQL_PREFIX?}_network_array_translation`
+INNER JOIN
+ `{?_MYSQL_PREFIX?}_network_translations`
+ON
+ `network_array_index`=`network_translation_id`
+ORDER BY
+ `network_array_sort` ASC', __FUNCTION__, __LINE__);
+
+ // Are there entries?
+ if (!SQL_HASZERONUMS($result)) {
+ // Get all entries
+ while ($row = SQL_FETCHARRAY($result)) {
+ // Add it to our global array
+ $GLOBALS['network_array_index'][$row['network_array_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_array_index'][$index])) {
+ // Then get the name
+ $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
+ } // END - if
+
+ // Return translation
+ return translateNetworkTranslationName($name);
+}
+
+// Translates network API configuration status (see function isNetworkApiConfigured()) by given id
+function translateNetworkApiConfiguredStatusById ($networkId) {
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
+ // By default it is not configured
+ $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
+
+ // So is it configured?
+ if (!isNetworkActiveById($networkId)) {
+ // Network is not active
+ $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_ACTIVE--}';
+ } elseif (isNetworkApiConfigured($networkId)) {
+ // Yes, it is
+ $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
+ } // END - if
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__][$networkId];
+}
+
+/**
+ * "Translates" given amount of queries; 0 = unlimited
+ *
+ * @param $amount Amount of free queries
+ * @return $translated "Translated" value; 0 = unlimited
+ */
+function translateNetworkQueryAmount ($amount) {
+ // Default is unlimited (good! ;-) )
+ $translated = '{--UNLIMITED--}';
+
+ // Is the amount larger zero?
+ if ($amount > 0) {
+ // Then translate it
+ $translated = translateComma($amount);
+ } // END - if
+
+ // Return translated value
+ return $translated;
+}
+
+/**
+ * "Translates given status (Y/N) to "de-/activated" but only if expert and
+ * debug mode are enabled.
+ *
+ * @param $status Can be one of Y/N
+ * @return $translated "Translated" status
+ */
+function translateNetworkActivationStatus ($status) {
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__][$status])) {
+ // Default is not enabled
+ $GLOBALS[__FUNCTION__][$status] = '';
+
+ // Is expert + debug mode enabled?
+ if ((isAdminsExpertSettingEnabled()) && (isDebugModeEnabled())) {
+ // Then "translate" it
+ $GLOBALS[__FUNCTION__][$status] = translateActivationStatus($status);
+ } // END - if
+ } // END - if
+
+ // Return "translation"
+ return $GLOBALS[__FUNCTION__][$status];
+}
+
+//------------------------------------------------------------------------------
+// Wrapper functions to save data to network tables
+//------------------------------------------------------------------------------
+
+// Updates given network (id) with data from array
+function doNetworkUpdateDataByArray ($networkId, $networkData) {
+ // Ids lower one are not accepted
+ if (!isValidId($networkId)) {
+ // Not good, should be fixed
+ reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
+ } // END - if
+
+ // Just call our inner method
+ return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), FALSE, FALSE);
+}
+
+// Updates given network type handler (id) with data from array
+function doNetworkUpdateTypeByArray ($networkTypeId, $networkTypeData) {
+ // Ids lower one are not accepted
+ if (!isValidId($networkTypeId)) {
+ // Not good, should be fixed
+ reportBug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkTypeId . ' is smaller than 1.');
+ } // END - if
+
+ // Just call our inner method
+ return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkTypeId)), array(), FALSE, FALSE);
+}
+
+// Updates given network request parameters (id) with data from array
+function doNetworkUpdateParamsByArray ($networkParamsId, $networkParamsData) {
+ // Ids lower one are not accepted
+ if (!isValidId($networkParamsId)) {
+ // Not good, should be fixed
+ reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkParamsId . ' is smaller than 1.');
+ } // END - if
+
+ // Just call our inner method
+ return adminSaveSettings($networkParamsData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkParamsId)), array(), FALSE, FALSE);
+}
+
+// Updates given network array translations (id) with data from array
+function doNetworkUpdateArrayTranslationsByArray ($networkTranslationsId, $networkTranslationsData) {
+ // Ids lower one are not accepted
+ if (!isValidId($networkTranslationsId)) {
+ // Not good, should be fixed
+ reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkTranslationsId . ' is smaller than 1.');
+ } // END - if
+
+ // Just call our inner method
+ return adminSaveSettings($networkTranslationsData, '_network_array_translation', sprintf("`network_array_id`=%s", bigintval($networkTranslationsId)), array(), FALSE, FALSE);
+}
+
+//------------------------------------------------------------------------------
+// Call-back functions for request parameter keys
+//------------------------------------------------------------------------------
+
+// ----------------------- Table: network_api_config -----------------------
+
+// Handles affiliate id
+function doHandleNetworkRequestAffiliateIdKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ } elseif (empty($configData['network_api_affiliate_id'])) {
+ // Required element is not set
+ reportBug(__FUNCTION__, __LINE__, 'network_api_affiliate_id for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+ }
+
+ // Return configured value
+ return $configData['network_api_affiliate_id'];
+}
+
+// Handles site id
+function doHandleNetworkRequestSiteIdKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ } elseif (empty($configData['network_api_site_id'])) {
+ // Required element is not set
+ reportBug(__FUNCTION__, __LINE__, 'network_api_site_id for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+ }
+
+ // Return configured value
+ return $configData['network_api_site_id'];
+}
+
+// Handles interface password
+function doHandleNetworkRequestPasswordKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ } elseif (empty($configData['network_api_password'])) {
+ // Required element is not set
+ reportBug(__FUNCTION__, __LINE__, 'network_api_password for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+ }
+
+ // Return configured value
+ return $configData['network_api_password'];
+}
+
+// ----------------------- Table: network_handler_config -----------------------
+
+// Handles reload lock
+function doHandleNetworkRequestReloadKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ }
+
+ // Return configured value
+ return caluculateTimeUnitValue($configData['network_max_reload_time'], $configData['network_type_reload_time_unit']);
+}
+
+// Handles minimum stay
+function doHandleNetworkRequestMinimumStayKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ }
+
+ // Return configured value
+ return $configData['network_min_waiting_time'];
+}
+
+// Handles maximum stay
+function doHandleNetworkRequestMaximumStayKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ }
+
+ // Return configured value
+ return $configData['network_max_waiting_time'];
+}
+
+// Handles remaining clicks
+function doHandleNetworkRequestRemainClicksKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ }
+
+ // Return configured value
+ return $configData['network_min_remain_clicks'];
+}
+
+// Handles remaining budget
+function doHandleNetworkRequestRemainBudgetKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ }
+
+ // Return configured value
+ return $configData['network_min_remain_budget'];
+}
+
+// Handles reward (payment)
+function doHandleNetworkRequestRewardKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ } elseif (empty($configData['network_min_payment'])) {
+ // Required element is not set
+ reportBug(__FUNCTION__, __LINE__, 'network_min_payment for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+ }
+
+ // Return configured value
+ return $configData['network_min_payment'];
+}
+
+// Handles media size
+function doHandleNetworkRequestSizeKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ } elseif (empty($configData['network_media_size'])) {
+ // Required element is not set
+ reportBug(__FUNCTION__, __LINE__, 'network_media_size for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+ }
+
+ // Return configured value
+ return $configData['network_media_size'];
+}
+
+// Handles media output (type)
+function doHandleNetworkRequestTypeKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ }
+
+ // Return configured value
+ return $configData['network_media_output'];
+}
+
+// Handles erotic
+function doHandleNetworkRequestEroticKey ($networkTypeId) {
+ // It is assumed that the network + type handler are both configured
+ // Load full config data (this will be "cached"!)
+ $configData = getFullNetworkConfigurationByTypeId($networkTypeId);
+
+ // Is the network activated?
+ if (!isset($configData['network_api_active'])) {
+ // Configuration could not be loaded
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for networkTypeId=' . $networkTypeId . ' could not be loaded.');
+ } elseif (($configData['network_api_active'] == 'N') && (!isDebugModeEnabled())) {
+ // Is not activated, so don't handle it in non-debug mode
+ reportBug(__FUNCTION__, __LINE__, 'Configuration for network_id ' . $configData['network_id'] .',networkTypeId=' . $networkTypeId . ' is not activated.');
+ } elseif (empty($configData['network_allow_erotic'])) {
+ // Required element is not set
+ reportBug(__FUNCTION__, __LINE__, 'network_allow_erotic for network_id=' . $configData['network_id'] . ',networkTypeId=' . $networkTypeId . ' is not set.');
+ }
+
+ // Return configured value
+ return $configData['network_allow_erotic'];
+}
+
+// ----------------------- Table: network_request_params -----------------------
+
+//------------------------------------------------------------------------------
+// Call-back functions for admin area
+//------------------------------------------------------------------------------
+
+// Callback function to add new network
+function doAdminNetworkProcessAddNetwork () {
+ // We can say here, the form is sent, so check if the network is already added
+ if (isNetworkNameValid(postRequestElement('network_short_name'))) {
+ // Already there
+ loadTemplate('admin_settings_unsaved', FALSE, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
+ return FALSE;
+ } // END - if
+
+ // Add the whole request to database
+ SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);