c6c5981b83c5180218d55876960c803a0bb6caa0
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Private setter for current network id
44 function setCurrentNetworkId ($networkId) {
45         $GLOBALS['current_network_id'] = bigintval($networkId);
46 }
47
48 // Private getter for current network id
49 function getCurrentNetworkId () {
50         return $GLOBALS['current_network_id'];
51 }
52
53 // Detects if a supported form has been sent
54 function detectNetworkProcessForm () {
55         // 'do' must be provided in URL
56         if (!isGetRequestElementSet('do')) {
57                 // Not provided!
58                 reportBug(__FUNCTION__, __LINE__, 'No "do" has been provided. Please fix your templates.');
59         } // END - if
60
61         // Default is invalid
62         $GLOBALS['network_form_name'] = 'invalid';
63
64         // Now search all valid
65         foreach (array('ok', 'edit', 'delete', 'do_edit', 'do_delete') as $form) {
66                 // Is it detected
67                 if (isFormSent($form)) {
68                         // Use this form name
69                         $GLOBALS['network_form_name'] = $form;
70
71                         // Abort loop
72                         break;
73                 } // END - if
74         } // END - foreach
75
76         // Has the form being detected?
77         if ($GLOBALS['network_form_name'] == 'invalid') {
78                 // Not supported
79                 reportBug(__FUNCTION__, __LINE__, 'POST form could not be detected.');
80         } // END - if
81 }
82
83 // Handle a (maybe) sent form here
84 function doNetworkHandleForm () {
85         // Do we have a form sent?
86         if (countRequestPost() > 0) {
87                 // Detect sent POST form
88                 detectNetworkProcessForm();
89         } elseif (!isGetRequestElementSet('do')) {
90                 // Skip any further requests
91                 return;
92         }
93
94         // Process the request
95         doAdminNetworkProcessForm();
96 }
97
98 // Processes an admin form
99 function doAdminNetworkProcessForm () {
100         // Create function name
101         $functionName = sprintf("doAdminNetworkProcess%s", capitalizeUnderscoreString(getRequestElement('do')));
102
103         // Is the function valid?
104         if (!function_exists($functionName)) {
105                 // Invalid function name
106                 reportBug(__FUNCTION__, __LINE__, 'Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', false);
107         } // END - if
108
109         // Init global arrays
110         $GLOBALS['network_types_disabled'] = array();
111
112         // Call-back the method handling our request
113         call_user_func($functionName);
114 }
115
116 // Checks whether the (short) network name is already used (valid)
117 function isNetworkNameValid ($name) {
118         // Query for it
119         $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
120                 array($name), __FUNCTION__, __LINE__);
121
122         // Does it exist?
123         $isValid = (SQL_NUMROWS($result) == 1);
124
125         // Free result
126         SQL_FREERESULT($result);
127
128         // Return result
129         return $isValid;
130 }
131
132 // Checks whether the given network type is already used (valid)
133 function isNetworkTypeHandleValid ($type, $networkId) {
134         // Query for it
135         $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handler`='%s' LIMIT 1",
136                 array(
137                         $networkId,
138                         $type
139                 ), __FUNCTION__, __LINE__);
140
141         // Does it exist?
142         $isValid = (SQL_NUMROWS($result) == 1);
143
144         // Free result
145         SQL_FREERESULT($result);
146
147         // Return result
148         return $isValid;
149 }
150
151 // Checks whether the given network request parameter is already used (valid)
152 function isNetworkRequestElementValid ($key, $type, $networkId) {
153         // Query for it
154         $result = SQL_QUERY_ESC("SELECT `network_request_param_id` FROM `{?_MYSQL_PREFIX?}_network_request_params` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_request_param_key`='%s' LIMIT 1",
155                 array(
156                         $networkId,
157                         $type,
158                         $key
159                 ), __FUNCTION__, __LINE__);
160
161         // Does it exist?
162         $isValid = (SQL_NUMROWS($result) == 1);
163
164         // Free result
165         SQL_FREERESULT($result);
166
167         // Return result
168         return $isValid;
169 }
170
171 // Checks whether the given vcheck request parameter is already used (valid)
172 function isNetworkVcheckElementValid ($key, $networkId) {
173         // Query for it
174         $result = SQL_QUERY_ESC("SELECT `network_vcheck_param_id` FROM `{?_MYSQL_PREFIX?}_network_vcheck_params` WHERE `network_id`=%s AND `network_vcheck_param_key`='%s' LIMIT 1",
175                 array(
176                         $networkId,
177                         $key
178                 ), __FUNCTION__, __LINE__);
179
180         // Does it exist?
181         $isValid = (SQL_NUMROWS($result) == 1);
182
183         // Free result
184         SQL_FREERESULT($result);
185
186         // Return result
187         return $isValid;
188 }
189
190 // Checks whether the given network API array translation
191 function isNetworkArrayTranslationValid ($key, $type, $networkId) {
192         // Query for it
193         $result = SQL_QUERY_ESC("SELECT `network_array_id` FROM `{?_MYSQL_PREFIX?}_network_array_translation` WHERE `network_id`=%s AND `network_type_id`=%s AND `network_array_index`='%s' LIMIT 1",
194                 array(
195                         $networkId,
196                         $type,
197                         $key
198                 ), __FUNCTION__, __LINE__);
199
200         // Does it exist?
201         $isValid = (SQL_NUMROWS($result) == 1);
202
203         // Free result
204         SQL_FREERESULT($result);
205
206         // Return result
207         return $isValid;
208 }
209
210 // "Getter" for a network's data by provided id number
211 function getNetworkDataById ($networkId, $column = '') {
212         // Ids lower one are not accepted
213         if ($networkId < 1) {
214                 // Not good, should be fixed
215                 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
216         } // END - if
217
218         // Set current network id
219         setCurrentNetworkId($networkId);
220
221         // Is it cached?
222         if (!isset($GLOBALS['network_data'][$networkId])) {
223                 // By default we have no data
224                 $GLOBALS['network_data'][$networkId] = array();
225
226                 // Query for the network data
227                 $result = SQL_QUERY_ESC("SELECT
228         `network_id`,
229         `network_short_name`,
230         `network_title`,
231         `network_reflink`,
232         `network_data_separator`,
233         `network_row_separator`,
234         `network_request_type`,
235         `network_charset`,
236         `network_require_id_card`,
237         `network_query_amount`
238 FROM
239         `{?_MYSQL_PREFIX?}_network_data`
240 WHERE
241         `network_id`=%s
242 LIMIT 1",
243                         array(bigintval($networkId)), __FUNCTION__, __LINE__);
244
245                 // Do we have an entry?
246                 if (SQL_NUMROWS($result) == 1) {
247                         // Then get it
248                         $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
249                 } // END - if
250
251                 // Free result
252                 SQL_FREERESULT($result);
253         } // END - if
254
255         // Return result
256         if (empty($column)) {
257                 // Return array
258                 return $GLOBALS['network_data'][$networkId];
259         } else {
260                 // Return column
261                 return $GLOBALS['network_data'][$networkId][$column];
262         }
263 }
264
265 // "Getter" for a network's data by provided type id number
266 function getNetworkDataByTypeId ($networkId, $column = '') {
267         // Ids lower one are not accepted
268         if ($networkId < 1) {
269                 // Not good, should be fixed
270                 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
271         } // END - if
272
273         // Set current network id
274         setCurrentNetworkId($networkId);
275
276         // Is it cached?
277         if (!isset($GLOBALS['network_data'][$networkId])) {
278                 // By default we have no data
279                 $GLOBALS['network_data'][$networkId] = array();
280
281                 // Query for the network data
282                 $result = SQL_QUERY_ESC("SELECT
283         d.`network_id`,
284         d.`network_short_name`,
285         d.`network_title`,
286         d.`network_reflink`,
287         d.`network_data_separator`,
288         d.`network_row_separator`,
289         d.`network_request_type`,
290         d.`network_charset`,
291         d.`network_require_id_card`,
292         d.`network_query_amount`,
293         t.`network_type_handler`,
294         t.`network_type_api_url`,
295         t.`network_type_click_url`,
296         t.`network_type_banner_url`
297 FROM
298         `{?_MYSQL_PREFIX?}_network_data` AS d
299 LEFT JOIN
300         `{?_MYSQL_PREFIX?}_network_types` AS t
301 ON
302         d.`network_id`=t.`network_id`
303 WHERE
304         t.`network_type_id`=%s
305 LIMIT 1",
306                         array(bigintval($networkId)), __FUNCTION__, __LINE__);
307
308                 // Do we have an entry?
309                 if (SQL_NUMROWS($result) == 1) {
310                         // Then get it
311                         $GLOBALS['network_data'][$networkId] = SQL_FETCHARRAY($result);
312                 } // END - if
313
314                 // Free result
315                 SQL_FREERESULT($result);
316         } // END - if
317
318         // Return result
319         if (empty($column)) {
320                 // Return array
321                 return $GLOBALS['network_data'][$networkId];
322         } else {
323                 // Return column
324                 return $GLOBALS['network_data'][$networkId][$column];
325         }
326 }
327
328 // "Getter" for a network type data by provided id number
329 function getNetworkTypeDataById ($networkId) {
330         // Ids lower one are not accepted
331         if ($networkId < 1) {
332                 // Not good, should be fixed
333                 reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
334         } // END - if
335
336         // By default we have no data
337         $GLOBALS['network_type_data'][$networkId] = array();
338
339         // Query for the network data
340         $result = SQL_QUERY_ESC('SELECT
341         `network_type_id`,
342         `network_id`,
343         `network_type_handler`,
344         `network_type_api_url`,
345         `network_type_click_url`,
346         `network_type_banner_url`
347 FROM
348         `{?_MYSQL_PREFIX?}_network_types`
349 WHERE
350         `network_type_id`=%s
351 LIMIT 1',
352                 array(bigintval($networkId)), __FUNCTION__, __LINE__);
353
354         // Do we have an entry?
355         if (SQL_NUMROWS($result) == 1) {
356                 // Then get it
357                 $GLOBALS['network_type_data'][$networkId] = SQL_FETCHARRAY($result);
358         } // END - if
359
360         // Free result
361         SQL_FREERESULT($result);
362
363         // Return result
364         return $GLOBALS['network_type_data'][$networkId];
365 }
366
367 // "Getter" for a network request parameter data by provided id number
368 function getNetworkRequestParamsDataById ($networkId) {
369         // Ids lower one are not accepted
370         if ($networkId < 1) {
371                 // Not good, should be fixed
372                 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
373         } // END - if
374
375         // By default we have no data
376         $networkRequestData = array();
377
378         // Query for the network data
379         $result = SQL_QUERY_ESC('SELECT
380         `network_request_param_id`,
381         `network_id`,
382         `network_type_id`,
383         `network_request_param_key`,
384         `network_request_param_value`,
385         `network_request_param_default`
386 FROM
387         `{?_MYSQL_PREFIX?}_network_request_params`
388 WHERE
389         `network_request_param_id`=%s
390 LIMIT 1',
391                 array(bigintval($networkId)), __FUNCTION__, __LINE__);
392
393         // Do we have an entry?
394         if (SQL_NUMROWS($result) == 1) {
395                 // Then get it
396                 $networkRequestData = SQL_FETCHARRAY($result);
397         } // END - if
398
399         // Free result
400         SQL_FREERESULT($result);
401
402         // Return result
403         return $networkRequestData;
404 }
405
406 // Updates given network (id) with data from array
407 function doNetworkUpdateDataByArray ($networkId, $networkData) {
408         // Ids lower one are not accepted
409         if ($networkId < 1) {
410                 // Not good, should be fixed
411                 reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
412         } // END - if
413
414         // Just call our inner method
415         return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($networkId)), array(), false, false);
416 }
417
418 // Updates given network type handler (id) with data from array
419 function doNetworkUpdateTypeByArray ($networkId, $networkTypeData) {
420         // Ids lower one are not accepted
421         if ($networkId < 1) {
422                 // Not good, should be fixed
423                 reportBug(__FUNCTION__, __LINE__, 'Network type handler id ' . $networkId . ' is smaller than 1.');
424         } // END - if
425
426         // Just call our inner method
427         return adminSaveSettings($networkTypeData, '_network_types', sprintf("`network_type_id`=%s", bigintval($networkId)), array(), false, false);
428 }
429
430 // Updates given network request parameters (id) with data from array
431 function doNetworkUpdateParamsByArray ($networkId, $networkParamData) {
432         // Ids lower one are not accepted
433         if ($networkId < 1) {
434                 // Not good, should be fixed
435                 reportBug(__FUNCTION__, __LINE__, 'Network request parameter id ' . $networkId . ' is smaller than 1.');
436         } // END - if
437
438         // Just call our inner method
439         return adminSaveSettings($networkParamData, '_network_request_params', sprintf("`network_request_param_id`=%s", bigintval($networkId)), array(), false, false);
440 }
441
442 // Removes given network entry
443 function doAdminRemoveNetworkEntry ($table, $column, $networkId, $limit = 1) {
444         // Remove the entry
445         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
446                 array(
447                         $table,
448                         $column,
449                         $networkId,
450                         $limit
451                 ), __FUNCTION__, __LINE__);
452
453         // Return affected rows
454         return SQL_AFFECTEDROWS();
455 }
456
457 // Generates a list of networks for given script and returns it
458 function generateAdminNetworkList () {
459         // Init output
460         $content = '';
461
462         // Query for all networks
463         $result = SQL_QUERY("SELECT
464         `network_id`,
465         `network_short_name`,
466         `network_title`
467 FROM
468         `{?_MYSQL_PREFIX?}_network_data`
469 WHERE
470         `network_active`='Y'
471 ORDER BY
472         `network_short_name` ASC", __FUNCTION__, __LINE__);
473
474         // Do we have entries?
475         if (!SQL_HASZERONUMS($result)) {
476                 // List all entries
477                 $rows = array();
478                 while ($row = SQL_FETCHARRAY($result)) {
479                         // Is this valid, then add it
480                         if ((is_array($row)) && (isset($row['network_id']))) {
481                                 // Add entry
482                                 $rows[$row['network_id']] = $row;
483                         } // END - if
484                 } // END - while
485
486                 // Generate the selection box
487                 $content = generateSelectionBoxFromArray($rows, 'network_id', 'network_id', '', '', 'network');
488         } else {
489                 // Nothing selected
490                 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
491         }
492
493         // Free the result
494         SQL_FREERESULT($result);
495
496         // Return the list
497         return $content;
498 }
499
500 // Generator (somewhat getter) for a list of network types for given network id
501 function generateAdminNetworkTypeList ($networkId) {
502         // Init content
503         $content = '';
504
505         // Query all types of this network
506         $result = SQL_QUERY_ESC('SELECT
507         `network_type_id`,
508         `network_type_handler`
509 FROM
510         `{?_MYSQL_PREFIX?}_network_types`
511 WHERE
512         `network_id`=%s
513 ORDER BY
514         `network_type_handler` ASC',
515                 array(
516                         bigintval($networkId)
517                 ), __FUNCTION__, __LINE__);
518
519         // Do we have entries?
520         if (!SQL_HASZERONUMS($result)) {
521                 // List all entries
522                 $rows = array();
523                 while ($row = SQL_FETCHARRAY($result)) {
524                         // Is this valid, then add it
525                         if ((is_array($row)) && (isset($row['network_type_id']))) {
526                                 // Add entry
527                                 $rows[$row['network_type_id']] = $row;
528                         } // END - if
529                 } // END - while
530
531                 // Generate the selection box
532                 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id');
533         } else {
534                 // Nothing selected
535                 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
536         }
537
538         // Free the result
539         SQL_FREERESULT($result);
540
541         // Return content
542         return $content;
543 }
544
545 // Generator (somewhat getter) for a list of network types for all types
546 function generateAdminDistinctNetworkTypeList () {
547         // Init content
548         $content = '';
549
550         // Query all types of this network
551         $result = SQL_QUERY("SELECT
552         t.`network_type_id`,
553         t.`network_type_handler`,
554         d.`network_title`
555 FROM
556         `{?_MYSQL_PREFIX?}_network_types` AS t
557 LEFT JOIN
558         `{?_MYSQL_PREFIX?}_network_data` AS d
559 ON
560         t.`network_id`=d.`network_id`
561 WHERE
562         d.`network_active`='Y'
563 ORDER BY
564         d.`network_short_name` ASC,
565         t.`network_type_handler` ASC", __FUNCTION__, __LINE__);
566
567         // Do we have entries?
568         if (!SQL_HASZERONUMS($result)) {
569                 // List all entries
570                 $rows = array();
571                 while ($row = SQL_FETCHARRAY($result)) {
572                         // Is this valid, then add it
573                         if ((is_array($row)) && (isset($row['network_type_id']))) {
574                                 // Add entry
575                                 $rows[$row['network_type_id']] = $row;
576                         } // END - if
577                 } // END - while
578
579                 // Generate the selection box
580                 $content = generateSelectionBoxFromArray($rows, 'network_type', 'network_type_id', '', '_title');
581         } else {
582                 // Nothing selected
583                 $content = loadTemplate('admin_settings_unsaved', false, '{--ADMIN_ENTRIES_404--}');
584         }
585
586         // Free the result
587         SQL_FREERESULT($result);
588         //* DEBUG: */ die('<pre>'.encodeEntities($content).'</pre>');
589
590         // Return content
591         return $content;
592 }
593
594 // Generator (somewhat getter) for network type options
595 function generateNetworkTypeOptions ($networkId) {
596         // Is this an array, then we just came back from edit/delete actions
597         if (is_array($networkId)) {
598                 $networkId = '';
599         } // END - if
600
601         // Is this cached?
602         if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
603                 // Generate output and cache it
604                 $GLOBALS[__FUNCTION__][$networkId] = generateOptions(
605                         'network_types',
606                         'network_type_id',
607                         'network_type_handler',
608                         $networkId,
609                         '',
610                         sprintf(
611                                 "WHERE `network_id`=%s",
612                                 bigintval(getRequestElement('network_id'))
613                         ),
614                         '',
615                         'translateNetworkTypeHandler'
616                 );
617         } // END - if
618
619         // Return content
620         return $GLOBALS[__FUNCTION__][$networkId];
621 }
622
623 // Generates an options list of all available (hard-coded) handlers
624 function generateNetworkTypesAvailableOptions ($defaultType = NULL) {
625         // Is it cached?
626         if (!isset($GLOBALS[__FUNCTION__][$defaultType])) {
627                 // Generate list
628                 $GLOBALS[__FUNCTION__][$defaultType] = generateOptions(
629                         '/ARRAY/',
630                         array(
631                                 'banner',
632                                 'banner_click',
633                                 'banner_view',
634                                 'button',
635                                 'button_click',
636                                 'button_view',
637                                 'surfbar',
638                                 'surfbar_click',
639                                 'surfbar_view',
640                                 'forcedbanner',
641                                 'forcedtextlink',
642                                 'textlink',
643                                 'textlink_click',
644                                 'textlink_view',
645                                 'skybanner',
646                                 'skybanner_click',
647                                 'skybanner_view',
648                                 'layer',
649                                 'layer_click',
650                                 'layer_view',
651                                 'popup',
652                                 'popdown',
653                                 'textmail',
654                                 'htmlmail',
655                                 'lead',
656                                 'sale',
657                                 'payperactive',
658                                 'pagepeel',
659                                 'traffic'
660                         ),
661                         array(),
662                         $defaultType,
663                         '', '',
664                         $GLOBALS['network_types_disabled'],
665                         'translateNetworkTypeHandler'
666                 );
667         } // END - if
668
669         // Return content
670         return $GLOBALS[__FUNCTION__][$defaultType];
671 }
672
673 // Generates an options list (somewhat getter) for request keys
674 function generateNetworkRequestKeyOptions () {
675         // Is it cached?
676         if (!isset($GLOBALS[__FUNCTION__])) {
677                 // Generate and cache it
678                 $GLOBALS[__FUNCTION__] = generateOptions(
679                         '/ARRAY/',
680                         array(
681                                 'id',
682                                 'sid',
683                                 'hash',
684                                 'password',
685                                 'reload',
686                                 'maximum_stay',
687                                 'minimum_stay',
688                                 'currency',
689                                 'type',
690                                 'remain',
691                                 'reward',
692                                 'size',
693                                 'erotic',
694                                 'extra',
695                                 'country'
696                         ),
697                         array(),
698                         '',
699                         '', '',
700                         $GLOBALS['network_request_params_disabled'],
701                         'translateNetworkRequestParameterKey'
702                 );
703         } // END - if
704
705         // Return content
706         return $GLOBALS[__FUNCTION__];
707 }
708
709 // Generates an options list for vcheck request keys
710 function generateNetworkVcheckKeyOptions () {
711         // Is it cached?
712         if (!isset($GLOBALS[__FUNCTION__])) {
713                 // Generate and cache it
714                 $GLOBALS[__FUNCTION__] = generateOptions(
715                         '/ARRAY/',
716                         array(
717                                 'network_key',
718                                 'sid',
719                                 'payment',
720                                 'remote_address',
721                                 'campaign_id',
722                                 'status',
723                                 'reason',
724                                 'type',
725                                 'network_name',
726                                 'extra_value1',
727                                 'extra_value2',
728                                 'extra_value3',
729                                 'extra_value4',
730                         ),
731                         array(),
732                         '',
733                         '', '',
734                         $GLOBALS['network_vcheck_params_disabled'],
735                         'translateNetworkVcheckParameterKey'
736                 );
737         } // END - if
738
739         // Return content
740         return $GLOBALS[__FUNCTION__];
741 }
742
743 // Generator (somewhat getter) for (return) array translation
744 function generateNetworkTranslationOptions ($default = '') {
745         // Is it cached?
746         if (!isset($GLOBALS[__FUNCTION__][$default])) {
747                 // Generate and cache it
748                 $GLOBALS[__FUNCTION__][$default] = generateOptions(
749                         'network_translations',
750                         'network_translation_id',
751                         'network_translation_name',
752                         $default,
753                         '',
754                         '',
755                         $GLOBALS['network_translation_disabled'],
756                         'translateNetworkTranslationName'
757                 );
758         } // END - if
759
760         // Return content
761         return $GLOBALS[__FUNCTION__][$default];
762 }
763
764 // Generates an option list of request types
765 function generateNetworkRequestTypeOptions ($default = '') {
766         // Do we have cache?
767         if (!isset($GLOBALS[__FUNCTION__][$default])) {
768                 // Generate the list
769                 $GLOBALS[__FUNCTION__][$default] = generateOptions(
770                         '/ARRAY/',
771                         array(
772                                 'GET',
773                                 'POST'
774                         ),
775                         array(
776                                 '{--ADMIN_NETWORK_REQUEST_TYPE_GET--}',
777                                 '{--ADMIN_NETWORK_REQUEST_TYPE_POST--}'
778                         ),
779                         $default
780                 );
781         } // END - if
782
783         // Return cache
784         return $GLOBALS[__FUNCTION__][$default];
785 }
786
787 // Generates an option list of network_api_active
788 function generateNetworkApiActiveOptions ($default = '') {
789         // Do we have cache?
790         if (!isset($GLOBALS[__FUNCTION__][$default])) {
791                 // Generate the list
792                 $GLOBALS[__FUNCTION__][$default] = generateYesNoOptions($default);
793         } // END - if
794
795         // Return cache
796         return $GLOBALS[__FUNCTION__][$default];
797 }
798
799 // Translates 'translate_name' for e.g. templates
800 function translateNetworkTranslationName ($name) {
801         // Generate id
802         $messageId = 'ADMIN_NETWORK_TRANSLATE_' . strtoupper($name) . '_NAME';
803
804         // Is the message id there?
805         if (!isMessageIdValid($messageId)) {
806                 // Not valid type
807                 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
808         } // END - if
809
810         // Return message id
811         return '{--' . $messageId . '--}';
812 }
813
814 // Translates the network type handler (e.g. banner, paidmail) for templates
815 function translateNetworkTypeHandler ($type) {
816         // Generate id
817         $messageId = 'ADMIN_NETWORK_TYPE_HANDLER_' . strtoupper($type);
818
819         // Is the message id there?
820         if (!isMessageIdValid($messageId)) {
821                 // Not valid type
822                 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
823         } // END - if
824
825         // Return message id
826         return '{--' . $messageId . '--}';
827 }
828
829 // Translates request type
830 function translateNetworkRequestType ($type) {
831         // Generate id
832         $messageId = 'ADMIN_NETWORK_REQUEST_TYPE_' . strtoupper($type) . '';
833
834         // Is the message id there?
835         if (!isMessageIdValid($messageId)) {
836                 // Not valid type
837                 reportBug(__FUNCTION__, __LINE__, 'type=' . $type . ' is invalid.');
838         } // END - if
839
840         // Return message id
841         return '{--' . $messageId . '--}';
842 }
843
844 // Translates request parameter
845 function translateNetworkRequestParameterKey ($param) {
846         // Generate id
847         $messageId = 'ADMIN_NETWORK_REQUEST_PARAMETER_' . strtoupper($param) . '';
848
849         // Is the message id there?
850         if (!isMessageIdValid($messageId)) {
851                 // Not valid param
852                 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
853         } // END - if
854
855         // Return message id
856         return '{--' . $messageId . '--}';
857 }
858
859 // Translates vheck request parameter
860 function translateNetworkVcheckParameterKey ($param) {
861         // Generate id
862         $messageId = 'ADMIN_NETWORK_VCHECK_PARAMETER_' . strtoupper($param) . '';
863
864         // Is the message id there?
865         if (!isMessageIdValid($messageId)) {
866                 // Not valid param
867                 reportBug(__FUNCTION__, __LINE__, 'param=' . $param . ' is invalid.');
868         } // END - if
869
870         // Return message id
871         return '{--' . $messageId . '--}';
872 }
873
874 // Translates API index
875 function translateNetworkApiIndex ($index) {
876         // Do we have cache?
877         if (!isset($GLOBALS['network_array_index'])) {
878                 // Get an array of all API array indexes
879                 $GLOBALS['network_array_index'] = array();
880
881                 // Get all entries
882                 $result = SQL_QUERY('SELECT
883         `network_array_id`,
884         `network_array_index`,
885         `network_translation_name`
886 FROM
887         `{?_MYSQL_PREFIX?}_network_array_translation`
888 INNER JOIN
889         `{?_MYSQL_PREFIX?}_network_translations`
890 ON
891         `network_array_index`=`network_translation_id`
892 ORDER BY
893         `sort` ASC', __FUNCTION__, __LINE__);
894
895                 // Do we have entries?
896                 if (!SQL_HASZERONUMS($result)) {
897                         // Get all entries
898                         while ($row = SQL_FETCHARRAY($result)) {
899                                 // Add it to our global array
900                                 $GLOBALS['network_array_index'][$row['network_array_index']] = $row;
901                         } // END - while
902                 } // END - if
903
904                 // Free result
905                 SQL_FREERESULT($result);
906         } // END - if
907
908         // Default name is unknown
909         $name = 'unknown';
910
911         // Is the entry there?
912         if (isset($GLOBALS['network_array_index'][$index])) {
913                 // Then get the name
914                 $name = $GLOBALS['network_array_index'][$index]['network_translation_name'];
915         } // END - if
916
917         // Return translation
918         return translateNetworkTranslationName($name);
919 }
920
921 // Translates network API configuration status (see function isNetworkApiConfigured()) by given id
922 function translateNetworkApiConfiguredStatusById ($networkId) {
923         // Do we have cache?
924         if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
925                 // By default it is not configured
926                 $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
927
928                 // So is it configured?
929                 if (isNetworkApiConfigured($networkId)) {
930                         // Yes, it is
931                         $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
932                 } // END - if
933         } // END - if
934
935         // Return cache
936         return $GLOBALS[__FUNCTION__][$networkId];
937 }
938
939 // Checks if the given network is configured by looking its API configuration entry up
940 function isNetworkApiConfigured ($networkId) {
941         // Do we have cache?
942         if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
943                 // Check for an entry in network_api_config
944                 $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(
945                         bigintval($networkId),
946                         'network_api_config',
947                         'network_id',
948                         'network_id',
949                         true
950                 ) == 1);
951         } // END - if
952
953         // Return cache
954         return $GLOBALS[__FUNCTION__][$networkId];
955 }
956
957 // Checks whether the given network type handler is configured
958 function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
959         // Do we have cache?
960         if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
961                 // Determine it
962                 $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
963                         bigintval($networkTypeId),
964                         'network_types_config',
965                         'network_data_id',
966                         'network_type_id',
967                         true,
968                         sprintf(' AND `network_id`=%s', bigintval($networkId))
969                 ) == 1);
970         } // END - if
971
972         // Return cache
973         return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
974 }
975
976 // Handles the network-payment-check request
977 function handleNetworkPaymentCheckRequest () {
978         // @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
979         reportBug(__FUNCTION__, __LINE__, 'Not yet implemented.');
980 }
981
982 //------------------------------------------------------------------------------
983 //                             Call-back functions
984 //------------------------------------------------------------------------------
985
986 // Callback function to add new network
987 function doAdminNetworkProcessAddNetwork () {
988         // We can say here, the form is sent, so check if the network is already added
989         if (isNetworkNameValid(postRequestElement('network_short_name'))) {
990                 // Already there
991                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
992                 return false;
993         } // END - if
994
995         // Remove the 'ok' part
996         unsetPostRequestElement('ok');
997
998         // Add the whole request to database
999         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_data'), __FUNCTION__, __LINE__);
1000
1001         // Add the id for output only
1002         setPostRequestElement('network_id', SQL_INSERTID());
1003
1004         // Output message
1005         if (!SQL_HASZEROAFFECTED()) {
1006                 // Successfully added
1007                 loadTemplate('admin_network_added', false, postRequestArray());
1008         } else {
1009                 // Not added
1010                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_DATA_NOT_ADDED=' . postRequestElement('network_short_name') . '%}');
1011         }
1012 }
1013
1014 // Displays selected networks for editing
1015 function doAdminNetworkProcessHandleNetworks () {
1016         // Do we have selections?
1017         if (ifPostContainsSelections()) {
1018                 // Something has been selected, so start displaying one by one
1019                 $OUT = '';
1020                 foreach (postRequestElement('sel') as $networkId => $sel) {
1021                         // Is this selected?
1022                         if ($sel == 1) {
1023                                 // Load this network's data
1024                                 $networkData = getNetworkDataById($networkId);
1025
1026                                 // Do we have found the network?
1027                                 if (count($networkData) > 0) {
1028                                         // Add row template with given form name
1029                                         $OUT .= loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks_row', true, $networkData);
1030                                 } // END - if
1031                         } // END - if
1032                 } // END - foreach
1033
1034                 // If we have no rows, we don't need to display the edit form
1035                 if (!empty($OUT)) {
1036                         // Output main template
1037                         loadTemplate('admin_' . $GLOBALS['network_form_name'] . '_networks', false, $OUT);
1038
1039                         // Don't display the list/add new form
1040                         $GLOBALS['network_display'] = false;
1041                 } else {
1042                         // Nothing selected/found
1043                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_FOUND--}');
1044                 }
1045         } // END - if
1046 }
1047
1048 // Handle network type form
1049 function doAdminNetworkProcessHandleNetworkTypes () {
1050         // Do we have selections?
1051         if (ifPostContainsSelections()) {
1052                 // Load network data
1053                 $networkData = getNetworkDataById(getRequestElement('network_id'));
1054
1055                 // Something has been selected, so start displaying one by one
1056                 $OUT = '';
1057                 foreach (postRequestElement('sel') as $networkId => $sel) {
1058                         // Is this selected?
1059                         if ($sel == 1) {
1060                                 // Load this network's data
1061                                 $networkTypeData = getNetworkTypeDataById($networkId);
1062
1063                                 // Do we have found the network?
1064                                 if (count($networkTypeData) > 0) {
1065                                         if (isFormSent('edit')) {
1066                                                 // Add row template for deleting
1067                                                 $OUT .= loadTemplate('admin_edit_network_types_row', true, $networkTypeData);
1068                                         } elseif (isFormSent('delete')) {
1069                                                 // Add row template for deleting
1070                                                 $OUT .= loadTemplate('admin_delete_network_types_row', true, $networkTypeData);
1071                                         } else {
1072                                                 // Problem!
1073                                                 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1074                                         }
1075                                 } // END - if
1076                         } // END - if
1077                 } // END - foreach
1078
1079                 // If we have no rows, we don't need to display the edit form
1080                 if (!empty($OUT)) {
1081                         // Output main template
1082                         if (isFormSent('edit')) {
1083                                 loadTemplate('admin_edit_network_types', false, $OUT);
1084                         } elseif (isFormSent('delete')) {
1085                                 loadTemplate('admin_delete_network_types', false, $OUT);
1086                         } else {
1087                                 // Problem!
1088                                 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1089                         }
1090
1091                         // Don't display the list/add new form
1092                         $GLOBALS['network_display'] = false;
1093                 } else {
1094                         // Nothing selected/found
1095                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_FOUND--}');
1096                 }
1097         } // END - if
1098 }
1099
1100 // Handle network request parameter form
1101 function doAdminNetworkProcessHandleRequestParams () {
1102         // Do we have selections?
1103         if (ifPostContainsSelections()) {
1104                 // Init cache array
1105                 $GLOBALS['network_request_params_disabled'] = array();
1106
1107                 // Load network data
1108                 $networkData = getNetworkDataById(getRequestElement('network_id'));
1109
1110                 // Something has been selected, so start displaying one by one
1111                 $OUT = '';
1112                 foreach (postRequestElement('sel') as $networkId => $sel) {
1113                         // Is this selected?
1114                         if ($sel == 1) {
1115                                 // Load this network's data
1116                                 $networkRequestData = getNetworkRequestParamsDataById($networkId);
1117
1118                                 // Do we have found the network?
1119                                 if (count($networkRequestData) > 0) {
1120                                         if (isFormSent('edit')) {
1121                                                 // Add row template for deleting
1122                                                 $OUT .= loadTemplate('admin_edit_network_request_params_row', true, $networkRequestData);
1123                                         } elseif (isFormSent('delete')) {
1124                                                 // Get type data
1125                                                 $networkRequestData['network_type_data'] = getNetworkTypeDataById($networkRequestData['network_type_id']);
1126
1127                                                 // Add row template for deleting
1128                                                 $OUT .= loadTemplate('admin_delete_network_request_params_row', true, $networkRequestData);
1129                                         } else {
1130                                                 // Problem!
1131                                                 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1132                                         }
1133                                 } // END - if
1134                         } // END - if
1135                 } // END - foreach
1136
1137                 // If we have no rows, we don't need to display the edit form
1138                 if (!empty($OUT)) {
1139                         // Output main template
1140                         if (isFormSent('edit')) {
1141                                 loadTemplate('admin_edit_network_request_params', false, $OUT);
1142                         } elseif (isFormSent('delete')) {
1143                                 loadTemplate('admin_delete_network_request_params', false, $OUT);
1144                         } else {
1145                                 // Problem!
1146                                 reportBug(__FUNCTION__, __LINE__, 'Cannot detect edit/del.');
1147                         }
1148
1149                         // Don't display the list/add new form
1150                         $GLOBALS['network_display'] = false;
1151                 } else {
1152                         // Nothing selected/found
1153                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_FOUND--}');
1154                 }
1155         } // END - if
1156 }
1157
1158 // Changes given networks
1159 function doAdminNetworkProcessChangeNetworks () {
1160         // Do we have selections?
1161         if (ifPostContainsSelections()) {
1162                 // By default nothing is updated
1163                 $updated = 0;
1164
1165                 // Something has been selected, so start updating them
1166                 foreach (postRequestElement('sel') as $networkId => $sel) {
1167                         // Update this entry?
1168                         if ($sel == 1) {
1169                                 // Init data array
1170                                 $networkData = array();
1171
1172                                 // Transfer whole array, except 'sel'
1173                                 foreach (postRequestArray() as $key => $entry) {
1174                                         // Skip 'sel' and submit button
1175                                         if (in_array($key, array('sel', 'do_edit'))) {
1176                                                 continue;
1177                                         } // END - if
1178
1179                                         // Do we have this enty?
1180                                         if (!isset($entry[$networkId])) {
1181                                                 // Not found, needs fixing
1182                                                 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1183                                         } // END - if
1184
1185                                         // Add this entry
1186                                         $networkData[$key] = $entry[$networkId];
1187                                 } // END - foreach
1188
1189                                 // Update the network data
1190                                 $updated += doNetworkUpdateDataByArray($networkId, $networkData);
1191                         } // END - if
1192                 } // END - foreach
1193
1194                 // Do we have updates?
1195                 if ($updated > 0) {
1196                         // Updates done
1197                         displayMessage('{%message,ADMIN_NETWORK_UPDATED=' . $updated . '%}');
1198                 } else {
1199                         // Nothing changed
1200                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_CHANGED--}');
1201                 }
1202         } // END - if
1203 }
1204
1205 // Removes given networks
1206 function doAdminNetworkProcessRemoveNetworks () {
1207         // Do we have selections?
1208         if (ifPostContainsSelections()) {
1209                 // By default nothing is removed
1210                 $removed = 0;
1211
1212                 // Something has been selected, so start updating them
1213                 foreach (postRequestElement('sel') as $networkId => $sel) {
1214                         // Update this entry?
1215                         if ($sel == 1) {
1216                                 // Remove this entry
1217                                 $removed += doAdminRemoveNetworkEntry('data', 'network_id', $networkId);
1218                         } // END - if
1219                 } // END - foreach
1220
1221                 // Do we have removes?
1222                 if ($removed > 0) {
1223                         // Removals done
1224                         displayMessage('{%message,ADMIN_NETWORK_REMOVED=' . $removed . '%}');
1225                 } else {
1226                         // Nothing removed
1227                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_NOTHING_REMOVED--}');
1228                 }
1229         } // END - if
1230 }
1231
1232 // Add a network type handler if not yet found
1233 function doAdminNetworkProcessAddNetworkType () {
1234         // Is the network type handle already used with given network?
1235         if (isNetworkTypeHandleValid(postRequestElement('network_type_handler'), getRequestElement('network_id'))) {
1236                 // Already added
1237                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_ALREADY_ADDED=' . postRequestElement('network_type_handler') . '%}');
1238
1239                 // ... so abort here
1240                 return false;
1241         } // END - if
1242
1243         // Remove the 'ok' part
1244         unsetPostRequestElement('ok');
1245
1246         // Add id
1247         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1248
1249         // Is network_type_banner_url set?
1250         if (postRequestElement('network_type_banner_url') == '') {
1251                 // Remove empty value to get a NULL for an optional entry
1252                 unsetPostRequestElement('network_type_banner_url');
1253         } // END - if
1254
1255         // Add the whole request to database
1256         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_types'), __FUNCTION__, __LINE__);
1257
1258         // Output message
1259         if (!SQL_HASZEROAFFECTED()) {
1260                 // Successfully added
1261                 loadTemplate('admin_network_type_added', false, postRequestArray());
1262         } else {
1263                 // Not added
1264                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_TYPE_HANDLER_NOT_ADDED=' . postRequestElement('network_type_handler') . '%}');
1265         }
1266 }
1267
1268 // Changes given network type handlers
1269 function doAdminNetworkProcessChangeHandlerTypes () {
1270         // Do we have selections?
1271         if (ifPostContainsSelections()) {
1272                 // By default nothing is updated
1273                 $updated = 0;
1274
1275                 // Something has been selected, so start updating them
1276                 foreach (postRequestElement('sel') as $networkId => $sel) {
1277                         // Update this entry?
1278                         if ($sel == 1) {
1279                                 // Init data array
1280                                 $networkTypeData = array();
1281
1282                                 // Transfer whole array, except 'sel'
1283                                 foreach (postRequestArray() as $key => $entry) {
1284                                         // Skip 'sel' and submit button
1285                                         if (in_array($key, array('sel', 'do_edit'))) {
1286                                                 continue;
1287                                         } // END - if
1288
1289                                         // Do we have this enty?
1290                                         if (!isset($entry[$networkId])) {
1291                                                 // Not found, needs fixing
1292                                                 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1293                                         } // END - if
1294
1295                                         // Fix empty network_type_banner_url to NULL
1296                                         if (($key == 'network_type_banner_url') && (trim($entry[$networkId]) == '')) {
1297                                                 // Set it to NULL
1298                                                 $entry[$networkId] = NULL;
1299                                         } // END - if
1300
1301                                         // Add this entry
1302                                         $networkTypeData[$key] = $entry[$networkId];
1303                                 } // END - foreach
1304
1305                                 // Update the network data
1306                                 $updated += doNetworkUpdateTypeByArray($networkId, $networkTypeData);
1307                         } // END - if
1308                 } // END - foreach
1309
1310                 // Do we have updates?
1311                 if ($updated > 0) {
1312                         // Updates done
1313                         displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_UPDATED=' . $updated . '%}');
1314                 } else {
1315                         // Nothing changed
1316                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_CHANGED--}');
1317                 }
1318         } // END - if
1319 }
1320
1321 // Changes given network request parameters
1322 function doAdminNetworkProcessChangeRequestParams () {
1323         // Do we have selections?
1324         if (ifPostContainsSelections()) {
1325                 // By default nothing is updated
1326                 $updated = 0;
1327
1328                 // Something has been selected, so start updating them
1329                 foreach (postRequestElement('sel') as $networkId => $sel) {
1330                         // Update this entry?
1331                         if ($sel == 1) {
1332                                 // Init data array
1333                                 $networkParamsData = array();
1334
1335                                 // Transfer whole array, except 'sel'
1336                                 foreach (postRequestArray() as $key => $entry) {
1337                                         // Skip 'sel' and submit button
1338                                         if (in_array($key, array('sel', 'do_edit'))) {
1339                                                 continue;
1340                                         } // END - if
1341
1342                                         // Do we have this enty?
1343                                         if (!isset($entry[$networkId])) {
1344                                                 // Not found, needs fixing
1345                                                 reportBug(__FUNCTION__, __LINE__, 'No entry in key=' . $key . ', id=' . $networkId . ' found.');
1346                                         } // END - if
1347
1348                                         // Fix empty network_request_param_default to NULL
1349                                         if (($key == 'network_request_param_default') && (trim($entry[$networkId]) == '')) {
1350                                                 // Set it to NULL
1351                                                 $entry[$networkId] = NULL;
1352                                         } // END - if
1353
1354                                         // Add this entry
1355                                         $networkParamsData[$key] = $entry[$networkId];
1356                                 } // END - foreach
1357
1358                                 // Update the network data
1359                                 $updated += doNetworkUpdateParamsByArray($networkId, $networkParamsData);
1360                         } // END - if
1361                 } // END - foreach
1362
1363                 // Do we have updates?
1364                 if ($updated > 0) {
1365                         // Updates done
1366                         displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_UPDATED=' . $updated . '%}');
1367                 } else {
1368                         // Nothing changed
1369                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_CHANGED--}');
1370                 }
1371         } // END - if
1372 }
1373
1374 // Removes given network type handlers
1375 function doAdminNetworkProcessRemoveNetworkTypes () {
1376         // Do we have selections?
1377         if (ifPostContainsSelections()) {
1378                 // By default nothing is removed
1379                 $removed = 0;
1380
1381                 // Something has been selected, so start updating them
1382                 foreach (postRequestElement('sel') as $networkId => $sel) {
1383                         // Update this entry?
1384                         if ($sel == 1) {
1385                                 // Remove this entry
1386                                 $removed += doAdminRemoveNetworkEntry('types', 'network_type_id', $networkId);
1387                         } // END - if
1388                 } // END - foreach
1389
1390                 // Do we have removes?
1391                 if ($removed > 0) {
1392                         // Removals done
1393                         displayMessage('{%message,ADMIN_NETWORK_TYPE_HANDLER_REMOVED=' . $removed . '%}');
1394                 } else {
1395                         // Nothing removed
1396                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_NOTHING_REMOVED--}');
1397                 }
1398         } // END - if
1399 }
1400
1401 // Removes given network request parameters
1402 function doAdminNetworkProcessRemoveNetworkRequestParams () {
1403         // Do we have selections?
1404         if (ifPostContainsSelections()) {
1405                 // By default nothing is removed
1406                 $removed = 0;
1407
1408                 // Something has been selected, so start updating them
1409                 foreach (postRequestElement('sel') as $networkId => $sel) {
1410                         // Update this entry?
1411                         if ($sel == 1) {
1412                                 // Remove this entry
1413                                 $removed += doAdminRemoveNetworkEntry('request_params', 'network_request_param_id', $networkId);
1414                         } // END - if
1415                 } // END - foreach
1416
1417                 // Do we have removes?
1418                 if ($removed > 0) {
1419                         // Removals done
1420                         displayMessage('{%message,ADMIN_NETWORK_REQUEST_PARAMETER_REMOVED=' . $removed . '%}');
1421                 } else {
1422                         // Nothing removed
1423                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_REQUEST_PARAMETER_NOTHING_REMOVED--}');
1424                 }
1425         } // END - if
1426 }
1427
1428 // Adds a request parameter to given network and type
1429 function doAdminNetworkProcessAddRequestParam () {
1430         // Is the request parameter already used with given network?
1431         if (isNetworkRequestElementValid(postRequestElement('network_request_param_key'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1432                 // Already added
1433                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1434
1435                 // ... so abort here
1436                 return false;
1437         } // END - if
1438
1439         // Remove the 'ok' part
1440         unsetPostRequestElement('ok');
1441
1442         // Add id
1443         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1444
1445         // Is network_request_param_default set?
1446         if (postRequestElement('network_request_param_default') == '') {
1447                 // Remove empty value to get a NULL for an optional entry
1448                 unsetPostRequestElement('network_request_param_default');
1449         } // END - if
1450
1451         // Add the whole request to database
1452         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_request_params'), __FUNCTION__, __LINE__);
1453
1454         // Output message
1455         if (!SQL_HASZEROAFFECTED()) {
1456                 // Successfully added
1457                 loadTemplate('admin_network_request_param_added', false, postRequestArray());
1458         } else {
1459                 // Not added
1460                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_REQUEST_PARAMETER_NOT_ADDED=' . postRequestElement('network_request_param_key') . '%}');
1461         }
1462 }
1463
1464 // Adds a vheck request parameter to given network
1465 function doAdminNetworkProcessAddVcheckParam () {
1466         // Is the request parameter already used with given network?
1467         if (isNetworkVcheckElementValid(postRequestElement('network_vcheck_param_key'), getRequestElement('network_id'))) {
1468                 // Already added
1469                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_ALREADY_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1470
1471                 // ... so abort here
1472                 return false;
1473         } // END - if
1474
1475         // Remove the 'ok' part
1476         unsetPostRequestElement('ok');
1477
1478         // Add id
1479         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1480
1481         // Is network_vcheck_param_default set?
1482         if (postRequestElement('network_vcheck_param_default') == '') {
1483                 // Remove empty value to get a NULL for an optional entry
1484                 unsetPostRequestElement('network_vcheck_param_default');
1485         } // END - if
1486
1487         // Add the whole vcheck to database
1488         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_vcheck_params'), __FUNCTION__, __LINE__);
1489
1490         // Output message
1491         if (!SQL_HASZEROAFFECTED()) {
1492                 // Successfully added
1493                 loadTemplate('admin_network_vcheck_param_added', false, postRequestArray());
1494         } else {
1495                 // Not added
1496                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_VCHECK_PARAMETER_NOT_ADDED=' . postRequestElement('network_vcheck_param_key') . '%}');
1497         }
1498 }
1499
1500 // Adds a API response array entry
1501 function doAdminNetworkProcessAddNetworkArrayTranslation () {
1502         // Is the request parameter already used with given network?
1503         if (isNetworkArrayTranslationValid(postRequestElement('network_array_index'), postRequestElement('network_type_id'), getRequestElement('network_id'))) {
1504                 // Already added
1505                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_ALREADY_ADDED=' . postRequestElement('network_array_index') . '%}');
1506
1507                 // ... so abort here
1508                 return false;
1509         } // END - if
1510
1511         // Remove the 'ok' part
1512         unsetPostRequestElement('ok');
1513
1514         // Add id
1515         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1516
1517         // Add sorting
1518         setPostRequestElement('sort', (countSumTotalData(
1519                 bigintval(postRequestElement('network_id')),
1520                 'network_array_translation',
1521                 'network_array_id',
1522                 'network_id',
1523                 true,
1524                 sprintf(" AND `network_type_id`=%s", bigintval(postRequestElement('network_type_id')))
1525         ) + 1));
1526
1527         // Add the whole request to database
1528         SQL_QUERY(getInsertSqlFromArray(postRequestArray(), 'network_array_translation'), __FUNCTION__, __LINE__);
1529
1530         // Output message
1531         if (!SQL_HASZEROAFFECTED()) {
1532                 // Successfully added
1533                 loadTemplate('admin_network_array_translation_added', false, postRequestArray());
1534         } else {
1535                 // Not added
1536                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ARRAY_TRANSLATION_NOT_ADDED=' . postRequestElement('network_array_index') . '%}');
1537         }
1538 }
1539
1540 // Adds/update network API configuration
1541 function doAdminNetworkProcessNetworkApiConfig () {
1542         // Remove the 'ok' part
1543         unsetPostRequestElement('ok');
1544
1545         // Add id
1546         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1547
1548         // Is network_api_referral_button set?
1549         if (postRequestElement('network_api_referral_button') == '') {
1550                 // Remove empty value to get a NULL for an optional entry
1551                 unsetPostRequestElement('network_api_referral_button');
1552         } // END - if
1553
1554         // Is there already an entry?
1555         if (isNetworkApiConfigured(getRequestElement('network_id'))) {
1556                 // Generate SQL query
1557                 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_api_config', 'network_id', postRequestElement('network_id'), array('network_id'));
1558         } else {
1559                 // Insert new entry
1560                 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_api_config');
1561         }
1562
1563         // Run the query
1564         SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1565
1566         // Output message
1567         if (!SQL_HASZEROAFFECTED()) {
1568                 // Successfully added
1569                 displayMessage('{--ADMIN_CONFIG_NETWORK_API_SAVED--}');
1570         } else {
1571                 // Not added
1572                 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_API_NOT_SAVED--}');
1573         }
1574 }
1575
1576 // Only adds network type configuration if not yet present
1577 function doAdminNetworkProcessAddHandlerTypesConfig ($displayMessage = true) {
1578         // Remove the 'ok' part
1579         unsetPostRequestElement('ok');
1580
1581         // Add both ids
1582         setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
1583         setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
1584
1585         /*
1586          * Some parameters are optional, at least one must be given so check a bunch
1587          * of parameters.
1588          */
1589         foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1590                 // Is this element empty?
1591                 if (postRequestElement($element) == '') {
1592                         // Then unset it to get a NULL for optional parameter
1593                         unsetPostRequestElement($element);
1594                 } // END - if
1595         } // END - foreach
1596
1597         // Convert data in POST array
1598         convertSelectionsToEpocheTimeInPostData($content, 'network_max_reload_time_ye', $skip);
1599
1600         // Is there already an entry?
1601         if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1602                 // This network type handler is already configured
1603                 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_ALREADY_CONFIGURED--}');
1604                 return;
1605         } // END - if
1606
1607         // Copy 'set all' and remove it from POST data
1608         $setAll = (postRequestElement('set_all') === 'Y');
1609         unsetPostRequestElement('set_all');
1610
1611         // Shall we set for all?
1612         if ($setAll === true) {
1613                 // Get all handlers
1614                 $result = SQL_QUERY_ESC('SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1615                         array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1616
1617                 // Do we have entries?
1618                 if (SQL_HASZERONUMS($result)) {
1619                         // No, then abort here
1620                         displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1621                         return;
1622                 } // END - if
1623
1624                 // Init number of rows
1625                 $numRows = 0;
1626
1627                 // Fetch all ids
1628                 while (list($typeId) = SQL_FETCHROW($result)) {
1629                         // Set it in GET data
1630                         setGetRequestElement('network_type_id', $typeId);
1631
1632                         // Call this function again
1633                         $numRows += doAdminNetworkProcessAddHandlerTypesConfig(false);
1634                 } // END - while
1635
1636                 // Free result
1637                 SQL_FREERESULT($result);
1638
1639                 // Output message
1640                 if ($numRows > 0) {
1641                         // Something has been updated
1642                         displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1643                 } else {
1644                         // Nothing has been saved
1645                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1646                 }
1647         } else {
1648                 // Get SQL query for new entry
1649                 $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
1650
1651                 // Run the query
1652                 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1653
1654                 // Shall we display the message?
1655                 if ($displayMessage === true) {
1656                         // Output message
1657                         if (!SQL_HASZEROAFFECTED()) {
1658                                 // Successfully added
1659                                 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1660                         } else {
1661                                 // Not added
1662                                 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_SAVED--}');
1663                         }
1664                 } else {
1665                         // Return amount of affected rows (1 or 2)
1666                         return SQL_AFFECTEDROWS();
1667                 }
1668         }
1669 }
1670
1671 // Only changes network type configuration if not yet present
1672 function doAdminNetworkProcessEditHandlerTypesConfig ($displayMessage = true) {
1673         // Remove the 'ok' part
1674         unsetPostRequestElement('ok');
1675
1676         /*
1677          * Some parameters are optional, at least one must be given so check a bunch
1678          * of parameters.
1679          */
1680         foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
1681                 // Is this element empty?
1682                 if (postRequestElement($element) == '') {
1683                         // Then unset it to get a NULL for optional parameter
1684                         unsetPostRequestElement($element);
1685                 } // END - if
1686         } // END - foreach
1687
1688         // Convert time selections in POST data
1689         convertSelectionsToEpocheTimeInPostArray('network_max_reload_time_ye');
1690
1691         // Is there already an entry?
1692         if (!isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
1693                 // This network type handler is not configured
1694                 displayMessage('{--ADMIN_NETWORK_HANDLER_TYPE_HANDLER_NOT_CONFIGURED--}');
1695                 return;
1696         } // END - if
1697
1698         // Copy 'set all' and remove it from POST data
1699         $setAll = (postRequestElement('set_all') === 'Y');
1700         unsetPostRequestElement('set_all');
1701
1702         // Shall we set for all?
1703         if ($setAll === true) {
1704                 // Get all data entries
1705                 $result = SQL_QUERY_ESC('SELECT `network_data_id` FROM `{?_MYSQL_PREFIX?}_network_types_config` WHERE `network_id`=%s ORDER BY `network_type_id` ASC',
1706                         array(bigintval(getRequestElement('network_id'))), __FUNCTION__, __LINE__);
1707
1708                 // Do we have entries?
1709                 if (SQL_HASZERONUMS($result)) {
1710                         // No, then abort here
1711                         displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_SET_ALL_404--}');
1712                         return;
1713                 } // END - if
1714
1715                 // Init number of rows
1716                 $numRows = 0;
1717
1718                 // Fetch all ids
1719                 while (list($dataId) = SQL_FETCHROW($result)) {
1720                         // Set it in GET data
1721                         setPostRequestElement('network_data_id', $dataId);
1722
1723                         // Call this function again
1724                         $numRows += doAdminNetworkProcessEditHandlerTypesConfig(false);
1725                 } // END - while
1726
1727                 // Free result
1728                 SQL_FREERESULT($result);
1729
1730                 // Output message
1731                 if ($numRows > 0) {
1732                         // Something has been updated
1733                         displayMessage('{%message,ADMIN_CONFIG_NETWORK_HANDLER_TYPE_ALL_HANDLER_SAVED=' . bigintval($numRows) . '%}');
1734                 } else {
1735                         // Nothing has been saved
1736                         loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1737                 }
1738         } else {
1739                 // Get SQL query for new entry
1740                 $SQL = getUpdateSqlFromArray(postRequestArray(), 'network_types_config', 'network_data_id', postRequestElement('network_data_id'), array('network_data_id'));
1741
1742                 // Run the query
1743                 SQL_QUERY($SQL, __FUNCTION__, __LINE__);
1744
1745                 // Shall we display the message?
1746                 if ($displayMessage === true) {
1747                         // Output message
1748                         if (!SQL_HASZEROAFFECTED()) {
1749                                 // Successfully added
1750                                 displayMessage('{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_SAVED--}');
1751                         } else {
1752                                 // Not added
1753                                 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_CONFIG_NETWORK_HANDLER_TYPE_HANDLER_NOT_CHANGED--}');
1754                         }
1755                 } else {
1756                         // Return amount of affected rows (1 or 2)
1757                         return SQL_AFFECTEDROWS();
1758                 }
1759         }
1760 }
1761
1762 // Do expression code for this extension
1763 function doExpressionNetwork ($data) {
1764         // Construct replacer
1765         $replacer = sprintf(
1766                 "{DQUOTE} . %s(%s, '%s') . {DQUOTE}",
1767                 $data['callback'],
1768                 $data['matches'][4][$data['key']],
1769                 $data['extra_func']
1770         );
1771
1772         // Replace %network_id% with the current network id
1773         $replacer = str_replace('%network_id%', getCurrentNetworkId(), $replacer);
1774
1775         // Replace the code
1776         $code = replaceExpressionCode($data, $replacer);
1777
1778         // Return it
1779         return $code;
1780 }
1781
1782 // ----------------------------------------------------------------------------
1783 //                     Call-back functions for exporting data
1784 // ----------------------------------------------------------------------------
1785
1786 // Callback function to export network tables
1787 function doAdminNetworkProcessExport () {
1788         // Init table with all valid what->table entries
1789         $validExports = array(
1790                 // General network data
1791                 'list_networks'                  => 'data',
1792                 // Network type handler
1793                 'list_network_types'             => 'types',
1794                 // Network request parameter
1795                 'list_network_request_params'    => 'request_params',
1796                 // Vcheck request parameter
1797                 'list_network_vcheck_params'     => 'vcheck_params',
1798                 // Network API response array index translation
1799                 'list_network_array_translation' => 'array_translation',
1800         );
1801
1802         // Is the 'what' key valid?
1803         if (!isset($validExports[getWhat()])) {
1804                 // Not valid
1805                 reportBug(__FUNCTION__, __LINE__, 'what=' . getWhat() . ' - not supported');
1806         } // END - if
1807
1808         // Generate call-back, some tables require to export not all columns
1809         $callbackName = 'doAdminNetworkExport' . capitalizeUnderscoreString($validExports[getWhat()]);
1810
1811         // Is the call-back function there?
1812         if (!function_exists($callbackName)) {
1813                 // No, this is really bad
1814                 reportBug(__FUNCTION__, __LINE__, 'Invalid call-back function ' . $callbackName . ' detected.');
1815         } elseif (isset($GLOBALS[__FUNCTION__][$callbackName])) {
1816                 // Already called!
1817                 reportBug(__FUNCTION__, __LINE__, 'Double-call of export function ' . $callbackName . ' detected.');
1818         }
1819
1820         // Call the function
1821         call_user_func($callbackName);
1822
1823         // Mark it as called
1824         $GLOBALS[__FUNCTION__][$callbackName] = true;
1825
1826         // Don't display the list/add new form
1827         $GLOBALS['network_display'] = false;
1828 }
1829
1830 // Exports (and displays) the table 'network_data'
1831 function doAdminNetworkExportData () {
1832         // Query for all networks
1833         $result = SQL_QUERY('SELECT
1834         `network_short_name`,
1835         `network_title`,
1836         `network_reflink`,
1837         `network_data_separator`,
1838         `network_row_separator`,
1839         `network_request_type`,
1840         `network_charset`,
1841         `network_require_id_card`,
1842         `network_query_amount`,
1843         `network_active`
1844 FROM
1845         `{?_MYSQL_PREFIX?}_network_data`
1846 ORDER BY
1847         `network_id` ASC',
1848                 __FUNCTION__, __LINE__);
1849
1850         // Start an empty SQL query
1851         $SQL = "INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_data` (`network_short_name`,`network_title`,`network_reflink`,`network_data_separator`,`network_row_separator`,`network_request_type`,`network_charset`,`network_require_id_card`,`network_query_amount`,`network_active`) VALUES\n";
1852
1853         // Load all entries
1854         while ($content = SQL_FETCHARRAY($result)) {
1855                 // Add row
1856                 $SQL .= "('" .
1857                         $content['network_short_name'] . "', '" .
1858                         $content['network_title'] . "', '" .
1859                         $content['network_reflink'] . "', '" .
1860                         $content['network_data_separator'] . "', '" .
1861                         $content['network_row_separator'] . "', '" .
1862                         $content['network_request_type'] . "', '" .
1863                         $content['network_charset'] . "', '" .
1864                         $content['network_require_id_card'] . "', " .
1865                         $content['network_query_amount'] . ", '" .
1866                         $content['network_active'] . "'),\n";
1867         } // END - while
1868
1869         // Remove last commata and close braces
1870         $SQL = substr($SQL, 0, -2);
1871
1872         // Free result
1873         SQL_FREERESULT($result);
1874
1875         // Output the SQL query
1876         loadTemplate('admin_export_network_data', false, $SQL);
1877 }
1878
1879 // Exports (and displays) the table 'network_types'
1880 function doAdminNetworkExportTypes () {
1881         // 'network_id' must be set
1882         if (!isGetRequestElementSet('network_id')) {
1883                 // Only network handlers of one network will be exported per time
1884                 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1885         } // END - if
1886
1887         // Get all network types of given network
1888         $result = SQL_QUERY_ESC('SELECT
1889         `network_type_id`,
1890         `network_id`,
1891         `network_type_handler`,
1892         `network_type_api_url`,
1893         `network_type_click_url`,
1894         `network_type_banner_url`,
1895         `network_type_reload_time_unit`
1896 FROM
1897         `{?_MYSQL_PREFIX?}_network_types`
1898 WHERE
1899         `network_id`=%s
1900 ORDER BY
1901         `network_type_id` ASC',
1902                 array(
1903                         bigintval(getRequestElement('network_id'))
1904                 ), __FUNCTION__, __LINE__);
1905
1906         // Start an empty SQL query
1907         $SQL = "INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_types` (`network_type_id`,`network_id`,`network_type_handler`,`network_type_api_url`,`network_type_click_url`,`network_type_banner_url`,`network_type_reload_time_unit`) VALUES\n";
1908
1909         // Load all entries
1910         while ($content = SQL_FETCHARRAY($result)) {
1911                 // Add row
1912                 $SQL .= '(' .
1913                         $content['network_type_id'] . ', ' .
1914                         $content['network_id'] . ", '" .
1915                         $content['network_type_handler'] . "', '" .
1916                         $content['network_type_api_url'] . "', '" .
1917                         $content['network_type_click_url'] . "', ";
1918                 
1919                 // Is the column NULL?
1920                 if (is_null($content['network_type_banner_url'])) {
1921                         // Column is NULL
1922                         $SQL .= 'NULL';
1923                 } else {
1924                         // Column is set
1925                         $SQL .= chr(39) . $content['network_type_banner_url'] . chr(39);
1926                 }
1927
1928                 // Add more
1929                 $SQL .= ",'" . $content['network_type_reload_time_unit'] . "'),\n";
1930         } // END - while
1931
1932         // Remove last commata and close braces
1933         $SQL = substr($SQL, 0, -2);
1934
1935         // Free result
1936         SQL_FREERESULT($result);
1937
1938         // Output the SQL query
1939         loadTemplate('admin_export_network_types', false, $SQL);
1940 }
1941
1942 // Exports (and displays) the table 'network_request_params'
1943 function doAdminNetworkExportRequestParams () {
1944         // 'network_id' must be set
1945         if (!isGetRequestElementSet('network_id')) {
1946                 // Only network request parameters of one network will be exported per time
1947                 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
1948         } // END - if
1949
1950         // Get all network types of given network
1951         $result = SQL_QUERY_ESC('SELECT
1952         `network_id`,
1953         `network_type_id`,
1954         `network_request_param_key`,
1955         `network_request_param_value`,
1956         `network_request_param_default`
1957 FROM
1958         `{?_MYSQL_PREFIX?}_network_request_params`
1959 WHERE
1960         `network_id`=%s
1961 ORDER BY
1962         `network_type_id` ASC ,
1963         `network_request_param_id` ASC',
1964                 array(
1965                         bigintval(getRequestElement('network_id'))
1966                 ), __FUNCTION__, __LINE__);
1967
1968         // Start an empty SQL query
1969         $SQL = "INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_request_params` (`network_id`,`network_type_id`,`network_request_param_key`,`network_request_param_value`,`network_request_param_default`) VALUES\n";
1970
1971         // Load all entries
1972         while ($content = SQL_FETCHARRAY($result)) {
1973                 // Add row
1974                 $SQL .= '(' .
1975                         $content['network_id'] . ', ' .
1976                         $content['network_type_id'] . ", '" .
1977                         $content['network_request_param_key'] . "', '" .
1978                         $content['network_request_param_value'] . "', ";
1979                 
1980                 // Is the column NULL?
1981                 if (is_null($content['network_request_param_default'])) {
1982                         // Column is NULL
1983                         $SQL .= "NULL),\n";
1984                 } else {
1985                         // Column is set
1986                         $SQL .= chr(39) . $content['network_request_param_default'] . "'),\n";
1987                 }
1988         } // END - while
1989
1990         // Remove last commata and close braces
1991         $SQL = substr($SQL, 0, -2);
1992
1993         // Free result
1994         SQL_FREERESULT($result);
1995
1996         // Output the SQL query
1997         loadTemplate('admin_export_network_request_params', false, $SQL);
1998 }
1999
2000 // Exports (and displays) the table 'network_vcheck_params'
2001 function doAdminNetworkExportVcheckParams () {
2002         // 'network_id' must be set
2003         if (!isGetRequestElementSet('network_id')) {
2004                 // Only network vcheck parameters of one network will be exported per time
2005                 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2006         } // END - if
2007
2008         // Get all network types of given network
2009         $result = SQL_QUERY_ESC('SELECT
2010         `network_id`,
2011         `network_vcheck_param_key`,
2012         `network_vcheck_param_value`,
2013         `network_vcheck_param_default`
2014 FROM
2015         `{?_MYSQL_PREFIX?}_network_vcheck_params`
2016 WHERE
2017         `network_id`=%s
2018 ORDER BY
2019         `network_vcheck_param_id` ASC',
2020                 array(
2021                         bigintval(getRequestElement('network_id'))
2022                 ), __FUNCTION__, __LINE__);
2023
2024         // Start an empty SQL query
2025         $SQL = "INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_vcheck_params` (`network_id`,`network_vcheck_param_key`,`network_vcheck_param_value`,`network_vcheck_param_default`) VALUES\n";
2026
2027         // Load all entries
2028         while ($content = SQL_FETCHARRAY($result)) {
2029                 // Add row
2030                 $SQL .= '(' .
2031                         $content['network_id'] . ", '" .
2032                         $content['network_vcheck_param_key'] . "', '" .
2033                         $content['network_vcheck_param_value'] . "', ";
2034                 
2035                 // Is the column NULL?
2036                 if (is_null($content['network_vcheck_param_default'])) {
2037                         // Column is NULL
2038                         $SQL .= "NULL),\n";
2039                 } else {
2040                         // Column is set
2041                         $SQL .= chr(39) . $content['network_vcheck_param_default'] . "'),\n";
2042                 }
2043         } // END - while
2044
2045         // Remove last commata and close braces
2046         $SQL = substr($SQL, 0, -2);
2047
2048         // Free result
2049         SQL_FREERESULT($result);
2050
2051         // Output the SQL query
2052         loadTemplate('admin_export_network_vcheck_params', false, $SQL);
2053 }
2054
2055 // Exports (and displays) the table 'network_array_translation'
2056 function doAdminNetworkExportArrayTranslation () {
2057         // 'network_id' must be set
2058         if (!isGetRequestElementSet('network_id')) {
2059                 // Only network API array index translations of one network will be exported per time
2060                 reportBug(__FUNCTION__, __LINE__, 'network_id not provided, please fix your links.');
2061         } // END - if
2062
2063         // Get all network types of given network
2064         $result = SQL_QUERY_ESC('SELECT
2065         `network_id`,
2066         `network_type_id`,
2067         `network_array_index`,
2068         `sort`
2069 FROM
2070         `{?_MYSQL_PREFIX?}_network_array_translation`
2071 WHERE
2072         `network_id`=%s
2073 ORDER BY
2074         `network_type_id` ASC,
2075         `sort` ASC',
2076                 array(
2077                         bigintval(getRequestElement('network_id'))
2078                 ), __FUNCTION__, __LINE__);
2079
2080         // Start an empty SQL query
2081         $SQL = "INSERT INTO `&#123;&#63;_MYSQL_PREFIX&#63;&#125;_network_array_translation` (`network_id`,`network_type_id`,`network_array_index`,`sort`) VALUES\n";
2082
2083         // Load all entries
2084         while ($content = SQL_FETCHARRAY($result)) {
2085                 // Add row
2086                 $SQL .= '(' .
2087                         $content['network_id'] . ', ' .
2088                         $content['network_type_id'] . ', ' .
2089                         $content['network_array_index'] . ', ' .
2090                         $content['sort'] . "),\n";
2091         } // END - while
2092
2093         // Remove last commata and close braces
2094         $SQL = substr($SQL, 0, -2);
2095
2096         // Free result
2097         SQL_FREERESULT($result);
2098
2099         // Output the SQL query
2100         loadTemplate('admin_export_network_array_translation', false, $SQL);
2101 }
2102
2103 // [EOF]
2104 ?>