2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 11/04/2009 *
4 * =================== Last change: 11/04/2009 *
6 * -------------------------------------------------------------------- *
7 * File : network_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Functions for ext-network *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Funktionen fuer ext-network *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Processes an admin form
45 function doAdminNetworkProcessForm () {
47 if ((!isFormSent()) && (!isPostRequestElementSet('edit')) && (!isPostRequestElementSet('del')) && (!isPostRequestElementSet('change')) && (!isPostRequestElementSet('remove'))) {
49 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_FORM_NOT_SENT'));
51 } elseif (!isGetRequestElementSet('do')) {
53 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_DO_404'));
57 // Create function name
58 $functionName = sprintf("doAdminNetworkProcess%sForm", ucfirst(strtolower(getRequestElement('do'))));
60 // Is the function valid?
61 if (!function_exists($functionName)) {
62 // Invalid function name
63 debug_report_bug('Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.');
66 // Call-back the method handling our request
67 call_user_func($functionName);
70 // Checks wether the (short) network name is already used (valid)
71 function isNetworkNameValid ($name) {
73 $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
74 array($name), __FUNCTION__, __LINE__);
77 $isValid = (SQL_NUMROWS($result) == 1);
80 SQL_FREERESULT($result);
86 // "Getter" for a network's data by provided id number
87 function getNetworkDataById ($id) {
88 // Ids lower one are not accepted
90 // Not good, should be fixed
91 debug_report_bug('Network id ' . $id . ' is smaller than 1.');
94 // By default we have no data
95 $networkData = array();
97 // Query for the network data
98 $result = SQL_QUERY_ESC("SELECT
99 `network_id`, `network_short_name`, `network_title`, `network_reflink`, `network_data_seperator`, `network_row_seperator`, `network_request_type`, `network_charset`
101 `{?_MYSQL_PREFIX?}_network_data`
105 array(bigintval($id)), __FUNCTION__, __LINE__);
107 // Do we have an entry?
108 if (SQL_NUMROWS($result) == 1) {
110 $networkData = SQL_FETCHARRAY($result);
114 SQL_FREERESULT($result);
120 // Updates given network (id) with data from array
121 function doNetworkUpdateDataByArray ($id, $networkData) {
122 // Ids lower one are not accepted
124 // Not good, should be fixed
125 debug_report_bug('Network id ' . $id . ' is smaller than 1.');
128 // Just call our inner method
129 return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($id)), array(), false, false);
132 // Removes given network entry
133 function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
135 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
136 array($table, $column, $id, $limit), __FILE__, __LINE__);
138 // Return affected rows
139 return SQL_AFFECTEDROWS();
142 //------------------------------------------------------------------------------
143 // Call-back functions
144 //------------------------------------------------------------------------------
146 // Callback function to add new network
147 function doAdminNetworkProcessAddnetworkForm () {
148 // We can say here, the form is sent, so check if the network is already added
149 if (isNetworkNameValid(postRequestElement('network_short_name'))) {
151 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_ALREADY_ADDED'), postRequestElement('network_short_name')));
155 // Remove the 'ok' part
156 unsetPostRequestElement('ok');
158 // Add the whole request to database
159 SQL_QUERY("INSERT INTO
160 `{?_MYSQL_PREFIX?}_network_data`
162 `" . implode('`,`', array_keys(postRequestArray())) . "`
164 '" . implode("','", array_values(postRequestArray())) . "'
165 )", __FUNCTION__, __LINE__);
167 // Add the id for output only
168 setRequestPostElement('network_id', SQL_INSERTID());
171 if (SQL_AFFECTEDROWS() == 1) {
172 // Successfully added
173 loadTemplate('admin_network_added', false, postRequestArray());
176 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_DATA_NOT_ADDED'), postRequestElement('network_short_name')));
180 // Displays selected networks for editing
181 function doAdminNetworkProcessHandlenetworkForm () {
182 // Do we have selections?
183 if (countPostSelection() > 0) {
184 // Something has been selected, so start displaying one by one
186 foreach (postRequestElement('sel') as $id => $sel) {
189 // Load this network's data
190 $networkData = getNetworkDataById($id);
192 // Do we have found the network?
193 if (count($networkData) > 0) {
195 $networkData['sw'] = $SW;
197 if (isPostRequestElementSet('edit')) {
198 // Make selection box for network_request_type
199 $networkData['network_request_type'] = generateOptionList(
202 array(getMessage('ADMIN_NETWORK_REQUEST_TYPE_GET'), getMessage('ADMIN_NETWORK_REQUEST_TYPE_POST')),
203 $networkData['network_request_type']
206 // Add row template for editing
207 $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
208 } elseif (isPostRequestElementSet('del')) {
209 // Translate the request type
210 $networkData['network_request_type'] = getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . $networkData['network_request_type']);
212 // Add row template for deleting
213 $OUT .= loadTemplate('admin_del_networks_row', true, $networkData);
216 debug_report_bug('Cannot detect edit/del.');
225 // If we have no rows, we don't need to display the edit form
227 // Output main template
228 if (isPostRequestElementSet('edit')) {
229 loadTemplate('admin_edit_networks', false, $OUT);
230 } elseif (isPostRequestElementSet('del')) {
231 loadTemplate('admin_del_networks', false, $OUT);
234 debug_report_bug('Cannot detect edit/del.');
237 // Don't display the list/add new form
238 $GLOBALS['network_display'] = false;
240 // Nothing selected/found
241 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_NOTHING_FOUND'));
246 // Changes given networks
247 function doAdminNetworkProcessChangenetworkForm () {
248 // Do we have selections?
249 if (countPostSelection() > 0) {
250 // By default nothing is updated
253 // Something has been selected, so start updating them
254 foreach (postRequestElement('sel') as $id => $sel) {
255 // Update this entry?
258 $networkData = array();
260 // Transfer whole array, except 'sel'
261 foreach (postRequestArray() as $key => $entry) {
262 // Skip 'sel' and submit button
263 if (in_array($key, array('sel', 'change'))) continue;
265 // Do we have this enty?
266 if (!isset($entry[$id])) {
267 // Not found, needs fixing
268 debug_report_bug('No entry in key=' . $key . ', id=' . $id . ' found.');
272 $networkData[$key] = $entry[$id];
275 // Update the network data
276 $updated += doNetworkUpdateDataByArray($id, $networkData);
280 // Do we have updates?
283 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_UPDATED'), $updated));
286 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_NOTHING_CHANGED'));
291 // Removes given networks
292 function doAdminNetworkProcessRemovenetworkForm () {
293 // Do we have selections?
294 if (countPostSelection() > 0) {
295 // By default nothing is removed
298 // Something has been selected, so start updating them
299 foreach (postRequestElement('sel') as $id => $sel) {
300 // Update this entry?
303 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $id);
307 // Do we have removes?
310 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_REMOVED'), $removed));
313 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_NOTHING_REMOVED'));