X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Flibs%2Fnetwork_functions.php;h=0c71a5269b071282c9a52cb1054abee17311d5cf;hp=af436aff7b8bb6d95ac3315d821068f2eaa483f9;hb=465859de0e017d99130df209391fe0742fc24271;hpb=9afd6ec5878544a7982c50ed9c0dd7de37606d5b diff --git a/inc/libs/network_functions.php b/inc/libs/network_functions.php index af436aff7b..0c71a5269b 100644 --- a/inc/libs/network_functions.php +++ b/inc/libs/network_functions.php @@ -1,7 +1,7 @@ '.encodeEntities($content).''); + + // Return content + return $content; +} + +// Generator (somewhat getter) for network type options +function generateNetworkTypeOptions ($networkId) { + // Is this an array, then we just came back from edit/delete actions + if (is_array($networkId)) { + $networkId = ''; + } // END - if + + // Is this cached? + if (!isset($GLOBALS[__FUNCTION__][$networkId])) { + // Generate output and cache it + $GLOBALS[__FUNCTION__][$networkId] = generateOptionList( + 'network_types', + 'network_type_id', + 'network_type_handle', + $networkId, + '', + sprintf( + "WHERE `network_id`=%s", + bigintval(getRequestElement('network_id')) + ), + '', + 'translateNetworkTypeHandler' + ); + } // END - if + + // Return content + return $GLOBALS[__FUNCTION__][$networkId]; +} + +// 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'], + 'translateNetworkRequestElement' + ); + } // 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]; +} + +// Generates an option list of network_api_active +function generateNetworkApiActiveOptions ($default = '') { + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__][$default])) { + // Generate the list + $GLOBALS[__FUNCTION__][$default] = generateYesNoOptionList($default); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__][$default]; +} + +// Translates 'translate_name' for e.g. templates +function translateNetworkTranslationName ($name) { + // Get the message id + return '{--ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME--}'; +} + +// Translates the network type handler (e.g. banner, paidmail) for templates +function translateNetworkTypeHandler ($type) { + // Get the message id + return '{--ADMIN_NETWORK_TYPES_' . strtoupper($type) . '--}'; +} + +// Translates request type +function translateNetworkRequestType ($type) { + // Get the message id + return '{--ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '--}'; +} + +// Translates request parameter +function translateNetworkRequestElement ($param) { + // Get the message id + return '{--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_HASZERONUMS($result)) { + // Get all entries + while ($row = SQL_FETCHARRAY($result)) { + // Add it to our global array + $GLOBALS['network_api_index'][$row['network_api_index']] = $row; + } // 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); +} + +// 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]; } //------------------------------------------------------------------------------ @@ -122,62 +808,109 @@ 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'))) { // Already there - loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_ALREADY_ADDED'), postRequestElement('network_short_name'))); - return; + loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}'); + return false; } // END - if // Remove the 'ok' part unsetPostRequestElement('ok'); // Add the whole request to database - SQL_QUERY("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 - setRequestPostElement('network_id', SQL_INSERTID()); + setPostRequestElement('network_id', SQL_INSERTID()); // Output message - if (SQL_AFFECTEDROWS() == 1) { + if (!SQL_HASZEROAFFECTED()) { // Successfully added 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, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('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 (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) { - // Add color - $networkData['sw'] = $SW; + if (isFormSent('edit')) { + // Add row template for editing + $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData); + } elseif (isFormSent('delete')) { + // Add row template for deleting + $OUT .= loadTemplate('admin_delete_networks_row', true, $networkData); + } else { + // Problem! + debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.'); + } + } // 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_networks', false, $OUT); + } elseif (isFormSent('delete')) { + loadTemplate('admin_delete_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_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(getRequestElement('network_id')); - // Make selection box for network_request_type - $networkData['network_request_type'] = addSelectionBox('network_request_type', $networkData['network_request_type'], '', 0, 'admin_select'); + // Something has been selected, so start displaying one by one + $OUT = ''; + foreach (postRequestElement('sel') as $networkId => $sel) { + // Is this selected? + if ($sel == 1) { + // Load this network's data + $networkTypeData = getNetworkTypeDataById($networkId); - // Add row template and switch color - $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData); - $SW = 3 - $SW; + // 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('delete')) { + // Add row template for deleting + $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData); + } else { + // Problem! + debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.'); + } } // END - if } // END - if } // END - foreach @@ -185,16 +918,483 @@ 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_network_types', false, $OUT); + } elseif (isFormSent('delete')) { + loadTemplate('admin_delete_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_saved', false, getMessage('ADMIN_NETWORK_NOTHING_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(getRequestElement('network_id')); + + // Something has been selected, so start displaying one by one + $OUT = ''; + foreach (postRequestElement('sel') as $networkId => $sel) { + // Is this selected? + if ($sel == 1) { + // Load this network's data + $networkRequestData = getNetworkRequestParamsDataById($networkId); + + // 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('delete')) { + // Get type data + $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']); + + // Add row template for deleting + $OUT .= loadTemplate('admin_delete_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('delete')) { + loadTemplate('admin_delete_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 (postRequestElement('sel') as $networkId => $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', 'do_edit'))) { + continue; + } // END - if + + // Do we have this enty? + if (!isset($entry[$networkId])) { + // Not found, needs fixing + debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.'); + } // END - if + + // Add this entry + $networkData[$key] = $entry[$networkId]; + } // END - foreach + + // Update the network data + $updated += doNetworkUpdateDataByArray($networkId, $networkData); + } // END - if + } // END - foreach + + // Do we have updates? + if ($updated > 0) { + // Updates done + displayMessage('{%message,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 (postRequestElement('sel') as $networkId => $sel) { + // Update this entry? + if ($sel == 1) { + // Remove this entry + $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId); + } // END - if + } // END - foreach + + // Do we have removes? + if ($removed > 0) { + // Removals done + displayMessage('{%message,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(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') . '%}'); + + // ... so abort here + return false; + } // END - if + + // Remove the 'ok' part + unsetPostRequestElement('ok'); + + // Add id + setPostRequestElement('network_id', bigintval(getRequestElement('network_id'))); + + // Is network_type_banner_url set? + if (postRequestElement('network_type_banner_url') == '') { + // Remove empty value to get a NULL for an optional entry + unsetPostRequestElement('network_type_banner_url'); + } // END - if + + // Add the whole request to database + SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__); + + // Output message + if (!SQL_HASZEROAFFECTED()) { + // Successfully added + loadTemplate('admin_network_type_added', false, postRequestArray()); + } else { + // Not added + loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPES_NOT_ADDED=' . postRequestElement('network_type_handle') . '%}'); + } +} + +// 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 (postRequestElement('sel') as $networkId => $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', 'do_edit'))) { + continue; + } // END - if + + // Do we have this enty? + if (!isset($entry[$networkId])) { + // Not found, needs fixing + 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[$networkId]) == '')) { + // Set it to NULL + $entry[$networkId] = NULL; + } // END - if + + // Add this entry + $networkTypeData[$key] = $entry[$networkId]; + } // END - foreach + + // Update the network data + $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData); + } // END - if + } // END - foreach + + // Do we have updates? + if ($updated > 0) { + // Updates done + displayMessage('{%message,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 (postRequestElement('sel') as $networkId => $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', 'do_edit'))) { + continue; + } // END - if + + // Do we have this enty? + if (!isset($entry[$networkId])) { + // Not found, needs fixing + debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.'); + } // END - if + + // Fix empty network_request_param_default to NULL + if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) { + // Set it to NULL + $entry[$networkId] = NULL; + } // END - if + + // Add this entry + $networkParamsData[$key] = $entry[$networkId]; + } // END - foreach + + // Update the network data + $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData); + } // END - if + } // END - foreach + + // Do we have updates? + if ($updated > 0) { + // Updates done + displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}'); + } else { + // Nothing changed + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}'); + } + } // 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 (postRequestElement('sel') as $networkId => $sel) { + // Update this entry? + if ($sel == 1) { + // Remove this entry + $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId); + } // END - if + } // END - foreach + + // Do we have removes? + if ($removed > 0) { + // Removals done + displayMessage('{%message,ADMIN_NETWORK_TYPES_REMOVED=' . $removed . '%}'); + } else { + // Nothing removed + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_REMOVED--}'); } } // END - if } +// 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 (postRequestElement('sel') as $networkId => $sel) { + // Update this entry? + if ($sel == 1) { + // Remove this entry + $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $networkId); + } // END - if + } // END - foreach + + // Do we have removes? + if ($removed > 0) { + // Removals done + displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}'); + } else { + // Nothing removed + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}'); + } + } // END - if +} + +// Adds a request parameter to given network and type +function doAdminNetworkProcessAddNetworkParam () { + // Is the request parameter already used with given network? + if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) { + // Already added + loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}'); + + // ... so abort here + return false; + } // END - if + + // Remove the 'ok' part + unsetPostRequestElement('ok'); + + // Add id + setPostRequestElement('network_id', bigintval(getRequestElement('network_id'))); + + // Is network_request_param_default set? + if (postRequestElement('network_request_param_default') == '') { + // Remove empty value to get a NULL for an optional entry + unsetPostRequestElement('network_request_param_default'); + } // END - if + + // Add the whole request to database + SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__); + + // Output message + if (!SQL_HASZEROAFFECTED()) { + // Successfully added + 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('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_id'))) { + // Already added + loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_api_index') . '%}'); + + // ... so abort here + return false; + } // END - if + + // Remove the 'ok' part + unsetPostRequestElement('ok'); + + // Add id + setPostRequestElement('network_id', bigintval(getRequestElement('network_id'))); + + // Add sorting + setPostRequestElement('sort', (countSumTotalData( + bigintval(postRequestElement('network_id')), + 'network_api_translation', + 'network_api_id', + 'network_id', + true, + sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id'))) + ) + 1)); + + // Add the whole request to database + SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_api_translation'), __FUNCTION__, __LINE__); + + // Output message + if (!SQL_HASZEROAFFECTED()) { + // Successfully added + loadTemplate('admin_network_api_translation_added', false, postRequestArray()); + } else { + // Not added + loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_API_TRANSLATION_NOT_ADDED=' . postRequestElement('network_api_index') . '%}'); + } +} + +// Adds/update network API configuration +function doAdminNetworkProcessNetworkApiConfig () { + // Remove the 'ok' part + unsetPostRequestElement('ok'); + + // Add id + setPostRequestElement('network_id', bigintval(getRequestElement('network_id'))); + + // Is network_api_referral_button set? + if (postRequestElement('network_api_referral_button') == '') { + // Remove empty value to get a NULL for an optional entry + unsetPostRequestElement('network_api_referral_button'); + } // END - if + + // Is there already an entry? + 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 = getInsertSqlFromArray(postRequestArray(), 'network_api_config'); + } + + // Run the query + SQL_QUERY($SQL, __FUNCTION__, __LINE__); + + // Output message + if (!SQL_HASZEROAFFECTED()) { + // Successfully added + displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}'); + } else { + // Not added + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}'); + } +} + +// 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] ?>