* -------------------------------------------------------------------- *
* Kurzbeschreibung : Funktionen fuer ext-network *
* -------------------------------------------------------------------- *
- * $Revision:: 1194 $ *
- * $Date:: 2009-10-27 18:24:18 +0100 (Tue, 27 Oct 2009) $ *
+ * $Revision:: $ *
+ * $Date:: $ *
* $Tag:: 0.2.1-FINAL $ *
- * $Author:: quix0r $ *
+ * $Author:: $ *
* Needs to be in all Files and every File needs "svn propset *
* svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
* -------------------------------------------------------------------- *
die();
} // END - if
+// Handle a (maybe) sent form here
+function doNetworkHandleForm () {
+ // Was the form sent?
+ if ((isFormSent()) || (isPostRequestParameterSet('edit')) || (isPostRequestParameterSet('del')) || (isPostRequestParameterSet('change')) || (isPostRequestParameterSet('remove'))) {
+ // Do we have a 'do'?
+ if (isGetRequestParameterSet('do')) {
+ // Process the request
+ doAdminNetworkProcessForm();
+ } else {
+ // No 'do' found
+ loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_DO_404'));
+ }
+ } // END - if
+}
+
// Processes an admin form
function doAdminNetworkProcessForm () {
// Form really sent?
- if ((!isFormSent()) && (!isPostRequestElementSet('edit')) && (!isPostRequestElementSet('del')) && (!isPostRequestElementSet('change')) && (!isPostRequestElementSet('remove'))) {
+ if ((!isFormSent()) && (!isPostRequestParameterSet('edit')) && (!isPostRequestParameterSet('del')) && (!isPostRequestParameterSet('change')) && (!isPostRequestParameterSet('remove'))) {
// Abort here
loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_FORM_NOT_SENT'));
return;
- } elseif (!isGetRequestElementSet('do')) {
+ } elseif (!isGetRequestParameterSet('do')) {
// No 'do' found
loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_DO_404'));
return;
}
// Create function name
- $functionName = sprintf("doAdminNetworkProcess%sForm", ucfirst(strtolower(getRequestElement('do'))));
+ $functionName = sprintf("doAdminNetworkProcess%sForm", ucfirst(strtolower(getRequestParameter('do'))));
// Is the function valid?
if (!function_exists($functionName)) {
// Invalid function name
- debug_report_bug('Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.');
+ debug_report_bug('Invalid do ' . getRequestParameter('do') . ', function ' . $functionName .' does not exist.', false);
} // END - if
// Call-back the method handling our request
return $isValid;
}
+// Checks wether the given network type is already used (valid)
+function isNetworkTypeHandleValid ($type, $networkId) {
+ // Query for it
+ $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handle`='%s' LIMIT 1",
+ array($networkId, $type), __FUNCTION__, __LINE__);
+
+ // Does it exist?
+ $isValid = (SQL_NUMROWS($result) == 1);
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return result
+ return $isValid;
+}
+
+// Checks wether the given network request parameter is already used (valid)
+function isNetworkRequestParameterValid ($key, $type, $networkId) {
+ // Query for it
+ $result = SQL_QUERY_ESC("SELECT `network_param_id` FROM `{?_MYSQL_PREFIX?}_network_request_params` WHERE `network_id`=%s AND `network_type_id`=%s AND `request_param_key`='%s' LIMIT 1",
+ 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) {
// Ids lower one are not accepted
return $networkData;
}
+// "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
+ $networkTypeData = 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
+ $networkTypeData = SQL_FETCHARRAY($result);
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return result
+ return $networkTypeData;
+}
+
// Updates given network (id) with data from array
function doNetworkUpdateDataByArray ($id, $networkData) {
// Ids lower one are not accepted
return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($id)), array(), false, false);
}
+// Updates given network type handler (id) with data from array
+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.');
+ } // END - if
+
+ // Just call our inner method
+ return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($id)), array(), false, false);
+}
+
+// Removes given network entry
+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__);
+
+ // Return affected rows
+ return SQL_AFFECTEDROWS();
+}
+
+// Generates a list of networks for given script and returns it
+function generateAdminNetworkList () {
+ // Init output
+ $content = '';
+
+ // Query for all networks
+ $result = SQL_QUERY("SELECT
+ `network_id`, `network_title`
+FROM
+ `{?_MYSQL_PREFIX?}_network_data`
+ORDER BY
+ `network_title` ASC", __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_id']))) $rows[] = $row;
+ } // END - while
+
+ // Generate the selection box
+ $content = generateSelectionBoxFromArray($rows, 'network', 'network_id', 'network_title');
+ } else {
+ // Nothing selected
+ $content = loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ENTRIES_404'));
+ }
+
+ // Free the result
+ SQL_FREERESULT($result);
+
+ // Return the list
+ return $content;
+}
+
//------------------------------------------------------------------------------
// Call-back functions
//------------------------------------------------------------------------------
// Callback function to add new network
function doAdminNetworkProcessAddnetworkForm () {
// We can say here, the form is sent, so check if the network is already added
- if (isNetworkNameValid(postRequestElement('network_short_name'))) {
+ if (isNetworkNameValid(postRequestParameter('network_short_name'))) {
// Already there
- loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_ALREADY_ADDED'), postRequestElement('network_short_name')));
- return;
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_ALREADY_ADDED', postRequestParameter('network_short_name')));
+ return false;
} // END - if
// Remove the 'ok' part
- unsetPostRequestElement('ok');
+ unsetPostRequestParameter('ok');
// Add the whole request to database
SQL_QUERY("INSERT INTO
)", __FUNCTION__, __LINE__);
// Add the id for output only
- setRequestPostElement('network_id', SQL_INSERTID());
+ setPostRequestParameter('network_id', SQL_INSERTID());
// Output message
if (SQL_AFFECTEDROWS() == 1) {
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_saved', false, getMaskedMessage('ADMIN_NETWORK_DATA_NOT_ADDED', postRequestParameter('network_short_name')));
}
}
if (countPostSelection() > 0) {
// Something has been selected, so start displaying one by one
$SW = 2; $OUT = '';
- foreach (postRequestElement('sel') as $id => $sel) {
+ foreach (postRequestParameter('sel') as $id => $sel) {
// Is this selected?
if ($sel == 1) {
// Load this network's data
// Add color
$networkData['sw'] = $SW;
- if (isPostRequestElementSet('edit')) {
+ if (isPostRequestParameterSet('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')),
+ 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 (isPostRequestElementSet('del')) {
+ } elseif (isPostRequestParameterSet('del')) {
// Translate the request type
$networkData['network_request_type'] = getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . $networkData['network_request_type']);
// If we have no rows, we don't need to display the edit form
if (!empty($OUT)) {
// Output main template
- if (isPostRequestElementSet('edit')) {
+ if (isPostRequestParameterSet('edit')) {
loadTemplate('admin_edit_networks', false, $OUT);
- } elseif (isPostRequestElementSet('del')) {
+ } elseif (isPostRequestParameterSet('del')) {
loadTemplate('admin_del_networks', false, $OUT);
} else {
// Problem!
} // END - if
}
+// Handle network type form
+function doAdminNetworkProcessHandlenetworktypeForm () {
+ // Do we have selections?
+ if (countPostSelection() > 0) {
+ // 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
+ $networkTypeData = getNetworkTypeDataById($id);
+
+ // Do we have found the network?
+ if (count($networkTypeData) > 0) {
+ // Add color
+ $networkTypeData['sw'] = $SW;
+
+ if (isPostRequestParameterSet('edit')) {
+ // Add row template for deleting
+ $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
+ } elseif (isPostRequestParameterSet('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.');
+ }
+
+ // 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 (isPostRequestParameterSet('edit')) {
+ loadTemplate('admin_edit_network_types', false, $content);
+ } elseif (isPostRequestParameterSet('del')) {
+ loadTemplate('admin_del_network_types', 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_saved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_FOUND'));
+ }
+ } // END - if
+}
+
// Changes given networks
function doAdminNetworkProcessChangenetworkForm () {
// Do we have selections?
$updated = 0;
// Something has been selected, so start updating them
- foreach (postRequestElement('sel') as $id => $sel) {
+ foreach (postRequestParameter('sel') as $id => $sel) {
// Update this entry?
if ($sel == 1) {
// Init data array
// Do we have updates?
if ($updated > 0) {
// Updates done
- loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_UPDATED'), $updated));
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_UPDATED', $updated));
} else {
// Nothing changed
loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_NOTHING_CHANGED'));
} // END - if
}
+// Removes given networks
+function doAdminNetworkProcessRemovenetworkForm () {
+ // 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('data', 'network_id', $id);
+ } // END - if
+ } // END - foreach
+
+ // Do we have removes?
+ if ($removed > 0) {
+ // Removals done
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REMOVED', $removed));
+ } else {
+ // Nothing removed
+ loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_NOTHING_REMOVED'));
+ }
+ } // END - if
+}
+
+// Add a network type handler if not yet found
+function doAdminNetworkProcessAddnetworktypeForm () {
+ // Is the network type handle already used with given network?
+ if (isNetworkTypeHandleValid(postRequestParameter('network_type_handle'), getRequestParameter('network'))) {
+ // Already added
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED', postRequestParameter('network_type_handle')));
+
+ // ... so abort here
+ return false;
+ } // END - if
+
+ // Remove the 'ok' part
+ unsetPostRequestParameter('ok');
+
+ // Add id
+ setPostRequestParameter('network_id', getRequestParameter('network'));
+
+ // Add the whole request to database
+ SQL_QUERY("INSERT INTO
+ `{?_MYSQL_PREFIX?}_network_types`
+(
+ `" . implode('`,`', array_keys(postRequestArray())) . "`
+) VALUES (
+ '" . implode("','", array_values(postRequestArray())) . "'
+)", __FUNCTION__, __LINE__);
+
+ // Output message
+ if (SQL_AFFECTEDROWS() == 1) {
+ // Successfully added
+ loadTemplate('admin_network_type_added', false, postRequestArray());
+ } else {
+ // Not added
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_NOT_ADDED', postRequestParameter('network_type_handle')));
+ }
+}
+
+// Changes given network type handlers
+function doAdminNetworkProcessChangenetworktypeForm () {
+ // 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
+ $networkTypeData = 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
+
+ // Add this entry
+ $networkTypeData[$key] = $entry[$id];
+ } // END - foreach
+
+ // Update the network data
+ $updated += doNetworkUpdateTypeByArray($id, $networkTypeData);
+ } // END - if
+ } // END - foreach
+
+ // Do we have updates?
+ if ($updated > 0) {
+ // Updates done
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_UPDATED', $updated));
+ } else {
+ // Nothing changed
+ loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_CHANGED'));
+ }
+ } // END - if
+}
+
+// Removes given network type handlers
+function doAdminNetworkProcessRemovenetworktypeForm () {
+ // 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('types', 'network_type_id', $id);
+ } // END - if
+ } // END - foreach
+
+ // Do we have removes?
+ if ($removed > 0) {
+ // Removals done
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_REMOVED', $removed));
+ } else {
+ // Nothing removed
+ loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_REMOVED'));
+ }
+ } // END - if
+}
+
+// Adds a request parameter to given network and type
+function doAdminNetworkProcessAddnetworkparamForm () {
+ // Is the request parameter already used with given network?
+ if (isNetworkRequestParameterValid(postRequestParameter('request_param_key'), postRequestParameter('network_type_id'), getRequestParameter('network'))) {
+ // Already added
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED', postRequestParameter('request_param_key')));
+
+ // ... so abort here
+ return false;
+ } // END - if
+
+ // Remove the 'ok' part
+ unsetPostRequestParameter('ok');
+
+ // Add id
+ setPostRequestParameter('network_id', getRequestParameter('network'));
+
+ // Add the whole request to database
+ SQL_QUERY("INSERT INTO
+ `{?_MYSQL_PREFIX?}_network_request_params`
+(
+ `" . implode('`,`', array_keys(postRequestArray())) . "`
+) VALUES (
+ '" . implode("','", array_values(postRequestArray())) . "'
+)", __FUNCTION__, __LINE__);
+
+ // Output message
+ if (SQL_AFFECTEDROWS() == 1) {
+ // Successfully added
+ loadTemplate('admin_network_request_param_added', false, postRequestArray());
+ } else {
+ // Not added
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED', postRequestParameter('request_param_key')));
+ }
+}
+
// [EOF]
?>