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