X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Fnetwork_functions.php;h=89392f1e1c73828748d25da4b3d631d77c3c8357;hb=f298f71846512b05d8eed6c03771253e2c39655f;hp=8220abf5c184426331081c1781955d64759300db;hpb=18e32f1a8971b18bace4f051094acf27800bd7d9;p=mailer.git diff --git a/inc/libs/network_functions.php b/inc/libs/network_functions.php index 8220abf5c1..89392f1e1c 100644 --- a/inc/libs/network_functions.php +++ b/inc/libs/network_functions.php @@ -42,6 +42,16 @@ if (!defined('__SECURITY')) { die(); } // END - if +// Private setter for current network id +function setCurrentNetworkId ($id) { + $GLOBALS['current_network_id'] = bigintval($id); +} + +// Private getter for current network id +function getCurrentNetworkId () { + return $GLOBALS['current_network_id']; +} + // Handle a (maybe) sent form here function doNetworkHandleForm () { // Was the form sent? @@ -52,7 +62,7 @@ function doNetworkHandleForm () { doAdminNetworkProcessForm(); } else { // No 'do' found - loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_DO_404')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}'); } } // END - if } @@ -62,21 +72,21 @@ function doAdminNetworkProcessForm () { // Form really sent? if ((!isFormSent()) && (!isFormSent('edit')) && (!isFormSent('del')) && (!isFormSent('change')) && (!isFormSent('remove'))) { // Abort here - loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_FORM_NOT_SENT')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_FORM_NOT_SENT--}'); return; } elseif (!isGetRequestParameterSet('do')) { // No 'do' found - loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_DO_404')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_DO_404--}'); return; } // Create function name - $functionName = sprintf("doAdminNetworkProcess%sForm", ucfirst(strtolower(getRequestParameter('do')))); + $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(getRequestParameter('do'))); // Is the function valid? if (!function_exists($functionName)) { // Invalid function name - debug_report_bug('Invalid do ' . getRequestParameter('do') . ', function ' . $functionName .' does not exist.', false); + debug_report_bug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestParameter('do') . ', function ' . $functionName .' does not exist.', false); } // END - if // Call-back the method handling our request @@ -131,40 +141,117 @@ function isNetworkRequestParameterValid ($key, $type, $networkId) { return $isValid; } +// Checks wether the given network API array translation +function isNetworkApiTranslationValid ($key, $type, $networkId) { + // Query for it + $result = SQL_QUERY_ESC("SELECT `network_api_id` FROM `{?_MYSQL_PREFIX?}_network_api_translation` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_api_index`='%s' LIMIT 1", + array($networkId, $type, $key), __FUNCTION__, __LINE__); + + // Does it exist? + $isValid = (SQL_NUMROWS($result) == 1); + + // Free result + SQL_FREERESULT($result); + + // Return result + return $isValid; +} + // "Getter" for a network's data by provided id number -function getNetworkDataById ($id) { +function getNetworkDataById ($id, $column = '') { // Ids lower one are not accepted if ($id < 1) { // Not good, should be fixed - debug_report_bug('Network id ' . $id . ' is smaller than 1.'); + debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.'); } // END - if - // By default we have no data - $networkData = array(); + // Set current network id + setCurrentNetworkId($id); - // Query for the network data - $result = SQL_QUERY_ESC("SELECT + // Is it cached? + if (!isset($GLOBALS['network_data'][$id])) { + // By default we have no data + $GLOBALS['network_data'][$id] = array(); + + // Query for the network data + $result = SQL_QUERY_ESC("SELECT `network_id`, `network_short_name`, `network_title`, `network_reflink`, `network_data_seperator`, `network_row_seperator`, `network_request_type`, `network_charset` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_id`=%s LIMIT 1", - array(bigintval($id)), __FUNCTION__, __LINE__); + array(bigintval($id)), __FUNCTION__, __LINE__); - // Do we have an entry? - if (SQL_NUMROWS($result) == 1) { - // Then get it - $networkData = SQL_FETCHARRAY($result); + // Do we have an entry? + if (SQL_NUMROWS($result) == 1) { + // Then get it + $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result); + } // END - if - // Solve disabled + // Free result + SQL_FREERESULT($result); } // END - if - // Free result - SQL_FREERESULT($result); + // Return result + if (empty($column)) { + // Return array + return $GLOBALS['network_data'][$id]; + } else { + // Return column + return $GLOBALS['network_data'][$id][$column]; + } +} + +// "Getter" for a network's data by provided type id number +function getNetworkDataByTypeId ($id, $column = '') { + // Ids lower one are not accepted + if ($id < 1) { + // Not good, should be fixed + debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.'); + } // END - if + + // Set current network id + setCurrentNetworkId($id); + + // Is it cached? + if (!isset($GLOBALS['network_data'][$id])) { + // By default we have no data + $GLOBALS['network_data'][$id] = array(); + + // Query for the network data + $result = SQL_QUERY_ESC("SELECT + d.`network_id`, d.`network_short_name`, d.`network_title`, d.`network_reflink`, d.`network_data_seperator`, d.`network_row_seperator`, d.`network_request_type`, d.`network_charset`, + t.`network_type_handle`, t.`network_type_api_url`, t.`network_type_click_url`, t.`network_type_banner_url` +FROM + `{?_MYSQL_PREFIX?}_network_data` AS d +LEFT JOIN + `{?_MYSQL_PREFIX?}_network_types` AS t +ON + d.`network_id`=t.`network_id` +WHERE + t.`network_type_id`=%s +LIMIT 1", + array(bigintval($id)), __FUNCTION__, __LINE__); + + // Do we have an entry? + if (SQL_NUMROWS($result) == 1) { + // Then get it + $GLOBALS['network_data'][$id] = SQL_FETCHARRAY($result); + } // END - if + + // Free result + SQL_FREERESULT($result); + } // END - if // Return result - return $networkData; + 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 @@ -172,11 +259,11 @@ 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.'); + debug_report_bug(__FUNCTION__, __LINE__, 'Network type id ' . $id . ' is smaller than 1.'); } // END - if // By default we have no data - $networkTypeData = array(); + $GLOBALS['network_type_data'][$id] = array(); // Query for the network data $result = SQL_QUERY_ESC("SELECT @@ -191,14 +278,14 @@ LIMIT 1", // Do we have an entry? if (SQL_NUMROWS($result) == 1) { // Then get it - $networkTypeData = SQL_FETCHARRAY($result); + $GLOBALS['network_type_data'][$id] = SQL_FETCHARRAY($result); } // END - if // Free result SQL_FREERESULT($result); // Return result - return $networkTypeData; + return $GLOBALS['network_type_data'][$id]; } // "Getter" for a network request parameter data by provided id number @@ -206,7 +293,7 @@ function getNetworkRequestParamsDataById ($id) { // 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.'); + debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.'); } // END - if // By default we have no data @@ -240,7 +327,7 @@ function doNetworkUpdateDataByArray ($id, $networkData) { // Ids lower one are not accepted if ($id < 1) { // Not good, should be fixed - debug_report_bug('Network id ' . $id . ' is smaller than 1.'); + debug_report_bug(__FUNCTION__, __LINE__, 'Network id ' . $id . ' is smaller than 1.'); } // END - if // Just call our inner method @@ -252,7 +339,7 @@ function doNetworkUpdateTypeByArray ($id, $networkTypeData) { // Ids lower one are not accepted if ($id < 1) { // Not good, should be fixed - debug_report_bug('Network type handler id ' . $id . ' is smaller than 1.'); + debug_report_bug(__FUNCTION__, __LINE__, 'Network type handler id ' . $id . ' is smaller than 1.'); } // END - if // Just call our inner method @@ -264,7 +351,7 @@ 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.'); + debug_report_bug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $id . ' is smaller than 1.'); } // END - if // Just call our inner method @@ -275,7 +362,7 @@ function doNetworkUpdateParamsByArray ($id, $networkParamData) { function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) { // Remove the entry SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s", - array($table, $column, $id, $limit), __FILE__, __LINE__); + array($table, $column, $id, $limit), __FUNCTION__, __LINE__); // Return affected rows return SQL_AFFECTEDROWS(); @@ -287,27 +374,30 @@ function generateAdminNetworkList () { $content = ''; // Query for all networks - $result = SQL_QUERY("SELECT + $result = SQL_QUERY('SELECT `network_id`, `network_short_name`, `network_title` FROM `{?_MYSQL_PREFIX?}_network_data` ORDER BY - `network_short_name` ASC", __FILE__, __LINE__); + `network_short_name` ASC', __FUNCTION__, __LINE__); // Do we have entries? - if (SQL_NUMROWS($result) > 0) { + if (!SQL_HASZERONUMS($result)) { // List all entries $rows = array(); while ($row = SQL_FETCHARRAY($result)) { // Is this valid, then add it - if ((is_array($row)) && (isset($row['network_id']))) $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 $content = generateSelectionBoxFromArray($rows, 'network', 'network_id'); } else { // Nothing selected - $content = loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_ENTRIES_404')); + $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}'); } // Free the result @@ -317,6 +407,95 @@ 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) + ), __FUNCTION__, __LINE__); + + // Do we have entries? + if (!SQL_HASZERONUMS($result)) { + // List all entries + $rows = array(); + while ($row = SQL_FETCHARRAY($result)) { + // Is this valid, then add it + if ((is_array($row)) && (isset($row['network_type_id']))) { + // Add entry + $rows[$row['network_type_id']] = $row; + } // END - if + } // END - while + + // Generate the selection box + $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id'); + } else { + // Nothing selected + $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}'); + } + + // Free the result + SQL_FREERESULT($result); + + // Return content + return $content; +} + +// Generator (somewhat getter) for a list of network types for all types +function generateAdminDistinctNetworkTypeList () { + // Init content + $content = ''; + + // Query all types of this network + $result = SQL_QUERY('SELECT + t.`network_type_id`, t.`network_type_handle`, d.`network_title` +FROM + `{?_MYSQL_PREFIX?}_network_types` AS t +LEFT JOIN + `{?_MYSQL_PREFIX?}_network_data` AS d +ON + t.`network_id`=d.`network_id` +ORDER BY + d.`network_short_name` ASC, + t.`network_type_handle` ASC', __FUNCTION__, __LINE__); + + // Do we have entries? + if (!SQL_HASZERONUMS($result)) { + // List all entries + $rows = array(); + while ($row = SQL_FETCHARRAY($result)) { + // Is this valid, then add it + if ((is_array($row)) && (isset($row['network_type_id']))) { + // Add entry + $rows[$row['network_type_id']] = $row; + } // END - if + } // END - while + + // Generate the selection box + $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title'); + } else { + // Nothing selected + $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}'); + } + + // Free the result + SQL_FREERESULT($result); + //* DEBUG: */ die('
'.encodeEntities($content).'
'); + + // 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 @@ -331,7 +510,12 @@ function generateNetworkTypeOptions ($id) { 'network_type_handle', $id, '', - sprintf("WHERE `network_id`=%s", getRequestParameter('network')) + sprintf( + "WHERE `network_id`=%s", + bigintval(getRequestParameter('network')) + ), + '', + 'translateNetworkTypeHandler' ); } // END - if @@ -352,8 +536,8 @@ function generateNetworkRequestKeyOptions ($key) { 'hash', 'password', 'reload', - 'max_stay', - 'min_stay', + 'maximum_stay', + 'minimum_stay', 'currency', 'type', 'remain', @@ -363,20 +547,20 @@ function generateNetworkRequestKeyOptions ($key) { 'extra' ), array( - '{--ADMIN_NETWORK_REQUEST_PARAMS_ID--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_SID--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_HASH--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_PASSWORD--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_RELOAD--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_MAXIMUM_STAY--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_MINIMUM_STAY--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_CURRENCY--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_TYPE--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_REMAIN--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_REWARD--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_SIZE--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_EROTIC--}', - '{--ADMIN_NETWORK_REQUEST_PARAMS_EXTRA--}' + '{--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, '', '', @@ -388,12 +572,74 @@ function generateNetworkRequestKeyOptions ($key) { return $GLOBALS['network_request_param_key'][$key]; } +// Generator (somewhat getter) for (return) array translation +function generateNetworkTranslationOptions ($default = '') { + // Is it cached? + if (!isset($GLOBALS['network_translation'][$default])) { + // Generate and cache it + $GLOBALS['network_translation'][$default] = generateOptionList( + 'network_translations', + 'network_translation_id', + 'network_translation_name', + $default, + '', + '', + $GLOBALS['network_translation_disabled'], + 'translateNetworkTranslationName' + ); + } // END - if + + // Return content + return $GLOBALS['network_translation'][$default]; +} + +// Generates an option list of request types +function generateNetworkRequestTypeOptions ($default = '') { + // Do we have cache? + if (!isset($GLOBALS['network_request_type'][$default])) { + // Generate the list + $GLOBALS['network_request_type'][$default] = generateOptionList( + '/ARRAY/', + array( + 'GET', + 'POST' + ), + array( + '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}', + '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}' + ), + $default + ); + } // END - if + + // Return cache + return $GLOBALS['network_request_type'][$default]; +} + +// Translates 'translate_name' for e.g. templates +function translateNetworkTranslationName ($name) { + // Get the message id + return getMessage('ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME'); +} + +// Translates the network type handler (e.g. banner, paidmail) for templates +function translateNetworkTypeHandler ($type) { + // Get the message id + return getMessage('ADMIN_NETWORK_TYPES_' . strtoupper($type) . ''); +} + +// Translates request type +function translateNetworkRequestType ($name) { + // Get the message id + return getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($name) . ''); +} + //------------------------------------------------------------------------------ // Call-back functions //------------------------------------------------------------------------------ // 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(postRequestParameter('network_short_name'))) { // Already there @@ -405,10 +651,10 @@ function doAdminNetworkProcessAddnetworkForm () { unsetPostRequestParameter('ok'); // Add the whole request to database - SQL_QUERY("INSERT INTO + SQL_QUERY('INSERT INTO `{?_MYSQL_PREFIX?}_network_data` ( - `" . implode('`,`', array_keys(postRequestArray())) . "` + `' . implode('`,`', array_keys(postRequestArray())) . "` ) VALUES ( '" . implode("','", array_values(postRequestArray())) . "' )", __FUNCTION__, __LINE__); @@ -427,11 +673,11 @@ function doAdminNetworkProcessAddnetworkForm () { } // 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 = ''; + $OUT = ''; foreach (postRequestParameter('sel') as $id => $sel) { // Is this selected? if ($sel == 1) { @@ -440,36 +686,16 @@ function doAdminNetworkProcessHandlenetworkForm () { // Do we have found the network? if (count($networkData) > 0) { - // Add color - $networkData['sw'] = $SW; - if (isFormSent('edit')) { - // Make selection box for network_request_type - $networkData['network_request_type'] = generateOptionList( - '/ARRAY/', - array('GET','POST'), - array( - getMessage('ADMIN_NETWORK_REQUEST_TYPE_GET'), - getMessage('ADMIN_NETWORK_REQUEST_TYPE_POST') - ), - $networkData['network_request_type'] - ); - // Add row template for editing $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData); } elseif (isFormSent('del')) { - // Translate the request type - $networkData['network_request_type'] = getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . $networkData['network_request_type']); - // Add row template for deleting $OUT .= loadTemplate('admin_del_networks_row', true, $networkData); } else { // Problem! - debug_report_bug('Cannot detect edit/del.'); + debug_report_bug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.'); } - - // Switch colors - $SW = 3 - $SW; } // END - if } // END - if } // END - foreach @@ -483,27 +709,27 @@ function doAdminNetworkProcessHandlenetworkForm () { loadTemplate('admin_del_networks', false, $OUT); } else { // Problem! - debug_report_bug('Cannot detect edit/del.'); + 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, getMessage('ADMIN_NETWORK_NOTHING_FOUND')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}'); } } // END - if } // Handle network type form -function doAdminNetworkProcessHandlenetworktypeForm () { +function doAdminNetworkProcessHandleNetworkType () { // Do we have selections? - if (countPostSelection() > 0) { + if (ifPostContainsSelections()) { // Load network data $networkData = getNetworkDataById(getRequestParameter('network')); // Something has been selected, so start displaying one by one - $SW = 2; $OUT = ''; + $OUT = ''; foreach (postRequestParameter('sel') as $id => $sel) { // Is this selected? if ($sel == 1) { @@ -512,60 +738,45 @@ function doAdminNetworkProcessHandlenetworktypeForm () { // Do we have found the network? if (count($networkTypeData) > 0) { - // Add color - $networkTypeData['sw'] = $SW; - if (isFormSent('edit')) { // Add row template for deleting $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData); } elseif (isFormSent('del')) { - // Fix empty banner URL - if (trim($networkTypeData['network_type_banner_url']) == '') $networkTypeData['network_type_banner_url'] = '---'; - // Add row template for deleting $OUT .= loadTemplate('admin_del_network_types_row', true, $networkTypeData); } else { // Problem! - debug_report_bug('Cannot detect edit/del.'); + debug_report_bug(__FUNCTION__, __LINE__, '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_types', false, $content); + loadTemplate('admin_edit_network_types', false, $OUT); } elseif (isFormSent('del')) { - loadTemplate('admin_del_network_types', false, $content); + loadTemplate('admin_del_network_types', false, $OUT); } else { // Problem! - debug_report_bug('Cannot detect edit/del.'); + 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, getMessage('ADMIN_NETWORK_TYPES_NOTHING_FOUND')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_FOUND--}'); } } // END - if } // Handle network request parameter form -function doAdminNetworkProcessHandlerequestparamsForm () { +function doAdminNetworkProcessHandleRequestParams () { // Do we have selections? - if (countPostSelection() > 0) { + if (ifPostContainsSelections()) { // Init cache array $GLOBALS['network_params_disabled'] = array(); @@ -573,7 +784,7 @@ function doAdminNetworkProcessHandlerequestparamsForm () { $networkData = getNetworkDataById(getRequestParameter('network')); // Something has been selected, so start displaying one by one - $SW = 2; $OUT = ''; + $OUT = ''; foreach (postRequestParameter('sel') as $id => $sel) { // Is this selected? if ($sel == 1) { @@ -582,22 +793,10 @@ function doAdminNetworkProcessHandlerequestparamsForm () { // 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']); @@ -605,46 +804,37 @@ function doAdminNetworkProcessHandlerequestparamsForm () { $OUT .= loadTemplate('admin_del_network_params_row', true, $networkRequestData); } else { // Problem! - debug_report_bug('Cannot detect edit/del.'); + debug_report_bug(__FUNCTION__, __LINE__, '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); + loadTemplate('admin_edit_network_params', false, $OUT); } elseif (isFormSent('del')) { - loadTemplate('admin_del_network_params', false, $content); + loadTemplate('admin_del_network_params', false, $OUT); } else { // Problem! - debug_report_bug('Cannot detect edit/del.'); + 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, getMessage('ADMIN_NETWORK_REQUEST_PARAMS_NOTHING_FOUND')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}'); } } // END - if } // Changes given networks -function doAdminNetworkProcessChangenetworkForm () { +function doAdminNetworkProcessChangeNetwork () { // Do we have selections? - if (countPostSelection() > 0) { + if (ifPostContainsSelections()) { // By default nothing is updated $updated = 0; @@ -663,7 +853,7 @@ function doAdminNetworkProcessChangenetworkForm () { // Do we have this enty? if (!isset($entry[$id])) { // Not found, needs fixing - debug_report_bug('No entry in key=' . $key . ', id=' . $id . ' found.'); + debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.'); } // END - if // Add this entry @@ -681,15 +871,15 @@ function doAdminNetworkProcessChangenetworkForm () { loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_UPDATED', $updated)); } else { // Nothing changed - loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_NOTHING_CHANGED')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}'); } } // END - if } // Removes given networks -function doAdminNetworkProcessRemovenetworkForm () { +function doAdminNetworkProcessRemoveNetwork () { // Do we have selections? - if (countPostSelection() > 0) { + if (ifPostContainsSelections()) { // By default nothing is removed $removed = 0; @@ -708,13 +898,13 @@ function doAdminNetworkProcessRemovenetworkForm () { loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REMOVED', $removed)); } else { // Nothing removed - loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_NOTHING_REMOVED')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}'); } } // END - if } // Add a network type handler if not yet found -function doAdminNetworkProcessAddnetworktypeForm () { +function doAdminNetworkProcessAddNetworkType () { // Is the network type handle already used with given network? if (isNetworkTypeHandleValid(postRequestParameter('network_type_handle'), getRequestParameter('network'))) { // Already added @@ -728,7 +918,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') == '') { @@ -737,10 +927,10 @@ function doAdminNetworkProcessAddnetworktypeForm () { } // END - if // Add the whole request to database - SQL_QUERY("INSERT INTO + SQL_QUERY('INSERT INTO `{?_MYSQL_PREFIX?}_network_types` ( - `" . implode('`,`', array_keys(postRequestArray())) . "` + `' . implode('`,`', array_keys(postRequestArray())) . "` ) VALUES ( '" . implode("','", array_values(postRequestArray())) . "' )", __FUNCTION__, __LINE__); @@ -756,9 +946,9 @@ function doAdminNetworkProcessAddnetworktypeForm () { } // Changes given network type handlers -function doAdminNetworkProcessChangenetworktypeForm () { +function doAdminNetworkProcessChangeNetworkType () { // Do we have selections? - if (countPostSelection() > 0) { + if (ifPostContainsSelections()) { // By default nothing is updated $updated = 0; @@ -777,7 +967,7 @@ function doAdminNetworkProcessChangenetworktypeForm () { // Do we have this enty? if (!isset($entry[$id])) { // Not found, needs fixing - debug_report_bug('No entry in key=' . $key . ', id=' . $id . ' found.'); + debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.'); } // END - if // Fix empty network_type_banner_url to NULL @@ -801,15 +991,15 @@ function doAdminNetworkProcessChangenetworktypeForm () { loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_UPDATED', $updated)); } else { // Nothing changed - loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_CHANGED')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_CHANGED--}'); } } // END - if } // Changes given network request parameters -function doAdminNetworkProcessChangenetworkparamForm () { +function doAdminNetworkProcessChangeNetworkParam () { // Do we have selections? - if (countPostSelection() > 0) { + if (ifPostContainsSelections()) { // By default nothing is updated $updated = 0; @@ -828,7 +1018,7 @@ function doAdminNetworkProcessChangenetworkparamForm () { // Do we have this enty? if (!isset($entry[$id])) { // Not found, needs fixing - debug_report_bug('No entry in key=' . $key . ', id=' . $id . ' found.'); + debug_report_bug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $id . ' found.'); } // END - if // Fix empty request_param_default to NULL @@ -849,18 +1039,18 @@ function doAdminNetworkProcessChangenetworkparamForm () { // Do we have updates? if ($updated > 0) { // Updates done - loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMS_UPDATED', $updated)); + loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED', $updated)); } else { // Nothing changed - loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_REQUEST_PARAMS_NOTHING_CHANGED')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}'); } } // END - if } // Removes given network type handlers -function doAdminNetworkProcessRemovenetworktypeForm () { +function doAdminNetworkProcessRemoveNetworkType () { // Do we have selections? - if (countPostSelection() > 0) { + if (ifPostContainsSelections()) { // By default nothing is removed $removed = 0; @@ -879,15 +1069,15 @@ function doAdminNetworkProcessRemovenetworktypeForm () { loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_REMOVED', $removed)); } else { // Nothing removed - loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_REMOVED')); + loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPES_NOTHING_REMOVED--}'); } } // END - if } // Removes given network request parameters -function doAdminNetworkProcessRemovenetworkparamForm () { +function doAdminNetworkProcessRemoveNetworkParam () { // Do we have selections? - if (countPostSelection() > 0) { + if (ifPostContainsSelections()) { // By default nothing is removed $removed = 0; @@ -903,16 +1093,16 @@ function doAdminNetworkProcessRemovenetworkparamForm () { // Do we have removes? if ($removed > 0) { // Removals done - loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMS_REMOVED', $removed)); + loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED', $removed)); } else { // Nothing removed - loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_REQUEST_PARAMS_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 doAdminNetworkProcessAddnetworkparamForm () { +function doAdminNetworkProcessAddNetworkParam () { // Is the request parameter already used with given network? if (isNetworkRequestParameterValid(postRequestParameter('request_param_key'), postRequestParameter('network_type_id'), getRequestParameter('network'))) { // Already added @@ -926,7 +1116,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') == '') { @@ -935,10 +1125,10 @@ function doAdminNetworkProcessAddnetworkparamForm () { } // END - if // Add the whole request to database - SQL_QUERY("INSERT INTO + SQL_QUERY('INSERT INTO `{?_MYSQL_PREFIX?}_network_request_params` ( - `" . implode('`,`', array_keys(postRequestArray())) . "` + `' . implode('`,`', array_keys(postRequestArray())) . "` ) VALUES ( '" . implode("','", array_values(postRequestArray())) . "' )", __FUNCTION__, __LINE__); @@ -953,5 +1143,61 @@ function doAdminNetworkProcessAddnetworkparamForm () { } } +// Adds a API response array entry +function doAdminNetworkProcessAddNetworkApiTranslation () { + // Is the request parameter already used with given network? + if (isNetworkApiTranslationValid(postRequestParameter('network_api_index'), postRequestParameter('network_type_id'), getRequestParameter('network'))) { + // Already added + loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_API_TRANSLATION_ALREADY_ADDED', postRequestParameter('request_param_key'))); + + // ... so abort here + return false; + } // END - if + + // Remove the 'ok' part + unsetPostRequestParameter('ok'); + + // Add id + setPostRequestParameter('network_id', bigintval(getRequestParameter('network'))); + + // Add the whole request to database + SQL_QUERY('INSERT INTO + `{?_MYSQL_PREFIX?}_network_api_translation` +( + `' . implode('`,`', array_keys(postRequestArray())) . "` +) VALUES ( + '" . implode("','", array_values(postRequestArray())) . "' +)", __FUNCTION__, __LINE__); + + // Output message + if (SQL_AFFECTEDROWS() == 1) { + // Successfully added + loadTemplate('admin_network_api_translation_added', false, postRequestArray()); + } else { + // Not added + loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_API_TRANSLATION_NOT_ADDED', postRequestParameter('network_api_index'))); + } +} + +// Do expression code for this extension +function doExpressionNetwork ($data) { + // Construct replacer + $replacer = sprintf( + "{DQUOTE} . %s(%s, '%s') . {DQUOTE}", + $data['callback'], + $data['matches'][4][$data['key']], + $data['extra_func'] + ); + + // Replace %network% with the current network id + $replacer = str_replace('%network%', getCurrentNetworkId(), $replacer); + + // Replace the code + $code = replaceExpressionCode($data, $replacer); + + // Return it + return $code; +} // [EOF] ?> +