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