X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Flibs%2Fnetwork_functions.php;h=b33bfea63ba7edea3f7d49082ede2fad9a7fb682;hp=3bdfec6e1d23601facee9422300c25aa3bd74b74;hb=0715fa7aa8e5e70bcf1d957fb09ae655c3896c4e;hpb=09f5758c42a33a56bdd461c946ffe759a59c54aa diff --git a/inc/libs/network_functions.php b/inc/libs/network_functions.php index 3bdfec6e1d..b33bfea63b 100644 --- a/inc/libs/network_functions.php +++ b/inc/libs/network_functions.php @@ -45,7 +45,7 @@ if (!defined('__SECURITY')) { // Handle a (maybe) sent form here function doNetworkHandleForm () { // Was the form sent? - if ((isFormSent()) || (isPostRequestParameterSet('edit')) || (isPostRequestParameterSet('del')) || (isPostRequestParameterSet('change')) || (isPostRequestParameterSet('remove'))) { + if ((isFormSent()) || (isFormSent('edit')) || (isFormSent('del')) || (isFormSent('change')) || (isFormSent('remove'))) { // Do we have a 'do'? if (isGetRequestParameterSet('do')) { // Process the request @@ -60,7 +60,7 @@ function doNetworkHandleForm () { // Processes an admin form function doAdminNetworkProcessForm () { // Form really sent? - if ((!isFormSent()) && (!isPostRequestParameterSet('edit')) && (!isPostRequestParameterSet('del')) && (!isPostRequestParameterSet('change')) && (!isPostRequestParameterSet('remove'))) { + if ((!isFormSent()) && (!isFormSent('edit')) && (!isFormSent('del')) && (!isFormSent('change')) && (!isFormSent('remove'))) { // Abort here loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_FORM_NOT_SENT')); return; @@ -132,71 +132,114 @@ function isNetworkRequestParameterValid ($key, $type, $networkId) { } // "Getter" for a network's data by provided id number -function getNetworkDataById ($id) { +function getNetworkDataById ($id, $column = '') { // Ids lower one are not accepted if ($id < 1) { // Not good, should be fixed debug_report_bug('Network id ' . $id . ' is smaller than 1.'); } // END - if - // By default we have no data - $networkData = array(); + // Is it cached? + if (!isset($GLOBALS['network_data'][$id])) { + // By default we have no data + $GLOBALS['network_data'][$id] = array(); - // Query for the network data - $result = SQL_QUERY_ESC("SELECT + // Query for the network data + $result = SQL_QUERY_ESC("SELECT `network_id`, `network_short_name`, `network_title`, `network_reflink`, `network_data_seperator`, `network_row_seperator`, `network_request_type`, `network_charset` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_id`=%s +LIMIT 1", + array(bigintval($id)), __FUNCTION__, __LINE__); + + // Do we have an entry? + if (SQL_NUMROWS($result) == 1) { + // Then get it + $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result); + } // END - if + + // Free result + SQL_FREERESULT($result); + } // END - if + + // Return result + if (empty($column)) { + // Return array + return $GLOBALS['network_data'][$id]; + } else { + // Return column + return $GLOBALS['network_data'][$id][$column]; + } +} + +// "Getter" for a network type data by provided id number +function getNetworkTypeDataById ($id) { + // Ids lower one are not accepted + if ($id < 1) { + // Not good, should be fixed + debug_report_bug('Network type id ' . $id . ' is smaller than 1.'); + } // END - if + + // By default we have no data + $GLOBALS['network_type_data'][$id] = array(); + + // Query for the network data + $result = SQL_QUERY_ESC("SELECT + `network_type_id`, `network_id`, `network_type_handle`, `network_type_api_url`, `network_type_click_url`, `network_type_banner_url` +FROM + `{?_MYSQL_PREFIX?}_network_types` +WHERE + `network_type_id`=%s LIMIT 1", array(bigintval($id)), __FUNCTION__, __LINE__); // Do we have an entry? if (SQL_NUMROWS($result) == 1) { // Then get it - $networkData = SQL_FETCHARRAY($result); + $GLOBALS['network_type_data'][$id] = SQL_FETCHARRAY($result); } // END - if // Free result SQL_FREERESULT($result); // Return result - return $networkData; + return $GLOBALS['network_type_data'][$id]; } -// "Getter" for a network type data by provided id number -function getNetworkTypeDataById ($id) { +// "Getter" for a network request parameter data by provided id number +function getNetworkRequestParamsDataById ($id) { // Ids lower one are not accepted if ($id < 1) { // Not good, should be fixed - debug_report_bug('Network type id ' . $id . ' is smaller than 1.'); + debug_report_bug('Network request parameter id ' . $id . ' is smaller than 1.'); } // END - if // By default we have no data - $networkTypeData = array(); + $networkRequestData = 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_param_id`, `network_id`, `network_type_id`, `request_param_key`, `request_param_value`, `request_param_default` FROM - `{?_MYSQL_PREFIX?}_network_types` + `{?_MYSQL_PREFIX?}_network_request_params` WHERE - `network_type_id`=%s + `network_param_id`=%s LIMIT 1", array(bigintval($id)), __FUNCTION__, __LINE__); // Do we have an entry? if (SQL_NUMROWS($result) == 1) { // Then get it - $networkTypeData = SQL_FETCHARRAY($result); + $networkRequestData = SQL_FETCHARRAY($result); } // END - if // Free result SQL_FREERESULT($result); // Return result - return $networkTypeData; + return $networkRequestData; } // Updates given network (id) with data from array @@ -223,6 +266,18 @@ function doNetworkUpdateTypeByArray ($id, $networkTypeData) { return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($id)), array(), false, false); } +// Updates given network request parameters (id) with data from array +function doNetworkUpdateParamsByArray ($id, $networkParamData) { + // Ids lower one are not accepted + if ($id < 1) { + // Not good, should be fixed + debug_report_bug('Network request parameter id ' . $id . ' is smaller than 1.'); + } // END - if + + // Just call our inner method + return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_param_id`=%s", bigintval($id)), array(), false, false); +} + // Removes given network entry function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) { // Remove the entry @@ -252,7 +307,10 @@ ORDER BY $rows = array(); while ($row = SQL_FETCHARRAY($result)) { // Is this valid, then add it - if ((is_array($row)) && (isset($row['network_id']))) $rows[] = $row; + if ((is_array($row)) && (isset($row['network_id']))) { + // Add entry + $rows[$row['network_id']] = $row; + } // END - if } // END - while // Generate the selection box @@ -269,6 +327,145 @@ ORDER BY return $content; } +// Generator (somewhat getter) for a list of network types for given network id +function generateAdminNetworkTypeList ($networkId) { + // Init content + $content = ''; + + // Query all types of this network + $result = SQL_QUERY_ESC("SELECT + `network_type_id`, `network_type_handle` +FROM + `{?_MYSQL_PREFIX?}_network_types` +WHERE + `network_id`=%s +ORDER BY + `network_type_handle` ASC", + array( + bigintval($networkId) + ), __FILE__, __LINE__); + + // Do we have entries? + if (SQL_NUMROWS($result) > 0) { + // List all entries + $rows = array(); + while ($row = SQL_FETCHARRAY($result)) { + // Is this valid, then add it + if ((is_array($row)) && (isset($row['network_type_id']))) { + // Add entry + $rows[$row['network_type_id']] = $row; + } // END - if + } // END - while + + // Generate the selection box + $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id'); + } else { + // Nothing selected + $content = loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_ENTRIES_404')); + } + + // Free the result + SQL_FREERESULT($result); + + // Return content + return $content; +} + +// Generator (somewhat getter) for network type options +function generateNetworkTypeOptions ($id) { + // Is this an array, then we just came back from edit/delete actions + if (is_array($id)) $id = ''; + + // Is this cached? + if (!isset($GLOBALS['network_type_options'][$id])) { + // Generate output and cache it + $GLOBALS['network_type_options'][$id] = generateOptionList( + 'network_types', + 'network_type_id', + 'network_type_handle', + $id, + '', + sprintf( + "WHERE `network_id`=%s", + bigintval(getRequestParameter('network')) + ) + ); + } // END - if + + // Return content + return $GLOBALS['network_type_options'][$id]; +} + +// Generator (somewhat getter) for request key options +function generateNetworkRequestKeyOptions ($key) { + // Is it cached? + if (!isset($GLOBALS['network_request_param_key'][$key])) { + // Generate and cache it + $GLOBALS['network_request_param_key'][$key] = generateOptionList( + '/ARRAY/', + array( + 'id', + 'sid', + 'hash', + 'password', + 'reload', + 'maximum_stay', + 'minimum_stay', + 'currency', + 'type', + 'remain', + 'reward', + 'size', + 'erotic', + 'extra' + ), + array( + '{--ADMIN_NETWORK_REQUEST_PARAMETER_ID--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_SID--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_HASH--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_PASSWORD--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_RELOAD--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_MAXIMUM_STAY--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_MINIMUM_STAY--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_CURRENCY--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_TYPE--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_REMAIN--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_REWARD--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_SIZE--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_EROTIC--}', + '{--ADMIN_NETWORK_REQUEST_PARAMETER_EXTRA--}' + ), + $key, + '', '', + $GLOBALS['network_params_disabled'] + ); + } // END - if + + // Return content + return $GLOBALS['network_request_param_key'][$key]; +} + +// Generator (somewhat getter) for (return) array translation +function generateNetworkArrayTranslationOptions ($default) { + // Is it cached? + if (!isset($GLOBALS['network_array_translation'][$default])) { + // Generate and cache it + $GLOBALS['network_array_translation'][$default] = generateOptionList( + 'network_request_params', + 'network_param_id', + 'request_param_key', + $default, + '', + sprintf("WHERE `network_id`='%s'", bigintval(getRequestParameter('network'))), + $GLOBALS['network_array_translation_disabled'], + 'ADMIN_NETWORK_REQUEST_PARAMETER_' + ); + } // END - if + + // Return content + return $GLOBALS['network_array_translation'][$default]; +} + //------------------------------------------------------------------------------ // Call-back functions //------------------------------------------------------------------------------ @@ -324,11 +521,14 @@ function doAdminNetworkProcessHandlenetworkForm () { // Add color $networkData['sw'] = $SW; - if (isPostRequestParameterSet('edit')) { + if (isFormSent('edit')) { // Make selection box for network_request_type $networkData['network_request_type'] = generateOptionList( '/ARRAY/', - array('GET','POST'), + array( + 'GET', + 'POST' + ), array( getMessage('ADMIN_NETWORK_REQUEST_TYPE_GET'), getMessage('ADMIN_NETWORK_REQUEST_TYPE_POST') @@ -338,7 +538,7 @@ function doAdminNetworkProcessHandlenetworkForm () { // Add row template for editing $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData); - } elseif (isPostRequestParameterSet('del')) { + } elseif (isFormSent('del')) { // Translate the request type $networkData['network_request_type'] = getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . $networkData['network_request_type']); @@ -358,9 +558,9 @@ function doAdminNetworkProcessHandlenetworkForm () { // If we have no rows, we don't need to display the edit form if (!empty($OUT)) { // Output main template - if (isPostRequestParameterSet('edit')) { + if (isFormSent('edit')) { loadTemplate('admin_edit_networks', false, $OUT); - } elseif (isPostRequestParameterSet('del')) { + } elseif (isFormSent('del')) { loadTemplate('admin_del_networks', false, $OUT); } else { // Problem! @@ -396,10 +596,10 @@ function doAdminNetworkProcessHandlenetworktypeForm () { // Add color $networkTypeData['sw'] = $SW; - if (isPostRequestParameterSet('edit')) { + if (isFormSent('edit')) { // Add row template for deleting $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData); - } elseif (isPostRequestParameterSet('del')) { + } elseif (isFormSent('del')) { // Fix empty banner URL if (trim($networkTypeData['network_type_banner_url']) == '') $networkTypeData['network_type_banner_url'] = '---'; @@ -420,14 +620,14 @@ function doAdminNetworkProcessHandlenetworktypeForm () { if (!empty($OUT)) { // Prepare content for template $content = array( - 'rows' => $OUT, + 'rows' => $OUT, 'network_data' => getNetworkDataById(getRequestParameter('network')) ); // Output main template - if (isPostRequestParameterSet('edit')) { + if (isFormSent('edit')) { loadTemplate('admin_edit_network_types', false, $content); - } elseif (isPostRequestParameterSet('del')) { + } elseif (isFormSent('del')) { loadTemplate('admin_del_network_types', false, $content); } else { // Problem! @@ -443,6 +643,85 @@ function doAdminNetworkProcessHandlenetworktypeForm () { } // END - if } +// Handle network request parameter form +function doAdminNetworkProcessHandlerequestparamsForm () { + // Do we have selections? + if (countPostSelection() > 0) { + // Init cache array + $GLOBALS['network_params_disabled'] = array(); + + // Load network data + $networkData = getNetworkDataById(getRequestParameter('network')); + + // Something has been selected, so start displaying one by one + $SW = 2; $OUT = ''; + foreach (postRequestParameter('sel') as $id => $sel) { + // Is this selected? + if ($sel == 1) { + // Load this network's data + $networkRequestData = getNetworkRequestParamsDataById($id); + + // Do we have found the network? + if (count($networkRequestData) > 0) { + // Add color + $networkRequestData['sw'] = $SW; + + if (isFormSent('edit')) { + // Add options list for network type + $networkRequestData['type_options'] = generateNetworkTypeOptions($networkRequestData['network_type_id']); + + // Add options list for request key + $networkRequestData['key_options'] = generateNetworkRequestKeyOptions($networkRequestData['request_param_key']); + + // Add row template for deleting + $OUT .= loadTemplate('admin_edit_network_params_row', true, $networkRequestData); + } elseif (isFormSent('del')) { + // Fix empty banner URL + if (trim($networkRequestData['request_param_default']) == '') $networkRequestData['request_param_default'] = '---'; + + // Get type data + $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']); + + // Add row template for deleting + $OUT .= loadTemplate('admin_del_network_params_row', true, $networkRequestData); + } else { + // Problem! + debug_report_bug('Cannot detect edit/del.'); + } + + // Switch colors + $SW = 3 - $SW; + } // END - if + } // END - if + } // END - foreach + + // If we have no rows, we don't need to display the edit form + if (!empty($OUT)) { + // Prepare content for template + $content = array( + 'rows' => $OUT, + 'network_data' => getNetworkDataById(getRequestParameter('network')) + ); + + // Output main template + if (isFormSent('edit')) { + loadTemplate('admin_edit_network_params', false, $content); + } elseif (isFormSent('del')) { + loadTemplate('admin_del_network_params', false, $content); + } else { + // Problem! + debug_report_bug('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, getMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND')); + } + } // END - if +} + // Changes given networks function doAdminNetworkProcessChangenetworkForm () { // Do we have selections? @@ -530,7 +809,7 @@ function doAdminNetworkProcessAddnetworktypeForm () { unsetPostRequestParameter('ok'); // Add id - setPostRequestParameter('network_id', getRequestParameter('network')); + setPostRequestParameter('network_id', bigintval(getRequestParameter('network'))); // Is network_type_banner_url set? if (postRequestParameter('network_type_banner_url') == '') { @@ -582,6 +861,12 @@ function doAdminNetworkProcessChangenetworktypeForm () { debug_report_bug('No entry in key=' . $key . ', id=' . $id . ' found.'); } // END - if + // Fix empty network_type_banner_url to NULL + if (($key == 'network_type_banner_url') && (trim($entry[$id]) == '')) { + // Set it to NULL + $entry[$id] = null; + } // END - if + // Add this entry $networkTypeData[$key] = $entry[$id]; } // END - foreach @@ -602,6 +887,57 @@ function doAdminNetworkProcessChangenetworktypeForm () { } // END - if } +// Changes given network request parameters +function doAdminNetworkProcessChangenetworkparamForm () { + // Do we have selections? + if (countPostSelection() > 0) { + // By default nothing is updated + $updated = 0; + + // Something has been selected, so start updating them + foreach (postRequestParameter('sel') as $id => $sel) { + // Update this entry? + if ($sel == 1) { + // Init data array + $networkParamsData = array(); + + // Transfer whole array, except 'sel' + foreach (postRequestArray() as $key => $entry) { + // Skip 'sel' and submit button + if (in_array($key, array('sel', 'change'))) continue; + + // Do we have this enty? + if (!isset($entry[$id])) { + // Not found, needs fixing + debug_report_bug('No entry in key=' . $key . ', id=' . $id . ' found.'); + } // END - if + + // Fix empty request_param_default to NULL + if (($key == 'request_param_default') && (trim($entry[$id]) == '')) { + // Set it to NULL + $entry[$id] = null; + } // END - if + + // Add this entry + $networkParamsData[$key] = $entry[$id]; + } // END - foreach + + // Update the network data + $updated += doNetworkUpdateParamsByArray($id, $networkParamsData); + } // END - if + } // END - foreach + + // Do we have updates? + if ($updated > 0) { + // Updates done + loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED', $updated)); + } else { + // Nothing changed + loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED')); + } + } // END - if +} + // Removes given network type handlers function doAdminNetworkProcessRemovenetworktypeForm () { // Do we have selections? @@ -629,6 +965,33 @@ function doAdminNetworkProcessRemovenetworktypeForm () { } // END - if } +// Removes given network request parameters +function doAdminNetworkProcessRemovenetworkparamForm () { + // Do we have selections? + if (countPostSelection() > 0) { + // By default nothing is removed + $removed = 0; + + // Something has been selected, so start updating them + foreach (postRequestParameter('sel') as $id => $sel) { + // Update this entry? + if ($sel == 1) { + // Remove this entry + $removed += doAdminRemoveNetworkEntry('request_params', 'network_param_id', $id); + } // END - if + } // END - foreach + + // Do we have removes? + if ($removed > 0) { + // Removals done + loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED', $removed)); + } else { + // Nothing removed + loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED')); + } + } // END - if +} + // Adds a request parameter to given network and type function doAdminNetworkProcessAddnetworkparamForm () { // Is the request parameter already used with given network? @@ -644,7 +1007,7 @@ function doAdminNetworkProcessAddnetworkparamForm () { unsetPostRequestParameter('ok'); // Add id - setPostRequestParameter('network_id', getRequestParameter('network')); + setPostRequestParameter('network_id', bigintval(getRequestParameter('network'))); // Is request_param_default set? if (postRequestParameter('request_param_default') == '') { @@ -671,5 +1034,22 @@ function doAdminNetworkProcessAddnetworkparamForm () { } } +// Do expression code for this extension +function doExpressionNetwork ($data) { + // Construct replacer + $replacer = sprintf( + "\" . %s(%s, '%s') . \"", + $data['callback'], + $data['matches'][4][$data['key']], + $data['extra_func'] + ); + + // Replace the code + $code = replaceExpressionCode($data, $replacer); + + // Return it + return $code; +} + // [EOF] ?>