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