8bbcae08a92a57125b8914cabdeb7568c3d22a04
[mailer.git] / inc / libs / network_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 11/04/2009 *
4  * ===================                          Last change: 11/04/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : network_functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Functions for ext-network                        *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Funktionen fuer ext-network                      *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } // END - if
43
44 // Handle a (maybe) sent form here
45 function doNetworkHandleForm () {
46         // Was the form sent?
47         if ((isFormSent()) || (isPostRequestParameterSet('edit')) || (isPostRequestParameterSet('del')) || (isPostRequestParameterSet('change')) || (isPostRequestParameterSet('remove'))) {
48                 // Do we have a 'do'?
49                 if (isGetRequestParameterSet('do')) {
50                         // Process the request
51                         doAdminNetworkProcessForm();
52                 } else {
53                         // No 'do' found
54                         loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_DO_404'));
55                 }
56         } // END - if
57 }
58
59 // Processes an admin form
60 function doAdminNetworkProcessForm () {
61         // Form really sent?
62         if ((!isFormSent()) && (!isPostRequestParameterSet('edit')) && (!isPostRequestParameterSet('del')) && (!isPostRequestParameterSet('change')) && (!isPostRequestParameterSet('remove'))) {
63                 // Abort here
64                 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_FORM_NOT_SENT'));
65                 return;
66         } elseif (!isGetRequestParameterSet('do')) {
67                 // No 'do' found
68                 loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_DO_404'));
69                 return;
70         }
71
72         // Create function name
73         $functionName = sprintf("doAdminNetworkProcess%sForm", ucfirst(strtolower(getRequestParameter('do'))));
74
75         // Is the function valid?
76         if (!function_exists($functionName)) {
77                 // Invalid function name
78                 debug_report_bug('Invalid do ' . getRequestParameter('do') . ', function ' . $functionName .' does not exist.', false);
79         } // END - if
80
81         // Call-back the method handling our request
82         call_user_func($functionName);
83 }
84
85 // Checks wether the (short) network name is already used (valid)
86 function isNetworkNameValid ($name) {
87         // Query for it
88         $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
89                 array($name), __FUNCTION__, __LINE__);
90
91         // Does it exist?
92         $isValid = (SQL_NUMROWS($result) == 1);
93
94         // Free result
95         SQL_FREERESULT($result);
96
97         // Return result
98         return $isValid;
99 }
100
101 // Checks wether the given network type is already used (valid)
102 function isNetworkTypeHandleValid ($type, $networkId) {
103         // Query for it
104         $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handle`='%s' LIMIT 1",
105                 array($networkId, $type), __FUNCTION__, __LINE__);
106
107         // Does it exist?
108         $isValid = (SQL_NUMROWS($result) == 1);
109
110         // Free result
111         SQL_FREERESULT($result);
112
113         // Return result
114         return $isValid;
115 }
116
117 // Checks wether the given network request parameter is already used (valid)
118 function isNetworkRequestParameterValid ($key, $type, $networkId) {
119         // Query for it
120         $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",
121                 array($networkId, $type, $key), __FUNCTION__, __LINE__);
122
123         // Does it exist?
124         $isValid = (SQL_NUMROWS($result) == 1);
125
126         // Free result
127         SQL_FREERESULT($result);
128
129         // Return result
130         return $isValid;
131 }
132
133 // "Getter" for a network's data by provided id number
134 function getNetworkDataById ($id) {
135         // Ids lower one are not accepted
136         if ($id < 1) {
137                 // Not good, should be fixed
138                 debug_report_bug('Network id ' . $id . ' is smaller than 1.');
139         } // END - if
140
141         // By default we have no data
142         $networkData = array();
143
144         // Query for the network data
145         $result = SQL_QUERY_ESC("SELECT
146         `network_id`, `network_short_name`, `network_title`, `network_reflink`, `network_data_seperator`, `network_row_seperator`, `network_request_type`, `network_charset`
147 FROM
148         `{?_MYSQL_PREFIX?}_network_data`
149 WHERE
150         `network_id`=%s
151 LIMIT 1",
152                 array(bigintval($id)), __FUNCTION__, __LINE__);
153
154         // Do we have an entry?
155         if (SQL_NUMROWS($result) == 1) {
156                 // Then get it
157                 $networkData = SQL_FETCHARRAY($result);
158         } // END - if
159
160         // Free result
161         SQL_FREERESULT($result);
162
163         // Return result
164         return $networkData;
165 }
166
167 // "Getter" for a network type data by provided id number
168 function getNetworkTypeDataById ($id) {
169         // Ids lower one are not accepted
170         if ($id < 1) {
171                 // Not good, should be fixed
172                 debug_report_bug('Network type id ' . $id . ' is smaller than 1.');
173         } // END - if
174
175         // By default we have no data
176         $networkTypeData = array();
177
178         // Query for the network data
179         $result = SQL_QUERY_ESC("SELECT
180         `network_type_id`, `network_id`, `network_type_handle`, `network_type_api_url`, `network_type_click_url`, `network_type_banner_url`
181 FROM
182         `{?_MYSQL_PREFIX?}_network_types`
183 WHERE
184         `network_type_id`=%s
185 LIMIT 1",
186                 array(bigintval($id)), __FUNCTION__, __LINE__);
187
188         // Do we have an entry?
189         if (SQL_NUMROWS($result) == 1) {
190                 // Then get it
191                 $networkTypeData = SQL_FETCHARRAY($result);
192         } // END - if
193
194         // Free result
195         SQL_FREERESULT($result);
196
197         // Return result
198         return $networkTypeData;
199 }
200
201 // Updates given network (id) with data from array
202 function doNetworkUpdateDataByArray ($id, $networkData) {
203         // Ids lower one are not accepted
204         if ($id < 1) {
205                 // Not good, should be fixed
206                 debug_report_bug('Network id ' . $id . ' is smaller than 1.');
207         } // END - if
208
209         // Just call our inner method
210         return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($id)), array(), false, false);
211 }
212
213 // Updates given network type handler (id) with data from array
214 function doNetworkUpdateTypeByArray ($id, $networkTypeData) {
215         // Ids lower one are not accepted
216         if ($id < 1) {
217                 // Not good, should be fixed
218                 debug_report_bug('Network type handler id ' . $id . ' is smaller than 1.');
219         } // END - if
220
221         // Just call our inner method
222         return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($id)), array(), false, false);
223 }
224
225 // Removes given network entry
226 function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
227         // Remove the entry
228         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
229                 array($table, $column, $id, $limit), __FILE__, __LINE__);
230
231         // Return affected rows
232         return SQL_AFFECTEDROWS();
233 }
234
235 // Generates a list of networks for given script and returns it
236 function generateAdminNetworkList () {
237         // Init output
238         $content = '';
239
240         // Query for all networks
241         $result = SQL_QUERY("SELECT
242         `network_id`, `network_title`
243 FROM
244         `{?_MYSQL_PREFIX?}_network_data`
245 ORDER BY
246         `network_title` ASC", __FILE__, __LINE__);
247
248         // Do we have entries?
249         if (SQL_NUMROWS($result) > 0) {
250                 // List all entries
251                 $rows = array();
252                 while ($row = SQL_FETCHARRAY($result)) {
253                         // Is this valid, then add it
254                         if ((is_array($row)) && (isset($row['network_id']))) $rows[] = $row;
255                 } // END - while
256
257                 // Generate the selection box
258                 $content = generateSelectionBoxFromArray($rows, 'network', 'network_id', 'network_title');
259         } else {
260                 // Nothing selected
261                 $content = loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_ENTRIES_404'));
262         }
263
264         // Free the result
265         SQL_FREERESULT($result);
266
267         // Return the list
268         return $content;
269 }
270
271 //------------------------------------------------------------------------------
272 //                             Call-back functions
273 //------------------------------------------------------------------------------
274
275 // Callback function to add new network
276 function doAdminNetworkProcessAddnetworkForm () {
277         // We can say here, the form is sent, so check if the network is already added
278         if (isNetworkNameValid(postRequestParameter('network_short_name'))) {
279                 // Already there
280                 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_ALREADY_ADDED', postRequestParameter('network_short_name')));
281                 return false;
282         } // END - if
283
284         // Remove the 'ok' part
285         unsetPostRequestParameter('ok');
286
287         // Add the whole request to database
288         SQL_QUERY("INSERT INTO
289         `{?_MYSQL_PREFIX?}_network_data`
290 (
291         `" . implode('`,`', array_keys(postRequestArray())) . "`
292 ) VALUES (
293         '" . implode("','", array_values(postRequestArray())) . "'
294 )", __FUNCTION__, __LINE__);
295
296         // Add the id for output only
297         setPostRequestParameter('network_id', SQL_INSERTID());
298
299         // Output message
300         if (SQL_AFFECTEDROWS() == 1) {
301                 // Successfully added
302                 loadTemplate('admin_network_added', false, postRequestArray());
303         } else {
304                 // Not added
305                 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_DATA_NOT_ADDED', postRequestParameter('network_short_name')));
306         }
307 }
308
309 // Displays selected networks for editing
310 function doAdminNetworkProcessHandlenetworkForm () {
311         // Do we have selections?
312         if (countPostSelection() > 0) {
313                 // Something has been selected, so start displaying one by one
314                 $SW = 2; $OUT = '';
315                 foreach (postRequestParameter('sel') as $id => $sel) {
316                         // Is this selected?
317                         if ($sel == 1) {
318                                 // Load this network's data
319                                 $networkData = getNetworkDataById($id);
320
321                                 // Do we have found the network?
322                                 if (count($networkData) > 0) {
323                                         // Add color
324                                         $networkData['sw'] = $SW;
325
326                                         if (isPostRequestParameterSet('edit')) {
327                                                 // Make selection box for network_request_type
328                                                 $networkData['network_request_type'] = generateOptionList(
329                                                         '/ARRAY/',
330                                                         array('GET','POST'),
331                                                         array(
332                                                                 getMessage('ADMIN_NETWORK_REQUEST_TYPE_GET'),
333                                                                 getMessage('ADMIN_NETWORK_REQUEST_TYPE_POST')
334                                                         ),
335                                                         $networkData['network_request_type']
336                                                 );
337
338                                                 // Add row template for editing
339                                                 $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
340                                         } elseif (isPostRequestParameterSet('del')) {
341                                                 // Translate the request type
342                                                 $networkData['network_request_type'] = getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . $networkData['network_request_type']);
343
344                                                 // Add row template for deleting
345                                                 $OUT .= loadTemplate('admin_del_networks_row', true, $networkData);
346                                         } else {
347                                                 // Problem!
348                                                 debug_report_bug('Cannot detect edit/del.');
349                                         }
350
351                                         // Switch colors
352                                         $SW = 3 - $SW;
353                                 } // END - if
354                         } // END - if
355                 } // END - foreach
356
357                 // If we have no rows, we don't need to display the edit form
358                 if (!empty($OUT)) {
359                         // Output main template
360                         if (isPostRequestParameterSet('edit')) {
361                                 loadTemplate('admin_edit_networks', false, $OUT);
362                         } elseif (isPostRequestParameterSet('del')) {
363                                 loadTemplate('admin_del_networks', false, $OUT);
364                         } else {
365                                 // Problem!
366                                 debug_report_bug('Cannot detect edit/del.');
367                         }
368
369                         // Don't display the list/add new form
370                         $GLOBALS['network_display'] = false;
371                 } else {
372                         // Nothing selected/found
373                         loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_NOTHING_FOUND'));
374                 }
375         } // END - if
376 }
377
378 // Handle network type form
379 function doAdminNetworkProcessHandlenetworktypeForm () {
380         // Do we have selections?
381         if (countPostSelection() > 0) {
382                 // Load network data
383                 $networkData = getNetworkDataById(getRequestParameter('network'));
384
385                 // Something has been selected, so start displaying one by one
386                 $SW = 2; $OUT = '';
387                 foreach (postRequestParameter('sel') as $id => $sel) {
388                         // Is this selected?
389                         if ($sel == 1) {
390                                 // Load this network's data
391                                 $networkTypeData = getNetworkTypeDataById($id);
392
393                                 // Do we have found the network?
394                                 if (count($networkTypeData) > 0) {
395                                         // Add color
396                                         $networkTypeData['sw'] = $SW;
397
398                                         if (isPostRequestParameterSet('edit')) {
399                                                 // Add row template for deleting
400                                                 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
401                                         } elseif (isPostRequestParameterSet('del')) {
402                                                 // Fix empty banner URL
403                                                 if (trim($networkTypeData['network_type_banner_url']) == '') $networkTypeData['network_type_banner_url'] = '---';
404
405                                                 // Add row template for deleting
406                                                 $OUT .= loadTemplate('admin_del_network_types_row', true, $networkTypeData);
407                                         } else {
408                                                 // Problem!
409                                                 debug_report_bug('Cannot detect edit/del.');
410                                         }
411
412                                         // Switch colors
413                                         $SW = 3 - $SW;
414                                 } // END - if
415                         } // END - if
416                 } // END - foreach
417
418                 // If we have no rows, we don't need to display the edit form
419                 if (!empty($OUT)) {
420                         // Prepare content for template
421                         $content = array(
422                                 'rows' => $OUT,
423                                 'network_data' => getNetworkDataById(getRequestParameter('network'))
424                         );
425
426                         // Output main template
427                         if (isPostRequestParameterSet('edit')) {
428                                 loadTemplate('admin_edit_network_types', false, $content);
429                         } elseif (isPostRequestParameterSet('del')) {
430                                 loadTemplate('admin_del_network_types', false, $content);
431                         } else {
432                                 // Problem!
433                                 debug_report_bug('Cannot detect edit/del.');
434                         }
435
436                         // Don't display the list/add new form
437                         $GLOBALS['network_display'] = false;
438                 } else {
439                         // Nothing selected/found
440                         loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_FOUND'));
441                 }
442         } // END - if
443 }
444
445 // Changes given networks
446 function doAdminNetworkProcessChangenetworkForm () {
447         // Do we have selections?
448         if (countPostSelection() > 0) {
449                 // By default nothing is updated
450                 $updated = 0;
451
452                 // Something has been selected, so start updating them
453                 foreach (postRequestParameter('sel') as $id => $sel) {
454                         // Update this entry?
455                         if ($sel == 1) {
456                                 // Init data array
457                                 $networkData = array();
458
459                                 // Transfer whole array, except 'sel'
460                                 foreach (postRequestArray() as $key => $entry) {
461                                         // Skip 'sel' and submit button
462                                         if (in_array($key, array('sel', 'change'))) continue;
463
464                                         // Do we have this enty?
465                                         if (!isset($entry[$id])) {
466                                                 // Not found, needs fixing
467                                                 debug_report_bug('No entry in key=' . $key . ', id=' . $id . ' found.');
468                                         } // END - if
469
470                                         // Add this entry
471                                         $networkData[$key] = $entry[$id];
472                                 } // END - foreach
473
474                                 // Update the network data
475                                 $updated += doNetworkUpdateDataByArray($id, $networkData);
476                         } // END - if
477                 } // END - foreach
478
479                 // Do we have updates?
480                 if ($updated > 0) {
481                         // Updates done
482                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_UPDATED', $updated));
483                 } else {
484                         // Nothing changed
485                         loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_NOTHING_CHANGED'));
486                 }
487         } // END - if
488 }
489
490 // Removes given networks
491 function doAdminNetworkProcessRemovenetworkForm () {
492         // Do we have selections?
493         if (countPostSelection() > 0) {
494                 // By default nothing is removed
495                 $removed = 0;
496
497                 // Something has been selected, so start updating them
498                 foreach (postRequestParameter('sel') as $id => $sel) {
499                         // Update this entry?
500                         if ($sel == 1) {
501                                 // Remove this entry
502                                 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $id);
503                         } // END - if
504                 } // END - foreach
505
506                 // Do we have removes?
507                 if ($removed > 0) {
508                         // Removals done
509                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_REMOVED', $removed));
510                 } else {
511                         // Nothing removed
512                         loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_NOTHING_REMOVED'));
513                 }
514         } // END - if
515 }
516
517 // Add a network type handler if not yet found
518 function doAdminNetworkProcessAddnetworktypeForm () {
519         // Is the network type handle already used with given network?
520         if (isNetworkTypeHandleValid(postRequestParameter('network_type_handle'), getRequestParameter('network'))) {
521                 // Already added
522                 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_HANDLE_ALREADY_ADDED', postRequestParameter('network_type_handle')));
523
524                 // ... so abort here
525                 return false;
526         } // END - if
527
528         // Remove the 'ok' part
529         unsetPostRequestParameter('ok');
530
531         // Add id
532         setPostRequestParameter('network_id', getRequestParameter('network'));
533
534         // Is network_type_banner_url set?
535         if (postRequestParameter('network_type_banner_url') == '') {
536                 // Remove empty value to get a NULL for an optional entry
537                 unsetPostRequestParameter('network_type_banner_url');
538         } // END - if
539
540         // Add the whole request to database
541         SQL_QUERY("INSERT INTO
542         `{?_MYSQL_PREFIX?}_network_types`
543 (
544         `" . implode('`,`', array_keys(postRequestArray())) . "`
545 ) VALUES (
546         '" . implode("','", array_values(postRequestArray())) . "'
547 )", __FUNCTION__, __LINE__);
548
549         // Output message
550         if (SQL_AFFECTEDROWS() == 1) {
551                 // Successfully added
552                 loadTemplate('admin_network_type_added', false, postRequestArray());
553         } else {
554                 // Not added
555                 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_NOT_ADDED', postRequestParameter('network_type_handle')));
556         }
557 }
558
559 // Changes given network type handlers
560 function doAdminNetworkProcessChangenetworktypeForm () {
561         // Do we have selections?
562         if (countPostSelection() > 0) {
563                 // By default nothing is updated
564                 $updated = 0;
565
566                 // Something has been selected, so start updating them
567                 foreach (postRequestParameter('sel') as $id => $sel) {
568                         // Update this entry?
569                         if ($sel == 1) {
570                                 // Init data array
571                                 $networkTypeData = array();
572
573                                 // Transfer whole array, except 'sel'
574                                 foreach (postRequestArray() as $key => $entry) {
575                                         // Skip 'sel' and submit button
576                                         if (in_array($key, array('sel', 'change'))) continue;
577
578                                         // Do we have this enty?
579                                         if (!isset($entry[$id])) {
580                                                 // Not found, needs fixing
581                                                 debug_report_bug('No entry in key=' . $key . ', id=' . $id . ' found.');
582                                         } // END - if
583
584                                         // Add this entry
585                                         $networkTypeData[$key] = $entry[$id];
586                                 } // END - foreach
587
588                                 // Update the network data
589                                 $updated += doNetworkUpdateTypeByArray($id, $networkTypeData);
590                         } // END - if
591                 } // END - foreach
592
593                 // Do we have updates?
594                 if ($updated > 0) {
595                         // Updates done
596                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_UPDATED', $updated));
597                 } else {
598                         // Nothing changed
599                         loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_CHANGED'));
600                 }
601         } // END - if
602 }
603
604 // Removes given network type handlers
605 function doAdminNetworkProcessRemovenetworktypeForm () {
606         // Do we have selections?
607         if (countPostSelection() > 0) {
608                 // By default nothing is removed
609                 $removed = 0;
610
611                 // Something has been selected, so start updating them
612                 foreach (postRequestParameter('sel') as $id => $sel) {
613                         // Update this entry?
614                         if ($sel == 1) {
615                                 // Remove this entry
616                                 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $id);
617                         } // END - if
618                 } // END - foreach
619
620                 // Do we have removes?
621                 if ($removed > 0) {
622                         // Removals done
623                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPES_REMOVED', $removed));
624                 } else {
625                         // Nothing removed
626                         loadTemplate('admin_settings_unsaved', false, getMessage('ADMIN_NETWORK_TYPES_NOTHING_REMOVED'));
627                 }
628         } // END - if
629 }
630
631 // Adds a request parameter to given network and type
632 function doAdminNetworkProcessAddnetworkparamForm () {
633         // Is the request parameter already used with given network?
634         if (isNetworkRequestParameterValid(postRequestParameter('request_param_key'), postRequestParameter('network_type_id'), getRequestParameter('network'))) {
635                 // Already added
636                 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED', postRequestParameter('request_param_key')));
637
638                 // ... so abort here
639                 return false;
640         } // END - if
641
642         // Remove the 'ok' part
643         unsetPostRequestParameter('ok');
644
645         // Add id
646         setPostRequestParameter('network_id', getRequestParameter('network'));
647
648         // Is request_param_default set?
649         if (postRequestParameter('request_param_default') == '') {
650                 // Remove empty value to get a NULL for an optional entry
651                 unsetPostRequestParameter('request_param_default');
652         } // END - if
653
654         // Add the whole request to database
655         SQL_QUERY("INSERT INTO
656         `{?_MYSQL_PREFIX?}_network_request_params`
657 (
658         `" . implode('`,`', array_keys(postRequestArray())) . "`
659 ) VALUES (
660         '" . implode("','", array_values(postRequestArray())) . "'
661 )", __FUNCTION__, __LINE__);
662
663         // Output message
664         if (SQL_AFFECTEDROWS() == 1) {
665                 // Successfully added
666                 loadTemplate('admin_network_request_param_added', false, postRequestArray());
667         } else {
668                 // Not added
669                 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED', postRequestParameter('request_param_key')));
670         }
671 }
672
673 // [EOF]
674 ?>